CLImage2D example program - Exception while executing kernel

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

CLImage2D example program - Exception while executing kernel

suleman
Hi,

I am working with a image processing code (using Image2d class). According to the ImageTest example in jocl i have coded the program but i am facing below exception while executing the kernel.

Any idea? whats wrong?

$ java -mx3500m CLSimpleGammaCorrection
Exception in thread "main" com.jogamp.opencl.CLException$CLOutOfResourcesException: can not enqueue read-image CLImage2d [id: 249794088 width: 64 height: 64] with inputRowPitch: 0 origin: [0, 0] range: [64, 64]
cond.: null events: null [error: CL_OUT_OF_RESOURCES]
        at com.jogamp.opencl.CLException.newException(CLException.java:78)
        at com.jogamp.opencl.CLCommandQueue.putReadImage(CLCommandQueue.java:647)
        at com.jogamp.opencl.CLCommandQueue.putReadImage(CLCommandQueue.java:600)
        at CLSimpleGammaCorrection.gammaCorrection(CLSimpleGammaCorrection.java:159)
        at CLSimpleGammaCorrection.main(CLSimpleGammaCorrection.java:134)
Reply | Threaded
Open this post in threaded view
|

Re: CLImage2D example program - Exception while executing kernel

suleman
main code
=========
      ......
            //load image
            BufferedImage image = readImage("colors.png");
            assert image.getColorModel().getNumComponents() == 3;

            //Image dimensions
            int imageWidth = image.getWidth();
            int imageHeight = image.getHeight();

            //Output image
            BufferedImage outputImage = new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_INT_RGB);
           
            //Create the memory object for the input- and output image

            float[] pixels = image.getRaster().getPixels(0, 0, image.getWidth(), image.getHeight(), (float[])null);


     CLImageFormat format = new CLImageFormat(RGB, FLOAT);

            CLImage2d<FloatBuffer> imageA = context.createImage2d(newDirectFloatBuffer(pixels), imageWidth, imageHeight, format);
            CLImage2d<FloatBuffer> imageB = context.createImage2d(newDirectFloatBuffer(pixels.length), imageWidth, imageHeight, format);
     
            //creade a command queue with benchmarking flag set
            CLCommandQueue queue = context.getDevices()[0].createCommandQueue(Mode.PROFILING_MODE);
           
            int localWorkSize = queue.getDevice().getMaxWorkGroupSize(); // Local work size dimensions
            int globalWorkSize = roundUp(localWorkSize, imageWidth*imageHeight);  // rounded up to the nearest multiple of the localWorkSize
             
            //create kernel and set function parameters
            CLKernel kernel = program.createCLKernel("gamma");
           
            //original lenna
            show(image, 0, 50, "reference");
           
            //a few gamma corrected versions
            float gamma = 0.5f;

            //gammaCorrection(gamma, queue, kernel, buffer, localWorkSize, globalWorkSize);
            gammaCorrection(imageWidth,imageHeight,gamma, queue, kernel, imageA,imageB,localWorkSize,globalWorkSize);
            FloatBuffer bufferA = imageA.getBuffer();
            FloatBuffer bufferB = imageB.getBuffer();
       
            // allocate a OpenCL buffer using the direct fb as working copy
            CLBuffer<FloatBuffer> buffer = context.createBuffer(bufferB, CLBuffer.Mem.READ_WRITE);
           
            show(createImage(imageWidth,imageHeight,buffer),image.getWidth()/2, 50, "gamma="+gamma);
           

------------------------------------------
//Kernel execution method
 private static void gammaCorrection(int width,int height,float gamma, CLCommandQueue queue, CLKernel kernel, CLImage2d imageA,CLImage2d imageB, int localWorkSize, int globalWorkSize) {
       
        float scaleFactor = (float) Math.pow(255, 1.0f-gamma);
       
        // setup kernel
        kernel.putArg(imageA).putArg(imageB).putArg(gamma).putArg(scaleFactor).putArg(width).putArg(height);  
        queue.putWriteImage(imageA, false);                                       // upload image
        queue.put2DRangeKernel(kernel, 0,0,width,height,0,0);   // execute program
        queue.putReadImage(imageB,true);
       
    }


KERNEL code
---------------------
 kernel void gamma(read_only image2d_t input, write_only image2d_t output,const float gamma, const float scale, const int width,const int height) {
       
        const sampler_t sampler=CLK_NORMALIZED_COORDS_FALSE|CLK_ADDRESS_CLAMP|CLK_FILTER_NEAREST;

        int x = get_global_id(0);
        int y = get_global_id(1);

        if((x>=width)||(y>=height))
                return;
 
        int2 coord = (int2)(x,y);
        float4 temp = read_imagef(input, sampler, coord);
  write_imagef(output, coord, pow(temp,(float4)gamma)*scale);
 
    }

Reply | Threaded
Open this post in threaded view
|

Re: CLImage2D example program - Exception while executing kernel

Michael Bien
  does the original demo work for you?
http://jogamp.org/deployment/webstart-next/jocl-demos/gamma.jnlp

CL_OUT_OF_RESOURCES is usually thrown if to large buffers or workgroup
sizes are used (hardware limitation).

-michael

On 04/26/2011 05:57 PM, suleman [via jogamp] wrote:

>
> main code
> =========
>        ......
>              //load image
>              BufferedImage image = readImage("colors.png");
>              assert image.getColorModel().getNumComponents() == 3;
>
>    //Image dimensions
>    int imageWidth = image.getWidth();
>    int imageHeight = image.getHeight();
>
>    //Output image
>    BufferedImage outputImage = new BufferedImage(imageWidth, imageHeight,
> BufferedImage.TYPE_INT_RGB);
>
>    //Create the memory object for the input- and output image
>
>              float[] pixels = image.getRaster().getPixels(0, 0,
> image.getWidth(), image.getHeight(), (float[])null);
>
>
>      CLImageFormat format = new CLImageFormat(RGB, FLOAT);
>
>              CLImage2d<FloatBuffer>  imageA =
> context.createImage2d(newDirectFloatBuffer(pixels), imageWidth, imageHeight,
> format);
>              CLImage2d<FloatBuffer>  imageB =
> context.createImage2d(newDirectFloatBuffer(pixels.length), imageWidth,
> imageHeight, format);
>
>              //creade a command queue with benchmarking flag set
>              CLCommandQueue queue =
> context.getDevices()[0].createCommandQueue(Mode.PROFILING_MODE);
>
>              int localWorkSize = queue.getDevice().getMaxWorkGroupSize(); //
> Local work size dimensions
>              int globalWorkSize = roundUp(localWorkSize,
> imageWidth*imageHeight);  // rounded up to the nearest multiple of the
> localWorkSize
>
>              //create kernel and set function parameters
>              CLKernel kernel = program.createCLKernel("gamma");
>
>              //original lenna
>              show(image, 0, 50, "reference");
>
>              //a few gamma corrected versions
>              float gamma = 0.5f;
>
>              //gammaCorrection(gamma, queue, kernel, buffer, localWorkSize,
> globalWorkSize);
>              gammaCorrection(imageWidth,imageHeight,gamma, queue, kernel,
> imageA,imageB,localWorkSize,globalWorkSize);
>              FloatBuffer bufferA = imageA.getBuffer();
>              FloatBuffer bufferB = imageB.getBuffer();
>
>    // allocate a OpenCL buffer using the direct fb as working copy
>              CLBuffer<FloatBuffer>  buffer = context.createBuffer(bufferB,
> CLBuffer.Mem.READ_WRITE);
>
>    show(createImage(imageWidth,imageHeight,buffer),image.getWidth()/2, 50,
> "gamma="+gamma);
>
>
> KERNEL code
> ---------------------
>   kernel void gamma(read_only image2d_t input, write_only image2d_t
> output,const float gamma, const float scale, const int width,const int
> height) {
>
> const sampler_t
> sampler=CLK_NORMALIZED_COORDS_FALSE|CLK_ADDRESS_CLAMP|CLK_FILTER_NEAREST;
>
> int x = get_global_id(0);
> int y = get_global_id(1);
>
> if((x>=width)||(y>=height))
> return;
>    
> int2 coord = (int2)(x,y);
> float4 temp = read_imagef(input, sampler, coord);
>   write_imagef(output, coord, pow(temp,(float4)gamma)*scale);
>
>      }
>
>
>
> _______________________________________________
> If you reply to this email, your message will be added to the discussion below:
> http://forum.jogamp.org/CLImage2D-example-program-Exception-while-executing-kernel-tp2866141p2866156.html
> To start a new topic under jogamp, email [hidden email]
> To unsubscribe from jogamp, visit
http://michael-bien.com/

Reply | Threaded
Open this post in threaded view
|

Re: CLImage2D example program - Exception while executing kernel

suleman

Yes the original demo (which uses the CLBuffer instead of CLImage2D) works.
I am using the 2D picture of  size 64*64 pixels, which i think is not very large.