Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
csdn_franckjun
Paddle
提交
642d3c46
P
Paddle
项目概览
csdn_franckjun
/
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
642d3c46
编写于
7月 18, 2017
作者:
Y
Yi Wang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactorize Tensor to Eigen convesion
上级
84a0d6d8
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
103 addition
and
138 deletion
+103
-138
paddle/framework/ddim.h
paddle/framework/ddim.h
+0
-11
paddle/framework/eigen.h
paddle/framework/eigen.h
+103
-0
paddle/framework/tensor.h
paddle/framework/tensor.h
+0
-60
paddle/framework/tensor_types.h
paddle/framework/tensor_types.h
+0
-67
未找到文件。
paddle/framework/ddim.h
浏览文件 @
642d3c46
...
@@ -119,17 +119,6 @@ int arity(const DDim& ddim);
...
@@ -119,17 +119,6 @@ int arity(const DDim& ddim);
std
::
ostream
&
operator
<<
(
std
::
ostream
&
,
const
DDim
&
);
std
::
ostream
&
operator
<<
(
std
::
ostream
&
,
const
DDim
&
);
template
<
int
NDIMS
>
Eigen
::
DSizes
<
Eigen
::
DenseIndex
,
NDIMS
>
ToEigenDSizes
(
const
DDim
&
dims
)
{
int
rank
=
arity
(
dims
);
PADDLE_ENFORCE
(
rank
==
NDIMS
,
"DDim and NDIMS must be same"
);
Eigen
::
DSizes
<
Eigen
::
DenseIndex
,
NDIMS
>
dsizes
;
for
(
int
d
=
0
;
d
<
rank
;
d
++
)
{
dsizes
[
d
]
=
dims
[
d
];
}
return
dsizes
;
}
}
// namespace framework
}
// namespace framework
}
// namespace paddle
}
// namespace paddle
...
...
paddle/framework/eigen.h
0 → 100644
浏览文件 @
642d3c46
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#pragma once
#include "paddle/platform/tensor.h"
#include "unsupported/Eigen/CXX11/Tensor"
namespace
paddle
{
namespace
framework
{
// EigenDim converts paddle::platform::DDim into Eigen::DSizes.
template
<
int
D
>
struct
EigenDim
{
typedef
Eigen
::
DSizes
<
Eigen
::
DenseIndex
,
D
>
Type
;
static
Type
From
(
const
DDim
&
dims
)
{
PADDLE_ENFORCE
(
arity
(
dims
)
==
D
,
"D must match arity(DDim)"
);
Type
ret
;
for
(
int
d
=
0
;
d
<
rank
;
d
++
)
{
ret
[
d
]
=
dims
[
d
];
}
return
ret
;
}
};
// Interpret paddle::platform::Tensor as EigenTensor and EigenConstTensor.
template
<
typename
T
,
size_t
D
,
typename
IndexType
=
Eigen
::
DenseIndex
>
struct
EigenTensor
{
using
Type
=
Eigen
::
TensorMap
<
Eigen
::
Tensor
<
T
,
D
,
Eigen
::
RowMajor
,
IndexType
>
,
Eigen
::
Aligned
>
;
using
ConstType
=
Eigen
::
TensorMap
<
Eigen
::
Tensor
<
const
T
,
D
,
Eigen
::
RowMajor
,
IndexType
>
,
Eigen
::
Aligned
>
ConstTensor
;
static
Type
From
(
Tensor
&
tensor
,
DDim
dims
)
{
return
Type
(
tensor
.
data
<
T
>
(),
EigenDim
<
D
>::
From
(
dims
));
}
static
Type
From
(
Tensor
&
tensor
)
{
return
From
(
tensor
,
tensor
.
dims_
);
}
static
ConstType
From
(
const
Tensor
&
tensor
,
DDim
dims
)
{
return
ConstType
(
tensor
.
data
<
T
>
(),
EigenDim
<
D
>::
From
(
dims
));
}
static
ConstType
From
(
const
Tensor
&
tensor
)
{
return
From
(
tensor
,
tensor
.
dims_
);
}
};
// Interpret paddle::platform::Tensor as EigenVecotr and EigenConstVector.
template
<
typename
T
,
typename
IndexType
=
Eigen
::
DenseIndex
>
struct
EigenVector
{
using
EigenVector
=
Eigen
::
TensorMap
<
Eigen
::
Tensor
<
T
,
1
,
Eigen
::
RowMajor
,
IndexType
>
,
Eigen
::
Aligned
>
;
using
EigenConstVector
=
Eigen
::
TensorMap
<
Eigen
::
Tensor
<
const
T
,
1
,
Eigen
::
RowMajor
,
IndexType
>
,
Eigen
::
Aligned
>
;
static
Type
From
(
Tensor
&
tensor
)
{
return
EigenTensor
<
T
,
1
>::
From
(
tensor
);
}
static
ConstType
From
(
const
Tensor
&
tensor
)
{
return
EigenTensor
<
T
,
1
>::
From
(
tensor
);
}
};
// Interpret paddle::platform::Tensor as EigenMatrix and EigenConstMatrix.
template
<
typename
T
,
typename
IndexType
=
Eigen
::
DenseIndex
>
struct
EigenMatrix
{
template
<
typename
T
,
typename
IndexType
=
Eigen
::
DenseIndex
>
using
EigenMatrix
=
Eigen
::
TensorMap
<
Eigen
::
Tensor
<
T
,
2
,
Eigen
::
RowMajor
,
IndexType
>
,
Eigen
::
Aligned
>
;
template
<
typename
T
,
typename
IndexType
=
Eigen
::
DenseIndex
>
using
EigenConstMatrix
=
Eigen
::
TensorMap
<
Eigen
::
Tensor
<
const
T
,
2
,
Eigen
::
RowMajor
,
IndexType
>
,
Eigen
::
Aligned
>
;
static
Type
From
(
Tensor
&
tensor
)
{
return
EigenTensor
<
T
,
2
>::
From
(
tensor
);
}
static
ConstType
From
(
const
Tensor
&
tensor
)
{
return
EigenTensor
<
T
,
2
>::
From
(
tensor
);
}
};
}
// namespace framework
}
// namespace paddle
paddle/framework/tensor.h
浏览文件 @
642d3c46
...
@@ -86,66 +86,6 @@ class Tensor {
...
@@ -86,66 +86,6 @@ class Tensor {
offset_
);
offset_
);
}
}
template
<
typename
T
,
size_t
NDIMS
>
typename
TTypes
<
T
,
NDIMS
>::
Tensor
shaped
(
DDim
new_dims
)
{
Eigen
::
array
<
Eigen
::
DenseIndex
,
NDIMS
>
dims
=
paddle
::
framework
::
ToEigenDSizes
<
NDIMS
>
(
new_dims
);
return
typename
TTypes
<
T
,
NDIMS
>::
Tensor
(
raw_data
<
T
>
(),
dims
);
}
template
<
typename
T
,
size_t
NDIMS
>
typename
TTypes
<
T
,
NDIMS
>::
Tensor
tensor
()
{
return
typename
TTypes
<
T
,
NDIMS
>::
Tensor
(
raw_data
<
T
>
(),
paddle
::
framework
::
ToEigenDSizes
<
NDIMS
>
(
dims_
));
}
// flat to rank = 1
template
<
typename
T
>
typename
TTypes
<
T
>::
Flat
flat
()
{
return
shaped
<
T
,
1
>
(
make_ddim
({
static_cast
<
int
>
(
product
(
dims_
))}));
}
// to TensorType Vec
template
<
typename
T
>
typename
TTypes
<
T
>::
Vec
vec
()
{
return
tensor
<
T
,
1
>
();
}
// to TensorType Matrix
template
<
typename
T
>
typename
TTypes
<
T
>::
Matrix
matrix
()
{
return
tensor
<
T
,
2
>
();
}
// const versions of all the methods above.
template
<
typename
T
,
size_t
NDIMS
>
typename
TTypes
<
T
,
NDIMS
>::
Tensor
shaped
(
DDim
new_dims
)
const
{
Eigen
::
array
<
Eigen
::
DenseIndex
,
NDIMS
>
dims
=
paddle
::
framework
::
ToEigenDSizes
<
NDIMS
>
(
new_dims
);
return
typename
TTypes
<
T
,
NDIMS
>::
Tensor
(
data
<
T
>
(),
dims
);
}
template
<
typename
T
,
size_t
NDIMS
>
typename
TTypes
<
T
,
NDIMS
>::
ConstantTensor
tensor
()
const
{
return
typename
TTypes
<
T
,
NDIMS
>::
Tensor
(
data
<
T
>
(),
paddle
::
framework
::
ToEigenDSizes
<
NDIMS
>
(
dims_
));
}
template
<
typename
T
>
typename
TTypes
<
T
>::
ConstFlat
flat
()
const
{
return
shaped
<
T
,
1
>
(
make_ddim
({
static_cast
<
int
>
(
product
(
dims_
))}));
}
template
<
typename
T
>
typename
TTypes
<
T
>::
ConstVec
vec
()
const
{
return
tensor
<
T
,
1
>
();
}
template
<
typename
T
>
typename
TTypes
<
T
>::
ConstMatrix
matrix
()
const
{
return
tensor
<
T
,
2
>
();
}
template
<
typename
T
>
template
<
typename
T
>
void
ShareDataFrom
(
const
Tensor
&
src
)
{
void
ShareDataFrom
(
const
Tensor
&
src
)
{
src
.
CheckDims
<
T
>
();
src
.
CheckDims
<
T
>
();
...
...
paddle/framework/tensor_types.h
已删除
100644 → 0
浏览文件 @
84a0d6d8
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#pragma once
#include "unsupported/Eigen/CXX11/Tensor"
namespace
paddle
{
namespace
framework
{
// Helper to define Tensor types given that the scalar is of type T.
template
<
typename
T
,
int
NDIMS
=
1
,
typename
IndexType
=
Eigen
::
DenseIndex
>
struct
TTypes
{
// Rank-<NDIMS> tensor of scalar type T.
typedef
Eigen
::
TensorMap
<
Eigen
::
Tensor
<
T
,
NDIMS
,
Eigen
::
RowMajor
,
IndexType
>
,
Eigen
::
Aligned
>
Tensor
;
typedef
Eigen
::
TensorMap
<
Eigen
::
Tensor
<
const
T
,
NDIMS
,
Eigen
::
RowMajor
,
IndexType
>
,
Eigen
::
Aligned
>
ConstTensor
;
// Scalar tensor (implemented as a rank-0 tensor) of scalar type T.
typedef
Eigen
::
TensorMap
<
Eigen
::
TensorFixedSize
<
T
,
Eigen
::
Sizes
<>
,
Eigen
::
RowMajor
,
IndexType
>
,
Eigen
::
Aligned
>
Scalar
;
typedef
Eigen
::
TensorMap
<
Eigen
::
TensorFixedSize
<
const
T
,
Eigen
::
Sizes
<>
,
Eigen
::
RowMajor
,
IndexType
>
,
Eigen
::
Aligned
>
ConstScalar
;
// Rank-1 tensor (vector) of scalar type T.
typedef
Eigen
::
TensorMap
<
Eigen
::
Tensor
<
T
,
1
,
Eigen
::
RowMajor
,
IndexType
>
,
Eigen
::
Aligned
>
Flat
;
typedef
Eigen
::
TensorMap
<
Eigen
::
Tensor
<
const
T
,
1
,
Eigen
::
RowMajor
,
IndexType
>
,
Eigen
::
Aligned
>
ConstFlat
;
typedef
Eigen
::
TensorMap
<
Eigen
::
Tensor
<
T
,
1
,
Eigen
::
RowMajor
,
IndexType
>
,
Eigen
::
Aligned
>
Vec
;
typedef
Eigen
::
TensorMap
<
Eigen
::
Tensor
<
const
T
,
1
,
Eigen
::
RowMajor
,
IndexType
>
,
Eigen
::
Aligned
>
ConstVec
;
// Rank-2 tensor (matrix) of scalar type T.
typedef
Eigen
::
TensorMap
<
Eigen
::
Tensor
<
T
,
2
,
Eigen
::
RowMajor
,
IndexType
>
,
Eigen
::
Aligned
>
Matrix
;
typedef
Eigen
::
TensorMap
<
Eigen
::
Tensor
<
const
T
,
2
,
Eigen
::
RowMajor
,
IndexType
>
,
Eigen
::
Aligned
>
ConstMatrix
;
};
}
// namespace framework
}
// namespace paddle
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录