From 83e1a07cd9cb19afeeed919de9bb9bd3a10211cc Mon Sep 17 00:00:00 2001 From: zhangbo9674 <82555433+zhangbo9674@users.noreply.github.com> Date: Fri, 9 Jun 2023 23:22:41 +0800 Subject: [PATCH] delete ir_exe_test (#54506) --- test/cpp/ir/core/CMakeLists.txt | 10 --- test/cpp/ir/core/ir_exe_test.cc | 134 -------------------------------- 2 files changed, 144 deletions(-) delete mode 100644 test/cpp/ir/core/ir_exe_test.cc diff --git a/test/cpp/ir/core/CMakeLists.txt b/test/cpp/ir/core/CMakeLists.txt index 111da5c3e29..b42bdc17078 100644 --- a/test/cpp/ir/core/CMakeLists.txt +++ b/test/cpp/ir/core/CMakeLists.txt @@ -22,16 +22,6 @@ cc_test_old( phi gtest) -cc_test_old( - ir_exe_test - SRCS - ir_exe_test.cc - DEPS - new_ir - pd_dialect - phi - gtest) - cc_test_old( scalar_attribute_test SRCS diff --git a/test/cpp/ir/core/ir_exe_test.cc b/test/cpp/ir/core/ir_exe_test.cc deleted file mode 100644 index 0ca3b996818..00000000000 --- a/test/cpp/ir/core/ir_exe_test.cc +++ /dev/null @@ -1,134 +0,0 @@ -// Copyright (c) 2023 PaddlePaddle 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 - -#include "paddle/fluid/ir/dialect/pd_dialect.h" -#include "paddle/fluid/ir/dialect/pd_type.h" -#include "paddle/fluid/ir/dialect/utils.h" -#include "paddle/fluid/ir/interface/op_yaml_info.h" -#include "paddle/ir/core/builtin_attribute.h" -#include "paddle/ir/core/builtin_dialect.h" -#include "paddle/ir/core/builtin_op.h" -#include "paddle/ir/core/ir_context.h" -#include "paddle/ir/core/program.h" -#include "paddle/ir/core/utils.h" -#include "paddle/phi/core/meta_tensor.h" -#include "paddle/phi/infermeta/binary.h" -#include "paddle/phi/kernels/elementwise_add_kernel.h" - -#include "paddle/fluid/framework/scope.h" -#include "paddle/fluid/framework/tensor.h" -#include "paddle/fluid/framework/variable.h" -#include "paddle/fluid/framework/variable_helper.h" - -#include "paddle/phi/common/place.h" -#include "paddle/phi/core/kernel_context.h" -#include "paddle/phi/core/kernel_factory.h" - -#include "paddle/fluid/platform/init.h" - -#include "paddle/fluid/ir/dialect/pd_attribute.h" - -#include "paddle/phi/core/kernel_registry.h" -#include "test/cpp/ir/core/phi_kernel_adaptor.h" - -PD_DECLARE_KERNEL(uniform, CPU, ALL_LAYOUT); -PD_DECLARE_KERNEL(add, CPU, ALL_LAYOUT); - -bool simple_cmp(float a, float b) { return std::abs((a - b) / a) < 1e-5; } - -TEST(program_test, program) { - ir::IrContext* ctx = ir::IrContext::Instance(); - ctx->GetOrRegisterDialect(); - - ir::Program program(ctx); - ir::Block* block = program.block(); - ir::Type fp32_dtype = ir::Float32Type::get(ctx); - - paddle::dialect::DenseTensorTypeStorage::Dim dims = {2, 2}; - paddle::dialect::DenseTensorTypeStorage::DataLayout data_layout = - paddle::dialect::DenseTensorTypeStorage::DataLayout::NCHW; - paddle::dialect::DenseTensorTypeStorage::LoD lod = {}; - size_t offset = 0; - ir::Type dense_tensor_dtype = paddle::dialect::DenseTensorType::get( - ctx, fp32_dtype, dims, data_layout, lod, offset); - - // (1) Def a = GetParameterOp("a") - std::string op1_name = std::string(paddle::dialect::UniformOp::name()); - ir::OpInfo op1_info = ctx->GetRegisteredOpInfo(op1_name); - - // ir::Attribute shape_1 = ir::ArrayAttribute::get(ctx, {ten} ); - ir::Attribute shape_1 = paddle::dialect::IntArrayAttribute::get( - ctx, std::vector({2, 2})); - ir::Attribute data_type = - paddle::dialect::DataTypeAttribute::get(ctx, phi::DataType::FLOAT32); - ir::Attribute min = ir::FloatAttribute::get(ctx, 0.0); - ir::Attribute max = ir::FloatAttribute::get(ctx, 1.0); - ir::Attribute seed = ir::Int32_tAttribute::get(ctx, 2); - ir::Attribute uni_place = paddle::dialect::PlaceAttribute::get( - ctx, phi::Place(phi::AllocationType::CPU)); - std::unordered_map op1_attribute{ - {"shape", shape_1}, - {"dtype", data_type}, - {"min", min}, - {"max", max}, - {"seed", seed}, - {"place", uni_place}}; - ir::Operation* op1 = - ir::Operation::Create({}, op1_attribute, {dense_tensor_dtype}, op1_info); - - block->push_back(op1); - - // (2) Def b = GetParameterOp("b") - std::string op2_name = std::string(paddle::dialect::UniformOp::name()); - ir::OpInfo op2_info = ctx->GetRegisteredOpInfo(op2_name); - ir::Attribute ten2 = ir::Int32_tAttribute::get(ctx, 3); - std::unordered_map op2_attribute{{"shape", ten2}}; - ir::Operation* op2 = - ir::Operation::Create({}, op1_attribute, {dense_tensor_dtype}, op2_info); - block->push_back(op2); - - // (3) Def out = AddOp(a, b) - std::string add_op_name = std::string(paddle::dialect::AddOp::name()); - ir::OpInfo add_op_info = ctx->GetRegisteredOpInfo(add_op_name); - ir::Operation* add_op = ir::Operation::Create( - {op1->GetResultByIndex(0), op2->GetResultByIndex(0)}, - {}, - {dense_tensor_dtype}, - add_op_info); - block->push_back(add_op); - - paddle::framework::Scope scope; - - PhiKernelAdaptor phi_kernel_adaptor(&scope); - - phi_kernel_adaptor.run(&program); - - auto out_tensor = - scope.Var(phi_kernel_adaptor.out_name)->Get(); - - bool res0 = simple_cmp(out_tensor.data()[0], 1.80721); - bool res1 = simple_cmp(out_tensor.data()[1], 1.70047); - bool res2 = simple_cmp(out_tensor.data()[2], 1.56764); - bool res3 = simple_cmp(out_tensor.data()[3], 1.85063); - std::cerr << out_tensor.data()[0] << "\t" - << out_tensor.data()[1] << "\t" - << out_tensor.data()[2] << "\t" - << out_tensor.data()[3] << std::endl; - EXPECT_EQ(res0, true); - EXPECT_EQ(res1, true); - EXPECT_EQ(res2, true); - EXPECT_EQ(res3, true); -} -- GitLab