Skip to content

Provide a user-friendly version of queue construction from a device selector callable returning a bool #325

@keryell

Description

@keryell

There are common use cases when a user wants to use a very precise device in her code and uses for example a boolean predicate to filter the device, like

sycl::queue { [](sycl::device dev) {
      return "xilinx_u200_gen3x16_xdma_1_202110_1" == dev.template get_info<sycl::info::device::name>();
    } };

and to throw if there is no such device.
The problem is that in this code the returned bool is converted to an int, so when the device does exist it works because true is converted to 1, but if it is not the case, false is converted to 0, so any other existing device is then equivalent, which is surprising.
To avoid this, the code has to be changed into something like

sycl::queue { [](sycl::device dev) {
      return ("xilinx_u200_gen3x16_xdma_1_202110_1" == dev.template get_info<sycl::info::device::name>()) - 1;
    } };

to convert 0 or 1 to -1 or 0 for example.

Having a different behavior for the sycl::queue constructor with a device selector returning a bool would be cleaner.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions