Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
64a625f8
P
Paddle-Lite
项目概览
PaddlePaddle
/
Paddle-Lite
通知
332
Star
4
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
271
列表
看板
标记
里程碑
合并请求
78
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle-Lite
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
271
Issue
271
列表
看板
标记
里程碑
合并请求
78
合并请求
78
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
64a625f8
编写于
9月 30, 2018
作者:
D
dolphin8
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
cl image & half
上级
22efb06f
变更
3
展开全部
隐藏空白更改
内联
并排
Showing
3 changed file
with
511 addition
and
1 deletion
+511
-1
src/framework/cl/cl_half.cpp
src/framework/cl/cl_half.cpp
+442
-0
src/framework/cl/cl_half.h
src/framework/cl/cl_half.h
+21
-0
src/framework/cl/cl_image.h
src/framework/cl/cl_image.h
+48
-1
未找到文件。
src/framework/cl/cl_half.cpp
0 → 100644
浏览文件 @
64a625f8
此差异已折叠。
点击以展开。
src/framework/cl/cl_half.h
0 → 100644
浏览文件 @
64a625f8
/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
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 <cstdint>
typedef
uint16_t
half_t
;
half_t
float2half
(
float
f
);
float
half2float
(
half_t
h
);
\ No newline at end of file
src/framework/cl/cl_image.h
浏览文件 @
64a625f8
...
...
@@ -17,6 +17,7 @@ limitations under the License. */
#include "framework/ddim.h"
#include "framework/tensor.h"
#include "CL/cl.h"
#include "cl_half.h"
namespace
paddle_mobile
{
namespace
framework
{
...
...
@@ -26,10 +27,56 @@ class CLImage {
CLImage
()
=
default
;
void
Init
(
cl_context
context
,
float
*
tensorInput
,
DDim
ddim
)
{
cl_image_format
cf
=
{
.
image_channel_order
=
CL_RGBA
,
.
image_channel_data_type
=
CL_HALF_FLOAT
};
// NCHW -> [W * (C+3)/4, H * N]
size_t
N
=
tensorDims_
[
0
];
size_t
C
=
tensorDims_
[
1
];
size_t
H
=
tensorDims_
[
2
];
size_t
W
=
tensorDims_
[
3
];
size_t
width
=
W
*
((
C
+
3
)
/
4
);
size_t
height
=
H
*
N
;
std
::
unique_ptr
<
half_t
[]
>
imageData
();
if
(
tensorInput
!=
nullptr
)
{
imageData
.
reset
(
new
half_t
[
width
*
height
*
4
]);
float
*
p
=
tensorInput
;
size_t
i0
=
0
;
for
(
int
n
=
0
;
n
<
N
;
n
++
)
{
for
(
int
c
=
0
;
c
<
C
;
c
++
)
{
size_t
i1
=
i0
;
for
(
int
h
=
0
;
h
<
H
;
h
++
)
{
size_t
i2
=
i1
<<
2
+
c
%
4
;
for
(
int
w
=
0
;
w
<
W
;
w
++
)
{
imageData
[
i2
]
=
float2half
(
*
p
);
i2
+=
4
;
p
++
;
}
i1
+=
width
;
}
}
i0
+=
width
*
H
;
}
}
cl_int
err
;
cl_image_
=
clCreateImage2D
(
context
,
// cl_context context
CL_MEM_READ_WRITE
|
CL_MEM_COPY_HOST_PTR
,
// cl_mem_flags flags
&
cf
,
// const cl_image_format *image_format
width
,
// size_t image_width
height
,
// size_t image_height
0
,
// size_t image_row_pitch
reinterpret_cast
<
void
*>
(
imageData
.
get
()),
// void *host_ptr
&
err
// cl_int *errcode_ret
);
if
(
err
!=
CL_SUCCESS
)
{
// TODO: error handling
}
}
void
Init
(
cl_context
context
,
DDim
ddim
)
{
Init
(
cl_context
context
,
nullptr
,
DDim
ddim
);
}
inline
CLImage
&
Resize
(
const
DDim
&
dims
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录