forked from taichi-dev/taichi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[test] Unify kernel setup for ndarray related tests
We'll reuse these two kernels for cgraph tests as well so let's clean it up first.
- Loading branch information
Ailing Zhang
committed
May 19, 2022
1 parent
7157b13
commit b9d8c50
Showing
4 changed files
with
68 additions
and
70 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
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#include "tests/cpp/ir/ndarray_kernel.h" | ||
|
||
namespace taichi { | ||
namespace lang { | ||
|
||
std::unique_ptr<Kernel> setup_kernel1(Program *prog) { | ||
IRBuilder builder1; | ||
{ | ||
auto *arg = builder1.create_arg_load(/*arg_id=*/0, get_data_type<int>(), | ||
/*is_ptr=*/true); | ||
auto *zero = builder1.get_int32(0); | ||
auto *one = builder1.get_int32(1); | ||
auto *two = builder1.get_int32(2); | ||
auto *a1ptr = builder1.create_external_ptr(arg, {one}); | ||
builder1.create_global_store(a1ptr, one); // a[1] = 1 | ||
auto *a0 = | ||
builder1.create_global_load(builder1.create_external_ptr(arg, {zero})); | ||
auto *a2ptr = builder1.create_external_ptr(arg, {two}); | ||
auto *a2 = builder1.create_global_load(a2ptr); | ||
auto *a0plusa2 = builder1.create_add(a0, a2); | ||
builder1.create_global_store(a2ptr, a0plusa2); // a[2] = a[0] + a[2] | ||
} | ||
auto block = builder1.extract_ir(); | ||
auto ker1 = std::make_unique<Kernel>(*prog, std::move(block), "ker1"); | ||
ker1->insert_arg(get_data_type<int>(), /*is_array=*/true); | ||
return ker1; | ||
} | ||
|
||
std::unique_ptr<Kernel> setup_kernel2(Program *prog) { | ||
IRBuilder builder2; | ||
|
||
{ | ||
auto *arg0 = builder2.create_arg_load(/*arg_id=*/0, get_data_type<int>(), | ||
/*is_ptr=*/true); | ||
auto *arg1 = builder2.create_arg_load(/*arg_id=*/1, get_data_type<int>(), | ||
/*is_ptr=*/false); | ||
auto *one = builder2.get_int32(1); | ||
auto *a1ptr = builder2.create_external_ptr(arg0, {one}); | ||
builder2.create_global_store(a1ptr, arg1); // a[1] = arg1 | ||
} | ||
auto block2 = builder2.extract_ir(); | ||
auto ker2 = std::make_unique<Kernel>(*prog, std::move(block2), "ker2"); | ||
ker2->insert_arg(get_data_type<int>(), /*is_array=*/true); | ||
ker2->insert_arg(get_data_type<int>(), /*is_array=*/false); | ||
return ker2; | ||
} | ||
} // namespace lang | ||
} // namespace taichi |
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,14 @@ | ||
#pragma once | ||
#include "taichi/ir/ir_builder.h" | ||
#include "taichi/ir/statements.h" | ||
#include "taichi/inc/constants.h" | ||
#include "taichi/program/program.h" | ||
|
||
namespace taichi { | ||
namespace lang { | ||
|
||
std::unique_ptr<Kernel> setup_kernel1(Program *prog); | ||
|
||
std::unique_ptr<Kernel> setup_kernel2(Program *prog); | ||
} // namespace lang | ||
} // namespace taichi |