Skip to content
This repository has been archived by the owner on Jan 3, 2023. It is now read-only.

Dynamic load of nvidia libs #765

Closed
WilliamTambellini opened this issue Mar 27, 2018 · 9 comments
Closed

Dynamic load of nvidia libs #765

WilliamTambellini opened this issue Mar 27, 2018 · 9 comments
Labels
External Contribution from outside the ngraph team

Comments

@WilliamTambellini
Copy link

WilliamTambellini commented Mar 27, 2018

Hi all
As today, if ngraph is compiled with NGRAPH_GPU_ENABLE=TRUE (which ofcourse needs a nvidia ecosystem installed) then libngraph.so is hardly linked with few nvidia libs:
`ldd /tmp/ngraph/lib/libngraph.so

libcuda.so.1 => /usr/lib/x86_64-linux-gnu/libcuda.so.1
libnvrtc.so.8.0 => /usr/local/cuda-8.0/targets/x86_64-linux/lib/libnvrtc.so.8.0
libcublas.so.8.0 => /usr/local/cuda-8.0/targets/x86_64-linux/lib/libcublas.so.8.0
libcudnn.so.7 => /usr/local/cuda-8.0/targets/x86_64-linux/lib/libcudnn.so.7
libnvidia-fatbinaryloader.so.375.74 => /usr/lib/nvidia-375/libnvidia-fatbinaryloader.so.375.74
...
`

For production & deployment purpose, this is not practical because such a libngraph build wont be able to be loaded at all on machines without the nvidia gpu ecosystem, ie cpu only.

Thanks to the fact that the ngraph arch is pretty clean, this is only needed for some C function calls needed in the gpu backend only (ngraph/src/ngraph/runtime/gpu) : cublasCreate, cudnnCreate, cublasSetPointerMode, cublasDestroy, cuInit, cuDeviceGet, cuCtxCreate, nvrtcCreateProgram, nvrtcCompileProgram, nvrtcGetPTXSize, nvrtcGetPTX, nvrtcDestroyProgram, cuLaunchKernel, ...

It could be possible to dynamically load these libs using standard posix 'dl' :
http://man7.org/linux/man-pages/man3/dlopen.3.html

The PyTorch team seems to also try to do such :
pytorch/pytorch#3395

Before moving forward, would you be open to this idea or do you see any red flags ?

Kind
W.

@diyessi
Copy link
Contributor

diyessi commented Mar 28, 2018

Thankyou for your suggestion. We think we will do something like this when our GPU support is further along.

At this time we do not yet have a contributor license agreement (CLA) procedure in place. Until that is resolved, we won't be able to accept outside contributions.

@WilliamTambellini
Copy link
Author

WilliamTambellini commented Mar 29, 2018

Thank you, you are welcome.
FYI, it seems that the CUEW library has implemented the dynamic loading wrapping of most of the nvidia API (nvrtc, cuda, ...) :
https://github.com/CudaWrangler/cuew

@WilliamTambellini
Copy link
Author

WilliamTambellini commented Apr 26, 2018

Hi @diyessi
I have seen a minimalist POC on devtalk :
main.cpp.txt
Could you tell at least if you would prefer :

  • an implementation using CudaWrangler (cuew)
  • an implementation not using any new external libraries

Kind

@diyessi
Copy link
Contributor

diyessi commented Apr 26, 2018

External libraries need to go through an approval process that looks into licensing, IP, security, etc.
We will need to do the dynamic loading before we can do binary releases.
@csullivan can you give an update on dynamic loading?

@WilliamTambellini
Copy link
Author

WilliamTambellini commented Apr 27, 2018

If I may emit 2 warnings/advices :

  • cuew does not wrap cudnn (yet ?) but does provide a mature cross platform dynamic loading framework (Linux, Mac and even Windows)
  • most cudaXxx from cudart (cuda runtime) should not need to be wrapped IF linking ngraph with cudart static (${CUDA_cudart_static_LIBRARY}, usually used if CUDA_USE_STATIC_CUDA_RUNTIME=ON)

@csullivan
Copy link

csullivan commented Apr 30, 2018

Thanks @WilliamTambellini. As you suggest, we'd like to dynamically load nvrtc, cuda, cublas, and cudnn all in one go. CUEW's cross-platform support is attractive and may be a good starting point if cudnn can be added in a straightforward way. Per your original question, we are still awaiting information on contributors licensing but hope to have that good to go soon. If you want to take a stab at it in the mean time, I'm more than happy to review / merge once we have our contributors license up. Otherwise, it's on our roadmap and I will provide updates here when this is underway internally.

@WilliamTambellini
Copy link
Author

WilliamTambellini commented May 5, 2018

Thank you @csullivan : I see enough reasons to wait a little :

To be continued.

@WilliamTambellini
Copy link
Author

Early result from the cudnn support in cuew :
https://github.com/Nazg-Gul/cuew/blob/cudnn_experiment/include/cuew.h
this header is generated so all the cudnn api should be in it.
@csullivan @diyessi : could you check if at least you see all the api ngraph needs ?

@csullivan
Copy link

@WilliamTambellini the update looks promising, I'll give it a review, thanks

@rkimballn1 rkimballn1 added the External Contribution from outside the ngraph team label Oct 6, 2018
@diyessi diyessi closed this as completed Oct 6, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
External Contribution from outside the ngraph team
Projects
None yet
Development

No branches or pull requests

4 participants