Skip to content

[SYCL][Test issue] Fix test-e2e/FilterSelector/select_device.cpp or replace with unit tests #20901

@againull

Description

@againull

Describe the bug

Test is not executed because of incorrect REQUIRES: cpu, gpu. (no device can be both cpu and gpu)

The way this test is written requires all three - opencl:cpu, opencl:gpu, level_zero:gpu be available, so something like this might work:
REQUIRES: any-device-is-cpu, any-device-is-gpu, any-device-is-level_zero, any-device-is-opencl
but still doesn't guarantee success because it seems currently there is no way to guarantee that both opencl:gpu and opencl:cpu are present (we might have opencl:cpu and level:gpu devices only, and above requirement will still be satisfied).

Tests also contains mistakes, it can be fixed like this (but probably better to just turn it into a unit test):

// RUN: %{build} -o %t.out
// RUN: env ONEAPI_DEVICE_SELECTOR="*:*" %{run-unfiltered-devices} %t.out
// RUN: env ONEAPI_DEVICE_SELECTOR="*:cpu" %{run-unfiltered-devices} %t.out
// RUN: env ONEAPI_DEVICE_SELECTOR=level_zero:gpu %{run-unfiltered-devices} %t.out
// RUN: env ONEAPI_DEVICE_SELECTOR=opencl:gpu %{run-unfiltered-devices} %t.out
// RUN: env ONEAPI_DEVICE_SELECTOR='*:cpu;level_zero:gpu' %{run-unfiltered-devices} %t.out
//
// Checks if only specified device types can be acquired from select_device
// when ONEAPI_DEVICE_SELECTOR is set
// Checks that no device is selected when no device of desired type is
// available.
//
// REQUIRES: any-device-is-cpu, any-device-is-gpu, any-device-is-level_zero, any-device-is-opencl


#include <iostream>

#include "../helpers.hpp"
#include <sycl/detail/core.hpp>
#include <sycl/platform.hpp>

using namespace sycl;
using namespace std;

int main() {
  std::string forcedDevice = env::getVal("ONEAPI_DEVICE_SELECTOR");
  if (forcedDevice == "*:*" ||
      forcedDevice.find("level_zero:gpu") != std::string::npos) {
    device d(default_selector_v);
    string name = d.get_platform().get_info<info::platform::name>();
    assert(name.find("Level-Zero") != string::npos);
  }
  if (forcedDevice != "*:*" &&
      forcedDevice.find("opencl:gpu") != std::string::npos) {
    device d(gpu_selector_v);
    string name = d.get_platform().get_info<info::platform::name>();
    assert(name.find("OpenCL") != string::npos);
  }
  if (forcedDevice == "*:*" ||
      forcedDevice.find("cpu") != std::string::npos) {
    device d(cpu_selector_v);
  }
  if (forcedDevice.find("cpu") == std::string::npos &&
                         forcedDevice.find("opencl") == std::string::npos &&
                         forcedDevice.find("*") == std::string::npos) {
    try {
      device d(cpu_selector_v);
    } catch (...) {
      return 0; // expected
    }
    std::cerr << "Error: CPU device is found, even though it shouldn't be"
              << std::endl;
    return -1;
  }

  return 0;
}

To reproduce

Environment

Linux

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions