Skip to content

Commit e841145

Browse files
Merge include-dpctl-tensor into remove_c_api_tensor
2 parents 996ecfb + 851628b commit e841145

File tree

9 files changed

+142
-24
lines changed

9 files changed

+142
-24
lines changed

.github/workflows/generate_coverage.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
name: Generate coverage and push to Coveralls.io
1212

1313
runs-on: ubuntu-latest
14-
timeout-minutes: 120
14+
timeout-minutes: 150
1515

1616
permissions:
1717
# Needed to cancel any previous runs that are not completed for a given workflow
@@ -122,7 +122,7 @@ jobs:
122122
uses: nick-fields/retry@ce71cc2ab81d554ebbe88c79ab5975992d79ba08 # v3.0.2
123123
with:
124124
shell: bash
125-
timeout_minutes: 90
125+
timeout_minutes: 120
126126
max_attempts: 5
127127
retry_on: error
128128
command: |
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
//*****************************************************************************
2+
// Copyright (c) 2026, Intel Corporation
3+
// All rights reserved.
4+
//
5+
// Redistribution and use in source and binary forms, with or without
6+
// modification, are permitted provided that the following conditions are met:
7+
// - Redistributions of source code must retain the above copyright notice,
8+
// this list of conditions and the following disclaimer.
9+
// - Redistributions in binary form must reproduce the above copyright notice,
10+
// this list of conditions and the following disclaimer in the documentation
11+
// and/or other materials provided with the distribution.
12+
// - Neither the name of the copyright holder nor the names of its contributors
13+
// may be used to endorse or promote products derived from this software
14+
// without specific prior written permission.
15+
//
16+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19+
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20+
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21+
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22+
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23+
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24+
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25+
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
26+
// THE POSSIBILITY OF SUCH DAMAGE.
27+
//*****************************************************************************
28+
//
29+
//===---------------------------------------------------------------------===//
30+
///
31+
/// \file
32+
/// This file provides access to dpctl_ext's C-API, including:
33+
/// - dpctl C-API (from external dpctl package - SYCL interface)
34+
/// - dpctl_ext tensor C-API (usm_ndarray)
35+
//===---------------------------------------------------------------------===//
36+
37+
#pragma once
38+
39+
// Include dpctl C-API headers explicitly from external dpctl package (SYCL
40+
// interface)
41+
// TODO: Once dpctl removes its tensor module and stabilizes dpctl_capi.h,
42+
// we can simplify to just: #include "dpctl_capi.h"
43+
// For now, explicit includes ensure we only get SYCL interface without tensor.
44+
45+
#include "syclinterface/dpctl_sycl_extension_interface.h"
46+
#include "syclinterface/dpctl_sycl_types.h"
47+
48+
#ifdef __cplusplus
49+
#define CYTHON_EXTERN_C extern "C"
50+
#else
51+
#define CYTHON_EXTERN_C
52+
#endif
53+
54+
#include "dpctl/_sycl_context.h"
55+
#include "dpctl/_sycl_context_api.h"
56+
#include "dpctl/_sycl_device.h"
57+
#include "dpctl/_sycl_device_api.h"
58+
#include "dpctl/_sycl_event.h"
59+
#include "dpctl/_sycl_event_api.h"
60+
#include "dpctl/_sycl_queue.h"
61+
#include "dpctl/_sycl_queue_api.h"
62+
#include "dpctl/memory/_memory.h"
63+
#include "dpctl/memory/_memory_api.h"
64+
#include "dpctl/program/_program.h"
65+
#include "dpctl/program/_program_api.h"
66+
67+
// Include the generated Cython C-API headers for usm_ndarray
68+
// These headers are generated during build and placed in the build directory
69+
#include "dpctl_ext/tensor/_usmarray.h"
70+
#include "dpctl_ext/tensor/_usmarray_api.h"
71+
72+
/*
73+
* Function to import dpctl_ext C-API and make it available.
74+
* This imports both:
75+
* - dpctl C-API (from external dpctl package - SYCL interface)
76+
* - dpctl_ext C-API (tensor interface - usm_ndarray)
77+
*
78+
* C functions can use dpctl_ext's C-API functions without linking to
79+
* shared objects defining these symbols, if they call `import_dpctl_ext()`
80+
* prior to using those symbols.
81+
*
82+
* It is declared inline to allow multiple definitions in
83+
* different translation units.
84+
*
85+
* TODO: When dpctl_ext is renamed to dpctl.tensor:
86+
* - Rename this file: dpctl_ext_capi.h → dpctl/tensor/tensor_capi.h
87+
* (Use tensor_capi.h, NOT dpctl_capi.h, to avoid conflict with external
88+
* dpctl)
89+
* - Rename this function: import_dpctl_ext() → import_dpctl_tensor()
90+
* - Include external dpctl_capi.h and simplify imports to use import_dpctl()
91+
*/
92+
static inline void import_dpctl_ext(void)
93+
{
94+
// Import dpctl SYCL interface
95+
// TODO: Once dpctl removes its tensor module and stabilizes dpctl_capi.h,
96+
// we can simplify to just: import_dpctl()
97+
import_dpctl___sycl_device();
98+
import_dpctl___sycl_context();
99+
import_dpctl___sycl_event();
100+
import_dpctl___sycl_queue();
101+
import_dpctl__memory___memory();
102+
import_dpctl__program___program();
103+
// Import dpctl_ext tensor interface
104+
import_dpctl_ext__tensor___usmarray();
105+
return;
106+
}

dpctl_ext/tensor/_dlpack.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1086,7 +1086,7 @@ def from_dlpack(x, /, *, device=None, copy=None):
10861086
.. code-block:: python
10871087
10881088
import dpctl
1089-
import dpctl.tensor as dpt
1089+
import dpctl_ext.tensor as dpt
10901090
10911091
class Container:
10921092
"Helper class implementing `__dlpack__` protocol"

dpctl_ext/tensor/_usmarray.pyx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ cdef class usm_ndarray:
466466
467467
.. code-block:: python
468468
469-
from dpctl import tensor
469+
from dpctl_ext import tensor
470470
471471
x = tensor.ones((3, 10, 7))
472472
y = tensor.flip(x[:, 1::2], axis=1)
@@ -660,7 +660,7 @@ cdef class usm_ndarray:
660660
661661
.. code-block:: python
662662
663-
from dpctl import tensor
663+
from dpctl_ext import tensor
664664
665665
x = tensor.arange(899)
666666
x.shape = (29, 31)
@@ -765,7 +765,7 @@ cdef class usm_ndarray:
765765
766766
.. code-block:: python
767767
768-
from dpctl import tensor
768+
from dpctl_ext import tensor
769769
770770
x = tensor.zeros((20, 30))
771771
xv = x[10:, :15]
@@ -878,7 +878,7 @@ cdef class usm_ndarray:
878878
879879
.. code-block:: python
880880
881-
>>> from dpctl import tensor
881+
>>> from dpctl_ext import tensor
882882
>>> x = tensor.ones(10)
883883
>>> x.device
884884
Device(level_zero:gpu:0)
@@ -929,7 +929,7 @@ cdef class usm_ndarray:
929929
930930
.. code-block:: python
931931
932-
from dpctl import tensor
932+
from dpctl_ext import tensor
933933
934934
# Create complex array from
935935
# arrays of real and imaginary parts
@@ -958,7 +958,7 @@ cdef class usm_ndarray:
958958
959959
.. code-block:: python
960960
961-
from dpctl import tensor
961+
from dpctl_ext import tensor
962962
963963
# Reset imaginary part of complex array
964964
@@ -1050,7 +1050,7 @@ cdef class usm_ndarray:
10501050
.. code-block:: python
10511051
10521052
import dpctl
1053-
import dpctl.tensor as dpt
1053+
import dpctl_ext.tensor as dpt
10541054
10551055
x = dpt.full(10**6, 2, dtype="int64")
10561056
q_prof = dpctl.SyclQueue(
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# DLPack header
22

3-
The header `dlpack.h` downloaded from `https://github.com/dmlc/dlpack.git` remote at tag v1.0rc commit [`62100c1`](https://github.com/dmlc/dlpack/commit/62100c123144ae7a80061f4220be2dbd3cbaefc7).
3+
The header `dlpack.h` downloaded from `https://github.com/dmlc/dlpack.git` remote at tag v1.3 commit [`84d107b`](https://github.com/dmlc/dlpack/commit/84d107bf416c6bab9ae68ad285876600d230490d).
44

5-
The file can also be viewed using github web interface at https://github.com/dmlc/dlpack/blob/62100c123144ae7a80061f4220be2dbd3cbaefc7/include/dlpack/dlpack.h
5+
The file can also be viewed using github web interface at https://github.com/dmlc/dlpack/blob/v1.3/include/dlpack/dlpack.h
66

77
License file was retrieved from https://github.com/dmlc/dlpack/blob/main/LICENSE

dpctl_ext/tensor/include/dlpack/dlpack.h

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#define DLPACK_MAJOR_VERSION 1
2020

2121
/*! \brief The current minor version of dlpack */
22-
#define DLPACK_MINOR_VERSION 2
22+
#define DLPACK_MINOR_VERSION 3
2323

2424
/*! \brief DLPACK_DLL prefix for windows */
2525
#ifdef _WIN32
@@ -397,7 +397,7 @@ typedef enum
397397
} DLManagedTensorVersioned;
398398

399399
//----------------------------------------------------------------------
400-
// DLPack `__c_dlpack_exchange_api__` fast exchange protocol definitions
400+
// DLPack `__dlpack_c_exchange_api__` fast exchange protocol definitions
401401
//----------------------------------------------------------------------
402402
/*!
403403
* \brief Request a producer library to create a new tensor.
@@ -442,6 +442,7 @@ typedef enum
442442
*
443443
* \param py_object The Python object to convert. Must have the same type
444444
* as the one the `DLPackExchangeAPI` was discovered from.
445+
* \param out The output DLManagedTensorVersioned.
445446
* \return The owning DLManagedTensorVersioned* or NULL on failure with a
446447
* Python exception set. If the data cannot be described using
447448
* DLPack this should be a BufferError if possible. \note - As a C function,
@@ -561,17 +562,24 @@ typedef enum
561562
* \brief Framework-specific function pointers table for DLPack exchange.
562563
*
563564
* Additionally to `__dlpack__()` we define a C function table sharable by
564-
* Python implementations via `__c_dlpack_exchange_api__`.
565-
* This attribute must be set on the type as a Python integer compatible
566-
* with `PyLong_FromVoidPtr`/`PyLong_AsVoidPtr`.
565+
*
566+
* Python implementations via `__dlpack_c_exchange_api__`.
567+
* This attribute must be set on the type as a Python PyCapsule
568+
* with name "dlpack_exchange_api".
567569
*
568570
* A consumer library may use a pattern such as:
569571
*
570572
* \code
571573
*
572-
* PyObject *api_obj = type(tensor_obj).__c_dlpack_exchange_api__; // as
573-
* C-code MyDLPackExchangeAPI *api = PyLong_AsVoidPtr(api_obj); if (api ==
574-
* NULL && PyErr_Occurred()) { goto handle_error; }
574+
* PyObject *api_capsule = PyObject_GetAttrString(
575+
* (PyObject *)Py_TYPE(tensor_obj), "__dlpack_c_exchange_api__")
576+
* );
577+
* if (api_capsule == NULL) { goto handle_error; }
578+
* MyDLPackExchangeAPI *api = (MyDLPackExchangeAPI *)PyCapsule_GetPointer(
579+
* api_capsule, "dlpack_exchange_api"
580+
* );
581+
* Py_DECREF(api_capsule);
582+
* if (api == NULL) { goto handle_error; }
575583
*
576584
* \endcode
577585
*
@@ -652,7 +660,7 @@ typedef enum
652660
/*!
653661
* \brief Producer function pointer for DLPackManagedTensorToPyObject
654662
* This function must be not NULL.
655-
* \sa DLPackManagedTensorToPyObject
663+
* \sa DLPackManagedTensorToPyObjectNoSync
656664
*/
657665
DLPackManagedTensorToPyObjectNoSync managed_tensor_to_py_object_no_sync;
658666
/*!

dpnp/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@
6060
[os.getenv("PATH", ""), dll_path]
6161
)
6262

63+
# TODO: revert to `from dpctl.tensor...`
64+
# when dpnp fully migrates dpctl/tensor
65+
from dpctl_ext.tensor import __array_api_version__, DLDeviceType
6366

6467
from .dpnp_array import dpnp_array as ndarray
6568
from .dpnp_array_api_info import __array_namespace_info__

dpnp/backend/extensions/lapack/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ set(_module_src
5555

5656
pybind11_add_module(${python_module_name} MODULE ${_module_src})
5757
add_sycl_to_target(TARGET ${python_module_name} SOURCES ${_module_src})
58+
target_link_libraries(${python_module_name} PRIVATE DpctlExtCAPI)
5859

5960
# Ensure Cython modules build first so _usmarray.h exists
6061
add_dependencies(${python_module_name} _usmarray)

dpnp/dpnp_iface_statistics.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@
5353
import dpnp
5454
import dpnp.backend.extensions.statistics._statistics_impl as statistics_ext
5555
from dpctl_ext.tensor._numpy_helper import normalize_axis_index
56-
from dpnp.dpnp_utils.dpnp_utils_common import (
56+
57+
from .dpnp_utils import get_usm_allocations
58+
from .dpnp_utils.dpnp_utils_common import (
5759
result_type_for_device,
5860
to_supported_dtypes,
5961
)
60-
61-
from .dpnp_utils import get_usm_allocations
6262
from .dpnp_utils.dpnp_utils_reduction import dpnp_wrap_reduction_call
6363
from .dpnp_utils.dpnp_utils_statistics import dpnp_cov, dpnp_median
6464

0 commit comments

Comments
 (0)