- Notifications
You must be signed in to change notification settings - Fork 5.9k
add python profiler package #40065
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add python profiler package #40065
Changes from 1 commit
8fd1e30 43c147a 541cd21 fb84d48 a90076a 4e69ff7 bc34d5b 6beff3b 2b10368 b7a3174 909d064 bee8254 9370ccb dccfaad df566e0 File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| | @@ -77,6 +77,9 @@ limitations under the License. */ | |
| #include "paddle/fluid/platform/monitor.h" | ||
| #include "paddle/fluid/platform/place.h" | ||
| #include "paddle/fluid/platform/profiler.h" | ||
| #include "paddle/fluid/platform/profiler/event_python.h" | ||
| #include "paddle/fluid/platform/profiler/event_tracing.h" | ||
| #include "paddle/fluid/platform/profiler/profiler.h" | ||
| #include "paddle/fluid/pybind/cuda_streams_py.h" | ||
| #include "paddle/fluid/pybind/distributed_py.h" | ||
| #include "paddle/fluid/pybind/eager.h" | ||
| | @@ -2913,6 +2916,85 @@ All parameter, weight, gradient are variables in Paddle. | |
| }); | ||
| | ||
| m.def("size_of_dtype", framework::SizeOfType); | ||
| py::class_<paddle::platform::ProfilerResult>(m, "_ProfilerResult") | ||
| .def(py::init<>()) | ||
| .def("get_data", &paddle::platform::ProfilerResult::GetData, | ||
| py::return_value_policy::automatic_reference) | ||
| .def("save", &paddle::platform::ProfilerResult::Save) | ||
| .def("get_extra_info", &paddle::platform::ProfilerResult::GetExtraInfo); | ||
| | ||
| py::class_<paddle::platform::DevicePythonNode>(m, "DevicePythonNode") | ||
| .def(py::init<>()) | ||
| .def_readwrite("name", &paddle::platform::DevicePythonNode::name) | ||
| .def_readwrite("type", &paddle::platform::DevicePythonNode::type) | ||
| .def_readwrite("start_ns", &paddle::platform::DevicePythonNode::start_ns) | ||
| .def_readwrite("end_ns", &paddle::platform::DevicePythonNode::end_ns) | ||
| .def_readwrite("device_id", | ||
| &paddle::platform::DevicePythonNode::device_id) | ||
| .def_readwrite("context_id", | ||
| &paddle::platform::DevicePythonNode::context_id) | ||
| .def_readwrite("stream_id", | ||
| &paddle::platform::DevicePythonNode::stream_id); | ||
| | ||
| py::class_<paddle::platform::HostPythonNode>(m, "HostPythonNode") | ||
| .def(py::init<>()) | ||
| .def_readwrite("name", &paddle::platform::HostPythonNode::name) | ||
| .def_readwrite("type", &paddle::platform::HostPythonNode::type) | ||
| .def_readwrite("start_ns", &paddle::platform::HostPythonNode::start_ns) | ||
| .def_readwrite("end_ns", &paddle::platform::HostPythonNode::end_ns) | ||
| .def_readwrite("process_id", | ||
| &paddle::platform::HostPythonNode::process_id) | ||
| .def_readwrite("thread_id", &paddle::platform::HostPythonNode::thread_id) | ||
| .def_readwrite("children_node", | ||
| &paddle::platform::HostPythonNode::children_node_ptrs) | ||
| .def_readwrite("runtime_node", | ||
| &paddle::platform::HostPythonNode::runtime_node_ptrs) | ||
| .def_readwrite("device_node", | ||
| &paddle::platform::HostPythonNode::device_node_ptrs); | ||
| | ||
| py::class_<paddle::platform::Profiler>(m, "_Profiler") | ||
| .def("Create", &paddle::platform::Profiler::Create) | ||
| .def("Prepare", | ||
| [](paddle::platform::Profiler *profiler) { | ||
| platform::EnableHostEventRecorder(); | ||
| profiler->Prepare(); | ||
| }) | ||
| .def("Start", &paddle::platform::Profiler::Start) | ||
| .def("Stop", &paddle::platform::Profiler::Stop, | ||
| ||
| py::return_value_policy::automatic_reference); | ||
| | ||
| py::class_<paddle::platform::ProfilerOptions>(m, "ProfilerOptions") | ||
| .def(py::init<>()) | ||
| .def_readwrite("trace_level", | ||
| ||
| &paddle::platform::ProfilerOptions::trace_level) | ||
| .def_readwrite("trace_switch", | ||
| &paddle::platform::ProfilerOptions::trace_switch); | ||
| | ||
| py::class_<platform::RecordEvent>(m, "_RecordEvent") | ||
| .def(py::init([](std::string name, platform::TracerEventType type) { | ||
| return std::unique_ptr<platform::RecordEvent>(new platform::RecordEvent( | ||
| ||
| name, type, 1, paddle::platform::EventRole::kOrdinary)); | ||
| })) | ||
| .def("end", [](platform::RecordEvent *event) { event->End(); }); | ||
| | ||
| py::enum_<paddle::platform::TracerEventType>(m, "TracerEventType") | ||
| .value("Operator", paddle::platform::TracerEventType::Operator) | ||
| .value("Dataloader", paddle::platform::TracerEventType::Dataloader) | ||
| .value("ProfileStep", paddle::platform::TracerEventType::ProfileStep) | ||
| .value("CudaRuntime", paddle::platform::TracerEventType::CudaRuntime) | ||
| .value("Kernel", paddle::platform::TracerEventType::Kernel) | ||
| .value("Memcpy", paddle::platform::TracerEventType::Memcpy) | ||
| .value("Memset", paddle::platform::TracerEventType::Memset) | ||
| .value("UserDefined", paddle::platform::TracerEventType::UserDefined) | ||
| .value("OperatorInner", paddle::platform::TracerEventType::OperatorInner) | ||
| .value("Forward", paddle::platform::TracerEventType::Forward) | ||
| .value("Backward", paddle::platform::TracerEventType::Backward) | ||
| .value("Optimization", paddle::platform::TracerEventType::Optimization) | ||
| .value("Communication", paddle::platform::TracerEventType::Communication) | ||
| .value("PythonOp", paddle::platform::TracerEventType::PythonOp) | ||
| .value("PythonUserDefined", | ||
| paddle::platform::TracerEventType::PythonUserDefined); | ||
| m.def("LoadProfilerResult", &paddle::platform::LoadProfilerResult); | ||
| | ||
| #if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) | ||
| m.def("set_cublas_switch", platform::SetAllowTF32Cublas); | ||
| | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| # Copyright (c) 2022 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 .profiler import ProfilerState, ProfilerTarget | ||
| from .profiler import make_scheduler, export_chrome_tracing, export_protobuf | ||
| from .profiler import Profiler | ||
| from .profiler import TracerEventType | ||
| from .utils import RecordEvent | ||
| from .profiler_statistic import SortedKeys | ||
| | ||
| __all__ = [ | ||
| 'ProfilerState', 'ProfilerTarget', 'TracerEventType', 'make_scheduler', | ||
| 'export_chrome_tracing', 'export_protobuf', 'Profiler', 'RecordEvent', | ||
| 'SortedKeys' | ||
| ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这块的Profiler相关调用函数首字母大写,这块是有调研过竞品,都是大写?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已修改为小写