Hi,
The function env->GetDirectBufferAddress always returns 0x0 even when the buffer.isDirect() returns true. This leads to the problem of cudaFreeHost() not being able to free the allocated page-locked memory.
As a workaround, I modified the function Java_jcuda_runtime_JCuda_cudaFreeHostNative in JCuda-All-0.4.1-src/JCudaRuntimeJNI/src/JCudaRuntime.cpp . The line
void *nativePtr = env->GetDirectBufferAddress(ptr);
was changed into
void *nativePtr = getPointer(env, ptr);
Does anybody observe the same problem? Here is a program which does nothing but allocate then free 1GB of pinned memory 100 times.
import jcuda.Sizeof;
import jcuda.runtime.JCuda;
public class PinnedMemTest {
public static void main(String args[]) {
for (int k = 0; k < 100; k++) {
int n = 1<<28;
Pointer host = new Pointer();
JCuda.cudaHostAlloc(host, n*Sizeof.FLOAT, JCuda.cudaHostAllocDefault);
JCuda.cudaFreeHost(host);
}
}
}
I run it using Centos 5.6 amd64, Java 1.7.0_03, and Cuda toolkit 4.1.