From b9136e43f1473a56e0b85f8745023e9f5bc8a025 Mon Sep 17 00:00:00 2001 From: xiaoyewww <641311428@qq.com> Date: Sun, 17 Mar 2024 15:15:01 +0000 Subject: [PATCH 1/2] feat(pir): reg barrier --- .../pir/dialect/op_generator/ops_api_gen.py | 2 + paddle/fluid/pir/dialect/operator/ir/ops.yaml | 8 ++++ paddle/phi/api/yaml/op_compat.yaml | 6 +++ test/ir/pir/translator/CMakeLists.txt | 1 + .../pir/translator/test_barrier_translator.py | 44 +++++++++++++++++++ 5 files changed, 61 insertions(+) create mode 100644 test/ir/pir/translator/test_barrier_translator.py diff --git a/paddle/fluid/pir/dialect/op_generator/ops_api_gen.py b/paddle/fluid/pir/dialect/op_generator/ops_api_gen.py index 6a86600c1f5f2..8bbb8018e9b9b 100644 --- a/paddle/fluid/pir/dialect/op_generator/ops_api_gen.py +++ b/paddle/fluid/pir/dialect/op_generator/ops_api_gen.py @@ -122,6 +122,8 @@ 'add_n_', 'all_reduce', 'all_reduce_', + 'barrier', + 'barrier_', 'c_allgather', 'c_allreduce_avg', 'c_allreduce_avg_', diff --git a/paddle/fluid/pir/dialect/operator/ir/ops.yaml b/paddle/fluid/pir/dialect/operator/ir/ops.yaml index 60f1bf2f03941..659a943840f80 100644 --- a/paddle/fluid/pir/dialect/operator/ir/ops.yaml +++ b/paddle/fluid/pir/dialect/operator/ir/ops.yaml @@ -133,6 +133,14 @@ data_type : dtype backend : place > output +- op : barrier + args : (Tensor x, int ring_id=0) + output : Tensor(out) + kernel : + func : barrier + data_type : x + inplace : (x -> out) + - op : batch_norm args : (Tensor x, Tensor mean, Tensor variance, Tensor scale, Tensor bias, bool is_test, float momentum, float epsilon, str data_format, bool use_global_stats, bool trainable_statistics) output : Tensor(out), Tensor(mean_out), Tensor(variance_out), Tensor(saved_mean), Tensor(saved_variance), Tensor(reserve_space) diff --git a/paddle/phi/api/yaml/op_compat.yaml b/paddle/phi/api/yaml/op_compat.yaml index 2fbd73623f0a0..6d84c153ab06d 100755 --- a/paddle/phi/api/yaml/op_compat.yaml +++ b/paddle/phi/api/yaml/op_compat.yaml @@ -329,6 +329,12 @@ outputs : {auc : AUC, stat_pos_out : StatPosOut, stat_neg_out : StatNegOut} +- op : barrier + inputs : + {x : X} + outputs : + out : Out + - op : batch_norm backward : batch_norm_grad, batch_norm_double_grad(batch_norm_grad_grad) inputs: diff --git a/test/ir/pir/translator/CMakeLists.txt b/test/ir/pir/translator/CMakeLists.txt index bdc08cd8f9bc1..ac55db0d34d5b 100644 --- a/test/ir/pir/translator/CMakeLists.txt +++ b/test/ir/pir/translator/CMakeLists.txt @@ -5,6 +5,7 @@ file( string(REPLACE ".py" "" TEST_INTERP_CASES "${TEST_INTERP_CASES}") set(DISTRIBUTED_OP_TRANSLATOR_TEST test_all_reduce_translator) +list(APPEND DISTRIBUTED_OP_TRANSLATOR_TEST test_barrier_translator) list(APPEND DISTRIBUTED_OP_TRANSLATOR_TEST test_c_reduce_min_translator) list(APPEND DISTRIBUTED_OP_TRANSLATOR_TEST test_c_allreduce_min_translator) list(APPEND DISTRIBUTED_OP_TRANSLATOR_TEST test_c_allreduce_prod_translator) diff --git a/test/ir/pir/translator/test_barrier_translator.py b/test/ir/pir/translator/test_barrier_translator.py new file mode 100644 index 0000000000000..7d570df843081 --- /dev/null +++ b/test/ir/pir/translator/test_barrier_translator.py @@ -0,0 +1,44 @@ +# Copyright (c) 2024 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. + +import unittest + +import test_op_translator + +import paddle +from paddle.base.layer_helper import LayerHelper + + +class TestBarrierOpTranslator(test_op_translator.TestOpTranslator): + def append_op(self): + self.op_type = "barrier" + x = paddle.ones(shape=(100, 2, 3), dtype='float32') + y = paddle.ones(shape=(100, 2, 3), dtype='float32') + attrs = { + 'ring_id': 0, + } + helper = LayerHelper(self.op_type) + helper.append_op( + type=self.op_type, + inputs={"X": x}, + outputs={"Out": y}, + attrs=attrs, + ) + + def test_translator(self): + self.check() + + +if __name__ == "__main__": + unittest.main() From 590343be070eeae3e461eb625788acde573695c5 Mon Sep 17 00:00:00 2001 From: xiaoyewww <641311428@qq.com> Date: Mon, 18 Mar 2024 14:57:45 +0000 Subject: [PATCH 2/2] feat(pir): reg barrier --- paddle/fluid/pir/dialect/op_generator/ops_api_gen.py | 1 - paddle/fluid/pir/dialect/operator/ir/ops.yaml | 2 -- 2 files changed, 3 deletions(-) diff --git a/paddle/fluid/pir/dialect/op_generator/ops_api_gen.py b/paddle/fluid/pir/dialect/op_generator/ops_api_gen.py index 8bbb8018e9b9b..c473bbdd1bfb6 100644 --- a/paddle/fluid/pir/dialect/op_generator/ops_api_gen.py +++ b/paddle/fluid/pir/dialect/op_generator/ops_api_gen.py @@ -123,7 +123,6 @@ 'all_reduce', 'all_reduce_', 'barrier', - 'barrier_', 'c_allgather', 'c_allreduce_avg', 'c_allreduce_avg_', diff --git a/paddle/fluid/pir/dialect/operator/ir/ops.yaml b/paddle/fluid/pir/dialect/operator/ir/ops.yaml index 659a943840f80..0245192a321ab 100644 --- a/paddle/fluid/pir/dialect/operator/ir/ops.yaml +++ b/paddle/fluid/pir/dialect/operator/ir/ops.yaml @@ -138,8 +138,6 @@ output : Tensor(out) kernel : func : barrier - data_type : x - inplace : (x -> out) - op : batch_norm args : (Tensor x, Tensor mean, Tensor variance, Tensor scale, Tensor bias, bool is_test, float momentum, float epsilon, str data_format, bool use_global_stats, bool trainable_statistics)