forked from taichi-dev/taichi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fill_sparse.py
42 lines (29 loc) · 830 Bytes
/
fill_sparse.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import taichi as ti
@ti.archs_support_sparse
def benchmark_nested_struct():
a = ti.field(dtype=ti.f32)
N = 512
ti.root.pointer(ti.ij, [N, N]).dense(ti.ij, [8, 8]).place(a)
@ti.kernel
def fill():
for i, j in ti.ndrange(N * 8, N * 8):
a[i, j] = 2.0
fill()
return ti.benchmark(fill)
@ti.archs_support_sparse
def benchmark_nested_struct_fill_and_clear():
a = ti.field(dtype=ti.f32)
N = 512
ti.root.pointer(ti.ij, [N, N]).dense(ti.ij, [8, 8]).place(a)
@ti.kernel
def fill():
for i, j in ti.ndrange(N * 8, N * 8):
a[i, j] = 2.0
@ti.kernel
def clear():
for i, j in a.parent():
ti.deactivate(a.parent().parent(), [i, j])
def task():
fill()
clear()
return ti.benchmark(task, repeat=30)