Skip to content
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

[Inference] Fix none-contiguous bug for python api. #29615

Merged
merged 1 commit into from
Dec 15, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions paddle/fluid/pybind/inference_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,23 +69,27 @@ void BindMkldnnQuantizerConfig(py::module *m);
#endif

template <typename T>
PaddleBuf PaddleBufCreate(py::array_t<T> data) {
PaddleBuf PaddleBufCreate(
py::array_t<T, py::array::c_style | py::array::forcecast> data) {
PaddleBuf buf(data.size() * sizeof(T));
std::copy_n(static_cast<const T *>(data.data()), data.size(),
static_cast<T *>(buf.data()));
return buf;
}

template <typename T>
void PaddleBufReset(PaddleBuf &buf, py::array_t<T> data) { // NOLINT
void PaddleBufReset(
PaddleBuf &buf, // NOLINT
py::array_t<T, py::array::c_style | py::array::forcecast> data) { // NOLINT
buf.Resize(data.size() * sizeof(T));
std::copy_n(static_cast<const T *>(data.data()), data.size(),
static_cast<T *>(buf.data()));
}

template <typename T>
PaddleTensor PaddleTensorCreate(
py::array_t<T> data, const std::string name = "",
py::array_t<T, py::array::c_style | py::array::forcecast> data,
const std::string name = "",
const std::vector<std::vector<size_t>> &lod = {}, bool copy = true) {
PaddleTensor tensor;

Expand Down Expand Up @@ -137,17 +141,19 @@ py::array PaddleTensorGetData(PaddleTensor &tensor) { // NOLINT
}

template <typename T>
void ZeroCopyTensorCreate(ZeroCopyTensor &tensor, // NOLINT
py::array_t<T> data) {
void ZeroCopyTensorCreate(
ZeroCopyTensor &tensor, // NOLINT
py::array_t<T, py::array::c_style | py::array::forcecast> data) {
std::vector<int> shape;
std::copy_n(data.shape(), data.ndim(), std::back_inserter(shape));
tensor.Reshape(std::move(shape));
tensor.copy_from_cpu(static_cast<const T *>(data.data()));
}

template <typename T>
void PaddleInferTensorCreate(paddle_infer::Tensor &tensor, // NOLINT
py::array_t<T> data) {
void PaddleInferTensorCreate(
paddle_infer::Tensor &tensor, // NOLINT
py::array_t<T, py::array::c_style | py::array::forcecast> data) {
std::vector<int> shape;
std::copy_n(data.shape(), data.ndim(), std::back_inserter(shape));
tensor.Reshape(std::move(shape));
Expand Down