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

  • Home
  • SEARCH
  • 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 8221841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:04:26+00:00 2026-06-07T14:04:26+00:00

I have stored the text in char array a[textLength], and pattern in an array

  • 0

I have stored the text in char array a[textLength], and pattern in an array b[patternLength]

cl_char *a = (cl_char *) malloc(textLength*sizeof(cl_char));

for(int i =0; i<textLength;i++)
{
    a[i]=text[i];
    }

// A buffer object is a handle to a region of memory
cl_mem a_buffer = clCreateBuffer(context,
                                 CL_MEM_READ_ONLY | // buffer object read only for kernel
                                 CL_MEM_COPY_HOST_PTR, // copy data from memory referenced
                                 // by host pointer
                                 textLength*sizeof(cl_char), // size in bytes of buffer object
                                 a, // host pointer
                                 NULL); // no error code returned

// for text and pattern kernal arguments
cl_char *b = (cl_char *) malloc(patternLength*sizeof(cl_char));

for(int i =0; i<patternLength;i++)
{
   b[i]=pattern[i];
}

// A buffer object is a handle to a region of memory
/*cl_mem b_buffer = clCreateBuffer(context,
                                 CL_MEM_READ_ONLY | // buffer object read only for kernel
                                 CL_MEM_COPY_HOST_PTR, // copy data from memory referenced
                                 // by host pointer
                                 patternLength*sizeof(cl_char), // size in bytes of buffer object
                                 b, // host pointer
                                 NULL); // no error code returned */
cl_mem b_buffer = NULL;


    clSetKernelArg(kernel, 0, sizeof(a_buffer), (void*) &a_buffer);
clSetKernelArg(kernel, 1, sizeof(cl_mem), NULL);
clSetKernelArg(kernel, n, sizeof(cl_mem), &b_buffer);
    size_t global_work_size = numberofWorkItem;
    cl_int error= clEnqueueNDRangeKernel(queue, kernel,
                       1, NULL, // global work items dimensions and offset
                       &global_work_size, // number of global work items
                       &patternLength, // number of local work items
                       0, NULL, // don't wait on any events to complete
                       &timeEvent); // no event object returned

 I have read that in clSetKernelArg, for __local indentifiers, the arg_value should be NULL. I have done that by doing b_buffer=NULL;

But doing that would prevent the b_buffer from storing the value of b[] (pattern)
How do I do it??

Also,
If I am not wrong, the local_work_size can not be greater than the value given by CL_DEVICE_MAX_WORK_ITEM_SIZES. Because the local_work_size is constrained by the underlying device/hardware.
The global_work_size, on the other hand, can be as big as one wants.
Does it have to be a multiple of local_work_size ???
If yes, why??

  • 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-06-07T14:04:28+00:00Added an answer on June 7, 2026 at 2:04 pm

    Your error is in the clSetKernelArg line:

    //incorrect
    clSetKernelArg(kernel, n, sizeof(cl_mem), &b_buffer);
    
    //correct
    clSetKernelArg(kernel, n, sizeof(cl_char)*patternLength, NULL);
    

    Local memory is cleared after kernel execution, so you won’t be able to get a copy of b_buffer using your method. Also, local memory is not assigned by the host. You need to copy from a global parameter to get it into the LDS.

    To get the local data copied, you need to pass in a global cl_mem as well as the local parameter. The copy can be done at the end of the kernel and red back to the host with clEnqueueReadBuffer.

    Update

    Here’s a specific example of how to use a dynamic local buffer, and assign it the contents of a global buffer.

    __kernel void copyBufferExample(__global int* srcBuff, __local int* localBuff, const int copyCount)
    {
        int lid = get_local_id(0);
        int ls = get_local_size(0);
        int i;
    
        for(i=lid; i<copyCount; i+=ls){
            localBuff[i] = srcBuff[i];
        }
    
        //use localBuff here
        //copy result back to global memory if needed
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have CSV text thats stored in the session array as csv. The lines
I have a char array, which is stored vertically, such as stringarray ab cd
I have stored values retrieved from a text file into an array. Now am
I have text stored in SQL as HTML. I'm not guaranteed that this data
I have some text stored in the body field of a custom content type
I have some text stored in a variable which contains some HTML. For example,
I have a column stored as text, this column is mainly full of numeric
If I have a text stored in db, file, resource does not matter: <code><%=
I have stored page contents (tables, plain text, images and paragraphs) into a variable.
I have some financial values stored as text in a mysql db. the significance

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.