Hi,
I got JCuda working in Java Processing, except i get an error on the Cuda Sort example.
import jcuda.*;
import jcuda.jcudpp.*;
import jcuda.runtime.*;
import jcuda.runtime.JCuda.*;
/**
* This is a sample class demonstrating the application of JCudpp for
* performing a sort of an integer array with 1000000 elements.
*/
void setup() {
noLoop();
}
void draw() {
testSort(1000000);
}
/**
* Test the JCudpp sort operation for an array of size n
*
* @param n The array size
*/
static boolean testSort(int N) {
println("Creating input data");
int array[] = createRandomIntData(N);
int arrayRef[] = array.clone();
println("Performing sort with Java...");
Arrays.sort(arrayRef);
println("Performing sort with JCudpp...");
Cuda_sort(array);
boolean passed = Arrays.equals(array, arrayRef);
println("testSort "+(passed?"PASSED":"FAILED"));
return passed;
}
/**
* Implementation of sort using JCudpp
*
* @param array The array to sort
*/
static void Cuda_sort(int array[]) {
int n = array.length;
// Allocate memory on the device
Pointer d_keys = new Pointer();
JCuda.cudaMalloc(d_keys, n * Sizeof.INT);
// Copy the input array from the host to the device
JCuda.cudaMemcpy(d_keys, Pointer.to(array), n * Sizeof.INT,
cudaMemcpyKind.cudaMemcpyHostToDevice);
// Create a CUDPPConfiguration for a radix sort of
// an array of ints
CUDPPConfiguration config = new CUDPPConfiguration();
config.algorithm = CUDPPAlgorithm.CUDPP_SORT_RADIX;
config.datatype = CUDPPDatatype.CUDPP_UINT;
config.op = CUDPPOperator.CUDPP_ADD;
config.options = CUDPPOption.CUDPP_OPTION_KEYS_ONLY;
// Create a CUDPPHandle for the sort operation
CUDPPHandle handle = new CUDPPHandle();
//JCudpp.cudppPlan(handle, config, n, 1, 0);
// Execute the sort operation
JCudpp.cudppSort(handle, d_keys, null, 32, n);
Arrays.fill(array, 0);
// Copy the result from the device to the host
JCuda.cudaMemcpy(Pointer.to(array), d_keys, n * Sizeof.INT,
cudaMemcpyKind.cudaMemcpyDeviceToHost);
// Clean up
//JCudpp.cudppDestroyPlan(handle);
JCuda.cudaFree(d_keys);
}
/**
* Creates an array of the specified size, containing some random data
*/
static int[] createRandomIntData(int n) {
Random random = new Random(0);
int x[] = new int[n];
for (int i = 0; i < n; i++) {
x** = random.nextInt(10);
}
return x;
}
The result from the console:
Creating input data
Performing sort with Java…
Performing sort with JCudpp…
Error while loading native library with base name “JCudpp”
Operating system name: Windows 7
Architecture : amd64
Architecture bit size: 64
processing.app.debug.RunnerException: UnsatisfiedLinkError: Could not load native library
at processing.app.Sketch.placeException(Sketch.java:1543)
at processing.app.debug.Runner.findException(Runner.java:582)
at processing.app.debug.Runner.reportException(Runner.java:558)
at processing.app.debug.Runner.exception(Runner.java:498)
at processing.app.debug.EventThread.exceptionEvent(EventThread.java:367)
at processing.app.debug.EventThread.handleEvent(EventThread.java:255)
at processing.app.debug.EventThread.run(EventThread.java:89)
Exception in thread “Animation Thread” java.lang.UnsatisfiedLinkError: Could not load native library
at jcuda.LibUtils.loadLibrary(LibUtils.java:79)
at jcuda.jcudpp.JCudpp.assertInit(JCudpp.java:175)
at jcuda.jcudpp.JCudpp.cudppSort(JCudpp.java:489)
at CUDA_sort.Cuda_sort(CUDA_sort.java:86)
at CUDA_sort.testSort(CUDA_sort.java:56)
at CUDA_sort.draw(CUDA_sort.java:41)
at processing.core.PApplet.handleDraw(Unknown Source)
at processing.core.PApplet.run(Unknown Source)
at java.lang.Thread.run(Thread.java:662)
It goes wrong on the line: JCudpp.cudppSort(handle, d_keys, null, 32, n);
The only thing i can think of, is that i miss a file called cudpp64_32_16.dll. Because this is the only file i don’t have as a dll. But i am not sure.
Is there somebody who knows?
Greetings, Dippo