forked from intel/llvm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusm_shortcuts_utility.cpp
More file actions
142 lines (109 loc) · 5.61 KB
/
usm_shortcuts_utility.cpp
File metadata and controls
142 lines (109 loc) · 5.61 KB
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// RUN: %{build} -o %t.out
// RUN: %{run} %t.out
//==------ usm_shortcuts_utility.cpp - USM shortcuts 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 <sycl/detail/core.hpp>
#include <sycl/ext/intel/experimental/usm_properties.hpp>
#include <sycl/usm.hpp>
#include <cassert>
using namespace sycl;
constexpr int N = 8;
static void check_and_free(int *array, const device &dev, const context &ctxt,
usm::alloc expected_type) {
// host device treats all allocations as host allocations
assert((get_pointer_type(array, ctxt) == expected_type) &&
"Allocation pointer has unexpected type.");
assert((get_pointer_device(array, ctxt) == dev) &&
"Allocation pointer has unexpected device associated with it.");
free(array, ctxt);
}
int main() {
queue q;
auto dev = q.get_device();
auto ctxt = q.get_context();
int *array;
if (dev.get_info<sycl::info::device::usm_host_allocations>()) {
array = (int *)ext::oneapi::experimental::malloc(N * sizeof(int), dev,
usm::alloc::host);
check_and_free(array, dev, ctxt, usm::alloc::host);
array = (int *)ext::oneapi::experimental::malloc(
N * sizeof(int), dev, usm::alloc::host, property_list{});
check_and_free(array, dev, ctxt, usm::alloc::host);
array = ext::oneapi::experimental::malloc<int>(N * sizeof(int), dev,
usm::alloc::host);
check_and_free(array, dev, ctxt, usm::alloc::host);
array = ext::oneapi::experimental::malloc<int>(
N * sizeof(int), dev, usm::alloc::host, property_list{});
check_and_free(array, dev, ctxt, usm::alloc::host);
array = (int *)ext::oneapi::experimental::aligned_alloc(
alignof(long long), N * sizeof(int), dev, usm::alloc::host);
check_and_free(array, dev, ctxt, usm::alloc::host);
array = (int *)ext::oneapi::experimental::aligned_alloc(
alignof(long long), N * sizeof(int), dev, usm::alloc::host,
property_list{});
check_and_free(array, dev, ctxt, usm::alloc::host);
array = ext::oneapi::experimental::aligned_alloc<int>(
alignof(long long), N * sizeof(int), dev, usm::alloc::host);
check_and_free(array, dev, ctxt, usm::alloc::host);
array = ext::oneapi::experimental::aligned_alloc<int>(
alignof(long long), N * sizeof(int), dev, usm::alloc::host,
property_list{});
check_and_free(array, dev, ctxt, usm::alloc::host);
}
if (dev.get_info<sycl::info::device::usm_shared_allocations>()) {
array =
(int *)ext::oneapi::experimental::malloc_shared(N * sizeof(int), dev);
check_and_free(array, dev, ctxt, usm::alloc::shared);
array = (int *)ext::oneapi::experimental::malloc_shared(
N * sizeof(int), dev, property_list{});
check_and_free(array, dev, ctxt, usm::alloc::shared);
array = ext::oneapi::experimental::malloc_shared<int>(N * sizeof(int), dev);
check_and_free(array, dev, ctxt, usm::alloc::shared);
array = ext::oneapi::experimental::malloc_shared<int>(N * sizeof(int), dev,
property_list{});
check_and_free(array, dev, ctxt, usm::alloc::shared);
array = (int *)ext::oneapi::experimental::aligned_alloc_shared(
alignof(long long), N * sizeof(int), dev);
check_and_free(array, dev, ctxt, usm::alloc::shared);
array = (int *)ext::oneapi::experimental::aligned_alloc_shared(
alignof(long long), N * sizeof(int), dev, property_list{});
check_and_free(array, dev, ctxt, usm::alloc::shared);
array = ext::oneapi::experimental::aligned_alloc_shared<int>(
alignof(long long), N * sizeof(int), dev);
check_and_free(array, dev, ctxt, usm::alloc::shared);
array = ext::oneapi::experimental::aligned_alloc_shared<int>(
alignof(long long), N * sizeof(int), dev, property_list{});
check_and_free(array, dev, ctxt, usm::alloc::shared);
}
if (dev.get_info<sycl::info::device::usm_device_allocations>()) {
array =
(int *)ext::oneapi::experimental::malloc_device(N * sizeof(int), dev);
check_and_free(array, dev, ctxt, usm::alloc::device);
array = (int *)ext::oneapi::experimental::malloc_device(N, dev,
property_list{});
check_and_free(array, dev, ctxt, usm::alloc::device);
array = ext::oneapi::experimental::malloc_device<int>(N * sizeof(int), dev);
check_and_free(array, dev, ctxt, usm::alloc::device);
array =
ext::oneapi::experimental::malloc_device<int>(N, dev, property_list{});
check_and_free(array, dev, ctxt, usm::alloc::device);
array = (int *)ext::oneapi::experimental::aligned_alloc_device(
alignof(long long), N * sizeof(int), dev);
check_and_free(array, dev, ctxt, usm::alloc::device);
array = (int *)ext::oneapi::experimental::aligned_alloc_device(
alignof(long long), N * sizeof(int), dev, property_list{});
check_and_free(array, dev, ctxt, usm::alloc::device);
array = ext::oneapi::experimental::aligned_alloc_device<int>(
alignof(long long), N * sizeof(int), dev);
check_and_free(array, dev, ctxt, usm::alloc::device);
array = ext::oneapi::experimental::aligned_alloc_device<int>(
alignof(long long), N * sizeof(int), dev, property_list{});
check_and_free(array, dev, ctxt, usm::alloc::device);
}
return 0;
}