Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
95851116
P
Paddle
项目概览
Crayon鑫
/
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看板
提交
95851116
编写于
7月 11, 2017
作者:
Q
qijun
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add simple add_op_functor
上级
d6f7c353
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
107 addition
and
9 deletion
+107
-9
paddle/framework/ddim.cc
paddle/framework/ddim.cc
+12
-0
paddle/framework/ddim.h
paddle/framework/ddim.h
+1
-7
paddle/framework/tensor.h
paddle/framework/tensor.h
+45
-2
paddle/framework/tensor_types.h
paddle/framework/tensor_types.h
+14
-0
paddle/operators/add_op_functor.h
paddle/operators/add_op_functor.h
+35
-0
未找到文件。
paddle/framework/ddim.cc
浏览文件 @
95851116
#include "paddle/framework/ddim.h"
#include "paddle/framework/enforce.h"
namespace
paddle
{
namespace
framework
{
...
...
@@ -220,5 +221,16 @@ std::ostream& operator<<(std::ostream& os, const DDim& ddim) {
return
os
;
}
template
<
int
NDIMS
>
Eigen
::
DSizes
<
Eigen
::
DenseIndex
,
NDIMS
>
ToEigenDSizes
(
DDim
dims
)
const
{
int
rank
=
paddle
::
framework
::
arity
(
dims
);
PADDLE_ENFORCE
(
rank
==
NDIMS
,
"DDim and NDIMS must be same"
)
Eigen
::
DSizes
<
Eigen
::
DenseIndex
,
NDIMS
>
dsizes
;
for
(
int
d
=
0
;
d
<
paddle
::
framework
::
arity
(
dims
);
d
++
)
{
dsizes
[
d
]
=
dims
[
d
];
}
return
dsizes
;
}
}
// namespace framework
}
// namespace paddle
paddle/framework/ddim.h
浏览文件 @
95851116
...
...
@@ -93,13 +93,7 @@ int arity(const DDim& ddim);
std
::
ostream
&
operator
<<
(
std
::
ostream
&
,
const
DDim
&
);
template
<
int
NDIMS
>
Eigen
::
DSizes
<
Eigen
::
DenseIndex
,
NDIMS
>
ToEigenDSizes
(
DDim
dims
)
const
{
Eigen
::
DSizes
<
Eigen
::
DenseIndex
,
NDIMS
>
dsizes
;
for
(
int
d
=
0
;
d
<
paddle
::
framework
::
arity
(
dims
);
d
++
)
{
dsizes
[
d
]
=
dims
[
d
];
}
return
dsizes
;
}
Eigen
::
DSizes
<
Eigen
::
DenseIndex
,
NDIMS
>
ToEigenDSizes
(
DDim
dims
)
const
;
}
// namespace framework
}
// namespace paddle
...
...
paddle/framework/tensor.h
浏览文件 @
95851116
...
...
@@ -57,18 +57,61 @@ class Tensor {
DDim
dim
()
const
{
return
dims_
;
}
size_t
NumElements
()
const
{
return
product
(
dims_
);
}
template
<
typename
T
,
size_t
NDIMS
>
typename
TTypes
<
T
,
NDIMS
>::
Tensor
Tensor
::
shaped
(
DDim
new_dims
)
{
Eigen
::
array
<
Eigen
::
DenseIndex
,
NDIMS
>
dims
=
paddle
::
framework
::
ToEigenDSizes
(
new_dims
);
return
typename
TTypes
<
T
,
NDIMS
>::
Tensor
(
data
<
T
>
(),
dims
);
}
template
<
typename
T
,
size_t
NDIMS
>
typename
TTypes
<
T
,
NDIMS
>::
Constant
Tensor
Tensor
::
tensor
()
{
typename
TTypes
<
T
,
NDIMS
>::
Tensor
Tensor
::
tensor
()
{
return
typename
TTypes
<
T
,
NDIMS
>::
Tensor
(
data
<
T
>
(),
paddle
::
framework
::
ToEigenDSizes
<
NDIMS
>
(
dims_
));
}
// flat to rank = 1
template
<
typename
T
>
typename
TTypes
<
T
>::
Flat
flat
()
{
return
shaped
<
T
,
1
>
({
NumElements
()});
}
// 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
Tensor
::
tensor
()
{
typename
TTypes
<
T
,
NDIMS
>::
ConstantTensor
Tensor
::
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
>
({
NumElements
()});
}
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
>
();
}
private:
// Placeholder hides type T, so it doesn't appear as a template
// parameter of Variable.
...
...
paddle/framework/tensor_types.h
浏览文件 @
95851116
/* 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"
...
...
paddle/operators/add_op_functor.h
0 → 100644
浏览文件 @
95851116
/* 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/framework/tensor_types.h"
#include "unsupported/Eigen/CXX11/Tensor"
namespace
paddle
{
namespace
operators
{
namespace
functor
{
template
<
typename
Device
,
typename
T
>
struct
Add
{
void
Operator
()(
const
Device
&
d
,
typename
TTypes
<
T
>::
ConstTensor
input1
,
typename
TTypes
<
T
>::
ConstTensor
input2
,
typename
TTypes
<
T
>::
Tensor
output
)
{
output
.
device
(
d
)
=
input1
+
input2
;
}
};
}
// namespace functor
}
// namespace operators
}
// namespace paddle
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录