-
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.
[aot] [llvm] LLVM AOT Field part-4: Added AOT tests for Fields - CUDA…
… backend (#5124) * [aot] [llvm] Implemented FieldCacheData and refactored initialize_llvm_runtime_snodes() * Addressed compilation erros * [aot] [llvm] LLVM AOT Field #1: Adjust serialization/deserialization logics for FieldCacheData * [llvm] [aot] Added Field support for LLVM AOT * [aot] [llvm] LLVM AOT Field #2: Updated LLVM AOTModuleLoader & AOTModuleBuilder to support Fields * [aot] [llvm] LLVM AOT Field #3: Added AOT tests for Fields running CPU backend * Added tests for activate/deactivate operations * [aot] [llvm] LLVM AOT Field #4: Added AOT tests for Fields running CUDA backend * Fixed merge issues * Addressed naming issues
- Loading branch information
1 parent
61d09c2
commit d0d70ae
Showing
8 changed files
with
210 additions
and
185 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 |
---|---|---|
@@ -1,108 +1,6 @@ | ||
import os | ||
from utils import compile_field_aot | ||
|
||
import taichi as ti | ||
|
||
|
||
def compile_aot(): | ||
# Make sure "debug" mode is on | ||
# in both python & C++ tests | ||
ti.init(arch=ti.x64, debug=True) | ||
|
||
x = ti.field(ti.i32) | ||
y = ti.field(ti.i32) | ||
|
||
common = ti.root.dense(ti.i, 4) | ||
common.dense(ti.i, 8).place(x) | ||
|
||
p = common.pointer(ti.i, 2) | ||
p.dense(ti.i, 8).place(y) | ||
|
||
@ti.kernel | ||
def init_fields(base: int): | ||
# Dense SNode | ||
for i in range(4 * 8): | ||
x[i] = base + i | ||
|
||
# Pointer SNode | ||
y[32] = 4 | ||
y[33] = 5 | ||
y[9] = 10 | ||
|
||
@ti.kernel | ||
def check_init_x(base: int): | ||
# Check numerical accuracy for Dense SNodes | ||
for i in range(4 * 8): | ||
assert (x[i] == base + i) | ||
|
||
@ti.kernel | ||
def check_init_y(): | ||
# Check sparsity for Pointer SNodes | ||
for i in range(8): | ||
if i == 1 or i == 4: | ||
assert (ti.is_active(p, [i])) | ||
else: | ||
assert (not ti.is_active(p, [i])) | ||
|
||
# Check numerical accuracy for Pointer SNodes | ||
for i in range(8, 8 + 8): | ||
if i == 9: | ||
assert (y[i] == 10) | ||
else: | ||
assert (y[i] == 0) | ||
|
||
for i in range(32, 32 + 8): | ||
if i == 32: | ||
assert (y[i] == 4) | ||
elif i == 33: | ||
assert (y[i] == 5) | ||
else: | ||
assert (y[i] == 0) | ||
|
||
@ti.kernel | ||
def deactivate_pointer_fields(): | ||
ti.deactivate(p, [1]) | ||
ti.deactivate(p, [4]) | ||
|
||
@ti.kernel | ||
def activate_pointer_fields(): | ||
ti.activate(p, [7]) | ||
ti.activate(p, [3]) | ||
|
||
@ti.kernel | ||
def check_deactivate_pointer_fields(): | ||
assert (not ti.is_active(p, [1])) | ||
assert (not ti.is_active(p, [4])) | ||
|
||
@ti.kernel | ||
def check_activate_pointer_fields(): | ||
assert (ti.is_active(p, [7])) | ||
assert (ti.is_active(p, [3])) | ||
|
||
for i in range(7 * 8, 7 * 8 + 8): | ||
assert (y[i] == 0) | ||
|
||
for i in range(3 * 8, 3 * 8 + 8): | ||
assert (y[i] == 0) | ||
|
||
assert "TAICHI_AOT_FOLDER_PATH" in os.environ.keys() | ||
dir_name = str(os.environ["TAICHI_AOT_FOLDER_PATH"]) | ||
|
||
m = ti.aot.Module(ti.x64) | ||
|
||
m.add_kernel(init_fields, template_args={}) | ||
m.add_kernel(check_init_x, template_args={}) | ||
m.add_kernel(check_init_y, template_args={}) | ||
|
||
m.add_kernel(deactivate_pointer_fields, template_args={}) | ||
m.add_kernel(activate_pointer_fields, template_args={}) | ||
|
||
m.add_kernel(check_deactivate_pointer_fields, template_args={}) | ||
m.add_kernel(check_activate_pointer_fields, template_args={}) | ||
|
||
m.add_field("x", x) | ||
m.add_field("y", y) | ||
|
||
m.save(dir_name, 'x64-aot') | ||
|
||
|
||
compile_aot() | ||
if __name__ == "__main__": | ||
compile_field_aot(arch=ti.x64) |
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,6 @@ | ||
from utils import compile_field_aot | ||
|
||
import taichi as ti | ||
|
||
if __name__ == "__main__": | ||
compile_field_aot(arch=ti.cuda) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,6 @@ | ||
import os | ||
from utils import compile_kernel_aot | ||
|
||
import taichi as ti | ||
|
||
|
||
def compile_aot(): | ||
ti.init(arch=ti.x64) | ||
|
||
@ti.kernel | ||
def run(base: int, arr: ti.types.ndarray()): | ||
for i in arr: | ||
arr[i] = base + i | ||
|
||
arr = ti.ndarray(int, shape=16) | ||
|
||
assert "TAICHI_AOT_FOLDER_PATH" in os.environ.keys() | ||
dir_name = str(os.environ["TAICHI_AOT_FOLDER_PATH"]) | ||
|
||
m = ti.aot.Module(ti.x64) | ||
m.add_kernel(run, template_args={'arr': arr}) | ||
m.save(dir_name, 'x64-aot') | ||
|
||
|
||
compile_aot() | ||
if __name__ == "__main__": | ||
compile_kernel_aot(arch=ti.x64) |
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 |
---|---|---|
@@ -1,24 +1,6 @@ | ||
import os | ||
from utils import compile_kernel_aot | ||
|
||
import taichi as ti | ||
|
||
|
||
def compile_aot(): | ||
ti.init(arch=ti.cuda) | ||
|
||
@ti.kernel | ||
def run(base: int, arr: ti.types.ndarray()): | ||
for i in arr: | ||
arr[i] = base + i | ||
|
||
arr = ti.ndarray(int, shape=16) | ||
|
||
assert "TAICHI_AOT_FOLDER_PATH" in os.environ.keys() | ||
dir_name = str(os.environ["TAICHI_AOT_FOLDER_PATH"]) | ||
|
||
m = ti.aot.Module(ti.cuda) | ||
m.add_kernel(run, template_args={'arr': arr}) | ||
m.save(dir_name, 'cuda-aot') | ||
|
||
|
||
compile_aot() | ||
if __name__ == "__main__": | ||
compile_kernel_aot(arch=ti.cuda) |
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.