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.
[IR] Support frontend type inference in simple cases (taichi-dev#3302)
* Add ret_type in Expression * Fix Expr::Var * Remove dt in test_matrix * Support Const, ArgLoad, Rand, Id, BinaryOp; Add C++ tests; Remove dt in some Python tests * Remove boilerplate test * Auto Format Co-authored-by: Taichi Gardener <[email protected]>
- Loading branch information
1 parent
3b179fb
commit 68bea56
Showing
12 changed files
with
108 additions
and
13 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
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
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,44 @@ | ||
#include "gtest/gtest.h" | ||
|
||
#include "taichi/ir/frontend_ir.h" | ||
#include "taichi/program/program.h" | ||
|
||
namespace taichi { | ||
namespace lang { | ||
|
||
TEST(FrontendTypeInference, Const) { | ||
auto const_i64 = Expr::make<ConstExpression, int64>(1LL << 63); | ||
EXPECT_EQ(const_i64->ret_type, PrimitiveType::i64); | ||
} | ||
|
||
TEST(FrontendTypeInference, ArgLoad) { | ||
auto arg_load_u64 = Expr::make<ArgLoadExpression>(2, PrimitiveType::u64); | ||
EXPECT_EQ(arg_load_u64->ret_type, PrimitiveType::u64); | ||
} | ||
|
||
TEST(FrontendTypeInference, Rand) { | ||
auto rand_f16 = Expr::make<RandExpression>(PrimitiveType::f16); | ||
EXPECT_EQ(rand_f16->ret_type, PrimitiveType::f16); | ||
} | ||
|
||
TEST(FrontendTypeInference, Id) { | ||
auto prog = std::make_unique<Program>(Arch::x64); | ||
auto func = []() {}; | ||
auto kernel = std::make_unique<Kernel>(*prog, func, "fake_kernel"); | ||
Callable::CurrentCallableGuard _(kernel->program, kernel.get()); | ||
auto const_i32 = Expr::make<ConstExpression, int32>(-(1 << 20)); | ||
auto id_i32 = Var(const_i32); | ||
EXPECT_EQ(id_i32->ret_type, PrimitiveType::i32); | ||
} | ||
|
||
TEST(FrontendTypeInference, BinaryOp) { | ||
auto prog = std::make_unique<Program>(Arch::x64); | ||
prog->config.default_fp = PrimitiveType::f64; | ||
auto const_i32 = Expr::make<ConstExpression, int32>(-(1 << 20)); | ||
auto const_f32 = Expr::make<ConstExpression, float32>(5.0); | ||
auto truediv_f64 = expr_truediv(const_i32, const_f32); | ||
EXPECT_EQ(truediv_f64->ret_type, PrimitiveType::f64); | ||
} | ||
|
||
} // 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
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