1

I have a program written in Java which involves massive amount of multidimensional array. I am trying to parallelize it using JOCL (OpenCL), but multidimensional array has to be converted to single dimensional array before being passed to OpenCL.

Besides rewriting the entire program using one dimensional array, is there any other solution?

aaronqli
  • 790
  • 9
  • 26
  • @HighPerformanceMark I thought there is no other way of flattening the array besides copy the entire array. This is not possible in this case because OpenCL kernel is executed in a massive loop, and the arrays are 500M~2GB large. Am I wrong? – aaronqli Aug 01 '12 at 11:06
  • I don't know what JOCL is or does, but Java doesn't have multidimensional arrays. All it has is arrays of arrays. So you effectively have a flat array. Each element of this flat array is an array. – JB Nizet Aug 01 '12 at 11:34
  • @JBNizet In that case I guess the best solution is to change all arrays into flat array and use complicated indices to make it "multidimensional" - I think I can write a script to massively create index functions and replace every multidimensional indices to one dimensional equivalent indices. – aaronqli Aug 01 '12 at 12:33

1 Answers1

1

Here is what I do in C++ when I have multidimensional arrays :

for (int i = 0 ; i < n ; i++) {
    queue.enqueueWriteBuffer(buffer, CL_FALSE, i*m*sizeof(int), m*sizeof(int), data[i]);
}

Same when I need to read, just be careful in your kernel with your indexes.

Can't you do the same in Java ?

dkg
  • 1,775
  • 14
  • 34
  • Thanks. This is a solution. I guess by doing this the cl_mem passed to kernel arguments can no longer rely on host pointer? – aaronqli Aug 19 '12 at 15:18