File: sycl_rebind.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 (50 lines) | stat: -rw-r--r-- 1,092 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
// This program demonstrates how to rebind syclFlow tasks
// to different device operations.

#include <taskflow/syclflow.hpp>

int main() {

  size_t N = 10000;

  sycl::queue queue;

  auto data = sycl::malloc_shared<int>(N, queue);

  tf::syclFlow syclflow(queue);

  // fill data with -1
  std::cout << "filling data with -1 ...\n";

  tf::syclTask task = syclflow.fill(data, -1, N);
  syclflow.offload();

  for(size_t i=0; i<N; i++) {
    if(data[i] != -1) {
      throw std::runtime_error("unexpected result after fill");
    }
  }
  std::cout << "correct result after fill\n";

  // rebind the task to for-each task setting each element to 100
  // You can rebind a syclTask to any other task type.
  std::cout << "rebind task to for_each task setting each element to 100\n";

  syclflow.for_each(
    task, data, data+N, [](int& i){ i = 100; }
  );
  syclflow.offload();

  for(size_t i=0; i<N; i++) {
    if(data[i] != 100) {
      throw std::runtime_error("unexpected result after for_each");
    }
  }
  std::cout << "correct result after updating for_each\n";


  return 0;
}