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

[SYCL] tests for ONEAPI_DEVICE_SELECTOR. #1270

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions SYCL/OneapiDeviceSelector/Inputs/trivial.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <iostream>
#include <sycl/sycl.hpp>
using namespace sycl;

int main() {
for (auto &d : device::get_devices()) {
std::cout << "Device: " << d.get_info<info::device::name>() << std::endl;
}
return 0;
}
7 changes: 7 additions & 0 deletions SYCL/OneapiDeviceSelector/backendonly_error.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// REQUIRES: level_zero
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %S/Inputs/trivial.cpp -o %t.out
// RUN: env ONEAPI_DEVICE_SELECTOR=level_zero %t.out
// XFAIL: *

// Calling ONEAPI_DEVICE_SELECTOR with a backend and no device should result in
// an error.
65 changes: 65 additions & 0 deletions SYCL/OneapiDeviceSelector/cpu_gpu_acc.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// REQUIRES: cpu, gpu, accelerator, opencl

// RUN: %clangxx -fsycl %s -o %t.out

// RUN: env ONEAPI_DEVICE_SELECTOR=opencl:fpga %t.out | FileCheck %s --check-prefixes=CHECK-ACC-ONLY
// RUN: env ONEAPI_DEVICE_SELECTOR=opencl:gpu %t.out | FileCheck %s --check-prefixes=CHECK-GPU-ONLY
// RUN: env ONEAPI_DEVICE_SELECTOR=opencl:cpu %t.out | FileCheck %s --check-prefixes=CHECK-CPU-ONLY

// RUN: env ONEAPI_DEVICE_SELECTOR=opencl:fpga,gpu %t.out | FileCheck %s --check-prefixes=CHECK-ACC-GPU
// RUN: env ONEAPI_DEVICE_SELECTOR=opencl:fpga,cpu %t.out | FileCheck %s --check-prefixes=CHECK-ACC-CPU

// RUN: env ONEAPI_DEVICE_SELECTOR=opencl:cpu,fpga,gpu %t.out | FileCheck %s --check-prefixes=CHECK-ACC-GPU-CPU
// RUN: env ONEAPI_DEVICE_SELECTOR="opencl:*" %t.out | FileCheck %s --check-prefixes=CHECK-ACC-GPU-CPU
//
// CHECK-ACC-ONLY-NOT: Device: cpu
// CHECK-ACC-ONLY-NOT: Device: gpu
// CHECK-ACC-ONLY: Device: acc

//
// CHECK-GPU-ONLY-NOT: Device: acc
// CHECK-GPU-ONLY-NOT: Device: cpu
// CHECK-GPU-ONLY: Device: gpu

//
// CHECK-CPU-ONLY-NOT: Device: acc
// CHECK-CPU-ONLY-NOT: Device: gpu
// CHECK-CPU-ONLY: Device: cpu

//
// CHECK-ACC-GPU-NOT: Device: cpu
// CHECK-ACC-GPU-DAG: Device: acc
// CHECK-ACC-GPU-DAG: Device: gpu

//
// CHECK-ACC-CPU-NOT: Device: gpu
// CHECK-ACC-CPU-DAG: Device: acc
// CHECK-ACC-CPU-DAG: Device: cpu

//
// CHECK-ACC-GPU-CPU-DAG: Device: acc
// CHECK-ACC-GPU-CPU-DAG: Device: gpu
// CHECK-ACC-GPU-CPU-DAG: Device: cpu
//

#include <iostream>
#include <map>
#include <sycl/sycl.hpp>

using namespace sycl;

int main() {

std::map<info::device_type, std::string> m = {
{info::device_type::cpu, "cpu"},
{info::device_type::gpu, "gpu"},
{info::device_type::accelerator, "acc"},
{info::device_type::all, "all"}};

for (auto &d : device::get_devices()) {
std::cout << "Device: " << m[d.get_info<info::device::device_type>()]
<< std::endl;
}

return 0;
}
52 changes: 52 additions & 0 deletions SYCL/OneapiDeviceSelector/cuda_top.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// REQUIRES: cuda,gpu
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
// RUN: env ONEAPI_DEVICE_SELECTOR=cuda:gpu %t.out
// RUN: env ONEAPI_DEVICE_SELECTOR=cuda:0 %t.out
// RUN: env ONEAPI_DEVICE_SELECTOR="cuda:*" %t.out

// At this time, CUDA only has one device (GPU). So this is easy to accept CUDA
// and GPU and reject anything else. This test is just testing top level
// devices, not sub-devices.

#include <iostream>
#include <sycl/sycl.hpp>

using namespace sycl;
using namespace std;

int main() {

{
device d(default_selector_v);
string name = d.get_platform().get_info<info::platform::name>();
assert(name.find("CUDA") != string::npos);
cout << "CUDA GPU Device is found: " << boolalpha << d.is_gpu()
<< std::endl;
}
{
device d(gpu_selector_v);
string name = d.get_platform().get_info<info::platform::name>();
assert(name.find("CUDA") != string::npos);
cout << name << " is found: " << boolalpha << d.is_gpu() << std::endl;
}
{
try {
device d(cpu_selector_v);
cerr << "CPU device is found in error: " << d.is_cpu() << std::endl;
return -1;
} catch (...) {
cout << "Expectedly, cpu device is not found." << std::endl;
}
}
{
try {
device d(accelerator_selector_v);
cerr << "ACC device is found in error: " << d.is_accelerator()
<< std::endl;
} catch (...) {
cout << "Expectedly, ACC device is not found." << std::endl;
}
}

return 0;
}
7 changes: 7 additions & 0 deletions SYCL/OneapiDeviceSelector/illegal_BE_error.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %S/Inputs/trivial.cpp -o %t.out
// RUN: env ONEAPI_DEVICE_SELECTOR="macaroni:*"" %t.out
// XFAIL: *

// Calling ONEAPI_DEVICE_SELECTOR with an illegal backend should result in an
// error.
52 changes: 52 additions & 0 deletions SYCL/OneapiDeviceSelector/level_zero_top.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// REQUIRES: level_zero,gpu
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
// RUN: env ONEAPI_DEVICE_SELECTOR=level_zero:gpu %t.out
// RUN: env ONEAPI_DEVICE_SELECTOR=level_zero:0 %t.out
// RUN: env ONEAPI_DEVICE_SELECTOR="level_zero:*" %t.out

// At this time, LevelZero only has one device (GPU). So this is easy to accept
// L0 and GPU and reject anything else. This test is just testing top level
// devices, not sub-devices.

#include <iostream>
#include <sycl/sycl.hpp>

using namespace sycl;
using namespace std;

int main() {

{
device d(default_selector_v);
string name = d.get_platform().get_info<info::platform::name>();
assert(name.find("Level-Zero") != string::npos);
cout << "Level-Zero GPU Device is found: " << boolalpha << d.is_gpu()
<< std::endl;
}
{
device d(gpu_selector_v);
string name = d.get_platform().get_info<info::platform::name>();
assert(name.find("Level-Zero") != string::npos);
cout << name << " is found: " << boolalpha << d.is_gpu() << std::endl;
}
{
try {
device d(cpu_selector_v);
cerr << "CPU device is found in error: " << d.is_cpu() << std::endl;
return -1;
} catch (...) {
cout << "Expectedly, cpu device is not found." << std::endl;
}
}
{
try {
device d(accelerator_selector_v);
cerr << "ACC device is found in error: " << d.is_accelerator()
<< std::endl;
} catch (...) {
cout << "Expectedly, ACC device is not found." << std::endl;
}
}

return 0;
}
38 changes: 38 additions & 0 deletions SYCL/OneapiDeviceSelector/no_duplicate_devices.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// REQUIRES: opencl, cpu
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
// RUN: env ONEAPI_DEVICE_SELECTOR="opencl:*" %t.out 1 &> tmp.txt
// RUN: env ONEAPI_DEVICE_SELECTOR="opencl:*,cpu" cat tmp.txt | %t.out
// RUN: env ONEAPI_DEVICE_SELECTOR="opencl:cpu,cpu" cat tmp.txt | %t.out

// on the first run we pass a dummy arg to the app. On seeing that, we count the
// number of CPU devices and output it. That is piped to a file. On subsequent
// runs we cat the file and pipe that to app. The app then compares the number
// of CPU devices to that number, erroring if they differ.

// clang++ -fsycl -o ndd.bin no_duplicate_devices.cpp

#include <string>
#include <sycl/sycl.hpp>

using namespace sycl;

int main(int argc, char *argv[]) {

unsigned numCPUDevices = device::get_devices(info::device_type::cpu).size();

// when arg is provided, simply count the number of CPU devices and output.
if (argc > 1) {
std::cout << numCPUDevices << std::endl;
return 0; // done!
}

// when arg is not provided, check the count against the piped value.
char charBuff[16];
std::cin.read(charBuff, 16);
unsigned expectedNumCPUDevices = std::stoi(charBuff);

assert(numCPUDevices == expectedNumCPUDevices &&
"wrong number of cpu devices. duplicates.");

return 0;
}