Ekaterina Sky Posted Monday at 07:17 AM Share Posted Monday at 07:17 AM 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! Quote Link to comment Share on other sites More sharing options...
Librarian Posted Monday at 08:40 AM Share Posted Monday at 08:40 AM Just find White dog on Twitter (X) he posted Some Files regarding that and everything its in openCL @Ekaterina Sky Quote Link to comment Share on other sites More sharing options...
Ekaterina Sky Posted Tuesday at 02:45 AM Author Share Posted Tuesday at 02:45 AM 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.