Coverage for cuda/core/_dlpack.pyx: 92.56%
121 statements
« prev ^ index » next coverage.py v7.16.0, created at 2026-09-03 02:41 +0000
« prev ^ index » next coverage.py v7.16.0, created at 2026-09-03 02:41 +0000
1# SPDX-FileCopyrightText: Copyright (c) 2024-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2#
3# SPDX-License-Identifier: Apache-2.0
6from enum import IntEnum
9cdef void pycapsule_deleter(object capsule) noexcept:
10 cdef DLManagedTensor* dlm_tensor
11 cdef DLManagedTensorVersioned* dlm_tensor_ver
12 # Do not invoke the deleter on a used capsule.
13 if cpython.PyCapsule_IsValid( 2b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ aba bbcbdbebfb
14 capsule, DLPACK_TENSOR_UNUSED_NAME):
15 dlm_tensor = <DLManagedTensor*>( 1a
16 cpython.PyCapsule_GetPointer( 1a
17 capsule, DLPACK_TENSOR_UNUSED_NAME))
18 if dlm_tensor.deleter: 1a
19 dlm_tensor.deleter(dlm_tensor) 1a
20 elif cpython.PyCapsule_IsValid( 2hbb c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ aba bbcbdbebfb
21 capsule, DLPACK_VERSIONED_TENSOR_UNUSED_NAME):
22 dlm_tensor_ver = <DLManagedTensorVersioned*>( 1a
23 cpython.PyCapsule_GetPointer( 1a
24 capsule, DLPACK_VERSIONED_TENSOR_UNUSED_NAME))
25 if dlm_tensor_ver.deleter: 1a
26 dlm_tensor_ver.deleter(dlm_tensor_ver) 2hba
29cdef void deleter(DLManagedTensor* tensor) noexcept with gil:
30 if tensor: 2gba
31 if tensor.dl_tensor.shape: 2gba
32 stdlib.free(tensor.dl_tensor.shape) 2gba
33 if tensor.manager_ctx: 2gba
34 cpython.Py_DECREF(<object>tensor.manager_ctx) 2gba
35 tensor.manager_ctx = NULL 2gba
36 stdlib.free(tensor) 2gba
39cdef void versioned_deleter(DLManagedTensorVersioned* tensor) noexcept with gil:
40 if tensor: 2b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ abgba bbcbdbebfb
41 if tensor.dl_tensor.shape: 2b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ aba bbcbdbebfb
42 stdlib.free(tensor.dl_tensor.shape) 2b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ aba bbcbdbebfb
43 if tensor.manager_ctx: 2b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ aba bbcbdbebfb
44 cpython.Py_DECREF(<object>tensor.manager_ctx) 2b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ aba bbcbdbebfb
45 tensor.manager_ctx = NULL 2b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ aba bbcbdbebfb
46 stdlib.free(tensor) 2b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ aba bbcbdbebfb
49cdef inline DLManagedTensorVersioned* allocate_dlm_tensor_versioned() except? NULL:
50 cdef DLManagedTensorVersioned* dlm_tensor_ver = NULL 2b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ aba bbcbdbebfb
51 try: 2b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ aba bbcbdbebfb
52 dlm_tensor_ver = <DLManagedTensorVersioned*>( 2b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ aba bbcbdbebfb
53 stdlib.malloc(sizeof(DLManagedTensorVersioned)))
54 dlm_tensor_ver.dl_tensor.shape = NULL 2b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ aba bbcbdbebfb
55 dlm_tensor_ver.manager_ctx = NULL 2b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ aba bbcbdbebfb
56 return dlm_tensor_ver 2b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ aba bbcbdbebfb
57 except:
58 if dlm_tensor_ver:
59 stdlib.free(dlm_tensor_ver)
60 raise
63cdef inline DLManagedTensor* allocate_dlm_tensor() except? NULL:
64 cdef DLManagedTensor* dlm_tensor = NULL 2gba
65 try: 2gba
66 dlm_tensor = <DLManagedTensor*>( 2gba
67 stdlib.malloc(sizeof(DLManagedTensor)))
68 dlm_tensor.dl_tensor.shape = NULL 2gba
69 dlm_tensor.manager_ctx = NULL 2gba
70 return dlm_tensor 2gba
71 except:
72 if dlm_tensor:
73 stdlib.free(dlm_tensor)
74 raise
77cdef inline int setup_dl_tensor_layout(DLTensor* dl_tensor, object buf) except -1:
78 dl_tensor.ndim = 1 2b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ abgba bbcbdbebfb
79 cdef int64_t* shape_strides = \
80 <int64_t*>stdlib.malloc(sizeof(int64_t) * 2) 2b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ abgba bbcbdbebfb
81 if shape_strides == NULL: 2b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ abgba bbcbdbebfb
82 raise MemoryError()
83 # DLPack v1.2+ requires non-NULL strides for ndim != 0.
84 shape_strides[0] = <int64_t>buf.size 2b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ abgba bbcbdbebfb
85 shape_strides[1] = 1 2b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ abgba bbcbdbebfb
86 dl_tensor.shape = shape_strides 2b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ abgba bbcbdbebfb
87 dl_tensor.strides = shape_strides + 1 2b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ abgba bbcbdbebfb
88 dl_tensor.byte_offset = 0 2b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ abgba bbcbdbebfb
89 return 0 2b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ abgba bbcbdbebfb
92def classify_dl_device(buf: object) -> tuple[int, int]:
93 """Classify a buffer into a DLPack (device_type, device_id) pair.
95 ``buf`` must expose ``is_device_accessible``, ``is_host_accessible``,
96 ``is_managed``, and ``device_id`` attributes.
97 """
98 cdef bint d = buf.is_device_accessible 2b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ abgbibmbjbkblba bbcbdbebfbnb
99 cdef bint h = buf.is_host_accessible 2b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ abgbibmbjbkblba bbcbdbebfbnb
100 if d and not h: 2b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ abgbibmbjbkblba bbcbdbebfbnb
101 return (_kDLCUDA, buf.device_id) 2mba nb
102 if d and h: 2b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ abgbibjbkblbbbcbdbebfb
103 return (_kDLCUDAManaged if buf.is_managed else _kDLCUDAHost, 0) 2b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ abkblbbbcbdbebfb
104 if not d and h: 2gbibjb
105 return (_kDLCPU, 0) 2jb
106 raise BufferError("buffer is neither device-accessible nor host-accessible") 2gbib
109cdef inline int setup_dl_tensor_device(DLTensor* dl_tensor, object buf) except -1:
110 cdef DLDevice* device = &dl_tensor.device 2b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ abgba bbcbdbebfb
111 dev_type, dev_id = classify_dl_device(buf) 2b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ abgba bbcbdbebfb
112 device.device_type = <_DLDeviceType>dev_type 2b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ aba bbcbdbebfb
113 device.device_id = <int32_t>dev_id 2b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ aba bbcbdbebfb
114 return 0 2b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ aba bbcbdbebfb
117cdef inline int setup_dl_tensor_dtype(DLTensor* dl_tensor) except -1 nogil:
118 dl_tensor.dtype = DLDataType( 2b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ aba bbcbdbebfb
119 code=<uint8_t>kDLInt, bits=<uint8_t>8, lanes=<uint16_t>1) 2b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ aba bbcbdbebfb
120 return 0 2b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ aba bbcbdbebfb
123cpdef object make_py_capsule(object buf, bint versioned):
124 cdef DLManagedTensor* dlm_tensor = NULL 2b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ abgba bbcbdbebfb
125 cdef DLManagedTensorVersioned* dlm_tensor_ver = NULL 2b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ abgba bbcbdbebfb
126 cdef DLTensor* dl_tensor
127 cdef void* tensor_ptr
128 cdef const char* capsule_name
129 cdef object ret = None 2b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ abgba bbcbdbebfb
131 try: 2b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ abgba bbcbdbebfb
132 if versioned: 2b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ abgba bbcbdbebfb
133 dlm_tensor_ver = allocate_dlm_tensor_versioned() 2hbb c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ aba bbcbdbebfb
134 # Transfer the reference to manager_ctx
135 cpython.Py_INCREF(buf) 2b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ aba bbcbdbebfb
136 dlm_tensor_ver.manager_ctx = <void*>buf 2b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ aba bbcbdbebfb
137 dlm_tensor_ver.deleter = versioned_deleter 2b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ aba bbcbdbebfb
138 dlm_tensor_ver.version.major = DLPACK_MAJOR_VERSION 2b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ aba bbcbdbebfb
139 dlm_tensor_ver.version.minor = DLPACK_MINOR_VERSION 2b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ aba bbcbdbebfb
140 dlm_tensor_ver.flags = 0 2b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ aba bbcbdbebfb
141 dl_tensor = &dlm_tensor_ver.dl_tensor 2b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ aba bbcbdbebfb
142 tensor_ptr = dlm_tensor_ver 2b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ aba bbcbdbebfb
143 capsule_name = DLPACK_VERSIONED_TENSOR_UNUSED_NAME 2b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ aba bbcbdbebfb
144 else:
145 dlm_tensor = allocate_dlm_tensor() 2gba
146 # Transfer the reference to manager_ctx
147 cpython.Py_INCREF(buf) 2gba
148 dlm_tensor.manager_ctx = <void*>buf 2gba
149 dlm_tensor.deleter = deleter 2gba
150 dl_tensor = &dlm_tensor.dl_tensor 2gba
151 tensor_ptr = dlm_tensor 2gba
152 capsule_name = DLPACK_TENSOR_UNUSED_NAME 2gba
154 dl_tensor.data = <void*><intptr_t>(int(buf.handle)) 2b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ abgba bbcbdbebfb
155 setup_dl_tensor_layout(dl_tensor, buf) 2b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ abgba bbcbdbebfb
156 setup_dl_tensor_device(dl_tensor, buf) 2b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ abgba bbcbdbebfb
157 setup_dl_tensor_dtype(dl_tensor) 2b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ aba bbcbdbebfb
158 ret = cpython.PyCapsule_New(tensor_ptr, capsule_name, pycapsule_deleter) 2b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ aba bbcbdbebfb
159 except: 2gb
160 if ret is None: 2gb
161 deleter(dlm_tensor) 2gb
162 versioned_deleter(dlm_tensor_ver) 2gb
163 raise 2gb
164 return ret 2b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ aba bbcbdbebfb
167# Values are fixed by the DLPack spec; see _include/dlpack.h. They are
168# hard-coded here (rather than referencing the cdef extern names) so that the
169# generated .pyi stub doesn't reference Cython-only identifiers.
170class DLDeviceType(IntEnum):
171 kDLCPU = 1
172 kDLCUDA = 2
173 kDLCUDAHost = 3
174 kDLCUDAManaged = 13