chore: import upstream snapshot with attribution

This commit is contained in:
wehub-resource-sync
2026-07-13 12:40:42 +08:00
commit e25996e7db
15472 changed files with 3536181 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
add_subdirectory(test)
+9
View File
@@ -0,0 +1,9 @@
# cinn_cc_test(test_ir SRCS ir_test.cc DEPS core)
# cinn_cc_test(test_ir_printer SRCS ir_printer_test.cc DEPS core)
# cinn_cc_test(test_ir_operators SRCS ir_operators_test.cc DEPS core)
# cinn_cc_test(test_tensor SRCS tensor_test.cc DEPS core)
cinn_cc_test(test_collect_ir_nodes SRCS collect_ir_nodes_test.cc DEPS cinncore)
cinn_cc_test(test_intrinsic_ops SRCS intrinsic_ops_test.cc DEPS cinncore)
cinn_cc_test(test_ir_verify SRCS ir_verify_test.cc DEPS cinncore)
cinn_cc_test(test_ir_copy SRCS ir_copy_test.cc DEPS cinncore)
@@ -0,0 +1,65 @@
// Copyright (c) 2021 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 "paddle/cinn/cinn.h"
#include "paddle/cinn/ir/ir.h"
#include "paddle/cinn/ir/utils/stmt_converter.h"
namespace cinn {
namespace ir {
namespace ir_utils {
TEST(CollectIRNodes, basic0) {
Expr C = Expr(1) + 2;
auto exprs =
CollectIRNodes(C, [](const Expr* x) { return x->As<ir::Add>(); });
ASSERT_EQ(exprs.size(), 1UL);
auto ints =
CollectIRNodes(C, [](const Expr* x) { return x->As<ir::IntImm>(); });
ASSERT_EQ(ints.size(), 2UL);
}
TEST(CollectIRNodes, basic) {
Expr M(100);
Expr N(200);
Placeholder<float> A("A", {M, N});
Placeholder<float> B("B", {M, N});
auto C = Compute(
{M, N}, [&](Var i, Var j) { return A(i, j) + B(i, j); }, "C");
ast_gen_ius::TensorGroup tensor_group({C});
auto fn = LowerToAst("fn", {A, B, C}, &tensor_group);
LOG(INFO) << "fn:\n" << fn;
Expr expr_func_body = ConvertStmtBlockToExprBlock(fn->body_block);
auto tensors = CollectIRNodes(expr_func_body,
[](const Expr* x) { return x->as_tensor(); });
ASSERT_EQ(tensors.size(), 3UL);
LOG(INFO) << "fn.body:\n" << expr_func_body;
auto tensors2 = CollectIRNodes(expr_func_body,
[](const Expr* x) { return x->as_tensor(); });
auto exprs = CollectIRNodes(expr_func_body, [](const Expr* x) { return x; });
}
} // namespace ir_utils
} // namespace ir
} // namespace cinn
@@ -0,0 +1,31 @@
// Copyright (c) 2021 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/ir/intrinsic_ops.h"
#include <gtest/gtest.h>
namespace cinn::ir {
TEST(IntrinsicOp, basic) {
Expr buffer(1);
buffer->set_type(type_of<cinn_buffer_t*>());
auto op = intrinsics::BufferGetDataHandle::Make(buffer);
auto* ptr = op.As<IntrinsicOp>();
ASSERT_TRUE(ptr);
auto* obj = llvm::dyn_cast<intrinsics::BufferGetDataHandle>(ptr);
ASSERT_TRUE(obj);
}
} // namespace cinn::ir
+32
View File
@@ -0,0 +1,32 @@
// Copyright (c) 2021 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/ir/utils/ir_copy.h"
#include <gtest/gtest.h>
#include "paddle/cinn/ir/ir_printer.h"
namespace cinn {
namespace ir {
namespace ir_utils {
TEST(IrCopy, basic) {
Expr a(1.f);
auto aa = IRCopy(a);
LOG(INFO) << "aa " << aa;
}
} // namespace ir_utils
} // namespace ir
} // namespace cinn
@@ -0,0 +1,28 @@
// Copyright (c) 2021 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/ir/op/ir_operators.h"
#include <gtest/gtest.h>
namespace cinn {
namespace ir {
TEST(ir_operators, test) {
Expr a(1);
Expr b = a + 1;
}
} // namespace ir
} // namespace cinn
+23
View File
@@ -0,0 +1,23 @@
// Copyright (c) 2021 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/ir/ir_printer.h"
#include <gtest/gtest.h>
#include <sstream>
namespace cinn {
namespace ir {} // namespace ir
} // namespace cinn
+31
View File
@@ -0,0 +1,31 @@
// Copyright (c) 2021 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/ir/ir.h"
#include <gtest/gtest.h>
#include "paddle/cinn/utils/string.h"
namespace cinn {
namespace ir {
TEST(Expr, basic) {
Expr a(1);
auto b = Expr(a);
LOG(INFO) << b.as_int32();
}
} // namespace ir
} // namespace cinn
+31
View File
@@ -0,0 +1,31 @@
// Copyright (c) 2021 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/ir/utils/ir_verify.h"
#include <gtest/gtest.h>
#include "paddle/cinn/ir/op/ir_operators.h"
namespace cinn {
namespace ir {
namespace ir_utils {
TEST(IrVerify, basic) {
Expr a(1);
Expr b(1);
IrVerify(a + b);
}
} // namespace ir_utils
} // namespace ir
} // namespace cinn