Wish/Suggestion: CUDA SDK with shared library option Need CUDA libraries as shared objects

The CUDA SDK comes setup to use static libraries. I’m working on a project where we’re interested in calling CUDA from Java via JNI to speed up a Java based modelling software. The problem is that JNI needs to be implemented as shared libraries to be loadable into the Java, this means that any CUDA libraries we want the JNI shared object to use also has to be shared code.

Otherwise you get a error when you compile:
/usr/bin/ld: /home/user/NVIDIA_CUDA_SDK/lib/libcutil.a(cutil.cpp_o): relocation R_X86_64_32 against `a local symbol’ can not be used when making a shared object; recompile with -fPIC[/indent]

What would be useful would be an easy way to recompile the SDK/lib files as shared libraries

Don’t use cutil. Do not use cutil. Do not use cutil. It is there for use within the SDK only and is not nearly robust enough to be used by anyone else.

Check your own error messages and do not rely on cutil. It changes a lot, it doesn’t always behave as you’d expect, and it’s not production quality.

I’ve seen many posts about not using cutil, but I think it’s kind of a contradictory message. If it’s so bad to use, why is it used extensively in the example code most people use to learn CUDA? Telling them not to use it is like saying, “Do as I say and not as I do.”

I do not think that any of the SDK examples are meant to be production quality or particularly high performance. cutil is along the same lines: it is useful for getting a quick and dirty example working, but if you are working on production quality code, then take the time to implement something equivalent well.

Also, people should consider using a build chain other than the sdk makefiles or visual studio templates if it makes sense in their project. Just because they use it in the SDK does not mean that it is the best choice in every case. For example, I find that it is much easier to incorporate CUDA into larger projects using automake than the custom makefiles in the SDK.

My intent was not necessarily using cutil for production code, we intend to eventually work towards speeding up a Java based modelling application by using JNI to call CUFFT. Our profiling shows the vast majority of our cycles are spent doing FFTs. So as a demonstration that the concept would work (ie that JNI can call CUDA FFT and allow us to do this) before working on the very complex real application, I took the project simpleCUFFT, converted the cu file to be a shared object so it could be called by a Java class with JNI. So basically I ended up with linking to cutil because simpleCUFFT did the same and I didn’t change that.

If there’s a good way to modify the simpleCUFFT.cu so it doesn’t need cutil that would be nice and I’ll look into that.

But my goal is just to see if JNI can be used to call CUFFT and find any obvious gotcha problems.

UPDATE: I found more info on this issue in the SDK : NVIDIA_CUDA_SDK/common/cutil_readme.txt

I updated to CUDA 2.1 and found the project examples in that SDK use the cutil much less and resolved my problems.