Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
b1a5a3ca
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
大约 1 年 前同步成功
通知
695
Star
11112
Fork
2696
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
184
列表
看板
标记
里程碑
合并请求
40
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
184
Issue
184
列表
看板
标记
里程碑
合并请求
40
合并请求
40
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
b1a5a3ca
编写于
4月 08, 2018
作者:
Y
Yi Wang
提交者:
GitHub
4月 08, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix cpplint errors with float16* (#9751)
上级
2b7e5bd3
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
43 addition
and
39 deletion
+43
-39
paddle/fluid/platform/float16_test.cc
paddle/fluid/platform/float16_test.cc
+22
-18
paddle/fluid/platform/float16_test.cu
paddle/fluid/platform/float16_test.cu
+21
-21
未找到文件。
paddle/fluid/platform/float16_test.cc
浏览文件 @
b1a5a3ca
...
...
@@ -8,13 +8,14 @@ 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. */
#include "paddle/fluid/platform/float16.h"
#include <vector>
#include "gtest/gtest.h"
#include "paddle/fluid/framework/init.h"
#include "paddle/fluid/framework/lod_tensor.h"
#include <gtest/gtest.h>
namespace
paddle
{
namespace
platform
{
...
...
@@ -74,24 +75,27 @@ TEST(float16, conversion_cpu) {
// Conversion operator
EXPECT_EQ
(
Eigen
::
half
(
float16
(
1.0
f
)).
x
,
0x3c00
);
EXPECT_EQ
(
float
(
float16
(
0.5
f
)),
0.5
f
);
EXPECT_NEAR
(
double
(
float16
(
0.33333
)),
0.33333
,
0.0001
);
EXPECT_EQ
(
int
(
float16
(
-
1
)),
-
1
);
EXPECT_EQ
(
bool
(
float16
(
true
)),
true
);
EXPECT_EQ
(
static_cast
<
float
>
(
float16
(
0.5
f
)),
0.5
f
);
EXPECT_NEAR
(
static_cast
<
double
>
(
float16
(
0.33333
)),
0.33333
,
0.0001
);
EXPECT_EQ
(
static_cast
<
int
>
(
float16
(
-
1
)),
-
1
);
EXPECT_EQ
(
static_cast
<
bool
>
(
float16
(
true
)),
true
);
}
TEST
(
float16
,
arithmetic_cpu
)
{
EXPECT_EQ
(
float
(
float16
(
1
)
+
float16
(
1
)),
2
);
EXPECT_EQ
(
float
(
float16
(
5
)
+
float16
(
-
5
)),
0
);
EXPECT_NEAR
(
float
(
float16
(
0.33333
f
)
+
float16
(
0.66667
f
)),
1.0
f
,
0.001
);
EXPECT_EQ
(
float
(
float16
(
3
)
-
float16
(
5
)),
-
2
);
EXPECT_NEAR
(
float
(
float16
(
0.66667
f
)
-
float16
(
0.33333
f
)),
0.33334
f
,
0.001
);
EXPECT_NEAR
(
float
(
float16
(
3.3
f
)
*
float16
(
2.0
f
)),
6.6
f
,
0.01
);
EXPECT_NEAR
(
float
(
float16
(
-
2.1
f
)
*
float16
(
-
3.0
f
)),
6.3
f
,
0.01
);
EXPECT_NEAR
(
float
(
float16
(
2.0
f
)
/
float16
(
3.0
f
)),
0.66667
f
,
0.001
);
EXPECT_EQ
(
float
(
float16
(
1.0
f
)
/
float16
(
2.0
f
)),
0.5
f
);
EXPECT_EQ
(
float
(
-
float16
(
512.0
f
)),
-
512.0
f
);
EXPECT_EQ
(
float
(
-
float16
(
-
512.0
f
)),
512.0
f
);
EXPECT_EQ
(
static_cast
<
float
>
(
float16
(
1
)
+
float16
(
1
)),
2
);
EXPECT_EQ
(
static_cast
<
float
>
(
float16
(
5
)
+
float16
(
-
5
)),
0
);
EXPECT_NEAR
(
static_cast
<
float
>
(
float16
(
0.33333
f
)
+
float16
(
0.66667
f
)),
1.0
f
,
0.001
);
EXPECT_EQ
(
static_cast
<
float
>
(
float16
(
3
)
-
float16
(
5
)),
-
2
);
EXPECT_NEAR
(
static_cast
<
float
>
(
float16
(
0.66667
f
)
-
float16
(
0.33333
f
)),
0.33334
f
,
0.001
);
EXPECT_NEAR
(
static_cast
<
float
>
(
float16
(
3.3
f
)
*
float16
(
2.0
f
)),
6.6
f
,
0.01
);
EXPECT_NEAR
(
static_cast
<
float
>
(
float16
(
-
2.1
f
)
*
float16
(
-
3.0
f
)),
6.3
f
,
0.01
);
EXPECT_NEAR
(
static_cast
<
float
>
(
float16
(
2.0
f
)
/
float16
(
3.0
f
)),
0.66667
f
,
0.001
);
EXPECT_EQ
(
static_cast
<
float
>
(
float16
(
1.0
f
)
/
float16
(
2.0
f
)),
0.5
f
);
EXPECT_EQ
(
static_cast
<
float
>
(
-
float16
(
512.0
f
)),
-
512.0
f
);
EXPECT_EQ
(
static_cast
<
float
>
(
-
float16
(
-
512.0
f
)),
512.0
f
);
}
TEST
(
float16
,
comparison_cpu
)
{
...
...
paddle/fluid/platform/float16_test.cu
浏览文件 @
b1a5a3ca
...
...
@@ -36,19 +36,19 @@ limitations under the License. */
half *in1, *in2, *out; \
half *d_in1, *d_in2, *d_out; \
int size = sizeof(half); \
cudaMalloc(
(void**)&d_in1, size);
\
cudaMalloc(
(void**)&d_in2, size);
\
cudaMalloc(
(void**)&d_out, size);
\
in1 =
(half*)malloc(size);
\
in2 =
(half*)malloc(size);
\
out =
(half*)malloc(size);
\
cudaMalloc(
reinterpret_cast<void**>(&d_in1), size);
\
cudaMalloc(
reinterpret_cast<void**>(&d_in2), size);
\
cudaMalloc(
reinterpret_cast<void**>(&d_out), size);
\
in1 =
reinterpret_cast<half*>(malloc(size));
\
in2 =
reinterpret_cast<half*>(malloc(size));
\
out =
reinterpret_cast<half*>(malloc(size));
\
in1[0] = half(float16(v_in1)); \
in2[0] = half(float16(v_in2)); \
cudaMemcpy(d_in1, in1, size, cudaMemcpyHostToDevice); \
cudaMemcpy(d_in2, in2, size, cudaMemcpyHostToDevice); \
op_type<<<1, 1>>>(d_in1, d_in2, d_out); \
cudaMemcpy(out, d_out, size, cudaMemcpyDeviceToHost); \
EXPECT_EQ(
float(float16(out[0])), v_out);
\
EXPECT_EQ(
static_cast<float>(float16(out[0])), v_out);
\
free(in1); \
free(in2); \
free(out); \
...
...
@@ -63,17 +63,17 @@ limitations under the License. */
half *in1, *in2; \
half *d_in1, *d_in2; \
int size = sizeof(half); \
cudaMalloc(
(void**)&d_in1, size);
\
cudaMalloc(
(void**)&d_in2, size);
\
in1 =
(half*)malloc(size);
\
in2 =
(half*)malloc(size);
\
cudaMalloc(
reinterpret_cast<void**>(&d_in1), size);
\
cudaMalloc(
reinterpret_cast<void**>(&d_in2), size);
\
in1 =
reinterpret_cast<half*>(malloc(size));
\
in2 =
reinterpret_cast<half*>(malloc(size));
\
in1[0] = half(float16(v_in1)); \
in2[0] = half(float16(v_in2)); \
cudaMemcpy(d_in1, in1, size, cudaMemcpyHostToDevice); \
cudaMemcpy(d_in2, in2, size, cudaMemcpyHostToDevice); \
op_type<<<1, 1>>>(d_in1, d_in2); \
cudaMemcpy(in1, d_in1, size, cudaMemcpyDeviceToHost); \
EXPECT_EQ(
float(float16(in1[0])), v_out);
\
EXPECT_EQ(
static_cast<float>(float16(in1[0])), v_out);
\
free(in1); \
free(in2); \
cudaFree(d_in1); \
...
...
@@ -87,12 +87,12 @@ limitations under the License. */
half *d_in1, *d_in2; \
bool *out, *d_out; \
int size = sizeof(half); \
cudaMalloc(
(void**)&d_in1, size);
\
cudaMalloc(
(void**)&d_in2, size);
\
cudaMalloc(
(void**)&d_out, 1);
\
in1 =
(half*)malloc(size);
\
in2 =
(half*)malloc(size);
\
out =
(bool*)malloc(1);
\
cudaMalloc(
reinterpret_cast<void**>(&d_in1), size);
\
cudaMalloc(
reinterpret_cast<void**>(&d_in2), size);
\
cudaMalloc(
reinterpret_cast<void**>(&d_out), 1);
\
in1 =
reinterpret_cast<half*>(malloc(size));
\
in2 =
reinterpret_cast<half*>(malloc(size));
\
out =
reinterpret_cast<bool*>(malloc(1));
\
in1[0] = half(float16(v_in1)); \
in2[0] = half(float16(v_in2)); \
cudaMemcpy(d_in1, in1, size, cudaMemcpyHostToDevice); \
...
...
@@ -130,13 +130,13 @@ void TestNeg(float v_in, float v_out) {
LOG
(
INFO
)
<<
"Test Neg on GPU!"
;
half
*
in
,
*
d_in
;
int
size
=
sizeof
(
half
);
cudaMalloc
(
(
void
**
)
&
d_in
,
size
);
in
=
(
half
*
)
malloc
(
size
);
cudaMalloc
(
reinterpret_cast
<
void
**>
(
&
d_in
)
,
size
);
in
=
reinterpret_cast
<
half
*>
(
malloc
(
size
)
);
in
[
0
]
=
half
(
float16
(
v_in
));
cudaMemcpy
(
d_in
,
in
,
size
,
cudaMemcpyHostToDevice
);
Neg
<<<
1
,
1
>>>
(
d_in
);
cudaMemcpy
(
in
,
d_in
,
size
,
cudaMemcpyDeviceToHost
);
EXPECT_EQ
(
float
(
float16
(
in
[
0
])),
v_out
);
EXPECT_EQ
(
static_cast
<
float
>
(
float16
(
in
[
0
])),
v_out
);
free
(
in
);
cudaFree
(
d_in
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录