ddemidov / vexcl
1
#define BOOST_TEST_MODULE SVM
2
#include <boost/test/unit_test.hpp>
3

4
#include <vexcl/vector.hpp>
5

6
#if defined(CL_VERSION_2_0) || defined(VEXCL_BACKEND_CUDA)
7
#include <vexcl/svm_vector.hpp>
8
#include <vexcl/element_index.hpp>
9
#include <vexcl/function.hpp>
10
#include "context_setup.hpp"
11

12
BOOST_AUTO_TEST_CASE(svm)
13
{
14
    const int n = 1024;
15

16
    std::vector<vex::command_queue> queue(1, ctx.queue(0));
17

18
#if !defined(VEXCL_BACKEND_CUDA)
19
    if (!vex::Filter::CLVersion(2,0)(ctx.device(0)))
20
        return;
21

22
    vex::push_compile_options(ctx.queue(0), "-cl-std=CL2.0");
23
#endif
24

25
    vex::svm_vector<int> x(queue[0], n);
26

27
    {
28
        auto p = x.map(vex::backend::MAP_WRITE);
29
        for(int i = 0; i < n; ++i) p[i] = i;
30
    }
31

32
    vex::vector<int> y(queue, n);
33
    y = x * 2;
34

35
    check_sample(y, [&](size_t idx, int v){ BOOST_CHECK_EQUAL(2 * idx, v); });
36

37
    x = y / 2;
38

39
    {
40
        auto p = x.map(vex::backend::MAP_READ);
41
        for(int i = 0; i < n; ++i)
42
            BOOST_CHECK_EQUAL(p[i], i);
43
    }
44

45
    vex::svm_vector<int> z(queue[0], n);
46
    z = x;
47

48
    {
49
        auto p = z.map(vex::backend::MAP_READ);
50
        for(int i = 0; i < n; ++i)
51
            BOOST_CHECK_EQUAL(p[i], i);
52
    }
53

54
    VEX_FUNCTION(int, dbl, (size_t, i)(int*, x),
55
            return x[i] * 2;
56
            );
57

58
    y = dbl(vex::element_index(), vex::raw_pointer(x));
59
    check_sample(y, [&](size_t idx, int v){ BOOST_CHECK_EQUAL(2 * idx, v); });
60
}
61

62
BOOST_AUTO_TEST_SUITE_END()
63

64
#else
65

66 6
BOOST_AUTO_TEST_CASE(empty)
67
{
68
}
69

70
#endif

Read our documentation on viewing source code .

Loading