Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
Actor Framework
Commits
ac4f96fb
Commit
ac4f96fb
authored
Dec 17, 2013
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
API refactoring
parent
964c198b
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
69 additions
and
89 deletions
+69
-89
libcaf_opencl/cppa/opencl/actor_facade.hpp
libcaf_opencl/cppa/opencl/actor_facade.hpp
+69
-89
No files found.
libcaf_opencl/cppa/opencl/actor_facade.hpp
View file @
ac4f96fb
...
...
@@ -28,7 +28,6 @@
* along with libcppa. If not, see <http://www.gnu.org/licenses/>. *
\******************************************************************************/
#ifndef CPPA_OPENCL_ACTOR_FACADE_HPP
#define CPPA_OPENCL_ACTOR_FACADE_HPP
...
...
@@ -55,34 +54,35 @@
#include "cppa/detail/scheduled_actor_dummy.hpp"
namespace
cppa
{
namespace
opencl
{
namespace
cppa
{
namespace
opencl
{
class
opencl_metainfo
;
template
<
typename
Signature
>
template
<
typename
Signature
>
class
actor_facade
;
template
<
typename
Ret
,
typename
...
Args
>
class
actor_facade
<
Ret
(
Args
...)
>
:
public
actor
{
template
<
typename
Ret
,
typename
...
Args
>
class
actor_facade
<
Ret
(
Args
...)
>
:
public
a
bstract_a
ctor
{
friend
class
command
<
actor_facade
,
Ret
>
;
public:
typedef
cow_tuple
<
typename
util
::
rm_const_and_ref
<
Args
>::
type
...
>
args_tuple
;
typedef
cow_tuple
<
typename
util
::
rm_const_and_ref
<
Args
>::
type
...
>
args_tuple
;
typedef
std
::
function
<
optional
<
args_tuple
>
(
any_tuple
)
>
arg_mapping
;
typedef
std
::
function
<
any_tuple
(
Ret
&
)
>
result_mapping
;
static
intrusive_ptr
<
actor_facade
>
create
(
const
program
&
prog
,
const
char
*
kernel_name
,
arg_mapping
map_args
,
result_mapping
map_result
,
const
dim_vec
&
global_dims
,
const
dim_vec
&
offsets
,
const
dim_vec
&
local_dims
)
{
static
intrusive_ptr
<
actor_facade
>
create
(
const
program
&
prog
,
const
char
*
kernel_name
,
arg_mapping
map_args
,
result_mapping
map_result
,
const
dim_vec
&
global_dims
,
const
dim_vec
&
offsets
,
const
dim_vec
&
local_dims
)
{
if
(
global_dims
.
empty
())
{
auto
str
=
"OpenCL kernel needs at least 1 global dimension."
;
CPPA_LOGM_ERROR
(
detail
::
demangle
(
typeid
(
actor_facade
)).
c_str
(),
str
);
CPPA_LOGM_ERROR
(
detail
::
demangle
(
typeid
(
actor_facade
)).
c_str
(),
str
);
throw
std
::
runtime_error
(
str
);
}
auto
check_vec
=
[
&
](
const
dim_vec
&
vec
,
const
char
*
name
)
{
...
...
@@ -90,30 +90,27 @@ class actor_facade<Ret(Args...)> : public actor {
std
::
ostringstream
oss
;
oss
<<
name
<<
" vector is not empty, but "
<<
"its size differs from global dimensions vector's size"
;
CPPA_LOGM_ERROR
(
detail
::
demangle
<
actor_facade
>
().
c_str
(),
oss
.
str
());
CPPA_LOGM_ERROR
(
detail
::
demangle
<
actor_facade
>
().
c_str
(),
oss
.
str
());
throw
std
::
runtime_error
(
oss
.
str
());
}
};
check_vec
(
offsets
,
"offsets"
);
check_vec
(
local_dims
,
"local dimensions"
);
cl_int
err
{
0
};
cl_int
err
{
0
};
kernel_ptr
kernel
;
kernel
.
adopt
(
clCreateKernel
(
prog
.
m_program
.
get
(),
kernel_name
,
&
err
));
kernel
.
adopt
(
clCreateKernel
(
prog
.
m_program
.
get
(),
kernel_name
,
&
err
));
if
(
err
!=
CL_SUCCESS
)
{
std
::
ostringstream
oss
;
oss
<<
"clCreateKernel: "
<<
get_opencl_error
(
err
);
CPPA_LOGM_ERROR
(
detail
::
demangle
<
actor_facade
>
().
c_str
(),
oss
.
str
());
CPPA_LOGM_ERROR
(
detail
::
demangle
<
actor_facade
>
().
c_str
(),
oss
.
str
());
throw
std
::
runtime_error
(
oss
.
str
());
}
return
new
actor_facade
<
Ret
(
Args
...)
>
{
prog
,
kernel
,
global_dims
,
offsets
,
local_dims
,
std
::
move
(
map_args
),
std
::
move
(
map_result
)};
return
new
actor_facade
<
Ret
(
Args
...)
>
{
prog
,
kernel
,
global_dims
,
offsets
,
local_dims
,
std
::
move
(
map_args
),
std
::
move
(
map_result
)
};
}
void
enqueue
(
const
message_header
&
hdr
,
any_tuple
msg
)
override
{
...
...
@@ -124,47 +121,38 @@ class actor_facade<Ret(Args...)> : public actor {
private:
actor_facade
(
const
program
&
prog
,
kernel_ptr
kernel
,
actor_facade
(
const
program
&
prog
,
kernel_ptr
kernel
,
const
dim_vec
&
global_dimensions
,
const
dim_vec
&
global_offsets
,
const
dim_vec
&
local_dimensions
,
arg_mapping
map_args
,
result_mapping
map_result
)
:
m_kernel
(
kernel
)
,
m_program
(
prog
.
m_program
)
,
m_context
(
prog
.
m_context
)
,
m_queue
(
prog
.
m_queue
)
,
m_global_dimensions
(
global_dimensions
)
,
m_global_offsets
(
global_offsets
)
,
m_local_dimensions
(
local_dimensions
)
,
m_map_args
(
std
::
move
(
map_args
))
,
m_map_result
(
std
::
move
(
map_result
))
{
const
dim_vec
&
global_offsets
,
const
dim_vec
&
local_dimensions
,
arg_mapping
map_args
,
result_mapping
map_result
)
:
m_kernel
(
kernel
),
m_program
(
prog
.
m_program
),
m_context
(
prog
.
m_context
),
m_queue
(
prog
.
m_queue
),
m_global_dimensions
(
global_dimensions
),
m_global_offsets
(
global_offsets
),
m_local_dimensions
(
local_dimensions
),
m_map_args
(
std
::
move
(
map_args
)),
m_map_result
(
std
::
move
(
map_result
))
{
CPPA_LOG_TRACE
(
"id: "
<<
this
->
id
());
}
template
<
long
...
Is
>
void
enqueue_impl
(
const
actor_ptr
&
sender
,
any_tuple
msg
,
message_id
id
,
template
<
long
...
Is
>
void
enqueue_impl
(
const
actor_ptr
&
sender
,
any_tuple
msg
,
message_id
id
,
util
::
int_list
<
Is
...
>
)
{
auto
opt
=
m_map_args
(
std
::
move
(
msg
));
if
(
opt
)
{
response_handle
handle
{
this
,
sender
,
id
.
response_id
()
};
response_handle
handle
{
this
,
sender
,
id
.
response_id
()
};
size_t
ret_size
=
std
::
accumulate
(
m_global_dimensions
.
begin
(),
m_global_dimensions
.
end
(),
1
,
std
::
multiplies
<
size_t
>
{});
m_global_dimensions
.
end
(),
1
,
std
::
multiplies
<
size_t
>
{});
std
::
vector
<
mem_ptr
>
arguments
;
add_arguments_to_kernel
<
Ret
>
(
arguments
,
ret_size
,
add_arguments_to_kernel
<
Ret
>
(
arguments
,
ret_size
,
get_ref
<
Is
>
(
*
opt
)...);
auto
cmd
=
make_counted
<
command
<
actor_facade
,
Ret
>>
(
handle
,
this
,
std
::
move
(
arguments
));
auto
cmd
=
make_counted
<
command
<
actor_facade
,
Ret
>>
(
handle
,
this
,
std
::
move
(
arguments
));
cmd
->
enqueue
();
}
else
{
CPPA_LOGMF
(
CPPA_ERROR
,
this
,
"actor_facade::enqueue() tuple_cast failed."
);
}
else
{
CPPA_LOGMF
(
CPPA_ERROR
,
this
,
"actor_facade::enqueue() tuple_cast failed."
);
}
}
typedef
std
::
vector
<
mem_ptr
>
args_vec
;
...
...
@@ -180,36 +168,30 @@ class actor_facade<Ret(Args...)> : public actor {
result_mapping
m_map_result
;
void
add_arguments_to_kernel_rec
(
args_vec
&
arguments
)
{
cl_int
err
{
0
};
for
(
size_t
i
=
1
;
i
<
arguments
.
size
();
++
i
)
{
err
=
clSetKernelArg
(
m_kernel
.
get
(),
(
i
-
1
),
sizeof
(
cl_mem
),
cl_int
err
{
0
};
for
(
size_t
i
=
1
;
i
<
arguments
.
size
();
++
i
)
{
err
=
clSetKernelArg
(
m_kernel
.
get
(),
(
i
-
1
),
sizeof
(
cl_mem
),
static_cast
<
void
*>
(
&
arguments
[
i
]));
CPPA_LOG_ERROR_IF
(
err
!=
CL_SUCCESS
,
"clSetKernelArg: "
<<
get_opencl_error
(
err
));
}
err
=
clSetKernelArg
(
m_kernel
.
get
(),
arguments
.
size
()
-
1
,
sizeof
(
cl_mem
),
static_cast
<
void
*>
(
&
arguments
[
0
]));
err
=
clSetKernelArg
(
m_kernel
.
get
(),
arguments
.
size
()
-
1
,
sizeof
(
cl_mem
),
static_cast
<
void
*>
(
&
arguments
[
0
]));
CPPA_LOG_ERROR_IF
(
err
!=
CL_SUCCESS
,
"clSetKernelArg: "
<<
get_opencl_error
(
err
));
}
template
<
typename
T0
,
typename
...
Ts
>
void
add_arguments_to_kernel_rec
(
args_vec
&
arguments
,
T0
&
arg0
,
Ts
&
...
args
)
{
cl_int
err
{
0
};
auto
buf
=
clCreateBuffer
(
m_context
.
get
(),
CL_MEM_READ_ONLY
|
CL_MEM_COPY_HOST_PTR
,
sizeof
(
typename
T0
::
value_type
)
*
arg0
.
size
(),
arg0
.
data
(),
&
err
);
template
<
typename
T0
,
typename
...
Ts
>
void
add_arguments_to_kernel_rec
(
args_vec
&
arguments
,
T0
&
arg0
,
Ts
&
...
args
)
{
cl_int
err
{
0
};
auto
buf
=
clCreateBuffer
(
m_context
.
get
(),
CL_MEM_READ_ONLY
|
CL_MEM_COPY_HOST_PTR
,
sizeof
(
typename
T0
::
value_type
)
*
arg0
.
size
(),
arg0
.
data
(),
&
err
);
if
(
err
!=
CL_SUCCESS
)
{
CPPA_LOGMF
(
CPPA_ERROR
,
this
,
"clCreateBuffer: "
<<
get_opencl_error
(
err
));
}
else
{
CPPA_LOGMF
(
CPPA_ERROR
,
this
,
"clCreateBuffer: "
<<
get_opencl_error
(
err
));
}
else
{
mem_ptr
tmp
;
tmp
.
adopt
(
std
::
move
(
buf
));
arguments
.
push_back
(
tmp
);
...
...
@@ -217,21 +199,18 @@ class actor_facade<Ret(Args...)> : public actor {
}
}
template
<
typename
R
,
typename
...
Ts
>
void
add_arguments_to_kernel
(
args_vec
&
arguments
,
size_t
ret_size
,
template
<
typename
R
,
typename
...
Ts
>
void
add_arguments_to_kernel
(
args_vec
&
arguments
,
size_t
ret_size
,
Ts
&&
...
args
)
{
arguments
.
clear
();
cl_int
err
{
0
};
auto
buf
=
clCreateBuffer
(
m_context
.
get
(),
CL_MEM_WRITE_ONLY
,
cl_int
err
{
0
};
auto
buf
=
clCreateBuffer
(
m_context
.
get
(),
CL_MEM_WRITE_ONLY
,
sizeof
(
typename
R
::
value_type
)
*
ret_size
,
nullptr
,
&
err
);
nullptr
,
&
err
);
if
(
err
!=
CL_SUCCESS
)
{
CPPA_LOGMF
(
CPPA_ERROR
,
this
,
"clCreateBuffer: "
<<
get_opencl_error
(
err
));
}
else
{
CPPA_LOGMF
(
CPPA_ERROR
,
this
,
"clCreateBuffer: "
<<
get_opencl_error
(
err
));
}
else
{
mem_ptr
tmp
;
tmp
.
adopt
(
std
::
move
(
buf
));
arguments
.
push_back
(
tmp
);
...
...
@@ -241,6 +220,7 @@ class actor_facade<Ret(Args...)> : public actor {
};
}
}
// namespace cppa::opencl
}
// namespace opencl
}
// namespace cppa
#endif // CPPA_OPENCL_ACTOR_FACADE_HPP
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment