diff --git a/backends/tfhe-cuda-backend/cuda/CMakeLists.txt b/backends/tfhe-cuda-backend/cuda/CMakeLists.txt index ad452451ed..e36aeaee6d 100644 --- a/backends/tfhe-cuda-backend/cuda/CMakeLists.txt +++ b/backends/tfhe-cuda-backend/cuda/CMakeLists.txt @@ -67,9 +67,21 @@ endif() add_compile_definitions(CUDA_ARCH=${CUDA_ARCH}) +# Check if the DEBUG flag is defined +if(CMAKE_BUILD_TYPE STREQUAL "Debug") + # Debug mode + message("Compiling in Debug mode") + add_definitions(-DDEBUG) + set(OPTIMIZATION_FLAGS "${OPTIMIZATION_FLAGS} -O0 -G -g") +else() + # Release mode + message("Compiling in Release mode") + set(OPTIMIZATION_FLAGS "${OPTIMIZATION_FLAGS} -O3") +endif() + # in production, should use -arch=sm_70 --ptxas-options=-v to see register spills -lineinfo for better debugging set(CMAKE_CUDA_FLAGS - "${CMAKE_CUDA_FLAGS} -ccbin ${CMAKE_CXX_COMPILER} -O3 \ + "${CMAKE_CUDA_FLAGS} -ccbin ${CMAKE_CXX_COMPILER} ${OPTIMIZATION_FLAGS}\ -std=c++17 --no-exceptions --expt-relaxed-constexpr -rdc=true \ --use_fast_math -Xcompiler -fPIC") diff --git a/backends/tfhe-cuda-backend/cuda/include/device.h b/backends/tfhe-cuda-backend/cuda/include/device.h index 203db79b82..af026a9255 100644 --- a/backends/tfhe-cuda-backend/cuda/include/device.h +++ b/backends/tfhe-cuda-backend/cuda/include/device.h @@ -13,6 +13,8 @@ extern "C" { #define check_cuda_error(ans) \ { cuda_error((ans), __FILE__, __LINE__); } + +#ifdef DEBUG inline void cuda_error(cudaError_t code, const char *file, int line) { if (code != cudaSuccess) { std::fprintf(stderr, "Cuda error: %s %s %d\n", cudaGetErrorString(code), @@ -20,6 +22,9 @@ inline void cuda_error(cudaError_t code, const char *file, int line) { std::abort(); } } +#else +inline void cuda_error(cudaError_t code, const char *file, int line) {} +#endif #define PANIC(format, ...) \ { \ std::fprintf(stderr, "%s::%d::%s: panic.\n" format "\n", __FILE__, \