From 7b564927d67775e25da96eee5c2354c0ed434677 Mon Sep 17 00:00:00 2001 From: Davis King Date: Sat, 1 Aug 2020 13:48:30 -0400 Subject: [PATCH] Switching to what is hopefully a better fix for the following CUDA error error: calling a constexpr host function("log1p") from a device function("cuda_log1pexp") is not allowed. The experimental flag '--expt-relaxed-constexpr' can be used to allow this. The error only happens with some versions of CUDA. --- dlib/CMakeLists.txt | 8 -------- dlib/cuda/cuda_dlib.cu | 4 ++-- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/dlib/CMakeLists.txt b/dlib/CMakeLists.txt index 0da187531..38ff302e8 100644 --- a/dlib/CMakeLists.txt +++ b/dlib/CMakeLists.txt @@ -633,14 +633,6 @@ if (NOT TARGET dlib) endif() endif() - if (CUDA_VERSION VERSION_LESS 10.3) - # To avoid this error from nvcc: - # error: calling a constexpr __host__ function("log1p") from a __device__ function("cuda_log1pexp") - # is not allowed. The experimental flag '--expt-relaxed-constexpr' can be used to allow this. - # which is a bug in nvcc in this version of cuda. - list(APPEND FLAGS_FOR_NVCC "--expt-relaxed-constexpr") - endif() - set(CUDA_HOST_COMPILATION_CPP ON) # Note that we add __STRICT_ANSI__ to avoid freaking out nvcc with gcc specific # magic in the standard C++ header files (since nvcc uses gcc headers on diff --git a/dlib/cuda/cuda_dlib.cu b/dlib/cuda/cuda_dlib.cu index b4a34024f..9d0a6cf24 100644 --- a/dlib/cuda/cuda_dlib.cu +++ b/dlib/cuda/cuda_dlib.cu @@ -1759,9 +1759,9 @@ namespace dlib if (x <= -18) return std::exp(x); else if (-18 < x && x <= 9) - return std::log1p(std::exp(x)); + return std::log1pf(std::exp(x)); else if (9 < x && x <= 16) - return x + std::exp(-x); + return x + expf(-x); else return x; }