Skip to content

Commit 20aadb4

Browse files
committed
Add SPM support to rocprofv3 tool and CLI
1 parent 7648b15 commit 20aadb4

File tree

7 files changed

+500
-29
lines changed

7 files changed

+500
-29
lines changed

projects/rocprofiler-sdk/source/bin/rocprofv3-avail.py

Lines changed: 118 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ def add_list_options(subparsers):
8282
"list", help="List options for hw counters, agents and pc-sampling support"
8383
)
8484
add_parser_bool_argument(list_command, "--pmc", help="List counters")
85+
add_parser_bool_argument(
86+
list_command, "--spm", help="List counters supporting SPM"
87+
)
8588
add_parser_bool_argument(
8689
list_command, "--agent", help="List basic info of agents"
8790
)
@@ -97,6 +100,7 @@ def add_info_options(subparsers):
97100
)
98101

99102
info_command.add_argument("--pmc", nargs="*", help="PMC info")
103+
info_command.add_argument("--spm", nargs="*", help="SPM info")
100104
info_command.add_argument(
101105
"--pc-sampling", nargs="*", help="Detailed PC Sampling info"
102106
)
@@ -198,6 +202,10 @@ def list_basic_agent(args, list_counters):
198202
from rocprofv3 import avail
199203

200204
def print_agent_counter(counters):
205+
if len(counters) == 0:
206+
msg = "No PMC counters supported"
207+
print("{:30}\n".format(msg))
208+
return
201209
names_len = [len(counter.name) for counter in counters]
202210
names = [
203211
"{name:{width}}".format(name=counter.name, width=max(names_len))
@@ -271,10 +279,57 @@ def info_pc_sampling(args):
271279
print("\n")
272280

273281

274-
def listing(args):
282+
def listing_spm(args):
283+
from rocprofv3 import avail
284+
285+
def print_agent_counter(counters):
286+
if len(counters) == 0:
287+
print("{:30}\n".format("No SPM counters supported"))
288+
return
289+
names_len = [len(counter.name) for counter in counters]
290+
names = [
291+
"{name:{width}}".format(name=counter.name, width=max(names_len))
292+
for counter in counters
293+
]
294+
columns = get_number_columns(max(names_len))
295+
print("{:30}:\n".format("SPM"))
296+
for idx in range(0, len(names), columns):
297+
print("{:30}".format(" ".join(names[idx : (idx + columns)])))
298+
299+
agent_spm_counters = avail.get_spm_counters()
300+
agent_info_map = avail.get_agent_info_map()
301+
302+
for agent, info in dict(sorted(agent_info_map.items())).items():
303+
if (
304+
info["type"] == 2
305+
and args.device is not None
306+
and info["logical_node_type_id"] == args.device
307+
):
308+
print(
309+
"{:30}:\t{}\n{:30}:\t{}".format(
310+
"GPU", info["logical_node_type_id"], "Name", info["name"]
311+
)
312+
)
313+
print_agent_counter(agent_spm_counters[agent])
314+
print("\n")
315+
break
316+
elif info["type"] == 2 and args.device is None:
317+
print(
318+
"{:30}:\t{}\n{:30}:\t{}".format(
319+
"GPU", info["logical_node_type_id"], "Name", info["name"]
320+
)
321+
)
322+
print_agent_counter(agent_spm_counters[agent])
323+
print("\n")
324+
325+
326+
def listing_pmc(args):
275327
from rocprofv3 import avail
276328

277329
def print_agent_counter(counters):
330+
if len(counters) == 0:
331+
print("{:30}\n".format("No PMC counters supported"))
332+
return
278333
names_len = [len(counter.name) for counter in counters]
279334
names = [
280335
"{name:{width}}".format(name=counter.name, width=max(names_len))
@@ -312,24 +367,65 @@ def print_agent_counter(counters):
312367
print("\n")
313368

314369

370+
def info_spm(args):
371+
from rocprofv3 import avail
372+
373+
agent_info_map = avail.get_agent_info_map()
374+
375+
def print_spm_info(_args, agent):
376+
377+
if not _args.spm:
378+
spm_counters = avail.get_spm_counters()[agent]
379+
for counter in spm_counters:
380+
print(counter)
381+
print("\n")
382+
else:
383+
spm_counters = avail.get_spm_counters()[agent]
384+
for spm in _args.spm:
385+
for counter in spm_counters:
386+
if spm == counter.get_as_dict()["Counter_Name"]:
387+
print(counter)
388+
389+
for agent, info in dict(sorted(agent_info_map.items())).items():
390+
if (
391+
info["type"] == 2
392+
and args.device is not None
393+
and info["logical_node_type_id"] == args.device
394+
):
395+
print(
396+
"{}:{}\n{}:{}".format(
397+
"GPU", info["logical_node_type_id"], "Name", info["name"]
398+
)
399+
)
400+
print_spm_info(args, agent)
401+
break
402+
elif info["type"] == 2 and args.device is None:
403+
print(
404+
"{}:{}\n{}:{}".format(
405+
"GPU", info["logical_node_type_id"], "Name", info["name"]
406+
)
407+
)
408+
print_spm_info(args, agent)
409+
410+
315411
def info_pmc(args):
316412
from rocprofv3 import avail
317413

318-
agent_counters = avail.get_counters()
319414
agent_info_map = avail.get_agent_info_map()
320415

321-
def print_pmc_info(args, pmc_counters):
416+
def print_pmc_info(_args, agent):
322417

323-
if not args.pmc:
418+
if not _args.pmc:
419+
pmc_counters = avail.get_counters()[agent]
324420
for counter in pmc_counters:
325421
print(counter)
326422
print("\n")
327423
else:
328-
for pmc in args.pmc:
424+
pmc_counters = avail.get_counters()[agent]
425+
for pmc in _args.pmc:
329426
for counter in pmc_counters:
330427
if pmc == counter.get_as_dict()["Counter_Name"]:
331428
print(counter)
332-
print("\n")
333429

334430
for agent, info in dict(sorted(agent_info_map.items())).items():
335431
if (
@@ -342,34 +438,44 @@ def print_pmc_info(args, pmc_counters):
342438
"GPU", info["logical_node_type_id"], "Name", info["name"]
343439
)
344440
)
345-
print_pmc_info(args, agent_counters[agent])
441+
print_pmc_info(args, agent)
346442
break
347443
elif info["type"] == 2 and args.device is None:
348444
print(
349445
"{}:{}\n{}:{}".format(
350446
"GPU", info["logical_node_type_id"], "Name", info["name"]
351447
)
352448
)
353-
print_pmc_info(args, agent_counters[agent])
449+
print_pmc_info(args, agent)
354450

355451

356452
def process_info(args):
357-
if args.pmc is None and args.pc_sampling is None:
453+
454+
if args.pmc is None and args.pc_sampling is None and args.spm is None:
358455
list_basic_agent(args, True)
359456
if args.pmc is not None:
360457
info_pmc(args)
458+
if args.spm is not None:
459+
info_spm(args)
361460
if args.pc_sampling is not None:
362461
os.environ["ROCPROFILER_PC_SAMPLING_BETA_ENABLED"] = "on"
363462
info_pc_sampling(args)
364463

365464

366465
def process_list(args):
367-
if args.agent is None and args.pc_sampling is None and args.pmc is None:
368-
listing(args)
466+
if (
467+
args.agent is None
468+
and args.pc_sampling is None
469+
and args.pmc is None
470+
and args.spm is None
471+
):
472+
listing_pmc(args)
369473
if args.agent:
370474
list_basic_agent(args, False)
371475
if args.pmc:
372-
listing(args)
476+
listing_pmc(args)
477+
if args.spm:
478+
listing_spm(args)
373479
if args.pc_sampling:
374480
os.environ["ROCPROFILER_PC_SAMPLING_BETA_ENABLED"] = "on"
375481
list_pc_sampling(args)

projects/rocprofiler-sdk/source/bin/rocprofv3.py

Lines changed: 94 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,44 @@ def add_parser_bool_argument(gparser, *args, **kwargs):
470470
action="append",
471471
)
472472

473+
spm_options = parser.add_argument_group("Streaming Performance Monitor(SPM) options")
474+
475+
add_parser_bool_argument(
476+
spm_options,
477+
"--spm-beta-enabled",
478+
help="enable SPM; beta version",
479+
)
480+
481+
spm_options.add_argument(
482+
"--spm",
483+
help=(
484+
"Specify SPM events to collect(comma OR space separated in case of more than 1 counters). "
485+
"Note: job will fail if entire set of counters cannot be collected in single pass"
486+
),
487+
default=None,
488+
nargs="*",
489+
)
490+
491+
spm_options.add_argument(
492+
"--spm-buffer-size",
493+
help="SPM Buffer size in kilobytes. Default value is set to 32768 KB in tool",
494+
default=None,
495+
type=str,
496+
)
497+
498+
spm_options.add_argument(
499+
"--spm-timeout",
500+
help="Timeout for SPM, in ms. Default value is set to 0 ms in tool",
501+
default=None,
502+
type=int,
503+
)
504+
505+
spm_options.add_argument(
506+
"--spm-frequency",
507+
help="Frequency in Ghz. This is estimated to shader clock count. Default is set to 0.5GHz in tool.",
508+
default=None,
509+
type=str,
510+
)
473511
pc_sampling_options = parser.add_argument_group("PC sampling options")
474512

475513
add_parser_bool_argument(
@@ -1143,6 +1181,20 @@ def is_filtered(key):
11431181
return patch_args(dotdict(data))
11441182

11451183

1184+
def int_auto(num_str):
1185+
if isinstance(num_str, str):
1186+
if "0x" in num_str:
1187+
return int(num_str, 16)
1188+
else:
1189+
return int(num_str, 10)
1190+
elif isinstance(num_str, int):
1191+
return num_str
1192+
else:
1193+
raise ValueError(
1194+
f"{type(num_str)} is not supported. {num_str} should be of type integer or string."
1195+
)
1196+
1197+
11461198
def run(app_args, args, **kwargs):
11471199

11481200
app_env = dict(os.environ)
@@ -1740,6 +1792,48 @@ def log_config(_env):
17401792
update_env("ROCPROF_PC_SAMPLING_METHOD", args.pc_sampling_method)
17411793
update_env("ROCPROF_PC_SAMPLING_INTERVAL", args.pc_sampling_interval)
17421794

1795+
if args.spm or args.spm_buffer_size or args.spm_timeout or args.spm_frequency:
1796+
1797+
if (
1798+
not args.spm_beta_enabled
1799+
and os.environ.get("ROCPROFILER_SPM_BETA_ENABLED", None) is None
1800+
):
1801+
fatal_error(
1802+
"SPM unavailable. The feature is implicitly disabled. To enable it, use --spm-beta-enabled option"
1803+
)
1804+
1805+
update_env("ROCPROFILER_SPM_BETA_ENABLED", True, overwrite=True)
1806+
update_env("ROCPROF_SPM_COUNTER_COLLECTION", True, overwrite=True)
1807+
1808+
if (
1809+
args.pmc
1810+
or args.pc_sampling_beta_enabled
1811+
or os.environ.get("ROCPROFILER_PC_SAMPLING_BETA_ENABLED", None) is not None
1812+
):
1813+
fatal_error(
1814+
"SPM feature cannot be enabled along with pc sampling or pmc counter collection"
1815+
)
1816+
1817+
if args.spm is None:
1818+
fatal_error("Please input list of counters to be sampled")
1819+
1820+
update_env(
1821+
"ROCPROF_SPM_COUNTERS",
1822+
"spm: {}".format(" ".join(args.spm)),
1823+
overwrite=True,
1824+
)
1825+
1826+
if args.spm_buffer_size:
1827+
update_env(
1828+
"ROCPROF_SPM_BUFFER_SIZE", int_auto(args.spm_buffer_size), overwrite=True
1829+
)
1830+
1831+
if args.spm_timeout:
1832+
update_env("ROCPROF_SPM_TIMEOUT_MS", args.spm_timeout, overwrite=True)
1833+
1834+
if args.spm_frequency:
1835+
update_env("ROCPROF_SPM_FREQUENCY", float(args.spm_frequency), overwrite=True)
1836+
17431837
if args.disable_signal_handlers is not None:
17441838
update_env("ROCPROF_SIGNAL_HANDLERS", not args.disable_signal_handlers)
17451839

@@ -1751,19 +1845,6 @@ def log_config(_env):
17511845

17521846
if args.advanced_thread_trace:
17531847

1754-
def int_auto(num_str):
1755-
if isinstance(num_str, str):
1756-
if "0x" in num_str:
1757-
return int(num_str, 16)
1758-
else:
1759-
return int(num_str, 10)
1760-
elif isinstance(num_str, int):
1761-
return num_str
1762-
else:
1763-
raise ValueError(
1764-
f"{type(num_str)} is not supported. {num_str} should be of type integer or string."
1765-
)
1766-
17671848
update_env("ROCPROF_ADVANCED_THREAD_TRACE", True, overwrite=True)
17681849

17691850
if args.att_target_cu is not None:

0 commit comments

Comments
 (0)