Commit 88185858 authored by Joseph Noir's avatar Joseph Noir

unit test changed to different calculations

validation missing
parent 9bcb3080
#include <vector> #include <vector>
#include <iomanip>
#include "test.hpp" #include "test.hpp"
...@@ -13,6 +14,7 @@ using namespace cppa::opencl; ...@@ -13,6 +14,7 @@ using namespace cppa::opencl;
#define STRINGIFY(A) #A #define STRINGIFY(A) #A
std::string kernel_source = STRINGIFY( std::string kernel_source = STRINGIFY(
/*
float function_example(float a, float b) { float function_example(float a, float b) {
return a + b; return a + b;
} }
...@@ -27,114 +29,105 @@ std::string kernel_source = STRINGIFY( ...@@ -27,114 +29,105 @@ std::string kernel_source = STRINGIFY(
unsigned int i = get_global_id(0); unsigned int i = get_global_id(0);
output[i] = input[i] * input[i]; output[i] = input[i] * input[i];
} }
*/
__kernel void matrix(__global float* matrix1,
__global float* matrix2,
__global float* output) {
int size = get_global_size(0); // == get_global_size_(1);
int x = get_global_id(0);
int y = get_global_id(1);
int idx = 0;
float result = 0;
while (idx < size) {
float i = matrix1[idx+y*size];
float j = matrix2[x+idx*size];
float tmp = i*j;
result = result + tmp;
++idx;
}
output[x+y*size] = result;
}
__kernel void dimensions(__global float* dummy, __global float* output) {
int size = get_global_size(0); // == get_global_size_(1);
int x = get_global_id(0);
int y = get_global_id(1);
int p = get_local_id(0);
int q = get_local_id(1);
output[x+y*size] = x * 10.0f + y * 1.0f + p * 0.1f + q* 0.01f;
}
); );
int main() { int main() {
CPPA_TEST(test_opencl); CPPA_TEST(test_opencl);
announce<vector<int>>();
announce<vector<float>>(); announce<vector<float>>();
int size{6};
program prog{kernel_source}; program prog{kernel_source};
command_dispatcher* disp = command_dispatcher* disp =
cppa::detail::singleton_manager::get_command_dispatcher(); cppa::detail::singleton_manager::get_command_dispatcher();
{ auto matrix_global = disp->spawn<vector<float>,
vector<float>,
unsigned size{1024}; vector<float>>(prog, "matrix",
size, size);
vector<float> a;
vector<float> b; vector<float> m1(size * size);
vector<float> m2(size * size);
a.reserve(size);
b.reserve(size); iota(m1.begin(), m1.end(), 0.0);
iota(m2.begin(), m2.end(), 0.0);
for (unsigned i{0}; i < size; ++i) {
a.push_back(i*1.0); send(matrix_global, m1, m2);
b.push_back(i*1.0);
receive (
on_arg_match >> [&] (const vector<float>& result) {
cout << "results:" << endl;
for (int y{0}; y < size; ++y) {
for (int x{0}; x < size; ++x) {
cout << fixed << setprecision(2) << setw(8) << result[x+y*size];
}
cout << endl;
}
},
others() >> [=]() {
cout << "Unexpected message: '"
<< to_string(self->last_dequeued()) << "'.\n";
} }
);
cout << endl;
auto matrix_local = disp->spawn<vector<float>,
vector<float>>(prog, "dimensions",
size, size, 1,
(size/3), (size/2), 1);
m1.clear();
m1.push_back(0.0); // dummy
send(matrix_local, m1);
receive (
on_arg_match >> [&] (const vector<float>& result) {
cout << "dimenson example:" << endl;
for (int y{0}; y < size; ++y) {
for (int x{0}; x < size; ++x) {
cout << fixed << setprecision(2) << setw(6) << result[x+y*size];
}
cout << endl;
}
},
others() >> [=]() {
cout << "Unexpected message: '"
<< to_string(self->last_dequeued()) << "'.\n";
}
);
cout << "add with 1 dimension size argument:" << endl; cppa::await_all_others_done();
auto a_add_arguments = disp->spawn<vector<float>, cppa::shutdown();
vector<float>,
vector<float>>(prog, "add", size);
send(a_add_arguments, a, b);
receive (
on_arg_match >> [&](const vector<float>& result) {
// copy(begin(result),
// end(result),
// std::ostream_iterator<float>(cout, "\n"));
cout << "first ("
<< a.front() << "/" << b.front()
<< ") :" << result.front() << endl
<< "last ("
<< a.back() << "/" << b.back()
<< ") :" << result.back() << endl;
},
others() >> CPPA_UNEXPECTED_MSG_CB()
);
cout << "add without arguments:" << endl;
auto a_add = disp->spawn<vector<float>,
vector<float>,
vector<float>>(prog, "add");
send(a_add, a, b);
receive (
on_arg_match >> [&](const vector<float>& result) {
// copy(begin(result),
// end(result),
// std::ostream_iterator<float>(cout, "\n"));
cout << "first ("
<< a.front() << "/" << b.front()
<< ") :" << result.front() << endl
<< "last ("
<< a.back() << "/" << b.back()
<< ") :" << result.back() << endl;
},
others() >> CPPA_UNEXPECTED_MSG_CB()
);
cout << "square with 1 dimension size argument:" << endl;
auto a_square = disp->spawn<vector<float>,
vector<float>>(prog, "square", size);
send(a_square, a);
receive (
on_arg_match >> [&](const vector<float>& result) {
// copy(begin(result),
// end(result),
// std::ostream_iterator<float>(cout, "\n"));
cout << "first ("
<< a.front() << "/" << b.front()
<< ") :" << result.front() << endl
<< "last ("
<< a.back() << "/" << b.back()
<< ") :" << result.back() << endl;
},
others() >> CPPA_UNEXPECTED_MSG_CB()
);
cout << "square without arguments:" << endl;
auto a_square_arguments = disp->spawn<vector<float>,
vector<float>>(prog, "square");
send(a_square_arguments, a);
receive (
on_arg_match >> [&](const vector<float>& result) {
// copy(begin(result),
// end(result),
// std::ostream_iterator<float>(cout, "\n"));
cout << "first ("
<< a.front() << "/" << b.front()
<< ") :" << result.front() << endl
<< "last ("
<< a.back() << "/" << b.back()
<< ") :" << result.back() << endl;
},
others() >> CPPA_UNEXPECTED_MSG_CB()
);
cppa::await_all_others_done();
cppa::shutdown();
}
return CPPA_TEST_RESULT(); return CPPA_TEST_RESULT();
} }
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