-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pfm parsing / nvidia gpu profiling init (#33)
- Loading branch information
1 parent
8810bad
commit 8fbc0eb
Showing
22 changed files
with
421 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,6 @@ bin | |
__pycache__ | ||
dist | ||
phlop.egg-info/ | ||
scope_timer.txt | ||
|
||
*scope_timer.txt | ||
tpp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#! clean build test run -p scope_timer,threaded_scope_timer -Oa "-fPIC -std=c++20" -W 9 | ||
|
||
# run script first: ./sh/setup_pfm.sh | ||
|
||
name: phlop.pfm | ||
parent: base | ||
|
||
profile: | ||
- name: base | ||
inc: inc | ||
|
||
- name: pfm | ||
inc: tpp/pfm/include | ||
|
||
- name: pfm_lib | ||
parent: pfm | ||
mode: static | ||
inc: tpp/pfm/lib, 0 | ||
src: tpp/pfm/lib | ||
|
||
- name: pfm_events | ||
self: pfm_lib | ||
main: tpp/pfm/examples/check_events.c | ||
out: check_events | ||
|
||
- name: pfm_info | ||
self: pfm_lib | ||
main: tpp/pfm/examples/showevtinfo.c | ||
out: showevtinfo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# | ||
# | ||
# | ||
# | ||
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# | ||
# | ||
# | ||
# | ||
# | ||
|
||
|
||
available_modules = """Available: | ||
phlop.app.nvidia.csan | ||
phlop.app.nvidia.ncu""" | ||
|
||
print(available_modules) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# compute sanitizer frontend | ||
|
||
# https://docs.nvidia.com/compute-sanitizer/ComputeSanitizer/index.html | ||
|
||
## samples | ||
# compute-sanitizer --tool memcheck [sanitizer_options] app_name [app_options] | ||
# compute-sanitizer --tool racecheck [sanitizer_options] app_name [app_options] | ||
# | ||
# | ||
# | ||
|
||
|
||
from phlop.dict import ValDict | ||
from phlop.proc import run | ||
|
||
metrics = [ | ||
"all", | ||
"l1tex__data_bank_conflicts_pipe_lsu_mem_shared_op_ld.sum", # read | ||
"l1tex__data_bank_conflicts_pipe_lsu_mem_shared_op_st.sum", # wrte | ||
] | ||
|
||
|
||
def build_command(cli_args): | ||
cmd_parts = [ | ||
"compute-sanitizer", | ||
f"--tool {cli_args.tool}", | ||
cli_args.extra if cli_args.extra else "", | ||
" ".join(cli_args.remaining) if cli_args.remaining else "", | ||
] | ||
return " ".join(filter(None, cmd_parts)) | ||
|
||
|
||
def exec(cli_args): | ||
return run(build_command(cli_args), check=True, cwd=cli_args.dir) | ||
|
||
|
||
def cli_args_parser(description="compute-sanitizer tool"): | ||
import argparse | ||
|
||
_help = ValDict( | ||
dir="working directory", | ||
quiet="Redirect output to /dev/null", | ||
logging="0=off, 1=on non zero exit code, 2=always", | ||
outfile="path for saved file if active", | ||
tool="Sanitizer tool to use (memcheck, racecheck, initcheck, synccheck)", | ||
extra="forward string to csan command", | ||
) | ||
|
||
parser = argparse.ArgumentParser( | ||
description=description, formatter_class=argparse.ArgumentDefaultsHelpFormatter | ||
) | ||
parser.add_argument("remaining", nargs=argparse.REMAINDER) | ||
parser.add_argument("-d", "--dir", default=".", help=_help.dir) | ||
parser.add_argument("-o", "--outfile", default=None, help=_help.outfile) | ||
parser.add_argument("-t", "--tool", default="memcheck", help=_help.tool) | ||
parser.add_argument("--logging", type=int, default=1, help=_help.logging) | ||
parser.add_argument("-e", "--extra", type=str, default="", help=_help.extra) | ||
|
||
return parser | ||
|
||
|
||
def verify_cli_args(cli_args): | ||
return cli_args |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# Nsight Compute CLI | ||
|
||
# https://docs.nvidia.com/nsight-compute/ProfilingGuide/index.html | ||
|
||
## samples | ||
# ncu --help | ||
# ncu --metrics all | ||
# ncu --metrics l1tex__data_bank_conflicts_pipe_lsu_mem_shared_op_st.sum | ||
# ncu --target-processes all -o <report-name> mpirun [mpi arguments] <app> [app arguments] | ||
# | ||
|
||
|
||
from phlop.dict import ValDict | ||
from phlop.proc import run | ||
|
||
metrics = [ | ||
"all", | ||
"l1tex__data_bank_conflicts_pipe_lsu_mem_shared_op_ld.sum", # read | ||
"l1tex__data_bank_conflicts_pipe_lsu_mem_shared_op_st.sum", # wrte | ||
] | ||
|
||
|
||
def build_command(cli_args): | ||
return f"ncu {cli_args.remaining}" | ||
|
||
|
||
def exec(cli_args): | ||
return run(build_command(cli_args), check=True) | ||
|
||
|
||
def cli_args_parser(description="ncu tool"): | ||
import argparse | ||
|
||
_help = ValDict( | ||
dir="working directory", | ||
quiet="Redirect output to /dev/null", | ||
logging="0=off, 1=on non zero exit code, 2=always", | ||
outfile="path for saved file if active", | ||
tool="", | ||
extra="forward string to csan command", | ||
) | ||
|
||
parser = argparse.ArgumentParser( | ||
description=description, formatter_class=argparse.ArgumentDefaultsHelpFormatter | ||
) | ||
parser.add_argument("remaining", nargs=argparse.REMAINDER) | ||
parser.add_argument("-d", "--dir", default=".", help=_help.dir) | ||
parser.add_argument("-o", "--outfile", default=None, help=_help.outfile) | ||
parser.add_argument("-t", "--tool", default="stat", help=_help.tool) | ||
parser.add_argument("--logging", type=int, default=1, help=_help.logging) | ||
parser.add_argument("-e", "--extra", type=str, default="", help=_help.extra) | ||
|
||
return parser | ||
|
||
|
||
def verify_cli_args(cli_args): | ||
return cli_args |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# | ||
# | ||
# | ||
# | ||
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# | ||
# | ||
# | ||
# | ||
# | ||
|
||
|
||
available_modules = """Available: | ||
phlop.app.pfm.check_events | ||
phlop.app.pfm.showevtinfo""" | ||
|
||
print(available_modules) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# | ||
# | ||
# | ||
# | ||
# | ||
|
||
|
||
import logging | ||
from pathlib import Path | ||
|
||
from phlop.os import pushd | ||
from phlop.proc import run | ||
from phlop.string import decode_bytes | ||
|
||
FILE_DIR = Path(__file__).resolve().parent | ||
|
||
logger = logging.getLogger(__name__) | ||
check_events_start = "Total events:" | ||
|
||
|
||
def parse_check_events_output(lines): | ||
return lines[-1].split(":")[1].strip().replace("0x", "r") | ||
|
||
|
||
def run_check_events(code): | ||
with pushd(FILE_DIR.parent.parent.parent): | ||
return decode_bytes( | ||
run(f"./tpp/pfm/examples/check_events {code}").stdout | ||
).splitlines() | ||
|
||
|
||
def get_evt_perf_code(code): | ||
return parse_check_events_output(run_check_events(code)) | ||
|
||
|
||
if __name__ == "__main__": | ||
from phlop.app.pfm.showevtinfo import get_evt_info | ||
|
||
key, code = "[MULT_FLOPS]", "" | ||
for info in get_evt_info(): | ||
if key in info.umask: | ||
code = f"{info.name}:{info.umask[key].code}" | ||
break | ||
|
||
assert code != "" | ||
|
||
# print("get_evt_perf_code", get_evt_perf_code(code)) | ||
print(run(f"perf stat -e {get_evt_perf_code(code)} sleep 5")) |
Oops, something went wrong.