|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
import paddle.v2.fluid.core as core
|
|
|
|
|
from contextlib import contextmanager
|
|
|
|
|
import os
|
|
|
|
|
|
|
|
|
|
__all__ = ['CudaProfiler']
|
|
|
|
|
|
|
|
|
@ -30,17 +31,21 @@ def cuda_profiler(output_file, output_mode=None, config=None):
|
|
|
|
|
written into this file.
|
|
|
|
|
output_mode (string) : The output mode has Key-Value pair format and
|
|
|
|
|
Comma separated values format. It should be 'kvp' or 'csv'.
|
|
|
|
|
config (string) : The profiler options and counters can refer to
|
|
|
|
|
"Compute Command Line Profiler User Guide".
|
|
|
|
|
config (list of string) : The profiler options and counters can refer
|
|
|
|
|
to "Compute Command Line Profiler User Guide".
|
|
|
|
|
"""
|
|
|
|
|
if output_mode is None:
|
|
|
|
|
output_mode = 'csv'
|
|
|
|
|
if output_mode not in ['kvp', 'csv']:
|
|
|
|
|
raise ValueError("The output mode must be 'kvp' or 'csv'.")
|
|
|
|
|
config = NVPROF_CONFIG if config is None else config
|
|
|
|
|
core.nvprof_init(output_file, output_mode, config)
|
|
|
|
|
config_file = 'nvprof_config_file'
|
|
|
|
|
with open(config_file, 'wb') as fp:
|
|
|
|
|
fp.writelines(["%s\n" % item for item in config])
|
|
|
|
|
core.nvprof_init(output_file, output_mode, config_file)
|
|
|
|
|
# Enables profiler collection by the active CUDA profiling tool.
|
|
|
|
|
core.nvprof_start()
|
|
|
|
|
yield
|
|
|
|
|
# Disables profiler collection.
|
|
|
|
|
core.nvprof_stop()
|
|
|
|
|
os.remove(config_file)
|
|
|
|
|