Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
8913aff1
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看板
提交
8913aff1
编写于
6月 19, 2017
作者:
Y
Yi Wang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make paddle/framework buildable and passed
上级
d03159be
变更
7
显示空白变更内容
内联
并排
Showing
7 changed file
with
125 addition
and
128 deletion
+125
-128
paddle/CMakeLists.txt
paddle/CMakeLists.txt
+1
-0
paddle/framework/ddim.cc
paddle/framework/ddim.cc
+10
-8
paddle/framework/ddim.h
paddle/framework/ddim.h
+9
-14
paddle/framework/ddim_test.cc
paddle/framework/ddim_test.cc
+13
-13
paddle/framework/dim.h
paddle/framework/dim.h
+13
-11
paddle/framework/dim_test.cu
paddle/framework/dim_test.cu
+63
-63
paddle/platform/assert.h
paddle/platform/assert.h
+16
-19
未找到文件。
paddle/CMakeLists.txt
浏览文件 @
8913aff1
...
@@ -18,6 +18,7 @@ add_subdirectory(strings)
...
@@ -18,6 +18,7 @@ add_subdirectory(strings)
find_package
(
Boost QUIET
)
find_package
(
Boost QUIET
)
add_subdirectory
(
platform
)
add_subdirectory
(
platform
)
add_subdirectory
(
framework
)
# if(Boost_FOUND)
# if(Boost_FOUND)
# include_directories(${Boost_INCLUDE_DIRS})
# include_directories(${Boost_INCLUDE_DIRS})
...
...
paddle/framework/ddim.cc
浏览文件 @
8913aff1
#include "paddle/
majel
/ddim.h"
#include "paddle/
framework
/ddim.h"
namespace
majel
{
namespace
paddle
{
namespace
framework
{
///@cond HIDDEN
///@cond HIDDEN
...
@@ -66,7 +67,7 @@ DDim make_ddim(const std::vector<int>& dims) {
...
@@ -66,7 +67,7 @@ DDim make_ddim(const std::vector<int>& dims) {
///@cond HIDDEN
///@cond HIDDEN
// XXX For some reason, putting this in an anonymous namespace causes errors
// XXX For some reason, putting this in an anonymous namespace causes errors
class
DynamicMutableIndexer
:
public
boost
::
static_visitor
<
int
&>
{
class
DynamicMutableIndexer
:
public
boost
::
static_visitor
<
int
&>
{
public:
public:
DynamicMutableIndexer
(
int
idx
)
:
idx_
(
idx
)
{}
DynamicMutableIndexer
(
int
idx
)
:
idx_
(
idx
)
{}
template
<
int
D
>
template
<
int
D
>
...
@@ -74,12 +75,12 @@ public:
...
@@ -74,12 +75,12 @@ public:
return
dim
[
idx_
];
return
dim
[
idx_
];
}
}
private:
private:
int
idx_
;
int
idx_
;
};
};
class
DynamicConstIndexer
:
public
boost
::
static_visitor
<
int
>
{
class
DynamicConstIndexer
:
public
boost
::
static_visitor
<
int
>
{
public:
public:
DynamicConstIndexer
(
int
idx
)
:
idx_
(
idx
)
{}
DynamicConstIndexer
(
int
idx
)
:
idx_
(
idx
)
{}
template
<
int
D
>
template
<
int
D
>
...
@@ -87,7 +88,7 @@ public:
...
@@ -87,7 +88,7 @@ public:
return
dim
[
idx_
];
return
dim
[
idx_
];
}
}
private:
private:
int
idx_
;
int
idx_
;
};
};
...
@@ -213,10 +214,11 @@ struct DDimPrinter : boost::static_visitor<void> {
...
@@ -213,10 +214,11 @@ struct DDimPrinter : boost::static_visitor<void> {
///\endcond
///\endcond
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
majel
::
DDim
&
ddim
)
{
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
DDim
&
ddim
)
{
DDimPrinter
printer
(
os
);
DDimPrinter
printer
(
os
);
boost
::
apply_visitor
(
printer
,
ddim
);
boost
::
apply_visitor
(
printer
,
ddim
);
return
os
;
return
os
;
}
}
}
// namespace majel
}
// namespace framework
}
// namespace paddle
paddle/framework/ddim.h
浏览文件 @
8913aff1
...
@@ -5,20 +5,14 @@
...
@@ -5,20 +5,14 @@
#include <stdexcept>
#include <stdexcept>
#include <vector>
#include <vector>
#include "paddle/
majel
/dim.h"
#include "paddle/
framework
/dim.h"
namespace
majel
{
namespace
paddle
{
namespace
framework
{
namespace
{
namespace
{
typedef
boost
::
variant
<
Dim
<
1
>
,
typedef
boost
::
variant
<
Dim
<
1
>
,
Dim
<
2
>
,
Dim
<
3
>
,
Dim
<
4
>
,
Dim
<
5
>
,
Dim
<
6
>
,
Dim
<
7
>
,
Dim
<
2
>
,
Dim
<
8
>
,
Dim
<
9
>>
Dim
<
3
>
,
Dim
<
4
>
,
Dim
<
5
>
,
Dim
<
6
>
,
Dim
<
7
>
,
Dim
<
8
>
,
Dim
<
9
>>
DDimVar
;
DDimVar
;
}
}
...
@@ -95,14 +89,15 @@ ssize_t product(const DDim& ddim);
...
@@ -95,14 +89,15 @@ ssize_t product(const DDim& ddim);
int
arity
(
const
DDim
&
ddim
);
int
arity
(
const
DDim
&
ddim
);
std
::
ostream
&
operator
<<
(
std
::
ostream
&
,
const
majel
::
DDim
&
);
std
::
ostream
&
operator
<<
(
std
::
ostream
&
,
const
DDim
&
);
}
// namespace majel
}
// namespace framework
}
// namespace paddle
namespace
boost
{
namespace
boost
{
template
<
typename
T
>
template
<
typename
T
>
T
get
(
const
majel
::
DDim
&
in
)
{
T
get
(
const
paddle
::
framework
::
DDim
&
in
)
{
return
boost
::
get
<
T
>
(
in
.
var
);
return
boost
::
get
<
T
>
(
in
.
var
);
}
}
...
...
paddle/framework/ddim_test.cc
浏览文件 @
8913aff1
...
@@ -4,18 +4,18 @@
...
@@ -4,18 +4,18 @@
#include <vector>
#include <vector>
#include "gtest/gtest.h"
#include "gtest/gtest.h"
#include "paddle/
majel
/ddim.h"
#include "paddle/
framework
/ddim.h"
TEST
(
DDim
,
Equality
)
{
TEST
(
DDim
,
Equality
)
{
// construct a DDim from an initialization list
// construct a DDim from an initialization list
majel
::
DDim
ddim
=
majel
::
make_ddim
({
9
,
1
,
5
});
paddle
::
framework
::
DDim
ddim
=
paddle
::
framework
::
make_ddim
({
9
,
1
,
5
});
EXPECT_EQ
(
ddim
[
0
],
9
);
EXPECT_EQ
(
ddim
[
0
],
9
);
EXPECT_EQ
(
ddim
[
1
],
1
);
EXPECT_EQ
(
ddim
[
1
],
1
);
EXPECT_EQ
(
ddim
[
2
],
5
);
EXPECT_EQ
(
ddim
[
2
],
5
);
// construct a DDim from a vector
// construct a DDim from a vector
std
::
vector
<
int
>
vec
({
9
,
1
,
5
});
std
::
vector
<
int
>
vec
({
9
,
1
,
5
});
majel
::
DDim
vddim
=
majel
::
make_ddim
(
vec
);
paddle
::
framework
::
DDim
vddim
=
paddle
::
framework
::
make_ddim
(
vec
);
EXPECT_EQ
(
ddim
[
0
],
9
);
EXPECT_EQ
(
ddim
[
0
],
9
);
EXPECT_EQ
(
ddim
[
1
],
1
);
EXPECT_EQ
(
ddim
[
1
],
1
);
EXPECT_EQ
(
ddim
[
2
],
5
);
EXPECT_EQ
(
ddim
[
2
],
5
);
...
@@ -23,43 +23,43 @@ TEST(DDim, Equality) {
...
@@ -23,43 +23,43 @@ 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
);
majel
::
set
(
ddim
,
0
,
6
);
paddle
::
framework
::
set
(
ddim
,
0
,
6
);
EXPECT_EQ
(
majel
::
get
(
ddim
,
0
),
6
);
EXPECT_EQ
(
paddle
::
framework
::
get
(
ddim
,
0
),
6
);
// vectorize a DDim
// vectorize a DDim
std
::
vector
<
int
>
res_vec
=
majel
::
vectorize
(
vddim
);
std
::
vector
<
int
>
res_vec
=
paddle
::
framework
::
vectorize
(
vddim
);
EXPECT_EQ
(
res_vec
[
0
],
9
);
EXPECT_EQ
(
res_vec
[
0
],
9
);
EXPECT_EQ
(
res_vec
[
1
],
1
);
EXPECT_EQ
(
res_vec
[
1
],
1
);
EXPECT_EQ
(
res_vec
[
2
],
5
);
EXPECT_EQ
(
res_vec
[
2
],
5
);
majel
::
Dim
<
3
>
d
(
3
,
2
,
1
);
paddle
::
framework
::
Dim
<
3
>
d
(
3
,
2
,
1
);
res_vec
=
majel
::
vectorize
(
majel
::
DDim
(
d
));
res_vec
=
paddle
::
framework
::
vectorize
(
paddle
::
framework
::
DDim
(
d
));
EXPECT_EQ
(
res_vec
[
0
],
3
);
EXPECT_EQ
(
res_vec
[
0
],
3
);
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
// add two DDims
majel
::
DDim
ddim_sum
=
ddim
+
vddim
;
paddle
::
framework
::
DDim
ddim_sum
=
ddim
+
vddim
;
EXPECT_EQ
(
ddim_sum
[
0
],
15
);
EXPECT_EQ
(
ddim_sum
[
0
],
15
);
EXPECT_EQ
(
ddim_sum
[
1
],
3
);
EXPECT_EQ
(
ddim_sum
[
1
],
3
);
EXPECT_EQ
(
ddim_sum
[
2
],
10
);
EXPECT_EQ
(
ddim_sum
[
2
],
10
);
// multiply two DDims
// multiply two DDims
majel
::
DDim
ddim_mul
=
ddim
*
vddim
;
paddle
::
framework
::
DDim
ddim_mul
=
ddim
*
vddim
;
EXPECT_EQ
(
ddim_mul
[
0
],
54
);
EXPECT_EQ
(
ddim_mul
[
0
],
54
);
EXPECT_EQ
(
ddim_mul
[
1
],
2
);
EXPECT_EQ
(
ddim_mul
[
1
],
2
);
EXPECT_EQ
(
ddim_mul
[
2
],
25
);
EXPECT_EQ
(
ddim_mul
[
2
],
25
);
// arity of a DDim
// arity of a DDim
EXPECT_EQ
(
majel
::
arity
(
ddim
),
3
);
EXPECT_EQ
(
paddle
::
framework
::
arity
(
ddim
),
3
);
// product of a DDim
// product of a DDim
EXPECT_EQ
(
majel
::
product
(
vddim
),
45
);
EXPECT_EQ
(
paddle
::
framework
::
product
(
vddim
),
45
);
}
}
TEST
(
DDim
,
Print
)
{
TEST
(
DDim
,
Print
)
{
// print a DDim
// print a DDim
std
::
stringstream
ss
;
std
::
stringstream
ss
;
majel
::
DDim
ddim
=
majel
::
make_ddim
({
2
,
3
,
4
});
paddle
::
framework
::
DDim
ddim
=
paddle
::
framework
::
make_ddim
({
2
,
3
,
4
});
ss
<<
ddim
;
ss
<<
ddim
;
EXPECT_EQ
(
"2, 3, 4"
,
ss
.
str
());
EXPECT_EQ
(
"2, 3, 4"
,
ss
.
str
());
}
}
paddle/framework/dim.h
浏览文件 @
8913aff1
...
@@ -5,10 +5,11 @@
...
@@ -5,10 +5,11 @@
#include <stdexcept>
#include <stdexcept>
#include <type_traits>
#include <type_traits>
#include "paddle/
majel/detail/cuda_
assert.h"
#include "paddle/
platform/
assert.h"
#include "paddle/
majel/detail
/hostdevice.h"
#include "paddle/
platform
/hostdevice.h"
namespace
majel
{
namespace
paddle
{
namespace
framework
{
// Statically sized, statically indexed dimension
// Statically sized, statically indexed dimension
template
<
int
i
>
template
<
int
i
>
...
@@ -74,7 +75,7 @@ struct Dim<1> {
...
@@ -74,7 +75,7 @@ struct Dim<1> {
throw
std
::
invalid_argument
(
"Index out of range."
);
throw
std
::
invalid_argument
(
"Index out of range."
);
}
}
#else
#else
MAJEL
_ASSERT
(
idx
<
size
.
head
);
PADDLE
_ASSERT
(
idx
<
size
.
head
);
#endif
#endif
}
}
...
@@ -131,7 +132,7 @@ HOSTDEVICE int& indexer(Dim<D>& dim, int idx) {
...
@@ -131,7 +132,7 @@ HOSTDEVICE int& indexer(Dim<D>& dim, int idx) {
throw
std
::
invalid_argument
(
"Tried to access a negative dimension"
);
throw
std
::
invalid_argument
(
"Tried to access a negative dimension"
);
}
}
#else
#else
MAJEL
_ASSERT
(
idx
>=
0
);
PADDLE
_ASSERT
(
idx
>=
0
);
#endif
#endif
if
(
idx
==
0
)
{
if
(
idx
==
0
)
{
return
dim
.
head
;
return
dim
.
head
;
...
@@ -146,7 +147,7 @@ HOSTDEVICE int& indexer<1>(Dim<1>& dim, int idx) {
...
@@ -146,7 +147,7 @@ HOSTDEVICE int& indexer<1>(Dim<1>& dim, int idx) {
throw
std
::
invalid_argument
(
"Invalid index"
);
throw
std
::
invalid_argument
(
"Invalid index"
);
}
}
#else
#else
MAJEL
_ASSERT
(
idx
==
0
);
PADDLE
_ASSERT
(
idx
==
0
);
#endif
#endif
return
dim
.
head
;
return
dim
.
head
;
}
}
...
@@ -158,7 +159,7 @@ HOSTDEVICE int indexer(const Dim<D>& dim, int idx) {
...
@@ -158,7 +159,7 @@ HOSTDEVICE int indexer(const Dim<D>& dim, int idx) {
throw
std
::
invalid_argument
(
"Tried to access a negative dimension"
);
throw
std
::
invalid_argument
(
"Tried to access a negative dimension"
);
}
}
#else
#else
MAJEL
_ASSERT
(
idx
>=
0
);
PADDLE
_ASSERT
(
idx
>=
0
);
#endif
#endif
if
(
idx
==
0
)
{
if
(
idx
==
0
)
{
return
dim
.
head
;
return
dim
.
head
;
...
@@ -173,7 +174,7 @@ HOSTDEVICE int indexer<1>(const Dim<1>& dim, int idx) {
...
@@ -173,7 +174,7 @@ HOSTDEVICE int indexer<1>(const Dim<1>& dim, int idx) {
throw
std
::
invalid_argument
(
"Invalid index"
);
throw
std
::
invalid_argument
(
"Invalid index"
);
}
}
#else
#else
MAJEL
_ASSERT
(
idx
==
0
);
PADDLE
_ASSERT
(
idx
==
0
);
#endif
#endif
return
dim
.
head
;
return
dim
.
head
;
}
}
...
@@ -411,7 +412,7 @@ HOSTDEVICE Dim<sizeof...(Args)> make_dim(Args... idxes) {
...
@@ -411,7 +412,7 @@ HOSTDEVICE Dim<sizeof...(Args)> make_dim(Args... idxes) {
// XXX For some reason, overloading fails to resolve this correctly
// XXX For some reason, overloading fails to resolve this correctly
template
<
int
i
>
template
<
int
i
>
typename
std
::
enable_if
<
(
i
>
1
),
std
::
ostream
&>::
type
operator
<<
(
typename
std
::
enable_if
<
(
i
>
1
),
std
::
ostream
&>::
type
operator
<<
(
std
::
ostream
&
os
,
const
majel
::
Dim
<
i
>&
d
)
{
std
::
ostream
&
os
,
const
Dim
<
i
>&
d
)
{
os
<<
d
.
head
<<
", "
<<
d
.
tail
;
os
<<
d
.
head
<<
", "
<<
d
.
tail
;
return
os
;
return
os
;
}
}
...
@@ -420,7 +421,7 @@ typename std::enable_if<(i > 1), std::ostream&>::type operator<<(
...
@@ -420,7 +421,7 @@ typename std::enable_if<(i > 1), std::ostream&>::type operator<<(
// XXX I wish this could be an overload instead of a template
// XXX I wish this could be an overload instead of a template
template
<
int
i
>
template
<
int
i
>
typename
std
::
enable_if
<
(
i
==
1
),
std
::
ostream
&>::
type
operator
<<
(
typename
std
::
enable_if
<
(
i
==
1
),
std
::
ostream
&>::
type
operator
<<
(
std
::
ostream
&
os
,
const
majel
::
Dim
<
i
>&
d
)
{
std
::
ostream
&
os
,
const
Dim
<
i
>&
d
)
{
os
<<
d
.
head
;
os
<<
d
.
head
;
return
os
;
return
os
;
}
}
...
@@ -448,4 +449,5 @@ HOSTDEVICE Dim<D> linear_to_dimension(int linear_index, Dim<D> extents) {
...
@@ -448,4 +449,5 @@ HOSTDEVICE Dim<D> linear_to_dimension(int linear_index, Dim<D> extents) {
return
result
;
return
result
;
}
}
}
// namespace majel
}
// namespace framework
}
// namespace paddle
paddle/framework/dim_test.cu
浏览文件 @
8913aff1
#include <thrust/device_vector.h>
#include <thrust/device_vector.h>
#include <sstream>
#include <sstream>
#include "paddle/
majel
/dim.h"
#include "paddle/
framework
/dim.h"
#include "gtest/gtest.h"
#include "gtest/gtest.h"
__global__
void
test
(
majel
::
Dim
<
2
>*
o
)
{
__global__
void
test
(
paddle
::
framework
::
Dim
<
2
>*
o
)
{
o
[
0
]
=
majel
::
make_dim
(
5
,
6
);
o
[
0
]
=
paddle
::
framework
::
make_dim
(
5
,
6
);
}
}
__global__
void
dyn_idx_gpu
(
int
*
o
)
{
__global__
void
dyn_idx_gpu
(
int
*
o
)
{
auto
d
=
majel
::
make_dim
(
5
,
6
);
auto
d
=
paddle
::
framework
::
make_dim
(
5
,
6
);
o
[
0
]
=
d
[
1
];
o
[
0
]
=
d
[
1
];
}
}
TEST
(
Dim
,
Equality
)
{
TEST
(
Dim
,
Equality
)
{
// construct a Dim on the CPU
// construct a Dim on the CPU
auto
a
=
majel
::
make_dim
(
3
,
4
);
auto
a
=
paddle
::
framework
::
make_dim
(
3
,
4
);
EXPECT_EQ
(
majel
::
get
<
0
>
(
a
),
3
);
EXPECT_EQ
(
paddle
::
framework
::
get
<
0
>
(
a
),
3
);
EXPECT_EQ
(
majel
::
get
<
1
>
(
a
),
4
);
EXPECT_EQ
(
paddle
::
framework
::
get
<
1
>
(
a
),
4
);
// construct a Dim on the GPU
// construct a Dim on the GPU
thrust
::
device_vector
<
majel
::
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
(
majel
::
get
<
0
>
(
a
),
5
);
EXPECT_EQ
(
paddle
::
framework
::
get
<
0
>
(
a
),
5
);
EXPECT_EQ
(
majel
::
get
<
1
>
(
a
),
6
);
EXPECT_EQ
(
paddle
::
framework
::
get
<
1
>
(
a
),
6
);
// linearization
// linearization
auto
b
=
majel
::
make_dim
(
7
,
8
);
auto
b
=
paddle
::
framework
::
make_dim
(
7
,
8
);
EXPECT_EQ
(
majel
::
linearize
(
a
,
b
),
83
);
EXPECT_EQ
(
paddle
::
framework
::
linearize
(
a
,
b
),
83
);
// product
// product
EXPECT_EQ
(
majel
::
product
(
a
),
30
);
EXPECT_EQ
(
paddle
::
framework
::
product
(
a
),
30
);
// mutate a Dim
// mutate a Dim
majel
::
get
<
1
>
(
b
)
=
10
;
paddle
::
framework
::
get
<
1
>
(
b
)
=
10
;
EXPECT_EQ
(
majel
::
get
<
0
>
(
b
),
7
);
EXPECT_EQ
(
paddle
::
framework
::
get
<
0
>
(
b
),
7
);
EXPECT_EQ
(
majel
::
get
<
1
>
(
b
),
10
);
EXPECT_EQ
(
paddle
::
framework
::
get
<
1
>
(
b
),
10
);
// dynamic access
// dynamic access
majel
::
get
(
b
,
0
)
=
8
;
paddle
::
framework
::
get
(
b
,
0
)
=
8
;
b
[
1
]
=
11
;
b
[
1
]
=
11
;
EXPECT_EQ
(
majel
::
get
<
0
>
(
b
),
8
);
EXPECT_EQ
(
paddle
::
framework
::
get
<
0
>
(
b
),
8
);
EXPECT_EQ
(
majel
::
get
<
1
>
(
b
),
11
);
EXPECT_EQ
(
paddle
::
framework
::
get
<
1
>
(
b
),
11
);
EXPECT_EQ
(
majel
::
get
(
b
,
0
),
8
);
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
...
@@ -53,49 +53,49 @@ TEST(Dim, Equality) {
...
@@ -53,49 +53,49 @@ TEST(Dim, Equality) {
EXPECT_EQ
(
res
,
6
);
EXPECT_EQ
(
res
,
6
);
// ex_prefix_mul
// ex_prefix_mul
majel
::
Dim
<
3
>
c
=
majel
::
ex_prefix_mul
(
majel
::
Dim
<
3
>
(
3
,
4
,
5
));
paddle
::
framework
::
Dim
<
3
>
c
=
paddle
::
framework
::
ex_prefix_mul
(
paddle
::
framework
::
Dim
<
3
>
(
3
,
4
,
5
));
EXPECT_EQ
(
majel
::
get
<
0
>
(
c
),
1
);
EXPECT_EQ
(
paddle
::
framework
::
get
<
0
>
(
c
),
1
);
EXPECT_EQ
(
majel
::
get
<
1
>
(
c
),
3
);
EXPECT_EQ
(
paddle
::
framework
::
get
<
1
>
(
c
),
3
);
EXPECT_EQ
(
majel
::
get
<
2
>
(
c
),
12
);
EXPECT_EQ
(
paddle
::
framework
::
get
<
2
>
(
c
),
12
);
// contiguous_strides
// contiguous_strides
c
=
majel
::
contiguous_strides
(
majel
::
Dim
<
3
>
(
10
,
1
,
10
));
c
=
paddle
::
framework
::
contiguous_strides
(
paddle
::
framework
::
Dim
<
3
>
(
10
,
1
,
10
));
EXPECT_EQ
(
majel
::
get
<
0
>
(
c
),
1
);
EXPECT_EQ
(
paddle
::
framework
::
get
<
0
>
(
c
),
1
);
EXPECT_EQ
(
majel
::
get
<
1
>
(
c
),
0
);
EXPECT_EQ
(
paddle
::
framework
::
get
<
1
>
(
c
),
0
);
EXPECT_EQ
(
majel
::
get
<
2
>
(
c
),
10
);
EXPECT_EQ
(
paddle
::
framework
::
get
<
2
>
(
c
),
10
);
c
=
majel
::
contiguous_strides
(
majel
::
Dim
<
3
>
(
10
,
10
,
1
));
c
=
paddle
::
framework
::
contiguous_strides
(
paddle
::
framework
::
Dim
<
3
>
(
10
,
10
,
1
));
EXPECT_EQ
(
majel
::
get
<
0
>
(
c
),
1
);
EXPECT_EQ
(
paddle
::
framework
::
get
<
0
>
(
c
),
1
);
EXPECT_EQ
(
majel
::
get
<
1
>
(
c
),
10
);
EXPECT_EQ
(
paddle
::
framework
::
get
<
1
>
(
c
),
10
);
EXPECT_EQ
(
majel
::
get
<
2
>
(
c
),
0
);
EXPECT_EQ
(
paddle
::
framework
::
get
<
2
>
(
c
),
0
);
c
=
majel
::
contiguous_strides
(
majel
::
Dim
<
3
>
(
1
,
10
,
10
));
c
=
paddle
::
framework
::
contiguous_strides
(
paddle
::
framework
::
Dim
<
3
>
(
1
,
10
,
10
));
EXPECT_EQ
(
majel
::
get
<
0
>
(
c
),
0
);
EXPECT_EQ
(
paddle
::
framework
::
get
<
0
>
(
c
),
0
);
EXPECT_EQ
(
majel
::
get
<
1
>
(
c
),
1
);
EXPECT_EQ
(
paddle
::
framework
::
get
<
1
>
(
c
),
1
);
EXPECT_EQ
(
majel
::
get
<
2
>
(
c
),
10
);
EXPECT_EQ
(
paddle
::
framework
::
get
<
2
>
(
c
),
10
);
c
=
majel
::
contiguous_strides
(
majel
::
Dim
<
3
>
(
2
,
3
,
4
));
c
=
paddle
::
framework
::
contiguous_strides
(
paddle
::
framework
::
Dim
<
3
>
(
2
,
3
,
4
));
EXPECT_EQ
(
majel
::
get
<
0
>
(
c
),
1
);
EXPECT_EQ
(
paddle
::
framework
::
get
<
0
>
(
c
),
1
);
EXPECT_EQ
(
majel
::
get
<
1
>
(
c
),
2
);
EXPECT_EQ
(
paddle
::
framework
::
get
<
1
>
(
c
),
2
);
EXPECT_EQ
(
majel
::
get
<
2
>
(
c
),
6
);
EXPECT_EQ
(
paddle
::
framework
::
get
<
2
>
(
c
),
6
);
// generate from an index
// generate from an index
auto
size
=
majel
::
make_dim
(
4
,
5
,
2
);
auto
size
=
paddle
::
framework
::
make_dim
(
4
,
5
,
2
);
c
=
majel
::
Dim
<
3
>
(
14
,
size
);
c
=
paddle
::
framework
::
Dim
<
3
>
(
14
,
size
);
EXPECT_EQ
(
majel
::
get
<
0
>
(
c
),
2
);
EXPECT_EQ
(
paddle
::
framework
::
get
<
0
>
(
c
),
2
);
EXPECT_EQ
(
majel
::
get
<
1
>
(
c
),
3
);
EXPECT_EQ
(
paddle
::
framework
::
get
<
1
>
(
c
),
3
);
EXPECT_EQ
(
majel
::
get
<
2
>
(
c
),
0
);
EXPECT_EQ
(
paddle
::
framework
::
get
<
2
>
(
c
),
0
);
c
=
majel
::
Dim
<
3
>
(
25
,
size
);
c
=
paddle
::
framework
::
Dim
<
3
>
(
25
,
size
);
EXPECT_EQ
(
majel
::
get
<
0
>
(
c
),
1
);
EXPECT_EQ
(
paddle
::
framework
::
get
<
0
>
(
c
),
1
);
EXPECT_EQ
(
majel
::
get
<
1
>
(
c
),
1
);
EXPECT_EQ
(
paddle
::
framework
::
get
<
1
>
(
c
),
1
);
EXPECT_EQ
(
majel
::
get
<
2
>
(
c
),
1
);
EXPECT_EQ
(
paddle
::
framework
::
get
<
2
>
(
c
),
1
);
}
}
TEST
(
Dim
,
Bool
)
{
TEST
(
Dim
,
Bool
)
{
auto
a
=
majel
::
make_dim
(
3
,
4
);
auto
a
=
paddle
::
framework
::
make_dim
(
3
,
4
);
auto
b
=
majel
::
make_dim
(
5
,
6
);
auto
b
=
paddle
::
framework
::
make_dim
(
5
,
6
);
auto
c
=
majel
::
make_dim
(
3
,
4
);
auto
c
=
paddle
::
framework
::
make_dim
(
3
,
4
);
// in_bounds check
// in_bounds check
EXPECT_TRUE
(
majel
::
contained
(
a
,
b
));
EXPECT_TRUE
(
paddle
::
framework
::
contained
(
a
,
b
));
EXPECT_FALSE
(
majel
::
contained
(
b
,
a
));
EXPECT_FALSE
(
paddle
::
framework
::
contained
(
b
,
a
));
// comparison
// comparison
EXPECT_TRUE
(
a
==
a
);
EXPECT_TRUE
(
a
==
a
);
...
@@ -104,25 +104,25 @@ TEST(Dim, Bool) {
...
@@ -104,25 +104,25 @@ TEST(Dim, Bool) {
// contiguous check
// contiguous check
int
x
=
4
,
y
=
5
,
z
=
2
;
int
x
=
4
,
y
=
5
,
z
=
2
;
majel
::
Dim
<
3
>
sizef
(
x
,
y
,
z
);
paddle
::
framework
::
Dim
<
3
>
sizef
(
x
,
y
,
z
);
majel
::
Dim
<
3
>
stridea
(
1
,
x
,
x
*
y
);
paddle
::
framework
::
Dim
<
3
>
stridea
(
1
,
x
,
x
*
y
);
majel
::
Dim
<
3
>
strideb
(
2
,
2
*
x
,
2
*
x
*
y
);
paddle
::
framework
::
Dim
<
3
>
strideb
(
2
,
2
*
x
,
2
*
x
*
y
);
majel
::
Dim
<
3
>
stridec
(
1
,
x
,
2
*
x
*
y
);
paddle
::
framework
::
Dim
<
3
>
stridec
(
1
,
x
,
2
*
x
*
y
);
EXPECT_TRUE
(
majel
::
contiguous
(
sizef
,
stridea
));
EXPECT_TRUE
(
paddle
::
framework
::
contiguous
(
sizef
,
stridea
));
EXPECT_FALSE
(
majel
::
contiguous
(
sizef
,
strideb
));
EXPECT_FALSE
(
paddle
::
framework
::
contiguous
(
sizef
,
strideb
));
EXPECT_FALSE
(
majel
::
contiguous
(
sizef
,
stridec
));
EXPECT_FALSE
(
paddle
::
framework
::
contiguous
(
sizef
,
stridec
));
}
}
TEST
(
Dim
,
Print
)
{
TEST
(
Dim
,
Print
)
{
{
{
std
::
stringstream
ss
;
std
::
stringstream
ss
;
auto
a
=
majel
::
make_dim
(
2
,
3
);
auto
a
=
paddle
::
framework
::
make_dim
(
2
,
3
);
ss
<<
a
;
ss
<<
a
;
EXPECT_EQ
(
ss
.
str
(),
"2, 3"
);
EXPECT_EQ
(
ss
.
str
(),
"2, 3"
);
}
}
{
{
std
::
stringstream
ss
;
std
::
stringstream
ss
;
ss
<<
majel
::
make_dim
(
8
);
ss
<<
paddle
::
framework
::
make_dim
(
8
);
EXPECT_EQ
(
ss
.
str
(),
"8"
);
EXPECT_EQ
(
ss
.
str
(),
"8"
);
}
}
}
}
paddle/platform/assert.h
浏览文件 @
8913aff1
...
@@ -5,28 +5,25 @@
...
@@ -5,28 +5,25 @@
#if defined(__APPLE__) && defined(__CUDA_ARCH__) && !defined(NDEBUG)
#if defined(__APPLE__) && defined(__CUDA_ARCH__) && !defined(NDEBUG)
#include <stdio.h>
#include <stdio.h>
#define
MAJEL_ASSERT(e)
\
#define
PADDLE_ASSERT(e)
\
do { \
do { \
if (!(e)) { \
if (!(e)) { \
printf(
\
printf(
"%s:%d Assertion `%s` failed.\n", __FILE__, __LINE__,
\
"%s:%d Assertion `%s` failed.\n", __FILE__, __LINE__, TOSTRING(e));
\
TOSTRING(e));
\
asm("trap;"); \
asm("trap;"); \
} \
} \
} while (0)
} while (0)
#define
MAJEL_ASSERT_MSG(e, m)
\
#define
PADDLE_ASSERT_MSG(e, m)
\
do { \
do { \
if (!(e)) { \
if (!(e)) { \
printf("%s:%d Assertion `%s` failed (%s).\n", \
printf("%s:%d Assertion `%s` failed (%s).\n", __FILE__, __LINE__, \
__FILE__, \
TOSTRING(e), m); \
__LINE__, \
TOSTRING(e), \
m); \
asm("trap;"); \
asm("trap;"); \
} \
} \
} while (0)
} while (0)
#else
#else
#include <assert.h>
#include <assert.h>
#define
MAJEL
_ASSERT(e) assert(e)
#define
PADDLE
_ASSERT(e) assert(e)
#define
MAJEL
_ASSERT_MSG(e, m) assert((e) && (m))
#define
PADDLE
_ASSERT_MSG(e, m) assert((e) && (m))
#endif
#endif
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录