NVlabs / nvdiffrast

Nvdiffrast - Modular Primitives for High-Performance Differentiable Rendering
Other
1.31k stars 139 forks source link

Question abount build in cpp #63

Closed Mirocos closed 2 years ago

Mirocos commented 2 years ago

Hi, I am trying to implement this powerful framework in c++ style. And when I build project with nvdiffrast, cpp link error says that it can not open file setgpu.lib provided in this project. Why this happened? and is there any way to solve this if possible?

I am using Visual Studio 2019 professional with CMake to build my project.

Mirocos commented 2 years ago

Can use those code to set gpu device? I guess.

// int res = set_gpu(pciBusId);
int device_id;
int res = cudaDeviceGetByPCIBusId(&device_id, pciBusId);
if(res) cudaSetDevice(device_id);
s-laine commented 2 years ago

The function provided by setgpu.lib attempts to select the device for OpenGL operations, whereas cudaSetDevice() affects Cuda only. Unless you have a multi-GPU setup on Windows, you can safely remove the call if you have linking problems.

Mirocos commented 2 years ago

Did you mean that the setgpu function provided by setgpu.lib tries to find another GPU for OpenGL opeartions so that some cuda operations can be seperated from OpenGL operations?

But what if I have a multi-GPU setup on Windows? Does there have any ways or suggestions?

s-laine commented 2 years ago

No, the goal is to run the OpenGL operations on the same GPU as the corresponding Cuda operations. To supports multi-GPU setups, I suggest you configure the linker so that it finds the relevant library.

Mirocos commented 2 years ago

Thanks a lot, Now I finally can linking the setgpu.lib in my cpp project. Though in cpp project, the example cube runs slower than python abount 21s while 4s in python.

Mirocos commented 2 years ago

Hello, when I implement the example earth.py in libtorch style. I found the gradients passed by torch in backward texture_func are different between pytorch and libtorch. In libtorch it'ss a nagetive but in pytorch it's a positive.

I compared the all input value between this two implementations. But cannot find out why libtorch return a nagetive gradient in autograd backward pass.

Here is the detial description url: description in pytorch

If you have any idea of this, please enlighten me.

Mirocos commented 2 years ago

Hi,again, I saw some wired log like this Selecting device with PCI bus id 0000:2B:00.0 - failed, expect crash or major slowdown which was printed after calling setgpu(...) function. Why this happen and any way to correct it ?

s-laine commented 2 years ago

It means that the GPU selection did not work as expected, and the OpenGL operations may still run on a different GPU than intended. I don't know why this happens in your project. I also don't think this is the proper forum for troubleshooting issues in derivative projects.