Unverified Commit 13e6b1b9 authored by Elham's avatar Elham Committed by GitHub
Browse files

[BugFix][CPU] Add CPU profiler summary file output (#38366)


Signed-off-by: default avatarElham Harirpoush <elham.harirpoush@arm.com>
parent 58c0a928
......@@ -240,6 +240,28 @@ class TorchProfilerWrapper(WorkerProfiler):
0,
)
def _build_profiler_table(
self,
sort_key: str,
row_limit: int | None = None,
) -> str:
if row_limit is None: # use profiler default row limit of 100
return self.profiler.key_averages().table(sort_by=sort_key)
return self.profiler.key_averages().table(
sort_by=sort_key,
row_limit=row_limit,
)
def _write_profiler_table(self, rank: int, table: str) -> None:
profiler_dir = self.profiler_config.torch_profiler_dir
# Skip file write for URI paths (gs://, s3://, etc.)
# as standard file I/O doesn't work with URI schemes
if not _is_uri_path(profiler_dir):
profiler_out_file = f"{profiler_dir}/profiler_out_{rank}.txt"
with open(profiler_out_file, "w") as f:
print(table, file=f)
@override
def _start(self) -> None:
self.profiler.start()
......@@ -251,26 +273,22 @@ class TorchProfilerWrapper(WorkerProfiler):
profiler_config = self.profiler_config
rank = self.local_rank
if profiler_config.torch_profiler_dump_cuda_time_total:
profiler_dir = profiler_config.torch_profiler_dir
sort_key = "self_cuda_time_total"
table = self.profiler.key_averages().table(sort_by=sort_key)
# Skip file write for URI paths (gs://, s3://, etc.)
# as standard file I/O doesn't work with URI schemes
if not _is_uri_path(profiler_dir):
profiler_out_file = f"{profiler_dir}/profiler_out_{rank}.txt"
with open(profiler_out_file, "w") as f:
print(table, file=f)
table = self._build_profiler_table(sort_key="self_cuda_time_total")
self._write_profiler_table(rank, table)
# only print profiler results on rank 0
if rank == 0:
print(table)
if self.dump_cpu_time_total and rank == 0:
logger.info(
self.profiler.key_averages().table(
sort_by="self_cpu_time_total", row_limit=50
)
if self.dump_cpu_time_total:
table = self._build_profiler_table(
sort_key="self_cpu_time_total", row_limit=50
)
self._write_profiler_table(rank, table)
# only print profiler results on rank 0
if rank == 0:
print(table)
@override
def _profiler_step(self) -> bool:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment