From 06bcae6343dc7e0039da0575f76b96608bf63fcf Mon Sep 17 00:00:00 2001 From: Scott McMillan Date: Mon, 21 Aug 2023 16:07:58 -0400 Subject: [PATCH] Cleaning up cmake for CUDA. Fixing the executable extension of cuda programs (now '.x') --- CMakeLists.txt | 10 +++------- cuda_demo/CMakeLists.txt | 8 +++++++- cuda_demo/cuda_relu.cu | 6 ++++++ 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8f965ab..fabe68c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,18 +48,14 @@ if(CMAKE_UARCH STREQUAL "ORIN") message("Configuring nvcc compiler") option(ENABLE_CUDA "Enable building CUDA components" ON) enable_language(CUDA) - set(CMAKE_VERBOSE_MAKEFILE on) + #set(CMAKE_VERBOSE_MAKEFILE on) SET(CMAKE_CUDA_COMPILER /usr/local/cuda/bin/nvcc) - #SET(CMAKE_CXX_COMPILER /usr/local/cuda/bin/nvcc) - #SET(CMAKE_C_COMPILER /usr/local/cuda/bin/nvcc) SET(CMAKE_CUDA_ARCHITECTURES 87) - #set(CMAKE_CXX_STANDARD 17) set(CMAKE_CUDA_STANDARD 17) - #SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17") SET(CMAKE_CUDA_FLAGS "${CMAKE_CXX_FLAGS} -arch=sm_87 -std=c++17") - #set_target_properties( PROPERTIES CUDA_SEPARABLE_COMPILATION ON) + # https://arnon.dk/matching-sm-architectures-arch-and-gencode-for-various-nvidia-cards/ - # -arch=sm_30 for Kepler + else() message("Configuring gnu compilers") set(CMAKE_VERBOSE_MAKEFILE off) diff --git a/cuda_demo/CMakeLists.txt b/cuda_demo/CMakeLists.txt index d235d0e..236690c 100644 --- a/cuda_demo/CMakeLists.txt +++ b/cuda_demo/CMakeLists.txt @@ -21,11 +21,17 @@ message("In cuda_demo/CMakeLists.txt: ${SOURCES}") foreach( source_file ${SOURCES} ) get_filename_component(justname ${source_file} NAME) - string( REPLACE ".cpp" ".exe" exename ${justname} ) + string( REPLACE ".cu" ".x" exename ${justname} ) set(exename "${exename}") message("Adding: ${exename}") add_executable(${exename} ${source_file}) target_link_libraries(${exename} /usr/local/cuda/lib64/libcudart.so) + + # The following is only necessary if cuda code is making calls to other + # kernel functions defined and compiled in different .cu files + # It should be unnecessary with the current organization + + #set_target_properties( PROPERTIES CUDA_SEPARABLE_COMPILATION ON) endforeach( source_file ${SOURCES} ) message("Leaving cuda_demo/CMakeLists.txt: ${SOURCES}") diff --git a/cuda_demo/cuda_relu.cu b/cuda_demo/cuda_relu.cu index 5c07101..72f713d 100644 --- a/cuda_demo/cuda_relu.cu +++ b/cuda_demo/cuda_relu.cu @@ -44,10 +44,16 @@ int main() small::ReLUActivation(num_channels, image_height, image_width, in, out); + std::cout << "Checking correctness:\n"; bool correct = true; for (size_t i = 0; i != num_elts; ++i) { correct &= (fabs(out[i] - check[i]) < 1e-15); + if (i < 20) + { + std::cout << i << ": ReLU(" << in[i] << ") = " + << out[i] << std::endl; + } } std::cout << (correct ? "PASSED" : "FAILED") << std::endl;