cuda_profiler

paddle.utils.profiler. cuda_profiler ( output_file, output_mode=None, config=None ) [source]

The CUDA profiler.

This fuctions is used to profile CUDA program by CUDA runtime application programming interface. The profiling result will be written into output_file. The users can set the output mode by output_mode argument and set the nvidia profiling config by config argument.

After getting the profiling result file, users can use NVIDIA Visual Profiler to load this output file to visualize results.

Parameters
  • output_file (str) – The output file name, the result will be written into this file.

  • output_mode (str, optional) – The output mode has Key-Value pair format (‘kvp’) and Comma separated values format (‘csv’, default).

  • config (list<str>, optional) – Nvidia profile config. Default config is [‘gpustarttimestamp’, ‘gpuendtimestamp’, ‘gridsize3d’, ‘threadblocksize’, ‘streamid’, ‘enableonstart 0’, ‘conckerneltrace’]. For more details, please refer to Compute Command Line Profiler User Guide .

Raises

ValueError – If output_mode is not in [‘kvp’, ‘csv’].

Examples

import paddle.fluid as fluid
import paddle.fluid.profiler as profiler
import numpy as np

epoc = 8
dshape = [4, 3, 28, 28]
data = fluid.data(name='data', shape=[None, 3, 28, 28], dtype='float32')
conv = fluid.layers.conv2d(data, 20, 3, stride=[1, 1], padding=[1, 1])

place = fluid.CUDAPlace(0)
exe = fluid.Executor(place)
exe.run(fluid.default_startup_program())

output_file = 'cuda_profiler.txt'
with profiler.cuda_profiler(output_file, 'csv') as nvprof:
    for i in range(epoc):
        input = np.random.random(dshape).astype('float32')
        exe.run(fluid.default_main_program(), feed={'data': input})
# then use  NVIDIA Visual Profiler (nvvp) to load this output file
# to visualize results.