generated from aselimov/cpp_project_template
Initial commit
This commit is contained in:
commit
311a93cdd6
9
.gitignore
vendored
Normal file
9
.gitignore
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
# Builds
|
||||
build/
|
||||
|
||||
# Google Tests
|
||||
tests/lib/
|
||||
|
||||
# Jet Brains
|
||||
.idea/
|
||||
cmake-build-debug/
|
55
CMakeLists.txt
Normal file
55
CMakeLists.txt
Normal file
@ -0,0 +1,55 @@
|
||||
cmake_minimum_required(VERSION 3.9)
|
||||
project(MyProject LANGUAGES CUDA CXX)
|
||||
|
||||
add_compile_options(-Wall -Wextra -Wpedantic)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CUDA_ARCHITECTURES 61)
|
||||
set(CUDA_SEPARABLE_COMPILATION ON)
|
||||
|
||||
|
||||
|
||||
include_directories(src)
|
||||
include_directories(kernels)
|
||||
include_directories(/usr/local/cuda-12.8/include)
|
||||
|
||||
|
||||
add_subdirectory(src)
|
||||
add_subdirectory(kernels)
|
||||
add_subdirectory(tests)
|
||||
|
||||
add_executable(${CMAKE_PROJECT_NAME}_run main.cpp)
|
||||
|
||||
|
||||
|
||||
target_link_libraries(
|
||||
${CMAKE_PROJECT_NAME}_run
|
||||
PRIVATE
|
||||
${CMAKE_PROJECT_NAME}_lib
|
||||
${CMAKE_PROJECT_NAME}_cuda_lib
|
||||
${CUDA_LIBRARIES}
|
||||
)
|
||||
|
||||
# Doxygen Build
|
||||
option(BUILD_DOC "Build Documentation" ON)
|
||||
|
||||
find_package(Doxygen)
|
||||
if(DOXYGEN_FOUND)
|
||||
set(BUILD_DOC_DIR ${CMAKE_SOURCE_DIR}/build/docs)
|
||||
if(NOT EXISTS ${BUILD_DOC_DIR})
|
||||
file(MAKE_DIRECTORY ${BUILD_DOC_DIR})
|
||||
endif()
|
||||
|
||||
set(DOXYGEN_IN ${CMAKE_CURRENT_SOURCE_DIR}/docs/Doxyfile)
|
||||
set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
|
||||
configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY)
|
||||
|
||||
message("Doxygen buld started")
|
||||
add_custom_target(Doxygen ALL
|
||||
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT}
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||
COMMENT "Generating API documentation with Doxygen"
|
||||
VERBATIM)
|
||||
else(DOXYGEN_FOUND)
|
||||
message("Doxygen needs to be installed to generate the documentation.")
|
||||
endif(DOXYGEN_FOUND)
|
21
LICENSE
Normal file
21
LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2017 Timothy Helton
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
12
README.md
Normal file
12
README.md
Normal file
@ -0,0 +1,12 @@
|
||||
# C++ Project Template
|
||||
When setting out on a new project in C++ there are a few configuration steps
|
||||
which need to be completed prior to actually getting down to writing code.
|
||||
This repository is going to be a C++ project template that already has the
|
||||
following components:
|
||||
|
||||
- Directory Structure
|
||||
- Make Build (CMake)
|
||||
- CUDA integration
|
||||
- Unit Test Framework (Google Test)
|
||||
- API Documentation (Doxygen)
|
||||
|
2473
docs/Doxyfile
Normal file
2473
docs/Doxyfile
Normal file
File diff suppressed because it is too large
Load Diff
18
kernels/CMakeLists.txt
Normal file
18
kernels/CMakeLists.txt
Normal file
@ -0,0 +1,18 @@
|
||||
project(${CMAKE_PROJECT_NAME}_cuda_lib CUDA CXX)
|
||||
|
||||
set(HEADER_FILES
|
||||
hello_world.h
|
||||
)
|
||||
set(SOURCE_FILES
|
||||
hello_world.cu
|
||||
)
|
||||
|
||||
# The library contains header and source files.
|
||||
add_library(${CMAKE_PROJECT_NAME}_cuda_lib STATIC
|
||||
${SOURCE_FILES}
|
||||
${HEADER_FILES}
|
||||
)
|
||||
|
||||
if(CMAKE_COMPILER_IS_GNUCXX)
|
||||
target_compile_options(${CMAKE_PROJECT_NAME}_cuda_lib PRIVATE -Wno-gnu-line-marker)
|
||||
endif()
|
46
kernels/hello_world.cu
Normal file
46
kernels/hello_world.cu
Normal file
@ -0,0 +1,46 @@
|
||||
#include <cuda_runtime.h>
|
||||
#include <stdio.h>
|
||||
|
||||
__global__ void hello_cuda() {
|
||||
printf("Hello CUDA from thread %d\n", threadIdx.x);
|
||||
}
|
||||
|
||||
extern "C" void launch_hello_cuda() {
|
||||
// First check device properties
|
||||
cudaDeviceProp prop;
|
||||
cudaGetDeviceProperties(&prop, 1);
|
||||
printf("Using device: %s with compute capability %d.%d\n", prop.name,
|
||||
prop.major, prop.minor);
|
||||
|
||||
hello_cuda<<<1, 10>>>();
|
||||
cudaDeviceSynchronize();
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
extern "C" void check_cuda() {
|
||||
int deviceCount = 0;
|
||||
cudaError_t error = cudaGetDeviceCount(&deviceCount);
|
||||
|
||||
if (error != cudaSuccess) {
|
||||
printf("CUDA error: %s\n", cudaGetErrorString(error));
|
||||
}
|
||||
|
||||
printf("Found %d CUDA devices\n", deviceCount);
|
||||
|
||||
for (int i = 0; i < deviceCount; i++) {
|
||||
cudaDeviceProp prop;
|
||||
cudaGetDeviceProperties(&prop, i);
|
||||
|
||||
printf("Device %d: %s\n", i, prop.name);
|
||||
printf(" Compute capability: %d.%d\n", prop.major, prop.minor);
|
||||
printf(" Total global memory: %.2f GB\n",
|
||||
static_cast<float>(prop.totalGlobalMem) / (1024 * 1024 * 1024));
|
||||
printf(" Multiprocessors: %d\n", prop.multiProcessorCount);
|
||||
printf(" Max threads per block: %d\n", prop.maxThreadsPerBlock);
|
||||
printf(" Max threads dimensions: (%d, %d, %d)\n", prop.maxThreadsDim[0],
|
||||
prop.maxThreadsDim[1], prop.maxThreadsDim[2]);
|
||||
printf(" Max grid dimensions: (%d, %d, %d)\n", prop.maxGridSize[0],
|
||||
prop.maxGridSize[1], prop.maxGridSize[2]);
|
||||
printf("\n");
|
||||
}
|
||||
}
|
10
kernels/hello_world.h
Normal file
10
kernels/hello_world.h
Normal file
@ -0,0 +1,10 @@
|
||||
#ifndef HELLO_WORLD_CU_H
|
||||
#define HELLO_WORLD_CU_H
|
||||
|
||||
extern "C" {
|
||||
// Declaration of the CUDA function that will be called from C++
|
||||
void launch_hello_cuda();
|
||||
void check_cuda();
|
||||
}
|
||||
|
||||
#endif // HELLO_WORLD_CU_H
|
10
main.cpp
Normal file
10
main.cpp
Normal file
@ -0,0 +1,10 @@
|
||||
#include "hello_world.h"
|
||||
#include <iostream>
|
||||
|
||||
int main() {
|
||||
std::cout << "Starting CUDA example..." << std::endl; // Using endl to flush
|
||||
check_cuda();
|
||||
launch_hello_cuda();
|
||||
std::cout << "Ending CUDA example" << std::endl; // Using endl to flush
|
||||
return 0;
|
||||
}
|
16
src/CMakeLists.txt
Normal file
16
src/CMakeLists.txt
Normal file
@ -0,0 +1,16 @@
|
||||
project(${CMAKE_PROJECT_NAME}_lib CUDA CXX)
|
||||
|
||||
set(HEADER_FILES
|
||||
./test.h
|
||||
)
|
||||
set(SOURCE_FILES
|
||||
./test.cpp
|
||||
)
|
||||
|
||||
# The library contains header and source files.
|
||||
add_library(${CMAKE_PROJECT_NAME}_lib
|
||||
${SOURCE_FILES}
|
||||
${HEADER_FILES}
|
||||
)
|
||||
|
||||
target_include_directories(${CMAKE_PROJECT_NAME}_lib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
4
src/test.cpp
Normal file
4
src/test.cpp
Normal file
@ -0,0 +1,4 @@
|
||||
#include "test.h"
|
||||
#include <iostream>
|
||||
|
||||
void test_hello() { std::cout << "Hello!"; }
|
2
src/test.h
Normal file
2
src/test.h
Normal file
@ -0,0 +1,2 @@
|
||||
#include <iostream>
|
||||
void test_hello();
|
13
tests/CMakeLists.txt
Normal file
13
tests/CMakeLists.txt
Normal file
@ -0,0 +1,13 @@
|
||||
project(${CMAKE_PROJECT_NAME}_tests)
|
||||
|
||||
# Clone Google Test
|
||||
set(GOOGLETEST_DIR ${CMAKE_SOURCE_DIR}/tests/lib/googletest)
|
||||
if(NOT EXISTS ${GOOGLETEST_DIR})
|
||||
find_package(Git REQUIRED)
|
||||
execute_process(
|
||||
COMMAND ${GIT_EXECUTABLE} clone https://github.com/google/googletest ${GOOGLETEST_DIR}
|
||||
)
|
||||
endif()
|
||||
|
||||
add_subdirectory(lib/googletest)
|
||||
add_subdirectory(unit_tests)
|
8
tests/unit_tests/CMakeLists.txt
Normal file
8
tests/unit_tests/CMakeLists.txt
Normal file
@ -0,0 +1,8 @@
|
||||
include_directories(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR})
|
||||
|
||||
add_executable(Unit_Tests_run
|
||||
test_example.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(Unit_Tests_run gtest gtest_main)
|
||||
target_link_libraries(Unit_Tests_run ${CMAKE_PROJECT_NAME}_lib)
|
5
tests/unit_tests/test_example.cpp
Normal file
5
tests/unit_tests/test_example.cpp
Normal file
@ -0,0 +1,5 @@
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
TEST(Example, Equals) {
|
||||
EXPECT_EQ(1, 1);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user