Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
a01ccc26
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看板
未验证
提交
a01ccc26
编写于
6月 11, 2020
作者:
W
Wilber
提交者:
GitHub
6月 11, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix mul kernel error. test=develop (#3774)
上级
6299a90a
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
12 addition
and
49 deletion
+12
-49
lite/kernels/cuda/CMakeLists.txt
lite/kernels/cuda/CMakeLists.txt
+1
-1
lite/kernels/cuda/mul_compute.h
lite/kernels/cuda/mul_compute.h
+11
-47
lite/kernels/cuda/mul_compute_test.cc
lite/kernels/cuda/mul_compute_test.cc
+0
-1
未找到文件。
lite/kernels/cuda/CMakeLists.txt
浏览文件 @
a01ccc26
...
...
@@ -5,7 +5,7 @@ endif()
message
(
STATUS
"compile with lite CUDA kernels"
)
# basic kernels
add_kernel
(
mul_compute_cuda CUDA basic SRCS mul_compute.cc DEPS
${
lite_kernel_deps
}
context
)
add_kernel
(
mul_compute_cuda CUDA basic SRCS mul_compute.cc DEPS
${
lite_kernel_deps
}
${
math_cuda
}
)
add_kernel
(
search_group_padding_compute_cuda CUDA basic SRCS search_group_padding_compute.cu DEPS
${
lite_kernel_deps
}
)
add_kernel
(
io_copy_compute_cuda CUDA basic SRCS io_copy_compute.cc DEPS
${
lite_kernel_deps
}
)
add_kernel
(
leaky_relu_compute_cuda CUDA basic SRCS leaky_relu_compute.cu DEPS
${
lite_kernel_deps
}
)
...
...
lite/kernels/cuda/mul_compute.h
浏览文件 @
a01ccc26
...
...
@@ -13,10 +13,9 @@
// limitations under the License.
#pragma once
#include
"lite/backends/cuda/blas.h"
#include "lite/
core/context
.h"
#include
<memory>
#include "lite/
backends/cuda/math/gemm
.h"
#include "lite/core/kernel.h"
#include "lite/core/types.h"
#include "lite/operators/op_params.h"
namespace
paddle
{
...
...
@@ -24,56 +23,17 @@ namespace lite {
namespace
kernels
{
namespace
cuda
{
template
<
typename
T
>
void
mul_compute
(
const
lite
::
cuda
::
Blas
<
float
>&
blas
,
const
T
*
x
,
int
x_h
,
int
x_w
,
const
T
*
y
,
int
y_h
,
int
y_w
,
T
*
out
)
{
float
alpha
=
1.0
;
float
beta
=
0.0
;
/*
blas.sgemm(CUBLAS_OP_N,
CUBLAS_OP_N,
x_h,
y_w,
x_w,
&alpha,
x,
x_w,
y,
y_w,
&beta,
out,
x_h);
*/
blas
.
sgemm
(
CUBLAS_OP_N
,
CUBLAS_OP_N
,
y_w
,
x_h
,
y_h
,
&
alpha
,
y
,
y_w
,
x
,
x_w
,
&
beta
,
out
,
y_w
);
}
class
MulCompute
:
public
KernelLite
<
TARGET
(
kCUDA
),
PRECISION
(
kFloat
)
>
{
public:
using
param_t
=
operators
::
MulParam
;
void
PrepareForRun
()
override
{
gemm_impl_
.
reset
(
new
lite
::
cuda
::
math
::
Gemm
<
float
,
float
>
);
}
void
Run
()
override
{
CHECK
(
ctx_
)
<<
"running context should be set first"
;
auto
&
context
=
this
->
ctx_
->
template
As
<
CUDAContext
>();
CHECK
(
context
.
cublas_fp32
())
<<
"blas should init first"
;
auto
&
blas
=
*
context
.
cublas_fp32
();
auto
&
param
=
this
->
Param
<
param_t
>
();
const
auto
*
x_data
=
param
.
x
->
data
<
float
>
();
...
...
@@ -94,10 +54,14 @@ class MulCompute : public KernelLite<TARGET(kCUDA), PRECISION(kFloat)> {
.
production
());
CHECK_EQ
(
x_w
,
y_h
)
<<
"x_w must be equal with y_h"
;
mul_compute
<
float
>
(
blas
,
x_data
,
x_h
,
x_w
,
y_data
,
y_h
,
y_w
,
out_data
);
CHECK
(
gemm_impl_
->
init
(
false
,
false
,
x_h
,
y_w
,
x_w
,
&
context
));
gemm_impl_
->
run
(
1.0
f
,
0.0
f
,
x_data
,
y_data
,
out_data
,
&
context
);
}
virtual
~
MulCompute
()
=
default
;
private:
std
::
unique_ptr
<
lite
::
cuda
::
math
::
Gemm
<
float
,
float
>>
gemm_impl_
{
nullptr
};
};
}
// namespace cuda
...
...
lite/kernels/cuda/mul_compute_test.cc
浏览文件 @
a01ccc26
...
...
@@ -27,7 +27,6 @@ TEST(mul_compute, normal) {
MulCompute
mul_kernel
;
std
::
unique_ptr
<
KernelContext
>
ctx
(
new
KernelContext
);
auto
&
context
=
ctx
->
As
<
CUDAContext
>
();
context
.
InitOnce
();
Tensor
x
,
y
,
out
,
x_cpu
,
y_cpu
,
out_cpu
;
int
x_h
=
2
,
x_w_y_h
=
3
,
y_w
=
4
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录