cudaMemCpy2D problem

weight_pitch = new long[1];
cudaMallocPitch(d_weights, weight_pitch, size * Sizeof.FLOAT, size);
weights = new float[size * size];
cudaMemcpy2D(d_weights, weight_pitch[0], Pointer.to(weights), size*Sizeof.FLOAT, size, size, cudaMemcpyHostToDevice);

A fatal error has been detected by the Java Runtime Environment:

SIGSEGV (0xb) at pc=0x00007fefd5782ece, pid=28876, tid=140668041004816

JRE version: 6.0_21-b06

Java VM: Java HotSpot™ 64-Bit Server VM (17.0-b16 mixed mode linux-amd64 )

Problematic frame:

C [libc.so.6+0x80ece] memcpy+0xe

An error report file with more information is saved as:

dfdsa

If you would like to submit a bug report, please visit:

http://java.sun.com/webapps/bugreport/crash.jsp

The crash happened outside the Java Virtual Machine in native code.

See problematic frame for where to report the bug.

Any ideas what I did wrong?

Hello Durandal,

It’s hard to tell what went wrong from the small code snippet. At the first glance, the parameters seem to be correct so far.

But regardless of the parameters, there may be another reason for this kind of error: I have read about potential problems with JNI on Linux when mixing it with OpenCL. The details are beyond my knowledge and understanding of the internal mechanims on Linux (some more technical details are described here). I assume that the same problem may occur for mixing JNI+CUDA, so you may want to try this:

Before starting the application, set the LD_PRELOAD environment variable as follows:
export LD_PRELOAD=/usr/lib/jvm/java-6-openjdk/jre/lib/amd64/libjsig.so

(adjusting the path according to the location of “libjsig.so” on your system)

If this does not help, I can build a minimal example program using cudaMemcpy2D, so that it may be possible to track down the reason for the error by comparing it to your application.

bye
Marco