NVIDIA / VisRTX

NVIDIA OptiX based implementation of ANARI

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Windows: error: identifier "M_PI" is undefined

oroppas opened this issue · comments

Hi,

Building on Windows failed with VisRTX\device\gpu/gpu_util.h(134): error: identifier "M_PI" is undefined
I believe the issue is related to https://stackoverflow.com/questions/56319494/nvcc-compilation-errors-with-m-pi-and-or

The following is the detailed log:

[6/62] Building CUDA object device\CMakeFiles\Debug_ptx_gen.dir\renderer\Debug_ptx.ptx
FAILED: device/CMakeFiles/Debug_ptx_gen.dir/renderer/Debug_ptx.ptx
C:\PROGRA~1\NVIDIA~2\CUDA\v11.6\bin\nvcc.exe -forward-unknown-to-host-compiler  -ID:\packages\visrtx\VisRTX\device -isystem=D:\local\include -isystem=D:\packages\visrtx\VisRTX\external\glm\include -isystem="C:\ProgramData\NVIDIA Corporation\OptiX SDK 7.5.0\include" -isystem="C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.6\include" -D_WINDOWS -Xcompiler=" /GR /EHsc" -Xcompiler="-Zi -Ob0 -Od /RTC1" -Xcompiler=-MDd -std=c++17 -MD -MT device\CMakeFiles\Debug_ptx_gen.dir\renderer\Debug_ptx.ptx -MF device\CMakeFiles\Debug_ptx_gen.dir\renderer\Debug_ptx.ptx.d -x cu -ptx D:\packages\visrtx\VisRTX\device\renderer\Debug_ptx.cu -o device\CMakeFiles\Debug_ptx_gen.dir\renderer\Debug_ptx.ptx -Xcompiler=-Fddevice\CMakeFiles\Debug_ptx_gen.dir\,-FS

[lots of warnings]

D:\packages\visrtx\VisRTX\device\gpu/gpu_util.h(134): error: identifier "M_PI" is undefined

D:\packages\visrtx\VisRTX\external\glm\include\glm\ext\scalar_constants.inl(9): warning #20013-D: calling a constexpr __host__ function("epsilon") from a __host__ __device__ function("epsilon") is not allowed. The experimental flag '--expt-relaxed-constexpr' can be used to allow this.
          detected during instantiation of "genType glm::epsilon<genType>() [with genType=float]"
D:\packages\visrtx\VisRTX\external\glm\include\glm\ext\scalar_ulp.inl(81): here

D:\packages\visrtx\VisRTX\external\glm\include\glm\ext\scalar_constants.inl(9): warning #20013-D: calling a constexpr __host__ function("epsilon") from a __host__ __device__ function("epsilon") is not allowed. The experimental flag '--expt-relaxed-constexpr' can be used to allow this.
          detected during instantiation of "genType glm::epsilon<genType>() [with genType=double]"
D:\packages\visrtx\VisRTX\external\glm\include\glm\ext\scalar_ulp.inl(136): here

1 error detected in the compilation of "D:/packages/visrtx/VisRTX/device/renderer/Debug_ptx.cu".

The simple reproducer is

#include <iostream>
#include <cmath>

int main() {
  std::cout << M_PI << std::endl;
}

This issue is Windows-specific. A possible workaround is to add -D_USE_MATH_DEFINES to CMAKE_CUDA_FLAGS or
define _USE_MATH_DEFINES in gpu/gpu_math.h before glm/glm.hpp which includes cmath.

diff --git a/device/gpu/gpu_math.h b/device/gpu/gpu_math.h
index 7dba5b2..4aa6326 100644
--- a/device/gpu/gpu_math.h
+++ b/device/gpu/gpu_math.h
@@ -33,6 +33,10 @@

 #include "gpu/gpu_decl.h"

+#if defined(_WIN32) || defined(_WIN64)
+#define _USE_MATH_DEFINES
+#endif
+
 #include <glm/ext.hpp>
 #include <glm/glm.hpp>
 #include <glm/gtx/component_wise.hpp>

Similar fix to #30 will be implemented soon, thanks for the report!

Enabling VISRTX_BUILD_INTERACTIVE_EXAMPLE gives me

[1/3] Building CXX object examples\viewer\CMakeFiles\viewer.dir\Orbit.cpp.obj
FAILED: examples/viewer/CMakeFiles/viewer.dir/Orbit.cpp.obj
C:\PROGRA~1\MIB055~1\2022\COMMUN~1\VC\Tools\MSVC\1431~1.311\bin\Hostx64\x64\cl.exe  /nologo /TP  -ID:\packages\visrtx\build\match3D_src\src\match3D\include -ID:\packages\visrtx\build\match3D_imgui -ID:\packages\visrtx\build\match3D_imgui\backends -ID:\packages\visrtx\build\match3D_imgui\misc\cpp -ID:\packages\visrtx\build\match3D_src\src\stb_image -ID:\packages\visrtx\windows_fixes\external\tiny_obj_loader -external:I D:\packages\glfw\include -external:I D:\local\include -external:I D:\packages\visrtx\windows_fixes\external\glm\include -external:I "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.6\include" -external:W0 /DWIN32 /D_WINDOWS /GR /EHsc /Zi /Ob0 /Od /RTC1 -MDd -std:c++17 /showIncludes /Foexamples\viewer\CMakeFiles\viewer.dir\Orbit.cpp.obj /Fdexamples\viewer\CMakeFiles\viewer.dir\ /FS -c D:\packages\visrtx\windows_fixes\examples\viewer\Orbit.cpp
D:\packages\visrtx\windows_fixes\examples\viewer\Orbit.cpp(38): error C2065: 'M_PI': undeclared identifier
[2/3] Building CXX object examples\viewer\CMakeFiles\viewer.dir\Scene.cpp.obj

This can be fixed as

diff --git a/examples/viewer/CMakeLists.txt b/examples/viewer/CMakeLists.txt
index f852e25..a39b4da 100644
--- a/examples/viewer/CMakeLists.txt
+++ b/examples/viewer/CMakeLists.txt
@@ -74,3 +74,6 @@ target_link_libraries(${PROJECT_NAME} PRIVATE
   CUDA::cudart
   tiny_obj_loader
 )
+if(WIN32)
+  target_compile_definitions(${PROJECT_NAME} PRIVATE _USE_MATH_DEFINES NOMINMAX)
+endif()

Fixed in jda/windows_fixes branch.