Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
68398abc
P
Paddle
项目概览
Crayon鑫
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
68398abc
编写于
1月 04, 2021
作者:
C
cc
提交者:
GitHub
1月 04, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[Inference] zero_copy_tensor supports int8_t (#30053)
* zero_copy_tensor supports int8_t
上级
1b999d2b
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
62 addition
and
68 deletion
+62
-68
paddle/fluid/inference/api/details/zero_copy_tensor.cc
paddle/fluid/inference/api/details/zero_copy_tensor.cc
+9
-0
paddle/fluid/inference/api/paddle_api.h
paddle/fluid/inference/api/paddle_api.h
+1
-0
paddle/fluid/inference/tests/api/tester_helper.h
paddle/fluid/inference/tests/api/tester_helper.h
+43
-68
paddle/fluid/pybind/inference_api.cc
paddle/fluid/pybind/inference_api.cc
+9
-0
未找到文件。
paddle/fluid/inference/api/details/zero_copy_tensor.cc
浏览文件 @
68398abc
...
...
@@ -165,10 +165,14 @@ template PD_INFER_DECL void ZeroCopyTensor::copy_from_cpu<int32_t>(
const
int32_t
*
data
);
template
PD_INFER_DECL
void
ZeroCopyTensor
::
copy_from_cpu
<
uint8_t
>(
const
uint8_t
*
data
);
template
PD_INFER_DECL
void
ZeroCopyTensor
::
copy_from_cpu
<
int8_t
>(
const
int8_t
*
data
);
template
PD_INFER_DECL
void
ZeroCopyTensor
::
copy_to_cpu
<
float
>(
float
*
data
);
template
PD_INFER_DECL
void
ZeroCopyTensor
::
copy_to_cpu
<
int64_t
>(
int64_t
*
data
);
template
PD_INFER_DECL
void
ZeroCopyTensor
::
copy_to_cpu
<
int32_t
>(
int32_t
*
data
);
template
PD_INFER_DECL
void
ZeroCopyTensor
::
copy_to_cpu
<
uint8_t
>(
uint8_t
*
data
);
template
PD_INFER_DECL
void
ZeroCopyTensor
::
copy_to_cpu
<
int8_t
>(
int8_t
*
data
);
template
PD_INFER_DECL
float
*
ZeroCopyTensor
::
data
<
float
>(
PaddlePlace
*
place
,
int
*
size
)
const
;
...
...
@@ -178,6 +182,9 @@ template PD_INFER_DECL int32_t *ZeroCopyTensor::data<int32_t>(
PaddlePlace
*
place
,
int
*
size
)
const
;
template
PD_INFER_DECL
uint8_t
*
ZeroCopyTensor
::
data
<
uint8_t
>(
PaddlePlace
*
place
,
int
*
size
)
const
;
template
PD_INFER_DECL
int8_t
*
ZeroCopyTensor
::
data
<
int8_t
>(
PaddlePlace
*
place
,
int
*
size
)
const
;
template
PD_INFER_DECL
float
*
ZeroCopyTensor
::
mutable_data
<
float
>(
PaddlePlace
place
);
template
PD_INFER_DECL
int64_t
*
ZeroCopyTensor
::
mutable_data
<
int64_t
>(
...
...
@@ -186,6 +193,8 @@ template PD_INFER_DECL int32_t *ZeroCopyTensor::mutable_data<int32_t>(
PaddlePlace
place
);
template
PD_INFER_DECL
uint8_t
*
ZeroCopyTensor
::
mutable_data
<
uint8_t
>(
PaddlePlace
place
);
template
PD_INFER_DECL
int8_t
*
ZeroCopyTensor
::
mutable_data
<
int8_t
>(
PaddlePlace
place
);
void
*
ZeroCopyTensor
::
FindTensor
()
const
{
PADDLE_ENFORCE_EQ
(
...
...
paddle/fluid/inference/api/paddle_api.h
浏览文件 @
68398abc
...
...
@@ -39,6 +39,7 @@ enum PaddleDType {
INT64
,
INT32
,
UINT8
,
INT8
,
// TODO(Superjomn) support more data types if needed.
};
...
...
paddle/fluid/inference/tests/api/tester_helper.h
浏览文件 @
68398abc
...
...
@@ -257,40 +257,29 @@ void CompareResult(const std::vector<PaddleTensor> &outputs,
EXPECT_GT
(
size
,
0UL
);
EXPECT_EQ
(
size
,
ref_size
);
EXPECT_EQ
(
out
.
dtype
,
ref_out
.
dtype
);
#define COMPARE(paddle_type, type, func) \
case paddle_type: { \
type *pdata = static_cast<type *>(out.data.data()); \
type *pdata_ref = static_cast<type *>(ref_out.data.data()); \
for (size_t j = 0; j < size; ++j) { \
func(pdata_ref[j], pdata[j]); \
} \
break; \
}
switch
(
out
.
dtype
)
{
case
PaddleDType
::
INT64
:
{
int64_t
*
pdata
=
static_cast
<
int64_t
*>
(
out
.
data
.
data
());
int64_t
*
pdata_ref
=
static_cast
<
int64_t
*>
(
ref_out
.
data
.
data
());
for
(
size_t
j
=
0
;
j
<
size
;
++
j
)
{
EXPECT_EQ
(
pdata_ref
[
j
],
pdata
[
j
]);
}
break
;
}
case
PaddleDType
::
FLOAT32
:
{
float
*
pdata
=
static_cast
<
float
*>
(
out
.
data
.
data
());
float
*
pdata_ref
=
static_cast
<
float
*>
(
ref_out
.
data
.
data
());
for
(
size_t
j
=
0
;
j
<
size
;
++
j
)
{
CheckError
(
pdata_ref
[
j
],
pdata
[
j
]);
}
break
;
}
case
PaddleDType
::
INT32
:
{
int32_t
*
pdata
=
static_cast
<
int32_t
*>
(
out
.
data
.
data
());
int32_t
*
pdata_ref
=
static_cast
<
int32_t
*>
(
ref_out
.
data
.
data
());
for
(
size_t
j
=
0
;
j
<
size
;
++
j
)
{
EXPECT_EQ
(
pdata_ref
[
j
],
pdata
[
j
]);
}
break
;
}
case
PaddleDType
::
UINT8
:
{
uint8_t
*
pdata
=
static_cast
<
uint8_t
*>
(
out
.
data
.
data
());
uint8_t
*
pdata_ref
=
static_cast
<
uint8_t
*>
(
ref_out
.
data
.
data
());
for
(
size_t
j
=
0
;
j
<
size
;
++
j
)
{
EXPECT_EQ
(
pdata_ref
[
j
],
pdata
[
j
]);
}
break
;
}
COMPARE
(
PaddleDType
::
INT64
,
int64_t
,
EXPECT_EQ
);
COMPARE
(
PaddleDType
::
FLOAT32
,
float
,
CheckError
);
COMPARE
(
PaddleDType
::
INT32
,
int32_t
,
EXPECT_EQ
);
COMPARE
(
PaddleDType
::
UINT8
,
uint8_t
,
EXPECT_EQ
);
COMPARE
(
PaddleDType
::
INT8
,
int8_t
,
EXPECT_EQ
);
default:
PADDLE_THROW
(
platform
::
errors
::
InvalidArgument
(
"VarMessageToVarType: Unsupported dtype %d"
,
static_cast
<
int
>
(
out
.
dtype
)));
}
#undef COMPARE
}
}
...
...
@@ -306,44 +295,30 @@ void CompareResult(const std::vector<PaddleTensor> &outputs,
EXPECT_GT
(
size
,
0UL
);
int
ref_size
=
0
;
// this is the number of elements not memory size
PaddlePlace
place
;
#define COMPARE(paddle_type, type, func) \
case paddle_type: { \
type *pdata = static_cast<type *>(out.data.data()); \
type *pdata_ref = ref_out.data<type>(&place, &ref_size); \
EXPECT_EQ(size, static_cast<size_t>(ref_size)); \
for (size_t j = 0; j < size; ++j) { \
func(pdata_ref[j], pdata[j]); \
} \
break; \
}
switch
(
out
.
dtype
)
{
case
PaddleDType
::
INT64
:
{
int64_t
*
pdata
=
static_cast
<
int64_t
*>
(
out
.
data
.
data
());
int64_t
*
pdata_ref
=
ref_out
.
data
<
int64_t
>
(
&
place
,
&
ref_size
);
EXPECT_EQ
(
size
,
static_cast
<
size_t
>
(
ref_size
));
for
(
size_t
j
=
0
;
j
<
size
;
++
j
)
{
EXPECT_EQ
(
pdata_ref
[
j
],
pdata
[
j
]);
}
break
;
}
case
PaddleDType
::
FLOAT32
:
{
float
*
pdata
=
static_cast
<
float
*>
(
out
.
data
.
data
());
float
*
pdata_ref
=
ref_out
.
data
<
float
>
(
&
place
,
&
ref_size
);
EXPECT_EQ
(
size
,
static_cast
<
size_t
>
(
ref_size
));
for
(
size_t
j
=
0
;
j
<
size
;
++
j
)
{
CheckError
(
pdata_ref
[
j
],
pdata
[
j
]);
}
break
;
}
case
PaddleDType
::
INT32
:
{
int32_t
*
pdata
=
static_cast
<
int32_t
*>
(
out
.
data
.
data
());
int32_t
*
pdata_ref
=
ref_out
.
data
<
int32_t
>
(
&
place
,
&
ref_size
);
EXPECT_EQ
(
size
,
static_cast
<
size_t
>
(
ref_size
));
for
(
size_t
j
=
0
;
j
<
size
;
++
j
)
{
EXPECT_EQ
(
pdata_ref
[
j
],
pdata
[
j
]);
}
break
;
}
case
PaddleDType
::
UINT8
:
{
uint8_t
*
pdata
=
static_cast
<
uint8_t
*>
(
out
.
data
.
data
());
uint8_t
*
pdata_ref
=
ref_out
.
data
<
uint8_t
>
(
&
place
,
&
ref_size
);
EXPECT_EQ
(
size
,
static_cast
<
size_t
>
(
ref_size
));
for
(
size_t
j
=
0
;
j
<
size
;
++
j
)
{
EXPECT_EQ
(
pdata_ref
[
j
],
pdata
[
j
]);
}
break
;
}
COMPARE
(
PaddleDType
::
INT64
,
int64_t
,
EXPECT_EQ
);
COMPARE
(
PaddleDType
::
FLOAT32
,
float
,
CheckError
);
COMPARE
(
PaddleDType
::
INT32
,
int32_t
,
EXPECT_EQ
);
COMPARE
(
PaddleDType
::
UINT8
,
uint8_t
,
EXPECT_EQ
);
COMPARE
(
PaddleDType
::
INT8
,
int8_t
,
EXPECT_EQ
);
default:
PADDLE_THROW
(
platform
::
errors
::
InvalidArgument
(
"VarMessageToVarType: Unsupported dtype %d"
,
static_cast
<
int
>
(
out
.
dtype
)));
}
#undef COMPARE
}
}
...
...
paddle/fluid/pybind/inference_api.cc
浏览文件 @
68398abc
...
...
@@ -199,6 +199,9 @@ py::array ZeroCopyTensorToNumpy(ZeroCopyTensor &tensor) { // NOLINT
case
PaddleDType
::
UINT8
:
tensor
.
copy_to_cpu
<
uint8_t
>
(
static_cast
<
uint8_t
*>
(
array
.
mutable_data
()));
break
;
case
PaddleDType
::
INT8
:
tensor
.
copy_to_cpu
<
int8_t
>
(
static_cast
<
int8_t
*>
(
array
.
mutable_data
()));
break
;
default:
PADDLE_THROW
(
platform
::
errors
::
Unimplemented
(
"Unsupported data type. Now only supports INT32, INT64, UINT8 and "
...
...
@@ -223,6 +226,12 @@ py::array PaddleInferTensorToNumpy(paddle_infer::Tensor &tensor) { // NOLINT
case
PaddleDType
::
FLOAT32
:
tensor
.
CopyToCpu
<
float
>
(
static_cast
<
float
*>
(
array
.
mutable_data
()));
break
;
case
PaddleDType
::
UINT8
:
tensor
.
CopyToCpu
(
static_cast
<
uint8_t
*>
(
array
.
mutable_data
()));
break
;
case
PaddleDType
::
INT8
:
tensor
.
CopyToCpu
(
static_cast
<
int8_t
*>
(
array
.
mutable_data
()));
break
;
default:
PADDLE_THROW
(
platform
::
errors
::
Unimplemented
(
"Unsupported data type. Now only supports INT32, INT64 and "
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录