Skip to content

Commit 416bdcf

Browse files
update docs about GPU arrays (#2704)
1 parent 72ebec6 commit 416bdcf

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

doc/sources/index.rst

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,21 @@ Note: executing on GPU has `additional system software requirements <https://www
102102
.. tab:: With GPU arrays
103103
.. code-block:: python
104104
105+
import os
106+
os.environ["SCIPY_ARRAY_API"] = "1"
105107
import numpy as np
106108
import dpnp
107109
from sklearnex import patch_sklearn
108110
patch_sklearn()
111+
from sklearn import config_context
109112
110113
from sklearn.cluster import DBSCAN
111114
112115
X = np.array([[1., 2.], [2., 2.], [2., 3.],
113116
[8., 7.], [8., 8.], [25., 80.]], dtype=np.float32)
114117
X = dpnp.array(X, device="gpu")
115-
clustering = DBSCAN(eps=3, min_samples=2).fit(X)
118+
with config_context(array_api_dispatch=True)
119+
clustering = DBSCAN(eps=3, min_samples=2).fit(X)
116120
117121
.. tab:: Without patching
118122
.. tabs::
@@ -131,14 +135,18 @@ Note: executing on GPU has `additional system software requirements <https://www
131135
.. tab:: With GPU arrays
132136
.. code-block:: python
133137
138+
import os
139+
os.environ["SCIPY_ARRAY_API"] = "1"
134140
import numpy as np
135141
import dpnp
142+
from sklearnex import config_context
136143
from sklearnex.cluster import DBSCAN
137144
138145
X = np.array([[1., 2.], [2., 2.], [2., 3.],
139146
[8., 7.], [8., 8.], [25., 80.]], dtype=np.float32)
140147
X = dpnp.array(X, device="gpu")
141-
clustering = DBSCAN(eps=3, min_samples=2).fit(X)
148+
with config_context(array_api_dispatch=True)
149+
clustering = DBSCAN(eps=3, min_samples=2).fit(X)
142150
143151
144152
See :ref:`oneapi_gpu` for other ways of executing on GPU.

doc/sources/oneapi-gpu.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,12 @@ call :code:`sklearnex.get_config()`.
128128
located, and the result will be returned as :code:`usm_ndarray` to the same
129129
device.
130130

131+
.. important::
132+
In order to enable zero-copy operations on GPU arrays, it's necessary to enable
133+
:ref:`array API support <array_api>` for scikit-learn. Otherwise, if passing a GPU
134+
array and array API support is not enabled, GPU arrays will first be transferred to
135+
host and then back to GPU.
136+
131137
.. note::
132138
All the input data for an algorithm must reside on the same device.
133139

@@ -154,7 +160,7 @@ A full example of how to patch your code with Intel CPU/GPU optimizations:
154160
X = np.array([[1., 2.], [2., 2.], [2., 3.],
155161
[8., 7.], [8., 8.], [25., 80.]], dtype=np.float32)
156162
with config_context(target_offload="gpu:0"):
157-
clustering = DBSCAN(eps=3, min_samples=2).fit(X)
163+
clustering = DBSCAN(eps=3, min_samples=2).fit(X)
158164
159165
160166
.. note:: Current offloading behavior restricts fitting and predictions (a.k.a. inference) of any models to be

0 commit comments

Comments
 (0)