Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
0a13d3c6
P
Paddle
项目概览
机器未来
/
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看板
提交
0a13d3c6
编写于
5月 08, 2018
作者:
Y
Yu Yang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Move MatMul to blas_impl.h
Rename MatDim to MatDescriptor
上级
3dd01823
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
35 addition
and
26 deletion
+35
-26
paddle/fluid/operators/math/blas.cc
paddle/fluid/operators/math/blas.cc
+3
-2
paddle/fluid/operators/math/blas.h
paddle/fluid/operators/math/blas.h
+6
-23
paddle/fluid/operators/math/blas_impl.h
paddle/fluid/operators/math/blas_impl.h
+25
-0
paddle/fluid/operators/matmul_op.h
paddle/fluid/operators/matmul_op.h
+1
-1
未找到文件。
paddle/fluid/operators/math/blas.cc
浏览文件 @
0a13d3c6
...
@@ -18,8 +18,9 @@
...
@@ -18,8 +18,9 @@
namespace
paddle
{
namespace
paddle
{
namespace
operators
{
namespace
operators
{
namespace
math
{
namespace
math
{
MatDim
GetMatDim
(
const
framework
::
DDim
&
dim
,
int
num_flatten_cols
,
bool
trans
)
{
MatDescriptor
GetMatDim
(
const
framework
::
DDim
&
dim
,
int
num_flatten_cols
,
MatDim
retv
;
bool
trans
)
{
MatDescriptor
retv
;
if
(
num_flatten_cols
>
1
)
{
if
(
num_flatten_cols
>
1
)
{
auto
flatten_dim
=
framework
::
flatten_to_2d
(
dim
,
num_flatten_cols
);
auto
flatten_dim
=
framework
::
flatten_to_2d
(
dim
,
num_flatten_cols
);
retv
.
height_
=
flatten_dim
[
0
];
retv
.
height_
=
flatten_dim
[
0
];
...
...
paddle/fluid/operators/math/blas.h
浏览文件 @
0a13d3c6
...
@@ -46,7 +46,7 @@ namespace paddle {
...
@@ -46,7 +46,7 @@ namespace paddle {
namespace
operators
{
namespace
operators
{
namespace
math
{
namespace
math
{
struct
MatD
im
{
struct
MatD
escriptor
{
int64_t
height_
;
int64_t
height_
;
int64_t
width_
;
int64_t
width_
;
int64_t
stride_
{
0
};
int64_t
stride_
{
0
};
...
@@ -54,8 +54,8 @@ struct MatDim {
...
@@ -54,8 +54,8 @@ struct MatDim {
bool
trans_
;
bool
trans_
;
};
};
extern
MatD
im
GetMatDim
(
const
framework
::
DDim
&
tensor
,
int
num_flatten_cols
,
extern
MatD
escriptor
GetMatDim
(
const
framework
::
DDim
&
tensor
,
bool
trans
);
int
num_flatten_cols
,
bool
trans
);
template
<
typename
DeviceContext
>
template
<
typename
DeviceContext
>
class
Blas
{
class
Blas
{
...
@@ -102,26 +102,9 @@ class Blas {
...
@@ -102,26 +102,9 @@ class Blas {
int
batchCount
,
int64_t
strideA
,
int64_t
strideB
)
const
;
int
batchCount
,
int64_t
strideA
,
int64_t
strideB
)
const
;
template
<
typename
T
>
template
<
typename
T
>
void
MatMul
(
const
framework
::
Tensor
&
mat_a
,
const
MatDim
&
dim_a
,
void
MatMul
(
const
framework
::
Tensor
&
mat_a
,
const
MatDescriptor
&
dim_a
,
const
framework
::
Tensor
&
mat_b
,
const
MatDim
&
dim_b
,
T
alpha
,
const
framework
::
Tensor
&
mat_b
,
const
MatDescriptor
&
dim_b
,
framework
::
Tensor
*
mat_out
,
T
beta
)
const
{
T
alpha
,
framework
::
Tensor
*
mat_out
,
T
beta
)
const
;
PADDLE_ENFORCE_EQ
(
dim_a
.
width_
,
dim_b
.
height_
);
CBLAS_TRANSPOSE
transA
=
!
dim_a
.
trans_
?
CblasNoTrans
:
CblasTrans
;
CBLAS_TRANSPOSE
transB
=
!
dim_b
.
trans_
?
CblasNoTrans
:
CblasTrans
;
if
(
dim_a
.
batch_size_
==
0
&&
dim_b
.
batch_size_
==
0
)
{
this
->
template
GEMM
<
T
>(
transA
,
transB
,
dim_a
.
height_
,
dim_b
.
width_
,
dim_a
.
width_
,
alpha
,
mat_a
.
data
<
T
>
(),
mat_b
.
data
<
T
>
(),
beta
,
mat_out
->
data
<
T
>
());
}
else
{
PADDLE_ENFORCE
(
dim_a
.
batch_size_
==
dim_b
.
batch_size_
||
dim_a
.
batch_size_
==
0
||
dim_b
.
batch_size_
==
0
);
this
->
template
BatchedGEMM
<
T
>(
transA
,
transB
,
dim_a
.
height_
,
dim_b
.
width_
,
dim_a
.
width_
,
alpha
,
mat_a
.
data
<
T
>
(),
mat_b
.
data
<
T
>
(),
beta
,
mat_out
->
data
<
T
>
(),
dim_a
.
batch_size_
==
0
?
dim_b
.
batch_size_
:
dim_a
.
batch_size_
,
dim_a
.
stride_
,
dim_b
.
stride_
);
}
}
private:
private:
const
DeviceContext
&
context_
;
const
DeviceContext
&
context_
;
...
...
paddle/fluid/operators/math/blas_impl.h
浏览文件 @
0a13d3c6
...
@@ -180,6 +180,31 @@ void Blas<platform::CPUDeviceContext>::BatchedGEMM(
...
@@ -180,6 +180,31 @@ void Blas<platform::CPUDeviceContext>::BatchedGEMM(
#endif
#endif
}
}
template
<
typename
DeviceContext
>
template
<
typename
T
>
void
Blas
<
DeviceContext
>::
MatMul
(
const
framework
::
Tensor
&
mat_a
,
const
MatDescriptor
&
dim_a
,
const
framework
::
Tensor
&
mat_b
,
const
MatDescriptor
&
dim_b
,
T
alpha
,
framework
::
Tensor
*
mat_out
,
T
beta
)
const
{
PADDLE_ENFORCE_EQ
(
dim_a
.
width_
,
dim_b
.
height_
);
CBLAS_TRANSPOSE
transA
=
!
dim_a
.
trans_
?
CblasNoTrans
:
CblasTrans
;
CBLAS_TRANSPOSE
transB
=
!
dim_b
.
trans_
?
CblasNoTrans
:
CblasTrans
;
if
(
dim_a
.
batch_size_
==
0
&&
dim_b
.
batch_size_
==
0
)
{
this
->
template
GEMM
<
T
>(
transA
,
transB
,
dim_a
.
height_
,
dim_b
.
width_
,
dim_a
.
width_
,
alpha
,
mat_a
.
data
<
T
>
(),
mat_b
.
data
<
T
>
(),
beta
,
mat_out
->
data
<
T
>
());
}
else
{
PADDLE_ENFORCE
(
dim_a
.
batch_size_
==
dim_b
.
batch_size_
||
dim_a
.
batch_size_
==
0
||
dim_b
.
batch_size_
==
0
);
this
->
template
BatchedGEMM
<
T
>(
transA
,
transB
,
dim_a
.
height_
,
dim_b
.
width_
,
dim_a
.
width_
,
alpha
,
mat_a
.
data
<
T
>
(),
mat_b
.
data
<
T
>
(),
beta
,
mat_out
->
data
<
T
>
(),
dim_a
.
batch_size_
==
0
?
dim_b
.
batch_size_
:
dim_a
.
batch_size_
,
dim_a
.
stride_
,
dim_b
.
stride_
);
}
}
}
// namespace math
}
// namespace math
}
// namespace operators
}
// namespace operators
}
// namespace paddle
}
// namespace paddle
paddle/fluid/operators/matmul_op.h
浏览文件 @
0a13d3c6
...
@@ -91,7 +91,7 @@ inline framework::Tensor CombineBatchAndN(const DeviceContext& context,
...
@@ -91,7 +91,7 @@ inline framework::Tensor CombineBatchAndN(const DeviceContext& context,
}
}
inline
void
NormalizeTensorShape
(
framework
::
Tensor
*
x
,
inline
void
NormalizeTensorShape
(
framework
::
Tensor
*
x
,
const
math
::
MatD
im
&
mat_dim_x
)
{
const
math
::
MatD
escriptor
&
mat_dim_x
)
{
int64_t
h
,
w
;
int64_t
h
,
w
;
h
=
mat_dim_x
.
height_
;
h
=
mat_dim_x
.
height_
;
w
=
mat_dim_x
.
width_
;
w
=
mat_dim_x
.
width_
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录