File: sycl_rebinds.cpp

package info (click to toggle)
taskflow 3.9.0%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 45,948 kB
  • sloc: cpp: 39,058; xml: 35,572; python: 12,935; javascript: 1,732; makefile: 59; sh: 16
file content (107 lines) | stat: -rw-r--r-- 2,276 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include <doctest.h>
#include <taskflow/syclflow.hpp>

// ----------------------------------------------------------------------------
// rebind algorithms
// ----------------------------------------------------------------------------

TEST_CASE("syclFlowCapturer.rebind.algorithms") {

  sycl::queue queue;

  tf::syclFlow syclflow(queue);

  auto data = sycl::malloc_shared<int>(10000, queue);
  auto res = sycl::malloc_shared<int>(1, queue);

  auto task = syclflow.for_each(
    data, data+10000, [](int& i) { i = 10; }
  );

  syclflow.offload();

  for(int i=0; i<10000; i++) {
    REQUIRE(data[i] == 10);
  }
  REQUIRE(syclflow.num_tasks() == 1);

  // rebind to single task
  syclflow.single_task(task, [=]  () {*data = 2;});

  syclflow.offload();

  REQUIRE(*data == 2);
  for(int i=1; i<10000; i++) {
    REQUIRE(data[i] == 10);
  }
  REQUIRE(syclflow.num_tasks() == 1);

  // rebind to for each index
  syclflow.for_each_index(
    task, 0, 10000, 1, [=] (int i) { data[i] = -23; }
  );

  syclflow.offload();


  for(int i=0; i<10000; i++) {
    REQUIRE(data[i] == -23);
  }
  REQUIRE(syclflow.num_tasks() == 1);

  // rebind to reduce
  *res = 10;
  syclflow.reduce(task, data, data + 10000, res,
    [](int a, int b){ return a + b; }
  );

  syclflow.offload();

  REQUIRE(*res == -229990);
  REQUIRE(syclflow.num_tasks() == 1);

  // rebind to uninitialized reduce
  syclflow.uninitialized_reduce(task, data, data + 10000, res,
    [](int a, int b){ return a + b; }
  );

  syclflow.offload();

  REQUIRE(*res == -230000);
  REQUIRE(syclflow.num_tasks() == 1);

  // rebind to single task
  syclflow.single_task(task, [res](){ *res = 999; });
  REQUIRE(*res == -230000);

  syclflow.offload();
  REQUIRE(*res == 999);
  REQUIRE(syclflow.num_tasks() == 1);

  // rebind to on
  syclflow.on(task, [res] (sycl::handler& handler) {
    handler.single_task([=](){ *res = 1000; });
  });

  syclflow.offload();
  REQUIRE(*res == 1000);

  // clear the syclflow
  syclflow.clear();
  REQUIRE(syclflow.num_tasks() == 0);

  syclflow.offload();

  REQUIRE(*res == 1000);
  for(int i=0; i<10000; i++) {
    REQUIRE(data[i] == -23);
  }

  return;

  // clear the memory
  sycl::free(data, queue);
  sycl::free(res, queue);
}