From 3d8591672f34beba4773d64720062cd3881afc63 Mon Sep 17 00:00:00 2001 From: yangkaixin Date: Wed, 2 Sep 2026 09:49:35 +0800 Subject: [PATCH] [API](feat) Deprecate legacy sync block APIs --- .../ascend/language/cann/extension/aux_ops.py | 35 ++++------- .../pytest_ut/test_aux_ops_deprecation.py | 59 +++++++++++++++++++ 2 files changed, 72 insertions(+), 22 deletions(-) create mode 100644 third_party/ascend/unittest/pytest_ut/test_aux_ops_deprecation.py diff --git a/third_party/ascend/language/cann/extension/aux_ops.py b/third_party/ascend/language/cann/extension/aux_ops.py index 6cdc9fdbf2..17bb7d5cf8 100644 --- a/third_party/ascend/language/cann/extension/aux_ops.py +++ b/third_party/ascend/language/cann/extension/aux_ops.py @@ -5,19 +5,16 @@ from typing import Optional, Tuple, List, overload, Union from triton._C.libtriton import ir -from ._utils import custom_op +from ._utils import _deprecated, custom_op +@_deprecated( + fn_name="triton.language.sync_block_all", + replacement="triton.language.extra.cann.extension.sync_block_all", +) @_tensor_member_fn @builtin def sync_block_all(mode, event_id, _semantic=None): - import warnings - - warnings.warn( - ("This method would be deprecated. Use al.sync_block_all instead."), - DeprecationWarning, - stacklevel=1, - ) mode = _unwrap_if_constexpr(mode) event_id = _unwrap_if_constexpr(event_id) assert isinstance(mode, str), f"mode: {mode} is not string" @@ -26,16 +23,13 @@ def sync_block_all(mode, event_id, _semantic=None): custom_op(_semantic.builder, "sync_block_all", mode=mode, event_id=event_id) +@_deprecated( + fn_name="triton.language.sync_block_set", + replacement="triton.language.extra.cann.extension.sync_block_set", +) @_tensor_member_fn @builtin def sync_block_set(sender, receiver, event_id, _semantic=None): - import warnings - - warnings.warn( - ("This method would be deprecated. Use al.sync_block_set instead."), - DeprecationWarning, - stacklevel=1, - ) sender = _unwrap_if_constexpr(sender) receiver = _unwrap_if_constexpr(receiver) event_id = _unwrap_if_constexpr(event_id) @@ -49,16 +43,13 @@ def sync_block_set(sender, receiver, event_id, _semantic=None): custom_op(_semantic.builder, "sync_block_set", sender=sender, event_id=event_id) +@_deprecated( + fn_name="triton.language.sync_block_wait", + replacement="triton.language.extra.cann.extension.sync_block_wait", +) @_tensor_member_fn @builtin def sync_block_wait(sender, receiver, event_id, _semantic=None): - import warnings - - warnings.warn( - ("This method would be deprecated. Use al.sync_block_wait instead."), - DeprecationWarning, - stacklevel=1, - ) sender = _unwrap_if_constexpr(sender) receiver = _unwrap_if_constexpr(receiver) event_id = _unwrap_if_constexpr(event_id) diff --git a/third_party/ascend/unittest/pytest_ut/test_aux_ops_deprecation.py b/third_party/ascend/unittest/pytest_ut/test_aux_ops_deprecation.py new file mode 100644 index 0000000000..d339b2326c --- /dev/null +++ b/third_party/ascend/unittest/pytest_ut/test_aux_ops_deprecation.py @@ -0,0 +1,59 @@ +# Copyright (c) Huawei Technologies Co., Ltd. 2026. All rights reserved. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. + +from types import SimpleNamespace +from unittest.mock import Mock + +import pytest +from triton.language import core as tl_core +from triton.language.extra.cann.extension import aux_ops + +pytestmark = pytest.mark.backend("none") + + +@pytest.mark.parametrize( + ("fn_name", "args", "expected_builder_args"), + [ + pytest.param( + "sync_block_all", + ("all", 0), + ("sync_block_all", "all", 0), + id="all", + ), + pytest.param( + "sync_block_set", + ("cube", "vector", 1), + ("sync_block_set", "cube", 1), + id="set", + ), + pytest.param( + "sync_block_wait", + ("cube", "vector", 1), + ("sync_block_wait", "cube", 1), + id="wait", + ), + ], +) +def test_legacy_sync_block_deprecation(fn_name, args, expected_builder_args): + emit_sync_op = Mock() + semantic = SimpleNamespace(builder=SimpleNamespace(create_custom_op_for_inter_core_sync=emit_sync_op, ), ) + fn = getattr(aux_ops, fn_name) + expected_message = (f"triton.language.{fn_name} is deprecated and will be removed in the next release; " + f"use triton.language.extra.cann.extension.{fn_name} instead.") + + assert tl_core.is_builtin(fn) + with pytest.warns(FutureWarning, match=fn_name) as caught: + fn(*args, _semantic=semantic) + + assert len(caught) == 1 + assert str(caught[0].message) == expected_message + emit_sync_op.assert_called_once_with(*expected_builder_args)