This repository has been archived by the owner on Mar 28, 2023. It is now read-only.
forked from llvm/llvm-test-suite
-
Notifications
You must be signed in to change notification settings - Fork 131
/
buffer_dev_to_dev.cpp
53 lines (44 loc) · 1.68 KB
/
buffer_dev_to_dev.cpp
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
// FIXME flaky fail on HIP
// UNSUPPORTED: hip
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
// RUN: %CPU_RUN_PLACEHOLDER %t.out
// RUN: %GPU_RUN_PLACEHOLDER %t.out
// RUN: %ACC_RUN_PLACEHOLDER %t.out
//==---------- buffer_dev_to_dev.cpp - SYCL buffer basic test --------------==//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include <cassert>
#include <memory>
#include <sycl/sycl.hpp>
using namespace sycl;
int main() {
int Data[10] = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
{
buffer<int, 1> Buffer(Data, range<1>(10),
{property::buffer::use_host_ptr()});
device Device(default_selector_v);
context FirstContext(Device);
context SecondContext(Device);
queue FirstQueue(FirstContext, Device);
queue SecondQueue(SecondContext, Device);
assert(FirstQueue.get_context() != SecondQueue.get_context());
FirstQueue.submit([&](handler &Cgh) {
auto Accessor = Buffer.get_access<access::mode::read_write>(Cgh);
Cgh.parallel_for<class init_b>(range<1>{10},
[=](id<1> Index) { Accessor[Index] = 0; });
});
SecondQueue.submit([&](handler &Cgh) {
auto Accessor = Buffer.get_access<access::mode::read_write>(Cgh);
Cgh.parallel_for<class increment_b>(
range<1>{10}, [=](id<1> Index) { Accessor[Index] += 1; });
});
} // Data is copied back
for (int I = 0; I < 10; I++) {
assert(Data[I] == 1);
}
return 0;
}