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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:05:29+00:00 2026-06-12T14:05:29+00:00

I have a situation where I (might) want to try using a std::vector (or

  • 0

I have a situation where I (might) want to try using a std::vector (or more precisely its storage) as host pointer for an opencl buffer object with CL_MEM_USE_HOST_PTR. This has obviously problems if the vector is resized and therefore reallocates its memory. The modifications to my vector are during phases of the program, where the buffer is not used, so my idea is that I check if the host pointer of the buffer is identical to the pointer to the first element of the vector and recreate the buffer if that is not the case. My problem is that I haven’t been able to find out if it is legal to have a buffer, for which the host-pointer has already been deallocated, if the buffer isn’t used.

I could of course destroy the buffer at the end of the phase where it is used, however I don’t know in advance if the vector contents and/or length are modified and if they aren’t I would rather keep the old buffer, since afaik that would enable it to stay cached on the device, reducing the amout of data needed to be transferred over the pci-e bus.

My question is: Is it allowed to have an opencl buffer with CL_MEM_USE_HOST_PTR for which the host pointer has already host pointer been deleted, if the buffer object only exists, but isn’t used in a kernel.

For the record I’m currently developing against nvidias opencl implementation, using a Tesla 2070 as a gpu and the software will probably be ported to amd gpus/cpus in the near future (the later being the main reason to use CL_MEM_USE_HOST_PTR). So if the answer is implementation specific, those are the primary targets, though I’m really more interested in the general answer, since I don’t know what else it will run on at later times.

  • 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-12T14:05:30+00:00Added an answer on June 12, 2026 at 2:05 pm

    I believe it would be safer if you did not try to change the buffer underneath the OpenCL implementation. As you suggested this would likely bring problems. For instance:

    vector<int> v(25);
    cl_mem buf = clCreateBuffer(.v.data(),.CL_MEM_USE_HOST_PTR,...);
    v.resize(1000); //Or some other way of changing the size of the stack
    clReleaseMemObject(buf);
    

    When the memory is released it will attempt to sync the data back to the original buffer (which has been deallocated) likely causing a segfault or some other nasty memory problems.

    According to some discussion on this thread, it should be assumed that as soon as you call the clCreateBuffer with the CL_MEM_USE_HOST_PTR flag that you have ceded control of that memory to the OpenCL platform and you can only reclaim that memory with a call to release that memory buffer.

    While it is possible that in your specific implementation this is not the case, I would think that overall it would be advisable to release the data. That way, if your underlying system changes in the future, you won’t see a bug associated with this behavior.

    Optionally, you could possibly extend the vector class such that on resizes of the underlying data structure, you could release and reallocate data on the device. I’m not sure how difficult this would be, or how much it would affect the rest of your program, though.

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

Sidebar

Related Questions

Situation: I have some persons with certain skills and they can/might belong to more
I have a situation where I might want to search by order number or
In my situation, I have might have userA and userB logged on to google
I have a situation where I might be getting one or both of a
I have a situation where I want to have a stored proc returning a
I have a weird situation, client does't want their application to support multitasking so
I have a situation where I want to connect two tables that do not
I have a situation where I want to convert some XAML to an image,
I have a situation where in MS Dynamics Crm it returns some objects using
What I want to achieve is to have an /etc/init.d script which more reliably

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.