diff --git a/paddle/fluid/pybind/pybind.cc b/paddle/fluid/pybind/pybind.cc index 6c4ba10e90e2165c118d26e19ff53c792faa056d..c3b25671468ac01fa2da8cbda7e6843965daebb5 100644 --- a/paddle/fluid/pybind/pybind.cc +++ b/paddle/fluid/pybind/pybind.cc @@ -2393,23 +2393,31 @@ All parameter, weight, gradient are variables in Paddle. py::return_value_policy::copy); py::class_(m, "_gpuDeviceProperties") - .def_readonly("name", &gpuDeviceProp::name) - .def_readonly("major", &gpuDeviceProp::major) - .def_readonly("minor", &gpuDeviceProp::minor) - .def_readonly("is_multi_gpu_board", &gpuDeviceProp::isMultiGpuBoard) - .def_readonly("is_integrated", &gpuDeviceProp::integrated) - .def_readonly("multi_processor_count", - &gpuDeviceProp::multiProcessorCount) - .def_readonly("total_memory", &gpuDeviceProp::totalGlobalMem) - .def("__repr__", [](const gpuDeviceProp &gpu_device_prop) { - std::ostringstream stream; - stream << "_gpuDeviceProperties(name='" << gpu_device_prop.name - << "', major=" << gpu_device_prop.major - << ", minor=" << gpu_device_prop.minor << ", total_memory=" - << gpu_device_prop.totalGlobalMem / (1024 * 1024) - << "MB, multi_processor_count=" - << gpu_device_prop.multiProcessorCount << ")"; - return stream.str(); + .def_property_readonly( + "name", [](const gpuDeviceProp &prop) { return prop.name; }) + .def_property_readonly( + "major", [](const gpuDeviceProp &prop) { return prop.major; }) + .def_property_readonly( + "minor", [](const gpuDeviceProp &prop) { return prop.minor; }) + .def_property_readonly( + "total_memory", + [](const gpuDeviceProp &prop) { return prop.totalGlobalMem; }) + .def_property_readonly( + "multi_processor_count", + [](const gpuDeviceProp &prop) { return prop.multiProcessorCount; }) + .def_property_readonly( + "is_multi_gpu_board", + [](const gpuDeviceProp &prop) { return prop.isMultiGpuBoard; }) + .def_property_readonly( + "is_integrated", + [](const gpuDeviceProp &prop) { return prop.integrated; }) + .def("__repr__", [](const gpuDeviceProp &prop) { + std::stringstream ostr; + ostr << "_gpuDeviceProperties(name='" << prop.name + << "', major=" << prop.major << ", minor=" << prop.minor + << ", total_memory=" << prop.totalGlobalMem / (1024 * 1024) + << "MB, multi_processor_count=" << prop.multiProcessorCount << ")"; + return ostr.str(); }); #if !defined(PADDLE_WITH_HIP) && !defined(_WIN32)