-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge commit 'b29e2f7f98a2185acd48b038ca74eed3d8f67fc2' into pir_pad
- Loading branch information
Showing
1,249 changed files
with
32,512 additions
and
15,186 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
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 @@ | ||
core_gather_headers() | ||
|
||
gather_srcs(cinnapi_src SRCS ast_gen.cc tensor_group.cc) | ||
|
||
cinn_cc_test(test_ast_gen_ius SRCS ast_gen_test.cc DEPS cinncore) | ||
cinn_cc_test(test_tensor_group SRCS tensor_group_test.cc DEPS cinncore) |
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,52 @@ | ||
// Copyright (c) 2023 CINN Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "paddle/cinn/ast_gen_ius/ast_gen.h" | ||
#include "paddle/cinn/ir/ir.h" | ||
#include "paddle/cinn/ir/ir_base.h" | ||
#include "paddle/cinn/ir/operation.h" | ||
#include "paddle/cinn/ir/tensor.h" | ||
#include "paddle/cinn/ir/utils/ir_printer.h" | ||
|
||
namespace cinn { | ||
namespace ast_gen_ius { | ||
|
||
ir::Expr AstGen::Build(const ir::Tensor& tensor) { | ||
const std::vector<ir::Var>& axis = tensor->axis(); | ||
const std::vector<ir::Expr>& shape = tensor->shape; | ||
size_t axis_len = axis.size(); | ||
CHECK_EQ(shape.size(), axis_len) | ||
<< "Internal Error: Tensor has different shape and axis length in AstGen"; | ||
|
||
std::vector<ir::Expr> axis_exprs; | ||
for (const auto& a : axis) { | ||
axis_exprs.push_back(a); | ||
} | ||
ir::Expr body = ir::Store::Make(tensor, tensor->body(), axis_exprs); | ||
|
||
for (int i = static_cast<int>(axis_len) - 1; i >= 0; --i) { | ||
ir::Var loop_var = axis[i]; | ||
ir::Expr loop_extent = shape[i]; | ||
body = ir::For::Make(loop_var, | ||
Expr(0), | ||
loop_extent, | ||
ir::ForType::Serial, | ||
ir::DeviceAPI::Host, | ||
ir::Block::Make({body})); | ||
} | ||
return body; | ||
} | ||
|
||
} // namespace ast_gen_ius | ||
} // 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,44 @@ | ||
// Copyright (c) 2023 CINN Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include <gtest/gtest.h> | ||
#include <vector> | ||
|
||
#include "paddle/cinn/ast_gen_ius/ast_gen.h" | ||
#include "paddle/cinn/ir/ir.h" | ||
#include "paddle/cinn/ir/ir_base.h" | ||
#include "paddle/cinn/ir/tensor.h" | ||
#include "paddle/cinn/lang/builtin.h" | ||
#include "paddle/cinn/lang/compute.h" | ||
#include "paddle/cinn/lang/placeholder.h" | ||
|
||
namespace cinn { | ||
namespace ast_gen_ius { | ||
|
||
using cinn::ir::Expr; | ||
using cinn::ir::Tensor; | ||
|
||
TEST(AstGen, Build) { | ||
std::vector<Expr> shape = {Expr(10), Expr(10), Expr(10), Expr(10)}; | ||
lang::Placeholder<float> A("A", shape); | ||
Tensor B = lang::Compute( | ||
shape, | ||
[&](const std::vector<Expr>& indice) { return lang::Relu(A(indice), 0); }, | ||
"relu_test"); | ||
Expr out = AstGen::Build(B); | ||
LOG(INFO) << out; | ||
} | ||
|
||
} // namespace ast_gen_ius | ||
} // namespace cinn |
Oops, something went wrong.