-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Taichi Gardener <taichigardener@gmail.com>
- Loading branch information
1 parent
65c151a
commit 333c86c
Showing
6 changed files
with
246 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import taichi as ti | ||
import time | ||
|
||
ti.init(async=True) | ||
|
||
x = ti.var(ti.i32) | ||
y = ti.var(ti.i32) | ||
z = ti.var(ti.i32) | ||
|
||
ti.root.dense(ti.i, 1024**3).place(x) | ||
ti.root.dense(ti.i, 1024**3).place(y) | ||
ti.root.dense(ti.i, 1024**3).place(z) | ||
|
||
|
||
@ti.kernel | ||
def x_to_y(): | ||
for i in x: | ||
y[i] = x[i] + 1 | ||
|
||
|
||
@ti.kernel | ||
def y_to_z(): | ||
for i in x: | ||
z[i] = y[i] + 4 | ||
|
||
|
||
@ti.kernel | ||
def inc(): | ||
for i in x: | ||
x[i] = x[i] + 1 | ||
|
||
|
||
n = 100 | ||
|
||
for i in range(n): | ||
x[i] = i * 10 | ||
|
||
repeat = 10 | ||
|
||
for i in range(repeat): | ||
t = time.time() | ||
x_to_y() | ||
ti.sync() | ||
print('x_to_y', time.time() - t) | ||
|
||
for i in range(repeat): | ||
t = time.time() | ||
y_to_z() | ||
ti.sync() | ||
print('y_to_z', time.time() - t) | ||
|
||
for i in range(repeat): | ||
t = time.time() | ||
x_to_y() | ||
y_to_z() | ||
ti.sync() | ||
print('fused x->y->z', time.time() - t) | ||
|
||
for i in range(repeat): | ||
t = time.time() | ||
inc() | ||
ti.sync() | ||
print('single inc', time.time() - t) | ||
|
||
for i in range(repeat): | ||
t = time.time() | ||
for j in range(10): | ||
inc() | ||
ti.sync() | ||
print('fused 10 inc', time.time() - t) | ||
|
||
for i in range(n): | ||
assert x[i] == i * 10 | ||
assert y[i] == x[i] + 1 | ||
assert z[i] == x[i] + 5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import taichi as ti | ||
|
||
ti.init() | ||
|
||
x = ti.var(ti.i32) | ||
y = ti.var(ti.i32) | ||
z = ti.var(ti.i32) | ||
|
||
ti.root.dynamic(ti.i, 1048576, chunk_size=2048).place(x, y, z) | ||
|
||
|
||
@ti.kernel | ||
def x_to_y(): | ||
for i in x: | ||
y[i] = x[i] + 1 | ||
|
||
|
||
@ti.kernel | ||
def y_to_z(): | ||
for i in x: | ||
z[i] = y[i] + 1 | ||
|
||
|
||
n = 10000 | ||
|
||
for i in range(n): | ||
x[i] = i * 10 | ||
|
||
x_to_y() | ||
y_to_z() | ||
|
||
for i in range(n): | ||
x[i] = i * 10 | ||
assert y[i] == x[i] + 1 | ||
assert z[i] == x[i] + 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.