OpenCL bind matrix3

   Views 1320   Replies 12   Subscribers 2
User Avatar
Member
100 posts
Joined: 11月 2019
Offline
I have been reading Houdini's OpenCL documentation and haven't really found a way of correctly binding an existing matrix3 attribute.
Trying this when having an matrix3 @xform in the input:

#bind point &xform mat3

I am getting the "Unknown token 'mat3'" warning. What would be the correct way of doing so?
User Avatar
Member
102 posts
Joined: 5月 2013
Offline
I'm also trying to figure out some OpenCL matrix stuff and have tried mat3 and mat4 (unsuccessfully).

When binding a volume, if you enable 'Volume transform to Voxel' you get a 4x4 matrix which is a float16...
If you try #bind point &xform float9 it doesn't throw an error or a warning but googling I can't find anything about float9...
Edited by j00ey - 2025年1月6日 08:44:51
User Avatar
Member
102 posts
Joined: 5月 2013
Offline
from a bit more digging around this appears to work (I'm in the habit of using the name 'transform' for a 3x3 and 'xform' for 4x4):

#bind point &transform float3x3

I'm struggling though to access the components of it. I can get the first 3 with either :

@transform.x, @transform.y, @transform.z
or
@transform.[0], @transform.[1], @transform.[2]
- but 3 and upwards doesn't seem to work.
Also
transform[0,0] [0,1] and [0, 2]
work - I thought maybe that would be row 0, col 0 etc but then after those first 3 it doesn't work either...

Btw depending what you're trying to do with the 3x3 I managed to use the rotation part of a 4x4 like this (where xform is a 4x4 point attrib):


// Bind writable position:
#bind point &P float3
#bind point &xform float16

@KERNEL
{
    float3 pos = @P;
    float4 pos4 = pos.x * @xform.lo.lo +
                  pos.y * @xform.lo.hi +
                  pos.z * @xform.hi.lo +
                  1 * @xform.hi.hi;
                  
    float3 new_pos = (float3)(pos4.x, pos4.y, pos4.z);

    @P.set(new_pos);
}
Edited by j00ey - 2025年1月6日 10:25:07
User Avatar
Member
100 posts
Joined: 11月 2019
Offline
At this point I am just trying to get to work with matrices in OpenCL. I mostly want to understand the syntax, specifically in the @-Binding, but I feel like not everything is covered in the documentation. I will be still going to pure OpenCL to get better insights.

Pretty cool findings! Thanks so much. I will post any useful thing I discover here too.
User Avatar
Member
102 posts
Joined: 5月 2013
Offline
Yes please do, I'll do the same. There's also a bit more info in another thread I started here in case useful:

https://www.sidefx.com/forum/topic/99305/ [www.sidefx.com]
User Avatar
Member
102 posts
Joined: 5月 2013
Offline
Also here's a thread about using matrices in OpenCL in COPs

https://www.sidefx.com/forum/topic/99150/ [www.sidefx.com]
User Avatar
Member
23 posts
Joined: 1月 2022
Offline
Try @transform.xx, @transform.yz, @transform.xz
User Avatar
Member
102 posts
Joined: 5月 2013
Offline
I tried that, doesn't work unfortunately.
User Avatar
Member
23 posts
Joined: 1月 2022
Offline
@transform.w
User Avatar
Member
102 posts
Joined: 5月 2013
Offline
nope tried that too
User Avatar
Member
23 posts
Joined: 1月 2022
Offline
I think your handwriting is irregular
Edited by 444366454 - 2025年1月7日 04:25:02

Attachments:
Snipaste_2025-01-07_17-22-33.png (93.9 KB)

User Avatar
Member
102 posts
Joined: 5月 2013
Offline
I'm still finding my way around OpenCL so all I can say is what works for me.

.w works for float4 but not for float3x3. I was trying to get at the 3 rows of a 3 x 3 matrix. The docs say there is a mat3, though also -

"There is no native 9-element type. The mat3 we have defined is actually a 12-element type, so care has to be done to move it to or from memory."

If I declare a mat3 inside my kernel I can get at the rows using
[0], [1] and [2]
However if I try to bind a mat3 it gives the warning "Unknown token 'mat3'."
If I bind a float3x3 it doesn't error but using either
tuple[0]
or
.x
just gives me the first element of the matrix, not the first row.

.w errors
Edited by j00ey - 2025年1月9日 05:46:02

Attachments:
Screenshot 2025-01-09 081236.png (35.4 KB)

User Avatar
Member
133 posts
Joined: 6月 2019
Offline
I've also recently worked with matrices in opencl houdini context.
Here is some info:
- float3x3 is probably just a bug and interprets as float3 (I can do bind point &P float3whateverand it still works
- mat3 is an alias to float3[3]and mat4 is float16which can be confusing. mat3 is basically an array and mat4 is builtin vector type
- mat3 being an array of float3 should be used carefully. it's not continuous in memory because float3 is actually 4 floats. you can't just copy float[9]for example
- there are many useful functions in matrix.h that compatible with vex row-major matrix, you should check them and use it when you interop with something coming from sops
- to bind 3x3 matrix you should use float9token on binding (which is illegal type as stated in docs so it became float[9]- an array)
- to construct mat3 from float[9]use mat3load

check this simple example above with the same transfrom in vex and opencl
Edited by elovikov - 2025年1月17日 16:02:42

Attachments:
cl-mat3.hiplc (106.0 KB)

  • Quick Links