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
+2
View File
@@ -0,0 +1,2 @@
cinn_cc_test(test_compute SRCS compute_test.cc DEPS cinncore)
cinn_cc_test(test_cinn_packed_func SRCS packed_func_test.cc DEPS cinncore)
+39
View File
@@ -0,0 +1,39 @@
// 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/lang/compute.h"
#include <gtest/gtest.h>
#include "paddle/cinn/cinn.h"
#include "paddle/cinn/ir/op/ir_operators.h"
#include "paddle/cinn/ir/tensor.h"
#include "paddle/cinn/lang/placeholder.h"
namespace cinn {
namespace lang {
TEST(Call, basic) {
Expr M(100);
Placeholder<float> x("x", {M, Expr(10)});
Placeholder<float> y("y", {M, Expr(10)});
std::vector<ReturnType> return_types(
{{Float(32), std::vector<Expr>{{M, Expr(20)}}, "C"}});
auto tensors = CallLowered("lowered_fun0", {Expr(x), Expr(y)}, return_types);
}
} // namespace lang
} // namespace cinn
+96
View File
@@ -0,0 +1,96 @@
// 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/lang/packed_func.h"
#include <gtest/gtest.h>
#include "paddle/cinn/ir/ir_printer.h"
#include "paddle/cinn/ir/op/ir_operators.h"
#include "paddle/cinn/utils/string.h"
namespace cinn {
namespace lang {
TEST(Function, test) {
PackedFunc::body_t func_body = [](Args args, RetValue* ret) {
int a = args[0];
int b = args[1];
*ret = (a + b);
};
PackedFunc func(func_body);
int c = func(1, 2);
LOG(INFO) << "c " << c;
}
TEST(Function, test1) {
PackedFunc::body_t body = [](Args args, RetValue* ret) {
auto* msg = static_cast<const char*>(args[0]);
(*ret) = msg;
};
PackedFunc func(body);
const char* msg = "hello world";
char* c = func(msg);
LOG(INFO) << static_cast<char*>(c);
}
TEST(Function, Expr) {
PackedFunc::body_t body = [](Args args, RetValue* ret) {
Expr a = args[0];
Expr b = args[1];
ASSERT_EQ(a->__ref_count__.val(), 4);
ASSERT_EQ(b->__ref_count__.val(), 4);
Expr c = a + b;
(*ret) = CINNValue(c);
};
PackedFunc func(body);
Expr a(1);
Expr b(2);
ASSERT_EQ(a->__ref_count__.val(), 1);
ASSERT_EQ(b->__ref_count__.val(), 1);
Expr ret = func(a, b);
ASSERT_EQ(utils::GetStreamCnt(ret), "(1 + 2)");
}
TEST(Function, ReturnMultiValue) {
PackedFunc::body_t body = [](Args args, RetValue* ret) {
int a = args[0];
int b = args[1];
int c = a + b;
int d = a - b;
*ret = cinn::common::CINNValuePack{
{cinn::common::CINNValue(c), cinn::common::CINNValue(d)}};
};
PackedFunc func(body);
cinn::common::CINNValuePack ret = func(1, 2);
int c = ret[0];
int d = ret[1];
EXPECT_EQ(c, 3);
EXPECT_EQ(d, -1);
}
} // namespace lang
} // namespace cinn