Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【PIR OpTest Fix No.39】 fix test_c_reduce_min_translate #60236

Merged
merged 9 commits into from
Dec 28, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions paddle/fluid/pir/dialect/op_generator/ops_api_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@
'sparse_momentum',
'soft_relu',
'uniform_random_batch_size_like',
'c_reduce_min',
'c_reduce_min_',
]


Expand Down
10 changes: 10 additions & 0 deletions paddle/fluid/pir/dialect/operator/ir/ops.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,16 @@
func : c_identity
inplace : (x -> out)

- op : c_reduce_min
args : (Tensor x, int ring_id, int root_id, bool use_calc_stream)
output : Tensor(out)
infer_meta :
func : DistReduceInferMeta
param : [x]
kernel :
func : c_reduce_min
inplace : (x -> out)

- op : c_reduce_sum
args : (Tensor x, int ring_id, int root_id, bool use_calc_stream)
output : Tensor(out)
Expand Down
3 changes: 2 additions & 1 deletion paddle/fluid/pir/dialect/operator/utils/utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ const std::unordered_set<std::string> LegacyOpList = {
RowConvOp::name(),
RowConvGradOp::name(),
SoftReluOp::name(),
SoftReluGradOp::name()};
SoftReluGradOp::name(),
CReduceMinOp::name()};

enum class AttrType {
UNDEFINED = 0,
Expand Down
6 changes: 6 additions & 0 deletions paddle/phi/api/yaml/op_compat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3364,6 +3364,12 @@
outputs :
out: Out

- op: c_reduce_min
inputs :
x : X
outputs :
out: Out

- op: c_reduce_sum
inputs :
x : X
Expand Down
4 changes: 4 additions & 0 deletions test/ir/pir/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,7 @@ py_test_modules(
FLAGS_pir_subgraph_saving_dir=${CMAKE_CURRENT_SOURCE_DIR})

add_subdirectory(fused_pass)

if(WITH_DISTRIBUTE)
add_subdirectory(translator)
endif()
9 changes: 9 additions & 0 deletions test/ir/pir/translator/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
file(
GLOB TEST_INTERP_CASES
RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
"test_*.py")
string(REPLACE ".py" "" TEST_INTERP_CASES "${TEST_INTERP_CASES}")

foreach(target ${TEST_INTERP_CASES})
py_test_modules(${target} MODULES ${target})
endforeach()
51 changes: 51 additions & 0 deletions test/ir/pir/translator/test_c_reduce_min_translate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# 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.

import unittest

import paddle
from paddle import pir
from paddle.base import core
from paddle.base.layer_helper import LayerHelper

paddle.enable_static()


class TestCReduceMinOpTranscriber(unittest.TestCase):
def test_program(self):
place = core.Place()
place.set_place(paddle.CPUPlace())

new_scope = paddle.static.Scope()
main_program = paddle.static.Program()
with paddle.static.scope_guard(new_scope):
with paddle.static.program_guard(main_program):
x = paddle.ones(shape=(100, 2, 3), dtype='float32')
y = paddle.ones(shape=(100, 2, 3), dtype='float32')
attrs = {'ring_id': 0, 'root_id': 0, 'use_calc_stream': False}
helper = LayerHelper('c_reduce_min')
helper.append_op(
type="c_reduce_min",
inputs={"X": x},
outputs={"Out": y},
attrs=attrs,
)
l = pir.translate_to_pir(main_program.desc)
assert (
l.global_block().ops[2].name() == "pd_op.c_reduce_min"
), "c_reduce_min should be translated to c_reduce_min"


if __name__ == "__main__":
unittest.main()