1

I wrote some code to multiply some symmetrical matrices and decided to use CUDA (cublasSgemm) to do the work for me.

I've got the Toolkit, as well as everything else set up but run into a problem when I try to use the cublas functions.

I've included:

#include <cuda_runtime.h>
#include "cublas_v2.h"

And I've also gone to Properties>Linker>Input and added cublas.lib to the dependencies. When I get everything going, I hit this error:

LINK : fatal error LNK1104: cannot open file 'cublas.lib'

If I remove the library from my dependencies, I get unsolved errors for all of the cublas functions.

Any help would be wonderful... :).

Kari
  • 1,244
  • 1
  • 13
  • 27
Mmm Donuts
  • 9,551
  • 6
  • 27
  • 49
  • 1
    You'll also need to add the search path to the project specification. I believe variants of this question have been asked many times before. Does [this](http://stackoverflow.com/questions/13570285/how-to-link-cusparse-library-for-cuda-5-on-windows) help ? It discusses cusparse, but adding cublas should be nearly identical. – Robert Crovella Oct 08 '15 at 23:34
  • A search path? I'm not entire sure how to implement that. As for the latter, I've done all of that already and I'm unfortunately still at a standstill. – Mmm Donuts Oct 08 '15 at 23:37
  • Follow the instructions for **Additional Library Directories** [here](http://stackoverflow.com/questions/4445418/how-to-add-additional-libraries-in-c). You'll need to know where on your machine the `cublas.lib` is located. You may know that already based on how you installed CUDA toolkit. If not, you can use windows file search to find it. The folder that it is in needs to be added to your VS project, so VS knows where to look to find cublas.lib. And I expect you will need to add cudart.lib to your project definition (dependencies) as well. If so you will discover that. – Robert Crovella Oct 08 '15 at 23:42
  • also, if you want to "cheat", you could open up a cuda sample project from the toolkit like [simpleCUBLAS](http://docs.nvidia.com/cuda/cuda-samples/index.html#simple-cublas) and just drop your code in that project, and it might just work, depending on what your code depends on. You could also study the project file for that sample and see all the settings that are needed. But adding a library (path) should be pretty simple for your existing project, and it's good knowledge to have if you're going to be using Visual Studio. – Robert Crovella Oct 08 '15 at 23:51
  • Okay, I know what's going on now. I'm on the Win32 platform which doesn't have cublas in the `lib`. Is there anyway to create an `x64` application (it's in that library)? – Mmm Donuts Oct 09 '15 at 00:07
  • 1
    Are you on a 32-bit OS or a 64-bit OS? What exact version of Visual Studio are you using? Which CUDA toolkit did you install (ie. what version, and was it the 32-bit or 64-bit toolkit) ? – Robert Crovella Oct 09 '15 at 00:20
  • I literally just changed the platform and it worked. I'm on a 64 bit version of 10, but this thing defaulted to 32 -_-. Thanks for the mountains if insight though! – Mmm Donuts Oct 09 '15 at 00:48
  • 1
    Why don't you provide an answer, stating what you did to fix the issue. – Robert Crovella Oct 09 '15 at 00:51

1 Answers1

5

So, the solution was simpler than I thought. Go to your project properties and make sure that you're running x64 rather than win32. The cublas lib file does not exist in the win32 library folder.

Mmm Donuts
  • 9,551
  • 6
  • 27
  • 49