From aef5df530f57dfe642b308534543dca9aeda48ea Mon Sep 17 00:00:00 2001 From: zachary sun <70642955+sunzhongkai588@users.noreply.github.com> Date: Wed, 27 Sep 2023 16:37:11 +0800 Subject: [PATCH] [xdoctest][task 325] reformat example code with google style in paddle/fluid/pybind/place.cc (#57610) * convert place.cc code * fix place.cc doc string * fix codestyle --- paddle/fluid/pybind/place.cc | 40 ++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/paddle/fluid/pybind/place.cc b/paddle/fluid/pybind/place.cc index 55a73cac1b6658..1b0101a85537ad 100644 --- a/paddle/fluid/pybind/place.cc +++ b/paddle/fluid/pybind/place.cc @@ -213,9 +213,10 @@ void BindPlace(pybind11::module &m) { // NOLINT Examples: .. code-block:: python - import paddle - fake_cpu_place = paddle.CustomPlace("FakeCPU", 0) - )DOC"); + >>> # doctest: +REQUIRES(env:CUSTOM_DEVICE) + >>> import paddle + >>> fake_cpu_place = paddle.CustomPlace("FakeCPU", 0) + )DOC"); g_customplace_pytype = reinterpret_cast(customplace.ptr()); customplace .def("__init__", @@ -293,7 +294,7 @@ void BindPlace(pybind11::module &m) { // NOLINT py::class_ cudaplace(m, "CUDAPlace", R"DOC( CUDAPlace is a descriptor of a device. - It represents a GPU device allocated or to be allocated with Tensor or LoDTensor. + It represents a GPU device allocated or to be allocated with Tensor. Each CUDAPlace has a dev_id to indicate the graphics card ID represented by the current CUDAPlace, staring from 0. The memory of CUDAPlace with different dev_id is not accessible. @@ -309,9 +310,9 @@ void BindPlace(pybind11::module &m) { // NOLINT Examples: .. code-block:: python - import paddle - - place = paddle.CUDAPlace(0) + >>> # doctest: +REQUIRES(env:GPU) + >>> import paddle + >>> place = paddle.CUDAPlace(0) )DOC"); g_cudaplace_pytype = reinterpret_cast(cudaplace.ptr()); @@ -391,11 +392,14 @@ void BindPlace(pybind11::module &m) { // NOLINT }); #endif py::class_ xpuplace(m, "XPUPlace", R"DOC( - **Note**: + Return a Baidu Kunlun Place + Examples: .. code-block:: python - import paddle.base as base - xpu_place = base.XPUPlace(0) + + >>> # doctest: +REQUIRES(env:XPU) + >>> import paddle.base as base + >>> xpu_place = base.XPUPlace(0) )DOC"); g_xpuplace_pytype = reinterpret_cast(xpuplace.ptr()); xpuplace @@ -492,8 +496,8 @@ void BindPlace(pybind11::module &m) { // NOLINT Examples: .. code-block:: python - import paddle - cpu_place = paddle.CPUPlace() + >>> import paddle + >>> cpu_place = paddle.CPUPlace() )DOC"); g_cpuplace_pytype = reinterpret_cast(cpuplace.ptr()); @@ -531,8 +535,9 @@ void BindPlace(pybind11::module &m) { // NOLINT Examples: .. code-block:: python - import paddle - place = paddle.CUDAPinnedPlace() + >>> # doctest: +REQUIRES(env:GPU) + >>> import paddle + >>> place = paddle.CUDAPinnedPlace() )DOC"); g_cudapinnedplace_pytype = @@ -567,11 +572,10 @@ void BindPlace(pybind11::module &m) { // NOLINT Examples: .. code-block:: python - import paddle - - # required: ipu - ipu_place = paddle.IPUPlace() + >>> # doctest: +REQUIRES(env:IPU) + >>> import paddle + >>> ipu_place = paddle.IPUPlace() )DOC"); g_ipuplace_pytype = reinterpret_cast(ipuplace.ptr());