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
2453725c
Commit
2453725c
authored
Mar 06, 2013
by
Joseph Noir
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
The command_dispatcher now uses event callbacks
to handle results from kernel executions.
parent
f75f328b
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
190 additions
and
167 deletions
+190
-167
libcaf_opencl/cppa/opencl/actor_facade.hpp
libcaf_opencl/cppa/opencl/actor_facade.hpp
+52
-138
libcaf_opencl/cppa/opencl/command.hpp
libcaf_opencl/cppa/opencl/command.hpp
+105
-13
libcaf_opencl/cppa/opencl/command_dispatcher.hpp
libcaf_opencl/cppa/opencl/command_dispatcher.hpp
+11
-3
libcaf_opencl/src/opencl/actor_facade.cpp
libcaf_opencl/src/opencl/actor_facade.cpp
+4
-2
libcaf_opencl/src/opencl/command_dispatcher.cpp
libcaf_opencl/src/opencl/command_dispatcher.cpp
+18
-11
No files found.
libcaf_opencl/cppa/opencl/actor_facade.hpp
View file @
2453725c
...
@@ -33,14 +33,18 @@
...
@@ -33,14 +33,18 @@
#define CPPA_OPENCL_ACTOR_FACADE_HPP
#define CPPA_OPENCL_ACTOR_FACADE_HPP
#include <iostream>
#include <iostream>
#include "cppa/to_string.hpp"
#include "cppa/channel.hpp"
#include "cppa/channel.hpp"
#include "cppa/to_string.hpp"
#include "cppa/tuple_cast.hpp"
#include "cppa/tuple_cast.hpp"
#include "cppa/intrusive_ptr.hpp"
#include "cppa/util/int_list.hpp"
#include "cppa/util/type_list.hpp"
#include "cppa/opencl/global.hpp"
#include "cppa/opencl/global.hpp"
#include "cppa/opencl/command.hpp"
#include "cppa/opencl/command.hpp"
#include "cppa/opencl/program.hpp"
#include "cppa/opencl/program.hpp"
#include "cppa/util/apply_args.hpp"
#include "cppa/opencl/smart_ptr.hpp"
#include "cppa/opencl/smart_ptr.hpp"
#include "cppa/detail/scheduled_actor_dummy.hpp"
#include "cppa/detail/scheduled_actor_dummy.hpp"
...
@@ -49,7 +53,7 @@ namespace cppa { namespace opencl {
...
@@ -49,7 +53,7 @@ namespace cppa { namespace opencl {
class
command_dispatcher
;
class
command_dispatcher
;
void
enqueue_to_dispatcher
(
command_dispatcher
*
,
command
*
);
void
enqueue_to_dispatcher
(
command_dispatcher
*
,
command
_ptr
);
template
<
typename
Signature
>
template
<
typename
Signature
>
class
actor_facade
;
class
actor_facade
;
...
@@ -63,55 +67,11 @@ class actor_facade<Ret(Args...)> : public cppa::detail::scheduled_actor_dummy {
...
@@ -63,55 +67,11 @@ class actor_facade<Ret(Args...)> : public cppa::detail::scheduled_actor_dummy {
const
program
&
prog
,
const
program
&
prog
,
const
std
::
string
&
kernel_name
)
const
std
::
string
&
kernel_name
)
:
m_program
(
prog
.
m_program
)
:
m_program
(
prog
.
m_program
)
,
m_kernel
()
,
m_context
(
prog
.
m_context
)
,
m_context
(
prog
.
m_context
)
,
m_kernel_name
(
kernel_name
)
,
m_kernel_name
(
kernel_name
)
,
m_dispatcher
(
dispatcher
){
,
m_dispatcher
(
dispatcher
)
{
}
void
enqueue
(
actor
*
sender
,
any_tuple
msg
)
{
auto
opt
=
tuple_cast
<
Args
...
>
(
msg
);
if
(
opt
)
{
response_handle
handle
{
this
,
sender
,
message_id_t
{}};
auto
fun
=
[
=
](
cl_command_queue
arg
)
{
auto
indices
=
util
::
get_indices
(
*
opt
);
return
util
::
apply_args_prefixed
(
*
this
,
*
opt
,
indices
,
arg
,
handle
,
1024
,
1
,
1
,
0
,
1
,
1
);
};
enqueue_to_dispatcher
(
m_dispatcher
,
new
command
(
fun
,
sender
));
}
else
{
// slap caller around with a large fish
}
}
/*
* todo:
* local_work_group_size currently unused, passing nullptr instead
*/
void
operator
()(
cl_command_queue
queue
,
response_handle
handle
,
size_t
global_work_size_dim1
,
size_t
global_work_size_dim2
,
size_t
global_work_size_dim3
,
size_t
local_work_size_dim1
,
size_t
local_work_size_dim2
,
size_t
local_work_size_dim3
,
Args
...
args
)
{
cl_int
err
{
0
};
cl_int
err
{
0
};
if
(
!
m_kernel
.
get
())
{
std
::
cout
<<
"no kernel found"
<<
std
::
endl
;
m_kernel
.
adopt
(
clCreateKernel
(
m_program
.
get
(),
m_kernel
.
adopt
(
clCreateKernel
(
m_program
.
get
(),
m_kernel_name
.
c_str
(),
m_kernel_name
.
c_str
(),
&
err
));
&
err
));
...
@@ -121,84 +81,44 @@ class actor_facade<Ret(Args...)> : public cppa::detail::scheduled_actor_dummy {
...
@@ -121,84 +81,44 @@ class actor_facade<Ret(Args...)> : public cppa::detail::scheduled_actor_dummy {
+
"'."
);
+
"'."
);
}
}
}
}
else
{
std
::
cout
<<
"i found a kernel"
<<
std
::
endl
;
void
enqueue
(
actor
*
sender
,
any_tuple
msg
)
{
typename
util
::
il_indices
<
util
::
type_list
<
Args
...
>>::
type
indices
;
enqueue_impl
(
sender
,
msg
,
indices
);
}
}
cl_event
event
;
int
number_of_values
=
global_work_size_dim1
*
global_work_size_dim2
*
global_work_size_dim3
;
/* add arguments */
private:
template
<
long
...
Is
>
void
enqueue_impl
(
actor
*
sender
,
any_tuple
msg
,
util
::
int_list
<
Is
...
>
)
{
auto
opt
=
tuple_cast
<
Args
...
>
(
msg
);
if
(
opt
)
{
response_handle
handle
{
this
,
sender
,
message_id_t
{}};
std
::
vector
<
size_t
>
global_dimensions
{
1024
,
1
,
1
};
std
::
vector
<
size_t
>
local_dimensions
;
int
number_of_values
=
1
;
for
(
size_t
s
:
global_dimensions
)
{
number_of_values
*=
s
;
}
Ret
result_buf
(
number_of_values
);
Ret
result_buf
(
number_of_values
);
std
::
vector
<
mem_ptr
>
arguments
;
std
::
vector
<
mem_ptr
>
arguments
;
add_arguments_to_kernel
(
arguments
,
add_arguments_to_kernel
(
arguments
,
m_context
.
get
(),
m_context
.
get
(),
m_kernel
.
get
(),
m_kernel
.
get
(),
queue
,
result_buf
,
result_buf
,
std
::
forward
<
Args
>
(
args
)...);
get_ref
<
Is
>
(
*
opt
)...);
enqueue_to_dispatcher
(
m_dispatcher
,
/* enqueue kernel */
make_counted
<
command_impl
<
Ret
>>
(
handle
,
size_t
global_work_group_size
[]
=
{
global_work_size_dim1
,
m_kernel
,
global_work_size_dim2
,
arguments
,
global_work_size_dim3
};
global_dimensions
,
if
(
local_work_size_dim1
==
0
)
{
local_dimensions
));
err
=
clEnqueueNDRangeKernel
(
queue
,
m_kernel
.
get
(),
3
,
NULL
,
global_work_group_size
,
nullptr
,
0
,
nullptr
,
&
event
);
}
}
else
{
else
{
size_t
local_work_group_size
[]
=
{
local_work_size_dim1
,
// slap caller around with a large fish
local_work_size_dim2
,
local_work_size_dim3
};
err
=
clEnqueueNDRangeKernel
(
queue
,
m_kernel
.
get
(),
3
,
NULL
,
global_work_group_size
,
local_work_group_size
,
0
,
nullptr
,
&
event
);
}
clReleaseEvent
(
event
);
if
(
err
!=
CL_SUCCESS
)
{
throw
std
::
runtime_error
(
"[!!!] clEnqueueNDRangeKernel: '"
+
get_opencl_error
(
err
)
+
"'."
);
}
clFinish
(
queue
);
/* get results from gpu */
Ret
results
(
number_of_values
);
err
=
clEnqueueReadBuffer
(
queue
,
arguments
[
0
].
get
(),
CL_TRUE
,
0
,
sizeof
(
typename
Ret
::
value_type
)
*
number_of_values
,
results
.
data
(),
0
,
NULL
,
&
event
);
clReleaseEvent
(
event
);
if
(
err
!=
CL_SUCCESS
)
{
throw
std
::
runtime_error
(
"[!!!] clEnqueueReadBuffer: '"
+
get_opencl_error
(
err
)
+
"'."
);
}
}
reply_to
(
handle
,
results
);
//return results;
}
}
private:
typedef
std
::
vector
<
mem_ptr
>
args_vec
;
typedef
std
::
vector
<
mem_ptr
>
args_vec
;
program_ptr
m_program
;
program_ptr
m_program
;
...
@@ -207,10 +127,9 @@ class actor_facade<Ret(Args...)> : public cppa::detail::scheduled_actor_dummy {
...
@@ -207,10 +127,9 @@ class actor_facade<Ret(Args...)> : public cppa::detail::scheduled_actor_dummy {
std
::
string
m_kernel_name
;
std
::
string
m_kernel_name
;
command_dispatcher
*
m_dispatcher
;
command_dispatcher
*
m_dispatcher
;
static
void
add_arguments_to_kernel_rec
(
args_vec
&
arguments
,
void
add_arguments_to_kernel_rec
(
args_vec
&
arguments
,
cl_context
,
cl_context
,
cl_kernel
kernel
,
cl_kernel
kernel
)
{
cl_command_queue
queue
)
{
cl_int
err
{
0
};
cl_int
err
{
0
};
for
(
unsigned
long
i
{
1
};
i
<
arguments
.
size
();
++
i
)
{
for
(
unsigned
long
i
{
1
};
i
<
arguments
.
size
();
++
i
)
{
err
=
clSetKernelArg
(
kernel
,
err
=
clSetKernelArg
(
kernel
,
...
@@ -232,16 +151,14 @@ class actor_facade<Ret(Args...)> : public cppa::detail::scheduled_actor_dummy {
...
@@ -232,16 +151,14 @@ class actor_facade<Ret(Args...)> : public cppa::detail::scheduled_actor_dummy {
+
get_opencl_error
(
err
)
+
get_opencl_error
(
err
)
+
"'."
);
+
"'."
);
}
}
clFinish
(
queue
);
}
}
template
<
typename
T0
,
typename
...
Ts
>
template
<
typename
T0
,
typename
...
Ts
>
static
void
add_arguments_to_kernel_rec
(
args_vec
&
arguments
,
void
add_arguments_to_kernel_rec
(
args_vec
&
arguments
,
cl_context
context
,
cl_context
context
,
cl_kernel
kernel
,
cl_kernel
kernel
,
cl_command_queue
queue
,
T0
&
arg0
,
T0
&&
arg0
,
Ts
&
...
args
)
{
Ts
&&
...
args
)
{
cl_int
err
{
0
};
cl_int
err
{
0
};
auto
buf
=
clCreateBuffer
(
context
,
auto
buf
=
clCreateBuffer
(
context
,
CL_MEM_READ_ONLY
|
CL_MEM_COPY_HOST_PTR
,
CL_MEM_READ_ONLY
|
CL_MEM_COPY_HOST_PTR
,
...
@@ -260,16 +177,14 @@ class actor_facade<Ret(Args...)> : public cppa::detail::scheduled_actor_dummy {
...
@@ -260,16 +177,14 @@ class actor_facade<Ret(Args...)> : public cppa::detail::scheduled_actor_dummy {
return
add_arguments_to_kernel_rec
(
arguments
,
return
add_arguments_to_kernel_rec
(
arguments
,
context
,
context
,
kernel
,
kernel
,
queue
,
args
...);
std
::
forward
<
Ts
>
(
args
)...);
}
}
}
}
template
<
typename
R
,
typename
...
Ts
>
template
<
typename
R
,
typename
...
Ts
>
static
void
add_arguments_to_kernel
(
args_vec
&
arguments
,
void
add_arguments_to_kernel
(
args_vec
&
arguments
,
cl_context
context
,
cl_context
context
,
cl_kernel
kernel
,
cl_kernel
kernel
,
cl_command_queue
queue
,
R
&
ret
,
R
&
ret
,
Ts
&&
...
args
)
{
Ts
&&
...
args
)
{
arguments
.
clear
();
arguments
.
clear
();
...
@@ -291,7 +206,6 @@ class actor_facade<Ret(Args...)> : public cppa::detail::scheduled_actor_dummy {
...
@@ -291,7 +206,6 @@ class actor_facade<Ret(Args...)> : public cppa::detail::scheduled_actor_dummy {
return
add_arguments_to_kernel_rec
(
arguments
,
return
add_arguments_to_kernel_rec
(
arguments
,
context
,
context
,
kernel
,
kernel
,
queue
,
std
::
forward
<
Ts
>
(
args
)...);
std
::
forward
<
Ts
>
(
args
)...);
}
}
}
}
...
...
libcaf_opencl/cppa/opencl/command.hpp
View file @
2453725c
...
@@ -37,33 +37,125 @@
...
@@ -37,33 +37,125 @@
#include "cppa/actor.hpp"
#include "cppa/actor.hpp"
#include "cppa/opencl/global.hpp"
#include "cppa/opencl/global.hpp"
#include "cppa/response_handle.hpp"
#include "cppa/opencl/smart_ptr.hpp"
namespace
cppa
{
namespace
opencl
{
namespace
cppa
{
namespace
opencl
{
class
command
{
class
command
:
public
ref_counted
{
public:
public:
command
*
next
;
command
*
next
;
// bool is_new_job; // if false == call handle_cl_result
virtual
void
enqueue
(
command_queue_ptr
queue
)
=
0
;
// struct callbacks {
// std::function<cl_job_id(cl_command_queue)> enqueue_cl_task;
// std::function<void()> handle_cl_result;
// };
// union { callbacks cbs; cl_job_id jid; };
std
::
function
<
void
(
cl_command_queue
)
>
fun
;
};
class
command_dummy
:
public
command
{
public:
void
enqueue
(
command_queue_ptr
)
{
}
};
template
<
typename
T
>
class
command_impl
:
public
command
{
actor
*
sender
;
public:
command_impl
(
response_handle
handle
,
kernel_ptr
kernel
,
std
::
vector
<
mem_ptr
>
arguments
,
std
::
vector
<
size_t
>
global_dimensions
,
std
::
vector
<
size_t
>
local_dimensions
)
:
m_number_of_values
(
1
)
,
m_handle
(
handle
)
,
m_kernel
(
kernel
)
,
m_arguments
(
arguments
)
,
m_global_dimensions
(
global_dimensions
)
,
m_local_dimensions
(
local_dimensions
)
{
m_kernel_event
.
adopt
(
cl_event
());
for
(
size_t
s
:
m_global_dimensions
)
{
m_number_of_values
*=
s
;
}
}
void
enqueue
(
command_queue_ptr
queue
)
{
this
->
ref
();
cl_int
err
{
0
};
m_queue
=
queue
;
auto
ptr
=
m_kernel_event
.
get
();
template
<
typename
T
>
/* enqueue kernel */
inline
command
(
T
f
,
actor
*
sender
)
err
=
clEnqueueNDRangeKernel
(
m_queue
.
get
(),
:
next
(
nullptr
),
fun
(
f
),
sender
(
sender
)
{
}
m_kernel
.
get
(),
3
,
NULL
,
m_global_dimensions
.
data
(),
m_local_dimensions
.
data
(),
0
,
nullptr
,
&
ptr
);
if
(
err
!=
CL_SUCCESS
)
{
throw
std
::
runtime_error
(
"[!!!] clEnqueueNDRangeKernel: '"
+
get_opencl_error
(
err
)
+
"'."
);
}
err
=
clSetEventCallback
(
ptr
,
CL_COMPLETE
,
[](
cl_event
,
cl_int
,
void
*
data
)
{
auto
cmd
=
reinterpret_cast
<
command_impl
*>
(
data
);
cmd
->
handle_results
();
cmd
->
deref
();
},
this
);
if
(
err
!=
CL_SUCCESS
)
{
throw
std
::
runtime_error
(
"[!!!] clSetEventCallback: '"
+
get_opencl_error
(
err
)
+
"'."
);
}
}
inline
command
()
:
next
(
nullptr
),
sender
(
nullptr
)
{
}
private:
int
m_number_of_values
;
response_handle
m_handle
;
kernel_ptr
m_kernel
;
event_ptr
m_kernel_event
;
command_queue_ptr
m_queue
;
std
::
vector
<
mem_ptr
>
m_arguments
;
std
::
vector
<
size_t
>
m_global_dimensions
;
std
::
vector
<
size_t
>
m_local_dimensions
;
void
handle_results
()
{
/* get results from gpu */
cl_int
err
{
0
};
cl_event
read_event
;
T
results
(
m_number_of_values
);
err
=
clEnqueueReadBuffer
(
m_queue
.
get
(),
m_arguments
[
0
].
get
(),
CL_TRUE
,
0
,
sizeof
(
typename
T
::
value_type
)
*
m_number_of_values
,
results
.
data
(),
0
,
NULL
,
&
read_event
);
clReleaseEvent
(
read_event
);
if
(
err
!=
CL_SUCCESS
)
{
throw
std
::
runtime_error
(
"[!!!] clEnqueueReadBuffer: '"
+
get_opencl_error
(
err
)
+
"'."
);
}
reply_to
(
m_handle
,
results
);
}
};
};
typedef
intrusive_ptr
<
command
>
command_ptr
;
}
}
// namespace cppa::opencl
}
}
// namespace cppa::opencl
#endif // CPPA_OPENCL_COMMAND_HPP
#endif // CPPA_OPENCL_COMMAND_HPP
libcaf_opencl/cppa/opencl/command_dispatcher.hpp
View file @
2453725c
...
@@ -48,6 +48,10 @@
...
@@ -48,6 +48,10 @@
namespace
cppa
{
namespace
opencl
{
namespace
cppa
{
namespace
opencl
{
struct
dereferencer
{
inline
void
operator
()(
ref_counted
*
ptr
)
{
ptr
->
deref
();
}
};
#ifdef CPPA_OPENCL
#ifdef CPPA_OPENCL
class
command_dispatcher
{
class
command_dispatcher
{
...
@@ -59,7 +63,8 @@ class command_dispatcher {
...
@@ -59,7 +63,8 @@ class command_dispatcher {
friend
class
program
;
friend
class
program
;
friend
void
enqueue_to_dispatcher
(
command_dispatcher
*
,
command
*
);
friend
void
enqueue_to_dispatcher
(
command_dispatcher
*
dispatcher
,
command_ptr
cmd
);
public:
public:
...
@@ -102,7 +107,7 @@ class command_dispatcher {
...
@@ -102,7 +107,7 @@ class command_dispatcher {
,
max_itms_per_dim
(
std
::
move
(
max_itms_per_dim
))
{
}
,
max_itms_per_dim
(
std
::
move
(
max_itms_per_dim
))
{
}
};
};
typedef
intrusive
::
blocking_single_reader_queue
<
command
>
job_queue
;
typedef
intrusive
::
blocking_single_reader_queue
<
command
,
dereferencer
>
job_queue
;
static
inline
command_dispatcher
*
create_singleton
()
{
static
inline
command_dispatcher
*
create_singleton
()
{
return
new
command_dispatcher
;
return
new
command_dispatcher
;
...
@@ -114,6 +119,7 @@ class command_dispatcher {
...
@@ -114,6 +119,7 @@ class command_dispatcher {
std
::
atomic
<
unsigned
>
dev_id_gen
;
std
::
atomic
<
unsigned
>
dev_id_gen
;
job_queue
m_job_queue
;
job_queue
m_job_queue
;
command_ptr
m_dummy
;
std
::
thread
m_supervisor
;
std
::
thread
m_supervisor
;
...
@@ -121,7 +127,9 @@ class command_dispatcher {
...
@@ -121,7 +127,9 @@ class command_dispatcher {
context_ptr
m_context
;
context_ptr
m_context
;
static
void
worker_loop
(
worker
*
);
static
void
worker_loop
(
worker
*
);
static
void
supervisor_loop
(
command_dispatcher
*
scheduler
,
job_queue
*
);
static
void
supervisor_loop
(
command_dispatcher
*
scheduler
,
job_queue
*
,
command_ptr
);
};
};
#else // CPPA_OPENCL
#else // CPPA_OPENCL
...
...
libcaf_opencl/src/opencl/actor_facade.cpp
View file @
2453725c
...
@@ -35,8 +35,10 @@
...
@@ -35,8 +35,10 @@
namespace
cppa
{
namespace
opencl
{
namespace
cppa
{
namespace
opencl
{
void
enqueue_to_dispatcher
(
command_dispatcher
*
dispatcher
,
void
enqueue_to_dispatcher
(
command_dispatcher
*
dispatcher
,
command
*
cmd
)
{
command_ptr
cmd
)
{
dispatcher
->
m_job_queue
.
push_back
(
cmd
);
cmd
->
ref
();
// implicit ref count of m_job_queue
dispatcher
->
m_job_queue
.
push_back
(
cmd
.
get
());
}
}
}
}
// namespace cppa::opencl
}
}
// namespace cppa::opencl
libcaf_opencl/src/opencl/command_dispatcher.cpp
View file @
2453725c
...
@@ -43,13 +43,14 @@ struct command_dispatcher::worker {
...
@@ -43,13 +43,14 @@ struct command_dispatcher::worker {
command_dispatcher
*
m_parent
;
command_dispatcher
*
m_parent
;
typedef
unique_ptr
<
command
>
job_ptr
;
typedef
command_ptr
job_ptr
;
job_queue
*
m_job_queue
;
job_queue
*
m_job_queue
;
thread
m_thread
;
thread
m_thread
;
job_ptr
m_dummy
;
worker
(
command_dispatcher
*
parent
,
job_queue
*
jq
)
worker
(
command_dispatcher
*
parent
,
job_queue
*
jq
,
job_ptr
dummy
)
:
m_parent
(
parent
),
m_job_queue
(
jq
)
{
}
:
m_parent
(
parent
),
m_job_queue
(
jq
),
m_dummy
(
dummy
)
{
}
void
start
()
{
void
start
()
{
m_thread
=
thread
(
&
command_dispatcher
::
worker_loop
,
this
);
m_thread
=
thread
(
&
command_dispatcher
::
worker_loop
,
this
);
...
@@ -65,12 +66,13 @@ struct command_dispatcher::worker {
...
@@ -65,12 +66,13 @@ struct command_dispatcher::worker {
/* wait for device */
/* wait for device */
/* get results */
/* get results */
/* wait for job */
/* wait for job */
job
.
reset
(
m_job_queue
->
pop
());
// adopt reference count of job queue
if
(
job
->
fun
)
{
job
.
adopt
(
m_job_queue
->
pop
());
if
(
job
!=
m_dummy
)
{
try
{
try
{
cl_command_queue
cmd_q
=
cl_command_queue
cmd_q
=
m_parent
->
m_devices
.
front
().
cmd_queue
.
get
();
m_parent
->
m_devices
.
front
().
cmd_queue
.
get
();
job
->
fun
(
cmd_q
);
job
->
enqueue
(
cmd_q
);
}
}
catch
(
exception
&
e
)
{
catch
(
exception
&
e
)
{
cerr
<<
e
.
what
()
<<
endl
;
cerr
<<
e
.
what
()
<<
endl
;
...
@@ -92,9 +94,9 @@ void command_dispatcher::worker_loop(command_dispatcher::worker* w) {
...
@@ -92,9 +94,9 @@ void command_dispatcher::worker_loop(command_dispatcher::worker* w) {
}
}
void
command_dispatcher
::
supervisor_loop
(
command_dispatcher
*
scheduler
,
void
command_dispatcher
::
supervisor_loop
(
command_dispatcher
*
scheduler
,
job_queue
*
jq
)
{
job_queue
*
jq
,
command_ptr
m_dummy
)
{
unique_ptr
<
command_dispatcher
::
worker
>
worker
;
unique_ptr
<
command_dispatcher
::
worker
>
worker
;
worker
.
reset
(
new
command_dispatcher
::
worker
(
scheduler
,
jq
));
worker
.
reset
(
new
command_dispatcher
::
worker
(
scheduler
,
jq
,
m_dummy
));
worker
->
start
();
worker
->
start
();
worker
->
m_thread
.
join
();
worker
->
m_thread
.
join
();
worker
.
reset
();
worker
.
reset
();
...
@@ -102,6 +104,9 @@ void command_dispatcher::supervisor_loop(command_dispatcher* scheduler,
...
@@ -102,6 +104,9 @@ void command_dispatcher::supervisor_loop(command_dispatcher* scheduler,
}
}
void
command_dispatcher
::
initialize
()
{
void
command_dispatcher
::
initialize
()
{
m_dummy
=
make_counted
<
command_dummy
>
();
cl_int
err
{
0
};
cl_int
err
{
0
};
/* find up to two available platforms */
/* find up to two available platforms */
...
@@ -217,11 +222,13 @@ void command_dispatcher::initialize() {
...
@@ -217,11 +222,13 @@ void command_dispatcher::initialize() {
}
}
m_supervisor
=
thread
(
&
command_dispatcher
::
supervisor_loop
,
m_supervisor
=
thread
(
&
command_dispatcher
::
supervisor_loop
,
this
,
this
,
&
m_job_queue
);
&
m_job_queue
,
m_dummy
);
}
}
void
command_dispatcher
::
destroy
()
{
void
command_dispatcher
::
destroy
()
{
m_job_queue
.
push_back
(
new
command
);
m_dummy
->
ref
();
// reference of m_job_queue
m_job_queue
.
push_back
(
m_dummy
.
get
());
m_supervisor
.
join
();
m_supervisor
.
join
();
delete
this
;
delete
this
;
}
}
...
...
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