diff --git a/CMakeLists.txt b/CMakeLists.txt index aad085d..725fe10 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.26) +cmake_minimum_required(VERSION 3.22) project(SimLOD) include(FetchContent) @@ -19,7 +19,19 @@ set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT $ set_target_properties(${PROJECT_NAME} PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "$" VS_DEBUGGER_COMMAND "$" VS_DEBUGGER_ENVIRONMENT "PATH=%PATH%;${CMAKE_PREFIX_PATH}") - +# Build options based on CMAKE_BUILD_TYPE +function(configure_build_type) + if (CMAKE_BUILD_TYPE STREQUAL "Debug") + target_compile_options(${PROJECT_NAME} PRIVATE -O0 -g) + elseif (CMAKE_BUILD_TYPE STREQUAL "Release") + target_compile_options(${PROJECT_NAME} PRIVATE -O3) + else() + message(WARNING "No CMAKE_BUILD_TYPE specified, defaulting to Release settings.") + set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Default build type: Release" FORCE) + target_compile_options(${PROJECT_NAME} PRIVATE -O3) + endif () +endfunction() +configure_build_type() target_include_directories(${PROJECT_NAME} PRIVATE include @@ -29,14 +41,13 @@ target_include_directories(${PROJECT_NAME} PRIVATE # Dependencies ## CUDA toolkit -find_package(CUDAToolkit 11.7 REQUIRED) +find_package(CUDAToolkit 11.8 REQUIRED) target_include_directories(${PROJECT_NAME} PRIVATE CUDAToolkit_INCLUDE_DIRS) + target_link_libraries(${PROJECT_NAME} CUDA::cuda_driver - CUDA::nvrtc - CUDA::nvrtc_static - CUDA::nvrtc_builtins_static) + CUDA::nvrtc) ## OpenGL find_package(OpenGL REQUIRED) diff --git a/include/CudaModularProgram.h b/include/CudaModularProgram.h index 59a8bb1..2217db9 100644 --- a/include/CudaModularProgram.h +++ b/include/CudaModularProgram.h @@ -43,18 +43,32 @@ struct CudaModule{ // cout << "================================================================================" << endl; printfmt("compiling {} ", fs::path(path).filename().string()); - success = false; - - string dir = fs::path(path).parent_path().string(); - string optInclude = "-I " + dir; + const char* cuda_path_cstr = std::getenv("CUDA_PATH"); + std::string cuda_path; + if (cuda_path_cstr) { + cuda_path = std::string(cuda_path_cstr); + if (!cuda_path.empty()) { + std::cout << "\nCUDA_PATH is set to: " << cuda_path << std::endl; + } else { + std::cout << "\nCUDA_PATH is empty. Please set it." << std::endl; + exit(-1); + } + } else { + std::cout << "\nCUDA_PATH is not set. Please set it." << std::endl; + exit(-1); + } - string cuda_path = std::getenv("CUDA_PATH"); - string cuda_include = "-I " + cuda_path + "/include"; + const string cuda_include = "-I " + cuda_path + "/include"; + const string dir = fs::path(path).parent_path().string(); + const string optInclude = "-I " + dir; nvrtcProgram prog; string source = readFile(path); nvrtcCreateProgram(&prog, source.c_str(), name.c_str(), 0, NULL, NULL); - std::vector opts = { + + success = false; + + std::vector opts = { // "--gpu-architecture=compute_75", "--gpu-architecture=compute_86", "--use_fast_math",