Skip to content

Conversation

@qingqing01
Copy link
Contributor

@qingqing01 qingqing01 commented Nov 27, 2017

Fix #5953

The usage is:

import paddle.v2.fluid.profiler as profiler with profiler.cuda_profiler("cuda_profiler.txt", 'csv') as nvprof: # run CUDA program. # then will create file cuda_profiler.txt, which contains the profiling results.
tonyyang-svail
tonyyang-svail previously approved these changes Nov 28, 2017
Copy link

@tonyyang-svail tonyyang-svail left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@qingqing01 Overall looks good to me.

In the issue description(#5953), could you please provide a couple of examples where this feature is useful? Especially where nvprof is not sufficient.

memcpy(buf.data(), tmpl.data(), tmpl.size());
auto result = mktemp(buf.data());
PADDLE_ENFORCE(strlen(result) != 0);
std::string config = result;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably config -> config_file would be a better name.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


void CudaProfilerStart() { PADDLE_ENFORCE(cudaProfilerStart()); }

void CudaProfilerStop() { PADDLE_ENFORCE((cudaProfilerStop())); }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove the parentheses.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

]


def nvporf_init(output_file, output_mode=None, flags=None):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We currently use google style for Python comment.

http://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Move the comments to the refined CudaProfiler.

core.nvprof_stop()


class CudaProfiler(object):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This a good implementation.

I recently found a wonderful package named contextmanager. It can make the profiler to one function.

http://book.pythontips.com/en/latest/context_managers.html#implementing-a-context-manager-as-a-generator

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Cool! Thanks!

core.nvprof_init(output_file, output_mode, flags)


def nvporf_start():
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nvporf --> nvprof

"""
Enables profiler collection by the active CUDA profiling tool.
"""
core.nvprof_start()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this function may not need wrap again in Python code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Remove them.

self.out_file = output_file
nvporf_init(output_file, output_mode, flags)

def __enter__(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these two functions can be replaced with contextmanager.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@qingqing01
Copy link
Contributor Author

@tonyyang-svail I update the issue description(#5953) and give a simple example. And the output file needs to be made more human-readable later.

Copy link
Collaborator

@reyoung reyoung left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Execellent.

@qingqing01 qingqing01 merged commit 21053c1 into PaddlePaddle:develop Nov 29, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

4 participants