No libtorch_cuda_cpp.so available when build pytorch from source

Donglin: <p>Dear community,</p>
<p>I build pytorch from the source following instructions from <a href="https://github.com/pytorch/pytorch#from-source" rel="noopener nofollow ugc">github webpage</a> using latest pytorch (commit 7c20ad3dfae18c5e262c59e09c2b6079ec7fc69f).  The build was successful and pytorch python API is able to detect CUDA devices.</p>
<p>However, thereis no libtorch_cuda_cpp.so available under …lib/python3.8/site-packages/torch/lib/ which should exists if install pytorch from pip or conda.</p>
<p>shared libraries after build from source:</p>
<pre><code class="lang-auto">ls .conda/envs/buildpt/lib/python3.8/site-packages/torch/lib/libtorch_cuda* 

.conda/envs/buildpt/lib/python3.8/site-packages/torch/lib/libtorch_cuda.so  
.conda/envs/buildpt/lib/python3.8/site-packages/torch/lib/libtorch_cuda_linalg.so
</code></pre>
<p>shared libraries after install from pip/conda</p>
<pre><code class="lang-auto">ls .conda/envs/pytorch/lib/python3.8/site-packages/torch/lib/libtorch_cuda* 

.conda/envs/pytorch/lib/python3.8/site-packages/torch/lib/libtorch_cuda.so       
.conda/envs/pytorch/lib/python3.8/site-packages/torch/lib/libtorch_cuda_cu.so 
.conda/envs/pytorch/lib/python3.8/site-packages/torch/lib/libtorch_cuda_cpp.so 
.conda/envs/pytorch/lib/python3.8/site-packages/torch/lib/libtorch_cuda_linalg.so 
</code></pre>
<p>How to build these missing shared libraries?</p>

ptrblck: <p>Note that your source build isn’t missing these libraries, but should create a single <code>libtorch_cuda.so</code> lib instead of the split libraries.<br>
However, if you really want to split them (we needed to use it to avoid linker errors due to the size of the lib), use <code>BUILD_SPLIT_CUDA=ON python setup.py install</code>.</p>

Donglin: <p>Thank you for the quick answer. I can see split libraries now <img src="https://discuss.pytorch.org/images/emoji/apple/slight_smile.png?v=12" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20"></p>

adizhol: <p><a class="mention" href="/u/ptrblck">@ptrblck</a><br>
why<br>
<code>BUILD_SPLIT_CUDA=ON python3 setup.py bdist_wheel &amp;&amp;  pip3 install dist/*.whl</code><br>
doesn’t split the libraries?<br>
(I’m using mmcv + mmdet and they require the split libraries)<br>
Thanks</p>

nkflash: <p><a class="mention" href="/u/ptrblck">@ptrblck</a><br>
BTW, How to generate libtorch_cuda_cu.so with torch 2.0 release(without compile from source code)?</p>

ptrblck: <p>You don’t need to generate this file and it won’t be built by default anymore as library splitting isn’t used in the current release if I’m not mistaken.</p>

nkflash: <p>Thank you for the answer!</p>

chrisuz: <p>it seems tensorrt needs this file when running. any advice to get it on install when not compiling from source?</p>

ptrblck: <p>I doubt a compatible TorchTRT version needs files that are not built, so could you give more context why this should be the case?</p>

chrisuz: <p>i just made <a href="https://discuss.pytorch.org/t/what-are-the-appropriate-torch-versions-to-use-when-using-torch-tensorrt/181286">this post</a> about it. but im also not 100% that my compatability is correct. tried torch 1.13 on a pip recommendation but that causes the boilerplate not to run properly which i havent been able to debug.</p>

mavs: <p>Does setup.py support cross compiling libtorch.</p>

ptrblck: <p>I don’t think the ability to cross compile is related to the <code>setup.py</code> and rather depends on your build toolchain. I’ve heard some users were able to do so, but I usually just compile on the native target platform.</p>

mavs: <p>thanks for your reply. Recently i have used cmake to cross compile libtorch directly, and i have my own toolchain file. Now i am confused which code is related with toolchain in setup.py or build_libtorch.py. I’d like to change the toolchain code line of pytorch source code with my cross compilation toolchain information and try using setup.py or  build_libtorch.py to cross compile the source code. thx.</p>