"cublas runtime error : library not initialized" when running nn.Linear with Cuda

username: Mechanica
cooked: <p>Hey all,<br>
I keep getting this error when trying to use nn.Linear with cuda:<br>
<code>cublas runtime error : library not initialized at ../aten/src/THC/THCGeneral.cpp:216</code></p>
<p>On the CPU it runs fine though.<br>
PyTorch is 1.2.0, python 3.7, Cuda 10.1, CuDNN 7.6.1, and my GPU is a GTX 970. I’m running macOS and I installed PyTorch from source.</p>
<p>Anyone know why this might be happening or how to debug this further? I’m a bit new to these tools.</p>

username: ptrblck
cooked: <p>Could you try some suggestions from <a href="https://github.com/torch/cutorch/issues/677" rel="nofollow noopener">this issue</a>?</p>

username: Mechanica
cooked: <p>Thank you for the reply! It appears that most of the info in that thread is about two GPU systems, which mine is not. The only potentially relevant suggestion I’m seeing is about removing the .nv file, which I don’t seem to have on my system.</p>
<p>I’m thinking my issue may be something like an incomplete install or missing dependencies or something?</p>
<p>If I use</p>
<pre><code class="lang-auto">linear = nn.Linear(2, 2)
x = torch.randn(2, 2)
print(linear(x))
</code></pre>
<p>everything works fine, but if instead I use</p>
<pre><code class="lang-auto">linear = nn.Linear(2, 2).cuda()
x = torch.randn(2, 2).cuda()
print(linear(x))
</code></pre>
<p>I get</p>
<pre><code class="lang-auto">RuntimeError                              Traceback (most recent call last)
&lt;ipython-input-3-81612b3daf91&gt; in &lt;module&gt;
      4 linear = nn.Linear(2, 2).cuda()
      5 x = torch.randn(2, 2).cuda()
----&gt; 6 print(linear(x))

~/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py in __call__(self, *input, **kwargs)
    537             result = self._slow_forward(*input, **kwargs)
    538         else:
--&gt; 539             result = self.forward(*input, **kwargs)
    540         for hook in self._forward_hooks.values():
    541             hook_result = hook(self, input, result)

~/anaconda3/lib/python3.7/site-packages/torch/nn/modules/linear.py in forward(self, input)
     85 
     86     def forward(self, input):
---&gt; 87         return F.linear(input, self.weight, self.bias)
     88 
     89     def extra_repr(self):

~/anaconda3/lib/python3.7/site-packages/torch/nn/functional.py in linear(input, weight, bias)
   1363     if input.dim() == 2 and bias is not None:
   1364         # fused op is marginally faster
-&gt; 1365         ret = torch.addmm(bias, input, weight.t())
   1366     else:
   1367         output = input.matmul(weight.t())

RuntimeError: cublas runtime error : library not initialized at ../aten/src/THC/THCGeneral.cpp:216
</code></pre>

username: John_G
cooked: <p>Hello, I hit this exact error trying to get pytorch/examples/mnist/main.py to work. The above print(linear(x)) code also generates the same error. I’m on a 2014 MacBook Pro with a GTX 750M. Built pytorch from GitHub src a couple days ago, rebuilding just now to see if it makes any difference. Would love to see this fixed! Thanks!</p>
<p>print(sys.version)<br>
print(torch.<strong>version</strong>)<br>
print(torchvision.<strong>version</strong>)<br>
print(torch.cuda.is_available())<br>
print(torch.backends.cudnn.enabled)<br>
print(torch.version.cuda)<br>
print(torch.backends.cudnn.version())</p>
<p>3.7.3 (default, Mar 30 2019, 03:44:34)<br>
[Clang 9.1.0 (clang-902.0.39.2)]<br>
1.2.0a0+5395db2<br>
0.3.0a0+487c9bf<br>
True<br>
True<br>
10.1<br>
7601</p>

username: John_G
cooked: <p>Just rebuilt pytorch from GitHub src. Same error.<br>
1.2.0a0+30e03df<br>
Thanks!</p>

username: Mechanica
cooked: <p>Well I’m glad I’m not alone at least. Sorry you’re suffering this too though.</p>

username: Mechanica
cooked: <p>John_G, you still encountering this? This is an ongoing problem for me. Perhaps I should open an issue on the github.</p>