forked from PaddlePaddle/Paddle
-
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.
Merge pull request #1 from Superjomn/fea/add-ir-description
add IrNodeTy ostream support
- Loading branch information
Showing
11 changed files
with
87 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
cc_library(cinn_gtest_main SRCS gtest_main.cc DEPS gtest) | ||
|
||
add_subdirectory(utils) | ||
add_subdirectory(ir) | ||
add_subdirectory(dsl) | ||
add_subdirectory(optim) |
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,4 +1,6 @@ | ||
cc_library(ir SRCS | ||
type.cc node.cc ir.cc | ||
type.cc node.cc ir.cc node.cc | ||
ir_visitor.cc | ||
) | ||
|
||
cc_test(test_ir SRCS ir_test.cc DEPS ir) |
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,22 @@ | ||
#include "cinn/ir/ir.h" | ||
#include <gtest/gtest.h> | ||
|
||
#include "cinn/utils/string.h" | ||
|
||
namespace cinn { | ||
namespace ir { | ||
|
||
TEST(ir, Add) { | ||
Builder builder; | ||
|
||
auto one = builder.make<IntImm>(Int(32), 1); | ||
auto two = builder.make<IntImm>(Int(32), 2); | ||
|
||
auto add = builder.make<Add>(one, two); | ||
|
||
auto cnt = utils::GetStreamCnt(add.node_type()); | ||
ASSERT_EQ(cnt, "<node: Add>"); | ||
} | ||
|
||
} // namespace ir | ||
} // namespace cinn |
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,10 +1,34 @@ | ||
#include "cinn/ir/node.h" | ||
#include "cinn/ir/ir.h" | ||
|
||
namespace cinn { | ||
namespace ir { | ||
|
||
template <> | ||
void ExprNode<IntImm>::Accept(cinn::ir::IRVisitor *v) const {} | ||
//! Implementations for Ir nodes. | ||
// @{ | ||
#define __m(t__) \ | ||
template <> \ | ||
void ExprNode<t__>::Accept(cinn::ir::IRVisitor *v) const {} | ||
NODETY_FORALL(__m) | ||
#undef __m | ||
// @} | ||
|
||
std::ostream &operator<<(std::ostream &os, IrNodeTy type) { | ||
switch (type) { | ||
#define __m(t__) \ | ||
case IrNodeTy::t__: \ | ||
os << "<node: " << #t__ << ">"; \ | ||
break; | ||
|
||
NODETY_FORALL(__m) | ||
#undef __m | ||
|
||
default: | ||
LOG(FATAL) << "unknown IrNodeTy found"; | ||
} | ||
|
||
return os; | ||
} | ||
|
||
} // namespace ir | ||
} // namespace cinn |
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 @@ | ||
cc_library(utils SRCS string.cc) |
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,5 @@ | ||
#include "cinn/utils/string.h" | ||
|
||
namespace cinn { | ||
namespace utils {} // namespace utils | ||
} // namespace cinn |
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,17 @@ | ||
#pragma once | ||
#include <sstream> | ||
#include <string> | ||
|
||
namespace cinn { | ||
namespace utils { | ||
|
||
//! Get the content of a stream. | ||
template <typename T> | ||
std::string GetStreamCnt(const T& x) { | ||
std::stringstream os; | ||
os << x; | ||
return os.str(); | ||
} | ||
|
||
} // namespace utils | ||
} // namespace cinn |
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