Jump to content

How to write velocity clamp in openCL for pyro sim


Ekaterina Sky

Recommended Posts

Hi, I have a openCL question. How can I write a velocity clamp in openCL for pyro sim? In VEX, I write like this:

float speed = length(v@vel);

vector dir = normalize(v@vel);

@vel = dir * clamp(speed, 0, 20); 

However, I have no idea how to write it in openCL for a minimal solver mode. I suceeded to use ChatGPT to write a minor change in exisitng code, but not for a full writing. 

I am expecting to use a Gas openCL node, and not only write a code but also set options, bindings, Generated code tabs. Thus, it would appriciate if someone provide an example hip file. 

Thanks for your assistance!

Link to comment
Share on other sites

here is his answer and the code is working;

kernel void kernelName(
    int stride_x,
    int stride_y,
    int stride_z,
    int stride_offset,
    global float * vel_1, global float * vel_2, global float * vel_3
)
{
    int gidx = get_global_id(0);
    int gidy = get_global_id(1);
    int gidz = get_global_id(2);
    int xres = get_global_size(0);
    int yres = get_global_size(1);
    int zres = get_global_size(2);
    int idx = stride_offset + gidx * stride_x + gidy * stride_y + gidz * stride_z;
    float3 vel = (float3)(vel_1[idx], vel_2[idx], vel_3[idx]);
    float speed = length(vel);
    float3 dir = normalize(vel);
    vel = dir * clamp(speed, 0.0f, 20.0f);
    vel_1[idx] = vel.x;
    vel_2[idx] = vel.y;
    vel_3[idx] = vel.z;
}

 

OpenCL is more difficult than VEX, but may figure out some formats and patterns when comparing other openCL codes, like an inside of gasTurbulence node. 

 

image.png.a69173fe89bb850795326fc8381c0ebc.png

 

image.png.b120e6e48868bf1e3c270ef7925c62df.png

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...