<commit_before>#include <vector>

#include "test.hpp"

#include "cppa/cppa.hpp"
#include "cppa/opencl/program.hpp"
#include "cppa/opencl/actor_facade.hpp"
#include "cppa/opencl/command_dispatcher.hpp"

using namespace std;
using namespace cppa;
using namespace cppa::opencl;

#define STRINGIFY(A) #A
std::string kernel_source = STRINGIFY(
    float function_example(float a, float b) {
        return a + b;
    }

    __kernel void add(__global float* a, __global float* b, __global float* c) {
        unsigned int i = get_global_id(0);
        c[i] = function_example(a[i], b[i]);
    }

    __kernel void square(__global float* input, __global float* output)
    {
        unsigned int i = get_global_id(0);
        output[i] = input[i] * input[i];
    }
);

int main() {
    CPPA_TEST(test_opencl);

    announce<vector<float>>();

    program prog{kernel_source};

    command_dispatcher* disp =
            cppa::detail::singleton_manager::get_command_dispatcher();

    {

        unsigned size{1024};

        vector<float> a;
        vector<float> b;

        a.reserve(size);
        b.reserve(size);

        for (unsigned i{0}; i < size; ++i) {
            a.push_back(i*1.0);
            b.push_back(i*1.0);
        }

        cout << "add with 1 dimension size argument:" << endl;
        auto a_add_arguments = disp->spawn<vector<float>,
                                           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();
    }
<commit_msg>unit test changed to different calculations<commit_after>#include <vector>
#include <iomanip>

#include "test.hpp"

#include "cppa/cppa.hpp"
#include "cppa/opencl/program.hpp"
#include "cppa/opencl/actor_facade.hpp"
#include "cppa/opencl/command_dispatcher.hpp"

using namespace std;
using namespace cppa;
using namespace cppa::opencl;

#define STRINGIFY(A) #A
std::string kernel_source = STRINGIFY(
/*
    float function_example(float a, float b) {
        return a + b;
    }

    __kernel void add(__global float* a, __global float* b, __global float* c) {
        unsigned int i = get_global_id(0);
        c[i] = function_example(a[i], b[i]);
    }

    __kernel void square(__global float* input, __global float* output)
    {
        unsigned int i = get_global_id(0);
        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() {
    CPPA_TEST(test_opencl);

    announce<vector<int>>();
    announce<vector<float>>();

    int size{6};
    program prog{kernel_source};

    command_dispatcher* disp =
            cppa::detail::singleton_manager::get_command_dispatcher();

    auto matrix_global = disp->spawn<vector<float>,
                                     vector<float>,
                                     vector<float>>(prog, "matrix",
                                                    size, size);

    vector<float> m1(size * size);
    vector<float> m2(size * size);

    iota(m1.begin(), m1.end(), 0.0);
    iota(m2.begin(), m2.end(), 0.0);

    send(matrix_global, m1, m2);

    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";
        }
    );

    cppa::await_all_others_done();
    cppa::shutdown();

{'fraction_non_alphanumeric': 0.15606665102088713, 'fraction_numerical': 0.008331377610889463, 'mean_word_length': 1.5082401412595645, 'pattern_counts': {'":': 0, '<': 223, '<?xml version=': 0, '>': 79, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 17, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1335494', 'n_tokens_mistral': 2618, 'n_tokens_neox': 2507, 'n_words': 518}