[BugFix][CPU] Add CPU profiler summary file output (#38366)
Signed-off-by: Elham Harirpoush <elham.harirpoush@arm.com>
This commit is contained in:
+33
-15
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user