Skip to content
Prev Previous commit
Next Next commit
Removed uses of device_context
  • Loading branch information
oleksandr-pavlyk committed Mar 17, 2024
commit 6309f2694322475f6b7d67f53ba4da601e5cffa0
23 changes: 13 additions & 10 deletions doc/dpctl.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,23 @@ Interplay with the Data Parallel Control Library
An example below demonstrates how the Data Parallel Extension for NumPy* can be
easily combined with the device management interface provided by dpctl package.

Literally, the SYCL* queue manager interface from the dpctl package allows
to set an input queue as the currently usable queue inside the context
manager's scope. This way an array creation function from the dpnp package
which is defined inside the context will allocate the data using that queue.

.. code-block:: python
:linenos:

import dpctl
import dpnp as np
import dpctl
import dpnp

d = dpctl.select_cpu_device()
x = dpnp.array([1, 2, 3], device=d)
s = dpnp.sum(x)

y = dpnp.linspace(0, dpnp.pi, num=10**6, device="gpu")
f = 1 + y * dpnp.sin(y)

with dpctl.device_context("opencl:gpu"):
x = np.array([1, 2, 3])
s = np.sum(x)
# locate argument where function attains global maximum
max_arg = x[dpnp.argmax(f)]
max_val = dpnp.max(f)


For more information please refer to `Data Parallel Control Library`_
documentation.
Expand Down
11 changes: 3 additions & 8 deletions examples/example10.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,7 @@ def example():


if __name__ == "__main__":
try:
import dpctl
import dpctl

with dpctl.device_context("opencl:gpu") as gpu_queue:
gpu_queue.get_sycl_device().print_device_info()
example()

except ImportError:
example()
dpctl.select_default_device().print_device_info()
example()
7 changes: 1 addition & 6 deletions tests/third_party/intel/zero-copy-test1.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,7 @@ def dppy_f(array_like_obj):
hb = np.arange(0, global_size, dtype="i4")
da = DuckUSMArray(hb.shape, dtype=hb.dtype, host_buffer=hb)

if dpctl.has_gpu_queues(dpctl.backend_type.level_zero):
print("\nScheduling on OpenCL GPU\n")
with dpctl.device_context("opencl:gpu") as gpu_queue:
dppy_f[global_size, dppy.DEFAULT_LOCAL_SIZE](da)
else:
print("\nSkip scheduling on OpenCL GPU\n")
dppy_f[global_size, dppy.DEFAULT_LOCAL_SIZE](da)

assert da[0] == 10

Expand Down