Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
52e13225
P
Paddle-Lite
项目概览
PaddlePaddle
/
Paddle-Lite
通知
331
Star
4
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
271
列表
看板
标记
里程碑
合并请求
78
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle-Lite
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
271
Issue
271
列表
看板
标记
里程碑
合并请求
78
合并请求
78
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
52e13225
编写于
10月 18, 2018
作者:
Z
Zhen Wang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add int8_t gemm and enable MulOp to support int8_t.
上级
1c893a02
变更
7
展开全部
隐藏空白更改
内联
并排
Showing
7 changed file
with
413 addition
and
182 deletion
+413
-182
src/framework/operator.cpp
src/framework/operator.cpp
+1
-1
src/framework/tensor.h
src/framework/tensor.h
+3
-1
src/operators/kernel/arm/mul_kernel.cpp
src/operators/kernel/arm/mul_kernel.cpp
+3
-0
src/operators/kernel/central-arm-func/mul_arm_func.h
src/operators/kernel/central-arm-func/mul_arm_func.h
+11
-5
src/operators/math/gemm.h
src/operators/math/gemm.h
+0
-1
src/operators/math/gemm_int8.cpp
src/operators/math/gemm_int8.cpp
+328
-107
test/operators/test_mul_op.cpp
test/operators/test_mul_op.cpp
+67
-67
未找到文件。
src/framework/operator.cpp
浏览文件 @
52e13225
...
@@ -32,7 +32,7 @@ template <typename Dtype>
...
@@ -32,7 +32,7 @@ template <typename Dtype>
vector
<
string
>
OperatorBase
<
Dtype
>::
GetInputKeys
()
const
{
vector
<
string
>
OperatorBase
<
Dtype
>::
GetInputKeys
()
const
{
auto
it
=
op_input_output_key
.
find
(
type_
);
auto
it
=
op_input_output_key
.
find
(
type_
);
if
(
it
==
op_input_output_key
.
end
())
{
if
(
it
==
op_input_output_key
.
end
())
{
DLOG
<<
type_
<<
" has no
out
puts"
;
DLOG
<<
type_
<<
" has no
in
puts"
;
return
{};
return
{};
}
}
return
it
->
second
.
first
;
return
it
->
second
.
first
;
...
...
src/framework/tensor.h
浏览文件 @
52e13225
...
@@ -338,10 +338,12 @@ inline Print &operator<<(Print &printer, const Tensor &tensor) {
...
@@ -338,10 +338,12 @@ inline Print &operator<<(Print &printer, const Tensor &tensor) {
for
(
int
i
=
0
;
i
<
tensor
.
numel
();
i
+=
stride
)
{
for
(
int
i
=
0
;
i
<
tensor
.
numel
();
i
+=
stride
)
{
if
(
tensor
.
type
()
==
typeid
(
float
))
{
if
(
tensor
.
type
()
==
typeid
(
float
))
{
printer
<<
tensor
.
data
<
float
>
()[
i
]
<<
" "
;
printer
<<
tensor
.
data
<
float
>
()[
i
]
<<
" "
;
}
else
if
(
tensor
.
type
()
==
typeid
(
int32_t
))
{
printer
<<
tensor
.
data
<
int32_t
>
()[
i
]
<<
" "
;
}
else
if
(
tensor
.
type
()
==
typeid
(
int64_t
))
{
}
else
if
(
tensor
.
type
()
==
typeid
(
int64_t
))
{
printer
<<
tensor
.
data
<
int64_t
>
()[
i
]
<<
" "
;
printer
<<
tensor
.
data
<
int64_t
>
()[
i
]
<<
" "
;
}
else
if
(
tensor
.
type
()
==
typeid
(
int8_t
))
{
}
else
if
(
tensor
.
type
()
==
typeid
(
int8_t
))
{
printer
<<
tensor
.
data
<
int8_t
>
()[
i
]
<<
" "
;
printer
<<
static_cast
<
int32_t
>
(
tensor
.
data
<
int8_t
>
()[
i
])
<<
" "
;
}
}
}
}
#endif
#endif
...
...
src/operators/kernel/arm/mul_kernel.cpp
浏览文件 @
52e13225
...
@@ -25,12 +25,15 @@ bool MulKernel<CPU, float>::Init(MulParam<CPU> *param) {
...
@@ -25,12 +25,15 @@ bool MulKernel<CPU, float>::Init(MulParam<CPU> *param) {
return
true
;
return
true
;
}
}
template
<
>
template
<
>
void
MulKernel
<
CPU
,
float
>::
Compute
(
const
MulParam
<
CPU
>
&
param
)
const
{
void
MulKernel
<
CPU
,
float
>::
Compute
(
const
MulParam
<
CPU
>
&
param
)
const
{
MulCompute
<
float
>
(
param
);
MulCompute
<
float
>
(
param
);
param
.
Out
()
->
set_lod
(
param
.
InputX
()
->
lod
());
param
.
Out
()
->
set_lod
(
param
.
InputX
()
->
lod
());
}
}
template
class
MulKernel
<
CPU
,
float
>;
}
// namespace operators
}
// namespace operators
}
// namespace paddle_mobile
}
// namespace paddle_mobile
...
...
src/operators/kernel/central-arm-func/mul_arm_func.h
浏览文件 @
52e13225
...
@@ -58,7 +58,7 @@ void MulCompute(const MulParam<CPU> ¶m) {
...
@@ -58,7 +58,7 @@ void MulCompute(const MulParam<CPU> ¶m) {
const
Tensor
*
input_x
=
param
.
InputX
();
const
Tensor
*
input_x
=
param
.
InputX
();
const
Tensor
*
input_y
=
param
.
InputY
();
const
Tensor
*
input_y
=
param
.
InputY
();
Tensor
*
out
=
param
.
Out
();
Tensor
*
out
=
param
.
Out
();
out
->
mutable_data
<
float
>
();
const
Tensor
x_matrix
=
const
Tensor
x_matrix
=
input_x
->
dims
().
size
()
>
2
input_x
->
dims
().
size
()
>
2
?
framework
::
ReshapeToMatrix
(
*
input_x
,
param
.
XNumColDims
())
?
framework
::
ReshapeToMatrix
(
*
input_x
,
param
.
XNumColDims
())
...
@@ -71,15 +71,21 @@ void MulCompute(const MulParam<CPU> ¶m) {
...
@@ -71,15 +71,21 @@ void MulCompute(const MulParam<CPU> ¶m) {
if
(
out_dim
.
size
()
!=
2
)
{
if
(
out_dim
.
size
()
!=
2
)
{
out
->
Resize
({
x_matrix
.
dims
()[
0
],
y_matrix
.
dims
()[
1
]});
out
->
Resize
({
x_matrix
.
dims
()[
0
],
y_matrix
.
dims
()[
1
]});
}
}
math
::
matmul
<
float
>
(
x_matrix
,
false
,
y_matrix
,
false
,
static_cast
<
float
>
(
1
),
if
(
param
.
InputX
()
->
type
()
==
typeid
(
int8_t
))
{
out
,
static_cast
<
float
>
(
0
));
out
->
mutable_data
<
int32_t
>
();
math
::
matmul
<
int8_t
>
(
x_matrix
,
false
,
y_matrix
,
false
,
static_cast
<
int8_t
>
(
1
),
out
,
static_cast
<
int8_t
>
(
0
));
}
else
{
out
->
mutable_data
<
float
>
();
math
::
matmul
<
float
>
(
x_matrix
,
false
,
y_matrix
,
false
,
static_cast
<
float
>
(
1
),
out
,
static_cast
<
float
>
(
0
));
}
if
(
out_dim
.
size
()
!=
2
)
{
if
(
out_dim
.
size
()
!=
2
)
{
out
->
Resize
(
out_dim
);
out
->
Resize
(
out_dim
);
}
}
}
}
template
class
MulKernel
<
CPU
,
float
>;
}
// namespace operators
}
// namespace operators
}
// namespace paddle_mobile
}
// namespace paddle_mobile
...
...
src/operators/math/gemm.h
浏览文件 @
52e13225
...
@@ -13,7 +13,6 @@ See the License for the specific language governing permissions and
...
@@ -13,7 +13,6 @@ See the License for the specific language governing permissions and
limitations under the License. */
limitations under the License. */
#pragma once
#pragma once
#include <stdint-gcc.h>
#include <string>
#include <string>
#include "common/log.h"
#include "common/log.h"
...
...
src/operators/math/gemm_int8.cpp
浏览文件 @
52e13225
此差异已折叠。
点击以展开。
test/operators/test_mul_op.cpp
浏览文件 @
52e13225
...
@@ -12,80 +12,80 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
...
@@ -12,80 +12,80 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
See the License for the specific language governing permissions and
limitations under the License. */
limitations under the License. */
#include "../test_helper.h"
#include "../test_include.h"
#include "../test_include.h"
#include "operators/mul_op.h"
#include "operators/mul_op.h"
int
main
()
{
#define a(i, j) a[(i)*lda + (j)]
paddle_mobile
::
Loader
<
paddle_mobile
::
CPU
>
loader
;
#define b(i, j) b[(i)*ldb + (j)]
auto
program
=
loader
.
Load
(
g_resnet
);
#define c(i, j) c[(i)*ldc + (j)]
PADDLE_MOBILE_ENFORCE
(
program
.
originProgram
!=
nullptr
,
"program file read fail"
);
namespace
paddle_mobile
{
using
framework
::
AttributeMap
;
Executor4Test
<
paddle_mobile
::
CPU
,
using
framework
::
DDim
;
paddle_mobile
::
operators
::
MulOp
<
paddle_mobile
::
CPU
,
float
>>
using
framework
::
Scope
;
executor
(
program
,
"mul"
);
using
framework
::
make_ddim
;
template
<
typename
I
,
typename
O
>
// 1. input_tensors;
int
TestMulOP
()
{
vector
<
Tensor
>
input_tensors
;
int32_t
m
=
1024
;
int32_t
n
=
1024
;
Tensor
input1
;
int32_t
k
=
1024
;
auto
input1_data
=
CreateInput
<
float
>
(
&
input1
,
{
3
,
2
,
1
,
1
},
0
,
1
);
int32_t
lda
=
k
;
input_tensors
.
push_back
(
input1
);
int32_t
ldb
=
n
;
Tensor
input2
;
int32_t
ldc
=
n
;
auto
input2_data
=
CreateInput
<
float
>
(
&
input2
,
{
2
,
3
},
0
,
1
);
DDim
inputA_shape
=
make_ddim
({
m
,
k
});
input_tensors
.
push_back
(
input2
);
DDim
inputB_shape
=
make_ddim
({
k
,
n
});
VariableNameMap
inputs
;
// 2. input_names
VariableNameMap
outputs
;
vector
<
string
>
input_names
({
auto
scope
=
std
::
make_shared
<
Scope
>
();
"pool2d_0.tmp_0"
,
inputs
[
"X"
]
=
std
::
vector
<
std
::
string
>
({
"inputA"
});
"fc_0.w_0"
,
inputs
[
"Y"
]
=
std
::
vector
<
std
::
string
>
({
"inputB"
});
});
outputs
[
"Out"
]
=
std
::
vector
<
std
::
string
>
({
"output"
});
// 3. output_names
auto
inputA_var
=
scope
.
get
()
->
Var
(
"inputA"
);
vector
<
string
>
output_names
({
"fc_0.tmp_0"
});
auto
inputA
=
inputA_var
->
template
GetMutable
<
framework
::
LoDTensor
>();
SetupTensor
<
I
>
(
inputA
,
inputA_shape
,
-
127
,
127
);
// 4. out_dims;
auto
inputB_var
=
scope
.
get
()
->
Var
(
"inputB"
);
vector
<
DDim
>
out_ddims
;
auto
inputB
=
inputB_var
->
template
GetMutable
<
framework
::
LoDTensor
>();
auto
out_ddim
=
paddle_mobile
::
framework
::
make_ddim
({
3
,
3
});
SetupTensor
<
I
>
(
inputB
,
inputB_shape
,
-
127
,
127
);
out_ddims
.
push_back
(
out_ddim
);
auto
output_var
=
scope
.
get
()
->
Var
(
"output"
);
auto
output
=
executor
.
Predict
<
LoDTensor
>
(
input_tensors
,
input_names
,
AttributeMap
attrs
;
output_names
,
out_ddims
);
attrs
[
"x_num_col_dims"
].
Set
<
int
>
(
1
);
attrs
[
"y_num_col_dims"
].
Set
<
int
>
(
1
);
auto
output0_data
=
output
[
0
]
->
data
<
float
>
();
auto
*
op
=
new
operators
::
MulOp
<
CPU
,
float
>
(
"mul"
,
inputs
,
outputs
,
attrs
,
scope
);
auto
dim_1
=
input1
.
numel
()
/
input1
.
dims
()[
0
];
op
->
InferShape
();
DLOG
<<
" input1 : "
;
op
->
Run
();
for
(
int
i
=
0
;
i
<
input1
.
dims
()[
0
];
++
i
)
{
auto
output
=
output_var
->
template
Get
<
framework
::
LoDTensor
>();
for
(
int
j
=
0
;
j
<
dim_1
;
++
j
)
{
const
O
*
output_data
=
output
->
data
<
O
>
();
DLOGF
(
"%f "
,
input1_data
[
i
*
dim_1
+
j
]);
// compare
O
*
c
=
static_cast
<
O
*>
(
memory
::
Alloc
(
sizeof
(
O
)
*
m
*
n
));
I
*
a
=
inputA
->
data
<
I
>
();
I
*
b
=
inputB
->
data
<
I
>
();
for
(
int32_t
i
=
0
;
i
<
m
;
++
i
)
{
for
(
int32_t
j
=
0
;
j
<
n
;
++
j
)
{
O
r
=
0
;
for
(
int32_t
p
=
0
;
p
<
k
;
p
++
)
{
r
+=
static_cast
<
O
>
(
a
(
i
,
p
))
*
static_cast
<
O
>
(
b
(
p
,
j
));
}
c
(
i
,
j
)
=
r
;
}
}
DLOGF
(
"
\n
"
);
}
}
auto
dim_2
=
input2
.
numel
()
/
input2
.
dims
()[
0
];
for
(
int32_t
i
=
0
;
i
<
m
*
n
;
++
i
)
{
DLOG
<<
" input2 : "
;
PADDLE_MOBILE_ENFORCE
(
for
(
int
i
=
0
;
i
<
input2
.
dims
()[
0
];
++
i
)
{
output_data
[
i
]
==
c
[
i
],
"output[%d] = %d, output_cmp[%d] = %d"
,
i
,
for
(
int
j
=
0
;
j
<
dim_2
;
++
j
)
{
static_cast
<
int32_t
>
(
output_data
[
i
]),
i
,
static_cast
<
int32_t
>
(
c
[
i
]));
DLOGF
(
"%f "
,
input2_data
[
i
*
dim_2
+
j
]);
}
DLOGF
(
"
\n
"
);
}
auto
dim_output0
=
output
[
0
]
->
numel
()
/
output
[
0
]
->
dims
()[
0
];
DLOG
<<
" output : "
;
for
(
int
i
=
0
;
i
<
output
[
0
]
->
dims
()[
0
];
++
i
)
{
for
(
int
j
=
0
;
j
<
dim_output0
;
++
j
)
{
DLOGF
(
"%f "
,
output0_data
[
i
*
dim_2
+
j
]);
}
DLOGF
(
"
\n
"
);
}
}
DLOG
<<
"Run MulOp successfully!"
;
delete
op
;
return
0
;
}
}
// namespace paddle_mobile
/// output (3,3)
int
main
()
{
DLOG
<<
"output memory size : "
<<
output
[
0
]
->
memory_size
();
paddle_mobile
::
TestMulOP
<
int8_t
,
int32_t
>
();
DLOG
<<
"output numel : "
<<
output
[
0
]
->
numel
();
paddle_mobile
::
TestMulOP
<
float
,
float
>
();
DLOG
<<
input1_data
[
0
]
<<
" x "
<<
input2_data
[
0
]
<<
" + "
<<
input1_data
[
1
]
<<
" x "
<<
input2_data
[
0
+
3
]
<<
" = "
<<
output0_data
[
0
];
return
0
;
return
0
;
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录