BitonicSort and RadixSortDemo

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

BitonicSort and RadixSortDemo

Rui Silva
Hello,

I am new to OpenCL and Jogamp. My problem is that when I try to change the size of the array in the examples BitonicSort and RadixSortDemo I always get an exception.

In BitonicSort if I change the following line of code from: "final int elements = 1048576;" to: "final int elements = 1048578;" I get the following exception:

Exception in thread "main" com.jogamp.opencl.CLException $ CLInvalidWorkGroupSizeException: can not enqueue 1DRange CLKernel [id: 1813676488 name: bitonicSortLocal1]
 with gwo: null GWS: 524289} {lws: {512}
cond.: null events: null [error: CL_INVALID_WORK_GROUP_SIZE]
        at com.jogamp.opencl.CLException.newException (CLException.java: 78)
        at com.jogamp.opencl.CLCommandQueue.putNDRangeKernel (CLCommandQueue.java: 1547)
        at com.jogamp.opencl.CLCommandQueue.put1DRangeKernel (CLCommandQueue.java: 1455)
        at com.jogamp.opencl.CLCommandQueue.put1DRangeKernel (CLCommandQueue.java: 1425)
        at com.jogamp.opencl.demos.bitonicsort.BitonicSort.bitonicSort (BitonicSort.java: 161)
        at com.jogamp.opencl.demos.bitonicsort.BitonicSort. <init> (BitonicSort.java: 73)
        at com.jogamp.opencl.demos.bitonicsort.BitonicSort.main (BitonicSort.java: 204)

In RadixSortDemo if I change the following line of code:

        from: "int [] runs = new int [] {32768,
                                       65536,
                                      131072,
                                      262144,
                                      524288,
                                     1048576,
                                     2097152,
                                     4194304,
                                     8388608}; "
        to: " int [] runs = new int [] {32768,
                                       65536,
                                      131072,
                                      262144,
                                      524288,
                                     1048576,
                                     2097152,
                                     4194304,
                                     8388606}; "
        I get the following exception:

Exception in thread "main" java.lang.RuntimeException
        at com.jogamp.opencl.demos.radixsort.Scan.scanExclusiveLarge (Scan.java: 61)
        at com.jogamp.opencl.demos.radixsort.RadixSort.radixSortStepKeysOnly (RadixSort.java: 103)
        at com.jogamp.opencl.demos.radixsort.RadixSort.radixSortKeysOnly (RadixSort.java: 87)
        at com.jogamp.opencl.demos.radixsort.RadixSort.sort (RadixSort.java: 75)
        at com.jogamp.opencl.demos.radixsort.RadixSortDemo. <init> (RadixSortDemo.java: 80)
        at com.jogamp.opencl.demos.radixsort.RadixSortDemo.main (RadixSortDemo.java: 131)

What am I doing wrong? I think that has to do with the size of localWorkSize and Size of the globalWorkSize but i do not understand how these values fit the new size of my array.

Thanks and regards
Rui Silva
Reply | Threaded
Open this post in threaded view
|

Re: BitonicSort and RadixSortDemo

Michael Bien
Hello Rui,

the global work size (specified by the NDRange) must be evenly divisible by the local work size. Thats the reason why you can't use arbitrary input buffer lenghts without additional work. The HelloJOCL sample does this right and allows to use arbitrary buffer lengths.

Take a look at the bounds check in the opencl kernel and the first three lines of the java code:

    kernel void VectorAdd(global const float* a, global const float* b, global float* c, int numElements) {

        // get index of the global data array
        int iGID = get_global_id(0);

        // bound check (equivalent to the limit on a 'for' loop for standard/serial C code)
        if (iGID >= numElements)  {
            return;
        }

java:
        int elementCount = 11444777;                                // Length of arrays to process
        int localWorkSize = 256;                                    // Local work size dimensions
        int globalWorkSize = roundUp(localWorkSize, elementCount);  // rounded up to the nearest multiple of the localWorkSize

the Nvidia sorting examples don't do this, thats why you get the exception.


hope that helps a bit,

best regards,

michael


On 12/17/2010 10:19 PM, Rui Silva [via jogamp] wrote:
Hello,

I am new to OpenCL and Jogamp. My problem is that when I try to change the size of the array in the examples BitonicSort and RadixSortDemo I always get an exception.

In BitonicSort if I change the following line of code from: "final int elements = 1048576;" to: "final int elements = 1048578;" I get the following exception:

Exception in thread "main" com.jogamp.opencl.CLException $ CLInvalidWorkGroupSizeException: can not enqueue 1DRange CLKernel [id: 1813676488 name: bitonicSortLocal1]
 with gwo: null GWS: 524289} {lws: {512}
cond.: null events: null [error: CL_INVALID_WORK_GROUP_SIZE]
        at com.jogamp.opencl.CLException.newException (CLException.java: 78)
        at com.jogamp.opencl.CLCommandQueue.putNDRangeKernel (CLCommandQueue.java: 1547)
        at com.jogamp.opencl.CLCommandQueue.put1DRangeKernel (CLCommandQueue.java: 1455)
        at com.jogamp.opencl.CLCommandQueue.put1DRangeKernel (CLCommandQueue.java: 1425)
        at com.jogamp.opencl.demos.bitonicsort.BitonicSort.bitonicSort (BitonicSort.java: 161)
        at com.jogamp.opencl.demos.bitonicsort.BitonicSort. <init> (BitonicSort.java: 73)
        at com.jogamp.opencl.demos.bitonicsort.BitonicSort.main (BitonicSort.java: 204)

In RadixSortDemo if I change the following line of code:

        from: "int [] runs = new int [] {32768,
                                       65536,
                                      131072,
                                      262144,
                                      524288,
                                     1048576,
                                     2097152,
                                     4194304,
                                     8388608}; "
        to: " int [] runs = new int [] {32768,
                                       65536,
                                      131072,
                                      262144,
                                      524288,
                                     1048576,
                                     2097152,
                                     4194304,
                                     8388606}; "
        I get the following exception:

Exception in thread "main" java.lang.RuntimeException
        at com.jogamp.opencl.demos.radixsort.Scan.scanExclusiveLarge (Scan.java: 61)
        at com.jogamp.opencl.demos.radixsort.RadixSort.radixSortStepKeysOnly (RadixSort.java: 103)
        at com.jogamp.opencl.demos.radixsort.RadixSort.radixSortKeysOnly (RadixSort.java: 87)
        at com.jogamp.opencl.demos.radixsort.RadixSort.sort (RadixSort.java: 75)
        at com.jogamp.opencl.demos.radixsort.RadixSortDemo. <init> (RadixSortDemo.java: 80)
        at com.jogamp.opencl.demos.radixsort.RadixSortDemo.main (RadixSortDemo.java: 131)

What am I doing wrong? I think that has to do with the size of localWorkSize and Size of the globalWorkSize but i do not understand how these values fit the new size of my array.

Thanks and regards
Rui Silva


View message @ http://jogamp.762907.n3.nabble.com/BitonicSort-and-RadixSortDemo-tp2107372p2107372.html
To start a new topic under jogamp, email [hidden email]
To unsubscribe from jogamp, click here.


-- 
- - - -
http://michael-bien.com