Ejemplo n.º 1
0
def test_dpctl_api(filter_str):
    device = dpctl.SyclDevice(filter_str)
    with dpctl.device_context(device):
        dpctl.lsplatform()
        dpctl.get_current_queue()
        dpctl.get_num_activated_queues()
        dpctl.is_in_device_context()
Ejemplo n.º 2
0
def test_dpctl_api(filter_str):
    if skip_test(filter_str):
        pytest.skip()

    device = dpctl.SyclDevice(filter_str)
    with dppy.offload_to_sycl_device(device):
        dpctl.lsplatform()
        dpctl.get_current_queue()
        dpctl.get_num_activated_queues()
        dpctl.is_in_device_context()
Ejemplo n.º 3
0
def test_is_in_device_context_inside_nested_device_ctxt_cpu():
    cpu = dpctl.SyclDevice("cpu")
    n = cpu.max_compute_units
    n_half = n // 2
    try:
        d0, d1 = cpu.create_subdevices(partition=[n_half, n - n_half])
    except Exception:
        pytest.skip("Could not create subdevices")
    assert 0 == dpctl.get_num_activated_queues()
    with dpctl.device_context(d0):
        assert 1 == dpctl.get_num_activated_queues()
        with dpctl.device_context(d1):
            assert 2 == dpctl.get_num_activated_queues()
            assert dpctl.is_in_device_context()
        assert dpctl.is_in_device_context()
        assert 1 == dpctl.get_num_activated_queues()
    assert not dpctl.is_in_device_context()
    assert 0 == dpctl.get_num_activated_queues()
Ejemplo n.º 4
0
    def __call__(self, *args, **kwargs):
        assert not kwargs, "Keyword Arguments are not supported"

        argtypes = self._get_argtypes(*args)
        compute_queue = None

        # Get the array type and whether all array are of same type or not
        array_type, uniform = self._datatype_is_same(argtypes)
        if not uniform:
            _raise_datatype_mixed_error(argtypes)

        if type(array_type) == USMNdArrayType:
            if dpctl.is_in_device_context():
                warnings.warn(cfd_ctx_mgr_wrng_msg)

            queues = []
            for i, argtype in enumerate(argtypes):
                if type(argtype) == USMNdArrayType:
                    memory = dpctl.memory.as_usm_memory(args[i])
                    if dpctl_version < (0, 12):
                        queue = memory._queue
                    else:
                        queue = memory.sycl_queue
                    queues.append(queue)

            # dpctl.utils.get_exeuction_queue() checks if the queues passed are equivalent and returns a
            # SYCL queue if they are equivalent and None if they are not.
            compute_queue = dpctl.utils.get_execution_queue(queues)
            if compute_queue is None:
                raise IndeterminateExecutionQueueError(
                    "Data passed as argument are not equivalent. Please "
                    "create dpctl.tensor.usm_ndarray with equivalent SYCL queue."
                )

        if compute_queue is None:
            try:
                compute_queue = dpctl.get_current_queue()
            except:
                _raise_no_device_found_error()

        kernel = self.specialize(argtypes, compute_queue)
        cfg = kernel.configure(
            kernel.sycl_queue, self.global_size, self.local_size
        )
        cfg(*args)
Ejemplo n.º 5
0
 def test_is_in_device_context_inside_nested_device_ctxt(self):
     with dpctl.device_context("opencl:cpu:0"):
         with dpctl.device_context("opencl:gpu:0"):
             self.assertTrue(dpctl.is_in_device_context())
         self.assertTrue(dpctl.is_in_device_context())
     self.assertFalse(dpctl.is_in_device_context())
Ejemplo n.º 6
0
 def test_is_in_device_context_outside_device_ctxt(self):
     self.assertFalse(dpctl.is_in_device_context())
Ejemplo n.º 7
0
def test_is_in_device_context_inside_nested_device_ctxt():
    with dpctl.device_context("opencl:cpu:0"):
        with dpctl.device_context("opencl:gpu:0"):
            assert dpctl.is_in_device_context()
        assert dpctl.is_in_device_context()
    assert not dpctl.is_in_device_context()
Ejemplo n.º 8
0
def test_is_in_device_context_inside_device_ctxt_cpu():
    with dpctl.device_context("opencl:cpu:0"):
        assert dpctl.is_in_device_context()
Ejemplo n.º 9
0
def test_is_in_device_context_outside_device_ctxt():
    assert not dpctl.is_in_device_context()