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
a1f03572
Commit
a1f03572
authored
May 27, 2013
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'unstable' of github.com:Neverlord/libcppa into unstable
Conflicts: examples/opencl/simple_matrix.cpp
parents
1a48d179
32f8ed4f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
13 deletions
+18
-13
cppa/opencl.hpp
cppa/opencl.hpp
+8
-1
examples/opencl/simple_matrix.cpp
examples/opencl/simple_matrix.cpp
+10
-12
No files found.
cppa/opencl.hpp
View file @
a1f03572
...
@@ -44,6 +44,13 @@ namespace cppa {
...
@@ -44,6 +44,13 @@ namespace cppa {
namespace
detail
{
namespace
detail
{
// converts C arrays, i.e., pointers, to vectors
template
<
typename
T
>
struct
carr_to_vec
{
typedef
T
type
;
};
template
<
typename
T
>
struct
carr_to_vec
<
T
*>
{
typedef
std
::
vector
<
T
>
type
;
};
template
<
typename
Signature
,
typename
SecondSignature
=
void
>
template
<
typename
Signature
,
typename
SecondSignature
=
void
>
struct
cl_spawn_helper
;
struct
cl_spawn_helper
;
...
@@ -52,7 +59,7 @@ struct cl_spawn_helper<R (Ts...), void> {
...
@@ -52,7 +59,7 @@ struct cl_spawn_helper<R (Ts...), void> {
template
<
typename
...
Us
>
template
<
typename
...
Us
>
actor_ptr
operator
()(
const
opencl
::
program
&
p
,
const
char
*
fname
,
Us
&&
...
args
)
{
actor_ptr
operator
()(
const
opencl
::
program
&
p
,
const
char
*
fname
,
Us
&&
...
args
)
{
auto
cd
=
opencl
::
get_command_dispatcher
();
auto
cd
=
opencl
::
get_command_dispatcher
();
return
cd
->
spawn
<
R
,
Ts
...
>
(
p
,
fname
,
std
::
forward
<
Us
>
(
args
)...);
return
cd
->
spawn
<
typename
carr_to_vec
<
R
>::
type
,
typename
carr_to_vec
<
Ts
>::
type
...
>
(
p
,
fname
,
std
::
forward
<
Us
>
(
args
)...);
}
}
};
};
...
...
examples/opencl/simple_matrix.cpp
View file @
a1f03572
...
@@ -41,8 +41,6 @@ using namespace cppa;
...
@@ -41,8 +41,6 @@ using namespace cppa;
namespace
{
namespace
{
using
fvec
=
vector
<
float
>
;
constexpr
size_t
matrix_size
=
8
;
constexpr
size_t
matrix_size
=
8
;
constexpr
const
char
*
kernel_name
=
"matrix_mult"
;
constexpr
const
char
*
kernel_name
=
"matrix_mult"
;
...
@@ -66,7 +64,7 @@ constexpr const char* kernel_source = R"__(
...
@@ -66,7 +64,7 @@ constexpr const char* kernel_source = R"__(
}
// namespace <anonymous>
}
// namespace <anonymous>
void
print_as_matrix
(
const
fvec
&
matrix
)
{
void
print_as_matrix
(
const
vector
<
float
>
&
matrix
)
{
for
(
size_t
column
=
0
;
column
<
matrix_size
;
++
column
)
{
for
(
size_t
column
=
0
;
column
<
matrix_size
;
++
column
)
{
for
(
size_t
row
=
0
;
row
<
matrix_size
;
++
row
)
{
for
(
size_t
row
=
0
;
row
<
matrix_size
;
++
row
)
{
cout
<<
fixed
<<
setprecision
(
2
)
<<
setw
(
9
)
cout
<<
fixed
<<
setprecision
(
2
)
<<
setw
(
9
)
...
@@ -79,8 +77,8 @@ void print_as_matrix(const fvec& matrix) {
...
@@ -79,8 +77,8 @@ void print_as_matrix(const fvec& matrix) {
void
multiplier
()
{
void
multiplier
()
{
// the opencl actor only understands vectors
// the opencl actor only understands vectors
// so these vectors represent the matrices
// so these vectors represent the matrices
fvec
m1
(
matrix_size
*
matrix_size
);
vector
<
float
>
m1
(
matrix_size
*
matrix_size
);
fvec
m2
(
matrix_size
*
matrix_size
);
vector
<
float
>
m2
(
matrix_size
*
matrix_size
);
// fill each with ascending values
// fill each with ascending values
iota
(
m1
.
begin
(),
m1
.
end
(),
0
);
iota
(
m1
.
begin
(),
m1
.
end
(),
0
);
...
@@ -92,8 +90,8 @@ void multiplier() {
...
@@ -92,8 +90,8 @@ void multiplier() {
cout
<<
endl
;
cout
<<
endl
;
// spawn an opencl actor
// spawn an opencl actor
// template parameter: signature of opencl kernel using
vectors instead of
// template parameter: signature of opencl kernel using
proper return type
//
pointer arguments and proper return type
(implicitly
//
instead of output parameter
(implicitly
// mapped to the last kernel argument)
// mapped to the last kernel argument)
// 1st arg: source code of one or more kernels
// 1st arg: source code of one or more kernels
// 2nd arg: name of the kernel to use
// 2nd arg: name of the kernel to use
...
@@ -101,12 +99,12 @@ void multiplier() {
...
@@ -101,12 +99,12 @@ void multiplier() {
// creates matrix_size * matrix_size global work items
// creates matrix_size * matrix_size global work items
// 4th arg: offsets for global dimensions (optional)
// 4th arg: offsets for global dimensions (optional)
// 5th arg: local dimensions (optional)
// 5th arg: local dimensions (optional)
auto
worker
=
spawn_cl
<
f
vec
(
fvec
&
,
fvec
&
)
>
(
kernel_source
,
auto
worker
=
spawn_cl
<
f
loat
*
(
float
*
,
float
*
)
>
(
kernel_source
,
kernel_name
,
kernel_name
,
{
matrix_size
,
matrix_size
});
{
matrix_size
,
matrix_size
});
// send both matrices to the actor and wait for a result
// send both matrices to the actor and wait for a result
sync_send
(
worker
,
move
(
m1
),
move
(
m2
)).
then
(
sync_send
(
worker
,
move
(
m1
),
move
(
m2
)).
then
(
[](
const
fvec
&
result
)
{
[](
const
vector
<
float
>
&
result
)
{
cout
<<
"result: "
<<
endl
;
cout
<<
"result: "
<<
endl
;
print_as_matrix
(
result
);
print_as_matrix
(
result
);
}
}
...
@@ -114,7 +112,7 @@ void multiplier() {
...
@@ -114,7 +112,7 @@ void multiplier() {
}
}
int
main
()
{
int
main
()
{
announce
<
fvec
>
();
announce
<
vector
<
float
>
>
();
spawn
(
multiplier
);
spawn
(
multiplier
);
await_all_others_done
();
await_all_others_done
();
shutdown
();
shutdown
();
...
...
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