Hi,<br><br>The itkGPUDataManager is a simple wrapper around CPU <-> GPU buffers with some support for synchronization logic.<br>In order to share the same CPU->GPU block of memory across multiple kernels follow the same recipe<br>
that was used for the itkGPUResampleImageFilter.<br><br>Some pseudo code below:<br><br>1. Create the data manager<br><br>typename GPUDataManager::Pointer m_MyBuffer;<br>m_MyBuffer = GPUDataManager::New();<br><br>m_MyBuffer->Initialize();<br>
m_MyBuffer->SetBufferFlag( CL_MEM_READ_WRITE ); // or use CL_MEM_READ_ONLY, if only will be used for read operations<br>m_MyBuffer->SetBufferSize( mem_size_MB ); // size of your buffer<br>m_MyBuffer->Allocate();<br>
<br>There is nothing yet in this buffer, you could fill it on GPU side for example.<br>You could also fill it beforehand with some values on CPU side and then copy to GPU.<br>If you want to fill it with something on CPU side then do this.<br>
<br>m_MyBuffer->SetCPUBufferPointer( ... );<br>m_MyBuffer->SetGPUDirtyFlag( true );<br>m_MyBuffer->UpdateGPUBuffer();<br><br>2. Define two kernel managers (also possible with only one using different kernel handles)<br>
<br>typedef typename GPUKernelManager::Pointer GPUKernelManagerPointer;<br>GPUKernelManagerPointer m_AKernelManager;<br>GPUKernelManagerPointer m_BKernelManager;<br><br>3. Create handles<br>m_AHandle = m_AKernelManager->CreateKernel( "OpenCLFilterA" ); // Your OpenCL code A<br>
m_BHandle = m_BKernelManager->CreateKernel( "OpenCLFilterB" ); // Your OpenCL code B<br><br>4. Set kernels with this block of memory<br>m_AKernelManager->SetKernelArgWithImage( m_AHandle, argidx++, m_MyBuffer ); // Confusing sometimes, should be called buffer or something like it.<br>
m_BKernelManager->SetKernelArgWithImage( m_BHandle, argidx++, m_MyBuffer ); // Confusing sometimes, should be called buffer or something like it.<br><br>5. Lunch the kernel B after kernel A using OpenCLEvent and OpenCLEventList in synchronize way.<br>
<br>OpenCLEventList eventList;<br><br>OpenCLEvent AEvent = m_AKernelManager->LaunchKernel( m_AHandle, eventList );<br>eventList.Append( AEvent );<br><br>OpenCLEvent BEvent = m_BKernelManager->LaunchKernel( m_BHandle, eventList );<br>
eventList.Append( BEvent );<br><br>eventList.WaitForFinished();<br><br>6. Inside the OpenCL kernel called 'OpenCLFilterA' you could fill it with some values or reuse the ones defined on CPU side.<br>When the kernel 'OpenCLFilterB' has been launched, retrieve this values, compute something else and put them back to the same buffer or to the output buffer.<br>
<br>That is it, Good luck. <br>Denis<br><br><div class="gmail_quote">On Wed, Feb 20, 2013 at 2:42 PM, Joachim Weber <span dir="ltr"><<a href="mailto:joachim.weber@stud.hs-regensburg.de" target="_blank">joachim.weber@stud.hs-regensburg.de</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">Thanks for that fast answer.<br>
<br>
1. I've already implemented my own version of an Gaussian Filter, according to FSL-Fast.<br>
2. I've looked into itkGPUDataManager. How is that done? Is it necessary to set a certain OpenCL flag for this?<br>
Normally it is recommended, just to create an cl_mem object and to set certain flags for that.<br>
I don't find any information, how to do this. It looks like, if I set up the GPUDataManger for each GPUImage right,<br>
I can achieve exactly that, what I want to. But I am not sure...<br>
<br>
Regards<br>
Weber Joachim<br>
________________________________________<br>
From: Denis Shamonin [<a href="mailto:dshamoni@gmail.com">dshamoni@gmail.com</a>]<br>
Sent: Wednesday, February 20, 2013 10:00 AM<br>
To: Joachim Weber<br>
Cc: <a href="mailto:insight-users@itk.org">insight-users@itk.org</a><br>
Subject: Re: [Insight-users] Question about using OpenCL shared buffer for more than one kernel<br>
<br>
Dear Weber,<br>
<br>
1. I've implemented the Gaussian Filter<br>
itkGPURecursiveGaussianImageFilter and itkGPUSmoothingRecursiveGaussianImageFilter<br>
in my paper <a href="http://hdl.handle.net/10380/3393" target="_blank">http://hdl.handle.net/10380/3393</a> have a look to the article.<br>
2. Yes, the memory could be copied only once from CPU->GPU and used by the multiple kernels via pointers, use itkGPUDataManager for that.<br>
<br>
Regards,<br>
<br>
-Denis Shamonin, MSc<br>
Division of Image Processing (LKEB)<br>
Department of Radiology<br>
Leiden University Medical Center<br>
<br>
On Wed, Feb 20, 2013 at 12:02 AM, Joachim Weber <<a href="mailto:joachim.weber@stud.hs-regensburg.de">joachim.weber@stud.hs-regensburg.de</a><mailto:<a href="mailto:joachim.weber@stud.hs-regensburg.de">joachim.weber@stud.hs-regensburg.de</a>>> wrote:<br>
Hi,<br>
i want to write a Gaussian Filter with ITK-GPU. I have a 3D image, which has to be filtered in all 3 directions(first Z, then X and then Y).<br>
Because ITK encapsulates the whole OpenCL functionality inside its on methods and classes, I find it very hard to define memory objects for multiple kernels.<br>
It don't want to copy the image between Host and Device the whole time, which would result in a heavy performance drawback.<br>
Is there a simple way to define OpenCL memory objects, which can be used by multiple kernels?<br>
I am not to much into ITK GPU, but it looks like, defining memory buffers for multiple kernels(which stay on Device) is not possible right now.<br>
Or do all kernels run in the same context?<br>
<br>
<br>
Many thanks in advance,<br>
Weber Joachim<br>
_____________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><<a href="http://www.kitware.com" target="_blank">http://www.kitware.com</a>><br>
<br>
Visit other Kitware open-source projects at<br>
<a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Kitware offers ITK Training Courses, for more information visit:<br>
<a href="http://www.kitware.com/products/protraining.php" target="_blank">http://www.kitware.com/products/protraining.php</a><br>
<br>
Please keep messages on-topic and check the ITK FAQ at:<br>
<a href="http://www.itk.org/Wiki/ITK_FAQ" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a><br>
<br>
</div></div>_____________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<div class="HOEnZb"><div class="h5"><br>
Visit other Kitware open-source projects at<br>
<a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Kitware offers ITK Training Courses, for more information visit:<br>
<a href="http://www.kitware.com/products/protraining.php" target="_blank">http://www.kitware.com/products/protraining.php</a><br>
<br>
Please keep messages on-topic and check the ITK FAQ at:<br>
<a href="http://www.itk.org/Wiki/ITK_FAQ" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a><br>
</div></div></blockquote></div><br>