Skip to content

Commit f19914a

Browse files
[SYCL][E2E] Added SYCL aspect for freememory (#8844)
Added an e2e test to check totalMemory >= freeMemory --------- Co-authored-by: aelovikov-intel <[email protected]>
1 parent 74afa2b commit f19914a

File tree

2 files changed

+61
-38
lines changed

2 files changed

+61
-38
lines changed

sycl/test-e2e/Basic/intel-ext-device.cpp

Lines changed: 12 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
// RUN: %clangxx -fsycl %s -o %t.out
2-
// RUN: env ONEAPI_DEVICE_SELECTOR=level_zero:gpu %t.out
3-
// RUN: env ONEAPI_DEVICE_SELECTOR=opencl:gpu %t.out
2+
// REQUIRES: level_zero || opencl
3+
// RUN: %GPU_RUN_PLACEHOLDER %t.out
44
//
5-
// REQUIRES: gpu
6-
// UNSUPPORTED: hip
7-
// Temporarily disable on L0 due to fails in CI
8-
95
//==--------- intel-ext-device.cpp - SYCL device test ------------==//
106
//
117
// Returns the low-level device details. These are Intel-specific extensions
12-
// that are only supported on Level Zero.
8+
// that are only supported on Level Zero or OpenCL.
139
//
1410
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
1511
// See https://llvm.org/LICENSE.txt for license information.
@@ -51,6 +47,8 @@ int main(int argc, char **argv) {
5147
std::cout << "Backend: ";
5248
if (plt.get_backend() == backend::ext_oneapi_level_zero) {
5349
std::cout << "Level Zero" << std::endl;
50+
// It's required to set the env variable to query free-memory.
51+
setenv("ZES_ENABLE_SYSMAN", "1", 0);
5452
} else if (plt.get_backend() == backend::opencl) {
5553
std::cout << "OpenCL" << std::endl;
5654
} else if (plt.get_backend() == backend::ext_oneapi_cuda) {
@@ -110,6 +108,13 @@ int main(int argc, char **argv) {
110108
std::cout << "Failed!" << std::endl;
111109
return 1;
112110
}
111+
if (dev.has(aspect::ext_intel_free_memory)) {
112+
auto TotalMemory = dev.get_info<info::device::global_mem_size>();
113+
auto FreeMemory =
114+
dev.get_info<ext::intel::info::device::free_memory>();
115+
assert((TotalMemory >= FreeMemory) &&
116+
"Expect total_memory >= free_memory");
117+
}
113118
if (SYCL_EXT_INTEL_DEVICE_INFO >= 2 &&
114119
dev.has(aspect::ext_intel_device_info_uuid)) {
115120
auto UUID = dev.get_info<ext::intel::info::device::uuid>();
@@ -126,37 +131,6 @@ int main(int argc, char **argv) {
126131
}
127132
} // SYCL_EXT_INTEL_DEVICE_INFO
128133
}
129-
130-
// Check if this experimental feature is supported
131-
#ifdef SYCL_EXT_ONEAPI_MAX_WORK_GROUP_QUERY
132-
sycl::id<1> groupD = dev.get_info<
133-
sycl::ext::oneapi::experimental::info::device::max_work_groups<1>>();
134-
std::cout << "Max work group size in 1D \n";
135-
std::cout << "Dimension 1:" << groupD[0] << std::endl;
136-
137-
sycl::id<2> group2D = dev.get_info<
138-
sycl::ext::oneapi::experimental::info::device::max_work_groups<2>>();
139-
std::cout << "Max work group size in 2D \n";
140-
std::cout << "Dimension 1:" << group2D[0] << "\n"
141-
<< "Dimension 2:" << group2D[1] << std::endl;
142-
143-
sycl::id<3> group3D = dev.get_info<
144-
sycl::ext::oneapi::experimental::info::device::max_work_groups<3>>();
145-
std::cout << "Max work group size in 3D \n";
146-
std::cout << "Dimension 1:" << group3D[0] << "\n"
147-
<< "Dimension 2:" << group3D[1] << "\n"
148-
<< "Dimension 3:" << group3D[2] << std::endl;
149-
150-
size_t group_max = dev.get_info<sycl::ext::oneapi::experimental::info::
151-
device::max_global_work_groups>();
152-
std::cout << "Max global work group size:" << group_max << "\n";
153-
154-
assert((group3D[0] <= group_max && group3D[1] <= group_max &&
155-
group3D[2] <= group_max) &&
156-
"Max work-group size of each dimension must be smaller than "
157-
"global work-group size");
158-
#endif
159-
160134
std::cout << std::endl;
161135
}
162136
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
2+
// REQUIRES: cuda || hip || level_zero
3+
// RUN: %GPU_RUN_PLACEHOLDER %t.out
4+
5+
#include <sycl/sycl.hpp>
6+
7+
#include <cassert>
8+
#include <iostream>
9+
10+
using namespace sycl;
11+
12+
int main() {
13+
queue q;
14+
device dev = q.get_device();
15+
16+
#if !defined(SYCL_EXT_ONEAPI_MAX_WORK_GROUP_QUERY)
17+
#error SYCL_EXT_ONEAPI_MAX_WORK_GROUP_QUERY is not defined!
18+
#endif
19+
20+
sycl::id<1> groupD = dev.get_info<
21+
sycl::ext::oneapi::experimental::info::device::max_work_groups<1>>();
22+
std::cout << "Max work group size in 1D \n";
23+
std::cout << "Dimension 1:" << groupD[0] << std::endl;
24+
25+
sycl::id<2> group2D = dev.get_info<
26+
sycl::ext::oneapi::experimental::info::device::max_work_groups<2>>();
27+
std::cout << "Max work group size in 2D \n";
28+
std::cout << "Dimension 1:" << group2D[0] << "\n"
29+
<< "Dimension 2:" << group2D[1] << std::endl;
30+
31+
sycl::id<3> group3D = dev.get_info<
32+
sycl::ext::oneapi::experimental::info::device::max_work_groups<3>>();
33+
std::cout << "Max work group size in 3D \n";
34+
std::cout << "Dimension 1:" << group3D[0] << "\n"
35+
<< "Dimension 2:" << group3D[1] << "\n"
36+
<< "Dimension 3:" << group3D[2] << std::endl;
37+
38+
size_t group_max = dev.get_info<
39+
sycl::ext::oneapi::experimental::info::device::max_global_work_groups>();
40+
std::cout << "Max global work group size:" << group_max << "\n";
41+
42+
assert((group3D[0] <= group_max && group3D[1] <= group_max &&
43+
group3D[2] <= group_max) &&
44+
"Max work-group size of each dimension must be smaller than "
45+
"global work-group size");
46+
47+
std::cout << "Passed!" << std::endl;
48+
return 0;
49+
}

0 commit comments

Comments
 (0)