Finding the source code or how the minpos function works

   653   5   0
User Avatar
Member
13 posts
Joined: Jan. 2019
Offline
I wrote a small algorithm in OpenCl and it works really fast. However, part of the entire asset is also VEX code and it runs many times longer than OpenCl. I have determined that the longest running VEX function is "minpos" and I would like to rewrite it in OpenCL as well, however I am not sure how to write it in the most optimal way. Please tell me, can I find the source code for "minpos" in VEX or C++ somewhere, so that I can understand how it works?
User Avatar
Member
4515 posts
Joined: Feb. 2012
Offline
You have to find the source code for xyzdist as minpos is just an alias for xyzdist. But even if you find the source code, it would be extremely hard to implement it using OpenCL in a manner that's optimized for GPU. Performing closest point calculations on arbitrary geometry in OpenCL is not a trivial task.

I asked SESI many times to add this functionality, and they said they didn't have any plans to do so.
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 | animatrix2k7.gumroad.com
User Avatar
Member
13 posts
Joined: Jan. 2019
Offline
animatrix_
I asked SESI many times to add this functionality, and they said they didn't have any plans to do so.

Thanks for your reply!
Over the past few days, I managed to reproduce the minpos functionality on VEX working for polygonal meshes (the task turned out to be quite extensive since edges with points also need to be taken into account). My code at least gives the same result, but it takes much longer than regular minpos with a large number of polygons (I would estimate the complexity as H*J Where H is the number of cells to move, and J is the number of polygons in the target geo). I tried not to use high-level functions and only used cross, dot, normolize, so that the code could be transferred to OpenCl with minimal changes. It's already obvious to me a few places where I can optimize this code in VEX, but I'm not sure how these optimizations will behave in OpenCl. Alas, I don’t know where to find execution time ratings for operations/functions for VEX and OpenCl (You can, of course, create your own rating using the performance tab, but it seems like that’s too much). I also wanted to have some kind of understandable guideline (something like SOLID), so that I could understand what exactly should not be done so as not to critically lose productivity specifically in VEX and OpenCl. If you can suggest something useful, I would be grateful!
Edited by Alt_stage - March 28, 2024 09:39:07
User Avatar
Member
4515 posts
Joined: Feb. 2012
Offline
Alt_stage
animatrix_
I asked SESI many times to add this functionality, and they said they didn't have any plans to do so.

Thanks for your reply!
Over the past few days, I managed to reproduce the minpos functionality on VEX working for polygonal meshes (the task turned out to be quite extensive since edges with points also need to be taken into account). My code at least gives the same result, but it takes much longer than regular minpos with a large number of polygons (I would estimate the complexity as H*J Where H is the number of cells to move, and J is the number of polygons in the target geo). I tried not to use high-level functions and only used cross, dot, normolize, so that the code could be transferred to OpenCl with minimal changes. It's already obvious to me a few places where I can optimize this code in VEX, but I'm not sure how these optimizations will behave in OpenCl. Alas, I don’t know where to find execution time ratings for operations/functions for VEX and OpenCl (You can, of course, create your own rating using the performance tab, but it seems like that’s too much). I also wanted to have some kind of understandable guideline (something like SOLID), so that I could understand what exactly should not be done so as not to critically lose productivity specifically in VEX and OpenCl. If you can suggest something useful, I would be grateful!

I imagine SESI is using acceleration structures like Kd-tree to speed up the queries, otherwise the performance would tank while doing multiple queries or using a high res geometry.

Porting these to OpenCL you would have to use the appropriate data structures like hash grids.

If you can limit the types of geometry, you could reduce the amount of code you have to write. Otherwise xyzdist supports all kinds of geometry like NURBS albeit orders of magnitude slower than polygonal meshes (bug pending).

In any case closest point look ups, point cloud look ups, ray triangle intersections on arbitrary geometry are sorely missing in OpenCL.

As always SESI knows best.
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 | animatrix2k7.gumroad.com
User Avatar
Member
13 posts
Joined: Jan. 2019
Offline
animatrix_
xyzdist as minpos is just an alias for xyzdis
The other day I transferred my version of minpos to OpenCl and the time from 60 seconds decreased to 4.1, standard VEX minpos does the same on the processor in 3.3 seconds. Tested on I7 8750H (turbo boost blocked for tests) and 1060 6G vram. You said that minpos is essentially xyzdist. However, I couldn’t find the source code for it either, if you know where to find it, could you send me the link? It would be interesting to know what difference there is in the logic used.
User Avatar
Member
201 posts
Joined: Jan. 2013
Offline
Well in the LLVM IR view it looks like this

https://godbolt.org/z/jsP4G5sn7 [godbolt.org]
  • Quick Links