Skip to content

Commit

Permalink
add topyobject for place
Browse files Browse the repository at this point in the history
  • Loading branch information
wanghuancoder committed Nov 19, 2021
1 parent fbde0b1 commit aa67cca
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
5 changes: 1 addition & 4 deletions paddle/fluid/pybind/eager_properties.cc
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,7 @@ PyObject* eager_tensor_properties_get_shape(EagerTensorObject* self,

PyObject* eager_tensor_properties_get_place(EagerTensorObject* self,
void* closure) {
auto place = self->eagertensor.place();
auto obj = ::pybind11::cast(place);
obj.inc_ref();
return obj.ptr();
return ToPyObject(self->eagertensor.place());
}

PyObject* eager_tensor_properties_get_place_str(EagerTensorObject* self,
Expand Down
6 changes: 6 additions & 0 deletions paddle/fluid/pybind/eager_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -329,5 +329,11 @@ PyObject* ToPyObject(const std::vector<egr::EagerTensor>& value) {
return result;
}

PyObject* ToPyObject(const platform::Place& value) {
auto obj = ::pybind11::cast(value);
obj.inc_ref();
return obj.ptr();
}

} // namespace pybind
} // namespace paddle
1 change: 1 addition & 0 deletions paddle/fluid/pybind/eager_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ PyObject* ToPyObject(const std::vector<int64_t>& value);
PyObject* ToPyObject(const std::vector<float>& value);
PyObject* ToPyObject(const std::vector<double>& value);
PyObject* ToPyObject(const std::vector<egr::EagerTensor>& value);
PyObject* ToPyObject(const platform::Place& value);

} // namespace pybind
} // namespace paddle

0 comments on commit aa67cca

Please sign in to comment.