Skip to content

Commit f9241e0

Browse files
[SYCL] Extend USM testing (#3189)
Splits sycl/test/extensions/usm.cpp into 2 new test files: * sycl/test/extensions/usm/usm_alloc_utility.cpp * sycl/test/extensions/usm/usm_allocator.cpp The on-device tests have been migrated to the Intel LLVM test suite: intel/llvm-test-suite#144 Signed-off-by: Steffen Larsen <[email protected]>
1 parent ed4b4c4 commit f9241e0

File tree

3 files changed

+125
-128
lines changed

3 files changed

+125
-128
lines changed

sycl/test/extensions/usm.cpp

Lines changed: 0 additions & 128 deletions
This file was deleted.
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t1.out
2+
// RUN: %RUN_ON_HOST %t1.out
3+
4+
//==------ usm_alloc_utility.cpp - USM malloc and aligned_alloc test -------==//
5+
//
6+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
7+
// See https://llvm.org/LICENSE.txt for license information.
8+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
9+
//
10+
//===----------------------------------------------------------------------===//
11+
12+
#include <CL/sycl.hpp>
13+
14+
#include <cassert>
15+
16+
using namespace cl::sycl;
17+
18+
constexpr int N = 8;
19+
20+
int main() {
21+
queue q;
22+
auto dev = q.get_device();
23+
auto ctxt = q.get_context();
24+
int *array;
25+
26+
if (dev.get_info<info::device::usm_host_allocations>()) {
27+
array = (int *)malloc_host(N * sizeof(int), q);
28+
assert((get_pointer_type(array, ctxt) == usm::alloc::host) &&
29+
"Allocation pointer should be host type");
30+
assert((get_pointer_device(array, ctxt) == dev) &&
31+
"Allocation pointer should be host type");
32+
free(array, ctxt);
33+
34+
array =
35+
(int *)aligned_alloc_host(alignof(long long), N * sizeof(int), ctxt);
36+
assert((get_pointer_type(array, ctxt) == usm::alloc::host) &&
37+
"Allocation pointer should be host type");
38+
assert((get_pointer_device(array, ctxt) == dev) &&
39+
"Allocation pointer should be host type");
40+
free(array, ctxt);
41+
}
42+
43+
if (dev.get_info<info::device::usm_shared_allocations>()) {
44+
array = (int *)malloc_shared(N * sizeof(int), q);
45+
// host device treats all allocations as host allocations
46+
assert((get_pointer_type(array, ctxt) == usm::alloc::host) &&
47+
"Allocation pointer should be host type");
48+
assert((get_pointer_device(array, ctxt) == dev) &&
49+
"Allocation pointer should be host type");
50+
free(array, ctxt);
51+
52+
array = (int *)aligned_alloc_shared(alignof(long long), N * sizeof(int),
53+
dev, ctxt);
54+
// host device treats all allocations as host allocations
55+
assert((get_pointer_type(array, ctxt) == usm::alloc::host) &&
56+
"Allocation pointer should be host type");
57+
assert((get_pointer_device(array, ctxt) == dev) &&
58+
"Allocation pointer should be host type");
59+
free(array, ctxt);
60+
}
61+
62+
if (dev.get_info<info::device::usm_device_allocations>()) {
63+
array = (int *)malloc_device(N * sizeof(int), q);
64+
// host device treats all allocations as host allocations
65+
assert((get_pointer_type(array, ctxt) == usm::alloc::host) &&
66+
"Allocation pointer should be host type");
67+
assert((get_pointer_device(array, ctxt) == dev) &&
68+
"Allocation pointer should be host type");
69+
free(array, ctxt);
70+
71+
array = (int *)aligned_alloc_device(alignof(long long), N * sizeof(int),
72+
dev, ctxt);
73+
// host device treats all allocations as host allocations
74+
assert((get_pointer_type(array, ctxt) == usm::alloc::host) &&
75+
"Allocation pointer should be host type");
76+
assert((get_pointer_device(array, ctxt) == dev) &&
77+
"Allocation pointer should be host type");
78+
free(array, ctxt);
79+
}
80+
81+
return 0;
82+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t1.out
2+
// RUN: %RUN_ON_HOST %t1.out
3+
4+
//==--------- usm_allocator.cpp - USM allocator construction test ----------==//
5+
//
6+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
7+
// See https://llvm.org/LICENSE.txt for license information.
8+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
9+
//
10+
//===----------------------------------------------------------------------===//
11+
12+
#include <CL/sycl.hpp>
13+
14+
#include <cassert>
15+
16+
using namespace cl::sycl;
17+
18+
constexpr int N = 8;
19+
20+
int main() {
21+
queue q;
22+
auto dev = q.get_device();
23+
auto ctxt = q.get_context();
24+
25+
{
26+
// Test usm_allocator
27+
if (dev.get_info<info::device::usm_shared_allocations>() &&
28+
dev.get_info<info::device::usm_host_allocations>()) {
29+
usm_allocator<int, usm::alloc::shared> alloc11(ctxt, dev);
30+
usm_allocator<int, usm::alloc::shared> alloc12(ctxt, dev);
31+
usm_allocator<int, usm::alloc::host> alloc21(q);
32+
usm_allocator<int, usm::alloc::host> alloc22(alloc21);
33+
34+
// usm::alloc::device is not supported by usm_allocator
35+
36+
assert((alloc11 != alloc22) && "Allocators should NOT be equal.");
37+
assert((alloc11 == alloc12) && "Allocators should be equal.");
38+
assert((alloc21 == alloc22) && "Allocators should be equal.");
39+
}
40+
}
41+
42+
return 0;
43+
}

0 commit comments

Comments
 (0)