# Loading a torchscript model in C++: Cannot initialize CUDA without ATen\_cuda library

**URL:** <https://discuss.pytorch.org/t/loading-a-torchscript-model-in-c-cannot-initialize-cuda-without-aten-cuda-library/57651>\
**Category:** C++\
**Created:** [October 7, 2019, 7:45pm UTC](https://discuss.pytorch.org/t/loading-a-torchscript-model-in-c-cannot-initialize-cuda-without-aten-cuda-library/57651 "2019-10-07T19:45:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![spiovesan](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/s/b5ac83/32.png) [@spiovesan](https://discuss.pytorch.org/u/spiovesan)\
**Post date:** [October 7, 2019, 7:45pm UTC](https://discuss.pytorch.org/t/loading-a-torchscript-model-in-c-cannot-initialize-cuda-without-aten-cuda-library/57651/1 "2019-10-07T19:45:05Z")

</div>

I have built a CNN with Pytorch with GPU support. It works fine in python and I would like to import it in my C++ application using VS2017. I am following these instructions [here](https://pytorch.org/tutorials/advanced/cpp_export.html) and [here](https://medium.com/@boonboontongbuasirilai/building-pytorch-c-integration-libtorch-with-ms-visual-studio-2017-44281f9921ea).  
I can build and run the application, but I get this error when loading the model:

```auto

```

error loading the model  
Cannot initialize CUDA without ATen\_cuda library. PyTorch splits its backend into two shared  
libraries: a CPU library and a CUDA library; this error has occurred because you are trying to use  
some CUDA functionality, but the CUDA library has not been loaded by the dynamic linker for some  
reason. The CUDA library MUST be loaded, EVEN IF you don’t directly use any symbols from the CUDA  
library! One common culprit is a lack of -Wl,–no-as-needed in your link arguments; many dynamic  
linkers will delete dynamic library dependencies if you don’t depend on any of their symbols. You  
can check if this has occurred by using ldd on your binary to see if there is a dependency on  
\*\_cuda.so library. (initCUDA at  
C:\w\1\s\windows\pytorch\aten\src\ATen/detail/CUDAHooksInterface.h:63)  
(no backtrace available)

```auto

```

How can I fix with VS2017 and CUDA 10?

---

<div class="post-metadata">

**Author:** ![tom](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/tom/32/3162_2.png) [@tom](https://discuss.pytorch.org/u/tom)\
**Post date:** [October 10, 2019, 6:52am UTC](https://discuss.pytorch.org/t/loading-a-torchscript-model-in-c-cannot-initialize-cuda-without-aten-cuda-library/57651/2 "2019-10-10T06:52:38Z")

</div>

But you did get a cuda-enabled libtorch?  
You could try calling `cuda_lazy_init` before if you did.

Best regards

Thomas

---

<div class="post-metadata">

**Author:** ![spiovesan](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/s/b5ac83/32.png) [@spiovesan](https://discuss.pytorch.org/u/spiovesan)\
**Post date:** [October 10, 2019, 7:45am UTC](https://discuss.pytorch.org/t/loading-a-torchscript-model-in-c-cannot-initialize-cuda-without-aten-cuda-library/57651/3 "2019-10-10T07:45:00Z")

</div>

I solved using the nightly [build](https://download.pytorch.org/libtorch/nightly/cu100/libtorch-win-shared-with-deps-latest.zip), that ships `libtorch` with all the needed `cuda` dlls and the correct conda python 3.7 pytorch 1.3 (the conda installer for [Windows](http://conda%20install%20pytorch%20torchvision%20cudatoolkit%3D10.0%20-c%20pytorch/) does not install the latest `pytorch stable 1.2` but an older `1.0.1`) .

---

<div class="post-metadata">

**Author:** ![tom](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/tom/32/3162_2.png) [@tom](https://discuss.pytorch.org/u/tom)\
**Post date:** [October 10, 2019, 11:35am UTC](https://discuss.pytorch.org/t/loading-a-torchscript-model-in-c-cannot-initialize-cuda-without-aten-cuda-library/57651/4 "2019-10-10T11:35:37Z")

</div>

Supergood, thank you for reporting back!

Best regards

Thomas
