Skip to content

Commit 43dbdd1

Browse files
authored
[PROTON] Add a flag to disable proton in order to use other profilers without commenting out code (#8293)
1 parent 1d74879 commit 43dbdd1

File tree

5 files changed

+20
-4
lines changed

5 files changed

+20
-4
lines changed

python/triton/knobs.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,7 @@ class amd_knobs(base_knobs):
515515

516516

517517
class proton_knobs(base_knobs):
518+
disable: env_bool = env_bool("TRITON_PROTON_DISABLE", False)
518519
cupti_lib_dir: env_str = env_str(
519520
"TRITON_CUPTI_LIB_PATH",
520521
str(pathlib.Path(__file__).parent.absolute() / "backends" / "nvidia" / "lib" / "cupti"))

third_party/proton/proton/flags.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
@dataclass
1919
class ProfilerFlags:
20-
# Whether to enable profiling. Default is False.
20+
# Whether profiling is enabled. Default is False.
2121
profiling_on: bool = False
2222
# Whether instrumentation is enabled. Default is False.
2323
instrumentation_on: bool = False

third_party/proton/proton/profile.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ def start(
9494
Returns:
9595
session (int): The session ID of the profiling session.
9696
"""
97-
if flags.command_line:
98-
# Ignore the start() call if the script is run from the command line.
97+
if flags.command_line or triton.knobs.proton.disable:
98+
# Ignore the start() call if the script is run from the command line or profiling is disabled.
9999
return
100100

101101
flags.profiling_on = True

third_party/proton/proton/proton.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def parse_arguments():
1919
choices=["shadow", "python"])
2020
parser.add_argument("-m", "--mode", type=str, help="Profiling mode", default=None)
2121
parser.add_argument("-d", "--data", type=str, help="Profiling data", default="tree", choices=["tree", "trace"])
22-
parser.add_argument("-k", "--hook", type=str, help="Profiling hook", default=None, choices=[None, "launch"])
22+
parser.add_argument("-k", "--hook", type=str, help="Profiling hook", default=None, choices=[None, "triton"])
2323
parser.add_argument('target_args', nargs=argparse.REMAINDER, help='Subcommand and its arguments')
2424
args = parser.parse_args()
2525
return args, args.target_args

third_party/proton/test/test_api.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
Profile correctness tests involving GPU kernels should be placed in `test_profile.py`.
55
"""
66

7+
import pytest
78
import json
89
import triton.profiler as proton
910
import pathlib
@@ -385,3 +386,17 @@ def test_throw(tmp_path: pathlib.Path):
385386
finally:
386387
proton.finalize()
387388
assert "Session has not been initialized: " + str(session_id + 1) in deactivate_error
389+
390+
391+
@pytest.mark.parametrize("disable", [True, False])
392+
def test_profile_disable(disable, fresh_knobs, tmp_path: pathlib.Path):
393+
fresh_knobs.proton.disable = disable
394+
temp_file = tmp_path / "test_profile_disable.hatchet"
395+
proton.start(str(temp_file.with_suffix("")))
396+
proton.enter_scope("test0")
397+
proton.exit_scope()
398+
proton.finalize()
399+
if disable:
400+
assert not temp_file.exists()
401+
else:
402+
assert temp_file.exists()

0 commit comments

Comments
 (0)