From 3d14d711b875ccb13b07d17637fa143167f81eb7 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 05:52:56 +0800 Subject: [PATCH 01/22] Update test_quantization_scale_pass.py --- test/quantization/test_quantization_scale_pass.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/quantization/test_quantization_scale_pass.py b/test/quantization/test_quantization_scale_pass.py index 48a7a71a73f64..daeb17b3c5ef8 100644 --- a/test/quantization/test_quantization_scale_pass.py +++ b/test/quantization/test_quantization_scale_pass.py @@ -75,8 +75,7 @@ def quantization_scale( for_ci=False, ): def build_program(main, startup, is_test): - main.random_seed = seed - startup.random_seed = seed + paddle.seed(2023) with paddle.utils.unique_name.guard(): with paddle.static.program_guard(main, startup): img = paddle.static.data( From be297b2bf4e87f9d39fb48bc4fb8f7d280c964a1 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 05:54:30 +0800 Subject: [PATCH 02/22] Update test_rnn_decode_api.py --- test/legacy_test/test_rnn_decode_api.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/legacy_test/test_rnn_decode_api.py b/test/legacy_test/test_rnn_decode_api.py index 72bf68db45c44..cc6d2274ce486 100644 --- a/test/legacy_test/test_rnn_decode_api.py +++ b/test/legacy_test/test_rnn_decode_api.py @@ -177,8 +177,7 @@ def __init__( base.Program() if startup_program is None else startup_program ) if seed is not None: - self.main_program.random_seed = seed - self.startup_program.random_seed = seed + paddle.seed(seed) self.build_program(model_cls, alg_cls, model_hparams, alg_hparams) self.executor = executor From 27acf936e85f484fa4dfc6178da3f295d014bf60 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 05:55:27 +0800 Subject: [PATCH 03/22] Update test_save_inference_model.py --- test/dygraph_to_static/test_save_inference_model.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/test/dygraph_to_static/test_save_inference_model.py b/test/dygraph_to_static/test_save_inference_model.py index 7c1fff1c22022..2130e26cd803b 100644 --- a/test/dygraph_to_static/test_save_inference_model.py +++ b/test/dygraph_to_static/test_save_inference_model.py @@ -92,8 +92,7 @@ def tearDown(self): def test_save_inference_model(self): fc_size = 20 x_data = np.random.random((fc_size, fc_size)).astype('float32') - base.default_startup_program().random_seed = SEED - base.default_main_program().random_seed = SEED + paddle.seed(SEED) x = paddle.to_tensor(x_data) layer = paddle.jit.to_static(SimpleFcLayer(fc_size)) @@ -139,8 +138,7 @@ def test_save_pylayer_model(self): x_data = np.random.random((fc_size, fc_size)).astype('float32') paddle.framework._set_expected_place(place) - base.default_startup_program().random_seed = SEED - base.default_main_program().random_seed = SEED + paddle.seed(SEED) x = paddle.to_tensor(x_data) layer = paddle.jit.to_static(SimplePyLayerNet(fc_size)) adam = paddle.optimizer.SGD( From c94fbc12828d7d1ca6e75b972b8964af3eef23b0 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 05:55:57 +0800 Subject: [PATCH 04/22] Update test_seq2seq.py --- test/dygraph_to_static/test_seq2seq.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/dygraph_to_static/test_seq2seq.py b/test/dygraph_to_static/test_seq2seq.py index 30649401f4406..a4f93a1e46a08 100644 --- a/test/dygraph_to_static/test_seq2seq.py +++ b/test/dygraph_to_static/test_seq2seq.py @@ -52,8 +52,7 @@ def prepare_input(batch): def train(args, attn_model=False): with base.dygraph.guard(place): - paddle.static.default_startup_program().random_seed = 2020 - paddle.static.default_main_program().random_seed = 2020 + paddle.seed(2020) if attn_model: model = paddle.jit.to_static( From 2fa5117326274b0642d578990978ec3ed5c1b3c0 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 05:57:30 +0800 Subject: [PATCH 05/22] Update test_static_save_load.py --- test/legacy_test/test_static_save_load.py | 27 ++++++++--------------- 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/test/legacy_test/test_static_save_load.py b/test/legacy_test/test_static_save_load.py index b46f49dbfefc9..ca1adaed4ef0a 100644 --- a/test/legacy_test/test_static_save_load.py +++ b/test/legacy_test/test_static_save_load.py @@ -266,8 +266,7 @@ def test_ptb_rnn_cpu_float32(self): temp_dir = tempfile.TemporaryDirectory() with new_program_scope(): - base.default_startup_program().random_seed = seed - base.default_main_program().random_seed = seed + paddle.seed(seed) ptb_model = PtbModel( "ptb_model", hidden_size=hidden_size, @@ -397,8 +396,7 @@ def test_ptb_rnn_cpu_float32(self): temp_dir = tempfile.TemporaryDirectory() with new_program_scope(): - base.default_startup_program().random_seed = seed - base.default_main_program().random_seed = seed + paddle.seed(seed) ptb_model = PtbModel( "ptb_model", hidden_size=hidden_size, @@ -541,8 +539,7 @@ def test_ptb_rnn_cpu_float32(self): temp_dir = tempfile.TemporaryDirectory() with new_program_scope(): - base.default_startup_program().random_seed = seed - base.default_main_program().random_seed = seed + paddle.seed(seed) ptb_model = PtbModel( "ptb_model", hidden_size=hidden_size, @@ -670,8 +667,7 @@ def test_ptb_rnn_cpu_float32(self): temp_dir = tempfile.TemporaryDirectory() with new_program_scope(): - base.default_startup_program().random_seed = seed - base.default_main_program().random_seed = seed + paddle.seed(seed) ptb_model = PtbModel( "ptb_model", hidden_size=hidden_size, @@ -1001,8 +997,7 @@ def test_load_from_old_interface(self): batch_num = 200 with new_program_scope(): - base.default_startup_program().random_seed = seed - base.default_main_program().random_seed = seed + paddle.seed(seed) ptb_model = PtbModel( "ptb_model", hidden_size=hidden_size, @@ -1144,8 +1139,7 @@ def test_load_from_old_interface_var_list(self): batch_num = 200 with new_program_scope(): - base.default_startup_program().random_seed = seed - base.default_main_program().random_seed = seed + paddle.seed(seed) ptb_model = PtbModel( "ptb_model", hidden_size=hidden_size, @@ -1287,8 +1281,7 @@ def test_load_from_old_interface(self): temp_dir = tempfile.TemporaryDirectory() with new_program_scope(): - base.default_startup_program().random_seed = seed - base.default_main_program().random_seed = seed + paddle.seed(seed) ptb_model = PtbModel( "ptb_model", hidden_size=hidden_size, @@ -1479,8 +1472,7 @@ def test_ptb_rnn_cpu_float32(self): batch_num = 200 with new_program_scope(): - base.default_startup_program().random_seed = seed - base.default_main_program().random_seed = seed + paddle.seed(seed) ptb_model = PtbModel( "ptb_model", hidden_size=hidden_size, @@ -1655,8 +1647,7 @@ def test_ptb_rnn_cpu_float32(self): temp_dir = tempfile.TemporaryDirectory() with new_program_scope(): - base.default_startup_program().random_seed = seed - base.default_main_program().random_seed = seed + paddle.seed(seed) ptb_model = PtbModel( "ptb_model", hidden_size=hidden_size, From 35a560400306156167b564655707ca6099bda3ce 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:20:44 +0800 Subject: [PATCH 06/22] Update CMakeLists.txt --- test/cpp/fluid/mkldnn/CMakeLists.txt | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/test/cpp/fluid/mkldnn/CMakeLists.txt b/test/cpp/fluid/mkldnn/CMakeLists.txt index 98a48cbc0a674..91911ce020cd7 100644 --- a/test/cpp/fluid/mkldnn/CMakeLists.txt +++ b/test/cpp/fluid/mkldnn/CMakeLists.txt @@ -1,17 +1,7 @@ get_property(paddle_lib GLOBAL PROPERTY PADDLE_LIB_NAME) -cc_test( +paddle_test( test_mkldnn_op_inplace - SRCS test_mkldnn_op_inplace.cc - DEPS executor - op_registry - elementwise_add_op - activation_op - phi - common - scope - device_context - enforce - generated_static_op) + SRCS test_mkldnn_op_inplace.cc) cc_test( test_mkldnn_cpu_quantize_pass SRCS test_mkldnn_cpu_quantize_pass.cc From e3a5f7de87637b890234b593d57bd608ce38dfdb Mon Sep 17 00:00:00 2001 From: liyulingyue <852433440@qq.com> Date: Wed, 7 Feb 2024 08:45:17 +0800 Subject: [PATCH 07/22] mv PD_DECLARE and USE_OP_ITSELF in test_mkldnn_op_inplace.cc --- test/cpp/fluid/mkldnn/test_mkldnn_op_inplace.cc | 6 ------ 1 file changed, 6 deletions(-) diff --git a/test/cpp/fluid/mkldnn/test_mkldnn_op_inplace.cc b/test/cpp/fluid/mkldnn/test_mkldnn_op_inplace.cc index 1c1a0cfb21914..9317722e6f8d4 100644 --- a/test/cpp/fluid/mkldnn/test_mkldnn_op_inplace.cc +++ b/test/cpp/fluid/mkldnn/test_mkldnn_op_inplace.cc @@ -26,13 +26,7 @@ #include "paddle/phi/core/enforce.h" #include "paddle/phi/core/kernel_registry.h" -USE_OP_ITSELF(elementwise_add); PD_DECLARE_KERNEL(add_raw, OneDNN, ONEDNN); -USE_OP_ITSELF(relu); -PD_DECLARE_KERNEL(relu, OneDNN, ONEDNN); -USE_OP_ITSELF(softmax); -PD_DECLARE_KERNEL(softmax, OneDNN, ONEDNN); -PD_DECLARE_KERNEL(softmax, CPU, ALL_LAYOUT); namespace paddle { namespace operators { From 6f2047ac9c7846c7b387a0e8b0830649fcf6fd8e 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:45:39 +0800 Subject: [PATCH 08/22] Update CMakeLists.txt --- test/cpp/fluid/mkldnn/CMakeLists.txt | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/test/cpp/fluid/mkldnn/CMakeLists.txt b/test/cpp/fluid/mkldnn/CMakeLists.txt index 91911ce020cd7..350ed9008bb3f 100644 --- a/test/cpp/fluid/mkldnn/CMakeLists.txt +++ b/test/cpp/fluid/mkldnn/CMakeLists.txt @@ -1,20 +1,6 @@ get_property(paddle_lib GLOBAL PROPERTY PADDLE_LIB_NAME) -paddle_test( - test_mkldnn_op_inplace - SRCS test_mkldnn_op_inplace.cc) -cc_test( - test_mkldnn_cpu_quantize_pass - SRCS test_mkldnn_cpu_quantize_pass.cc - DEPS executor - op_registry - activation_op - conv_activation_mkldnn_fuse_pass - cpu_quantize_placement_pass - cpu_quantize_pass - phi - common - scope - device_context) +paddle_test(test_mkldnn_op_inplace SRCS test_mkldnn_op_inplace.cc) +paddle_test(test_mkldnn_cpu_quantize_pass SRCS test_mkldnn_cpu_quantize_pass.cc) cc_test( test_conv_mkldnn_nhwc From 1623c0ca528b4ce3a3eb2f76d386afe77e9f129a Mon Sep 17 00:00:00 2001 From: liyulingyue <852433440@qq.com> Date: Wed, 7 Feb 2024 23:10:58 +0800 Subject: [PATCH 09/22] add test_API and rm USE_PASS --- paddle/fluid/framework/ir/pass.h | 6 +++--- test/cpp/fluid/mkldnn/test_mkldnn_cpu_quantize_pass.cc | 4 ---- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/paddle/fluid/framework/ir/pass.h b/paddle/fluid/framework/ir/pass.h index 753fadd242ebc..2249378bce3b5 100644 --- a/paddle/fluid/framework/ir/pass.h +++ b/paddle/fluid/framework/ir/pass.h @@ -37,7 +37,7 @@ constexpr char kStartupProgramDescs[] = "startup_program_descs"; } // namespace details namespace ir { -class Graph; +class TEST_API Graph; template struct PassRegistrar; @@ -81,7 +81,7 @@ class Pass { std::string Type() const { return type_; } - Graph *Apply(Graph *graph) const; + TEST_API Graph *Apply(Graph *graph) const; // Get a reference to the attributed previously set. template @@ -238,7 +238,7 @@ class Registrar { class PassRegistry { public: - static PassRegistry &Instance(); + TEST_API static PassRegistry &Instance(); bool Has(const std::string &pass_type) const { return map_.find(pass_type) != map_.end(); diff --git a/test/cpp/fluid/mkldnn/test_mkldnn_cpu_quantize_pass.cc b/test/cpp/fluid/mkldnn/test_mkldnn_cpu_quantize_pass.cc index d6ba2f7a0c232..b87f32dcb5a85 100644 --- a/test/cpp/fluid/mkldnn/test_mkldnn_cpu_quantize_pass.cc +++ b/test/cpp/fluid/mkldnn/test_mkldnn_cpu_quantize_pass.cc @@ -110,7 +110,3 @@ TEST(cpuQuantizePass, ConvReLU6) { } // namespace pass } // namespace paddle - -USE_PASS(conv_activation_mkldnn_fuse_pass); -USE_PASS(cpu_quantize_placement_pass); -USE_PASS(cpu_quantize_pass); From b5153fcc4cc9454fd45d93e01f15080666a888c6 Mon Sep 17 00:00:00 2001 From: liyulingyue <852433440@qq.com> Date: Wed, 7 Feb 2024 23:46:31 +0800 Subject: [PATCH 10/22] add test_API --- paddle/fluid/framework/dlpack_tensor.h | 3 ++- paddle/fluid/framework/tensor_util.h | 15 ++++++++------- paddle/fluid/memory/memcpy.h | 2 +- paddle/phi/kernels/isfinite_kernel.h | 2 +- paddle/phi/kernels/reduce_all_kernel.h | 10 +++++----- paddle/phi/kernels/reduce_any_kernel.h | 10 +++++----- 6 files changed, 22 insertions(+), 20 deletions(-) diff --git a/paddle/fluid/framework/dlpack_tensor.h b/paddle/fluid/framework/dlpack_tensor.h index 943ee88b67695..f39d91b84ee3d 100644 --- a/paddle/fluid/framework/dlpack_tensor.h +++ b/paddle/fluid/framework/dlpack_tensor.h @@ -28,7 +28,8 @@ class DLPackTensor { std::remove_reference::type; // int64_t // lanes is only used in CPU to enable vectorization - explicit DLPackTensor(const phi::DenseTensor& tensor, LaneType lanes = 1); + TEST_API explicit DLPackTensor(const phi::DenseTensor& tensor, + LaneType lanes = 1); inline operator const ::DLTensor&() const { return t_; } diff --git a/paddle/fluid/framework/tensor_util.h b/paddle/fluid/framework/tensor_util.h index 96f3d71c132af..927216ccd115e 100644 --- a/paddle/fluid/framework/tensor_util.h +++ b/paddle/fluid/framework/tensor_util.h @@ -53,12 +53,12 @@ class PrintOptions { PrintOptions() {} }; -void TensorToStream(std::ostream& os, - const phi::DenseTensor& tensor, - const platform::DeviceContext& dev_ctx); -void TensorFromStream(std::istream& is, - phi::DenseTensor* tensor, - const platform::DeviceContext& dev_ctx); +TEST_API void TensorToStream(std::ostream& os, + const phi::DenseTensor& tensor, + const platform::DeviceContext& dev_ctx); +TEST_API void TensorFromStream(std::istream& is, + phi::DenseTensor* tensor, + const platform::DeviceContext& dev_ctx); void TensorFromStream(std::istream& is, phi::DenseTensor* tensor, const platform::DeviceContext& dev_ctx, @@ -107,7 +107,8 @@ void TesnorToVector(const phi::DenseTensor& src, std::vector* dst); // convert dlpack's DLTensor to tensor -void TensorFromDLPack(const ::DLTensor& dl_tensor, phi::DenseTensor* dst); +TEST_API void TensorFromDLPack(const ::DLTensor& dl_tensor, + phi::DenseTensor* dst); void TensorFromDLPack(const DLManagedTensor* src, phi::DenseTensor* dst); // diff --git a/paddle/fluid/memory/memcpy.h b/paddle/fluid/memory/memcpy.h index c8d9208c48219..3897fbe10cea3 100644 --- a/paddle/fluid/memory/memcpy.h +++ b/paddle/fluid/memory/memcpy.h @@ -31,7 +31,7 @@ namespace memory { * */ template -void Copy(DstPlace, void* dst, SrcPlace, const void* src, size_t num); +TEST_API void Copy(DstPlace, void* dst, SrcPlace, const void* src, size_t num); /** * \brief Copy memory from one place to another place. diff --git a/paddle/phi/kernels/isfinite_kernel.h b/paddle/phi/kernels/isfinite_kernel.h index e695a8e074223..291bec9b78436 100644 --- a/paddle/phi/kernels/isfinite_kernel.h +++ b/paddle/phi/kernels/isfinite_kernel.h @@ -20,7 +20,7 @@ namespace phi { #define DEFINE_ISFINITE_KERNEL(isfinite_kernel) \ template \ - void isfinite_kernel( \ + TEST_API void isfinite_kernel( \ const Context& ctx, const DenseTensor& x, DenseTensor* out); DEFINE_ISFINITE_KERNEL(IsinfKernel) diff --git a/paddle/phi/kernels/reduce_all_kernel.h b/paddle/phi/kernels/reduce_all_kernel.h index af34a0a5d4c6f..3610ec245ac98 100644 --- a/paddle/phi/kernels/reduce_all_kernel.h +++ b/paddle/phi/kernels/reduce_all_kernel.h @@ -27,10 +27,10 @@ void AllRawKernel(const Context& dev_ctx, DenseTensor* out); template -void AllKernel(const Context& dev_ctx, - const DenseTensor& x, - const std::vector& dims, - bool keep_dim, - DenseTensor* out); +TEST_API void AllKernel(const Context& dev_ctx, + const DenseTensor& x, + const std::vector& dims, + bool keep_dim, + DenseTensor* out); } // namespace phi diff --git a/paddle/phi/kernels/reduce_any_kernel.h b/paddle/phi/kernels/reduce_any_kernel.h index 9514d02dbdf94..d6a9392e4996b 100644 --- a/paddle/phi/kernels/reduce_any_kernel.h +++ b/paddle/phi/kernels/reduce_any_kernel.h @@ -26,10 +26,10 @@ void AnyRawKernel(const Context& dev_ctx, DenseTensor* out); template -void AnyKernel(const Context& dev_ctx, - const DenseTensor& x, - const std::vector& dims, - bool keep_dim, - DenseTensor* out); +TEST_API void AnyKernel(const Context& dev_ctx, + const DenseTensor& x, + const std::vector& dims, + bool keep_dim, + DenseTensor* out); } // namespace phi From 63cd174e1d69e96812a09bd2e033e62ba5ee4cf6 Mon Sep 17 00:00:00 2001 From: liyulingyue <852433440@qq.com> Date: Thu, 8 Feb 2024 00:30:48 +0800 Subject: [PATCH 11/22] rollback --- paddle/fluid/framework/dlpack_tensor.h | 3 +-- paddle/fluid/framework/tensor_util.h | 15 +++++++-------- paddle/fluid/memory/memcpy.h | 2 +- paddle/phi/kernels/isfinite_kernel.h | 2 +- paddle/phi/kernels/reduce_all_kernel.h | 10 +++++----- paddle/phi/kernels/reduce_any_kernel.h | 10 +++++----- 6 files changed, 20 insertions(+), 22 deletions(-) diff --git a/paddle/fluid/framework/dlpack_tensor.h b/paddle/fluid/framework/dlpack_tensor.h index f39d91b84ee3d..943ee88b67695 100644 --- a/paddle/fluid/framework/dlpack_tensor.h +++ b/paddle/fluid/framework/dlpack_tensor.h @@ -28,8 +28,7 @@ class DLPackTensor { std::remove_reference::type; // int64_t // lanes is only used in CPU to enable vectorization - TEST_API explicit DLPackTensor(const phi::DenseTensor& tensor, - LaneType lanes = 1); + explicit DLPackTensor(const phi::DenseTensor& tensor, LaneType lanes = 1); inline operator const ::DLTensor&() const { return t_; } diff --git a/paddle/fluid/framework/tensor_util.h b/paddle/fluid/framework/tensor_util.h index 927216ccd115e..96f3d71c132af 100644 --- a/paddle/fluid/framework/tensor_util.h +++ b/paddle/fluid/framework/tensor_util.h @@ -53,12 +53,12 @@ class PrintOptions { PrintOptions() {} }; -TEST_API void TensorToStream(std::ostream& os, - const phi::DenseTensor& tensor, - const platform::DeviceContext& dev_ctx); -TEST_API void TensorFromStream(std::istream& is, - phi::DenseTensor* tensor, - const platform::DeviceContext& dev_ctx); +void TensorToStream(std::ostream& os, + const phi::DenseTensor& tensor, + const platform::DeviceContext& dev_ctx); +void TensorFromStream(std::istream& is, + phi::DenseTensor* tensor, + const platform::DeviceContext& dev_ctx); void TensorFromStream(std::istream& is, phi::DenseTensor* tensor, const platform::DeviceContext& dev_ctx, @@ -107,8 +107,7 @@ void TesnorToVector(const phi::DenseTensor& src, std::vector* dst); // convert dlpack's DLTensor to tensor -TEST_API void TensorFromDLPack(const ::DLTensor& dl_tensor, - phi::DenseTensor* dst); +void TensorFromDLPack(const ::DLTensor& dl_tensor, phi::DenseTensor* dst); void TensorFromDLPack(const DLManagedTensor* src, phi::DenseTensor* dst); // diff --git a/paddle/fluid/memory/memcpy.h b/paddle/fluid/memory/memcpy.h index 3897fbe10cea3..c8d9208c48219 100644 --- a/paddle/fluid/memory/memcpy.h +++ b/paddle/fluid/memory/memcpy.h @@ -31,7 +31,7 @@ namespace memory { * */ template -TEST_API void Copy(DstPlace, void* dst, SrcPlace, const void* src, size_t num); +void Copy(DstPlace, void* dst, SrcPlace, const void* src, size_t num); /** * \brief Copy memory from one place to another place. diff --git a/paddle/phi/kernels/isfinite_kernel.h b/paddle/phi/kernels/isfinite_kernel.h index 291bec9b78436..e695a8e074223 100644 --- a/paddle/phi/kernels/isfinite_kernel.h +++ b/paddle/phi/kernels/isfinite_kernel.h @@ -20,7 +20,7 @@ namespace phi { #define DEFINE_ISFINITE_KERNEL(isfinite_kernel) \ template \ - TEST_API void isfinite_kernel( \ + void isfinite_kernel( \ const Context& ctx, const DenseTensor& x, DenseTensor* out); DEFINE_ISFINITE_KERNEL(IsinfKernel) diff --git a/paddle/phi/kernels/reduce_all_kernel.h b/paddle/phi/kernels/reduce_all_kernel.h index 3610ec245ac98..af34a0a5d4c6f 100644 --- a/paddle/phi/kernels/reduce_all_kernel.h +++ b/paddle/phi/kernels/reduce_all_kernel.h @@ -27,10 +27,10 @@ void AllRawKernel(const Context& dev_ctx, DenseTensor* out); template -TEST_API void AllKernel(const Context& dev_ctx, - const DenseTensor& x, - const std::vector& dims, - bool keep_dim, - DenseTensor* out); +void AllKernel(const Context& dev_ctx, + const DenseTensor& x, + const std::vector& dims, + bool keep_dim, + DenseTensor* out); } // namespace phi diff --git a/paddle/phi/kernels/reduce_any_kernel.h b/paddle/phi/kernels/reduce_any_kernel.h index d6a9392e4996b..9514d02dbdf94 100644 --- a/paddle/phi/kernels/reduce_any_kernel.h +++ b/paddle/phi/kernels/reduce_any_kernel.h @@ -26,10 +26,10 @@ void AnyRawKernel(const Context& dev_ctx, DenseTensor* out); template -TEST_API void AnyKernel(const Context& dev_ctx, - const DenseTensor& x, - const std::vector& dims, - bool keep_dim, - DenseTensor* out); +void AnyKernel(const Context& dev_ctx, + const DenseTensor& x, + const std::vector& dims, + bool keep_dim, + DenseTensor* out); } // namespace phi From 270355686d9f020d8df7bdd86849a7ccdddbdf37 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, 8 Feb 2024 05:34:10 +0800 Subject: [PATCH 12/22] Update graph.h --- paddle/fluid/framework/ir/graph.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/paddle/fluid/framework/ir/graph.h b/paddle/fluid/framework/ir/graph.h index 578824fbcad7e..9856183b4e500 100644 --- a/paddle/fluid/framework/ir/graph.h +++ b/paddle/fluid/framework/ir/graph.h @@ -86,7 +86,7 @@ namespace ir { class Graph { public: // Construct a main_graph with some sub_graphs - explicit Graph(const ProgramDesc &program); + TEST_API explicit Graph(const ProgramDesc &program); // Construct a main_graph with some sub_graphs, and the 1st sub_graph is // constructed with ops[start_op_index, end_op_index) From 74c0e5a68efb528063aa3a91c0dca80388c1363f 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, 8 Feb 2024 05:34:43 +0800 Subject: [PATCH 13/22] Apply suggestions from code review --- paddle/fluid/framework/ir/pass.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/paddle/fluid/framework/ir/pass.h b/paddle/fluid/framework/ir/pass.h index 2249378bce3b5..304d12cf94ecf 100644 --- a/paddle/fluid/framework/ir/pass.h +++ b/paddle/fluid/framework/ir/pass.h @@ -37,7 +37,7 @@ constexpr char kStartupProgramDescs[] = "startup_program_descs"; } // namespace details namespace ir { -class TEST_API Graph; +class Graph; template struct PassRegistrar; From 5e82724001a43d54820c3354c5734883eeed7911 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, 8 Feb 2024 08:22:26 +0800 Subject: [PATCH 14/22] Update CMakeLists.txt --- test/cpp/fluid/mkldnn/CMakeLists.txt | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/test/cpp/fluid/mkldnn/CMakeLists.txt b/test/cpp/fluid/mkldnn/CMakeLists.txt index 350ed9008bb3f..f359eac744de8 100644 --- a/test/cpp/fluid/mkldnn/CMakeLists.txt +++ b/test/cpp/fluid/mkldnn/CMakeLists.txt @@ -2,19 +2,7 @@ get_property(paddle_lib GLOBAL PROPERTY PADDLE_LIB_NAME) paddle_test(test_mkldnn_op_inplace SRCS test_mkldnn_op_inplace.cc) paddle_test(test_mkldnn_cpu_quantize_pass SRCS test_mkldnn_cpu_quantize_pass.cc) -cc_test( - test_conv_mkldnn_nhwc - SRCS test_conv_mkldnn_nhwc.cc - DEPS executor - op_registry - depthwise_conv - tensor - phi - common - scope - device_context - enforce - generated_static_op) +paddle_test(test_conv_mkldnn_nhwc SRCS test_conv_mkldnn_nhwc.cc) set(TEST_MKLDNN_CACHING_DEPS op_registry From 0a2728eb5611411222e8df457793492550ff5c35 Mon Sep 17 00:00:00 2001 From: liyulingyue <852433440@qq.com> Date: Thu, 8 Feb 2024 11:23:51 +0800 Subject: [PATCH 15/22] delete use_it_self of conv2 in test_conv_mkldnn_nhwc.cc --- test/cpp/fluid/mkldnn/test_conv_mkldnn_nhwc.cc | 3 --- 1 file changed, 3 deletions(-) diff --git a/test/cpp/fluid/mkldnn/test_conv_mkldnn_nhwc.cc b/test/cpp/fluid/mkldnn/test_conv_mkldnn_nhwc.cc index 4dfc4a731bff2..1bc92cde48a65 100644 --- a/test/cpp/fluid/mkldnn/test_conv_mkldnn_nhwc.cc +++ b/test/cpp/fluid/mkldnn/test_conv_mkldnn_nhwc.cc @@ -26,9 +26,6 @@ #include "paddle/phi/core/enforce.h" #include "paddle/phi/core/kernel_registry.h" -USE_OP_ITSELF(conv2d); -PD_DECLARE_KERNEL(conv2d, OneDNN, ONEDNN); - template void AddVarToScope(const std::string var_name, paddle::framework::Scope* scope, From 279aedbfff3395db982ae65a7e25abb455f1cb3f 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, 8 Feb 2024 14:10:47 +0800 Subject: [PATCH 16/22] Update CMakeLists.txt --- test/cpp/fluid/mkldnn/CMakeLists.txt | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/test/cpp/fluid/mkldnn/CMakeLists.txt b/test/cpp/fluid/mkldnn/CMakeLists.txt index f359eac744de8..8788b0ae08a47 100644 --- a/test/cpp/fluid/mkldnn/CMakeLists.txt +++ b/test/cpp/fluid/mkldnn/CMakeLists.txt @@ -19,10 +19,7 @@ set(TEST_MKLDNN_CACHING_DEPS if(WITH_GPU OR WITH_ROCM) set(TEST_MKLDNN_CACHING_DEPS ${TEST_MKLDNN_CACHING_DEPS} depthwise_conv) endif() -cc_test( - test_mkldnn_caching - SRCS test_mkldnn_caching.cc - DEPS ${TEST_MKLDNN_CACHING_DEPS}) +paddle_test(test_mkldnn_caching SRCS test_mkldnn_caching.cc) if(WITH_TESTING) paddle_test(test_mkldnn_op_nhwc SRCS test_mkldnn_op_nhwc.cc) From e14292050cb70badda842ac5838b903cf1ad79f0 Mon Sep 17 00:00:00 2001 From: liyulingyue <852433440@qq.com> Date: Fri, 9 Feb 2024 06:04:44 +0800 Subject: [PATCH 17/22] add TEST_API and rm use_it_self --- paddle/phi/backends/onednn/onednn_context.h | 2 +- test/cpp/fluid/mkldnn/test_mkldnn_caching.cc | 11 ----------- 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/paddle/phi/backends/onednn/onednn_context.h b/paddle/phi/backends/onednn/onednn_context.h index aec9f7f0d5e4f..2324b5b1084f6 100644 --- a/paddle/phi/backends/onednn/onednn_context.h +++ b/paddle/phi/backends/onednn/onednn_context.h @@ -114,7 +114,7 @@ class OneDNNContext : public CPUContext { const dnnl::engine& GetEngine() const { return tls().get_engine(); } // Remove all entries from the blob map - void ResetBlobMap(void* ptr); + TEST_API void ResetBlobMap(void* ptr); // Prevent next ResetBlobMap() void BlockNextCacheClearing(); diff --git a/test/cpp/fluid/mkldnn/test_mkldnn_caching.cc b/test/cpp/fluid/mkldnn/test_mkldnn_caching.cc index 0f62301cdfe6d..efa82b26783c8 100644 --- a/test/cpp/fluid/mkldnn/test_mkldnn_caching.cc +++ b/test/cpp/fluid/mkldnn/test_mkldnn_caching.cc @@ -26,17 +26,6 @@ #include "paddle/phi/core/enforce.h" #include "paddle/phi/core/kernel_registry.h" -USE_OP_ITSELF(elementwise_add); -PD_DECLARE_KERNEL(add_raw, OneDNN, ONEDNN); -USE_OP_ITSELF(elementwise_mul); -PD_DECLARE_KERNEL(multiply_raw, OneDNN, ONEDNN); -USE_OP_ITSELF(relu); -PD_DECLARE_KERNEL(relu, OneDNN, ONEDNN); -USE_OP_ITSELF(softmax); -PD_DECLARE_KERNEL(softmax, OneDNN, ONEDNN); -USE_OP_ITSELF(conv2d); -PD_DECLARE_KERNEL(conv2d, OneDNN, ONEDNN); - namespace paddle { namespace operators { From 8ba6972d9f2fb5139d29a7d74473918bc79e3d46 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, 9 Feb 2024 13:40:13 +0800 Subject: [PATCH 18/22] Update CMakeLists.txt --- test/cpp/fluid/mkldnn/CMakeLists.txt | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/test/cpp/fluid/mkldnn/CMakeLists.txt b/test/cpp/fluid/mkldnn/CMakeLists.txt index 8788b0ae08a47..545437a9c2609 100644 --- a/test/cpp/fluid/mkldnn/CMakeLists.txt +++ b/test/cpp/fluid/mkldnn/CMakeLists.txt @@ -25,20 +25,9 @@ if(WITH_TESTING) paddle_test(test_mkldnn_op_nhwc SRCS test_mkldnn_op_nhwc.cc) endif() -cc_test( +paddle_test( test_mkldnn_pool_adaptive_op - SRCS test_mkldnn_pool_adaptive_op.cc - DEPS fleet_executor - conditional_block_op - executor - op_registry - generated_static_op - generated_op - phi - common - scope - device_context - enforce) + SRCS test_mkldnn_pool_adaptive_op.cc) cc_test( test_mkldnn_squeeze From 79806778676f50e683a34243022d0107292e51ac 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, 9 Feb 2024 14:15:58 +0800 Subject: [PATCH 19/22] Update test_mkldnn_pool_adaptive_op.cc --- test/cpp/fluid/mkldnn/test_mkldnn_pool_adaptive_op.cc | 4 ---- 1 file changed, 4 deletions(-) diff --git a/test/cpp/fluid/mkldnn/test_mkldnn_pool_adaptive_op.cc b/test/cpp/fluid/mkldnn/test_mkldnn_pool_adaptive_op.cc index 3e1a9230ec231..da378c12f89f9 100644 --- a/test/cpp/fluid/mkldnn/test_mkldnn_pool_adaptive_op.cc +++ b/test/cpp/fluid/mkldnn/test_mkldnn_pool_adaptive_op.cc @@ -85,7 +85,3 @@ TEST(Pool2dOpConverter, avg_ceil_test) { test_pool2d(true, true, "avg"); } } // namespace tensorrt } // namespace inference } // namespace paddle - -USE_OP_ITSELF(pool2d); -PD_DECLARE_KERNEL(pool2d, OneDNN, ONEDNN); -PD_DECLARE_KERNEL(pool2d, CPU, ALL_LAYOUT); From 2fa1fb5574d2e43a34db03ac7fcfd5c3fafaf6d5 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, 9 Feb 2024 14:16:56 +0800 Subject: [PATCH 20/22] Update CMakeLists.txt --- test/cpp/fluid/mkldnn/CMakeLists.txt | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/test/cpp/fluid/mkldnn/CMakeLists.txt b/test/cpp/fluid/mkldnn/CMakeLists.txt index 545437a9c2609..2b7b28172960a 100644 --- a/test/cpp/fluid/mkldnn/CMakeLists.txt +++ b/test/cpp/fluid/mkldnn/CMakeLists.txt @@ -29,19 +29,9 @@ paddle_test( test_mkldnn_pool_adaptive_op SRCS test_mkldnn_pool_adaptive_op.cc) -cc_test( +paddle_test( test_mkldnn_squeeze - SRCS test_mkldnn_squeeze.cc - DEPS fleet_executor - conditional_block_op - executor - op_registry - generated_static_op - generated_op - phi - scope - device_context - enforce) + SRCS test_mkldnn_squeeze.cc) if(WITH_ONNXRUNTIME AND WIN32) # Copy onnxruntime for some c++ test in Windows, since the test will From bf9b98d51ca9f8f39cba1d5f78ba2a69fe13374a Mon Sep 17 00:00:00 2001 From: liyulingyue <852433440@qq.com> Date: Fri, 9 Feb 2024 15:29:13 +0800 Subject: [PATCH 21/22] add TEST_API and rm use-op-self --- paddle/phi/backends/onednn/onednn_context.h | 4 ++-- test/cpp/fluid/mkldnn/test_mkldnn_squeeze.cc | 3 --- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/paddle/phi/backends/onednn/onednn_context.h b/paddle/phi/backends/onednn/onednn_context.h index 2324b5b1084f6..499be34650098 100644 --- a/paddle/phi/backends/onednn/onednn_context.h +++ b/paddle/phi/backends/onednn/onednn_context.h @@ -57,7 +57,7 @@ class OneDNNContextThreadLocals { size_t get_cur_mkldnn_session_id(void); void set_cur_input_shape_str(std::string input_shape_str); void set_cur_input_shape_cache_capacity(int input_shape_cache_capacity); - void set_cur_paddle_data_layout(DataLayout dl); + TEST_API void set_cur_paddle_data_layout(DataLayout dl); DataLayout get_cur_paddle_data_layout(void); void log_lib_version(void); const dnnl::engine& get_engine(void) { return cur_engine; } @@ -77,7 +77,7 @@ class OneDNNContextThreadLocals { static constexpr size_t kMKLDNNSessionID_Default = 0; // mkldnn session id for cache clearing mode static constexpr size_t kMKLDNNSessionID_CacheClearing = -1; - static Body& fetch(); + TEST_API static Body& fetch(); }; class OneDNNContext : public CPUContext { diff --git a/test/cpp/fluid/mkldnn/test_mkldnn_squeeze.cc b/test/cpp/fluid/mkldnn/test_mkldnn_squeeze.cc index a08ca3075ca00..343c043cb9860 100644 --- a/test/cpp/fluid/mkldnn/test_mkldnn_squeeze.cc +++ b/test/cpp/fluid/mkldnn/test_mkldnn_squeeze.cc @@ -101,6 +101,3 @@ TEST(SqueezeOpConverter_2, normal) { test_squeeze2(); } } // namespace tensorrt } // namespace inference } // namespace paddle - -USE_OP_ITSELF(squeeze2); -PD_DECLARE_KERNEL(squeeze_infer, OneDNN, ONEDNN); From 78fae41dd1a87e3a5408cc767283a75863225410 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, 9 Feb 2024 18:39:50 +0800 Subject: [PATCH 22/22] Update CMakeLists.txt --- test/cpp/fluid/mkldnn/CMakeLists.txt | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/test/cpp/fluid/mkldnn/CMakeLists.txt b/test/cpp/fluid/mkldnn/CMakeLists.txt index 2b7b28172960a..2e6772a5d2eed 100644 --- a/test/cpp/fluid/mkldnn/CMakeLists.txt +++ b/test/cpp/fluid/mkldnn/CMakeLists.txt @@ -25,13 +25,9 @@ if(WITH_TESTING) paddle_test(test_mkldnn_op_nhwc SRCS test_mkldnn_op_nhwc.cc) endif() -paddle_test( - test_mkldnn_pool_adaptive_op - SRCS test_mkldnn_pool_adaptive_op.cc) +paddle_test(test_mkldnn_pool_adaptive_op SRCS test_mkldnn_pool_adaptive_op.cc) -paddle_test( - test_mkldnn_squeeze - SRCS test_mkldnn_squeeze.cc) +paddle_test(test_mkldnn_squeeze SRCS test_mkldnn_squeeze.cc) if(WITH_ONNXRUNTIME AND WIN32) # Copy onnxruntime for some c++ test in Windows, since the test will