Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
14cdf84c
P
Paddle-Lite
项目概览
PaddlePaddle
/
Paddle-Lite
通知
331
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看板
提交
14cdf84c
编写于
10月 17, 2018
作者:
R
Ray Liu
提交者:
GitHub
10月 17, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1115 from codeWorm2015/opencl
update cl tensor
上级
d9ed6f14
ca9f3648
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
70 addition
and
76 deletion
+70
-76
src/framework/cl/cl_tensor.h
src/framework/cl/cl_tensor.h
+41
-44
src/framework/tensor.h
src/framework/tensor.h
+28
-0
src/framework/tensor_base.h
src/framework/tensor_base.h
+0
-30
src/operators/kernel/cl/feed_kernel.cpp
src/operators/kernel/cl/feed_kernel.cpp
+1
-2
未找到文件。
src/framework/cl/cl_tensor.h
浏览文件 @
14cdf84c
...
...
@@ -48,16 +48,15 @@ class CLTensor : TensorBase {
return
*
this
;
}
template
<
typename
T
>
inline
T
mutable_with_data
(
void
*
data
)
{
inline
cl_mem
mutable_with_data
(
void
*
data
)
{
int64_t
size
=
numel
()
*
sizeof
(
float
);
holder_
.
reset
(
new
PlaceholderImpl
(
size
,
data
,
typeid
(
T
),
context_
,
command_queue_
));
return
reinterpret_cast
<
T
>
(
holder_
.
reset
(
new
PlaceholderImpl
(
size
,
data
,
typeid
(
cl_mem
),
context_
,
command_queue_
));
return
reinterpret_cast
<
cl_mem
>
(
reinterpret_cast
<
void
*>
(
reinterpret_cast
<
uintptr_t
>
(
holder_
->
ptr
())));
}
inline
void
*
mutable_data
(
std
::
type_index
type
)
{
inline
cl_mem
mutable_data
(
std
::
type_index
type
)
{
if
(
holder_
!=
nullptr
)
{
holder_
->
set_type
(
type
);
}
...
...
@@ -67,22 +66,20 @@ class CLTensor : TensorBase {
holder_
.
reset
(
new
PlaceholderImpl
(
size
,
type
,
context_
,
command_queue_
));
offset_
=
0
;
}
return
reinterpret_cast
<
void
*>
(
reinterpret_cast
<
uintptr_t
>
(
holder_
->
ptr
())
+
offset_
);
return
reinterpret_cast
<
cl_mem
>
(
holder_
->
ptr
());
}
/**
* @brief Return a pointer to
mutable memory block
.
* @brief Return a pointer to
cl buffer
.
* @note If not exist, then allocation.
*/
template
<
typename
T
>
inline
T
*
mutable_data
()
{
static_assert
(
std
::
is_pod
<
T
>::
value
,
"T must be POD"
);
return
reinterpret_cast
<
T
*>
(
mutable_data
(
typeid
(
T
)));
inline
cl_mem
mutable_data
()
{
return
reinterpret_cast
<
cl_mem
>
(
mutable_data
(
typeid
(
T
)));
}
/**
* @brief Return a pointer to
mutable memory block
.
* @brief Return a pointer to
cl buffer
.
*
* @param[in] dims The dimensions of the memory block.
* @param[in] place The place of the memory block.
...
...
@@ -90,27 +87,44 @@ class CLTensor : TensorBase {
* @note If not exist, then allocation.
*/
template
<
typename
T
>
inline
T
*
mutable_data
(
DDim
dims
)
{
static_assert
(
std
::
is_pod
<
T
>::
value
,
"T must be POD"
);
inline
cl_mem
mutable_data
(
DDim
dims
)
{
Resize
(
dims
);
return
mutable_data
<
T
>
();
}
private:
cl_context
context_
;
cl_command_queue
command_queue_
;
/*
* virtual ~Placeholder() = default;
inline
cl_mem
CLBuffer
()
{
check_memory_size
();
return
reinterpret_cast
<
cl_mem
>
(
reinterpret_cast
<
uintptr_t
>
(
holder_
->
ptr
())
+
offset_
);
}
virtual void *ptr() const = 0;
template
<
typename
T
>
inline
T
*
Data
()
{
if
(
host_ptr_
)
{
delete
(
host_ptr_
);
host_ptr_
=
nullptr
;
}
cl_mem
buffer
=
CLBuffer
();
host_ptr_
=
new
char
[
holder_
->
size
()];
cl_int
status
;
status
=
clEnqueueReadBuffer
(
command_queue_
,
buffer
,
CL_TRUE
,
0
,
holder_
->
size
(),
host_ptr_
,
0
,
NULL
,
NULL
);
CL_CHECK_ERRORS
(
status
);
return
reinterpret_cast
<
T
*>
(
host_ptr_
);
}
virtual size_t size() const = 0;
~
CLTensor
()
{
if
(
host_ptr_
)
{
delete
(
host_ptr_
);
host_ptr_
=
nullptr
;
}
}
virtual std::type_index type() const = 0;
private:
cl_context
context_
;
cl_command_queue
command_queue_
;
void
*
host_ptr_
;
virtual void set_type(std::type_index type) = 0;
* */
struct
PlaceholderImpl
:
public
Placeholder
{
PlaceholderImpl
(
size_t
size
,
void
*
input
,
std
::
type_index
type
,
cl_context
context
,
cl_command_queue
command_queue
)
...
...
@@ -129,15 +143,7 @@ class CLTensor : TensorBase {
virtual
size_t
size
()
const
{
return
size_
;
}
virtual
void
*
ptr
()
const
{
if
(
host_ptr_
)
{
delete
(
host_ptr_
);
}
char
*
host_ptr
=
new
char
[
size_
];
clEnqueueReadBuffer
(
command_queue_
,
ptr_
.
get
(),
CL_TRUE
,
0
,
size_
,
host_ptr
,
0
,
NULL
,
NULL
);
return
static_cast
<
void
*>
(
host_ptr
);
}
virtual
void
*
ptr
()
const
{
return
static_cast
<
void
*>
(
ptr_
.
get
());
}
virtual
std
::
type_index
type
()
const
{
return
type_
;
}
...
...
@@ -151,15 +157,6 @@ class CLTensor : TensorBase {
std
::
type_index
type_
;
cl_command_queue
command_queue_
;
~
PlaceholderImpl
()
{
if
(
host_ptr_
)
{
delete
(
host_ptr_
);
}
}
private:
void
*
host_ptr_
;
};
};
...
...
src/framework/tensor.h
浏览文件 @
14cdf84c
...
...
@@ -157,6 +157,34 @@ class Tensor : public TensorBase {
}
}
/*! Return a pointer to mutable memory block. */
template
<
typename
T
>
inline
T
*
data
()
{
check_memory_size
();
PADDLE_MOBILE_ENFORCE
(
(
std
::
is_same
<
T
,
void
>::
value
||
holder_
->
type
().
hash_code
()
==
typeid
(
T
).
hash_code
()),
"Tensor holds the wrong type, it holds %s"
,
this
->
holder_
->
type
().
name
());
return
reinterpret_cast
<
T
*>
(
reinterpret_cast
<
uintptr_t
>
(
holder_
->
ptr
())
+
offset_
);
}
/*! Return a pointer to constant memory block. */
template
<
typename
T
>
inline
const
T
*
data
()
const
{
check_memory_size
();
PADDLE_MOBILE_ENFORCE
(
(
std
::
is_same
<
T
,
void
>::
value
||
holder_
->
type
().
hash_code
()
==
typeid
(
T
).
hash_code
()),
"Tensor holds the wrong type, it holds %s ,requested:%s"
,
this
->
holder_
->
type
().
name
(),
typeid
(
T
).
name
());
return
reinterpret_cast
<
const
T
*>
(
reinterpret_cast
<
uintptr_t
>
(
holder_
->
ptr
())
+
offset_
);
}
private:
struct
PlaceholderImpl
:
public
Placeholder
{
PlaceholderImpl
(
size_t
size
,
std
::
type_index
type
)
...
...
src/framework/tensor_base.h
浏览文件 @
14cdf84c
...
...
@@ -72,36 +72,6 @@ class TensorBase {
inline
bool
IsInitialized
()
const
{
return
holder_
!=
nullptr
;
}
virtual
inline
void
*
mutable_data
(
std
::
type_index
type
)
=
0
;
/*! Return a pointer to mutable memory block. */
template
<
typename
T
>
inline
T
*
data
()
{
check_memory_size
();
PADDLE_MOBILE_ENFORCE
(
(
std
::
is_same
<
T
,
void
>::
value
||
holder_
->
type
().
hash_code
()
==
typeid
(
T
).
hash_code
()),
"Tensor holds the wrong type, it holds %s"
,
this
->
holder_
->
type
().
name
());
return
reinterpret_cast
<
T
*>
(
reinterpret_cast
<
uintptr_t
>
(
holder_
->
ptr
())
+
offset_
);
}
/*! Return a pointer to constant memory block. */
template
<
typename
T
>
inline
const
T
*
data
()
const
{
check_memory_size
();
PADDLE_MOBILE_ENFORCE
(
(
std
::
is_same
<
T
,
void
>::
value
||
holder_
->
type
().
hash_code
()
==
typeid
(
T
).
hash_code
()),
"Tensor holds the wrong type, it holds %s ,requested:%s"
,
this
->
holder_
->
type
().
name
(),
typeid
(
T
).
name
());
return
reinterpret_cast
<
const
T
*>
(
reinterpret_cast
<
uintptr_t
>
(
holder_
->
ptr
())
+
offset_
);
}
/*! Return the dimensions of the memory block. */
inline
const
DDim
&
dims
()
const
{
return
dims_
;
}
...
...
src/operators/kernel/cl/feed_kernel.cpp
浏览文件 @
14cdf84c
...
...
@@ -39,8 +39,7 @@ void FeedKernel<GPU_CL, float>::Compute(const FeedParam<GPU_CL> ¶m) {
CLTensor
input_cl_tensor
(
this
->
cl_helper_
.
CLContext
(),
this
->
cl_helper_
.
CLCommandQueue
());
input_cl_tensor
.
Resize
(
input
->
dims
());
cl_mem
inputBuffer
=
input_cl_tensor
.
mutable_with_data
<
cl_mem
>
((
void
*
)
input_data
);
cl_mem
inputBuffer
=
input_cl_tensor
.
mutable_with_data
((
void
*
)
input_data
);
status
=
clSetKernelArg
(
kernel
,
0
,
sizeof
(
cl_mem
),
(
void
*
)
&
inputBuffer
);
CL_CHECK_ERRORS
(
status
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录