Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
be24e5b3
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2302
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看板
未验证
提交
be24e5b3
编写于
7月 10, 2019
作者:
Z
Zeng Jinle
提交者:
GitHub
7月 10, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Clean unused code of dim and place (#18565)
* clean code of dim and place, test=develop * fix failed unittests, test=develop
上级
8869d7f7
变更
12
显示空白变更内容
内联
并排
Showing
12 changed file
with
14 addition
and
394 deletion
+14
-394
paddle/fluid/framework/ddim.cc
paddle/fluid/framework/ddim.cc
+0
-46
paddle/fluid/framework/ddim.h
paddle/fluid/framework/ddim.h
+0
-7
paddle/fluid/framework/ddim_test.cc
paddle/fluid/framework/ddim_test.cc
+2
-14
paddle/fluid/framework/details/CMakeLists.txt
paddle/fluid/framework/details/CMakeLists.txt
+1
-2
paddle/fluid/framework/dim.h
paddle/fluid/framework/dim.h
+0
-187
paddle/fluid/framework/dim_test.cu
paddle/fluid/framework/dim_test.cu
+10
-38
paddle/fluid/framework/unroll_array_ops.h
paddle/fluid/framework/unroll_array_ops.h
+0
-47
paddle/fluid/framework/unroll_array_ops_test.cc
paddle/fluid/framework/unroll_array_ops_test.cc
+0
-25
paddle/fluid/operators/hierarchical_sigmoid_op.h
paddle/fluid/operators/hierarchical_sigmoid_op.h
+1
-2
paddle/fluid/platform/place.cc
paddle/fluid/platform/place.cc
+0
-9
paddle/fluid/platform/place.h
paddle/fluid/platform/place.h
+0
-7
paddle/fluid/platform/place_test.cc
paddle/fluid/platform/place_test.cc
+0
-10
未找到文件。
paddle/fluid/framework/ddim.cc
浏览文件 @
be24e5b3
...
@@ -48,52 +48,6 @@ bool DDim::operator==(const DDim& d) const {
...
@@ -48,52 +48,6 @@ bool DDim::operator==(const DDim& d) const {
bool
DDim
::
operator
!=
(
const
DDim
&
d
)
const
{
return
!
(
*
this
==
d
);
}
bool
DDim
::
operator
!=
(
const
DDim
&
d
)
const
{
return
!
(
*
this
==
d
);
}
struct
DDimPlusVisitor
{
explicit
DDimPlusVisitor
(
const
int64_t
*
d1
,
const
int64_t
*
d2
)
:
d1_
(
d1
),
d2_
(
d2
)
{}
template
<
int
D
>
inline
void
operator
()(
Dim
<
D
>&
self
)
const
{
UnrollAdd
<
D
>::
Run
(
d1_
,
d2_
,
self
.
GetMutable
());
}
const
int64_t
*
d1_
;
const
int64_t
*
d2_
;
};
DDim
DDim
::
operator
+
(
const
DDim
&
d
)
const
{
PADDLE_ENFORCE
(
size
()
==
d
.
size
());
DDim
ret
;
ret
.
rank_
=
rank_
;
ret
.
apply_visitor
(
DDimPlusVisitor
(
Get
(),
d
.
Get
()));
return
ret
;
}
struct
DDimMulVisitor
{
explicit
DDimMulVisitor
(
const
int64_t
*
d1
,
const
int64_t
*
d2
)
:
d1_
(
d1
),
d2_
(
d2
)
{}
template
<
int
D
>
inline
void
operator
()(
Dim
<
D
>&
self
)
const
{
UnrollMul
<
D
>::
Run
(
d1_
,
d2_
,
self
.
GetMutable
());
}
const
int64_t
*
d1_
;
const
int64_t
*
d2_
;
};
DDim
DDim
::
operator
*
(
const
DDim
&
d
)
const
{
PADDLE_ENFORCE
(
size
()
==
d
.
size
());
DDim
ret
;
ret
.
rank_
=
rank_
;
ret
.
apply_visitor
(
DDimMulVisitor
(
Get
(),
d
.
Get
()));
return
ret
;
}
int64_t
get
(
const
DDim
&
ddim
,
int
idx
)
{
return
ddim
[
idx
];
}
void
set
(
DDim
&
ddim
,
int
idx
,
int
value
)
{
ddim
[
idx
]
=
value
;
}
// NOLINT
std
::
vector
<
int64_t
>
vectorize
(
const
DDim
&
ddim
)
{
std
::
vector
<
int64_t
>
vectorize
(
const
DDim
&
ddim
)
{
std
::
vector
<
int64_t
>
result
(
DDim
::
kMaxRank
);
std
::
vector
<
int64_t
>
result
(
DDim
::
kMaxRank
);
dynamic_dim_assign
(
ddim
.
Get
(),
result
.
data
(),
ddim
.
size
());
dynamic_dim_assign
(
ddim
.
Get
(),
result
.
data
(),
ddim
.
size
());
...
...
paddle/fluid/framework/ddim.h
浏览文件 @
be24e5b3
...
@@ -117,10 +117,6 @@ class DDim {
...
@@ -117,10 +117,6 @@ class DDim {
bool
operator
!=
(
const
DDim
&
d
)
const
;
bool
operator
!=
(
const
DDim
&
d
)
const
;
DDim
operator
+
(
const
DDim
&
d
)
const
;
DDim
operator
*
(
const
DDim
&
d
)
const
;
inline
const
int64_t
*
Get
()
const
{
return
dim_
.
Get
();
}
inline
const
int64_t
*
Get
()
const
{
return
dim_
.
Get
();
}
inline
int64_t
*
GetMutable
()
{
return
dim_
.
GetMutable
();
}
inline
int64_t
*
GetMutable
()
{
return
dim_
.
GetMutable
();
}
...
@@ -174,9 +170,6 @@ DDim make_ddim(const std::vector<int>& dims);
...
@@ -174,9 +170,6 @@ DDim make_ddim(const std::vector<int>& dims);
*/
*/
DDim
make_ddim
(
std
::
initializer_list
<
int64_t
>
dims
);
DDim
make_ddim
(
std
::
initializer_list
<
int64_t
>
dims
);
int64_t
get
(
const
DDim
&
dim
,
int
idx
);
void
set
(
DDim
&
dim
,
int
idx
,
int
val
);
// NOLINT
std
::
vector
<
int64_t
>
vectorize
(
const
DDim
&
ddim
);
std
::
vector
<
int64_t
>
vectorize
(
const
DDim
&
ddim
);
std
::
vector
<
int
>
vectorize2int
(
const
DDim
&
ddim
);
std
::
vector
<
int
>
vectorize2int
(
const
DDim
&
ddim
);
...
...
paddle/fluid/framework/ddim_test.cc
浏览文件 @
be24e5b3
...
@@ -34,8 +34,8 @@ TEST(DDim, Equality) {
...
@@ -34,8 +34,8 @@ TEST(DDim, Equality) {
// mutate a DDim
// mutate a DDim
ddim
[
1
]
=
2
;
ddim
[
1
]
=
2
;
EXPECT_EQ
(
ddim
[
1
],
2
);
EXPECT_EQ
(
ddim
[
1
],
2
);
paddle
::
framework
::
set
(
ddim
,
0
,
6
)
;
ddim
[
0
]
=
6
;
EXPECT_EQ
(
paddle
::
framework
::
get
(
ddim
,
0
)
,
6
);
EXPECT_EQ
(
ddim
[
0
]
,
6
);
// vectorize a DDim
// vectorize a DDim
std
::
vector
<
int64_t
>
res_vec
=
paddle
::
framework
::
vectorize
(
vddim
);
std
::
vector
<
int64_t
>
res_vec
=
paddle
::
framework
::
vectorize
(
vddim
);
...
@@ -48,18 +48,6 @@ TEST(DDim, Equality) {
...
@@ -48,18 +48,6 @@ TEST(DDim, Equality) {
EXPECT_EQ
(
res_vec
[
1
],
2
);
EXPECT_EQ
(
res_vec
[
1
],
2
);
EXPECT_EQ
(
res_vec
[
2
],
1
);
EXPECT_EQ
(
res_vec
[
2
],
1
);
// add two DDims
paddle
::
framework
::
DDim
ddim_sum
=
ddim
+
vddim
;
EXPECT_EQ
(
ddim_sum
[
0
],
15
);
EXPECT_EQ
(
ddim_sum
[
1
],
3
);
EXPECT_EQ
(
ddim_sum
[
2
],
10
);
// multiply two DDims
paddle
::
framework
::
DDim
ddim_mul
=
ddim
*
vddim
;
EXPECT_EQ
(
ddim_mul
[
0
],
54
);
EXPECT_EQ
(
ddim_mul
[
1
],
2
);
EXPECT_EQ
(
ddim_mul
[
2
],
25
);
// arity of a DDim
// arity of a DDim
EXPECT_EQ
(
paddle
::
framework
::
arity
(
ddim
),
3
);
EXPECT_EQ
(
paddle
::
framework
::
arity
(
ddim
),
3
);
EXPECT_EQ
(
ddim
.
size
(),
3
);
EXPECT_EQ
(
ddim
.
size
(),
3
);
...
...
paddle/fluid/framework/details/CMakeLists.txt
浏览文件 @
be24e5b3
...
@@ -94,5 +94,4 @@ cc_library(build_strategy SRCS build_strategy.cc DEPS
...
@@ -94,5 +94,4 @@ cc_library(build_strategy SRCS build_strategy.cc DEPS
fuse_relu_depthwise_conv_pass
fuse_relu_depthwise_conv_pass
memory_optimize_pass lock_free_optimize_pass
memory_optimize_pass lock_free_optimize_pass
alloc_continuous_space_for_grad_pass fuse_all_reduce_op_pass backward_optimizer_op_deps_pass
alloc_continuous_space_for_grad_pass fuse_all_reduce_op_pass backward_optimizer_op_deps_pass
fuse_adam_op_pass fuse_sgd_op_pass fuse_momentum_op_pass
fuse_adam_op_pass fuse_sgd_op_pass fuse_momentum_op_pass record_skip_memory_opt_vars_pass
)
record_skip_memory_opt_vars_pass
)
paddle/fluid/framework/dim.h
浏览文件 @
be24e5b3
...
@@ -45,10 +45,6 @@ class Dim : public Array<int64_t, D> {
...
@@ -45,10 +45,6 @@ class Dim : public Array<int64_t, D> {
HOSTDEVICE
explicit
Dim
(
int64_t
head
,
Args
...
args
)
HOSTDEVICE
explicit
Dim
(
int64_t
head
,
Args
...
args
)
:
BaseClass
(
head
,
args
...)
{}
:
BaseClass
(
head
,
args
...)
{}
/** Construct a Dim from a linear index and size. Uses Fortran order
* indexing. */
HOSTDEVICE
Dim
(
int64_t
idx
,
const
Dim
<
D
>&
size
);
/** Construct a Dim with each dimension set to the given index */
/** Construct a Dim with each dimension set to the given index */
HOSTDEVICE
explicit
Dim
(
int64_t
idx
)
{
this
->
Fill
(
idx
);
}
HOSTDEVICE
explicit
Dim
(
int64_t
idx
)
{
this
->
Fill
(
idx
);
}
...
@@ -57,181 +53,12 @@ class Dim : public Array<int64_t, D> {
...
@@ -57,181 +53,12 @@ class Dim : public Array<int64_t, D> {
HOST
std
::
string
to_string
()
const
;
HOST
std
::
string
to_string
()
const
;
};
};
namespace
detail
{
template
<
int
kStart
,
int
kEnd
,
bool
kStop
>
struct
FortranOrderIndexingConstructorFunctor
{
HOSTDEVICE
inline
static
void
Run
(
const
int64_t
*
in
,
int64_t
*
idx
,
int64_t
*
out
)
{
out
[
kStart
]
=
(
*
idx
)
%
in
[
kStart
];
(
*
idx
)
/=
in
[
kStart
];
FortranOrderIndexingConstructorFunctor
<
kStart
+
1
,
kEnd
,
kStart
+
1
==
kEnd
>::
Run
(
in
,
idx
,
out
);
}
};
template
<
int
kStart
,
int
kEnd
>
struct
FortranOrderIndexingConstructorFunctor
<
kStart
,
kEnd
,
true
>
{
HOSTDEVICE
inline
static
void
Run
(
const
int64_t
*
in
,
int64_t
*
idx
,
int64_t
*
out
)
{}
};
}
// namespace detail
template
<
int
D
>
HOSTDEVICE
Dim
<
D
>::
Dim
(
int64_t
idx
,
const
Dim
<
D
>&
size
)
{
detail
::
FortranOrderIndexingConstructorFunctor
<
0
,
D
,
D
==
0
>::
Run
(
size
.
Get
(),
&
idx
,
this
->
GetMutable
());
}
template
<
int
idx
,
int
D
>
HOSTDEVICE
inline
int64_t
get
(
const
Dim
<
D
>&
dim
)
{
return
dim
[
idx
];
}
template
<
int
idx
,
int
D
>
HOSTDEVICE
inline
int64_t
&
get
(
Dim
<
D
>&
dim
)
{
// NOLINT
return
dim
[
idx
];
}
template
<
int
D
>
HOSTDEVICE
inline
int64_t
get
(
const
Dim
<
D
>&
dim
,
int
idx
)
{
return
dim
[
idx
];
}
template
<
int
D
>
HOSTDEVICE
inline
int64_t
&
get
(
Dim
<
D
>&
dim
,
int
idx
)
{
// NOLINT
return
dim
[
idx
];
}
// Dot product of two dims
template
<
int
D
>
HOSTDEVICE
inline
int64_t
linearize
(
const
Dim
<
D
>&
a
,
const
Dim
<
D
>&
b
)
{
return
UnrollProduct
<
D
>::
Run
(
a
.
Get
(),
b
.
Get
());
}
// Product of a Dim
// Product of a Dim
template
<
int
D
>
template
<
int
D
>
HOSTDEVICE
inline
int64_t
product
(
const
Dim
<
D
>&
a
)
{
HOSTDEVICE
inline
int64_t
product
(
const
Dim
<
D
>&
a
)
{
return
UnrollProduct
<
D
>::
Run
(
a
.
Get
());
return
UnrollProduct
<
D
>::
Run
(
a
.
Get
());
}
}
// Is 0 <= idx_i < size_i for all i?
namespace
detail
{
template
<
int
kStart
,
int
kEnd
,
bool
kStop
>
struct
ContainedFunctor
{
HOSTDEVICE
static
inline
bool
Run
(
const
int64_t
*
idx
,
const
int64_t
*
size
)
{
return
(
idx
[
kStart
]
>=
0
&&
idx
[
kStart
]
<
size
[
kStart
])
&&
ContainedFunctor
<
kStart
+
1
,
kEnd
,
kStart
+
1
==
kEnd
>::
Run
(
idx
,
size
);
}
};
template
<
int
kStart
,
int
kEnd
>
struct
ContainedFunctor
<
kStart
,
kEnd
,
true
>
{
HOSTDEVICE
static
constexpr
inline
bool
Run
(
const
int64_t
*
idx
,
const
int64_t
*
size
)
{
return
true
;
}
};
}
// namespace detail
template
<
int
D
>
HOSTDEVICE
inline
bool
contained
(
const
Dim
<
D
>&
idx
,
const
Dim
<
D
>&
size
)
{
return
detail
::
ContainedFunctor
<
0
,
D
,
D
==
0
>::
Run
(
idx
.
Get
(),
size
.
Get
());
}
/**
* \brief Compute exclusive prefix-multiply of a Dim.
*/
namespace
detail
{
template
<
int
kStart
,
int
kEnd
,
bool
kStop
>
struct
ExPrefixMulFunctor
{
HOSTDEVICE
static
inline
void
Run
(
const
int64_t
*
in
,
int64_t
*
out
)
{
kStart
==
0
?
out
[
kStart
]
=
1
:
out
[
kStart
]
=
out
[
kStart
-
1
]
*
in
[
kStart
-
1
];
detail
::
ExPrefixMulFunctor
<
kStart
+
1
,
kEnd
,
kStart
+
1
==
kEnd
>::
Run
(
in
,
out
);
}
};
template
<
int
kStart
,
int
kEnd
>
struct
ExPrefixMulFunctor
<
kStart
,
kEnd
,
true
>
{
HOSTDEVICE
static
inline
void
Run
(
const
int64_t
*
in
,
int64_t
*
out
)
{}
};
}
// namespace detail
template
<
int
D
>
HOSTDEVICE
inline
Dim
<
D
>
ex_prefix_mul
(
const
Dim
<
D
>&
src
)
{
Dim
<
D
>
ret
;
detail
::
ExPrefixMulFunctor
<
0
,
D
,
D
==
0
>::
Run
(
src
.
Get
(),
ret
.
GetMutable
());
return
ret
;
}
/**
* Add two dimensions together
*/
template
<
int
D
>
HOSTDEVICE
inline
Dim
<
D
>
dim_plus
(
const
Dim
<
D
>&
a
,
const
Dim
<
D
>&
b
)
{
Dim
<
D
>
ret
;
UnrollAdd
<
D
>::
Run
(
a
.
Get
(),
b
.
Get
(),
ret
.
GetMutable
());
return
ret
;
}
template
<
int
D
>
HOSTDEVICE
inline
Dim
<
D
>
operator
+
(
const
Dim
<
D
>&
lhs
,
const
Dim
<
D
>&
rhs
)
{
return
dim_plus
(
lhs
,
rhs
);
}
/**
* Multiply two dimensions together
*/
template
<
int
D
>
HOSTDEVICE
inline
Dim
<
D
>
dim_mult
(
const
Dim
<
D
>&
a
,
const
Dim
<
D
>&
b
)
{
Dim
<
D
>
ret
;
UnrollMul
<
D
>::
Run
(
a
.
Get
(),
b
.
Get
(),
ret
.
GetMutable
());
return
ret
;
}
template
<
int
D
>
HOSTDEVICE
Dim
<
D
>
operator
*
(
const
Dim
<
D
>&
lhs
,
const
Dim
<
D
>&
rhs
)
{
return
dim_mult
(
lhs
,
rhs
);
}
/**
* \brief Normalize strides to ensure any dimension with extent 1
* has stride 0.
*
* \param size Dim object containing the size of an array
* \param stride Dim object containing stride of an array
* \return Dim object the same size as \p size with normalized strides
*
*/
namespace
detail
{
template
<
int
kStart
,
int
kEnd
,
bool
kStop
>
struct
NormalizeStridesFunctor
{
HOSTDEVICE
static
void
Run
(
const
int64_t
*
size
,
const
int64_t
*
stride
,
int64_t
*
ret
)
{
ret
[
kStart
]
=
(
size
[
kStart
]
==
1
?
0
:
stride
[
kStart
]);
NormalizeStridesFunctor
<
kStart
+
1
,
kEnd
,
kStart
+
1
==
kEnd
>::
Run
(
size
,
stride
,
ret
);
}
};
template
<
int
kStart
,
int
kEnd
>
struct
NormalizeStridesFunctor
<
kStart
,
kEnd
,
true
>
{
HOSTDEVICE
static
void
Run
(
const
int64_t
*
size
,
const
int64_t
*
stride
,
int64_t
*
ret
)
{}
};
}
// namespace detail
template
<
int
D
>
HOSTDEVICE
Dim
<
D
>
normalize_strides
(
const
Dim
<
D
>&
size
,
const
Dim
<
D
>&
stride
)
{
Dim
<
D
>
ret
;
detail
::
NormalizeStridesFunctor
<
0
,
D
,
D
==
0
>::
Run
(
size
.
Get
(),
stride
.
Get
(),
ret
.
GetMutable
());
return
ret
;
}
/**
/**
* Helper function to create a Dim
* Helper function to create a Dim
*
*
...
@@ -265,20 +92,6 @@ HOST std::string Dim<D>::to_string() const {
...
@@ -265,20 +92,6 @@ HOST std::string Dim<D>::to_string() const {
return
stream
.
str
();
return
stream
.
str
();
}
}
template
<
int
D
>
HOSTDEVICE
Dim
<
D
>
linear_to_dimension
(
int
linear_index
,
const
Dim
<
D
>&
extents
)
{
Dim
<
D
>
result
;
for
(
int
i
=
0
;
i
<
D
-
1
;
++
i
)
{
result
[
i
]
=
linear_index
%
extents
[
i
];
linear_index
/=
extents
[
i
];
}
result
[
D
-
1
]
=
linear_index
;
return
result
;
}
template
<
int
D
,
typename
T1
,
typename
T2
>
template
<
int
D
,
typename
T1
,
typename
T2
>
inline
void
static_dim_assign
(
const
T1
*
in
,
T2
*
out
)
{
inline
void
static_dim_assign
(
const
T1
*
in
,
T2
*
out
)
{
UnrollAssign
<
D
>::
Run
(
in
,
out
);
UnrollAssign
<
D
>::
Run
(
in
,
out
);
...
...
paddle/fluid/framework/dim_test.cu
浏览文件 @
be24e5b3
...
@@ -29,34 +29,28 @@ __global__ void dyn_idx_gpu(int64_t* o) {
...
@@ -29,34 +29,28 @@ __global__ void dyn_idx_gpu(int64_t* o) {
TEST
(
Dim
,
Equality
)
{
TEST
(
Dim
,
Equality
)
{
// construct a Dim on the CPU
// construct a Dim on the CPU
auto
a
=
paddle
::
framework
::
make_dim
(
3
,
4
);
auto
a
=
paddle
::
framework
::
make_dim
(
3
,
4
);
EXPECT_EQ
(
paddle
::
framework
::
get
<
0
>
(
a
)
,
3
);
EXPECT_EQ
(
a
[
0
]
,
3
);
EXPECT_EQ
(
paddle
::
framework
::
get
<
1
>
(
a
)
,
4
);
EXPECT_EQ
(
a
[
1
]
,
4
);
// construct a Dim on the GPU
// construct a Dim on the GPU
thrust
::
device_vector
<
paddle
::
framework
::
Dim
<
2
>>
t
(
2
);
thrust
::
device_vector
<
paddle
::
framework
::
Dim
<
2
>>
t
(
2
);
test
<<<
1
,
1
>>>
(
thrust
::
raw_pointer_cast
(
t
.
data
()));
test
<<<
1
,
1
>>>
(
thrust
::
raw_pointer_cast
(
t
.
data
()));
a
=
t
[
0
];
a
=
t
[
0
];
EXPECT_EQ
(
paddle
::
framework
::
get
<
0
>
(
a
),
5
);
EXPECT_EQ
(
a
[
0
],
5
);
EXPECT_EQ
(
paddle
::
framework
::
get
<
1
>
(
a
),
6
);
EXPECT_EQ
(
a
[
1
],
6
);
// linearization
auto
b
=
paddle
::
framework
::
make_dim
(
7
,
8
);
EXPECT_EQ
(
paddle
::
framework
::
linearize
(
a
,
b
),
83
);
// product
// product
EXPECT_EQ
(
paddle
::
framework
::
product
(
a
),
30
);
EXPECT_EQ
(
paddle
::
framework
::
product
(
a
),
30
);
// mutate a Dim
// mutate a Dim
paddle
::
framework
::
get
<
1
>
(
b
)
=
10
;
auto
b
=
paddle
::
framework
::
make_dim
(
7
,
8
);
EXPECT_EQ
(
paddle
::
framework
::
get
<
0
>
(
b
),
7
);
b
[
1
]
=
10
;
EXPECT_EQ
(
paddle
::
framework
::
get
<
1
>
(
b
),
10
);
EXPECT_EQ
(
b
[
0
],
7
);
EXPECT_EQ
(
b
[
1
],
10
);
// dynamic access
b
[
0
]
=
8
;
paddle
::
framework
::
get
(
b
,
0
)
=
8
;
b
[
1
]
=
11
;
b
[
1
]
=
11
;
EXPECT_EQ
(
paddle
::
framework
::
get
<
0
>
(
b
),
8
);
EXPECT_EQ
(
b
[
0
],
8
);
EXPECT_EQ
(
paddle
::
framework
::
get
<
1
>
(
b
),
11
);
EXPECT_EQ
(
paddle
::
framework
::
get
(
b
,
0
),
8
);
EXPECT_EQ
(
b
[
1
],
11
);
EXPECT_EQ
(
b
[
1
],
11
);
// dynamic access on GPU
// dynamic access on GPU
...
@@ -64,24 +58,6 @@ TEST(Dim, Equality) {
...
@@ -64,24 +58,6 @@ TEST(Dim, Equality) {
dyn_idx_gpu
<<<
1
,
1
>>>
(
thrust
::
raw_pointer_cast
(
r
.
data
()));
dyn_idx_gpu
<<<
1
,
1
>>>
(
thrust
::
raw_pointer_cast
(
r
.
data
()));
int64_t
res
=
r
[
0
];
int64_t
res
=
r
[
0
];
EXPECT_EQ
(
res
,
6
);
EXPECT_EQ
(
res
,
6
);
// ex_prefix_mul
paddle
::
framework
::
Dim
<
3
>
c
=
paddle
::
framework
::
ex_prefix_mul
(
paddle
::
framework
::
Dim
<
3
>
(
3
,
4
,
5
));
EXPECT_EQ
(
paddle
::
framework
::
get
<
0
>
(
c
),
1
);
EXPECT_EQ
(
paddle
::
framework
::
get
<
1
>
(
c
),
3
);
EXPECT_EQ
(
paddle
::
framework
::
get
<
2
>
(
c
),
12
);
// generate from an index
auto
size
=
paddle
::
framework
::
make_dim
(
4
,
5
,
2
);
c
=
paddle
::
framework
::
Dim
<
3
>
(
14
,
size
);
EXPECT_EQ
(
paddle
::
framework
::
get
<
0
>
(
c
),
2
);
EXPECT_EQ
(
paddle
::
framework
::
get
<
1
>
(
c
),
3
);
EXPECT_EQ
(
paddle
::
framework
::
get
<
2
>
(
c
),
0
);
c
=
paddle
::
framework
::
Dim
<
3
>
(
25
,
size
);
EXPECT_EQ
(
paddle
::
framework
::
get
<
0
>
(
c
),
1
);
EXPECT_EQ
(
paddle
::
framework
::
get
<
1
>
(
c
),
1
);
EXPECT_EQ
(
paddle
::
framework
::
get
<
2
>
(
c
),
1
);
}
}
TEST
(
Dim
,
Bool
)
{
TEST
(
Dim
,
Bool
)
{
...
@@ -89,10 +65,6 @@ TEST(Dim, Bool) {
...
@@ -89,10 +65,6 @@ TEST(Dim, Bool) {
auto
b
=
paddle
::
framework
::
make_dim
(
5
,
6
);
auto
b
=
paddle
::
framework
::
make_dim
(
5
,
6
);
auto
c
=
paddle
::
framework
::
make_dim
(
3
,
4
);
auto
c
=
paddle
::
framework
::
make_dim
(
3
,
4
);
// in_bounds check
EXPECT_TRUE
(
paddle
::
framework
::
contained
(
a
,
b
));
EXPECT_FALSE
(
paddle
::
framework
::
contained
(
b
,
a
));
// comparison
// comparison
EXPECT_TRUE
(
a
==
a
);
EXPECT_TRUE
(
a
==
a
);
EXPECT_FALSE
(
a
==
b
);
EXPECT_FALSE
(
a
==
b
);
...
...
paddle/fluid/framework/unroll_array_ops.h
浏览文件 @
be24e5b3
...
@@ -94,36 +94,6 @@ struct UnrollCompare<kStart, kEnd, true> {
...
@@ -94,36 +94,6 @@ struct UnrollCompare<kStart, kEnd, true> {
}
}
};
};
template
<
size_t
kStart
,
size_t
kEnd
,
bool
kStop
>
struct
UnrollAdd
{
template
<
typename
T
>
HOSTDEVICE
inline
static
void
Run
(
const
T
*
d1
,
const
T
*
d2
,
T
*
d3
)
{
d3
[
kStart
]
=
d1
[
kStart
]
+
d2
[
kStart
];
UnrollAdd
<
kStart
+
1
,
kEnd
,
kStart
+
1
==
kEnd
>::
Run
(
d1
,
d2
,
d3
);
}
};
template
<
size_t
kStart
,
size_t
kEnd
>
struct
UnrollAdd
<
kStart
,
kEnd
,
true
>
{
template
<
typename
T
>
HOSTDEVICE
inline
static
void
Run
(
const
T
*
d1
,
const
T
*
d2
,
T
*
d3
)
{}
};
template
<
size_t
kStart
,
size_t
kEnd
,
bool
kStop
>
struct
UnrollMul
{
template
<
typename
T
>
HOSTDEVICE
inline
static
void
Run
(
const
T
*
d1
,
const
T
*
d2
,
T
*
d3
)
{
d3
[
kStart
]
=
d1
[
kStart
]
*
d2
[
kStart
];
UnrollMul
<
kStart
+
1
,
kEnd
,
kStart
+
1
==
kEnd
>::
Run
(
d1
,
d2
,
d3
);
}
};
template
<
size_t
kStart
,
size_t
kEnd
>
struct
UnrollMul
<
kStart
,
kEnd
,
true
>
{
template
<
typename
T
>
HOSTDEVICE
inline
static
void
Run
(
const
T
*
d1
,
const
T
*
d2
,
T
*
d3
)
{}
};
template
<
size_t
kStart
,
size_t
kEnd
,
bool
kStop
>
template
<
size_t
kStart
,
size_t
kEnd
,
bool
kStop
>
struct
UnrollProduct
{
struct
UnrollProduct
{
template
<
typename
T
>
template
<
typename
T
>
...
@@ -131,12 +101,6 @@ struct UnrollProduct {
...
@@ -131,12 +101,6 @@ struct UnrollProduct {
return
d
[
kStart
]
*
return
d
[
kStart
]
*
UnrollProduct
<
kStart
+
1
,
kEnd
,
kStart
+
1
==
kEnd
>::
Run
(
d
);
UnrollProduct
<
kStart
+
1
,
kEnd
,
kStart
+
1
==
kEnd
>::
Run
(
d
);
}
}
template
<
typename
T
>
HOSTDEVICE
inline
static
T
Run
(
const
T
*
d1
,
const
T
*
d2
)
{
return
d1
[
kStart
]
*
d2
[
kStart
]
+
UnrollProduct
<
kStart
+
1
,
kEnd
,
kStart
+
1
==
kEnd
>::
Run
(
d1
,
d2
);
}
};
};
template
<
size_t
kStart
,
size_t
kEnd
>
template
<
size_t
kStart
,
size_t
kEnd
>
...
@@ -145,11 +109,6 @@ struct UnrollProduct<kStart, kEnd, true> {
...
@@ -145,11 +109,6 @@ struct UnrollProduct<kStart, kEnd, true> {
HOSTDEVICE
inline
constexpr
static
T
Run
(
const
T
*
d
)
{
HOSTDEVICE
inline
constexpr
static
T
Run
(
const
T
*
d
)
{
return
1
;
return
1
;
}
}
template
<
typename
T
>
HOSTDEVICE
inline
constexpr
static
T
Run
(
const
T
*
d1
,
const
T
*
d2
)
{
return
0
;
}
};
};
}
// namespace detail
}
// namespace detail
...
@@ -166,12 +125,6 @@ using UnrollVarArgsAssign = detail::UnrollVarArgsAssign<T>;
...
@@ -166,12 +125,6 @@ using UnrollVarArgsAssign = detail::UnrollVarArgsAssign<T>;
template
<
size_t
N
>
template
<
size_t
N
>
using
UnrollCompare
=
detail
::
UnrollCompare
<
0
,
N
,
N
==
0
>
;
using
UnrollCompare
=
detail
::
UnrollCompare
<
0
,
N
,
N
==
0
>
;
template
<
size_t
N
>
using
UnrollAdd
=
detail
::
UnrollAdd
<
0
,
N
,
N
==
0
>
;
template
<
size_t
N
>
using
UnrollMul
=
detail
::
UnrollMul
<
0
,
N
,
N
==
0
>
;
template
<
size_t
N
>
template
<
size_t
N
>
using
UnrollProduct
=
detail
::
UnrollProduct
<
0
,
N
,
N
==
0
>
;
using
UnrollProduct
=
detail
::
UnrollProduct
<
0
,
N
,
N
==
0
>
;
...
...
paddle/fluid/framework/unroll_array_ops_test.cc
浏览文件 @
be24e5b3
...
@@ -74,34 +74,9 @@ TEST(unroll_ops, compare) {
...
@@ -74,34 +74,9 @@ TEST(unroll_ops, compare) {
EXPECT_FALSE
(
UnrollCompare
<
1
>::
Run
(
a
,
b
));
EXPECT_FALSE
(
UnrollCompare
<
1
>::
Run
(
a
,
b
));
}
}
TEST
(
unroll_ops
,
add
)
{
int
a
[]
=
{
2
,
3
,
4
};
int
b
[]
=
{
5
,
10
,
102
};
int
c
[]
=
{
0
,
0
,
0
};
UnrollAdd
<
2
>::
Run
(
a
,
b
,
c
);
EXPECT_EQ
(
a
[
0
]
+
b
[
0
],
c
[
0
]);
EXPECT_EQ
(
a
[
1
]
+
b
[
1
],
c
[
1
]);
EXPECT_EQ
(
c
[
2
],
0
);
}
TEST
(
unroll_ops
,
mul
)
{
int
a
[]
=
{
2
,
3
,
4
};
int
b
[]
=
{
5
,
10
,
102
};
int
c
[]
=
{
0
,
0
,
0
};
UnrollMul
<
2
>::
Run
(
a
,
b
,
c
);
EXPECT_EQ
(
a
[
0
]
*
b
[
0
],
c
[
0
]);
EXPECT_EQ
(
a
[
1
]
*
b
[
1
],
c
[
1
]);
EXPECT_EQ
(
c
[
2
],
0
);
}
TEST
(
unroll_ops
,
product
)
{
TEST
(
unroll_ops
,
product
)
{
int
a
[]
=
{
2
,
3
,
4
};
int
a
[]
=
{
2
,
3
,
4
};
int
b
[]
=
{
5
,
10
,
102
};
EXPECT_EQ
(
UnrollProduct
<
3
>::
Run
(
a
),
a
[
0
]
*
a
[
1
]
*
a
[
2
]);
EXPECT_EQ
(
UnrollProduct
<
3
>::
Run
(
a
),
a
[
0
]
*
a
[
1
]
*
a
[
2
]);
EXPECT_EQ
(
UnrollProduct
<
3
>::
Run
(
a
,
b
),
a
[
0
]
*
b
[
0
]
+
a
[
1
]
*
b
[
1
]
+
a
[
2
]
*
b
[
2
]);
}
}
}
// namespace framework
}
// namespace framework
...
...
paddle/fluid/operators/hierarchical_sigmoid_op.h
浏览文件 @
be24e5b3
...
@@ -248,8 +248,7 @@ class HierarchicalSigmoidGradOpKernel : public framework::OpKernel<T> {
...
@@ -248,8 +248,7 @@ class HierarchicalSigmoidGradOpKernel : public framework::OpKernel<T> {
w_grad
->
set_height
(
w
.
dims
()[
0
]);
w_grad
->
set_height
(
w
.
dims
()[
0
]);
auto
*
w_grad_value
=
w_grad
->
mutable_value
();
auto
*
w_grad_value
=
w_grad
->
mutable_value
();
framework
::
DDim
temp_dim
(
w
.
dims
());
framework
::
DDim
temp_dim
(
w
.
dims
());
set
(
temp_dim
,
0
,
real_rows
.
size
());
temp_dim
[
0
]
=
real_rows
.
size
();
w_grad_value
->
mutable_data
<
T
>
(
temp_dim
,
ctx
.
GetPlace
());
w_grad_value
->
mutable_data
<
T
>
(
temp_dim
,
ctx
.
GetPlace
());
zero
(
dev_ctx
,
w_grad_value
,
static_cast
<
T
>
(
0.0
));
zero
(
dev_ctx
,
w_grad_value
,
static_cast
<
T
>
(
0.0
));
bit_code
->
MulGradWeight
(
pre_out_grad
,
w_grad
,
in
);
bit_code
->
MulGradWeight
(
pre_out_grad
,
w_grad
,
in
);
...
...
paddle/fluid/platform/place.cc
浏览文件 @
be24e5b3
...
@@ -40,15 +40,6 @@ class PlacePrinter : public boost::static_visitor<> {
...
@@ -40,15 +40,6 @@ class PlacePrinter : public boost::static_visitor<> {
}
// namespace detail
}
// namespace detail
static
Place
the_default_place
;
void
set_place
(
const
Place
&
place
)
{
the_default_place
=
place
;
}
const
Place
&
get_place
()
{
return
the_default_place
;
}
const
CUDAPlace
default_gpu
()
{
return
CUDAPlace
(
0
);
}
const
CPUPlace
default_cpu
()
{
return
CPUPlace
();
}
const
CUDAPinnedPlace
default_cuda_pinned
()
{
return
CUDAPinnedPlace
();
}
bool
is_gpu_place
(
const
Place
&
p
)
{
bool
is_gpu_place
(
const
Place
&
p
)
{
return
boost
::
apply_visitor
(
IsCUDAPlace
(),
p
);
return
boost
::
apply_visitor
(
IsCUDAPlace
(),
p
);
}
}
...
...
paddle/fluid/platform/place.h
浏览文件 @
be24e5b3
...
@@ -80,13 +80,6 @@ typedef boost::variant<CUDAPlace, CPUPlace, CUDAPinnedPlace> Place;
...
@@ -80,13 +80,6 @@ typedef boost::variant<CUDAPlace, CPUPlace, CUDAPinnedPlace> Place;
using
PlaceList
=
std
::
vector
<
Place
>
;
using
PlaceList
=
std
::
vector
<
Place
>
;
void
set_place
(
const
Place
&
);
const
Place
&
get_place
();
const
CUDAPlace
default_gpu
();
const
CPUPlace
default_cpu
();
const
CUDAPinnedPlace
default_cuda_pinned
();
bool
is_gpu_place
(
const
Place
&
);
bool
is_gpu_place
(
const
Place
&
);
bool
is_cpu_place
(
const
Place
&
);
bool
is_cpu_place
(
const
Place
&
);
bool
is_cuda_pinned_place
(
const
Place
&
);
bool
is_cuda_pinned_place
(
const
Place
&
);
...
...
paddle/fluid/platform/place_test.cc
浏览文件 @
be24e5b3
...
@@ -30,16 +30,6 @@ TEST(Place, Equality) {
...
@@ -30,16 +30,6 @@ TEST(Place, Equality) {
EXPECT_FALSE
(
paddle
::
platform
::
places_are_same_class
(
g0
,
cpu
));
EXPECT_FALSE
(
paddle
::
platform
::
places_are_same_class
(
g0
,
cpu
));
}
}
TEST
(
Place
,
Default
)
{
EXPECT_TRUE
(
paddle
::
platform
::
is_gpu_place
(
paddle
::
platform
::
get_place
()));
EXPECT_TRUE
(
paddle
::
platform
::
is_gpu_place
(
paddle
::
platform
::
default_gpu
()));
EXPECT_TRUE
(
paddle
::
platform
::
is_cpu_place
(
paddle
::
platform
::
default_cpu
()));
EXPECT_FALSE
(
paddle
::
platform
::
is_cpu_place
(
paddle
::
platform
::
get_place
()));
paddle
::
platform
::
set_place
(
paddle
::
platform
::
CPUPlace
());
EXPECT_TRUE
(
paddle
::
platform
::
is_cpu_place
(
paddle
::
platform
::
get_place
()));
}
TEST
(
Place
,
Print
)
{
TEST
(
Place
,
Print
)
{
{
{
std
::
stringstream
ss
;
std
::
stringstream
ss
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录