Skip to content

Commit c5c4e95

Browse files
committed
update
1 parent 76b9287 commit c5c4e95

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

paddle/fluid/inference/api/analysis_predictor.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,16 @@
2525
#include "paddle/fluid/inference/api/details/reset_tensor_array.h"
2626
#include "paddle/fluid/inference/api/helper.h"
2727
#include "paddle/fluid/inference/api/paddle_inference_api.h"
28+
#include "paddle/fluid/platform/float16.h"
2829
#include "paddle/fluid/string/printf.h"
2930
#ifdef PADDLE_WITH_TESTING
3031
#include <gtest/gtest.h>
3132
#include <gtest/gtest_prod.h>
3233
#endif
3334

35+
namespace paddle_infer {
36+
using float16 = paddle::platform::float16;
37+
}
3438
///
3539
/// \file analysis_predictor.h
3640
///

paddle/fluid/inference/api/details/zero_copy_tensor.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@
1919
#include "paddle/fluid/inference/api/paddle_tensor.h"
2020
#include "paddle/fluid/memory/memcpy.h"
2121
#include "paddle/fluid/platform/enforce.h"
22+
#include "paddle/fluid/platform/float16.h"
2223

2324
namespace paddle_infer {
2425

26+
using float16 = paddle::platform::float16;
27+
2528
void Tensor::Reshape(const std::vector<int> &shape) {
2629
PADDLE_ENFORCE_EQ(
2730
name_.empty(), false,
@@ -263,16 +266,14 @@ template PD_INFER_DECL void Tensor::CopyFromCpu<int64_t>(const int64_t *data);
263266
template PD_INFER_DECL void Tensor::CopyFromCpu<int32_t>(const int32_t *data);
264267
template PD_INFER_DECL void Tensor::CopyFromCpu<uint8_t>(const uint8_t *data);
265268
template PD_INFER_DECL void Tensor::CopyFromCpu<int8_t>(const int8_t *data);
266-
template PD_INFER_DECL void Tensor::CopyFromCpu<paddle::platform::float16>(
267-
const paddle::platform::float16 *data);
269+
template PD_INFER_DECL void Tensor::CopyFromCpu<float16>(const float16 *data);
268270

269271
template PD_INFER_DECL void Tensor::CopyToCpu<float>(float *data);
270272
template PD_INFER_DECL void Tensor::CopyToCpu<int64_t>(int64_t *data);
271273
template PD_INFER_DECL void Tensor::CopyToCpu<int32_t>(int32_t *data);
272274
template PD_INFER_DECL void Tensor::CopyToCpu<uint8_t>(uint8_t *data);
273275
template PD_INFER_DECL void Tensor::CopyToCpu<int8_t>(int8_t *data);
274-
template PD_INFER_DECL void Tensor::CopyToCpu<paddle::platform::float16>(
275-
paddle::platform::float16 *data);
276+
template PD_INFER_DECL void Tensor::CopyToCpu<float16>(float16 *data);
276277

277278
template PD_INFER_DECL float *Tensor::data<float>(PlaceType *place,
278279
int *size) const;

paddle/fluid/pybind/inference_api.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ constexpr int NPY_UINT16_ = 4;
4747
// paddle::platform::float16 as numpy.float16.
4848
// Ref: https://github.com/pybind/pybind11/issues/1776
4949
template <>
50-
struct npy_format_descriptor<paddle::platform::float16> {
50+
struct npy_format_descriptor<paddle_infer::float16> {
5151
static py::dtype dtype() {
5252
handle ptr = npy_api::get().PyArray_DescrFromType_(NPY_FLOAT16_);
5353
return reinterpret_borrow<py::dtype>(ptr);
@@ -157,7 +157,7 @@ py::dtype PaddleDTypeToNumpyDType(PaddleDType dtype) {
157157
dt = py::dtype::of<uint8_t>();
158158
break;
159159
case PaddleDType::FLOAT16:
160-
dt = py::dtype("e");
160+
dt = py::dtype::of<paddle_infer::float16>();
161161
break;
162162
default:
163163
PADDLE_THROW(platform::errors::Unimplemented(
@@ -683,7 +683,7 @@ void BindZeroCopyTensor(py::module *m) {
683683
.def("copy_from_cpu", &ZeroCopyTensorCreate<int32_t>)
684684
.def("copy_from_cpu", &ZeroCopyTensorCreate<int64_t>)
685685
.def("copy_from_cpu", &ZeroCopyTensorCreate<float>)
686-
.def("copy_from_cpu", &ZeroCopyTensorCreate<paddle::platform::float16>)
686+
.def("copy_from_cpu", &ZeroCopyTensorCreate<paddle_infer::float16>)
687687
.def("copy_to_cpu", &ZeroCopyTensorToNumpy)
688688
.def("shape", &ZeroCopyTensor::shape)
689689
.def("set_lod", &ZeroCopyTensor::SetLoD)
@@ -697,7 +697,7 @@ void BindPaddleInferTensor(py::module *m) {
697697
.def("copy_from_cpu", &PaddleInferTensorCreate<int32_t>)
698698
.def("copy_from_cpu", &PaddleInferTensorCreate<int64_t>)
699699
.def("copy_from_cpu", &PaddleInferTensorCreate<float>)
700-
.def("copy_from_cpu", &PaddleInferTensorCreate<paddle::platform::float16>)
700+
.def("copy_from_cpu", &PaddleInferTensorCreate<paddle_infer::float16>)
701701
.def("copy_to_cpu", &PaddleInferTensorToNumpy)
702702
.def("shape", &paddle_infer::Tensor::shape)
703703
.def("set_lod", &paddle_infer::Tensor::SetLoD)

0 commit comments

Comments
 (0)