Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
a9c18241
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
a9c18241
编写于
11月 05, 2018
作者:
T
tensor-tang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refine jit vmul code supporting multiple of 2
上级
61fdc38e
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
34 addition
and
15 deletion
+34
-15
paddle/fluid/operators/math/jit_code.cc
paddle/fluid/operators/math/jit_code.cc
+29
-8
paddle/fluid/operators/math/jit_code.h
paddle/fluid/operators/math/jit_code.h
+4
-6
paddle/fluid/operators/math/jit_kernel_test.cc
paddle/fluid/operators/math/jit_kernel_test.cc
+1
-1
未找到文件。
paddle/fluid/operators/math/jit_code.cc
浏览文件 @
a9c18241
...
...
@@ -25,10 +25,10 @@ namespace gen {
using
namespace
platform
::
jit
;
// NOLINT
bool
VMulJitCode
::
init
(
int
d
)
{
//
TODO(TJ): maybe one AVX is enough, AVX above would slow down freq
//
try more with avx2 or avx512
if
(
MayIUse
(
avx
)
||
MayIUse
(
avx2
)
)
{
return
d
%
AVX_FLOAT_BLOCK
==
0
;
//
It's not necessary to use avx512 since it would slow down the frequency
//
and this kernel is not compute bound.
if
(
MayIUse
(
avx
))
{
return
d
%
2
==
0
;
}
else
{
return
false
;
}
...
...
@@ -36,12 +36,33 @@ bool VMulJitCode::init(int d) {
void
VMulJitCode
::
generate
()
{
// do not need push stack, and do not need save avx512reg if do not use avx512
int
stride
=
sizeof
(
float
)
*
AVX_FLOAT_BLOCK
;
int
offset
=
0
;
for
(
int
i
=
0
;
i
<
num_
/
AVX_FLOAT_BLOCK
;
++
i
)
{
vmovups
(
ymm_src1
,
ptr
[
param1
+
i
*
stride
]);
vmovups
(
ymm_src2
,
ptr
[
param2
+
i
*
stride
]);
vmovups
(
ymm_src1
,
ptr
[
param1
+
offset
]);
vmovups
(
ymm_src2
,
ptr
[
param2
+
offset
]);
vmulps
(
ymm_dst
,
ymm_src1
,
ymm_src2
);
vmovups
(
ptr
[
param3
+
stride
*
i
],
ymm_dst
);
vmovups
(
ptr
[
param3
+
offset
],
ymm_dst
);
offset
+=
sizeof
(
float
)
*
AVX_FLOAT_BLOCK
;
}
int
rest
=
num_
%
AVX_FLOAT_BLOCK
;
if
(
rest
>=
4
)
{
vmovups
(
xmm_src1
,
ptr
[
param1
+
offset
]);
vmovups
(
xmm_src2
,
ptr
[
param2
+
offset
]);
vmulps
(
xmm_dst
,
xmm_src1
,
xmm_src2
);
vmovups
(
ptr
[
param3
+
offset
],
xmm_dst
);
offset
+=
sizeof
(
float
)
*
4
;
rest
-=
4
;
}
if
(
rest
>=
2
)
{
mov
(
tmp
,
qword
[
param1
+
offset
]);
vmovq
(
xmm_src1
,
tmp
);
mov
(
tmp
,
qword
[
param2
+
offset
]);
vmovq
(
xmm_src2
,
tmp
);
vmulps
(
xmm_dst
,
xmm_src1
,
xmm_src2
);
vmovq
(
tmp
,
xmm_dst
);
mov
(
ptr
[
param3
+
offset
],
tmp
);
offset
+=
sizeof
(
float
)
*
2
;
rest
-=
2
;
}
ret
();
}
...
...
paddle/fluid/operators/math/jit_code.h
浏览文件 @
a9c18241
...
...
@@ -43,17 +43,15 @@ class VMulJitCode : public JitCode {
reg64_t
param1
{
abi_param1
};
reg64_t
param2
{
abi_param2
};
reg64_t
param3
{
abi_param3
};
reg64_t
tmp
=
rax
;
xmm_t
xmm_src1
=
xmm_t
(
0
);
ymm_t
ymm_src1
=
ymm_t
(
0
);
zmm_t
zmm_src1
=
zmm_t
(
0
);
xmm_t
xmm_src2
=
xmm_t
(
1
);
ymm_t
ymm_src2
=
ymm_t
(
1
);
zmm_t
zmm_src2
=
zmm_t
(
1
);
xmm_t
xmm_dst
=
xmm_t
(
2
);
ymm_t
ymm_src1
=
ymm_t
(
0
);
ymm_t
ymm_src2
=
ymm_t
(
1
);
ymm_t
ymm_dst
=
ymm_t
(
2
);
zmm_t
zmm_dst
=
zmm_t
(
2
);
};
}
// namespace gen
...
...
paddle/fluid/operators/math/jit_kernel_test.cc
浏览文件 @
a9c18241
...
...
@@ -578,7 +578,7 @@ void vmul_mkl(const int n, const float* x, const float* y, float* z) {
TEST
(
JitKernel
,
vmul
)
{
namespace
jit
=
paddle
::
operators
::
math
::
jitkernel
;
for
(
int
d
:
{
7
,
8
,
15
,
16
,
30
,
256
,
512
,
1000
,
1024
})
{
for
(
int
d
:
{
7
,
8
,
15
,
16
,
20
,
30
,
256
,
512
,
1000
,
1024
})
{
std
::
vector
<
float
>
x
(
d
),
y
(
d
);
std
::
vector
<
float
>
zref
(
d
),
ztgt
(
d
);
RandomVec
<
float
>
(
d
,
x
.
data
());
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录