Login  Register

Re: CLImage2D example program - Exception while executing kernel

Posted by Michael Bien on Apr 26, 2011; 4:43pm
URL: https://forum.jogamp.org/CLImage2D-example-program-Exception-while-executing-kernel-tp2866141p2866364.html

  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/