taichi icon indicating copy to clipboard operation
taichi copied to clipboard

Struct-for parital

Open xuhao1 opened this issue 1 year ago • 3 comments

Concisely describe the proposed feature I would like to run struct-for partially (with some dims fixed) on a SNode field.

Describe the solution you'd like (if any) One possible solution is via slicing sparse data structure

@ti.kernel
def example():
    #struct for a 3d sparse field on i=0
    for j, k in data[0,:,:]:
        do_some_work()

Another solution is via some function

@ti.kernel
def example():
    #struct for a 3d sparse field on i=0
    for j, k in ti.part_for(data, [0,:,:]):
        do_some_work()

xuhao1 avatar Jul 14 '22 15:07 xuhao1

@xuhao1 I guess you can work around this by

for i, j, k in data:
  if i == 0: 
    do_some_work()

right? Would you mind elaborate if there's any extra benefit you'd expect from this partial struct-for? Thanks a lot!

ailzhang avatar Jul 22 '22 01:07 ailzhang

Hi @ailzhang Yes I am currently using

for i, j, k in data:
  if i == 0: 
    do_some_work()

However, this implementation needs to visit all the memory of the SNode. This will bring overhead when data is quite large.

xuhao1 avatar Jul 26 '22 22:07 xuhao1

@xuhao1 Yea this is totally a reasonable feature request! Implementation wise might be a bit tricky tho. I feel like this is a good get started task for sparse. We'll put this in todo for now and let you know once we've implemented it. Thanks!

ailzhang avatar Aug 05 '22 02:08 ailzhang