Skip to content

Commit a0df5b7

Browse files
author
github-actions[doc-deploy-bot]
committed
Latest docs.
1 parent efae457 commit a0df5b7

File tree

4 files changed

+62
-24
lines changed

4 files changed

+62
-24
lines changed

master/api_reference/dpctl/generated/dpctl.tensor.from_dlpack.html

Lines changed: 60 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -821,60 +821,96 @@ <h1>dpctl.tensor.from_dlpack<a class="headerlink" href="#dpctl-tensor-from-dlpac
821821
<dl class="py function">
822822
<dt class="sig sig-object py" id="dpctl.tensor.from_dlpack">
823823
<span class="sig-prename descclassname"><span class="pre">dpctl.tensor.</span></span><span class="sig-name descname"><span class="pre">from_dlpack</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">x</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">/</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">*</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">device</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">copy</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#dpctl.tensor.from_dlpack" title="Permalink to this definition"></a></dt>
824-
<dd><p>Constructs <a class="reference internal" href="dpctl.tensor.usm_ndarray.html#dpctl.tensor.usm_ndarray" title="dpctl.tensor.usm_ndarray"><code class="xref py py-class docutils literal notranslate"><span class="pre">dpctl.tensor.usm_ndarray</span></code></a> instance from a Python
825-
object <code class="docutils literal notranslate"><span class="pre">x</span></code> that implements <code class="docutils literal notranslate"><span class="pre">__dlpack__</span></code> protocol.</p>
824+
<dd><p>Constructs <a class="reference internal" href="dpctl.tensor.usm_ndarray.html#dpctl.tensor.usm_ndarray" title="dpctl.tensor.usm_ndarray"><code class="xref py py-class docutils literal notranslate"><span class="pre">dpctl.tensor.usm_ndarray</span></code></a> or <a class="reference external" href="https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray" title="(in NumPy v2.1)"><code class="xref py py-class docutils literal notranslate"><span class="pre">numpy.ndarray</span></code></a> instance
825+
from a Python object <code class="docutils literal notranslate"><span class="pre">x</span></code> that implements <code class="docutils literal notranslate"><span class="pre">__dlpack__</span></code> protocol.</p>
826826
<dl class="field-list simple">
827827
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
828828
<dd class="field-odd"><ul class="simple">
829829
<li><p><strong>x</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#object" title="(in Python v3.13)"><em>object</em></a>) – A Python object representing an array that supports
830830
<code class="docutils literal notranslate"><span class="pre">__dlpack__</span></code> protocol.</p></li>
831-
<li><p><strong>device</strong> (Optional[str, <a class="reference internal" href="dpctl.SyclDevice.html#dpctl.SyclDevice" title="dpctl.SyclDevice"><code class="xref py py-class docutils literal notranslate"><span class="pre">dpctl.SyclDevice</span></code></a>, <a class="reference internal" href="dpctl.SyclQueue.html#dpctl.SyclQueue" title="dpctl.SyclQueue"><code class="xref py py-class docutils literal notranslate"><span class="pre">dpctl.SyclQueue</span></code></a>, <a class="reference internal" href="../tensor.utility_functions.html#dpctl.tensor.Device" title="dpctl.tensor.Device"><code class="xref py py-class docutils literal notranslate"><span class="pre">dpctl.tensor.Device</span></code></a>, tuple([<a class="reference external" href="https://docs.python.org/3/library/enum.html#enum.IntEnum" title="(in Python v3.13)"><code class="xref py py-class docutils literal notranslate"><span class="pre">enum.IntEnum</span></code></a>, int])])) – Array API concept of a device where the output array is to be placed.
832-
<code class="docutils literal notranslate"><span class="pre">device</span></code> can be <code class="docutils literal notranslate"><span class="pre">None</span></code>, a oneAPI filter selector
833-
string, an instance of <a class="reference internal" href="dpctl.SyclDevice.html#dpctl.SyclDevice" title="dpctl.SyclDevice"><code class="xref py py-class docutils literal notranslate"><span class="pre">dpctl.SyclDevice</span></code></a> corresponding to
834-
a non-partitioned SYCL device, an instance of
835-
<a class="reference internal" href="dpctl.SyclQueue.html#dpctl.SyclQueue" title="dpctl.SyclQueue"><code class="xref py py-class docutils literal notranslate"><span class="pre">dpctl.SyclQueue</span></code></a>, a <a class="reference internal" href="../tensor.utility_functions.html#dpctl.tensor.Device" title="dpctl.tensor.Device"><code class="xref py py-class docutils literal notranslate"><span class="pre">dpctl.tensor.Device</span></code></a> object
836-
returned by <a class="reference internal" href="generated/dpctl.tensor.usm_ndarray.device.html#dpctl.tensor.usm_ndarray.device" title="dpctl.tensor.usm_ndarray.device"><code class="xref py py-attr docutils literal notranslate"><span class="pre">dpctl.tensor.usm_ndarray.device</span></code></a>, or a
837-
2-tuple matching the format of the output of the <code class="docutils literal notranslate"><span class="pre">__dlpack_device__</span></code>
838-
method, an integer enumerator representing the device type followed by
839-
an integer representing the index of the device. The only supported
840-
<a class="reference internal" href="../tensor.constants.html#dpctl.tensor.DLDeviceType" title="dpctl.tensor.DLDeviceType"><code class="xref py py-class docutils literal notranslate"><span class="pre">dpctl.tensor.DLDeviceType</span></code></a> types are “kDLCPU” and
841-
“kDLOneAPI”.
842-
Default: <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p></li>
843-
<li><p><strong>copy</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><em>bool</em></a><em>, </em><em>optional</em>) – <p>Boolean indicating whether or not to copy the input.</p>
831+
<li><p><strong>device</strong> (Optional[str, <a class="reference internal" href="dpctl.SyclDevice.html#dpctl.SyclDevice" title="dpctl.SyclDevice"><code class="xref py py-class docutils literal notranslate"><span class="pre">dpctl.SyclDevice</span></code></a>, <a class="reference internal" href="dpctl.SyclQueue.html#dpctl.SyclQueue" title="dpctl.SyclQueue"><code class="xref py py-class docutils literal notranslate"><span class="pre">dpctl.SyclQueue</span></code></a>, <a class="reference internal" href="../tensor.utility_functions.html#dpctl.tensor.Device" title="dpctl.tensor.Device"><code class="xref py py-class docutils literal notranslate"><span class="pre">dpctl.tensor.Device</span></code></a>, tuple([<a class="reference external" href="https://docs.python.org/3/library/enum.html#enum.IntEnum" title="(in Python v3.13)"><code class="xref py py-class docutils literal notranslate"><span class="pre">enum.IntEnum</span></code></a>, int])])) – <p>Device where the output array is to be placed. <code class="docutils literal notranslate"><span class="pre">device</span></code> keyword values can be:</p>
844832
<ul>
845833
<li><dl class="simple">
846-
<dt>If <code class="docutils literal notranslate"><span class="pre">copy</span></code> is <code class="docutils literal notranslate"><span class="pre">True</span></code>, the input will always be</dt><dd><p>copied.</p>
834+
<dt><code class="docutils literal notranslate"><span class="pre">None</span></code></dt><dd><p>The data remains on the same device.</p>
835+
</dd>
836+
</dl>
837+
</li>
838+
<li><dl class="simple">
839+
<dt>oneAPI filter selector string</dt><dd><p>SYCL device selected by <a class="reference internal" href="../filter_selector_string.html#filter-selector-string"><span class="std std-ref">filter selector string</span></a>.</p>
847840
</dd>
848841
</dl>
849842
</li>
850843
<li><dl class="simple">
851-
<dt>If <code class="docutils literal notranslate"><span class="pre">False</span></code>, a <code class="docutils literal notranslate"><span class="pre">BufferError</span></code> will be raised if a</dt><dd><p>copy is deemed necessary.</p>
844+
<dt><a class="reference internal" href="dpctl.SyclDevice.html#dpctl.SyclDevice" title="dpctl.SyclDevice"><code class="xref py py-class docutils literal notranslate"><span class="pre">dpctl.SyclDevice</span></code></a></dt><dd><p>explicit SYCL device that must correspond to
845+
a non-partitioned SYCL device.</p>
852846
</dd>
853847
</dl>
854848
</li>
855849
<li><dl class="simple">
856-
<dt>If <code class="docutils literal notranslate"><span class="pre">None</span></code>, a copy will be made only if deemed</dt><dd><p>necessary, otherwise, the existing memory buffer will
857-
be reused.</p>
850+
<dt><a class="reference internal" href="dpctl.SyclQueue.html#dpctl.SyclQueue" title="dpctl.SyclQueue"><code class="xref py py-class docutils literal notranslate"><span class="pre">dpctl.SyclQueue</span></code></a></dt><dd><p>implies SYCL device targeted by the SYCL queue.</p>
851+
</dd>
852+
</dl>
853+
</li>
854+
<li><dl class="simple">
855+
<dt><a class="reference internal" href="../tensor.utility_functions.html#dpctl.tensor.Device" title="dpctl.tensor.Device"><code class="xref py py-class docutils literal notranslate"><span class="pre">dpctl.tensor.Device</span></code></a></dt><dd><p>implies SYCL device <cite>device.sycl_queue</cite>. The <cite>Device</cite> object
856+
is obtained via <a class="reference internal" href="generated/dpctl.tensor.usm_ndarray.device.html#dpctl.tensor.usm_ndarray.device" title="dpctl.tensor.usm_ndarray.device"><code class="xref py py-attr docutils literal notranslate"><span class="pre">dpctl.tensor.usm_ndarray.device</span></code></a>.</p>
857+
</dd>
858+
</dl>
859+
</li>
860+
<li><dl class="simple">
861+
<dt><code class="docutils literal notranslate"><span class="pre">(device_type,</span> <span class="pre">device_id)</span></code></dt><dd><p>2-tuple matching the format of the output of the <code class="docutils literal notranslate"><span class="pre">__dlpack_device__</span></code>
862+
method: an integer enumerator representing the device type followed by
863+
an integer representing the index of the device.
864+
The only supported <a class="reference internal" href="../tensor.constants.html#dpctl.tensor.DLDeviceType" title="dpctl.tensor.DLDeviceType"><code class="xref py py-class docutils literal notranslate"><span class="pre">dpctl.tensor.DLDeviceType</span></code></a> device types
865+
are <code class="docutils literal notranslate"><span class="pre">&quot;kDLCPU&quot;</span></code> and <code class="docutils literal notranslate"><span class="pre">&quot;kDLOneAPI&quot;</span></code>.</p>
858866
</dd>
859867
</dl>
860868
</li>
861869
</ul>
862870
<p>Default: <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p>
863871
</p></li>
872+
<li><p><strong>copy</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><em>bool</em></a><em>, </em><em>optional</em>) – <p>Boolean indicating whether or not to copy the input.</p>
873+
<ul>
874+
<li><p>If <code class="docutils literal notranslate"><span class="pre">copy</span></code> is <code class="docutils literal notranslate"><span class="pre">True</span></code>, the input will always be
875+
copied.</p></li>
876+
<li><p>If <code class="docutils literal notranslate"><span class="pre">False</span></code>, a <code class="docutils literal notranslate"><span class="pre">BufferError</span></code> will be raised if a
877+
copy is deemed necessary.</p></li>
878+
<li><p>If <code class="docutils literal notranslate"><span class="pre">None</span></code>, a copy will be made only if deemed
879+
necessary, otherwise, the existing memory buffer will
880+
be reused.</p></li>
881+
</ul>
882+
<p>Default: <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p>
883+
</p></li>
864884
</ul>
865885
</dd>
866886
<dt class="field-even">Returns<span class="colon">:</span></dt>
867-
<dd class="field-even"><p>An array containing the data in <code class="docutils literal notranslate"><span class="pre">x</span></code>. When <code class="docutils literal notranslate"><span class="pre">copy</span></code> is
887+
<dd class="field-even"><p><p>An array containing the data in <code class="docutils literal notranslate"><span class="pre">x</span></code>. When <code class="docutils literal notranslate"><span class="pre">copy</span></code> is
868888
<code class="docutils literal notranslate"><span class="pre">None</span></code> or <code class="docutils literal notranslate"><span class="pre">False</span></code>, this may be a view into the original
869889
memory.</p>
890+
<p>The type of the returned object
891+
depends on where the data backing up input object <code class="docutils literal notranslate"><span class="pre">x</span></code> resides.
892+
If it resides in a USM allocation on a SYCL device, the
893+
type <a class="reference internal" href="dpctl.tensor.usm_ndarray.html#dpctl.tensor.usm_ndarray" title="dpctl.tensor.usm_ndarray"><code class="xref py py-class docutils literal notranslate"><span class="pre">dpctl.tensor.usm_ndarray</span></code></a> is returned, otherwise if it resides
894+
on <code class="docutils literal notranslate"><span class="pre">&quot;kDLCPU&quot;</span></code> device the type is <a class="reference external" href="https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray" title="(in NumPy v2.1)"><code class="xref py py-class docutils literal notranslate"><span class="pre">numpy.ndarray</span></code></a>, and otherwise
895+
an exception is raised.</p>
896+
<div class="admonition note">
897+
<p class="admonition-title">Note</p>
898+
<p>If the return type is <a class="reference internal" href="dpctl.tensor.usm_ndarray.html#dpctl.tensor.usm_ndarray" title="dpctl.tensor.usm_ndarray"><code class="xref py py-class docutils literal notranslate"><span class="pre">dpctl.tensor.usm_ndarray</span></code></a>, the associated
899+
SYCL queue is derived from the <code class="docutils literal notranslate"><span class="pre">device</span></code> keyword. When <code class="docutils literal notranslate"><span class="pre">device</span></code>
900+
keyword value has type <a class="reference internal" href="dpctl.SyclQueue.html#dpctl.SyclQueue" title="dpctl.SyclQueue"><code class="xref py py-class docutils literal notranslate"><span class="pre">dpctl.SyclQueue</span></code></a>, the explicit queue
901+
instance is used, when <code class="docutils literal notranslate"><span class="pre">device</span></code> keyword value has type <a class="reference internal" href="../tensor.utility_functions.html#dpctl.tensor.Device" title="dpctl.tensor.Device"><code class="xref py py-class docutils literal notranslate"><span class="pre">dpctl.tensor.Device</span></code></a>,
902+
the <code class="docutils literal notranslate"><span class="pre">device.sycl_queue</span></code> is used. In all other cases, the cached
903+
SYCL queue corresponding to the implied SYCL device is used.</p>
904+
</div>
905+
</p>
870906
</dd>
871907
<dt class="field-odd">Return type<span class="colon">:</span></dt>
872-
<dd class="field-odd"><p><a class="reference internal" href="dpctl.tensor.usm_ndarray.html#dpctl.tensor.usm_ndarray" title="dpctl.tensor.usm_ndarray">usm_ndarray</a></p>
908+
<dd class="field-odd"><p>Alternative[<a class="reference internal" href="dpctl.tensor.usm_ndarray.html#dpctl.tensor.usm_ndarray" title="dpctl.tensor.usm_ndarray">usm_ndarray</a>, <a class="reference external" href="https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray" title="(in NumPy v2.1)">numpy.ndarray</a>]</p>
873909
</dd>
874910
<dt class="field-even">Raises<span class="colon">:</span></dt>
875911
<dd class="field-even"><ul class="simple">
876912
<li><p><a class="reference external" href="https://docs.python.org/3/library/exceptions.html#TypeError" title="(in Python v3.13)"><strong>TypeError</strong></a> – if <code class="docutils literal notranslate"><span class="pre">x</span></code> does not implement <code class="docutils literal notranslate"><span class="pre">__dlpack__</span></code> method</p></li>
877-
<li><p><a class="reference external" href="https://docs.python.org/3/library/exceptions.html#ValueError" title="(in Python v3.13)"><strong>ValueError</strong></a> – if the input array resides on an unsupported device</p></li>
913+
<li><p><a class="reference external" href="https://docs.python.org/3/library/exceptions.html#ValueError" title="(in Python v3.13)"><strong>ValueError</strong></a> – if data of the input object resides on an unsupported device</p></li>
878914
</ul>
879915
</dd>
880916
</dl>
@@ -896,7 +932,9 @@ <h1>dpctl.tensor.from_dlpack<a class="headerlink" href="#dpctl-tensor-from-dlpac
896932
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_array</span><span class="o">.</span><span class="n">__dlpack_device__</span><span class="p">()</span>
897933

898934
<span class="n">C</span> <span class="o">=</span> <span class="n">Container</span><span class="p">(</span><span class="n">dpt</span><span class="o">.</span><span class="n">linspace</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">100</span><span class="p">,</span> <span class="n">num</span><span class="o">=</span><span class="mi">20</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="s2">&quot;int16&quot;</span><span class="p">))</span>
935+
<span class="c1"># create usm_ndarray view</span>
899936
<span class="n">X</span> <span class="o">=</span> <span class="n">dpt</span><span class="o">.</span><span class="n">from_dlpack</span><span class="p">(</span><span class="n">C</span><span class="p">)</span>
937+
<span class="c1"># migrate content of the container to device of type kDLCPU</span>
900938
<span class="n">Y</span> <span class="o">=</span> <span class="n">dpt</span><span class="o">.</span><span class="n">from_dlpack</span><span class="p">(</span><span class="n">C</span><span class="p">,</span> <span class="n">device</span><span class="o">=</span><span class="p">(</span><span class="n">dpt</span><span class="o">.</span><span class="n">DLDeviceType</span><span class="o">.</span><span class="n">kDLCPU</span><span class="p">,</span> <span class="mi">0</span><span class="p">))</span>
901939
</pre></div>
902940
</div>

0 commit comments

Comments
 (0)