Skip to content
This repository was archived by the owner on Mar 28, 2023. It is now read-only.

Commit e184d60

Browse files
authored
[SYCL] Add test for usm buffer location properties (#955)
Resolves intel/llvm#5750 The test intended to test changes in PR: intel/llvm#5634
1 parent b171125 commit e184d60

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed

SYCL/USM/buffer_location.cpp

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t1.out
2+
// RUN: %HOST_RUN_PLACEHOLDER %t1.out
3+
// RUN: %CPU_RUN_PLACEHOLDER %t1.out
4+
// RUN: %ACC_RUN_PLACEHOLDER %t1.out
5+
6+
//==------------------- buffer_location.cpp - USM buffer location ----------==//
7+
//
8+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
9+
// See https://llvm.org/LICENSE.txt for license information.
10+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
11+
//
12+
//===----------------------------------------------------------------------===//
13+
14+
#include <CL/sycl.hpp>
15+
#include <iostream>
16+
#include <memory>
17+
18+
using namespace cl::sycl;
19+
20+
// Pointer wrapper allows custom deleter to clean up resources
21+
struct ptr_wrapper {
22+
sycl::context m_ctx;
23+
int *m_ptr;
24+
ptr_wrapper(sycl::context ctx, int *ptr) {
25+
m_ctx = ctx;
26+
m_ptr = ptr;
27+
}
28+
~ptr_wrapper() { sycl::free(m_ptr, m_ctx); }
29+
};
30+
31+
int main() {
32+
queue q;
33+
auto dev = q.get_device();
34+
auto ctxt = q.get_context();
35+
36+
if (!dev.get_info<info::device::usm_device_allocations>())
37+
return 0;
38+
39+
int true_buf_loc = 3;
40+
auto test_src_ptr_unq = std::unique_ptr<ptr_wrapper>(new ptr_wrapper(
41+
ctxt, malloc_device<int>(
42+
1, dev, ctxt,
43+
property_list{
44+
ext::intel::experimental::property::usm::buffer_location(
45+
true_buf_loc)})));
46+
if (test_src_ptr_unq == nullptr) {
47+
return -1;
48+
}
49+
auto test_dst_ptr_unq = std::unique_ptr<ptr_wrapper>(new ptr_wrapper(
50+
ctxt, malloc_device<int>(
51+
1, dev, ctxt,
52+
property_list{
53+
ext::intel::experimental::property::usm::buffer_location(
54+
true_buf_loc)})));
55+
if (test_dst_ptr_unq == nullptr) {
56+
return -1;
57+
}
58+
int src_val = 3;
59+
int dst_val = 4;
60+
int *test_src_ptr = test_src_ptr_unq.get()->m_ptr;
61+
int *test_dst_ptr = test_dst_ptr_unq.get()->m_ptr;
62+
event e0 = q.memcpy(test_src_ptr, &src_val, sizeof(int));
63+
e0.wait();
64+
event e1 = q.memcpy(test_dst_ptr, &dst_val, sizeof(int));
65+
e1.wait();
66+
67+
auto e2 = q.submit([=](handler &cgh) {
68+
cgh.single_task<class foo>([=]() { *test_src_ptr = *test_dst_ptr; });
69+
});
70+
e2.wait();
71+
72+
if (*test_src_ptr != dst_val) {
73+
return -1;
74+
}
75+
76+
return 0;
77+
}

0 commit comments

Comments
 (0)