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

转换规则 No. 141/142 #180

Merged
merged 2 commits into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 11 additions & 0 deletions paconvert/api_mapping.json
Original file line number Diff line number Diff line change
Expand Up @@ -3619,6 +3619,17 @@
"device": "device"
}
},
"torch.cuda.nvtx.range_pop": {
"Matcher": "GenericMatcher",
"paddle_api": "paddle.fluid.core.nvprof_nvtx_pop"
},
"torch.cuda.nvtx.range_push": {
"Matcher": "CudaNvtxRangePushMatcher",
"paddle_api": "paddle.fluid.core.nvprof_nvtx_push",
"args_list": [
"msg"
]
},
"torch.cuda.set_device": {
"Matcher": "GenericMatcher",
"paddle_api": "paddle.device.set_device",
Expand Down
6 changes: 6 additions & 0 deletions paconvert/api_matcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -3659,6 +3659,12 @@ def generate_code(self, kwargs):
return GenericMatcher.generate_code(self, kwargs)


class CudaNvtxRangePushMatcher(BaseMatcher):
def generate_code(self, kwargs):
code = "{}({})".format(self.get_paddle_api(), kwargs["msg"])
return code


class Attribute2Func(BaseMatcher):
def get_paddle_class_attribute_nodes(self, node):
self.parse_func(node)
Expand Down
31 changes: 31 additions & 0 deletions tests/test_cuda_nvtx_range_pop.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# 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 textwrap

from apibase import APIBase

obj = APIBase("torch.cuda.nvtx.range_pop")


def test_case_1():
pytorch_code = textwrap.dedent(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这种cuda类型的api先在本地跑看是否单测能够通过,截图可以贴到下面。CI没有GPU,无法跑这个单测,可以用torch.cuda is_available()来绕过。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已修改

"""
import torch
if torch.cuda.is_available():
torch.cuda.nvtx.range_pop()
result = None
"""
)
obj.run(pytorch_code, ["result"])
43 changes: 43 additions & 0 deletions tests/test_cuda_nvtx_range_push.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# 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 textwrap

from apibase import APIBase

obj = APIBase("torch.cuda.nvtx.range_push")


def test_case_1():
pytorch_code = textwrap.dedent(
"""
import torch
if torch.cuda.is_available():
torch.cuda.nvtx.range_push("msg")
result = None
"""
)
obj.run(pytorch_code, ["result"])


def test_case_2():
pytorch_code = textwrap.dedent(
"""
import torch
if torch.cuda.is_available():
torch.cuda.nvtx.range_push(msg="msg")
result = None
"""
)
obj.run(pytorch_code, ["result"])