Skip to content

Commit

Permalink
Cleaning up cmake for CUDA. Fixing the executable extension of cuda p…
Browse files Browse the repository at this point in the history
…rograms (now '.x')
  • Loading branch information
sei-smcmillan committed Aug 21, 2023
1 parent bf49ca5 commit 06bcae6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
10 changes: 3 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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(<target_name> 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)
Expand Down
8 changes: 7 additions & 1 deletion cuda_demo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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(<target_name> PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
endforeach( source_file ${SOURCES} )

message("Leaving cuda_demo/CMakeLists.txt: ${SOURCES}")
6 changes: 6 additions & 0 deletions cuda_demo/cuda_relu.cu
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 06bcae6

Please sign in to comment.