Skip to content

Commit ad39860

Browse files
committed
Add SPM support to rocprofv3 tool and CLI
1 parent 1fe2a80 commit ad39860

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
@@ -441,6 +441,44 @@ def add_parser_bool_argument(gparser, *args, **kwargs):
441441
action="append",
442442
)
443443

444+
spm_options = parser.add_argument_group("Streaming Performance Monitor(SPM) options")
445+
446+
add_parser_bool_argument(
447+
spm_options,
448+
"--spm-beta-enabled",
449+
help="enable SPM; beta version",
450+
)
451+
452+
spm_options.add_argument(
453+
"--spm",
454+
help=(
455+
"Specify SPM events to collect(comma OR space separated in case of more than 1 counters). "
456+
"Note: job will fail if entire set of counters cannot be collected in single pass"
457+
),
458+
default=None,
459+
nargs="*",
460+
)
461+
462+
spm_options.add_argument(
463+
"--spm-buffer-size",
464+
help="SPM Buffer size in kilobytes. Default value is set to 32768 KB in tool",
465+
default=None,
466+
type=str,
467+
)
468+
469+
spm_options.add_argument(
470+
"--spm-timeout",
471+
help="Timeout for SPM, in ms. Default value is set to 0 ms in tool",
472+
default=None,
473+
type=int,
474+
)
475+
476+
spm_options.add_argument(
477+
"--spm-frequency",
478+
help="Frequency in Ghz. This is estimated to shader clock count. Default is set to 0.5GHz in tool.",
479+
default=None,
480+
type=str,
481+
)
444482
pc_sampling_options = parser.add_argument_group("PC sampling options")
445483

446484
add_parser_bool_argument(
@@ -1078,6 +1116,20 @@ def is_filtered(key):
10781116
return patch_args(dotdict(data))
10791117

10801118

1119+
def int_auto(num_str):
1120+
if isinstance(num_str, str):
1121+
if "0x" in num_str:
1122+
return int(num_str, 16)
1123+
else:
1124+
return int(num_str, 10)
1125+
elif isinstance(num_str, int):
1126+
return num_str
1127+
else:
1128+
raise ValueError(
1129+
f"{type(num_str)} is not supported. {num_str} should be of type integer or string."
1130+
)
1131+
1132+
10811133
def run(app_args, args, **kwargs):
10821134

10831135
app_env = dict(os.environ)
@@ -1660,6 +1712,48 @@ def log_config(_env):
16601712
update_env("ROCPROF_PC_SAMPLING_METHOD", args.pc_sampling_method)
16611713
update_env("ROCPROF_PC_SAMPLING_INTERVAL", args.pc_sampling_interval)
16621714

1715+
if args.spm or args.spm_buffer_size or args.spm_timeout or args.spm_frequency:
1716+
1717+
if (
1718+
not args.spm_beta_enabled
1719+
and os.environ.get("ROCPROFILER_SPM_BETA_ENABLED", None) is None
1720+
):
1721+
fatal_error(
1722+
"SPM unavailable. The feature is implicitly disabled. To enable it, use --spm-beta-enabled option"
1723+
)
1724+
1725+
update_env("ROCPROFILER_SPM_BETA_ENABLED", True, overwrite=True)
1726+
update_env("ROCPROF_SPM_COUNTER_COLLECTION", True, overwrite=True)
1727+
1728+
if (
1729+
args.pmc
1730+
or args.pc_sampling_beta_enabled
1731+
or os.environ.get("ROCPROFILER_PC_SAMPLING_BETA_ENABLED", None) is not None
1732+
):
1733+
fatal_error(
1734+
"SPM feature cannot be enabled along with pc sampling or pmc counter collection"
1735+
)
1736+
1737+
if args.spm is None:
1738+
fatal_error("Please input list of counters to be sampled")
1739+
1740+
update_env(
1741+
"ROCPROF_SPM_COUNTERS",
1742+
"spm: {}".format(" ".join(args.spm)),
1743+
overwrite=True,
1744+
)
1745+
1746+
if args.spm_buffer_size:
1747+
update_env(
1748+
"ROCPROF_SPM_BUFFER_SIZE", int_auto(args.spm_buffer_size), overwrite=True
1749+
)
1750+
1751+
if args.spm_timeout:
1752+
update_env("ROCPROF_SPM_TIMEOUT_MS", args.spm_timeout, overwrite=True)
1753+
1754+
if args.spm_frequency:
1755+
update_env("ROCPROF_SPM_FREQUENCY", float(args.spm_frequency), overwrite=True)
1756+
16631757
if args.disable_signal_handlers is not None:
16641758
update_env("ROCPROF_SIGNAL_HANDLERS", not args.disable_signal_handlers)
16651759

@@ -1671,19 +1765,6 @@ def log_config(_env):
16711765

16721766
if args.advanced_thread_trace:
16731767

1674-
def int_auto(num_str):
1675-
if isinstance(num_str, str):
1676-
if "0x" in num_str:
1677-
return int(num_str, 16)
1678-
else:
1679-
return int(num_str, 10)
1680-
elif isinstance(num_str, int):
1681-
return num_str
1682-
else:
1683-
raise ValueError(
1684-
f"{type(num_str)} is not supported. {num_str} should be of type integer or string."
1685-
)
1686-
16871768
update_env("ROCPROF_ADVANCED_THREAD_TRACE", True, overwrite=True)
16881769

16891770
if args.att_target_cu is not None:

0 commit comments

Comments
 (0)