def test_get_devices_with_enum_args(enum_args):
    devices = dpctl.get_devices(backend=enum_args[0], device_type=enum_args[1])
    if len(devices):
        check_if_backend_matches(devices, enum_args[0])
        check_if_device_type_matches(devices, enum_args[1])
    else:
        pytest.skip()
def test_get_devices_with_device_type_str(device_type_str):
    devices = dpctl.get_devices(device_type=device_type_str)
    if len(devices):
        d = string_to_device_type(device_type_str)
        check_if_device_type_matches(devices, d)
        check_if_device_type_is_valid(devices)
    else:
        pytest.skip()
def test_get_devices_with_device_type_enum(device_type):
    devices = dpctl.get_devices(device_type=device_type)
    if len(devices):
        if device_type != dty.all:
            check_if_device_type_matches(devices, device_type)
        check_if_device_type_is_valid(devices)
        check_if_backend_is_valid(devices)
    else:
        pytest.skip()
def test_get_devices_with_backend_str(backend_str):
    print(backend_str)
    devices = dpctl.get_devices(backend=backend_str)
    if len(devices):
        b = string_to_backend_type(backend_str)
        check_if_backend_matches(devices, b)
        check_if_device_type_is_valid(devices)
    else:
        pytest.skip()
def test_get_devices_with_string_args(str_args):
    devices = dpctl.get_devices(backend=str_args[0], device_type=str_args[1])
    if len(devices):
        d = string_to_device_type(str_args[1])
        b = string_to_backend_type(str_args[0])
        check_if_backend_matches(devices, b)
        check_if_device_type_matches(devices, d)
    else:
        pytest.skip()
def test_get_devices_with_backend_enum(backend):
    devices = dpctl.get_devices(backend=backend)
    if len(devices):
        check_if_device_type_is_valid(devices)
        check_if_backend_is_valid(devices)
        if backend != bty.all:
            check_if_backend_matches(devices, backend)

    else:
        pytest.skip()
示例#7
0
def test_filter_string_property():
    """
    Test that filter_string reconstructs the same device.
    """
    devices = dpctl.get_devices()
    for d in devices:
        if d.default_selector_score >= 0:
            dev_id = d.filter_string
            d_r = dpctl.SyclDevice(dev_id)
            assert d == d_r
示例#8
0
def test_filter_string_method():
    """
    Test that filter_string reconstructs the same device.
    """
    devices = dpctl.get_devices()
    for d in devices:
        for be in [True, False]:
            for dt in [True, False]:
                if d.default_selector_score >= 0:
                    dev_id = d.get_filter_string(include_backend=be,
                                                 include_device_type=dt)
                    d_r = dpctl.SyclDevice(dev_id)
                    assert d == d_r, "Failed "
def test_get_devices_with_device_type_str(device_type_str):
    num_devices = dpctl.get_num_devices(device_type=device_type_str)
    if num_devices > 0:
        devices = dpctl.get_devices(device_type=device_type_str)
        assert len(devices) == num_devices
        dty = string_to_device_type(device_type_str)
        check_if_device_type_matches(devices, dty)
        check_if_device_type_is_valid(devices)
        # check for consistency of ordering between filter selector
        # where backend is omitted, but device type and id is specified
        for i in range(num_devices):
            dev = dpctl.SyclDevice(":".join((device_type_str, str(i))))
            assert dev == devices[i]
    else:
        pytest.skip()
示例#10
0
def test_asarray_input_validation2():
    d = dpctl.get_devices()
    if len(d) < 2:
        pytest.skip("Not enough SYCL devices available")

    d0, d1 = d[:2]
    try:
        q0 = dpctl.SyclQueue(d0)
    except dpctl.SyclQueueCreationError:
        pytest.skip(f"SyclQueue could not be created for {d0}")
    try:
        q1 = dpctl.SyclQueue(d1)
    except dpctl.SyclQueueCreationError:
        pytest.skip(f"SyclQueue could not be created for {d1}")
    with pytest.raises(TypeError):
        dpt.asarray([1, 2], sycl_queue=q0, device=q1)
示例#11
0
def custom_select_device():
    """
    Programmatically select among available devices.
    Device created can be influenced by environment variable
    SYCL_DEVICE_FILTER, which determines SYCL devices seen by the
    SYCL runtime.
    """
    # select devices that support half-precision computation
    devs = [d for d in dpctl.get_devices() if d.has_aspect_fp16]
    # choose the device with highest default_selector score
    max_score = 0
    selected_dev = None
    for d in devs:
        if d.default_selector_score > max_score:
            max_score = d.default_selector_score
            selected_dev = d
    if selected_dev:
        print_device(selected_dev)
    else:
        print("No device with half-precision support is available.")
    return selected_dev
示例#12
0
def test_multi_device_different_platforms():
    devs = dpctl.get_devices()  # all devices
    if len(devs) > 1:
        with pytest.raises(ValueError):
            dpctl.SyclContext(devs)
示例#13
0
def test_to_device():
    X = dpt.usm_ndarray(1, "d")
    for dev in dpctl.get_devices():
        if dev.default_selector_score > 0:
            Y = X.to_device(dev)
            assert Y.sycl_device == dev