Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
s920243400
PaddleDetection
提交
110a4022
P
PaddleDetection
项目概览
s920243400
/
PaddleDetection
与 Fork 源项目一致
Fork自
PaddlePaddle / PaddleDetection
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
110a4022
编写于
5月 18, 2017
作者:
F
fengjiayi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
make up missing 'majel::' and import majel/util.h
上级
051f0b99
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
55 addition
and
21 deletion
+55
-21
paddle/majel/dim.h
paddle/majel/dim.h
+7
-12
paddle/majel/test/dim_test.cu
paddle/majel/test/dim_test.cu
+9
-9
paddle/majel/util.h
paddle/majel/util.h
+39
-0
未找到文件。
paddle/majel/dim.h
浏览文件 @
110a4022
...
@@ -4,14 +4,9 @@
...
@@ -4,14 +4,9 @@
#include <sstream>
#include <sstream>
#include <stdexcept>
#include <stdexcept>
#include <type_traits>
#include <type_traits>
/*
#ifdef __CUDACC__
#include <host_defines.h>
#endif
*/
#include "hostdevice.h"
#include "
majel/
hostdevice.h"
#include "
paddle/utils/Logging
.h"
#include "
majel/util
.h"
namespace
majel
{
namespace
majel
{
...
@@ -79,7 +74,7 @@ struct Dim<1> {
...
@@ -79,7 +74,7 @@ struct Dim<1> {
throw
std
::
invalid_argument
(
"Index out of range."
);
throw
std
::
invalid_argument
(
"Index out of range."
);
}
}
#else
#else
CHECK
(
idx
<
size
.
head
);
MAJEL_ASSERT
(
idx
<
size
.
head
);
#endif
#endif
}
}
...
@@ -136,7 +131,7 @@ HOSTDEVICE int& indexer(Dim<D>& dim, int idx) {
...
@@ -136,7 +131,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
CHECK
(
idx
>=
0
);
MAJEL_ASSERT
(
idx
>=
0
);
#endif
#endif
if
(
idx
==
0
)
{
if
(
idx
==
0
)
{
return
dim
.
head
;
return
dim
.
head
;
...
@@ -151,7 +146,7 @@ HOSTDEVICE int& indexer<1>(Dim<1>& dim, int idx) {
...
@@ -151,7 +146,7 @@ HOSTDEVICE int& indexer<1>(Dim<1>& dim, int idx) {
throw
std
::
invalid_argument
(
"Invalid index"
);
throw
std
::
invalid_argument
(
"Invalid index"
);
}
}
#else
#else
CHECK
(
idx
==
0
);
MAJEL_ASSERT
(
idx
==
0
);
#endif
#endif
return
dim
.
head
;
return
dim
.
head
;
}
}
...
@@ -163,7 +158,7 @@ HOSTDEVICE int indexer(const Dim<D>& dim, int idx) {
...
@@ -163,7 +158,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
CHECK
(
idx
>=
0
);
MAJEL_ASSERT
(
idx
>=
0
);
#endif
#endif
if
(
idx
==
0
)
{
if
(
idx
==
0
)
{
return
dim
.
head
;
return
dim
.
head
;
...
@@ -178,7 +173,7 @@ HOSTDEVICE int indexer<1>(const Dim<1>& dim, int idx) {
...
@@ -178,7 +173,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
CHECK
(
idx
==
0
);
MAJEL_ASSERT
(
idx
==
0
);
#endif
#endif
return
dim
.
head
;
return
dim
.
head
;
}
}
...
...
paddle/majel/test/dim_test.cu
浏览文件 @
110a4022
#include <thrust/device_vector.h>
#include <thrust/device_vector.h>
#include <sstream>
#include <sstream>
#include "majel/dim.h"
#include "majel/dim.h"
#include "gtest/gtest.h"
#include "gtest/gtest.h"
__global__
void
test
(
majel
::
Dim
<
2
>*
o
)
{
__global__
void
test
(
majel
::
Dim
<
2
>*
o
)
{
...
@@ -16,22 +16,22 @@ __global__ void dyn_idx_gpu(int* o) {
...
@@ -16,22 +16,22 @@ __global__ void dyn_idx_gpu(int* o) {
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
=
majel
::
make_dim
(
3
,
4
);
EXPECT_EQ
(
get
<
0
>
(
a
),
3
);
EXPECT_EQ
(
majel
::
get
<
0
>
(
a
),
3
);
EXPECT_EQ
(
get
<
1
>
(
a
),
4
);
EXPECT_EQ
(
majel
::
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
<
majel
::
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
(
get
<
0
>
(
a
),
5
);
EXPECT_EQ
(
majel
::
get
<
0
>
(
a
),
5
);
EXPECT_EQ
(
get
<
1
>
(
a
),
6
);
EXPECT_EQ
(
majel
::
get
<
1
>
(
a
),
6
);
// linearization
// linearization
auto
b
=
make_dim
(
7
,
8
);
auto
b
=
ma
jel
::
ma
ke_dim
(
7
,
8
);
EXPECT_EQ
(
linearize
(
a
,
b
),
83
);
EXPECT_EQ
(
majel
::
linearize
(
a
,
b
),
83
);
// product
// product
EXPECT_EQ
(
product
(
a
),
30
);
EXPECT_EQ
(
majel
::
product
(
a
),
30
);
// mutate a Dim
// mutate a Dim
majel
::
get
<
1
>
(
b
)
=
10
;
majel
::
get
<
1
>
(
b
)
=
10
;
...
@@ -53,7 +53,7 @@ TEST(Dim, Equality) {
...
@@ -53,7 +53,7 @@ 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
(
Dim
<
3
>
(
3
,
4
,
5
));
majel
::
Dim
<
3
>
c
=
majel
::
ex_prefix_mul
(
majel
::
Dim
<
3
>
(
3
,
4
,
5
));
EXPECT_EQ
(
majel
::
get
<
0
>
(
c
),
1
);
EXPECT_EQ
(
majel
::
get
<
0
>
(
c
),
1
);
EXPECT_EQ
(
majel
::
get
<
1
>
(
c
),
3
);
EXPECT_EQ
(
majel
::
get
<
1
>
(
c
),
3
);
EXPECT_EQ
(
majel
::
get
<
2
>
(
c
),
12
);
EXPECT_EQ
(
majel
::
get
<
2
>
(
c
),
12
);
...
...
paddle/majel/util.h
0 → 100644
浏览文件 @
110a4022
#pragma once
#define STRINGIFY(x) #x
#define TOSTRING(x) STRINGIFY(x)
#if defined(__APPLE__) && defined(__CUDA_ARCH__) && !defined(NDEBUG)
#include <stdio.h>
#define MAJEL_ASSERT(e) \
do { \
if (!(e)) { \
printf( \
"%s:%d Assertion `%s` failed.\n", __FILE__, __LINE__, TOSTRING(e)); \
asm("trap;"); \
} \
} while (0)
#define MAJEL_ASSERT_MSG(e, m) \
do { \
if (!(e)) { \
printf("%s:%d Assertion `%s` failed (%s).\n", \
__FILE__, \
__LINE__, \
TOSTRING(e), \
m); \
asm("trap;"); \
} \
} while (0)
#else
#include <assert.h>
#define MAJEL_ASSERT(e) assert(e)
#define MAJEL_ASSERT_MSG(e, m) assert((e) && (m))
#endif
namespace
majel
{
namespace
detail
{
inline
int
div_up
(
int
x
,
int
y
)
{
return
(
x
+
y
-
1
)
/
y
;
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录