Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5962125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:03:42+00:00 2026-05-22T19:03:42+00:00

Right now I am programming some samples to understand OpenCL for future use. In

  • 0

Right now I am programming some samples to understand OpenCL for future use.
In the sample with the problem, I load some big 8bit Images and calculate
pixelwise mean values.

Result[X,Y] = (Image1[X,Y] + Image2[X,Y] + … ) / ImageCount

This works very well for 0 to 9 pictures. But when i load 10 or more images, the result is just a black image (all Pixels 0).

I thought that it may be a problem with the amount of memory. But with 10 pictures the image data is only 100MB. The graphic card is a 8600GTS with 256MB RAM.

Also i checked all of the error code returns and don’t get anything different than a CL_SUCCESS.

Host program (Delphi, but I thing also C people can read it):

//Settings
MaxImg := 4;  //Images from 0..4 Count = 5
SetLength(InImgs,MaxImg+1);    //Array for images in Host memory
SetLength(GPUInMems,MaxImg+1); //Array for images in GPU memory

//Create Kernel
CLKernel := clCreateKernel(CLProgram, PChar('MainKernel'), @LastError);
//Create Queue
CLQueue := clCreateCommandQueue(CLContext, CLDevices[0].DeviceID, 0, @LastError);

//Load images
for I := 0 to MaxImg do
begin
  InImgs[I] := TImageMem.Create;
  InImgs[I].LoadFile('C:\Test\Img-' + IntToStr(I) + '.bmp');
  GPUInMems[I] := clCreateBuffer(CLContext, CL_MEM_READ_ONLY or CL_MEM_COPY_HOST_PTR, InImgs[I].MemSize, InImgs[I].Memory, @LastError);
end;

//Prepare Outputimage
OutImg := TImageMem.Create;
OutImg.LoadFile('C:\Test\CLTestOut.bmp');//Temporary solution to get right memory size and headers
GPUOutMem := clCreateBuffer(CLContext, CL_MEM_WRITE_ONLY, OutImg.MemSize, nil, @LastError);

//Set parameter for kernel call
LastError := clSetKernelArg(CLKernel, 0, sizeof(cl_mem), @GPUOutMem);   //Output image
LastError := clSetKernelArg(CLKernel, 1, sizeof(integer), @OutImg.Width);
LastError := clSetKernelArg(CLKernel, 2, sizeof(integer), @OutImg.Height);

//Add pointer to memory from images as parameters
for I := 0 to MaxImg do
begin
  LastError := clSetKernelArg(CLKernel, I+3, sizeof(cl_mem), @GPUInMems[I]);
end;

//Specify Group and Grid sizes
GlobalWSize[0]:= (OutImg.Width div 512 + 1) * 512; //Calc groups needed for resolution
LocalWSize[0] := 512; //Max WorkItems per group possible

//Execute and transfer ouput to host memory
LastError := clEnqueueNDRangeKernel(CLQueue, CLKernel, 1, nil, @GlobalWSize, @LocalWSize, 0, nil, nil);
LastError := clEnqueueReadBuffer(CLQueue, GPUOutMem, CL_TRUE, 0, OutImg.MemSize, OutImg.Memory, 0, nil, nil);

//Write output
OutImg.SaveFile('C:\Test\CLTestOut.bmp');

Kernel:

__kernel void MainKernel(
    __global uchar* ret,
    int xRes,
    int yRes,
    __global uchar* I0,
    __global uchar* I1,
    __global uchar* I2,
    __global uchar* I3,
    __global uchar* I4)
    {
            //Get line position
            int y = get_global_id(0);

            //Check inbound
            if (y >= yRes) return;

            //Set pointers to position
            ret += xRes * y;
            I0 += xRes * y;
            I1 += xRes * y;
            I2 += xRes * y;
            I3 += xRes * y;
            I4 += xRes * y;

            //Set val for each pixel in line
            for (int x = 0; x < xRes; ++x)
            {
              ret[x] = (I0[x] + I1[x] + I2[x] + I3[x] + I4[x]) / 5 ;
            }
    }

It would be great if somebody can tell me, why it is not working with more than 9 Images and why I don’t get an errorcode.

Thanks for any help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T19:03:42+00:00Added an answer on May 22, 2026 at 7:03 pm

    The Kernel Args SHOULD be static.
    Use a struct to load all your images, or maybe load all of them in an array form, and add some Args to the kernel setting the length of every image. To be able to separate inside the kernel each image.

    I’ve seen lots of people that gets errors using 10+ Kernel Args.

    Also as “Eric Bainville” said. You should add the images as a vector. Since you don’t do any special procesing to the rows or cols.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am totally new to programming and to some new technologies. Right now I
Right now, I have two Eclipse projects - they both use Maven 2 for
Right now, my SVN repository is on my laptop's HDD (although I use a
I am programming an app that eventually will have several Activities. Right now, however,
For a problem that I'm working on right now, I would like a reasonably
If you were programming a small database application in .NET 2008 right now would
I'm developping a website to train students for programming contest. Right now the website
Right now, I keep all of my projects on my laptop. I'm thinking that
Right now, I'm particularly interested in reading the data from MP3 files (ID3 tags?),
Right now my ant task looks like. <javadoc sourcepath=${source} destdir=${doc}> <link href=http://java.sun.com/j2se/1.5.0/docs/api/ /> </javadoc>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.