No such file or directory #include <cublas_v2.h>

jingyu_han: <p>I’m trying to write a C++ version of maskrcnn based on<code> libtorch</code>, then when compiling my project, I got an error like this. I have seen this kind of error when compiling <code>Caffe</code>. However, that solution can not be used when talking about libtorch. Is there anyone have cues? thank you in advance.</p>
<pre><code class="lang-auto">-- Found Threads: TRUE  
-- Found CUDA: /usr/local/cuda-10.1 (found version "10.1") 
-- Caffe2: CUDA detected: 10.1
-- Caffe2: CUDA nvcc is: /usr/local/cuda-10.1/bin/nvcc
-- Caffe2: CUDA toolkit directory: /usr/local/cuda-10.1
-- Caffe2: Header version is: 10.1
-- Found CUDNN: /usr/lib/x86_64-linux-gnu/libcudnn.so  
-- Found cuDNN: v7.6.4  (include: /usr/include, library: /usr/lib/x86_64-linux-gnu/libcudnn.so)
-- Autodetected CUDA architecture(s):  5.2 5.2
-- Added CUDA NVCC flags for: -gencode;arch=compute_52,code=sm_52
-- Found torch: /home/tengfeihan/maskrcnn_benchmark.cpp/lib/libtorch/lib/libtorch.so  
-- Found OpenCV: /usr/local (found version "3.4.2") 
CUDA FOUND
-- The CUDA compiler identification is NVIDIA 10.1.243
-- Check for working CUDA compiler: /usr/local/cuda-10.1/bin/nvcc
-- Check for working CUDA compiler: /usr/local/cuda-10.1/bin/nvcc -- works
-- Detecting CUDA compiler ABI info
-- Detecting CUDA compiler ABI info - done
-- Found PythonInterp: /home/tengfeihan/anaconda3/bin/python (found version "3.7.4") 
-- Found GTest: /home/tengfeihan/maskrcnn_benchmark.cpp/lib/libtorch/lib/libgtest.a  
-- Configuring done
-- Generating done
-- Build files have been written to: /home/tengfeihan/maskrcnn_benchmark.cpp/build
(base) ┌─[tengfeihan@tengfeihan-X10SRA-F] - [~/maskrcnn_benchmark.cpp/build] - [Sat Mar 14, 19:06]
└─[$] &lt;git:(master*)&gt; make
Scanning dependencies of target layers
[  1%] Building CUDA object source/rcnn/layers/CMakeFiles/layers.dir/cuda/ROIAlign_cuda.cu.o
In file included from /home/tengfeihan/maskrcnn_benchmark.cpp/source/rcnn/layers/cuda/ROIAlign_cuda.cu:3:0:
/home/tengfeihan/maskrcnn_benchmark.cpp/lib/libtorch/include/ATen/cuda/CUDAContext.h:7:10: fatal error: cublas_v2.h: No such file or directory
 #include &lt;cublas_v2.h&gt;
          ^~~~~~~~~~~~~
compilation terminated.
source/rcnn/layers/CMakeFiles/layers.dir/build.make:62: recipe for target 'source/rcnn/layers/CMakeFiles/layers.dir/cuda/ROIAlign_cuda.cu.o' failed
make[2]: *** [source/rcnn/layers/CMakeFiles/layers.dir/cuda/ROIAlign_cuda.cu.o] Error 1
CMakeFiles/Makefile2:337: recipe for target 'source/rcnn/layers/CMakeFiles/layers.dir/all' failed
make[1]: *** [source/rcnn/layers/CMakeFiles/layers.dir/all] Error 2
Makefile:129: recipe for target 'all' failed
make: *** [all] Error 2
</code></pre>

pppplin: <p>hey, I encountered the exact same problem, have you find a solution yet? Thanks!</p>

ptrblck: <p>Which CUDA version are you using to build PyTorch from source?</p>

pppplin: <p>10.1, I encountered this issue while building detectron2.</p>

ptrblck: <p>Could you search for this file in your CUDA directory?<br>
I’m seeing the file in:</p>
<pre><code class="lang-auto">find /usr/local/ -name cublas_v2.h
/usr/local/cuda-11.0/targets/x86_64-linux/include/cublas_v2.h
</code></pre>

pppplin: <p>cublas_v2.h is not in my CUDA_HOME /usr/local/cuda-10.1/, but I find it at /usr/include/</p>

nilinykh: <p>Hey,<br>
I am facing the same issue, my cublas_v2.h file is located at /usr/include/.<br>
How did you solve the issue? Did you change the path to a different one?</p>

skrsna: <p>Hi,</p>
<p>I had a similar issue trying to build apex with cuda10.2 and pytorch 1.7 nightly. You can use symbolic linking like the following to resolve the issue:<br>
<code>ln -s /usr/include/cublas_v2.h /usr/local/cuda-10.2/targets/x86_64-linux/include/cublas_v2.h</code> .  Please use appropriate cuda version and target for the target link. Cheers!</p>

ghasemikasra39: <p>I have the same issue <a href="https://github.com/facebookresearch/NSVF/issues/27" rel="noopener nofollow ugc">here</a>. I tried <code>ln -s /usr/include/cublas_v2.h /usr/local/cuda-10.2/targets/x86_64-linux/include/cublas_v2.h </code> but I get the output:</p>
<pre><code class="lang-auto">
ln: failed to create symbolic link '/usr/local/cuda-10.2/targets/x86_64-linux/include/cublas_v2.h': File exists

</code></pre>
<p>and my issue is still there. Do you have any solution?</p>

HeyangQin: <p>I am compiling apex with Pytorch 1.6. For my case it’s the other way around: <code>cublas_v2.h</code> is located at <code>/usr/local/cuda-10.1/targets/x86_64-linux/include/cublas_v2.h</code> but compiler expects it to be at <code>/usr/include/cublas_v2.h</code>.</p>

mito: <p>I’ve got the very same problem for the very same repository (NSVF). I tried installing different cuda versions, reinstalling them, linking,… nothing works.</p>
<p>Edit: Ok, this worked for me. Make sure <code>cublas_v2.h</code> is located somewhere on your system, you can use what <a class="mention" href="/u/ptrblck">@ptrblck</a> suggested, i.e <code>find /usr/local/ -name cublas_v2.h</code> If it doesn’t find anything you have to reinstall cuda - I recommend this tutorial <a href="https://medium.com/@stephengregory_69986/installing-cuda-10-1-on-ubuntu-20-04-e562a5e724a0" class="inline-onebox" rel="noopener nofollow ugc">Installing CUDA 10.1 on Ubuntu 20.04 | by Stephen Gregory | Medium</a></p>
<p>Do <code>find /usr/local/ -name cublas_v2.h</code> once again to make sure <code>cublas_v2.h</code> is there, if you followed the aforementioned tutorial <code>cublas_v2.h</code> will be in <code>cuda-10-2</code> folder. No worries, we will symlink it and everything else that is necessary. Just do the following:</p>
<p><code>sudo ln -s /usr/local/cuda-10.2/targets/x86_64-linux/include/cublas_v2.h /usr/local/cuda-10.1/targets/x86_64-linux/include/cublas_v2.h</code></p>
<p>and</p>
<p><code>sudo ln -s /usr/local/cuda-10.2/targets/x86_64-linux/include/cublas_api.h /usr/local/cuda-10.1/targets/x86_64-linux/include/cublas_api.h</code></p>
<p>You should be good to go. In my case I got:</p>
<pre><code class="lang-auto">$ pip install --editable ./
Obtaining file:///home/milos/Projects/repositories/NSVF
Installing collected packages: fairnr
  Running setup.py develop for fairnr
Successfully installed fairnr
</code></pre>
<p>Let me know if it works <img src="https://discuss.pytorch.org/images/emoji/apple/slight_smile.png?v=9" title=":slight_smile:" class="emoji" alt=":slight_smile:"></p>

thanhmvu: <aside class="quote no-group" data-username="ghasemikasra39" data-post="9" data-topic="73204">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/ghasemikasra39/48/31019_2.png" class="avatar"> ghasemikasra39:</div>
<blockquote>
<p>ln -s /usr/include/cublas_v2.h /usr/local/cuda-10.2/targets/x86_64-linux/include/cublas_v2.h</p>
</blockquote>
</aside>
<p>This failed because the file order is reversed. It should be <code>ln -s path/to/src path/to/dst</code> so you want</p>
<blockquote>
<p><code>ln -s /usr/local/cuda-10.2/targets/x86_64-linux/include/cublas_v2.h /usr/include/cublas_v2.h</code></p>
</blockquote>
<p>then do the same for <code>cublas_api.h</code>.</p>
<blockquote>
<p><code>ln -s /usr/local/cuda-10.2/targets/x86_64-linux/include/cublas_api.h /usr/include/cublas_api.h</code></p>
</blockquote>
<p>This worked for me.</p>

sammi: <p><a class="mention" href="/u/thanhmvu">@thanhmvu</a> tips are very helpful. Now I encounter the errors for the links in the libraries for <code>cublas_api.h</code></p>
<pre><code class="lang-auto">/usr/include/cublas_api.h:76:10: fatal error: cuda_bf16.h: 
</code></pre>

ptrblck: <p>I guess your cublas installations is newer than the CUDA toolkit, which is why the <code>cuda_bf16.h</code> cannot be found.</p>

sammi: <p>Thanks! I solved the problem by <a href="https://forums.developer.nvidia.com/t/cublas-for-10-1-is-missing/71015/18" class="inline-onebox" rel="noopener nofollow ugc">cublas for 10.1 is missing - #18 by phillip3m - CUDA Setup and Installation - NVIDIA Developer Forums</a> (You might want to change the order of symbolic)</p>