Commit a1f03572 authored by Dominik Charousset's avatar Dominik Charousset

Merge branch 'unstable' of github.com:Neverlord/libcppa into unstable

Conflicts:
	examples/opencl/simple_matrix.cpp
parents 1a48d179 32f8ed4f
...@@ -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)...);
} }
}; };
......
...@@ -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<fvec(fvec&, fvec&)>(kernel_source, auto worker = spawn_cl<float*(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();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment