Using the JCuda runtime API with gpuocelot


The JCuda Runtime API can be used with the CUDA emulation mode that is supported by gpuocelot. (Please note that the Driver API may not work correctly due to compatibilty issues between CUDA 5.0 and gpuocelot 2.1)

The following is a summary of the information that was provided by nadal in a forum thread about JCuda and gpuocelot.


Prerequisites:


Due to limited support of newer CUDA features in gpuocelot, this approach may not work with the latest CUDA versions. It has been tested with CUDA 5 on Linux. So one possible settup is the following: General information for setting up gpuocelot can be found on the web, for example in this gpuocelot and CUDA tutorial.


Integration of gpuocelot with JCuda



The gpuocelot emulator can be integrated with JCuda by linking the gpuocelot libraries during compilation.

The gpuocelot library can be linked by adding "-locelot" in the file "link.txt" in each of the component folders that are generated by CMake. For example, to emulate the JCuda runtime api, the file "link.txt" is located at CMakeBuild/JCudaRuntimeJNI/CMakeFiles/JCudaRuntime-linux-x86_64.dir

In this "link.txt" file, change the linker call to

    /usr/bin/c++ -fPIC -shared -Wl,-soname,libJCudaRuntime-linux-x86_64.so -o ../lib/libJCudaRuntime-linux-x86_64.so CMakeFiles/JCudaRuntime-linux-x86_64.dir/src/JCudaRuntime.cpp.o -locelot /usr/local/cuda/lib64/libcudart.so -lcuda ../lib/libCommonJNI.a -Wl,-rpath,/usr/local/cuda/lib64

(Note: It should also be possible to modify the CMake files to achieve this, but this has not yet been investigated further)

Make sure that the gpuocelot library is listed before the cuda and cudart libraries, as shown above, to completely bypass them so that the NVIDIA library is not invoked.

Then, compile the JCuda source code with the above settings to generate new JCuda binaries. Running a JCuda program with these binaries will invoke the gpuocelot emulator instead of NVIDIA CUDA.