From 7ed915682395a522abedbf4287599274e2fb636a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=98=A5=E4=B9=94?= <83450930+Liyulingyue@users.noreply.github.com> Date: Mon, 15 Jan 2024 22:21:55 +0800 Subject: [PATCH 01/29] Update CMakeLists.txt --- test/cpp/pir/pattern_rewrite/CMakeLists.txt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/cpp/pir/pattern_rewrite/CMakeLists.txt b/test/cpp/pir/pattern_rewrite/CMakeLists.txt index b06577552d52b3..b4ebbc26aa3440 100644 --- a/test/cpp/pir/pattern_rewrite/CMakeLists.txt +++ b/test/cpp/pir/pattern_rewrite/CMakeLists.txt @@ -1,29 +1,29 @@ -cc_test( +paddle_test( pattern_rewrite_test SRCS pattern_rewrite_test.cc DEPS gtest op_dialect_vjp pir pir_transforms) -cc_test( +paddle_test( drr_test SRCS drr_test.cc DEPS drr pir_transforms) -cc_test( +paddle_test( drr_same_type_binding_test SRCS drr_same_type_binding_test.cc DEPS drr gtest op_dialect_vjp pir pir_transforms) -cc_test( +paddle_test( drr_fuse_linear_test SRCS drr_fuse_linear_test.cc DEPS pir_transforms drr gtest op_dialect_vjp pir) -cc_test( +paddle_test( drr_fuse_linear_param_grad_add_test SRCS drr_fuse_linear_param_grad_add_test.cc DEPS pir_transforms drr gtest op_dialect_vjp pir) -cc_test( +paddle_test( drr_attention_fuse_test SRCS drr_attention_fuse_test.cc DEPS pir_transforms drr gtest op_dialect_vjp pir) From e5e4670a7b8c2b48e77cf4e39e9decf7198e9558 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=98=A5=E4=B9=94?= <83450930+Liyulingyue@users.noreply.github.com> Date: Tue, 16 Jan 2024 18:49:52 +0800 Subject: [PATCH 02/29] Update CMakeLists.txt --- test/cpp/pir/pattern_rewrite/CMakeLists.txt | 54 ++++++++++++++++----- 1 file changed, 42 insertions(+), 12 deletions(-) diff --git a/test/cpp/pir/pattern_rewrite/CMakeLists.txt b/test/cpp/pir/pattern_rewrite/CMakeLists.txt index b4ebbc26aa3440..30e22c273b2e08 100644 --- a/test/cpp/pir/pattern_rewrite/CMakeLists.txt +++ b/test/cpp/pir/pattern_rewrite/CMakeLists.txt @@ -1,29 +1,59 @@ paddle_test( pattern_rewrite_test - SRCS pattern_rewrite_test.cc - DEPS gtest op_dialect_vjp pir pir_transforms) + SRCS + pattern_rewrite_test.cc + DEPS + gtest op_dialect_vjp + pir + pir_transforms) paddle_test( drr_test - SRCS drr_test.cc - DEPS drr pir_transforms) + SRCS + drr_test.cc + DEPS + drr pir_transforms) paddle_test( drr_same_type_binding_test - SRCS drr_same_type_binding_test.cc - DEPS drr gtest op_dialect_vjp pir pir_transforms) + SRCS + drr_same_type_binding_test.cc + DEPS + drr + gtest + op_dialect_vjp + pir + pir_transforms) paddle_test( drr_fuse_linear_test - SRCS drr_fuse_linear_test.cc - DEPS pir_transforms drr gtest op_dialect_vjp pir) + SRCS + drr_fuse_linear_test.cc + DEPS + pir_transforms + drr + gtest + op_dialect_vjp + pir) paddle_test( drr_fuse_linear_param_grad_add_test - SRCS drr_fuse_linear_param_grad_add_test.cc - DEPS pir_transforms drr gtest op_dialect_vjp pir) + SRCS + drr_fuse_linear_param_grad_add_test.cc + DEPS + pir_transforms + drr + gtest + op_dialect_vjp + pir) paddle_test( drr_attention_fuse_test - SRCS drr_attention_fuse_test.cc - DEPS pir_transforms drr gtest op_dialect_vjp pir) + SRCS + drr_attention_fuse_test.cc + DEPS + pir_transforms + drr + gtest + op_dialect_vjp + pir) From 77306c30312df8742ce1537b6cc518997de4e1a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=98=A5=E4=B9=94?= <83450930+Liyulingyue@users.noreply.github.com> Date: Wed, 17 Jan 2024 07:04:59 +0800 Subject: [PATCH 03/29] Update CMakeLists.txt --- test/cpp/pir/pattern_rewrite/CMakeLists.txt | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/test/cpp/pir/pattern_rewrite/CMakeLists.txt b/test/cpp/pir/pattern_rewrite/CMakeLists.txt index 30e22c273b2e08..98e3f9a8fc8242 100644 --- a/test/cpp/pir/pattern_rewrite/CMakeLists.txt +++ b/test/cpp/pir/pattern_rewrite/CMakeLists.txt @@ -3,16 +3,12 @@ paddle_test( SRCS pattern_rewrite_test.cc DEPS - gtest op_dialect_vjp + gtest + op_dialect_vjp pir pir_transforms) -paddle_test( - drr_test - SRCS - drr_test.cc - DEPS - drr pir_transforms) +paddle_test(drr_test SRCS drr_test.cc DEPS drr pir_transforms) paddle_test( drr_same_type_binding_test From 305624242c0f6bbd30769b006aba08d71b1b4ef8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=98=A5=E4=B9=94?= <83450930+Liyulingyue@users.noreply.github.com> Date: Sun, 28 Jan 2024 21:49:39 +0800 Subject: [PATCH 04/29] Update CMakeLists.txt --- test/cpp/pir/pattern_rewrite/CMakeLists.txt | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/test/cpp/pir/pattern_rewrite/CMakeLists.txt b/test/cpp/pir/pattern_rewrite/CMakeLists.txt index 98e3f9a8fc8242..b9c667ca7f7d39 100644 --- a/test/cpp/pir/pattern_rewrite/CMakeLists.txt +++ b/test/cpp/pir/pattern_rewrite/CMakeLists.txt @@ -3,10 +3,7 @@ paddle_test( SRCS pattern_rewrite_test.cc DEPS - gtest - op_dialect_vjp - pir - pir_transforms) + op_dialect_vjp) paddle_test(drr_test SRCS drr_test.cc DEPS drr pir_transforms) @@ -16,10 +13,7 @@ paddle_test( drr_same_type_binding_test.cc DEPS drr - gtest - op_dialect_vjp - pir - pir_transforms) + op_dialect_vjp) paddle_test( drr_fuse_linear_test @@ -27,10 +21,7 @@ paddle_test( drr_fuse_linear_test.cc DEPS pir_transforms - drr - gtest - op_dialect_vjp - pir) + drr) paddle_test( drr_fuse_linear_param_grad_add_test @@ -39,8 +30,6 @@ paddle_test( DEPS pir_transforms drr - gtest - op_dialect_vjp pir) paddle_test( @@ -50,6 +39,4 @@ paddle_test( DEPS pir_transforms drr - gtest - op_dialect_vjp pir) From 2e2bf71dd76ad743905d494a902638dca35989a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=98=A5=E4=B9=94?= <83450930+Liyulingyue@users.noreply.github.com> Date: Mon, 29 Jan 2024 17:58:58 +0800 Subject: [PATCH 05/29] Update CMakeLists.txt --- test/cpp/pir/pattern_rewrite/CMakeLists.txt | 31 +++------------------ 1 file changed, 4 insertions(+), 27 deletions(-) diff --git a/test/cpp/pir/pattern_rewrite/CMakeLists.txt b/test/cpp/pir/pattern_rewrite/CMakeLists.txt index b03fbc7bf8ee9a..d95e357736c800 100644 --- a/test/cpp/pir/pattern_rewrite/CMakeLists.txt +++ b/test/cpp/pir/pattern_rewrite/CMakeLists.txt @@ -2,36 +2,13 @@ paddle_test(pattern_rewrite_test SRCS pattern_rewrite_test.cc) paddle_test(drr_test SRCS drr_test.cc DEPS drr pir_transforms) -paddle_test( - drr_same_type_binding_test - SRCS - drr_same_type_binding_test.cc - DEPS - drr) +paddle_test(drr_same_type_binding_test SRCS drr_same_type_binding_test.cc) -paddle_test( - drr_fuse_linear_test - SRCS - drr_fuse_linear_test.cc - DEPS - pir_transforms - drr) +paddle_test(drr_fuse_linear_test SRCS drr_fuse_linear_test.cc DEPS) -paddle_test( - drr_fuse_linear_param_grad_add_test - SRCS - drr_fuse_linear_param_grad_add_test.cc - DEPS - pir_transforms - drr) +paddle_test(drr_fuse_linear_param_grad_add_test SRCS drr_fuse_linear_param_grad_add_test.cc) if(WITH_GPU) paddle_test( - drr_attention_fuse_test - SRCS - drr_attention_fuse_test.cc - DEPS - pir_transforms - drr - gtest) + drr_attention_fuse_test SRCS drr_attention_fuse_test.cc) endif() From 6351c9fd99a21fcc3fe56f9fe4431eb6a3367f29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=98=A5=E4=B9=94?= <83450930+Liyulingyue@users.noreply.github.com> Date: Mon, 29 Jan 2024 22:53:20 +0800 Subject: [PATCH 06/29] Update op_gen.py --- paddle/fluid/pir/dialect/op_generator/op_gen.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/paddle/fluid/pir/dialect/op_generator/op_gen.py b/paddle/fluid/pir/dialect/op_generator/op_gen.py index 1ea887a7a1920e..d728264da5c4de 100644 --- a/paddle/fluid/pir/dialect/op_generator/op_gen.py +++ b/paddle/fluid/pir/dialect/op_generator/op_gen.py @@ -46,7 +46,7 @@ # Note(Galaxy1458) The need_export_symbol_op_list is used # for some unittests these need to export symbol op compiled with dynamic lib. -need_export_symbol_op_list = ['AbsOp', 'FullOp', 'UniformOp'] +need_export_symbol_op_list = ['AbsOp', 'FullOp', 'UniformOp', 'ScaleOp', 'AddOp', 'FetchOp', 'MatmulOp', 'ReshapeOp', 'SoftmaxOp', 'TransposeOp'] # ===================================== # String Template for h file code gen From 68a92d3ece16530922c56954e44cea3c971a1ed0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=98=A5=E4=B9=94?= <83450930+Liyulingyue@users.noreply.github.com> Date: Tue, 30 Jan 2024 06:40:01 +0800 Subject: [PATCH 07/29] Update CMakeLists.txt --- test/cpp/pir/pattern_rewrite/CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/cpp/pir/pattern_rewrite/CMakeLists.txt b/test/cpp/pir/pattern_rewrite/CMakeLists.txt index d95e357736c800..e9a1cec2902b3e 100644 --- a/test/cpp/pir/pattern_rewrite/CMakeLists.txt +++ b/test/cpp/pir/pattern_rewrite/CMakeLists.txt @@ -1,14 +1,14 @@ paddle_test(pattern_rewrite_test SRCS pattern_rewrite_test.cc) -paddle_test(drr_test SRCS drr_test.cc DEPS drr pir_transforms) +paddle_test(drr_test SRCS drr_test.cc) paddle_test(drr_same_type_binding_test SRCS drr_same_type_binding_test.cc) -paddle_test(drr_fuse_linear_test SRCS drr_fuse_linear_test.cc DEPS) +paddle_test(drr_fuse_linear_test SRCS drr_fuse_linear_test.cc) paddle_test(drr_fuse_linear_param_grad_add_test SRCS drr_fuse_linear_param_grad_add_test.cc) if(WITH_GPU) paddle_test( - drr_attention_fuse_test SRCS drr_attention_fuse_test.cc) + drr_attention_fuse_test SRCS drr_attention_fuse_test.cc) endif() From af7f20c5007984c34990fba3ebd99c857f5ebeec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=98=A5=E4=B9=94?= <83450930+Liyulingyue@users.noreply.github.com> Date: Tue, 30 Jan 2024 22:02:23 +0800 Subject: [PATCH 08/29] Update CMakeLists.txt --- test/cpp/pir/pattern_rewrite/CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/cpp/pir/pattern_rewrite/CMakeLists.txt b/test/cpp/pir/pattern_rewrite/CMakeLists.txt index e9a1cec2902b3e..b895384cf11c18 100644 --- a/test/cpp/pir/pattern_rewrite/CMakeLists.txt +++ b/test/cpp/pir/pattern_rewrite/CMakeLists.txt @@ -6,9 +6,9 @@ paddle_test(drr_same_type_binding_test SRCS drr_same_type_binding_test.cc) paddle_test(drr_fuse_linear_test SRCS drr_fuse_linear_test.cc) -paddle_test(drr_fuse_linear_param_grad_add_test SRCS drr_fuse_linear_param_grad_add_test.cc) +paddle_test(drr_fuse_linear_param_grad_add_test SRCS + drr_fuse_linear_param_grad_add_test.cc) if(WITH_GPU) - paddle_test( - drr_attention_fuse_test SRCS drr_attention_fuse_test.cc) + paddle_test(drr_attention_fuse_test SRCS drr_attention_fuse_test.cc) endif() From b19e188db563e03c5ce4765558723e03702c9717 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=98=A5=E4=B9=94?= <83450930+Liyulingyue@users.noreply.github.com> Date: Tue, 30 Jan 2024 23:10:11 +0800 Subject: [PATCH 09/29] Apply suggestions from code review --- test/cpp/pir/pattern_rewrite/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/cpp/pir/pattern_rewrite/CMakeLists.txt b/test/cpp/pir/pattern_rewrite/CMakeLists.txt index b895384cf11c18..4bd5a144a691f4 100644 --- a/test/cpp/pir/pattern_rewrite/CMakeLists.txt +++ b/test/cpp/pir/pattern_rewrite/CMakeLists.txt @@ -6,7 +6,7 @@ paddle_test(drr_same_type_binding_test SRCS drr_same_type_binding_test.cc) paddle_test(drr_fuse_linear_test SRCS drr_fuse_linear_test.cc) -paddle_test(drr_fuse_linear_param_grad_add_test SRCS +paddle_test(drr_fuse_linear_param_grad_add_test SRCS drr_fuse_linear_param_grad_add_test.cc) if(WITH_GPU) From 57f505271ef48c097a9406a2e9aa9f86f50081db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=98=A5=E4=B9=94?= <83450930+Liyulingyue@users.noreply.github.com> Date: Wed, 31 Jan 2024 07:13:08 +0800 Subject: [PATCH 10/29] Update op_gen.py --- paddle/fluid/pir/dialect/op_generator/op_gen.py | 1 + 1 file changed, 1 insertion(+) diff --git a/paddle/fluid/pir/dialect/op_generator/op_gen.py b/paddle/fluid/pir/dialect/op_generator/op_gen.py index 5da1f3132dc3ac..f110204a0815b0 100644 --- a/paddle/fluid/pir/dialect/op_generator/op_gen.py +++ b/paddle/fluid/pir/dialect/op_generator/op_gen.py @@ -57,6 +57,7 @@ 'FetchOp', 'MatmulOp', 'SoftmaxOp', + 'ReshapeOp', 'TransposeOp', ] From 126b33b6dc7a80790ddf960de629e5f511daba30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=98=A5=E4=B9=94?= <83450930+Liyulingyue@users.noreply.github.com> Date: Thu, 1 Feb 2024 19:54:19 +0800 Subject: [PATCH 11/29] Update op_gen.py --- paddle/fluid/pir/dialect/op_generator/op_gen.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/paddle/fluid/pir/dialect/op_generator/op_gen.py b/paddle/fluid/pir/dialect/op_generator/op_gen.py index a522a17f8cbf81..543ef9d0b94584 100644 --- a/paddle/fluid/pir/dialect/op_generator/op_gen.py +++ b/paddle/fluid/pir/dialect/op_generator/op_gen.py @@ -61,6 +61,14 @@ 'TransposeOp', 'LessThanOp', 'AddGradOp', + 'ConcatOp', + 'CummaxOp', + 'CastOp', + 'ReluOp', + 'ReluGradOp', + 'BatchNorm_Op', + 'GeluOp', + 'GeluGradOp', 'MatmulGradOp', ] From 5cbd2337becf73b4580ce7d83ab8f9b177183eb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=98=A5=E4=B9=94?= <83450930+Liyulingyue@users.noreply.github.com> Date: Thu, 1 Feb 2024 23:09:38 +0800 Subject: [PATCH 12/29] Update op_gen.py --- paddle/fluid/pir/dialect/op_generator/op_gen.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/paddle/fluid/pir/dialect/op_generator/op_gen.py b/paddle/fluid/pir/dialect/op_generator/op_gen.py index 543ef9d0b94584..c6606fbabb154c 100644 --- a/paddle/fluid/pir/dialect/op_generator/op_gen.py +++ b/paddle/fluid/pir/dialect/op_generator/op_gen.py @@ -47,6 +47,7 @@ # Note(Galaxy1458) The need_export_symbol_op_list is used # for some unittests these need to export symbol op compiled with dynamic lib. need_export_symbol_op_list = [ + 'Add_Op', 'AbsOp', 'FullOp', 'UniformOp', @@ -55,11 +56,13 @@ 'Conv2dOp', 'BatchNormOp', 'FetchOp', + 'FullIntArrayOp', 'MatmulOp', 'SoftmaxOp', 'ReshapeOp', 'TransposeOp', 'LessThanOp', + 'LayerNormOp', 'AddGradOp', 'ConcatOp', 'CummaxOp', From af41fe82cc41fbfe43dbae5214bef4f41eeaaa40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=98=A5=E4=B9=94?= <83450930+Liyulingyue@users.noreply.github.com> Date: Fri, 2 Feb 2024 06:58:03 +0800 Subject: [PATCH 13/29] Update transform_general_functions.h --- paddle/fluid/pir/transforms/transform_general_functions.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/paddle/fluid/pir/transforms/transform_general_functions.h b/paddle/fluid/pir/transforms/transform_general_functions.h index 82ca3ae79491f1..07839ed282559d 100644 --- a/paddle/fluid/pir/transforms/transform_general_functions.h +++ b/paddle/fluid/pir/transforms/transform_general_functions.h @@ -61,7 +61,7 @@ pir::Type GetDataTypeFromValue(pir::Value value); * * @return Operation* */ -Operation* GetDefiningOpForInput(const Operation* op, uint32_t index); +TEST_API Operation* GetDefiningOpForInput(const Operation* op, uint32_t index); /** * @brief Get operations and the index of designative op operand (op result) From e4e6c813adeadf1af7c77d19a1a6692d5a7f8bcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=98=A5=E4=B9=94?= <83450930+Liyulingyue@users.noreply.github.com> Date: Fri, 2 Feb 2024 18:46:08 +0800 Subject: [PATCH 14/29] Update manual_op.h --- paddle/fluid/pir/dialect/operator/ir/manual_op.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/paddle/fluid/pir/dialect/operator/ir/manual_op.h b/paddle/fluid/pir/dialect/operator/ir/manual_op.h index d01b089981b7c2..0c19efd09cb74c 100644 --- a/paddle/fluid/pir/dialect/operator/ir/manual_op.h +++ b/paddle/fluid/pir/dialect/operator/ir/manual_op.h @@ -549,10 +549,10 @@ class ExpandOp : public pir::Op &shape = {}); - static void Build(pir::Builder &builder, // NOLINT - pir::OperationArgument &argument, // NOLINT - pir::Value x_, // NOLINT - pir::Value shape_ // NOLINT + TEST_API static void Build(pir::Builder &builder, // NOLINT + pir::OperationArgument &argument, // NOLINT + pir::Value x_, // NOLINT + pir::Value shape_ // NOLINT ); static void Build(pir::Builder &builder, // NOLINT pir::OperationArgument &argument, // NOLINT From 4314aa027e803a1122dc786e3fc263c7e91734fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=98=A5=E4=B9=94?= <83450930+Liyulingyue@users.noreply.github.com> Date: Fri, 2 Feb 2024 18:54:46 +0800 Subject: [PATCH 15/29] Update drr_pattern_context.h --- .../pir/drr/include/drr_pattern_context.h | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/paddle/fluid/pir/drr/include/drr_pattern_context.h b/paddle/fluid/pir/drr/include/drr_pattern_context.h index f6705ecdc76781..c1f7ade9cb9d2a 100644 --- a/paddle/fluid/pir/drr/include/drr_pattern_context.h +++ b/paddle/fluid/pir/drr/include/drr_pattern_context.h @@ -105,7 +105,7 @@ class DrrPatternContext { DrrPatternContext(); ~DrrPatternContext() = default; - drr::SourcePattern SourcePattern(); + TEST_API drr::SourcePattern SourcePattern(); std::shared_ptr source_pattern_graph() const { return source_pattern_graph_; @@ -121,19 +121,19 @@ class DrrPatternContext { friend class drr::SourcePattern; friend class drr::ResultPattern; - const Op& SourceOpPattern( + TEST_API const Op& SourceOpPattern( const std::string& op_type, const std::unordered_map& attributes = {}); - const drr::Tensor& SourceTensorPattern(const std::string& name); + TEST_API const drr::Tensor& SourceTensorPattern(const std::string& name); - const Op& ResultOpPattern( + TEST_API const Op& ResultOpPattern( const std::string& op_type, const std::unordered_map& attributes = {}); - drr::Tensor& ResultTensorPattern(const std::string& name); + TEST_API drr::Tensor& ResultTensorPattern(const std::string& name); // void RequireEqual(const Attribute& first, const Attribute& second); void RequireEqual(const TensorShape& first, const TensorShape& second); - void RequireEqual(const TensorDataType& first, const TensorDataType& second); + TEST_API void RequireEqual(const TensorDataType& first, const TensorDataType& second); void RequireNativeCall(const ConstraintFunction& custom_fn); std::shared_ptr source_pattern_graph_; @@ -147,17 +147,17 @@ class Op { public: const std::string& name() const { return op_type_name_; } - void operator()(const Tensor& arg, const Tensor* out) const; + TEST_API void operator()(const Tensor& arg, const Tensor* out) const; Tensor& operator()() const; - Tensor& operator()(const Tensor& arg) const; - Tensor& operator()(const Tensor& arg0, const Tensor& arg1) const; + TEST_API Tensor& operator()(const Tensor& arg) const; + TEST_API Tensor& operator()(const Tensor& arg0, const Tensor& arg1) const; Tensor& operator()(const Tensor& arg0, const Tensor& arg1, const Tensor& arg2) const; - void operator()(const std::vector& args, - const std::vector& outputs) const; + TEST_API void operator()(const std::vector& args, + const std::vector& outputs) const; // const Tensor& operator()(const Tensor& arg0, const Tensor& arg1, const // Tensor& arg2) const; const Tensor& operator()(const Tensor& arg0, const // Tensor& arg1, const Tensor& arg2, const Tensor& arg3) const; const Tensor& @@ -198,9 +198,9 @@ class Tensor { bool is_none() const { return name_ == NONE_TENSOR_NAME; } - void Assign(const Tensor& other); + TEST_API void Assign(const Tensor& other); - void operator=(const Tensor& other) const; // NOLINT + TEST_API void operator=(const Tensor& other) const; // NOLINT const std::string& name() const { return name_; } From 5f3db99572ca78c2d2959ca230646c9bb57beeb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=98=A5=E4=B9=94?= <83450930+Liyulingyue@users.noreply.github.com> Date: Fri, 2 Feb 2024 22:16:52 +0800 Subject: [PATCH 16/29] Update drr_pattern_context.h --- paddle/fluid/pir/drr/include/drr_pattern_context.h | 1 + 1 file changed, 1 insertion(+) diff --git a/paddle/fluid/pir/drr/include/drr_pattern_context.h b/paddle/fluid/pir/drr/include/drr_pattern_context.h index c1f7ade9cb9d2a..14bd027bfea74d 100644 --- a/paddle/fluid/pir/drr/include/drr_pattern_context.h +++ b/paddle/fluid/pir/drr/include/drr_pattern_context.h @@ -25,6 +25,7 @@ #include #include "paddle/fluid/pir/drr/include/drr_match_context.h" +#include "paddle/utils/test_macros.h" namespace paddle { namespace drr { From eab5a64d5c9c3788c305593b714278ce1e8d4a0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=98=A5=E4=B9=94?= <83450930+Liyulingyue@users.noreply.github.com> Date: Sat, 3 Feb 2024 12:04:01 +0800 Subject: [PATCH 17/29] Apply suggestions from code review --- paddle/fluid/pir/drr/include/drr_pattern_context.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/paddle/fluid/pir/drr/include/drr_pattern_context.h b/paddle/fluid/pir/drr/include/drr_pattern_context.h index 14bd027bfea74d..3e44123fa099f8 100644 --- a/paddle/fluid/pir/drr/include/drr_pattern_context.h +++ b/paddle/fluid/pir/drr/include/drr_pattern_context.h @@ -134,7 +134,8 @@ class DrrPatternContext { // void RequireEqual(const Attribute& first, const Attribute& second); void RequireEqual(const TensorShape& first, const TensorShape& second); - TEST_API void RequireEqual(const TensorDataType& first, const TensorDataType& second); + TEST_API void RequireEqual(const TensorDataType& first, + const TensorDataType& second); void RequireNativeCall(const ConstraintFunction& custom_fn); std::shared_ptr source_pattern_graph_; From 62ef0f9ef8c7f3d3917beec303713c1bd5a12190 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=98=A5=E4=B9=94?= <83450930+Liyulingyue@users.noreply.github.com> Date: Sat, 3 Feb 2024 21:04:22 +0800 Subject: [PATCH 18/29] Update drr_pattern_context.h --- paddle/fluid/pir/drr/include/drr_pattern_context.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/paddle/fluid/pir/drr/include/drr_pattern_context.h b/paddle/fluid/pir/drr/include/drr_pattern_context.h index 3e44123fa099f8..d72c3d2ade99fe 100644 --- a/paddle/fluid/pir/drr/include/drr_pattern_context.h +++ b/paddle/fluid/pir/drr/include/drr_pattern_context.h @@ -135,7 +135,7 @@ class DrrPatternContext { // void RequireEqual(const Attribute& first, const Attribute& second); void RequireEqual(const TensorShape& first, const TensorShape& second); TEST_API void RequireEqual(const TensorDataType& first, - const TensorDataType& second); + const TensorDataType& second); void RequireNativeCall(const ConstraintFunction& custom_fn); std::shared_ptr source_pattern_graph_; From 78cce3d7403347e97bfca24cdc13b8e43b97bfdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=98=A5=E4=B9=94?= <83450930+Liyulingyue@users.noreply.github.com> Date: Sat, 3 Feb 2024 22:10:04 +0800 Subject: [PATCH 19/29] Update drr_pattern_context.h --- paddle/fluid/pir/drr/include/drr_pattern_context.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/paddle/fluid/pir/drr/include/drr_pattern_context.h b/paddle/fluid/pir/drr/include/drr_pattern_context.h index d72c3d2ade99fe..40be284ecced87 100644 --- a/paddle/fluid/pir/drr/include/drr_pattern_context.h +++ b/paddle/fluid/pir/drr/include/drr_pattern_context.h @@ -134,7 +134,7 @@ class DrrPatternContext { // void RequireEqual(const Attribute& first, const Attribute& second); void RequireEqual(const TensorShape& first, const TensorShape& second); - TEST_API void RequireEqual(const TensorDataType& first, + TEST_API void RequireEqual(const TensorDataType& first, const TensorDataType& second); void RequireNativeCall(const ConstraintFunction& custom_fn); From 828fcb78936186024d14f59855437901a81b1a73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=98=A5=E4=B9=94?= <83450930+Liyulingyue@users.noreply.github.com> Date: Sun, 4 Feb 2024 18:35:10 +0800 Subject: [PATCH 20/29] Update drr_pattern_base.h --- paddle/fluid/pir/drr/include/drr_pattern_base.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/paddle/fluid/pir/drr/include/drr_pattern_base.h b/paddle/fluid/pir/drr/include/drr_pattern_base.h index 9e541dc53183f9..275cf9bb730b61 100644 --- a/paddle/fluid/pir/drr/include/drr_pattern_base.h +++ b/paddle/fluid/pir/drr/include/drr_pattern_base.h @@ -44,7 +44,7 @@ class DrrPatternBase { virtual uint32_t benefit() const { return 1; } // Build the Drr Pattern. - std::unique_ptr Build(pir::IrContext* ir_context) const; + TEST_API std::unique_ptr Build(pir::IrContext* ir_context) const; }; } // namespace drr From 25c4c36f9c4f8a6047fea3caec1b995a30d48862 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=98=A5=E4=B9=94?= <83450930+Liyulingyue@users.noreply.github.com> Date: Sun, 4 Feb 2024 18:37:14 +0800 Subject: [PATCH 21/29] Update drr_match_context.h --- paddle/fluid/pir/drr/include/drr_match_context.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/paddle/fluid/pir/drr/include/drr_match_context.h b/paddle/fluid/pir/drr/include/drr_match_context.h index 4339595b710d45..9ab2a18513f861 100644 --- a/paddle/fluid/pir/drr/include/drr_match_context.h +++ b/paddle/fluid/pir/drr/include/drr_match_context.h @@ -34,7 +34,7 @@ class MatchContext final { const pir::Value& Tensor(const std::string& tensor_name) const; template - T Attr(const std::string& attr_name) const; + TEST_API T Attr(const std::string& attr_name) const; private: std::shared_ptr impl_; From aa35989e6043c0d1885f19b62c152b8ea61dcdc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=98=A5=E4=B9=94?= <83450930+Liyulingyue@users.noreply.github.com> Date: Sun, 4 Feb 2024 18:42:24 +0800 Subject: [PATCH 22/29] Update drr_pattern_context.h --- .../fluid/pir/drr/include/drr_pattern_context.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/paddle/fluid/pir/drr/include/drr_pattern_context.h b/paddle/fluid/pir/drr/include/drr_pattern_context.h index 40be284ecced87..5ae6a48d5e2730 100644 --- a/paddle/fluid/pir/drr/include/drr_pattern_context.h +++ b/paddle/fluid/pir/drr/include/drr_pattern_context.h @@ -93,7 +93,7 @@ class Constraint { public: explicit Constraint(const ConstraintFunction& constrain_fn) : IsContextMatchConstraint_(constrain_fn) {} - bool operator()(const MatchContext& match_context) const { + bool erator()(const MatchContext& match_context) const { return IsContextMatchConstraint_(match_context); } @@ -122,13 +122,13 @@ class DrrPatternContext { friend class drr::SourcePattern; friend class drr::ResultPattern; - TEST_API const Op& SourceOpPattern( - const std::string& op_type, + TEST_API const & SourcePattern( + const std::string& _type, const std::unordered_map& attributes = {}); TEST_API const drr::Tensor& SourceTensorPattern(const std::string& name); - TEST_API const Op& ResultOpPattern( - const std::string& op_type, + TEST_API const & ResultPattern( + const std::string& _type, const std::unordered_map& attributes = {}); TEST_API drr::Tensor& ResultTensorPattern(const std::string& name); @@ -142,16 +142,16 @@ class DrrPatternContext { std::vector constraints_; std::shared_ptr result_pattern_graph_; - std::vector> owned_ops_; + std::vector> owned_s_; }; -class Op { +class { public: const std::string& name() const { return op_type_name_; } TEST_API void operator()(const Tensor& arg, const Tensor* out) const; - Tensor& operator()() const; + TEST_API Tensor& operator()() const; TEST_API Tensor& operator()(const Tensor& arg) const; TEST_API Tensor& operator()(const Tensor& arg0, const Tensor& arg1) const; From 1aa763b6f4d725d3600f5645574bfb13ea924d39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=98=A5=E4=B9=94?= <83450930+Liyulingyue@users.noreply.github.com> Date: Sun, 4 Feb 2024 19:11:53 +0800 Subject: [PATCH 23/29] Update drr_pattern_context.h --- paddle/fluid/pir/drr/include/drr_pattern_context.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/paddle/fluid/pir/drr/include/drr_pattern_context.h b/paddle/fluid/pir/drr/include/drr_pattern_context.h index 5ae6a48d5e2730..77d6f94d6b4c9c 100644 --- a/paddle/fluid/pir/drr/include/drr_pattern_context.h +++ b/paddle/fluid/pir/drr/include/drr_pattern_context.h @@ -93,7 +93,7 @@ class Constraint { public: explicit Constraint(const ConstraintFunction& constrain_fn) : IsContextMatchConstraint_(constrain_fn) {} - bool erator()(const MatchContext& match_context) const { + bool operator()(const MatchContext& match_context) const { return IsContextMatchConstraint_(match_context); } @@ -122,13 +122,13 @@ class DrrPatternContext { friend class drr::SourcePattern; friend class drr::ResultPattern; - TEST_API const & SourcePattern( - const std::string& _type, + TEST_API const Op& SourcePattern( + const std::string& op_type, const std::unordered_map& attributes = {}); TEST_API const drr::Tensor& SourceTensorPattern(const std::string& name); - TEST_API const & ResultPattern( - const std::string& _type, + TEST_API const Op& ResultPattern( + const std::string& op_type, const std::unordered_map& attributes = {}); TEST_API drr::Tensor& ResultTensorPattern(const std::string& name); @@ -142,10 +142,10 @@ class DrrPatternContext { std::vector constraints_; std::shared_ptr result_pattern_graph_; - std::vector> owned_s_; + std::vector> owned_ops_; }; -class { +class Op { public: const std::string& name() const { return op_type_name_; } From 30c3828e5a44a5c9f1cfd1ce0c6b6c537edf6a63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=98=A5=E4=B9=94?= <83450930+Liyulingyue@users.noreply.github.com> Date: Wed, 7 Feb 2024 05:37:43 +0800 Subject: [PATCH 24/29] Update drr_match_context.h --- paddle/fluid/pir/drr/include/drr_match_context.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/paddle/fluid/pir/drr/include/drr_match_context.h b/paddle/fluid/pir/drr/include/drr_match_context.h index 9ab2a18513f861..c999ece699f7cb 100644 --- a/paddle/fluid/pir/drr/include/drr_match_context.h +++ b/paddle/fluid/pir/drr/include/drr_match_context.h @@ -17,6 +17,8 @@ #include #include +#include "paddle/utils/test_macros.h" + namespace pir { class Value; } From cbfa108b530753b362b4ca4c26c839f8107b5897 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=98=A5=E4=B9=94?= <83450930+Liyulingyue@users.noreply.github.com> Date: Wed, 7 Feb 2024 07:18:33 +0800 Subject: [PATCH 25/29] Apply suggestions from code review --- paddle/fluid/pir/drr/include/drr_pattern_context.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/paddle/fluid/pir/drr/include/drr_pattern_context.h b/paddle/fluid/pir/drr/include/drr_pattern_context.h index e0e0289bd1cd1f..9d0b95733ec72a 100644 --- a/paddle/fluid/pir/drr/include/drr_pattern_context.h +++ b/paddle/fluid/pir/drr/include/drr_pattern_context.h @@ -122,7 +122,7 @@ class DrrPatternContext { friend class drr::SourcePattern; friend class drr::ResultPattern; - TEST_API const Op& SourcePattern( + TEST_API const Op& SourceOpPattern( const std::string& op_type, const std::unordered_map& attributes = {}); TEST_API const drr::Tensor& SourceTensorPattern(const std::string& name); From 527dd40450f78b6178128bbbd4dfa92a1d694b2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=98=A5=E4=B9=94?= <83450930+Liyulingyue@users.noreply.github.com> Date: Wed, 7 Feb 2024 07:18:48 +0800 Subject: [PATCH 26/29] Apply suggestions from code review --- paddle/fluid/pir/drr/include/drr_pattern_context.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/paddle/fluid/pir/drr/include/drr_pattern_context.h b/paddle/fluid/pir/drr/include/drr_pattern_context.h index 9d0b95733ec72a..af70dee24b8d4c 100644 --- a/paddle/fluid/pir/drr/include/drr_pattern_context.h +++ b/paddle/fluid/pir/drr/include/drr_pattern_context.h @@ -127,7 +127,7 @@ class DrrPatternContext { const std::unordered_map& attributes = {}); TEST_API const drr::Tensor& SourceTensorPattern(const std::string& name); - TEST_API const Op& ResultPattern( + TEST_API const Op& ResultOpPattern( const std::string& op_type, const std::unordered_map& attributes = {}); TEST_API drr::Tensor& ResultTensorPattern(const std::string& name); From 8ab27ad0bd634baad6cbfd55305f8f4573c2b25e Mon Sep 17 00:00:00 2001 From: liyulingyue <852433440@qq.com> Date: Wed, 7 Feb 2024 08:20:48 +0800 Subject: [PATCH 27/29] add test_API --- paddle/fluid/pir/drr/include/drr_pattern_base.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/paddle/fluid/pir/drr/include/drr_pattern_base.h b/paddle/fluid/pir/drr/include/drr_pattern_base.h index da90f313bde900..ced3646d341c9c 100644 --- a/paddle/fluid/pir/drr/include/drr_pattern_base.h +++ b/paddle/fluid/pir/drr/include/drr_pattern_base.h @@ -30,7 +30,7 @@ namespace drr { class DrrPatternBase : public std::enable_shared_from_this { public: - static std::unique_ptr Build( + TEST_API static std::unique_ptr Build( pir::IrContext* ir_context, const std::shared_ptr& drr_pattern); From f3f990cc3460f384a3fb811a02b407129cced05e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=98=A5=E4=B9=94?= <83450930+Liyulingyue@users.noreply.github.com> Date: Wed, 7 Feb 2024 14:40:53 +0800 Subject: [PATCH 28/29] Update CMakeLists.txt --- test/cpp/pir/pattern_rewrite/CMakeLists.txt | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/cpp/pir/pattern_rewrite/CMakeLists.txt b/test/cpp/pir/pattern_rewrite/CMakeLists.txt index a3101d80f8e046..14393f37e45e7e 100644 --- a/test/cpp/pir/pattern_rewrite/CMakeLists.txt +++ b/test/cpp/pir/pattern_rewrite/CMakeLists.txt @@ -10,3 +10,16 @@ paddle_test(drr_fuse_linear_param_grad_add_test SRCS if(WITH_GPU) paddle_test(drr_attention_fuse_test SRCS drr_attention_fuse_test.cc) endif() + +if(WITH_ONNXRUNTIME AND WIN32) + # Copy onnxruntime for some c++ test in Windows, since the test will + # be build only in CI, so suppose the generator in Windows is Ninja. + copy_onnx(pattern_rewrite_test) + copy_onnx(drr_same_type_binding_test) + copy_onnx(drr_fuse_linear_test) + copy_onnx(drr_fuse_linear_param_grad_add_test) + + if(WITH_GPU) + copy_onnx(drr_attention_fuse_test) + endif() +endif() From f69ccd9f6a9312dca4cf256ca60c17fb3ac18f66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=98=A5=E4=B9=94?= <83450930+Liyulingyue@users.noreply.github.com> Date: Wed, 7 Feb 2024 15:02:26 +0800 Subject: [PATCH 29/29] Apply suggestions from code review --- test/cpp/pir/pattern_rewrite/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/test/cpp/pir/pattern_rewrite/CMakeLists.txt b/test/cpp/pir/pattern_rewrite/CMakeLists.txt index 14393f37e45e7e..30027fb5dd4c09 100644 --- a/test/cpp/pir/pattern_rewrite/CMakeLists.txt +++ b/test/cpp/pir/pattern_rewrite/CMakeLists.txt @@ -18,7 +18,6 @@ if(WITH_ONNXRUNTIME AND WIN32) copy_onnx(drr_same_type_binding_test) copy_onnx(drr_fuse_linear_test) copy_onnx(drr_fuse_linear_param_grad_add_test) - if(WITH_GPU) copy_onnx(drr_attention_fuse_test) endif()