Skip to content

Commit 33523e5

Browse files
cperkinsintelbb-sycl
authored andcommitted
[SYCL] tests for ONEAPI_DEVICE_SELECTOR. (intel#1270)
1 parent 5d64153 commit 33523e5

File tree

7 files changed

+231
-0
lines changed

7 files changed

+231
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include <iostream>
2+
#include <sycl/sycl.hpp>
3+
using namespace sycl;
4+
5+
int main() {
6+
for (auto &d : device::get_devices()) {
7+
std::cout << "Device: " << d.get_info<info::device::name>() << std::endl;
8+
}
9+
return 0;
10+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// REQUIRES: level_zero
2+
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %S/Inputs/trivial.cpp -o %t.out
3+
// RUN: env ONEAPI_DEVICE_SELECTOR=level_zero %t.out
4+
// XFAIL: *
5+
6+
// Calling ONEAPI_DEVICE_SELECTOR with a backend and no device should result in
7+
// an error.
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// REQUIRES: cpu, gpu, accelerator, opencl
2+
3+
// RUN: %clangxx -fsycl %s -o %t.out
4+
5+
// RUN: env ONEAPI_DEVICE_SELECTOR=opencl:fpga %t.out | FileCheck %s --check-prefixes=CHECK-ACC-ONLY
6+
// RUN: env ONEAPI_DEVICE_SELECTOR=opencl:gpu %t.out | FileCheck %s --check-prefixes=CHECK-GPU-ONLY
7+
// RUN: env ONEAPI_DEVICE_SELECTOR=opencl:cpu %t.out | FileCheck %s --check-prefixes=CHECK-CPU-ONLY
8+
9+
// RUN: env ONEAPI_DEVICE_SELECTOR=opencl:fpga,gpu %t.out | FileCheck %s --check-prefixes=CHECK-ACC-GPU
10+
// RUN: env ONEAPI_DEVICE_SELECTOR=opencl:fpga,cpu %t.out | FileCheck %s --check-prefixes=CHECK-ACC-CPU
11+
12+
// RUN: env ONEAPI_DEVICE_SELECTOR=opencl:cpu,fpga,gpu %t.out | FileCheck %s --check-prefixes=CHECK-ACC-GPU-CPU
13+
// RUN: env ONEAPI_DEVICE_SELECTOR="opencl:*" %t.out | FileCheck %s --check-prefixes=CHECK-ACC-GPU-CPU
14+
//
15+
// CHECK-ACC-ONLY-NOT: Device: cpu
16+
// CHECK-ACC-ONLY-NOT: Device: gpu
17+
// CHECK-ACC-ONLY: Device: acc
18+
19+
//
20+
// CHECK-GPU-ONLY-NOT: Device: acc
21+
// CHECK-GPU-ONLY-NOT: Device: cpu
22+
// CHECK-GPU-ONLY: Device: gpu
23+
24+
//
25+
// CHECK-CPU-ONLY-NOT: Device: acc
26+
// CHECK-CPU-ONLY-NOT: Device: gpu
27+
// CHECK-CPU-ONLY: Device: cpu
28+
29+
//
30+
// CHECK-ACC-GPU-NOT: Device: cpu
31+
// CHECK-ACC-GPU-DAG: Device: acc
32+
// CHECK-ACC-GPU-DAG: Device: gpu
33+
34+
//
35+
// CHECK-ACC-CPU-NOT: Device: gpu
36+
// CHECK-ACC-CPU-DAG: Device: acc
37+
// CHECK-ACC-CPU-DAG: Device: cpu
38+
39+
//
40+
// CHECK-ACC-GPU-CPU-DAG: Device: acc
41+
// CHECK-ACC-GPU-CPU-DAG: Device: gpu
42+
// CHECK-ACC-GPU-CPU-DAG: Device: cpu
43+
//
44+
45+
#include <iostream>
46+
#include <map>
47+
#include <sycl/sycl.hpp>
48+
49+
using namespace sycl;
50+
51+
int main() {
52+
53+
std::map<info::device_type, std::string> m = {
54+
{info::device_type::cpu, "cpu"},
55+
{info::device_type::gpu, "gpu"},
56+
{info::device_type::accelerator, "acc"},
57+
{info::device_type::all, "all"}};
58+
59+
for (auto &d : device::get_devices()) {
60+
std::cout << "Device: " << m[d.get_info<info::device::device_type>()]
61+
<< std::endl;
62+
}
63+
64+
return 0;
65+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// REQUIRES: cuda,gpu
2+
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
3+
// RUN: env ONEAPI_DEVICE_SELECTOR=cuda:gpu %t.out
4+
// RUN: env ONEAPI_DEVICE_SELECTOR=cuda:0 %t.out
5+
// RUN: env ONEAPI_DEVICE_SELECTOR="cuda:*" %t.out
6+
7+
// At this time, CUDA only has one device (GPU). So this is easy to accept CUDA
8+
// and GPU and reject anything else. This test is just testing top level
9+
// devices, not sub-devices.
10+
11+
#include <iostream>
12+
#include <sycl/sycl.hpp>
13+
14+
using namespace sycl;
15+
using namespace std;
16+
17+
int main() {
18+
19+
{
20+
device d(default_selector_v);
21+
string name = d.get_platform().get_info<info::platform::name>();
22+
assert(name.find("CUDA") != string::npos);
23+
cout << "CUDA GPU Device is found: " << boolalpha << d.is_gpu()
24+
<< std::endl;
25+
}
26+
{
27+
device d(gpu_selector_v);
28+
string name = d.get_platform().get_info<info::platform::name>();
29+
assert(name.find("CUDA") != string::npos);
30+
cout << name << " is found: " << boolalpha << d.is_gpu() << std::endl;
31+
}
32+
{
33+
try {
34+
device d(cpu_selector_v);
35+
cerr << "CPU device is found in error: " << d.is_cpu() << std::endl;
36+
return -1;
37+
} catch (...) {
38+
cout << "Expectedly, cpu device is not found." << std::endl;
39+
}
40+
}
41+
{
42+
try {
43+
device d(accelerator_selector_v);
44+
cerr << "ACC device is found in error: " << d.is_accelerator()
45+
<< std::endl;
46+
} catch (...) {
47+
cout << "Expectedly, ACC device is not found." << std::endl;
48+
}
49+
}
50+
51+
return 0;
52+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %S/Inputs/trivial.cpp -o %t.out
3+
// RUN: env ONEAPI_DEVICE_SELECTOR="macaroni:*"" %t.out
4+
// XFAIL: *
5+
6+
// Calling ONEAPI_DEVICE_SELECTOR with an illegal backend should result in an
7+
// error.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// REQUIRES: level_zero,gpu
2+
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
3+
// RUN: env ONEAPI_DEVICE_SELECTOR=level_zero:gpu %t.out
4+
// RUN: env ONEAPI_DEVICE_SELECTOR=level_zero:0 %t.out
5+
// RUN: env ONEAPI_DEVICE_SELECTOR="level_zero:*" %t.out
6+
7+
// At this time, LevelZero only has one device (GPU). So this is easy to accept
8+
// L0 and GPU and reject anything else. This test is just testing top level
9+
// devices, not sub-devices.
10+
11+
#include <iostream>
12+
#include <sycl/sycl.hpp>
13+
14+
using namespace sycl;
15+
using namespace std;
16+
17+
int main() {
18+
19+
{
20+
device d(default_selector_v);
21+
string name = d.get_platform().get_info<info::platform::name>();
22+
assert(name.find("Level-Zero") != string::npos);
23+
cout << "Level-Zero GPU Device is found: " << boolalpha << d.is_gpu()
24+
<< std::endl;
25+
}
26+
{
27+
device d(gpu_selector_v);
28+
string name = d.get_platform().get_info<info::platform::name>();
29+
assert(name.find("Level-Zero") != string::npos);
30+
cout << name << " is found: " << boolalpha << d.is_gpu() << std::endl;
31+
}
32+
{
33+
try {
34+
device d(cpu_selector_v);
35+
cerr << "CPU device is found in error: " << d.is_cpu() << std::endl;
36+
return -1;
37+
} catch (...) {
38+
cout << "Expectedly, cpu device is not found." << std::endl;
39+
}
40+
}
41+
{
42+
try {
43+
device d(accelerator_selector_v);
44+
cerr << "ACC device is found in error: " << d.is_accelerator()
45+
<< std::endl;
46+
} catch (...) {
47+
cout << "Expectedly, ACC device is not found." << std::endl;
48+
}
49+
}
50+
51+
return 0;
52+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// REQUIRES: opencl, cpu
2+
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
3+
// RUN: env ONEAPI_DEVICE_SELECTOR="opencl:*" %t.out 1 &> tmp.txt
4+
// RUN: env ONEAPI_DEVICE_SELECTOR="opencl:*,cpu" cat tmp.txt | %t.out
5+
// RUN: env ONEAPI_DEVICE_SELECTOR="opencl:cpu,cpu" cat tmp.txt | %t.out
6+
7+
// on the first run we pass a dummy arg to the app. On seeing that, we count the
8+
// number of CPU devices and output it. That is piped to a file. On subsequent
9+
// runs we cat the file and pipe that to app. The app then compares the number
10+
// of CPU devices to that number, erroring if they differ.
11+
12+
// clang++ -fsycl -o ndd.bin no_duplicate_devices.cpp
13+
14+
#include <string>
15+
#include <sycl/sycl.hpp>
16+
17+
using namespace sycl;
18+
19+
int main(int argc, char *argv[]) {
20+
21+
unsigned numCPUDevices = device::get_devices(info::device_type::cpu).size();
22+
23+
// when arg is provided, simply count the number of CPU devices and output.
24+
if (argc > 1) {
25+
std::cout << numCPUDevices << std::endl;
26+
return 0; // done!
27+
}
28+
29+
// when arg is not provided, check the count against the piped value.
30+
char charBuff[16];
31+
std::cin.read(charBuff, 16);
32+
unsigned expectedNumCPUDevices = std::stoi(charBuff);
33+
34+
assert(numCPUDevices == expectedNumCPUDevices &&
35+
"wrong number of cpu devices. duplicates.");
36+
37+
return 0;
38+
}

0 commit comments

Comments
 (0)