-
Hi, apologies if this is a foolish question, I'm still new to GPU programming and Tai Chi (which is really amazing btw!). I was looking at this old whitepaper from Nvidia that is about using a grid to detect particle collisions, and it seems to have a pattern that I didn't think was possible on GPU. In the section "Building the Grid using Atomic Operations" (page 7-8), they describe using a "scattered global write" to write the indices of all the particles in a grid cell to a fixed-length array (one array per grid cell) without race conditions in writing to the array; the races are avoided by using grid = ti.Struct.field(
{
"num_in_cell": ti.i32, # number of particles in grid cell
"indices": ti.types.vector(4, ti.i32), # indices of particles in this grid cell
}
)
...
@ti.kernel
def bin_particles():
for p in particles:
ij = particles[p].x.cast(int)
num_in_cell = grid[ij].num_in_cell
grid[ij].indices[num_in_cell] = p
grid[ij].num_in_cell += 1 I thought I would go ahead and just try this to see if it would work, and I'm not surprised to find that it doesn't, because it seems like a weird pattern. I get the error:
So I guess I have a couple questions:
Thanks for you help! :-) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Oops. The immediate issue I can tell is that you cannot index into a vector (matrix) using a runtime integer variable yet. (The for vi in static(range(4)):
if num_in_cell == vi:
grid[ij].indices[vi] = p |
Beta Was this translation helpful? Give feedback.
Oops. The immediate issue I can tell is that you cannot index into a vector (matrix) using a runtime integer variable yet. (The
.indices[num_in_cell]
part, asnum_in_cell
is a runtime variable). The current situation is a bit unfortunate, but we're really close on supporting it (@strongoier is driving this feature). For now a workaround is to do a static loop: