Last active
April 1, 2022 11:13
-
-
Save MathiasMagnus/0edacac888a758fe233cb69f3e291d62 to your computer and use it in GitHub Desktop.
Minimal CMakeLists.txt template for CUDA
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cmake_minimum_required(VERSION 3.8) # CUDA language support | |
project(template | |
LANGUAGES | |
CXX CUDA | |
) | |
set(Hdrs Other.hpp) | |
set(Srcs | |
Main.cpp | |
Other.cu | |
) | |
add_executable(${PROJECT_NAME} ${Hdrs} ${Srcs}) | |
target_include_directories(${PROJECT_NAME} | |
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} | |
) | |
target_compile_features(${PROJECT_NAME} | |
PRIVATE | |
cxx_std_17 | |
cuda_std_17 | |
) | |
target_compile_definitions(${PROJECT_NAME} | |
PRIVATE | |
$<$<COMPILE_LANGUAGE:CXX>:SOME_ABI_CONTROLLING_DEFINE=WHATEVER> | |
$<$<COMPILE_LANGUAGE:CUDA>:SOME_DEVICE_DEF=32> | |
) | |
set_target_properties(${PROJECT_NAME} | |
PROPERTIES | |
CUDA_SEPARABLE_COMPILATION ON | |
) | |
source_group ("Headers" FILES ${Hdrs}) | |
source_group ("Sources" FILES ${Srcs}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Other.hpp> | |
int main() | |
{ | |
return foo(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cuda_runtime.h> | |
__global__ void kernel() {} | |
int foo() | |
{ | |
kernel<<<SOME_DEVICE_DEF,SOME_DEVICE_DEF>>>(); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int foo(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment