Open CL Snippets (search for examples)

   2615   13   2
User Avatar
Member
14 posts
Joined: Jan. 2019
Offline
I'm very interested in working with OpenCl in SOP.
What was shown on ( Open CL Snippets demo [www.sidefx.com] ) this link looks very interesting! However, the subtleties of language use are not entirely clear.
I only found this link ( OpenCL for VEX users [www.sidefx.com] ) which clears up the details to some extent.
Are there a number of examples of use somewhere?
User Avatar
Member
35 posts
Joined: Feb. 2016
Offline
Here's an example comparison I did to test how fast the improved OpenCL SOP can be. To be honest I am a bit disappointed, as VEX is clearly the winner among those 3 different ways do displace a grid. Not sure if I did something wrong or inefficient. The OpenCL Code is very simple but shows how to bind incoming attributes and displace along Normals.

With VEX I get Draw Time around 30 FPS
OpenCL clocks in at 16 FPS
and last but not least SoftPeak at 27FPS
Edited by Yader - Nov. 11, 2023 05:07:52

Attachments:
Screenshot 2023-11-11 110025.png (447.8 KB)
OpenCL-VEX-SOP_v001.hiplc (174.7 KB)

https://behance.net/derya [behance.net]
User Avatar
Member
14 posts
Joined: Jan. 2019
Offline
Yader
Here's an example comparison I did to test how fast OpenCL can be. To be honest I am a bit disappointed, as VEX is clearly the winner among those 4 different ways do displace a grid. Not sure if I did something wrong or inefficient. The OpenCL Code is very simple but shows how to bind incoming attributes and displace along Normals.

With VEX I get Draw Time around 30 FPS
OpenCL clocks in at 16 FPS
and last but not least SoftPeak at 27FPS

Thanks for the answer! Yes, I also put together a similar example (moving the grid), and as a result, Open CL performance approached VEX performance only when using millions of points. I think this is not the best scenario when using this node. I think that a lot of time is spent on compilation and other side operations, and that the real gain can be obtained when a long complex algorithm is executed inside OpenCl.

It seems to me that a task that will be performed well in Open Cl must involve intensive work with memory, since video memory is usually many times faster.
User Avatar
Member
4595 posts
Joined: Feb. 2012
Offline
OpenCL is more suited when you have complex calculations per point or per voxel especially with high number of iterations.

Things like volume convolution, volume blur, volume sharpen, any COP-like filters, mesh smoothing, etc.



For example if you implement the same paper for the Smooth SOP using OpenCL, it will most likely dominate the C++ version in performance but it would require a linear solve, etc. Implementing this in OpenCL without using external libraries would be quite challenging so you could try using the new Linear Solver SOP:
https://www.sidefx.com/docs/houdini/nodes/sop/linearsolver.html [www.sidefx.com]

But then you will lose out some of the GPU gains.
Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]

youtube.com/@pragmaticvfx | patreon.com/animatrix | pragmaticvfx.gumroad.com
User Avatar
Member
14 posts
Joined: Jan. 2019
Offline
animatrix_
OpenCL is more suited when you have complex calculations per point or per voxel especially with high number of iterations.
Could you please advise what I can read to better understand how to use OpenCl in HOUDINI, as well as the syntax for the OpenCl SOP node itself? (except for the links that I already provided in the first post). Perhaps you know where I can find examples of use?
User Avatar
Member
4595 posts
Joined: Feb. 2012
Offline
Alt_stage
animatrix_
OpenCL is more suited when you have complex calculations per point or per voxel especially with high number of iterations.
Could you please advise what I can read to better understand how to use OpenCl in HOUDINI, as well as the syntax for the OpenCl SOP node itself? (except for the links that I already provided in the first post). Perhaps you know where I can find examples of use?

The best resource is from SideFX. You can search the Houdini install directory for *.cl files. That should already be thousands of lines of code. Sometimes SESI uses OpenCL code snippets for example in nodes like Attribute Blur SOP, and sometimes it's mixed for example in Shallow Water solver SOP.

After that you can look into more GPU based resources like GPU Gems:
https://developer.nvidia.com/gpugems/gpugems/contributors [developer.nvidia.com]

You can try to adapt these examples to OpenCL and whatever else you want to solve.

I might also release an advanced OpenCL course called Pragmatic OpenCL for Houdini in the future, possible after Pragmatic VEX: Volume 2 or 3
Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]

youtube.com/@pragmaticvfx | patreon.com/animatrix | pragmaticvfx.gumroad.com
User Avatar
Member
900 posts
Joined: Feb. 2016
Offline
As far as I understand (correct me if I'm wrong) the issue with this OpenCL Sop is that it's missing all the super useful vex functions and you have to implement the logic from scratch, which might be daunting.
Edited by Andr - Nov. 11, 2023 09:07:08
User Avatar
Member
4595 posts
Joined: Feb. 2012
Offline
Andr
As far as I understand (correct me if I'm wrong) the issue with this OpenCL Sop is that it's missing all the super useful vex functions and you have to implement the logic from scratch, which might be daunting.

Yes that's one of the major challenges when using OpenCL over VEX. You are out of luck if you want to perform arbitrary ray intersections against a polygonal geometry like you do using intersect VEX function. AFAIK SideFX doesn't have any plans to implement this in OpenCL.
Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]

youtube.com/@pragmaticvfx | patreon.com/animatrix | pragmaticvfx.gumroad.com
User Avatar
Member
14 posts
Joined: Jan. 2019
Offline
animatrix_
The best resource is from SideFX. You can search the Houdini install directory for *.cl files. That should already be thousands of lines of code. Sometimes SESI uses OpenCL code snippets for example in nodes like Attribute Blur SOP, and sometimes it's mixed for example in Shallow Water solver SOP.

Thanks, this is a valuable source!
What do you think about the built-in macros in the OpenCl SOP node that can be activated by clicking the "Enable @-Binding" checkbox? Does it make sense to understand how to use them or is it better to immediately learn pure OpenCl? What do you think about the performance when using these macros?
User Avatar
Member
4595 posts
Joined: Feb. 2012
Offline
Alt_stage
What do you think about the built-in macros in the OpenCl SOP node that can be activated by clicking the "Enable @-Binding" checkbox? Does it make sense to understand how to use them or is it better to immediately learn pure OpenCl? What do you think about the performance when using these macros?

They are great. SESI did a great job in making the OpenCL syntax higher level so people can write the same code faster and the same equivalent code without the new changes would be a lot more verbose.

The vast majority of the code examples in Houdini is using the old syntax so you are better off learning that first and understanding OpenCL before you can jump to the new syntax. Gradually you can try to introduce the new syntax to your code so you can memorize it.

As for performance these are using the macro pre-processing which occurs before the actual compilation phase in programming, so they are unlikely to impact runtime performance.
Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]

youtube.com/@pragmaticvfx | patreon.com/animatrix | pragmaticvfx.gumroad.com
User Avatar
Member
32 posts
Joined: Aug. 2011
Online
Can't find much info on the new syntax. Are there any docs available somewhere?
User Avatar
Member
4595 posts
Joined: Feb. 2012
Offline
SESI added some nice examples under the presets:

Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]

youtube.com/@pragmaticvfx | patreon.com/animatrix | pragmaticvfx.gumroad.com
User Avatar
Member
14 posts
Joined: Jan. 2019
Offline
animatrix_
SESI added some nice examples under the presets:
I tried to reproduce the code from the OpenCL examples on VEX.
I conducted performance testing, and noticed that the OpenCL code in the best case (tens of millions of points) has 2 times worse performance than VEX. As the number of points decreases, the gap increases.

Testing was carried out on a laptop with an Nvidia GTX 1060, 6GB VRAM, 1280 CUDA cores video card and an Intel i7 8750H processor (6 cores - 3.3 -3.8 GHz boost freq.) .

What do you think is the reason for the lack of performance advantage of OpenCL over VEX?
Perhaps this is a sign that I have incorrect settings (In the settings, the device for executing OpenCL is 1060), or the video card performance is not enough to unlock the potential of OpenCl? Or maybe this OpenCL code from the example should not demonstrate the benefits of OpenCL, but is intended only to demonstrate the syntax?

Attachments:
OpenCl.PNG (30.5 KB)
VEX.PNG (14.1 KB)

User Avatar
Member
264 posts
Joined: Jan. 2013
Online
With this example it is very difficult to see the benefits of using OpenCL because there is no processing of large amounts of data for each point and a lot of time is spent on the fact that we have to transfer data on the bus through global memory from the CPU to the device's GPU and back, and this can be slow.

As animatrix_ wrote above the best way to understand where this has a big benefit is to look at where the OpenCL node is used. The most typical use cases you can find for example inside HDA: AttribBlur, Heightfield Blur, Heightfield Erode, etc.
  • Quick Links