2121from nsight import exceptions , extraction , utils
2222from nsight .collection import core
2323from nsight .exceptions import NCUErrorContext
24+ from nsight .utils import VerbosityLevel
2425
2526
2627def get_signature (
@@ -40,7 +41,7 @@ def launch_ncu(
4041 cache_control : Literal ["none" , "all" ],
4142 clock_control : Literal ["none" , "base" ],
4243 replay_mode : Literal ["kernel" , "range" ],
43- verbose : bool ,
44+ verbosity : VerbosityLevel ,
4445) -> str | None :
4546 """
4647 Launch NVIDIA Nsight Compute to profile the current script with specified options.
@@ -51,7 +52,7 @@ def launch_ncu(
5152 cache_control: Select cache control option
5253 clock_control: Select clock control option
5354 replay_mode: Select replay mode option
54- verbose: If False, log is written to a file (ncu_log.txt)
55+ verbosity: Controls output verbosity level.
5556
5657 Raises:
5758 NCUNotAvailableError: If NCU is not available on the system.
@@ -84,11 +85,16 @@ def launch_ncu(
8485 replay = f"--replay-mode { replay_mode } "
8586 log_path = os .path .splitext (report_path )[0 ] + ".log"
8687 log = f"--log-file { log_path } "
88+
8789 nvtx = f'--nvtx --nvtx-include "regex:{ utils .NVTX_DOMAIN } @.+/"'
8890 metrics_str = "," .join (metrics )
91+ verbose_flag = "--verbose" if verbosity >= VerbosityLevel .DEBUG else ""
8992
9093 # Construct the ncu command
91- ncu_command = f"""ncu { log } { cache } { clocks } { replay } { nvtx } --metrics { metrics_str } -f -o { report_path } { sys .executable } { script_path } { script_args } """
94+ ncu_command = f"""ncu { log } { cache } { clocks } { replay } { nvtx } { verbose_flag } --metrics { metrics_str } -f -o { report_path } { sys .executable } { script_path } { script_args } """
95+
96+ if verbosity >= VerbosityLevel .DEBUG :
97+ print (f"[NSIGHT-PYTHON] NCU command: { ncu_command } " )
9298
9399 # Check if ncu is available on the system
94100 ncu_available = False
@@ -113,19 +119,16 @@ def launch_ncu(
113119 )
114120
115121 return log_path
116- except subprocess .CalledProcessError as e :
122+ except subprocess .CalledProcessError :
117123 log_parser = utils .NCULogParser ()
118124 error_logs = log_parser .get_logs (log_path , "ERROR" )
119-
120- # Create error context
121- error_context = NCUErrorContext (
122- errors = error_logs ,
123- log_file_path = log_path ,
124- metrics = metrics ,
125- )
126-
127- error_message = utils .format_ncu_error_message (error_context )
128- raise exceptions .ProfilerException (error_message ) from None
125+ raise exceptions .ProfilerException (
126+ utils .format_ncu_error_message (
127+ NCUErrorContext (
128+ errors = error_logs , log_file_path = log_path , metrics = metrics
129+ )
130+ )
131+ ) from None
129132 else :
130133 subprocess .run ([sys .executable , script_path ], env = env )
131134 raise exceptions .NCUNotAvailableError (
@@ -230,10 +233,10 @@ def collect(
230233 self .cache_control ,
231234 self .clock_control ,
232235 self .replay_mode ,
233- settings .output_detailed ,
236+ settings .verbosity ,
234237 )
235238
236- if settings .output_progress :
239+ if settings .verbosity >= VerbosityLevel . INFO :
237240 print ("[NSIGHT-PYTHON] Profiling completed successfully !" )
238241 print (
239242 f"[NSIGHT-PYTHON] Refer to { report_path } for the NVIDIA Nsight Compute CLI report"
@@ -250,7 +253,7 @@ def collect(
250253 func ,
251254 settings .derive_metric ,
252255 self .ignore_kernel_list , # type: ignore[arg-type]
253- settings .output_progress ,
256+ settings .verbosity ,
254257 self .combine_kernel_metrics ,
255258 )
256259
@@ -264,7 +267,7 @@ def collect(
264267 if get_signature (func , configs_list ) != sig :
265268 return None
266269
267- if settings .output_progress :
270+ if settings .verbosity >= VerbosityLevel . INFO :
268271 utils .print_header (
269272 f"Profiling { func .__name__ } " ,
270273 f"{ len (configs_list )} configurations, { settings .runs } runs each" ,
@@ -274,8 +277,7 @@ def collect(
274277 func ,
275278 configs_list ,
276279 settings .runs ,
277- settings .output_progress ,
278- settings .output_detailed ,
280+ settings .verbosity ,
279281 settings .thermal_mode ,
280282 settings .thermal_wait ,
281283 settings .thermal_cont ,
0 commit comments