diff --git a/python/paddle/fluid/profiler.py b/python/paddle/fluid/profiler.py index 40b0862be0177ec9ce90088bf48ff7a068868bec..fc48a48450efd88f59bd4cc47c53b44b6a904436 100644 --- a/python/paddle/fluid/profiler.py +++ b/python/paddle/fluid/profiler.py @@ -38,72 +38,15 @@ NVPROF_CONFIG = [ @signature_safe_contextmanager def cuda_profiler(output_file, output_mode=None, config=None): """ - 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. - - Args: - 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, 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: - - .. code-block:: python - - 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. + API cuda_profiler has been abandoned. If you have relevant requirements, you can use `paddle.utils.profiler.start_profiler` and `paddle.utils.profiler.stop_profiler`. + The relevant reference documents are as follows: + + + """ - 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 - config_file = 'nvprof_config_file' - with open(config_file, 'wb') as fp: - fp.writelines([six.b("%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() - try: - yield - # Disables profiler collection. - finally: - core.nvprof_stop() - os.remove(config_file) + raise RuntimeError( + "API cuda_profiler has been abandoned. If you have relevant requirements, you can use `paddle.utils.profiler.start_profiler` and `paddle.utils.profiler.stop_profiler`.\nThe relevant reference documents are as follows:\n\n\n" + ) @signature_safe_contextmanager @@ -167,8 +110,7 @@ def npu_profiler(output_file, config=None): def reset_profiler(): """ - Clear the previous time record. This interface does not work for - `fluid.profiler.cuda_profiler`, it only works for + Clear the previous time record. It works for `fluid.profiler.start_profiler`, `fluid.profiler.stop_profiler`, and `fluid.profiler.profiler`. @@ -176,6 +118,7 @@ def reset_profiler(): .. code-block:: python + # required: gpu import paddle.fluid as fluid import paddle.fluid.profiler as profiler with profiler.profiler('CPU', 'total', '/tmp/profile'): @@ -316,8 +259,7 @@ def profiler(state, profile_path='/tmp/profile', tracer_option='Default'): """ - The profiler interface. Different from `fluid.profiler.cuda_profiler`, - this profiler can be used to profile both CPU and GPU program. + The profiler interface. This profiler can be used to profile both CPU and GPU program. Args: state (str) : The profiling state, which should be one of 'CPU', 'GPU' @@ -349,9 +291,12 @@ def profiler(state, .. code-block:: python + # required: gpu import paddle.fluid as fluid import paddle.fluid.profiler as profiler import numpy as np + import paddle + paddle.enable_static() epoc = 8 dshape = [4, 3, 28, 28] diff --git a/python/paddle/fluid/tests/unittests/test_nvprof.py b/python/paddle/fluid/tests/unittests/test_nvprof.py deleted file mode 100644 index da943d64da6cfc64d121b7373f7c067c1cff731c..0000000000000000000000000000000000000000 --- a/python/paddle/fluid/tests/unittests/test_nvprof.py +++ /dev/null @@ -1,48 +0,0 @@ -# Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from __future__ import print_function - -import unittest -import os -import numpy as np -import paddle.fluid as fluid -import paddle.fluid.profiler as profiler -import paddle.fluid.layers as layers -import paddle.fluid.core as core - - -class TestNVProf(unittest.TestCase): - def test_nvprof(self): - if not fluid.core.is_compiled_with_cuda(): - return - epoc = 8 - dshape = [4, 3, 28, 28] - data = layers.data(name='data', shape=[3, 28, 28], dtype='float32') - conv = 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}) - os.remove(output_file) - - -if __name__ == '__main__': - unittest.main()