mitsuba-renderer / mitsuba2

Mitsuba 2: A Retargetable Forward and Inverse Renderer
Other
2.05k stars 267 forks source link

[❔ other question] PTX linker error on Windows10 #442

Open GCLemon opened 3 years ago

GCLemon commented 3 years ago

Summary

PTX link error while using mitsuba2 python interface.

System configuration

Description

I am trying to use mitsuba2 python interface with GPU variant. I have compiled the system in Anaconda Powershell using the following commands:

> cmake -G "Visual Studio 16 2019" -A x64 -T host=x64 -DCMAKE_CUDA_COMPILER="path/to/nvcc" -DMTS_OPTIX_PATH="path/to/optix" ..
> cmake --build . --config RELEASE

Then I executed setpath.ps1, imported mitsuba in python, and attempted to render a scene. While the rendering using the variant gpu_spectral, it caused PTX link error:

2021-05-28 12:19:21 INFO  main  [optix_api.cpp:56] Dynamic loading of the Optix library ..
2021-05-28 12:19:21 INFO  main  [PluginManager] Loading plugin "plugins\path.dll" ..
2021-05-28 12:19:21 INFO  main  [PluginManager] Loading plugin "plugins\perspective.dll" ..
2021-05-28 12:19:21 INFO  main  [PluginManager] Loading plugin "plugins\ldsampler.dll" ..
2021-05-28 12:19:21 WARN  main  [LowDiscrepancySampler] Sample count should be square and power of two, rounding to 1024
2021-05-28 12:19:21 INFO  main  [PluginManager] Loading plugin "plugins\hdrfilm.dll" ..
2021-05-28 12:19:21 INFO  main  [PluginManager] Loading plugin "plugins\gaussian.dll" ..
PTX linker error:
ptxas fatal   : SM version specified by .target is higher than default SM version assumed

Using XML file and mitsuba command caused the same error.

Any responses will be appreciated.

Speierers commented 3 years ago

Hi @GCLemon ,

It could be that your GPU is too old and therefore not supported in this framework? According to this website, the Quadro 2000 is built on the Fermi architecture, which only supports sm_20.

GCLemon commented 3 years ago

Thanks for your advice. I have just changed my GPU to GeForce GTX 980, which is newer than Quadro 2000, but it caused another runtime error:

2021-05-29 15:08:36 INFO  main  [optix_api.cpp:56] Dynamic loading of the Optix library ..
2021-05-29 15:08:36 INFO  main  [PluginManager] Loading plugin "plugins\path.dll" ..
2021-05-29 15:08:36 INFO  main  [PluginManager] Loading plugin "plugins\perspective.dll" ..
2021-05-29 15:08:36 INFO  main  [PluginManager] Loading plugin "plugins\ldsampler.dll" ..
2021-05-29 15:08:36 WARN  main  [LowDiscrepancySampler] Sample count should be square and power of two, rounding to 1024
2021-05-29 15:08:36 INFO  main  [PluginManager] Loading plugin "plugins\hdrfilm.dll" ..
2021-05-29 15:08:36 INFO  main  [PluginManager] Loading plugin "plugins\gaussian.dll" ..
2021-05-29 15:08:36 INFO  main  [PluginManager] Loading plugin "plugins\envmap.dll" ..
2021-05-29 15:08:37 INFO  main  [srgb.cpp:22] Loading spectral upsampling model "data/srgb.coeff" ..
2021-05-29 15:08:38 INFO  main  [PluginManager] Loading plugin "plugins\d65.dll" ..
2021-05-29 15:08:38 INFO  main  [PluginManager] Loading plugin "plugins\regular.dll" ..
2021-05-29 15:08:38 INFO  main  [PluginManager] Loading plugin "plugins\obj.dll" ..
2021-05-29 15:08:38 INFO  main  [PluginManager] Loading plugin "plugins\roughplastic.dll" ..
2021-05-29 15:08:38 INFO  main  [PluginManager] Loading plugin "plugins\uniform.dll" ..
2021-05-29 15:08:38 INFO  main  [Scene] Building scene in OptiX ..
rt_check(): OptiX API error = 7200 (Invalid PTX input) in C:\[path_to_mitsuba]\src\librender\scene_optix.inl:109.
        Log:
Speierers commented 3 years ago

Is this really the whole log? The bottom part seems to be missing.

GCLemon commented 3 years ago

Actually, I didn't get anything else but that......

Speierers commented 3 years ago

Could you please compile in debug mode and try again? You should get a more verbose log that will be very helpful for debugging this.

GCLemon commented 3 years ago

This is a whole log in DEBUG mode. Since mitsuba2 supports CUDA10.x and OptiX 7, my GPU might be still old or something else?

2021-05-31 17:40:30 INFO  main  [optix_api.cpp:56] Dynamic loading of the Optix library ..
2021-05-31 17:40:30 INFO  main  [PluginManager] Loading plugin "plugins\path.dll" ..
2021-05-31 17:40:30 INFO  main  [PluginManager] Loading plugin "plugins\perspective.dll" ..
2021-05-31 17:40:30 INFO  main  [PluginManager] Loading plugin "plugins\ldsampler.dll" ..
2021-05-31 17:40:30 WARN  main  [LowDiscrepancySampler] Sample count should be square and power of two, rounding to 1024
2021-05-31 17:40:30 INFO  main  [PluginManager] Loading plugin "plugins\hdrfilm.dll" ..
2021-05-31 17:40:30 INFO  main  [PluginManager] Loading plugin "plugins\gaussian.dll" ..
cuda_eval(): launching kernel (n=1, in=0, out=1, ops=11)
cuda_eval(): launching kernel (n=1, in=0, out=1, ops=11)
cuda_eval(): launching kernel (n=1, in=0, out=1, ops=11)
cuda_eval(): launching kernel (n=1, in=0, out=1, ops=11)
cuda_eval(): launching kernel (n=1, in=0, out=1, ops=11)
cuda_eval(): launching kernel (n=1, in=0, out=1, ops=11)
cuda_eval(): launching kernel (n=1, in=0, out=1, ops=11)
cuda_eval(): launching kernel (n=1, in=0, out=1, ops=11)
cuda_eval(): launching kernel (n=1, in=0, out=1, ops=11)
cuda_eval(): launching kernel (n=1, in=0, out=1, ops=11)
cuda_eval(): launching kernel (n=1, in=0, out=1, ops=11)
cuda_eval(): launching kernel (n=1, in=0, out=1, ops=11)
cuda_eval(): launching kernel (n=1, in=0, out=1, ops=11)
cuda_eval(): launching kernel (n=1, in=0, out=1, ops=11)
cuda_eval(): launching kernel (n=1, in=0, out=1, ops=11)
cuda_eval(): launching kernel (n=1, in=0, out=1, ops=11)
cuda_eval(): launching kernel (n=1, in=0, out=1, ops=11)
cuda_eval(): launching kernel (n=1, in=0, out=1, ops=11)
cuda_eval(): launching kernel (n=1, in=0, out=1, ops=11)
cuda_eval(): launching kernel (n=1, in=0, out=1, ops=11)
cuda_eval(): launching kernel (n=1, in=0, out=1, ops=11)
cuda_eval(): launching kernel (n=1, in=0, out=1, ops=11)
cuda_eval(): launching kernel (n=1, in=0, out=1, ops=11)
cuda_eval(): launching kernel (n=1, in=0, out=1, ops=11)
cuda_eval(): launching kernel (n=1, in=0, out=1, ops=11)
cuda_eval(): launching kernel (n=1, in=0, out=1, ops=11)
cuda_eval(): launching kernel (n=1, in=0, out=1, ops=11)
cuda_eval(): launching kernel (n=1, in=0, out=1, ops=11)
cuda_eval(): launching kernel (n=1, in=0, out=1, ops=11)
cuda_eval(): launching kernel (n=1, in=0, out=1, ops=11)
cuda_eval(): launching kernel (n=1, in=0, out=1, ops=11)
2021-05-31 17:40:30 INFO  main  [PluginManager] Loading plugin "plugins\envmap.dll" ..
2021-05-31 17:40:30 DEBUG main  [Bitmap] Loading OpenEXR file "C:\............\ilum001.exr" (3200x1600, rgb, float16) ..
2021-05-31 17:40:31 INFO  main  [srgb.cpp:22] Loading spectral upsampling model "data/srgb.coeff" ..
2021-05-31 17:40:36 INFO  main  [PluginManager] Loading plugin "plugins\d65.dll" ..
2021-05-31 17:40:36 INFO  main  [PluginManager] Loading plugin "plugins\regular.dll" ..
2021-05-31 17:40:36 INFO  main  [PluginManager] Loading plugin "plugins\obj.dll" ..
2021-05-31 17:40:36 INFO  main  [PluginManager] Loading plugin "plugins\roughplastic.dll" ..
2021-05-31 17:40:36 INFO  main  [PluginManager] Loading plugin "plugins\uniform.dll" ..
cuda_eval(): launching kernel (n=1, in=0, out=3, ops=4)
cuda_eval(): launching kernel (n=1, in=1, out=1, ops=2)
2021-05-31 17:40:46 DEBUG main  [OBJMesh] Loading mesh from "sphere002.obj" ..
2021-05-31 17:40:46 DEBUG main  [OBJMesh] "sphere002.obj": read 45000 faces, 22801 vertices (1.21 MiB in 462ms)
2021-05-31 17:40:46 INFO  main  [Scene] Building scene in OptiX ..
[ 2][COMPILE FEEDBACK]: COMPILE ERROR: Malformed PTX input. See compile details for more information.
Error: Invalid target architecture. Maximum feasible for current context: sm_52, found: sm_61

rt_check(): OptiX API error = 7200 (Invalid PTX input) in C:\............\mitsuba\src\librender\scene_optix.inl:109.
        Log: cuda_shutdown()
cuda_shutdown(): variable 399 is still live.
cuda_shutdown(): variable 393 is still live.
cuda_shutdown(): variable 388 is still live.
cuda_shutdown(): variable 387 is still live.
cuda_shutdown(): variable 382 is still live.
cuda_shutdown(): variable 397 is still live.
cuda_shutdown(): variable 407 is still live.
cuda_shutdown(): variable 386 is still live.
cuda_shutdown(): variable 383 is still live.
cuda_shutdown(): variable 384 is still live.
(skipping remainder)
cuda_shutdown(): 25 variables were still live at shutdown.
TBB Warning: Leaked 1 observer_proxy objects
Speierers commented 3 years ago

One thing you could try is to replace compute_61 by compute_51 in resources/ptx/MakeFile and run make in that folder to re-generate the mitsuba main PTX kernels. After this you will need to re-compile Mitsuba 2.

Let me know if this fixes your issue.

GCLemon commented 3 years ago

I have installed make command for Windows and modified Makefile as following to make it works on Windows:

mts_include_folder = ..\..\include
mts_shape_folder   = ..\..\src\shapes\optix
mts_optix_main     = ..\..\src\librender\optix\optix_rt.cu

all: optix_rt.ptx

optix_rt.ptx: $(mts_optix_main) 
    nvcc $(mts_optix_main) \
         -I $(mts_include_folder) -I $(mts_shape_folder) -I \opt\optix-7.0.0\include\ \
         -O3 -gencode arch=compute_51,code=compute_51 --ptx

clean:
    rm -f optix_rt.ptx

Then I ran make command in the folder which contains Makefile, to find my CUDA compiler seemed not to support compute_51.

nvcc ..\..\src\librender\optix\optix_rt.cu \
                 -I ..\..\include -I ..\..\src\shapes\optix -I \opt\optix-7.0.0\include\ \
                 -O3 -gencode arch=compute_51,code=compute_51 --ptx
nvcc fatal   : Unsupported gpu architecture 'compute_51'
make: *** [optix_rt.ptx] Error 1

Next I restored compute_51 to compute_61 and ran make again, but it caused another error:

nvcc ..\..\src\librender\optix\optix_rt.cu \
                 -I ..\..\include -I ..\..\src\shapes\optix -I \opt\optix-7.0.0\include\ \
                 -O3 -gencode arch=compute_61,code=compute_61 --ptx
optix_rt.cu
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.2\bin/../include\cuda_runtime.h(1): warning C4819: The file contains a character that cannot be represented in the current code page (932). Save the file in Unicode format to prevent data loss.
............
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.2\include\cuda_runtime_api.h(9349): warning C4819: The file contains a character that cannot be represented in the current code page (932). Save the file in Unicode format to prevent data loss.
../../include\mitsuba/render/optix/ray.cuh(4): fatal error C1083: Cannot open include file: 'optix.h': No such file or directory
make: *** [optix_rt.ptx] Error 2

Since I thought that \opt\optix-7.0.0\include\ should be the path to OptiX SDK, I replaced it to C:\ProgramData\NVIDIA Corporation\OptiX SDK 7.3.0\include, but it still caused some errors:

nvcc ..\..\src\librender\optix\optix_rt.cu \
                 -I ..\..\include -I ..\..\src\shapes\optix -I "C:\ProgramData\NVIDIA Corporation\OptiX SDK 7.3.0\include" \
                 -O3 -gencode arch=compute_61,code=compute_61 --ptx
optix_rt.cu
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.2\bin/../include\cuda_runtime.h(1): warning C4819: The file contains a character that cannot be represented in the current code page (932). Save the file in Unicode format to prevent data loss.
............
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.2\include\cuda_runtime_api.h(9349): warning C4819: The file contains a character that cannot be represented in the current code page (932). Save the file in Unicode format to prevent data loss.
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\cmath(259): error: calling a __host__ function("__copysignf") from a __device__ function("solve_quadratic") is not allowed

C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\cmath(259): error: identifier "__copysignf" is undefined in device code

2 errors detected in the compilation of "C:/Users/yamamoto/AppData/Local/Temp/tmpxft_00003b90_00000000-10_optix_rt.cpp1.ii".
make: *** [optix_rt.ptx] Error 1
Speierers commented 3 years ago

In a seperate folder could you maybe try to use nvcc to compile a dummy CUDA kernel (without optix) and check what is the highest compute_XX supported by your system?

GCLemon commented 3 years ago

I found that compute_62 is the highest, and compute_52 is the lowest additionally.

Speierers commented 3 years ago

How could you get this error then?

Error: Invalid target architecture. Maximum feasible for current context: sm_52, found: sm_61
GCLemon commented 3 years ago

I succeeded to compile empty CUDA compiler with -gencode option compute_52,code=compute_52, compute_61,code=compute_61, and compute_62,code=compute_62, and I did not understand why this error happened......

Since I failed to regenerate optix_rt.ptx, it is possible that current mitsuba, which uses optix_rt.ptx before regenerating, supports sm_61 or later.