cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

notyou
Adept III

USE_HOST_PTR with dynamic array?

Jump to solution

I have a piece of code that I'm trying to optimize for an APU that looks something like this:

float* temp = new float; // some size x determined at runtime

// create/copy values into temp

// sizeof * x needs to be used since it doesn't get the size of temp from *temp

cl_buffer = clCreateBuffer(context, CL_MEM_USE_HOST_PTR, sizeof(*temp) * x, &temp, &error);

clEnqueueMapBuffer(cmd_queue, cl_buffer, CL_TRUE, CL_MAP_READ, 0, sizeof(*temp) * x, 0, NULL, &cmd_event, &error);

but this gives me incorrect results compared to the version which just uses on-device buffers. I believe the issue is with &temp not pointing to the full array (it also works with a static array if I use a host pointer). Can anyone correct my understanding on how to use USE_HOST_PTR with a dynamic host pointer (if this is even possible)? Thanks.

Matt

0 Likes
1 Solution

Accepted Solutions
notyou
Adept III

Re: USE_HOST_PTR with dynamic array?

Jump to solution

Just wanted to reply and say that I was getting incorrect results because I was using &temp instead of just temp.

View solution in original post

3 Replies
himanshu_gautam
Grandmaster

Re: USE_HOST_PTR with dynamic array?

Jump to solution

Why do you need the clEnqueueMapBuffer Command? Are you reading the contents of the host_ptr as generated by this API for checking correctness?

I do not see anything wrong in your code snippet. Probably you should check the error status. You can also attach your testcase as a zip file.

0 Likes
notyou
Adept III

Re: USE_HOST_PTR with dynamic array?

Jump to solution

Isn't clEnqueueMapBuffer required when using a host pointer? My code currently uses device memory but I'm trying to get it to use host memory since there are a large number of data transfers and the size is changing every iteration. I have checked the error status and I'm not seeing anything come up saying there is a noted error. I'll do some more research into this tonight and try to post a small test case.

0 Likes
notyou
Adept III

Re: USE_HOST_PTR with dynamic array?

Jump to solution

Just wanted to reply and say that I was getting incorrect results because I was using &temp instead of just temp.

View solution in original post