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 8485363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:37:21+00:00 2026-06-10T20:37:21+00:00

If a variable is passed to kernel with CL_MEM_USE_HOST_PTR, does it mean any change

  • 0

If a variable is passed to kernel with CL_MEM_USE_HOST_PTR, does it mean any change to the variable in the device would be also shown in host memory?

I am in a scenario where I am using CPU as the device instead of GPU, so everything passed to kernel will be marked with CL_MEM_USE_HOST_PTR.

If this is true, then I no longer need to read everything back to host, which is very convenient.

  • 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-10T20:37:23+00:00Added an answer on June 10, 2026 at 8:37 pm

    Your understanding is correct, except one possible pitfall: documentation states that

    OpenCL implementations are allowed to cache the buffer contents
    pointed to by host_ptr in device memory. This cached copy can be used
    when kernels are executed on a device.

    This means that changes to data performed by kernel might not be immediately reflected in host_ptr. In fact, there is no guarantee that host_ptr contains valid data while it is used for buffer.

    In order to have valid and up-to-date data you must force synchronization. The offcial documentation is a little vague about this moment, but buffer mapping/unmapping definetly works:

    If the buffer object is created with CL_MEM_USE_HOST_PTR set in
    mem_flags, the host_ptr specified in clCreateBuffer is guaranteed to
    contain the latest bits in the region being mapped when the
    clEnqueueMapBuffer command has completed; and the pointer value
    returned by clEnqueueMapBuffer will be derived from the host_ptr
    specified when the buffer object is created.

    Here is an example adapted from Khronos group forum post:

    cl_mem device_output = clCreateBuffer(context, CL_MEM_READ_WRITE | CL_MEM_USE_HOST_PTR, size, original_output, NULL);
    // run the kernel
    void* pointer = clEnqueueMapBuffer(queue, device_output, CL_TRUE, CL_MAP_READ, size, 0, 0, NULL, NULL, NULL);
    // work with 'original_output'
    clEnqueueUnmapMemObject(queue, device_output, pointer, 0, NULL, NULL);
    clReleaseMemObject(device_output);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using a global variable say d_myVar, which will be allocated device memory
How to change value of variable passed as argument in C? I tried this:
Is there any way to determine the type of a variable passed as an
if there is a volatile variable passed in a function something like below... Does
How does php access a variable passed by JQuery? I have the following code:
I need to parse any variable passed to any static page in Prestashop and
i want to change my variable passed as argument to this function: bool verifyStudent(string
Is there a way to determine the type of variable passed to a template
I know, I know, sounds silly, but I am having this one variable passed
Possible Duplicate: Finding the Variable Name passed to a Function in C# In C#,

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.