Coverage for cuda/core/_kernel_arg_handler.pyx: 87.50%
224 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
5from cpython.mem cimport PyMem_Malloc, PyMem_Free
6from libc.stdint cimport (intptr_t,
7 int8_t, int16_t, int32_t, int64_t,
8 uint8_t, uint16_t, uint32_t, uint64_t,)
9from libcpp cimport bool as cpp_bool
10from libcpp.complex cimport complex as cpp_complex
11from libcpp cimport nullptr
12from libcpp cimport vector
14import ctypes
15from typing import Sequence, Any
17import numpy
19from cuda.core._memory import Buffer
20from cuda.core._memory._buffer cimport Buffer as cyBuffer, Buffer_check_open
21from cuda.core._tensor_map import TensorMapDescriptor as _TensorMapDescriptor_py
22from cuda.core._tensor_map cimport TensorMapDescriptor
23from cuda.core.graph._graph_definition cimport GraphCondition
24from cuda.core._utils.cuda_utils import driver
25from cuda.bindings cimport cydriver
28ctypedef cpp_complex.complex[float] cpp_single_complex
29ctypedef cpp_complex.complex[double] cpp_double_complex
32# We need an identifier for fp16 for copying scalars on the host. This is a minimal
33# implementation borrowed from cuda_fp16.h.
34cdef extern from *:
35 """
36 #if __cplusplus >= 201103L
37 #define __CUDA_ALIGN__(n) alignas(n) /* C++11 kindly gives us a keyword for this */
38 #else
39 #if defined(__GNUC__)
40 #define __CUDA_ALIGN__(n) __attribute__ ((aligned(n)))
41 #elif defined(_MSC_VER)
42 #define __CUDA_ALIGN__(n) __declspec(align(n))
43 #else
44 #define __CUDA_ALIGN__(n)
45 #endif /* defined(__GNUC__) */
46 #endif /* __cplusplus >= 201103L */
48 typedef struct __CUDA_ALIGN__(2) {
49 /**
50 * Storage field contains bits representation of the \p half floating-point number.
51 */
52 unsigned short x;
53 } __half_raw;
54 """
55 ctypedef struct __half_raw:
56 unsigned short x
59ctypedef fused supported_type:
60 cpp_bool
61 int8_t
62 int16_t
63 int32_t
64 int64_t
65 uint8_t
66 uint16_t
67 uint32_t
68 uint64_t
69 __half_raw
70 float
71 double
72 intptr_t
73 cpp_single_complex
74 cpp_double_complex
77# cache ctypes/numpy type objects to avoid attribute access
78cdef object ctypes_bool = ctypes.c_bool
79cdef object ctypes_int8 = ctypes.c_int8
80cdef object ctypes_int16 = ctypes.c_int16
81cdef object ctypes_int32 = ctypes.c_int32
82cdef object ctypes_int64 = ctypes.c_int64
83cdef object ctypes_uint8 = ctypes.c_uint8
84cdef object ctypes_uint16 = ctypes.c_uint16
85cdef object ctypes_uint32 = ctypes.c_uint32
86cdef object ctypes_uint64 = ctypes.c_uint64
87cdef object ctypes_float = ctypes.c_float
88cdef object ctypes_double = ctypes.c_double
89cdef object numpy_bool = numpy.bool_
90cdef object numpy_int8 = numpy.int8
91cdef object numpy_int16 = numpy.int16
92cdef object numpy_int32 = numpy.int32
93cdef object numpy_int64 = numpy.int64
94cdef object numpy_uint8 = numpy.uint8
95cdef object numpy_uint16 = numpy.uint16
96cdef object numpy_uint32 = numpy.uint32
97cdef object numpy_uint64 = numpy.uint64
98cdef object numpy_float16 = numpy.float16
99cdef object numpy_float32 = numpy.float32
100cdef object numpy_float64 = numpy.float64
101cdef object numpy_complex64 = numpy.complex64
102cdef object numpy_complex128 = numpy.complex128
105cdef object tensor_map_descriptor_type = _TensorMapDescriptor_py
108# limitation due to cython/cython#534
109ctypedef void* voidptr
112# Cython can't infer the overload without at least one input argument with fused type
113cdef inline int prepare_arg(
114 vector.vector[void*]& data,
115 vector.vector[void*]& data_addresses,
116 arg, # important: keep it a Python object and don't cast
117 const size_t idx,
118 const supported_type* __unused=NULL) except -1:
119 cdef void* ptr = PyMem_Malloc(sizeof(supported_type)) 2ibt u jbkblbv w c d l m n o x y e f p q r s z A B C D E g h i j mbnbobpbqbrbsbtb^ _ ` { | } ~ abbbcbdbubvbwbfbxbybzbAbBbCbDbEbgba FbGbHbIbJbKbLbk MbNbObPb- . / QbH 9 b hb[ 6 5 S T 2 3 0 1 4 Z W X U V Y # ! ] ( ) ' eb@ ? = ; : , + * R F I Q P O N M L K J 8 Rb$ %
120 # note: this should also work once ctypes has complex support:
121 # python/cpython#121248
122 if supported_type is cpp_single_complex:
123 (<supported_type*>ptr)[0] = cpp_complex.complex[float](arg.real, arg.imag) 1#
124 elif supported_type is cpp_double_complex:
125 (<supported_type*>ptr)[0] = cpp_complex.complex[double](arg.real, arg.imag) 1b!]
126 elif supported_type is __half_raw:
127 (<supported_type*>ptr).x = <int16_t>(arg.view(numpy_int16)) 1(
128 else:
129 (<supported_type*>ptr)[0] = <supported_type>(arg) 2ibt u jbkblbv w c d l m n o x y e f p q r s z A B C D E g h i j mbnbobpbqbrbsbtb^ _ ` { | } ~ abbbcbdbubvbwbfbxbybzbAbBbCbDbEbgba FbGbHbIbJbKbLbk MbNbObPb- . / QbH 9 b hb[ 6 5 S T 2 3 0 1 4 Z W X U V Y # ! ] ( ) ' eb@ ? = ; : , + * R F I Q P O N M L K J 8 Rb$ %
130 data_addresses[idx] = ptr # take the address to the scalar 2ibt u jbkblbv w c d l m n o x y e f p q r s z A B C D E g h i j mbnbobpbqbrbsbtb^ _ ` { | } ~ abbbcbdbubvbwbfbxbybzbAbBbCbDbEbgba FbGbHbIbJbKbLbk MbNbObPb- . / QbH 9 b hb[ 6 5 S T 2 3 0 1 4 Z W X U V Y # ! ] ( ) ' eb@ ? = ; : , + * R F I Q P O N M L K J 8 Rb$ %
131 data[idx] = ptr # for later dealloc 2ibt u jbkblbv w c d l m n o x y e f p q r s z A B C D E g h i j mbnbobpbqbrbsbtb^ _ ` { | } ~ abbbcbdbubvbwbfbxbybzbAbBbCbDbEbgba FbGbHbIbJbKbLbk MbNbObPb- . / QbH 9 b hb[ 6 5 S T 2 3 0 1 4 Z W X U V Y # ! ] ( ) ' eb@ ? = ; : , + * R F I Q P O N M L K J 8 Rb$ %
132 return 0 2ibt u jbkblbv w c d l m n o x y e f p q r s z A B C D E g h i j mbnbobpbqbrbsbtb^ _ ` { | } ~ abbbcbdbubvbwbfbxbybzbAbBbCbDbEbgba FbGbHbIbJbKbLbk MbNbObPb- . / QbH 9 b hb[ 6 5 S T 2 3 0 1 4 Z W X U V Y # ! ] ( ) ' eb@ ? = ; : , + * R F I Q P O N M L K J 8 Rb$ %
135cdef inline int prepare_tensor_map_arg(
136 vector.vector[void*]& data,
137 vector.vector[void*]& data_addresses,
138 TensorMapDescriptor arg,
139 const size_t idx) except -1:
140 # cuLaunchKernel copies argument bytes during launch, so a TensorMap
141 # descriptor can point directly at its internal CUtensorMap storage.
142 data_addresses[idx] = arg._get_data_ptr()
143 return 0
146cdef inline int prepare_ctypes_arg(
147 vector.vector[void*]& data,
148 vector.vector[void*]& data_addresses,
149 arg,
150 const size_t idx) except -1:
151 cdef object arg_type = type(arg) 1tuvwcdlmnoxyefpqrszABCDEghijakHbG65ST23014ZWXUVYRFIQPONMLKJ
152 if arg_type is ctypes_bool: 1tuvwcdlmnoxyefpqrszABCDEghijakHbG65ST23014ZWXUVYRFIQPONMLKJ
153 return prepare_arg[cpp_bool](data, data_addresses, arg.value, idx) 1lmpq6
154 elif arg_type is ctypes_int8: 17tuvwcdlmnoxyefpqrszABCDEghijakHbG5ST23014ZWXUVYRFIQPONMLKJ
155 return prepare_arg[int8_t](data, data_addresses, arg.value, idx) 15
156 elif arg_type is ctypes_int16: 1tuvwcdlmnoxyefpqrszABCDEghijakHbGST23014ZWXUVYRFIQPONMLKJ
157 return prepare_arg[int16_t](data, data_addresses, arg.value, idx) 14
158 elif arg_type is ctypes_int32: 1tuvwcdlmnoxyefpqrszABCDEghijakHbGST2301ZWXUVYRFIQPONMLKJ
159 return prepare_arg[int32_t](data, data_addresses, arg.value, idx) 1723
160 elif arg_type is ctypes_int64: 1tuvwcdlmnoxyefpqrszABCDEghijakHbGST01ZWXUVYRFIQPONMLKJ
161 return prepare_arg[int64_t](data, data_addresses, arg.value, idx) 101
162 elif arg_type is ctypes_uint8: 1tuvwcdlmnoxyefpqrszABCDEghijakHbGSTZWXUVYRFIQPONMLKJ
163 return prepare_arg[uint8_t](data, data_addresses, arg.value, idx) 1Z
164 elif arg_type is ctypes_uint16: 17tuvwcdlmnoxyefpqrszABCDEghijakHbGSTWXUVYRFIQPONMLKJ
165 return prepare_arg[uint16_t](data, data_addresses, arg.value, idx) 1Y
166 elif arg_type is ctypes_uint32: 1tuvwcdlmnoxyefpqrszABCDEghijakHbGSTWXUVRFIQPONMLKJ
167 return prepare_arg[uint32_t](data, data_addresses, arg.value, idx) 1WX
168 elif arg_type is ctypes_uint64: 1tuvwcdlmnoxyefpqrszABCDEghijakHbGSTUVRFIQPONMLKJ
169 return prepare_arg[uint64_t](data, data_addresses, arg.value, idx) 1UV
170 elif arg_type is ctypes_float: 1tuvwcdlmnoxyefpqrszABCDEghijakHbGSTRFIQPONMLKJ
171 return prepare_arg[float](data, data_addresses, arg.value, idx) 1T
172 elif arg_type is ctypes_double: 1tuvwcdlmnoxyefpqrszABCDEghijakHbGSRFIQPONMLKJ
173 return prepare_arg[double](data, data_addresses, arg.value, idx) 1S
174 else:
175 # If no exact types are found, fallback to slower `isinstance` check
176 if isinstance(arg, ctypes_bool): 1tuvwcdlmnoxyefpqrszABCDEghijakHbGRFIQPONMLKJ
177 return prepare_arg[cpp_bool](data, data_addresses, arg.value, idx) 1HR
178 elif isinstance(arg, ctypes_int8): 1tuvwcdlmnoxyefpqrszABCDEghijakHbGFIQPONMLKJ
179 return prepare_arg[int8_t](data, data_addresses, arg.value, idx) 17Q
180 elif isinstance(arg, ctypes_int16): 1tuvwcdlmnoxyefpqrszABCDEghijakHbGFIPONMLKJ
181 return prepare_arg[int16_t](data, data_addresses, arg.value, idx) 1P
182 elif isinstance(arg, ctypes_int32): 1tuvwcdlmnoxyefpqrszABCDEghijakHbGFIONMLKJ
183 return prepare_arg[int32_t](data, data_addresses, arg.value, idx) 1HO
184 elif isinstance(arg, ctypes_int64): 1tuvwcdlmnoxyefpqrszABCDEghijakHbGFINMLKJ
185 return prepare_arg[int64_t](data, data_addresses, arg.value, idx) 17N
186 elif isinstance(arg, ctypes_uint8): 1tuvwcdlmnoxyefpqrszABCDEghijakHbGFIMLKJ
187 return prepare_arg[uint8_t](data, data_addresses, arg.value, idx) 1M
188 elif isinstance(arg, ctypes_uint16): 1tuvwcdlmnoxyefpqrszABCDEghijakHbGFILKJ
189 return prepare_arg[uint16_t](data, data_addresses, arg.value, idx) 1L
190 elif isinstance(arg, ctypes_uint32): 1tuvwcdlmnoxyefpqrszABCDEghijakHbGFIKJ
191 return prepare_arg[uint32_t](data, data_addresses, arg.value, idx) 1K
192 elif isinstance(arg, ctypes_uint64): 1tuvwcdlmnoxyefpqrszABCDEghijakHbGFIJ
193 return prepare_arg[uint64_t](data, data_addresses, arg.value, idx) 1J
194 elif isinstance(arg, ctypes_float): 17tuvwcdlmnoxyefpqrszABCDEghijakHbGFI
195 return prepare_arg[float](data, data_addresses, arg.value, idx) 1HI
196 elif isinstance(arg, ctypes_double): 1tuvwcdlmnoxyefpqrszABCDEghijakbGF
197 return prepare_arg[double](data, data_addresses, arg.value, idx) 1F
198 else:
199 return 1 1tuvwcdlmnoxyefpqrszABCDEghijakbG
202cdef inline int prepare_numpy_arg(
203 vector.vector[void*]& data,
204 vector.vector[void*]& data_addresses,
205 arg,
206 const size_t idx) except -1:
207 cdef object arg_type = type(arg) 1tuvwcdlmnoxyefpqrszABCDEghijak-./H9bG[65ST23014ZWXUVY#!()'@?=;:,+*RFIQPONMLKJ8$%
208 if arg_type is numpy_bool: 1tuvwcdlmnoxyefpqrszABCDEghijak-./H9bG[65ST23014ZWXUVY#!()'@?=;:,+*RFIQPONMLKJ8$%
209 return prepare_arg[cpp_bool](data, data_addresses, arg, idx) 1nors[
210 elif arg_type is numpy_int8: 1tuvwcdlmnoxyefpqrszABCDEghijak-./H9bG65ST23014ZWXUVY#!()'@?=;:,+*RFIQPONMLKJ8$%
211 return prepare_arg[int8_t](data, data_addresses, arg, idx) 1@
212 elif arg_type is numpy_int16: 1tuvwcdlmnoxyefpqrszABCDEghijak-./H9bG65ST23014ZWXUVY#!()'?=;:,+*RFIQPONMLKJ8$%
213 return prepare_arg[int16_t](data, data_addresses, arg, idx) 17?
214 elif arg_type is numpy_int32: 1tuvwcdlmnoxyefpqrszABCDEghijak-./H9bG65ST23014ZWXUVY#!()'=;:,+*RFIQPONMLKJ8$%
215 return prepare_arg[int32_t](data, data_addresses, arg, idx) 1-./=
216 elif arg_type is numpy_int64: 1tuvwcdlmnoxyefpqrszABCDEghijakH9bG65ST23014ZWXUVY#!()';:,+*RFIQPONMLKJ8$%
217 return prepare_arg[int64_t](data, data_addresses, arg, idx) 1;
218 elif arg_type is numpy_uint8: 1tuvwcdlmnoxyefpqrszABCDEghijakH9bG65ST23014ZWXUVY#!()':,+*RFIQPONMLKJ8$%
219 return prepare_arg[uint8_t](data, data_addresses, arg, idx) 17:
220 elif arg_type is numpy_uint16: 1tuvwcdlmnoxyefpqrszABCDEghijakH9bG65ST23014ZWXUVY#!()',+*RFIQPONMLKJ8$%
221 return prepare_arg[uint16_t](data, data_addresses, arg, idx) 1,
222 elif arg_type is numpy_uint32: 1tuvwcdlmnoxyefpqrszABCDEghijakH9bG65ST23014ZWXUVY#!()'+*RFIQPONMLKJ8$%
223 return prepare_arg[uint32_t](data, data_addresses, arg, idx) 17+
224 elif arg_type is numpy_uint64: 1tuvwcdlmnoxyefpqrszABCDEghijakH9bG65ST23014ZWXUVY#!()'*RFIQPONMLKJ8$%
225 return prepare_arg[uint64_t](data, data_addresses, arg, idx) 1*
226 elif arg_type is numpy_float16: 1tuvwcdlmnoxyefpqrszABCDEghijakH9bG65ST23014ZWXUVY#!()'RFIQPONMLKJ8$%
227 return prepare_arg[__half_raw](data, data_addresses, arg, idx) 1(
228 elif arg_type is numpy_float32: 1tuvwcdlmnoxyefpqrszABCDEghijakH9bG65ST23014ZWXUVY#!)'RFIQPONMLKJ8$%
229 return prepare_arg[float](data, data_addresses, arg, idx) 1)$%
230 elif arg_type is numpy_float64: 1tuvwcdlmnoxyefpqrszABCDEghijakH9bG65ST23014ZWXUVY#!'RFIQPONMLKJ8
231 return prepare_arg[double](data, data_addresses, arg, idx) 1'
232 elif arg_type is numpy_complex64: 17tuvwcdlmnoxyefpqrszABCDEghijakH9bG65ST23014ZWXUVY#!RFIQPONMLKJ8
233 return prepare_arg[cpp_single_complex](data, data_addresses, arg, idx) 1#
234 elif arg_type is numpy_complex128: 1tuvwcdlmnoxyefpqrszABCDEghijakH9bG65ST23014ZWXUVY!RFIQPONMLKJ8
235 return prepare_arg[cpp_double_complex](data, data_addresses, arg, idx) 1!
236 else:
237 # If no exact types are found, fallback to slower `isinstance` check
238 if isinstance(arg, numpy_bool): 1tuvwcdlmnoxyefpqrszABCDEghijakH9bG65ST23014ZWXUVYRFIQPONMLKJ8
239 return prepare_arg[cpp_bool](data, data_addresses, arg, idx)
240 elif isinstance(arg, numpy_int8): 1tuvwcdlmnoxyefpqrszABCDEghijakH9bG65ST23014ZWXUVYRFIQPONMLKJ8
241 return prepare_arg[int8_t](data, data_addresses, arg, idx)
242 elif isinstance(arg, numpy_int16): 1tuvwcdlmnoxyefpqrszABCDEghijakH9bG65ST23014ZWXUVYRFIQPONMLKJ8
243 return prepare_arg[int16_t](data, data_addresses, arg, idx)
244 elif isinstance(arg, numpy_int32): 1tuvwcdlmnoxyefpqrszABCDEghijakH9bG65ST23014ZWXUVYRFIQPONMLKJ8
245 return prepare_arg[int32_t](data, data_addresses, arg, idx) 19
246 elif isinstance(arg, numpy_int64): 17tuvwcdlmnoxyefpqrszABCDEghijakH9bG65ST23014ZWXUVYRFIQPONMLKJ8
247 return prepare_arg[int64_t](data, data_addresses, arg, idx)
248 elif isinstance(arg, numpy_uint8): 1tuvwcdlmnoxyefpqrszABCDEghijakH9bG65ST23014ZWXUVYRFIQPONMLKJ8
249 return prepare_arg[uint8_t](data, data_addresses, arg, idx)
250 elif isinstance(arg, numpy_uint16): 1tuvwcdlmnoxyefpqrszABCDEghijakH9bG65ST23014ZWXUVYRFIQPONMLKJ8
251 return prepare_arg[uint16_t](data, data_addresses, arg, idx)
252 elif isinstance(arg, numpy_uint32): 1tuvwcdlmnoxyefpqrszABCDEghijakH9bG65ST23014ZWXUVYRFIQPONMLKJ8
253 return prepare_arg[uint32_t](data, data_addresses, arg, idx)
254 elif isinstance(arg, numpy_uint64): 1tuvwcdlmnoxyefpqrszABCDEghijakH9bG65ST23014ZWXUVYRFIQPONMLKJ8
255 return prepare_arg[uint64_t](data, data_addresses, arg, idx)
256 elif isinstance(arg, numpy_float16): 1tuvwcdlmnoxyefpqrszABCDEghijakH9bG65ST23014ZWXUVYRFIQPONMLKJ8
257 return prepare_arg[__half_raw](data, data_addresses, arg, idx)
258 elif isinstance(arg, numpy_float32): 17tuvwcdlmnoxyefpqrszABCDEghijakH9bG65ST23014ZWXUVYRFIQPONMLKJ8
259 return prepare_arg[float](data, data_addresses, arg, idx) 198
260 elif isinstance(arg, numpy_float64): 1tuvwcdlmnoxyefpqrszABCDEghijakHbG65ST23014ZWXUVYRFIQPONMLKJ
261 return prepare_arg[double](data, data_addresses, arg, idx)
262 elif isinstance(arg, numpy_complex64): 1tuvwcdlmnoxyefpqrszABCDEghijakHbG65ST23014ZWXUVYRFIQPONMLKJ
263 return prepare_arg[cpp_single_complex](data, data_addresses, arg, idx)
264 elif isinstance(arg, numpy_complex128): 1tuvwcdlmnoxyefpqrszABCDEghijakHbG65ST23014ZWXUVYRFIQPONMLKJ
265 return prepare_arg[cpp_double_complex](data, data_addresses, arg, idx)
266 else:
267 return 1 1tuvwcdlmnoxyefpqrszABCDEghijakHbG65ST23014ZWXUVYRFIQPONMLKJ
270cdef class ParamHolder:
272 def __init__(self, kernel_args: Sequence[Any]) -> None:
273 if len(kernel_args) == 0: 2ibSbTbt u UbVbWbjbXbYbZb0bkb1b2b3blbv w c d l m n o x y e f p q r s z A B C D E g h i j 4b5b6b7b8b9b!b#b$b%b'b(b)b*b+b,b-b.b/b:b;b=b?b@b[b]bmbnb^b_b`b{b|bobpbqbrbsbtb^ _ ` { | } ~ abbbcbdbubvbwbfbxbybzbAbBbCb}bDbEbgb~ba FbGbHbacIbJbKbLbbcccdcecfcgck MbNbObPbhc- . / QbicH 9 b G jchb[ 6 5 S T 2 3 0 1 4 Z W X U V Y # ! ] ( ) ' eb@ ? = ; : , + * R F I Q P O N M L K J 8 Rb$ % kclcmcncocpcqcrcsctcucvcwcxcyczcAcBcCcDcEcFcGcHcIcJcKcLcMcNcOcPcQcRcScTcUcVcWcXcYcZc0c1c2c3c4c5c6c7c8c9c!c#c$c%c'c(c)c*c+c,c-c.c/c:c;c=c?c@c[c]c^c_c`c{c|c}c~cadbdcdddedfdgdhdidjdkdldmdndodpdqdrdsdtdudvdwdxdydzdAdBdCdDdEdFdGdHdIdJdKd
274 self.ptr = 0 2SbTbUbVbWbXbYbZb0b1b2b3bg h i j 4b5b6b7b8b9b!b#b$b%b'b(b)b*b+b,b-b.b/b:b;b=b?b@b[b]b^b_b`b{b|bfb}bgb~bacbcccdcecfcgck hcicjckclcmcncocpcqcrcsctcucvcwcxcyczcAcBcCcDcEcFcGcHcIcJcKcLcMcNcOcPcQcRcScTcUcVcWcXcYcZc0c1c2c3c4c5c6c7c8c9c!c#c$c%c'c(c)c*c+c,c-c.c/c:c;c=c?c@c[c]c^c_c`c{c|c}c~cadbdcdddedfdgdhdidjdkdldmdndodpdqdrdsdtdudvdwdxdydzdAdBdCdDdEdFdGdHdIdJdKd
275 return 2SbTbUbVbWbXbYbZb0b1b2b3bg h i j 4b5b6b7b8b9b!b#b$b%b'b(b)b*b+b,b-b.b/b:b;b=b?b@b[b]b^b_b`b{b|bfb}bgb~bacbcccdcecfcgck hcicjckclcmcncocpcqcrcsctcucvcwcxcyczcAcBcCcDcEcFcGcHcIcJcKcLcMcNcOcPcQcRcScTcUcVcWcXcYcZc0c1c2c3c4c5c6c7c8c9c!c#c$c%c'c(c)c*c+c,c-c.c/c:c;c=c?c@c[c]c^c_c`c{c|c}c~cadbdcdddedfdgdhdidjdkdldmdndodpdqdrdsdtdudvdwdxdydzdAdBdCdDdEdFdGdHdIdJdKd
277 cdef size_t n_args = len(kernel_args) 2ibt u jbkblbv w c d l m n o x y e f p q r s z A B C D E g h i j mbnbobpbqbrbsbtb^ _ ` { | } ~ abbbcbdbubvbwbfbxbybzbAbBbCbDbEbgba FbGbHbIbJbKbLbk MbNbObPb- . / QbH 9 b G hb[ 6 5 S T 2 3 0 1 4 Z W X U V Y # ! ] ( ) ' eb@ ? = ; : , + * R F I Q P O N M L K J 8 Rb$ %
278 cdef size_t i
279 cdef int not_prepared
280 cdef object arg_type
281 self.data = vector.vector[voidptr](n_args, nullptr) 2ibt u jbkblbv w c d l m n o x y e f p q r s z A B C D E g h i j mbnbobpbqbrbsbtb^ _ ` { | } ~ abbbcbdbubvbwbfbxbybzbAbBbCbDbEbgba FbGbHbIbJbKbLbk MbNbObPb- . / QbH 9 b G hb[ 6 5 S T 2 3 0 1 4 Z W X U V Y # ! ] ( ) ' eb@ ? = ; : , + * R F I Q P O N M L K J 8 Rb$ %
282 self.data_addresses = vector.vector[voidptr](n_args) 2ibt u jbkblbv w c d l m n o x y e f p q r s z A B C D E g h i j mbnbobpbqbrbsbtb^ _ ` { | } ~ abbbcbdbubvbwbfbxbybzbAbBbCbDbEbgba FbGbHbIbJbKbLbk MbNbObPb- . / QbH 9 b G hb[ 6 5 S T 2 3 0 1 4 Z W X U V Y # ! ] ( ) ' eb@ ? = ; : , + * R F I Q P O N M L K J 8 Rb$ %
283 for i, arg in enumerate(kernel_args): 2ibt u jbkblbv w c d l m n o x y e f p q r s z A B C D E g h i j mbnbobpbqbrbsbtb^ _ ` { | } ~ abbbcbdbubvbwbfbxbybzbAbBbCbDbEbgba FbGbHbIbJbKbLbk MbNbObPb- . / QbH 9 b G hb[ 6 5 S T 2 3 0 1 4 Z W X U V Y # ! ] ( ) ' eb@ ? = ; : , + * R F I Q P O N M L K J 8 Rb$ %
284 arg_type = type(arg) 2ibt u jbkblbv w c d l m n o x y e f p q r s z A B C D E g h i j mbnbobpbqbrbsbtb^ _ ` { | } ~ abbbcbdbubvbwbfbxbybzbAbBbCbDbEbgba FbGbHbIbJbKbLbk MbNbObPb- . / QbH 9 b G hb[ 6 5 S T 2 3 0 1 4 Z W X U V Y # ! ] ( ) ' eb@ ? = ; : , + * R F I Q P O N M L K J 8 Rb$ %
285 if arg_type is Buffer: 2ibt u jbkblbv w c d l m n o x y e f p q r s z A B C D E g h i j mbnbobpbqbrbsbtb^ _ ` { | } ~ abbbcbdbubvbwbfbxbybzbAbBbCbDbEbgba FbGbHbIbJbKbLbk MbNbObPb- . / QbH 9 b G hb[ 6 5 S T 2 3 0 1 4 Z W X U V Y # ! ] ( ) ' eb@ ? = ; : , + * R F I Q P O N M L K J 8 Rb$ %
286 Buffer_check_open(<cyBuffer>arg) 2mbnb^ _ ` { | } ~ abbbcbdbubvbwbfbxbybzbAbBbCbDbEbgba FbGbHbIb- . / Rb$ %
287 # we need the address of where the actual buffer address is stored
288 if type(arg.handle) is int: 2mbnb^ _ ` { | } ~ abbbcbdbubvbwbfbxbybzbAbBbCbDbEbgba FbGbHbIb- . / Rb$ %
289 # see note below on handling int arguments
290 prepare_arg[intptr_t](self.data, self.data_addresses, arg.handle, i) 2mbnb^ _ ` { | } ~ abbbcbdbubvbwbfbxbybzbAbBbCbDbEbgba FbGbHbIb- . / Rb$ %
291 continue 2mbnb^ _ ` { | } ~ abbbcbdbubvbwbfbxbybzbAbBbCbDbEbgba FbGbHbIb- . / Rb$ %
292 else:
293 # it's a CUdeviceptr:
294 self.data_addresses[i] = <void*><intptr_t>(arg.handle.getPtr())
295 continue
296 elif arg_type is bool: 2ibt u jbkblbv w c d l m n o x y e f p q r s z A B C D E g h i j obpbqbrbsbtb^ _ ` { | } ~ abbbcbdba JbKbLbk MbNbObPb- . / QbH 9 b G hb[ 6 5 S T 2 3 0 1 4 Z W X U V Y # ! ] ( ) ' eb@ ? = ; : , + * R F I Q P O N M L K J 8 $ %
297 prepare_arg[cpp_bool](self.data, self.data_addresses, arg, i) 2c d e f k hb
298 continue 2c d e f k hb
299 elif arg_type is int: 2ibt u jbkblbv w c d l m n o x y e f p q r s z A B C D E g h i j obpbqbrbsbtb^ _ ` { | } ~ abbbcbdba JbKbLbk MbNbObPb- . / QbH 9 b G hb[ 6 5 S T 2 3 0 1 4 Z W X U V Y # ! ] ( ) ' eb@ ? = ; : , + * R F I Q P O N M L K J 8 $ %
300 # Here's the dilemma: We want to have a fast path to pass in Python
301 # integers as pointer addresses, but one could also (mistakenly) pass
302 # it with the intention of passing a scalar integer. It's a mistake
303 # bacause a Python int is ambiguous (arbitrary width). Our judgement
304 # call here is to treat it as a pointer address, without any warning!
305 prepare_arg[intptr_t](self.data, self.data_addresses, arg, i) 2ibt u jbkblbv w c d l m n o x y e f p q r s z A B C D E g h i j obpbqbrbsbtb^ _ ` { | } ~ abbbcbdbJbKbLbMbNbObPbQbhb[ 6 5 S T 2 3 0 1 4 Z W X U V Y # ! ] ( ) ' eb@ ? = ; : , + * R F I Q P O N M L K J 8
306 continue 2ibt u jbkblbv w c d l m n o x y e f p q r s z A B C D E g h i j obpbqbrbsbtb^ _ ` { | } ~ abbbcbdbJbKbLbMbNbObPbQbhb[ 6 5 S T 2 3 0 1 4 Z W X U V Y # ! ] ( ) ' eb@ ? = ; : , + * R F I Q P O N M L K J 8
307 elif arg_type is float: 2t u v w c d l m n o x y e f p q r s z A B C D E g h i j a k - . / H 9 b G [ 6 5 S T 2 3 0 1 4 Z W X U V Y # ! ] ( ) ' eb@ ? = ; : , + * R F I Q P O N M L K J 8 $ %
308 prepare_arg[double](self.data, self.data_addresses, arg, i) 2eb
309 continue 2eb
310 elif arg_type is complex: 1tuvwcdlmnoxyefpqrszABCDEghijak-./H9bG[65ST23014ZWXUVY#!]()'@?=;:,+*RFIQPONMLKJ8$%
311 prepare_arg[cpp_double_complex](self.data, self.data_addresses, arg, i) 17]
312 continue 1]
313 elif arg_type is tensor_map_descriptor_type: 1tuvwcdlmnoxyefpqrszABCDEghijak-./H9bG[65ST23014ZWXUVY#!()'@?=;:,+*RFIQPONMLKJ8$%
314 prepare_tensor_map_arg(self.data, self.data_addresses, <TensorMapDescriptor>arg, i)
315 continue
317 not_prepared = prepare_numpy_arg(self.data, self.data_addresses, arg, i) 1tuvwcdlmnoxyefpqrszABCDEghijak-./H9bG[65ST23014ZWXUVY#!()'@?=;:,+*RFIQPONMLKJ8$%
318 if not_prepared: 1tuvwcdlmnoxyefpqrszABCDEghijak-./H9bG[65ST23014ZWXUVY#!()'@?=;:,+*RFIQPONMLKJ8$%
319 not_prepared = prepare_ctypes_arg(self.data, self.data_addresses, arg, i) 1tuvwcdlmnoxyefpqrszABCDEghijakHbG65ST23014ZWXUVYRFIQPONMLKJ
320 if not_prepared: 1tuvwcdlmnoxyefpqrszABCDEghijak-./H9bG[65ST23014ZWXUVY#!()'@?=;:,+*RFIQPONMLKJ8$%
321 # TODO: revisit this treatment if we decide to cythonize cuda.core
322 if arg_type is driver.CUgraphConditionalHandle: 1tuvwcdlmnoxyefpqrszABCDEghijakbG
323 prepare_arg[cydriver.CUgraphConditionalHandle](self.data, self.data_addresses, <intptr_t>int(arg), i)
324 continue
325 elif arg_type is GraphCondition: 1tuvwcdlmnoxyefpqrszABCDEghijakbG
326 prepare_arg[cydriver.CUgraphConditionalHandle]( 1tuvwcdlmnoxyefpqrszABCDEghijk
327 self.data, self.data_addresses,
328 <intptr_t><unsigned long long>(<GraphCondition>arg)._c_handle, i) 1tuvwcdlmnoxyefpqrszABCDEghijk
329 continue 1tuvwcdlmnoxyefpqrszABCDEghijk
330 # If no exact types are found, fallback to slower `isinstance` check
331 elif isinstance(arg, Buffer): 1abG
332 Buffer_check_open(<cyBuffer>arg)
333 if isinstance(arg.handle, int):
334 prepare_arg[intptr_t](self.data, self.data_addresses, arg.handle, i)
335 continue
336 else:
337 self.data_addresses[i] = <void*><intptr_t>(arg.handle.getPtr())
338 continue
339 elif isinstance(arg, bool): 1abG
340 prepare_arg[cpp_bool](self.data, self.data_addresses, arg, i)
341 continue
342 elif isinstance(arg, int): 1abG
343 prepare_arg[intptr_t](self.data, self.data_addresses, arg, i) 1b
344 continue 1b
345 elif isinstance(arg, float): 1abG
346 prepare_arg[double](self.data, self.data_addresses, arg, i) 1b
347 continue 1b
348 elif isinstance(arg, complex): 1abG
349 prepare_arg[cpp_double_complex](self.data, self.data_addresses, arg, i) 1b
350 continue 1b
351 elif isinstance(arg, driver.CUgraphConditionalHandle): 17aG
352 prepare_arg[cydriver.CUgraphConditionalHandle](self.data, self.data_addresses, arg, i)
353 continue
354 elif isinstance(arg, GraphCondition): 1aG
355 prepare_arg[cydriver.CUgraphConditionalHandle](
356 self.data, self.data_addresses,
357 <intptr_t><unsigned long long>(<GraphCondition>arg)._c_handle, i)
358 continue
359 # TODO: support ctypes/numpy struct
360 raise TypeError("the argument is of unsupported type: " + str(type(arg))) 1aG
362 self.kernel_args = kernel_args 2ibt u jbkblbv w c d l m n o x y e f p q r s z A B C D E g h i j mbnbobpbqbrbsbtb^ _ ` { | } ~ abbbcbdbubvbwbfbxbybzbAbBbCbDbEbgba FbGbHbIbJbKbLbk MbNbObPb- . / QbH 9 b hb[ 6 5 S T 2 3 0 1 4 Z W X U V Y # ! ] ( ) ' eb@ ? = ; : , + * R F I Q P O N M L K J 8 Rb$ %
363 self.ptr = <intptr_t>self.data_addresses.data() 2ibt u jbkblbv w c d l m n o x y e f p q r s z A B C D E g h i j mbnbobpbqbrbsbtb^ _ ` { | } ~ abbbcbdbubvbwbfbxbybzbAbBbCbDbEbgba FbGbHbIbJbKbLbk MbNbObPb- . / QbH 9 b hb[ 6 5 S T 2 3 0 1 4 Z W X U V Y # ! ] ( ) ' eb@ ? = ; : , + * R F I Q P O N M L K J 8 Rb$ %
365 def __dealloc__(self) -> None:
366 for data in self.data: 2ibSbTbt u UbVbWbjbXbYbZb0bkb1b2b3blbv w c d l m n o x y e f p q r s z A B C D E g h i j 4b5b6b7b8b9b!b#b$b%b'b(b)b*b+b,b-b.b/b:b;b=b?b@b[b]bmbnb^b_b`b{b|bobpbqbrbsbtb^ _ ` { | } ~ abbbcbdbubvbwbfbxbybzbAbBbCb}bDbEbgb~ba FbGbHbacIbJbKbLbbcccdcecfcgck MbNbObPbhc- . / QbicH 9 b G jchb[ 6 5 S T 2 3 0 1 4 Z W X U V Y # ! ] ( ) ' eb@ ? = ; : , + * R F I Q P O N M L K J 8 Rb$ % kclcmcncocpcqcrcsctcucvcwcxcyczcAcBcCcDcEcFcGcHcIcJcKcLcMcNcOcPcQcRcScTcUcVcWcXcYcZc0c1c2c3c4c5c6c7c8c9c!c#c$c%c'c(c)c*c+c,c-c.c/c:c;c=c?c@c[c]c^c_c`c{c|c}c~cadbdcdddedfdgdhdidjdkdldmdndodpdqdrdsdtdudvdwdxdydzdAdBdCdDdEdFdGdHdIdJdKd
367 if data: 2ibt u jbkblbv w c d l m n o x y e f p q r s z A B C D E g h i j mbnbobpbqbrbsbtb^ _ ` { | } ~ abbbcbdbubvbwbfbxbybzbAbBbCbDbEbgba FbGbHbIbJbKbLbk MbNbObPb- . / QbH 9 b G hb[ 6 5 S T 2 3 0 1 4 Z W X U V Y # ! ] ( ) ' eb@ ? = ; : , + * R F I Q P O N M L K J 8 Rb$ %
368 PyMem_Free(data) 2ibt u jbkblbv w c d l m n o x y e f p q r s z A B C D E g h i j mbnbobpbqbrbsbtb^ _ ` { | } ~ abbbcbdbubvbwbfbxbybzbAbBbCbDbEbgba FbGbHbIbJbKbLbk MbNbObPb- . / QbH 9 b hb[ 6 5 S T 2 3 0 1 4 Z W X U V Y # ! ] ( ) ' eb@ ? = ; : , + * R F I Q P O N M L K J 8 Rb$ %