cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

adityagadre
Journeyman III

Kernel Process Communication

I have a scenario in which I want OpenCL kernel to wait in between and want to execute a piece of code in normal process(could be the host process) and resume the kernel execution after the function in the process completes. What are the ways in which a host process and OpenCL Kernel can communicate(synchronize) with each other? Please if possible provide the links to suitable tutorials.

Thanks in advance.

 

0 Likes
11 Replies
nou
Exemplar

this is not possible. you must break kernel in two parts.

0 Likes

write the code in two different kernel.

clEnqueueNDRangeKernel(Kernel1,...)

clFinish()

HostCode()

clEnqueueNDRangeKernel(Kernel2,...);

If the host code do not depend on the KErnel1 you can execute  it concurrently with kernel1 using another thread.This can speed up the execution.

0 Likes

Is it technically feasible to implement such a functionallity using shared memory? (i.e. Implement customized synchronization mechanism)

0 Likes

Hi adityagadre,
I am not sure I understood your question completely.
If you are asking, whether customized synchronization of clEnqueue Commands are possible or not. The answer is yes. It can be done using command barriers and Events.
Refer to openCL computing Guide Page 14.

0 Likes

Actually I mean implementing synchronization the way it is implemented in operation systems. By using shared memory and setting resetting variables.

Can memory be shared between host process and the OpenCL kernel whicle both should be able to access it simultaneously?

0 Likes

this is not possible. not in a way that OpenCL support.

0 Likes

AFAIK Memory is always created on the same device on which kernel needs to be executed.A common memory as such will slow down one of the kernel beyond recovery.

0 Likes

If an OpenCL kernel and a process cannot communicate during execution, the how does the printf in the OpenCL kernel works? I suppose it should do the same thing to send the text to the terminal.

0 Likes

hi adityagadre,

AFAIK printf function has its buffer on GPU device or device  accessible host memory.The buffer will be flushed to the host output stream only at the time of kernel finish.So there is no communication between host process and kernel during execution.

0 Likes

This sort of reassembles my thought about host memory and clCreateBuffer(), especially the flags CL_MEM_USE_HOST_PTR, CL_MEM_ALLOC_HOST_PTR and CL_MEM_COPY_HOST_PTR.

Having some struggle to visualize when to use the different flags and what the different advantages are. Is copy_host_ptr just a clCreateBuffer() followed by a clEnqueueWriteBuffer()?

Some examples to clarify when and how to use these on ATI Stream SDK would be appreciated! Thanks.

0 Likes

hi eklund.n,

AFAIK these flags have these significancies:

CL_MEM_USE_HOST_PTR:Most suitable when you need to create the buffer on kernel executing device with relevent data in it.It can act as input to the kernel.If kernel executing device is host only no second buffer is created in this case.

CL_MEM_ALLOC_HOST_PTR:We dont need to create any permanent host buffer to be supplied as data input to clCreateBuffer function.Buffer is uninitilized so it might be possible that no data transfer over PCIe bus is required.A memory block can be allocated on Kernel executing device's global memory and named as the buffer name specified.Use it when just uninitialized memory is needed.

CL_MEM_COPY_HOST_PTR:There might be some situation where the algorithm will change the contents of the buffer input and we might need original contents as well.Usung copy host ptr will create another copy of buffer on host for buffer protection.

Please refer to openCL spec for more info.

Thanks

0 Likes