@@ -43,12 +43,25 @@ def _check_env(backend: str) -> None:
4343 )
4444
4545
46+ def _check_mode (backend : str , mode : Optional [str ]) -> None :
47+ # TODO(Keren): Need a better mode registration mechanism
48+ backend_modes = {
49+ "cupti" : [None , "pcsampling" ],
50+ "roctracer" : [None ],
51+ "instrumentation" : [None ],
52+ }
53+
54+ if mode not in backend_modes [backend ]:
55+ raise ValueError (f"Invalid mode { mode } for backend { backend } " )
56+
57+
4658def start (
4759 name : Optional [str ] = None ,
4860 * ,
4961 context : Optional [str ] = "shadow" ,
5062 data : Optional [str ] = "tree" ,
5163 backend : Optional [str ] = None ,
64+ mode : Optional [str ] = None ,
5265 hook : Optional [str ] = None ,
5366):
5467 """
@@ -65,15 +78,20 @@ def start(
6578 Args:
6679 name (str, optional): The name (with path) of the profiling session.
6780 If not provided, the default name is "~/proton.hatchet".
68- backend (str, optional): The backend to use for profiling.
69- Available options are [None, "cupti", "cupti_pcsampling", "roctracer"].
70- Defaults to None, which automatically selects the backend matching the current active runtime.
7181 context (str, optional): The context to use for profiling.
7282 Available options are ["shadow", "python"].
7383 Defaults to "shadow".
7484 data (str, optional): The data structure to use for profiling.
7585 Available options are ["tree"].
7686 Defaults to "tree".
87+ backend (str, optional): The backend to use for profiling.
88+ Available options are [None, "cupti", "roctracer", "instrumentation"].
89+ Defaults to None, which automatically selects the backend matching the current active runtime.
90+ mode (str, optional): The "mode" to use for profiling, which is specific to the backend.
91+ Defaults to None.
92+ For "cupti", available options are [None, "pcsampling"].
93+ For "roctracer", available options are [None].
94+ For "instrumentation", available options are [None].
7795 hook (str, optional): The hook to use for profiling.
7896 Available options are [None, "triton"].
7997 Defaults to None.
@@ -91,6 +109,7 @@ def start(
91109 backend = _select_backend ()
92110
93111 _check_env (backend )
112+ _check_mode (backend , mode )
94113
95114 backend_path = _get_backend_default_path (backend )
96115
@@ -167,6 +186,7 @@ def _profiling(
167186 context : Optional [str ] = "shadow" ,
168187 data : Optional [str ] = "tree" ,
169188 backend : Optional [str ] = None ,
189+ mode : Optional [str ] = None ,
170190 hook : Optional [str ] = None ,
171191):
172192 """
@@ -181,7 +201,7 @@ def _profiling(
181201
182202 @functools .wraps (func )
183203 def wrapper (* args , ** kwargs ):
184- session = start (name , context = context , data = data , backend = backend , hook = hook )
204+ session = start (name , context = context , data = data , backend = backend , mode = mode , hook = hook )
185205 ret = func (* args , ** kwargs )
186206 deactivate (session )
187207 return ret
@@ -196,6 +216,7 @@ def profile(
196216 context : Optional [str ] = "shadow" ,
197217 data : Optional [str ] = "tree" ,
198218 backend : Optional [str ] = None ,
219+ mode : Optional [str ] = None ,
199220 hook : Optional [str ] = None ,
200221):
201222 """
@@ -218,9 +239,9 @@ def foo():
218239 if func is None :
219240 # It's being used with parentheses, so return a decorator
220241 def decorator (f ):
221- return _profiling (f , name = name , context = context , data = data , backend = backend , hook = hook )
242+ return _profiling (f , name = name , context = context , data = data , backend = backend , mode = mode , hook = hook )
222243
223244 return decorator
224245 else :
225246 # It's being used without parentheses, so apply the decorator directly
226- return _profiling (func , name = name , context = context , data = data , backend = backend , hook = hook )
247+ return _profiling (func , name = name , context = context , data = data , backend = backend , mode = mode , hook = hook )
0 commit comments