Skip to content

Commit

Permalink
[XPU] Added a Python interface to Context::set_debug_level in XDNN fo…
Browse files Browse the repository at this point in the history
…r setting the XPUAPI_DEBUG level. (PaddlePaddle#62210)
  • Loading branch information
ZibinGuo authored and runzhech committed Apr 30, 2024
1 parent db63fc4 commit 98ef510
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 0 deletions.
4 changes: 4 additions & 0 deletions paddle/fluid/platform/device/xpu/xpu_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ phi::backends::xpu::XPUVersion get_xpu_version(int dev_id) {
return phi::backends::xpu::get_xpu_version(dev_id);
}

void set_xpu_debug_level(int level) {
phi::backends::xpu::set_xpu_debug_level(level);
}

/**************************** XPU Allocator **************************/
size_t XPUMinChunkSize() { return 1 << 6; }

Expand Down
2 changes: 2 additions & 0 deletions paddle/fluid/platform/device/xpu/xpu_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ using XPUDeviceGuard = phi::backends::xpu::XPUDeviceGuard;

phi::backends::xpu::XPUVersion get_xpu_version(int dev_id);

void set_xpu_debug_level(int level);

//! Get the minimum chunk size for XPU allocator.
size_t XPUMinChunkSize();

Expand Down
2 changes: 2 additions & 0 deletions paddle/fluid/pybind/place.cc
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,8 @@ void BindPlace(pybind11::module &m) { // NOLINT
.value("XPU3", phi::backends::xpu::XPUVersion::XPU3)
.export_values();
m.def("get_xpu_device_count", platform::GetXPUDeviceCount);
m.def("set_xpu_debug_level",
[](int level) { platform::set_xpu_debug_level(level); });
m.def("get_xpu_device_version",
[](int device_id) { return platform::get_xpu_version(device_id); });
#ifdef PADDLE_WITH_XPU_KP
Expand Down
9 changes: 9 additions & 0 deletions paddle/phi/backends/xpu/xpu_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ limitations under the License. */
#include "paddle/phi/backends/xpu/xpu_header.h"
#include "paddle/phi/common/place.h"

#include "paddle/phi/api/lib/kernel_dispatch.h"

// TODO(wilber): The phi computing library requires a component to manage
// flags.
#include "paddle/common/flags.h"
Expand Down Expand Up @@ -204,6 +206,13 @@ XPUVersion get_xpu_version(int dev_id) {
}
}

void set_xpu_debug_level(int level) {
auto* dev_ctx =
paddle::experimental::GetDeviceContextByBackend(phi::Backend::XPU);
auto* xpu_ctx = static_cast<const phi::XPUContext*>(dev_ctx);
PADDLE_ENFORCE_XPU_SUCCESS(xpu_ctx->x_context()->set_debug_level(level));
}

int get_xpu_max_ptr_size(int dev_id) {
auto xpu_version = get_xpu_version(dev_id);
int max_ptr_size = 0;
Expand Down
1 change: 1 addition & 0 deletions paddle/phi/backends/xpu/xpu_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ class XPUDeviceGuard {

enum XPUVersion { XPU1, XPU2, XPU3 };
XPUVersion get_xpu_version(int dev_id);
void set_xpu_debug_level(int level);

int get_xpu_max_ptr_size(int dev_id);

Expand Down
23 changes: 23 additions & 0 deletions python/paddle/device/xpu/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,26 @@ def device_count():
)

return num_xpus


def set_debug_level(level=1):
'''
Set the debug level of XPUs' api.
Parameters:
int: debug level of XPUs available.
|level |name |usage
|0 |stop |stop the debug mode
|0x1 |trace |Print the invocation of the interface
|0x10 |checksum |Print the checksum of the tensor
|0x100 |dump |Save the tensor as a file in npy format
|0x1000 |profiling |Record the execution time of each operator
Examples:
.. code-block:: python
>>> import paddle
>>> paddle.device.xpu.set_debug_level(0x1)
'''
core.set_xpu_debug_level(level)

0 comments on commit 98ef510

Please sign in to comment.