Coverage for cuda/bindings/cufile.pyx: 40.79%
1807 statements
« prev ^ index » next coverage.py v7.16.2, created at 2026-10-16 01:23 +0000
« prev ^ index » next coverage.py v7.16.2, created at 2026-10-16 01:23 +0000
1# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2#
3# SPDX-License-Identifier: Apache-2.0
4#
5# This code was automatically generated across versions from 12.9.1 to 13.4.1. Do not modify it directly.
6# CYTHON-BINDINGS-GENERATED-DO-NOT-MODIFY-THIS-FILE: format=1; content-sha256=81d29d3c883454c4864665cd1027a72114cacd123e4bfdd997485faedb5a054a
9# <<<< PREAMBLE CONTENT >>>>
11cimport cpython as _cyb_cpython
12cimport cpython.buffer as _cyb_cpython_buffer
13from cpython.buffer cimport (
14 PyBUF_SIMPLE as _cyb_PyBUF_SIMPLE,
15 PyBuffer_Release as _cyb_PyBuffer_Release,
16 PyObject_GetBuffer as _cyb_PyObject_GetBuffer,
17 Py_buffer as _cyb_Py_buffer,
18)
19cimport cpython.memoryview as _cyb_cpython_memoryview
20from cython cimport view as _cyb_view
21from libc.stdint cimport (
22 intptr_t,
23 uint64_t,
24)
25from libc.stdlib cimport (
26 calloc as _cyb_calloc,
27 free as _cyb_free,
28 malloc as _cyb_malloc,
29)
30from libc.string cimport (
31 memcmp as _cyb_memcmp,
32 memcpy as _cyb_memcpy,
33 memmove as _cyb_memmove,
34)
35from libcpp cimport bool as _cyb_bool
37from cuda.bindings._internal._fast_enum import FastEnum as _cyb_FastEnum
39import numpy as _numpy
41cdef _cyb___getbuffer(object self, _cyb_cpython.Py_buffer *buffer, void *ptr, int size, bint readonly):
42 buffer.buf = <char *>ptr
43 buffer.format = 'b'
44 buffer.internal = NULL
45 buffer.itemsize = 1
46 buffer.len = size
47 buffer.ndim = 1
48 buffer.obj = self
49 buffer.readonly = readonly
50 buffer.shape = &buffer.len
51 buffer.strides = &buffer.itemsize
52 buffer.suboffsets = NULL
54cdef _cyb_from_buffer(buffer, size, lowpp_type):
55 cdef _cyb_cpython.Py_buffer view
56 if _cyb_cpython.PyObject_GetBuffer(buffer, &view, _cyb_cpython_buffer.PyBUF_SIMPLE) != 0:
57 raise TypeError("buffer argument does not support the buffer protocol")
58 try:
59 if view.itemsize != 1:
60 raise ValueError("buffer itemsize must be 1 byte")
61 if view.len != size:
62 raise ValueError(f"buffer length must be {size} bytes")
63 return lowpp_type.from_ptr(<intptr_t><void *>view.buf, view.readonly != 0, buffer)
64 finally:
65 _cyb_cpython.PyBuffer_Release(&view)
67cdef _cyb_from_data(data, dtype_name, expected_dtype, lowpp_type):
68 # _numpy.recarray is a subclass of _numpy.ndarray, so implicitly handled here.
69 if isinstance(data, lowpp_type): 1ebc
70 return data 1ebc
71 if not isinstance(data, _numpy.ndarray):
72 raise TypeError("data argument must be a NumPy ndarray")
73 if data.size != 1:
74 raise ValueError("data array must have a size of 1")
75 if data.dtype != expected_dtype:
76 raise ValueError(f"data array must be of dtype {dtype_name}")
77 return lowpp_type.from_ptr(data.ctypes.data, not data.flags.writeable, data)
80# <<<< END OF PREAMBLE CONTENT >>>>
82cimport cython # NOQA
83from libc cimport errno
84from ._internal.utils cimport (get_nested_resource_ptr,
85 nested_resource)
87import cython
89from cuda.bindings.driver import CUresult as pyCUresult
91###############################################################################
92# POD
93###############################################################################
95cdef _get__py_anon_pod1_dtype_offsets():
96 cdef cuda_bindings_cufile__anon_pod1 pod
97 return _numpy.dtype({
98 'names': ['fd', 'handle'],
99 'formats': [_numpy.int32, _numpy.intp],
100 'offsets': [
101 (<intptr_t>&(pod.fd)) - (<intptr_t>&pod),
102 (<intptr_t>&(pod.handle)) - (<intptr_t>&pod),
103 ],
104 'itemsize': sizeof(cuda_bindings_cufile__anon_pod1),
105 })
107_py_anon_pod1_dtype = _get__py_anon_pod1_dtype_offsets()
109cdef class _py_anon_pod1:
110 """Empty-initialize an instance of `cuda_bindings_cufile__anon_pod1`.
113 .. seealso:: `cuda_bindings_cufile__anon_pod1`
114 """
115 cdef:
116 cuda_bindings_cufile__anon_pod1 *_ptr
117 object _owner
118 bint _owns_ptr
119 bint _readonly
121 def __init__(self):
122 self._ptr = <cuda_bindings_cufile__anon_pod1 *>_cyb_calloc(1, sizeof(cuda_bindings_cufile__anon_pod1))
123 if self._ptr == NULL:
124 raise MemoryError("Error allocating _py_anon_pod1")
125 self._owns_ptr = True
126 self._owner = None
127 self._readonly = False
129 def __dealloc__(self):
130 cdef cuda_bindings_cufile__anon_pod1 *ptr
131 if self._owns_ptr and self._ptr != NULL:
132 ptr = self._ptr
133 self._ptr = NULL
134 _cyb_free(ptr)
136 def __repr__(self):
137 return f"<{__name__}._py_anon_pod1 object at {hex(id(self))}>"
139 @property
140 def ptr(self):
141 """Get the pointer address to the data as Python :class:`int`."""
142 return <intptr_t>(self._ptr)
144 cdef intptr_t _get_ptr(self):
145 return <intptr_t>(self._ptr)
147 def __int__(self):
148 return <intptr_t>(self._ptr)
150 def __eq__(self, other):
151 cdef _py_anon_pod1 other_
152 if not isinstance(other, _py_anon_pod1):
153 return False
154 other_ = other
155 return (_cyb_memcmp(<void *><intptr_t>(self._ptr), <void *><intptr_t>(other_._ptr), sizeof(cuda_bindings_cufile__anon_pod1)) == 0)
157 def __getbuffer__(self, _cyb_cpython.Py_buffer *buffer, int flags):
158 _cyb___getbuffer(self, buffer, <void *>self._ptr, sizeof(cuda_bindings_cufile__anon_pod1), self._readonly)
160 def __releasebuffer__(self, Py_buffer *buffer):
161 pass
163 def __setitem__(self, key, val):
164 cdef _cyb_Py_buffer view
165 if key == 0:
166 if self._readonly:
167 raise ValueError("This _py_anon_pod1 instance is read-only")
168 _cyb_PyObject_GetBuffer(val, &view, _cyb_PyBUF_SIMPLE)
169 try:
170 if <size_t>view.len < sizeof(cuda_bindings_cufile__anon_pod1):
171 raise ValueError(
172 "source buffer too small: expected at least %d bytes, got %d" % (sizeof(cuda_bindings_cufile__anon_pod1), view.len)
173 )
174 _cyb_memmove(<void*>self._ptr, view.buf, sizeof(cuda_bindings_cufile__anon_pod1))
175 self._readonly = view.readonly != 0
176 finally:
177 _cyb_PyBuffer_Release(&view)
178 else:
179 setattr(self, key, val)
181 @property
182 def fd(self):
183 """int: """
184 return self._ptr[0].fd
186 @fd.setter
187 def fd(self, val):
188 if self._readonly:
189 raise ValueError("This _py_anon_pod1 instance is read-only")
190 self._ptr[0].fd = val
192 @property
193 def handle(self):
194 """int: """
195 return <intptr_t>(self._ptr[0].handle)
197 @handle.setter
198 def handle(self, val):
199 if self._readonly:
200 raise ValueError("This _py_anon_pod1 instance is read-only")
201 self._ptr[0].handle = <void *><intptr_t>val
203 @staticmethod
204 def from_buffer(buffer):
205 """Create an _py_anon_pod1 instance with the memory from the given buffer."""
206 return _cyb_from_buffer(buffer, sizeof(cuda_bindings_cufile__anon_pod1), _py_anon_pod1)
208 @staticmethod
209 def from_data(data):
210 """Create an _py_anon_pod1 instance wrapping the given NumPy array.
212 Args:
213 data (_numpy.ndarray): a single-element array of dtype `_py_anon_pod1_dtype` holding the data.
214 """
215 return _cyb_from_data(data, "_py_anon_pod1_dtype", _py_anon_pod1_dtype, _py_anon_pod1)
217 @staticmethod
218 def from_ptr(intptr_t ptr, bint readonly=False, object owner=None):
219 """Create an _py_anon_pod1 instance wrapping the given pointer.
221 Args:
222 ptr (intptr_t): pointer address as Python :class:`int` to the data.
223 owner (object): The Python object that owns the pointer. If not provided, data will be copied.
224 readonly (bool): whether the data is read-only (to the user). default is `False`.
225 """
226 if ptr == 0:
227 raise ValueError("ptr must not be null (0)")
228 cdef _py_anon_pod1 obj = _py_anon_pod1.__new__(_py_anon_pod1)
229 if owner is None:
230 obj._ptr = <cuda_bindings_cufile__anon_pod1 *>_cyb_malloc(sizeof(cuda_bindings_cufile__anon_pod1))
231 if obj._ptr == NULL:
232 raise MemoryError("Error allocating _py_anon_pod1")
233 _cyb_memcpy(<void*>(obj._ptr), <void*>ptr, sizeof(cuda_bindings_cufile__anon_pod1))
234 obj._owns_ptr = True
235 obj._owner = None
236 else:
237 obj._ptr = <cuda_bindings_cufile__anon_pod1 *>ptr
238 obj._owns_ptr = False
239 obj._owner = owner
240 obj._readonly = readonly
241 return obj
244cdef _get__py_anon_pod3_dtype_offsets():
245 cdef cuda_bindings_cufile__anon_pod3 pod
246 return _numpy.dtype({
247 'names': ['dev_ptr_base', 'file_offset', 'dev_ptr_offset', 'size_'],
248 'formats': [_numpy.intp, _numpy.int64, _numpy.int64, _numpy.uint64],
249 'offsets': [
250 (<intptr_t>&(pod.devPtr_base)) - (<intptr_t>&pod),
251 (<intptr_t>&(pod.file_offset)) - (<intptr_t>&pod),
252 (<intptr_t>&(pod.devPtr_offset)) - (<intptr_t>&pod),
253 (<intptr_t>&(pod.size)) - (<intptr_t>&pod),
254 ],
255 'itemsize': sizeof(cuda_bindings_cufile__anon_pod3),
256 })
258_py_anon_pod3_dtype = _get__py_anon_pod3_dtype_offsets()
260cdef class _py_anon_pod3:
261 """Empty-initialize an instance of `cuda_bindings_cufile__anon_pod3`.
264 .. seealso:: `cuda_bindings_cufile__anon_pod3`
265 """
266 cdef:
267 cuda_bindings_cufile__anon_pod3 *_ptr
268 object _owner
269 bint _owns_ptr
270 bint _readonly
272 def __init__(self):
273 self._ptr = <cuda_bindings_cufile__anon_pod3 *>_cyb_calloc(1, sizeof(cuda_bindings_cufile__anon_pod3))
274 if self._ptr == NULL:
275 raise MemoryError("Error allocating _py_anon_pod3")
276 self._owns_ptr = True
277 self._owner = None
278 self._readonly = False
280 def __dealloc__(self):
281 cdef cuda_bindings_cufile__anon_pod3 *ptr
282 if self._owns_ptr and self._ptr != NULL:
283 ptr = self._ptr
284 self._ptr = NULL
285 _cyb_free(ptr)
287 def __repr__(self):
288 return f"<{__name__}._py_anon_pod3 object at {hex(id(self))}>"
290 @property
291 def ptr(self):
292 """Get the pointer address to the data as Python :class:`int`."""
293 return <intptr_t>(self._ptr)
295 cdef intptr_t _get_ptr(self):
296 return <intptr_t>(self._ptr)
298 def __int__(self):
299 return <intptr_t>(self._ptr)
301 def __eq__(self, other):
302 cdef _py_anon_pod3 other_
303 if not isinstance(other, _py_anon_pod3):
304 return False
305 other_ = other
306 return (_cyb_memcmp(<void *><intptr_t>(self._ptr), <void *><intptr_t>(other_._ptr), sizeof(cuda_bindings_cufile__anon_pod3)) == 0)
308 def __getbuffer__(self, _cyb_cpython.Py_buffer *buffer, int flags):
309 _cyb___getbuffer(self, buffer, <void *>self._ptr, sizeof(cuda_bindings_cufile__anon_pod3), self._readonly)
311 def __releasebuffer__(self, Py_buffer *buffer):
312 pass
314 def __setitem__(self, key, val):
315 cdef _cyb_Py_buffer view
316 if key == 0:
317 if self._readonly:
318 raise ValueError("This _py_anon_pod3 instance is read-only")
319 _cyb_PyObject_GetBuffer(val, &view, _cyb_PyBUF_SIMPLE)
320 try:
321 if <size_t>view.len < sizeof(cuda_bindings_cufile__anon_pod3):
322 raise ValueError(
323 "source buffer too small: expected at least %d bytes, got %d" % (sizeof(cuda_bindings_cufile__anon_pod3), view.len)
324 )
325 _cyb_memmove(<void*>self._ptr, view.buf, sizeof(cuda_bindings_cufile__anon_pod3))
326 self._readonly = view.readonly != 0
327 finally:
328 _cyb_PyBuffer_Release(&view)
329 else:
330 setattr(self, key, val)
332 @property
333 def dev_ptr_base(self):
334 """int: """
335 return <intptr_t>(self._ptr[0].devPtr_base)
337 @dev_ptr_base.setter
338 def dev_ptr_base(self, val):
339 if self._readonly:
340 raise ValueError("This _py_anon_pod3 instance is read-only")
341 self._ptr[0].devPtr_base = <void *><intptr_t>val
343 @property
344 def file_offset(self):
345 """int: """
346 return self._ptr[0].file_offset
348 @file_offset.setter
349 def file_offset(self, val):
350 if self._readonly:
351 raise ValueError("This _py_anon_pod3 instance is read-only")
352 self._ptr[0].file_offset = val
354 @property
355 def dev_ptr_offset(self):
356 """int: """
357 return self._ptr[0].devPtr_offset
359 @dev_ptr_offset.setter
360 def dev_ptr_offset(self, val):
361 if self._readonly:
362 raise ValueError("This _py_anon_pod3 instance is read-only")
363 self._ptr[0].devPtr_offset = val
365 @property
366 def size_(self):
367 """int: """
368 return self._ptr[0].size
370 @size_.setter
371 def size_(self, val):
372 if self._readonly:
373 raise ValueError("This _py_anon_pod3 instance is read-only")
374 self._ptr[0].size = val
376 @staticmethod
377 def from_buffer(buffer):
378 """Create an _py_anon_pod3 instance with the memory from the given buffer."""
379 return _cyb_from_buffer(buffer, sizeof(cuda_bindings_cufile__anon_pod3), _py_anon_pod3)
381 @staticmethod
382 def from_data(data):
383 """Create an _py_anon_pod3 instance wrapping the given NumPy array.
385 Args:
386 data (_numpy.ndarray): a single-element array of dtype `_py_anon_pod3_dtype` holding the data.
387 """
388 return _cyb_from_data(data, "_py_anon_pod3_dtype", _py_anon_pod3_dtype, _py_anon_pod3)
390 @staticmethod
391 def from_ptr(intptr_t ptr, bint readonly=False, object owner=None):
392 """Create an _py_anon_pod3 instance wrapping the given pointer.
394 Args:
395 ptr (intptr_t): pointer address as Python :class:`int` to the data.
396 owner (object): The Python object that owns the pointer. If not provided, data will be copied.
397 readonly (bool): whether the data is read-only (to the user). default is `False`.
398 """
399 if ptr == 0:
400 raise ValueError("ptr must not be null (0)")
401 cdef _py_anon_pod3 obj = _py_anon_pod3.__new__(_py_anon_pod3)
402 if owner is None:
403 obj._ptr = <cuda_bindings_cufile__anon_pod3 *>_cyb_malloc(sizeof(cuda_bindings_cufile__anon_pod3))
404 if obj._ptr == NULL:
405 raise MemoryError("Error allocating _py_anon_pod3")
406 _cyb_memcpy(<void*>(obj._ptr), <void*>ptr, sizeof(cuda_bindings_cufile__anon_pod3))
407 obj._owns_ptr = True
408 obj._owner = None
409 else:
410 obj._ptr = <cuda_bindings_cufile__anon_pod3 *>ptr
411 obj._owns_ptr = False
412 obj._owner = owner
413 obj._readonly = readonly
414 return obj
417cdef _get_io_events_dtype_offsets():
418 cdef CUfileIOEvents_t pod
419 return _numpy.dtype({
420 'names': ['cookie', 'status', 'ret'],
421 'formats': [_numpy.intp, _numpy.int32, _numpy.uint64],
422 'offsets': [
423 (<intptr_t>&(pod.cookie)) - (<intptr_t>&pod),
424 (<intptr_t>&(pod.status)) - (<intptr_t>&pod),
425 (<intptr_t>&(pod.ret)) - (<intptr_t>&pod),
426 ],
427 'itemsize': sizeof(CUfileIOEvents_t),
428 })
430io_events_dtype = _get_io_events_dtype_offsets()
432cdef class IOEvents:
433 """Empty-initialize an array of `CUfileIOEvents_t`.
434 The resulting object is of length `size` and of dtype `io_events_dtype`.
435 If default-constructed, the instance represents a single struct.
437 Args:
438 size (int): number of structs, default=1.
440 .. seealso:: `CUfileIOEvents_t`
441 """
442 cdef:
443 readonly object _data
444 object _owner
446 def __init__(self, size=1):
447 arr = _numpy.empty(size, dtype=io_events_dtype) 1df
448 self._data = arr.view(_numpy.recarray) 1df
449 assert self._data.itemsize == sizeof(CUfileIOEvents_t), \ 1df
450 f"itemsize {self._data.itemsize} mismatches struct size { sizeof(CUfileIOEvents_t) }"
452 def __repr__(self):
453 if self._data.size > 1:
454 return f"<{__name__}.IOEvents_Array_{self._data.size} object at {hex(id(self))}>"
455 else:
456 return f"<{__name__}.IOEvents object at {hex(id(self))}>"
458 @property
459 def ptr(self):
460 """Get the pointer address to the data as Python :class:`int`."""
461 return self._data.ctypes.data 1df
463 cdef intptr_t _get_ptr(self):
464 return self._data.ctypes.data
466 def __int__(self):
467 if self._data.size > 1 and not self._data.flags["C_CONTIGUOUS"]:
468 raise TypeError("int() argument must be a bytes-like object of size 1, or a "
469 "C-contiguous array. To get the pointer address of a "
470 "non-contiguous array, use .ptr")
471 return self._data.ctypes.data
473 def __len__(self):
474 return self._data.size
476 def __eq__(self, other):
477 cdef object self_data = self._data
478 if (not isinstance(other, IOEvents)) or self_data.size != other._data.size or self_data.dtype != other._data.dtype:
479 return False
480 return bool((self_data == other._data).all())
482 def __getbuffer__(self, Py_buffer *buffer, int flags):
483 _cyb_cpython.PyObject_GetBuffer(self._data, buffer, flags)
485 def __releasebuffer__(self, Py_buffer *buffer):
486 _cyb_cpython.PyBuffer_Release(buffer)
488 @property
489 def cookie(self):
490 """Union[~_numpy.intp, int]: """
491 if self._data.size == 1: 1df
492 return int(self._data.cookie[0]) 1df
493 return self._data.cookie
495 @cookie.setter
496 def cookie(self, val):
497 self._data.cookie = val
499 @property
500 def status(self):
501 """Union[~_numpy.int32, int]: """
502 if self._data.size == 1: 1df
503 return int(self._data.status[0]) 1df
504 return self._data.status
506 @status.setter
507 def status(self, val):
508 self._data.status = val
510 @property
511 def ret(self):
512 """Union[~_numpy.uint64, int]: """
513 if self._data.size == 1: 1d
514 return int(self._data.ret[0]) 1d
515 return self._data.ret
517 @ret.setter
518 def ret(self, val):
519 self._data.ret = val
521 def __getitem__(self, key):
522 cdef ssize_t key_
523 cdef ssize_t size
524 if isinstance(key, int): 1df
525 key_ = key 1df
526 size = self._data.size 1df
527 if key_ >= size or key_ <= -(size+1): 1df
528 raise IndexError("index is out of bounds")
529 if key_ < 0: 1df
530 key_ += size
531 return IOEvents.from_data(self._data[key_:key_+1]) 1df
532 out = self._data[key]
533 if isinstance(out, _numpy.recarray) and out.dtype == io_events_dtype:
534 return IOEvents.from_data(out)
535 return out
537 def __setitem__(self, key, val):
538 self._data[key] = val
540 @staticmethod
541 def from_buffer(buffer):
542 """Create an IOEvents instance with the memory from the given buffer."""
543 return IOEvents.from_data(_numpy.frombuffer(buffer, dtype=io_events_dtype))
545 @staticmethod
546 def from_data(data):
547 """Create an IOEvents instance wrapping the given NumPy array.
549 Args:
550 data (_numpy.ndarray): a 1D array of dtype `io_events_dtype` holding the data.
551 """
552 cdef IOEvents obj = IOEvents.__new__(IOEvents) 1df
553 if not isinstance(data, _numpy.ndarray): 1df
554 raise TypeError("data argument must be a NumPy ndarray")
555 if data.ndim != 1: 1df
556 raise ValueError("data array must be 1D")
557 if data.dtype != io_events_dtype: 1df
558 raise ValueError("data array must be of dtype io_events_dtype")
559 obj._data = data.view(_numpy.recarray) 1df
561 return obj 1df
563 @staticmethod
564 def from_ptr(intptr_t ptr, size_t size=1, bint readonly=False, object owner=None):
565 """Create an IOEvents instance wrapping the given pointer.
567 Args:
568 ptr (intptr_t): pointer address as Python :class:`int` to the data.
569 size (int): number of structs, default=1.
570 readonly (bool): whether the data is read-only (to the user). default is `False`.
571 owner (object): object that owns the memory at *ptr*. A strong reference is
572 kept so the backing storage outlives this wrapper.
573 """
574 if ptr == 0:
575 raise ValueError("ptr must not be null (0)")
576 cdef IOEvents obj = IOEvents.__new__(IOEvents)
577 cdef flag = _cyb_cpython_buffer.PyBUF_READ if readonly else _cyb_cpython_buffer.PyBUF_WRITE
578 cdef object buf = _cyb_cpython_memoryview.PyMemoryView_FromMemory(
579 <char*>ptr, sizeof(CUfileIOEvents_t) * size, flag)
580 data = _numpy.ndarray(size, buffer=buf, dtype=io_events_dtype)
581 obj._data = data.view(_numpy.recarray)
582 obj._owner = owner
584 return obj
587cdef _get_op_counter_dtype_offsets():
588 cdef CUfileOpCounter_t pod
589 return _numpy.dtype({
590 'names': ['ok', 'err'],
591 'formats': [_numpy.uint64, _numpy.uint64],
592 'offsets': [
593 (<intptr_t>&(pod.ok)) - (<intptr_t>&pod),
594 (<intptr_t>&(pod.err)) - (<intptr_t>&pod),
595 ],
596 'itemsize': sizeof(CUfileOpCounter_t),
597 })
599op_counter_dtype = _get_op_counter_dtype_offsets()
601cdef class OpCounter:
602 """Empty-initialize an instance of `CUfileOpCounter_t`.
605 .. seealso:: `CUfileOpCounter_t`
606 """
607 cdef:
608 CUfileOpCounter_t *_ptr
609 object _owner
610 bint _owns_ptr
611 bint _readonly
613 def __init__(self):
614 self._ptr = <CUfileOpCounter_t *>_cyb_calloc(1, sizeof(CUfileOpCounter_t))
615 if self._ptr == NULL:
616 raise MemoryError("Error allocating OpCounter")
617 self._owns_ptr = True
618 self._owner = None
619 self._readonly = False
621 def __dealloc__(self):
622 cdef CUfileOpCounter_t *ptr
623 if self._owns_ptr and self._ptr != NULL: 1eb
624 ptr = self._ptr
625 self._ptr = NULL
626 _cyb_free(ptr)
628 def __repr__(self):
629 return f"<{__name__}.OpCounter object at {hex(id(self))}>"
631 @property
632 def ptr(self):
633 """Get the pointer address to the data as Python :class:`int`."""
634 return <intptr_t>(self._ptr)
636 cdef intptr_t _get_ptr(self):
637 return <intptr_t>(self._ptr)
639 def __int__(self):
640 return <intptr_t>(self._ptr)
642 def __eq__(self, other):
643 cdef OpCounter other_
644 if not isinstance(other, OpCounter):
645 return False
646 other_ = other
647 return (_cyb_memcmp(<void *><intptr_t>(self._ptr), <void *><intptr_t>(other_._ptr), sizeof(CUfileOpCounter_t)) == 0)
649 def __getbuffer__(self, _cyb_cpython.Py_buffer *buffer, int flags):
650 _cyb___getbuffer(self, buffer, <void *>self._ptr, sizeof(CUfileOpCounter_t), self._readonly)
652 def __releasebuffer__(self, Py_buffer *buffer):
653 pass
655 def __setitem__(self, key, val):
656 cdef _cyb_Py_buffer view
657 if key == 0:
658 if self._readonly:
659 raise ValueError("This OpCounter instance is read-only")
660 _cyb_PyObject_GetBuffer(val, &view, _cyb_PyBUF_SIMPLE)
661 try:
662 if <size_t>view.len < sizeof(CUfileOpCounter_t):
663 raise ValueError(
664 "source buffer too small: expected at least %d bytes, got %d" % (sizeof(CUfileOpCounter_t), view.len)
665 )
666 _cyb_memmove(<void*>self._ptr, view.buf, sizeof(CUfileOpCounter_t))
667 self._readonly = view.readonly != 0
668 finally:
669 _cyb_PyBuffer_Release(&view)
670 else:
671 setattr(self, key, val)
673 @property
674 def ok(self):
675 """int: """
676 return self._ptr[0].ok 1eb
678 @ok.setter
679 def ok(self, val):
680 if self._readonly:
681 raise ValueError("This OpCounter instance is read-only")
682 self._ptr[0].ok = val
684 @property
685 def err(self):
686 """int: """
687 return self._ptr[0].err
689 @err.setter
690 def err(self, val):
691 if self._readonly:
692 raise ValueError("This OpCounter instance is read-only")
693 self._ptr[0].err = val
695 @staticmethod
696 def from_buffer(buffer):
697 """Create an OpCounter instance with the memory from the given buffer."""
698 return _cyb_from_buffer(buffer, sizeof(CUfileOpCounter_t), OpCounter)
700 @staticmethod
701 def from_data(data):
702 """Create an OpCounter instance wrapping the given NumPy array.
704 Args:
705 data (_numpy.ndarray): a single-element array of dtype `op_counter_dtype` holding the data.
706 """
707 return _cyb_from_data(data, "op_counter_dtype", op_counter_dtype, OpCounter) 1eb
709 @staticmethod
710 def from_ptr(intptr_t ptr, bint readonly=False, object owner=None):
711 """Create an OpCounter instance wrapping the given pointer.
713 Args:
714 ptr (intptr_t): pointer address as Python :class:`int` to the data.
715 owner (object): The Python object that owns the pointer. If not provided, data will be copied.
716 readonly (bool): whether the data is read-only (to the user). default is `False`.
717 """
718 if ptr == 0: 1eb
719 raise ValueError("ptr must not be null (0)")
720 cdef OpCounter obj = OpCounter.__new__(OpCounter) 1eb
721 if owner is None: 1eb
722 obj._ptr = <CUfileOpCounter_t *>_cyb_malloc(sizeof(CUfileOpCounter_t))
723 if obj._ptr == NULL:
724 raise MemoryError("Error allocating OpCounter")
725 _cyb_memcpy(<void*>(obj._ptr), <void*>ptr, sizeof(CUfileOpCounter_t))
726 obj._owns_ptr = True
727 obj._owner = None
728 else:
729 obj._ptr = <CUfileOpCounter_t *>ptr 1eb
730 obj._owns_ptr = False 1eb
731 obj._owner = owner 1eb
732 obj._readonly = readonly 1eb
733 return obj 1eb
736cdef _get_per_gpu_stats_dtype_offsets():
737 cdef CUfilePerGpuStats_t pod
738 return _numpy.dtype({
739 'names': ['uuid', 'read_bytes', 'read_bw_bytes_per_sec', 'read_utilization', 'read_duration_us', 'n_total_reads', 'n_p2p_reads', 'n_nvfs_reads', 'n_posix_reads', 'n_unaligned_reads', 'n_dr_reads', 'n_sparse_regions', 'n_inline_regions', 'n_reads_err', 'writes_bytes', 'write_bw_bytes_per_sec', 'write_utilization', 'write_duration_us', 'n_total_writes', 'n_p2p_writes', 'n_nvfs_writes', 'n_posix_writes', 'n_unaligned_writes', 'n_dr_writes', 'n_writes_err', 'n_mmap', 'n_mmap_ok', 'n_mmap_err', 'n_mmap_free', 'reg_bytes'],
740 'formats': [(_numpy.int8, 16), _numpy.uint64, _numpy.uint64, _numpy.uint64, _numpy.uint64, _numpy.uint64, _numpy.uint64, _numpy.uint64, _numpy.uint64, _numpy.uint64, _numpy.uint64, _numpy.uint64, _numpy.uint64, _numpy.uint64, _numpy.uint64, _numpy.uint64, _numpy.uint64, _numpy.uint64, _numpy.uint64, _numpy.uint64, _numpy.uint64, _numpy.uint64, _numpy.uint64, _numpy.uint64, _numpy.uint64, _numpy.uint64, _numpy.uint64, _numpy.uint64, _numpy.uint64, _numpy.uint64],
741 'offsets': [
742 (<intptr_t>&(pod.uuid)) - (<intptr_t>&pod),
743 (<intptr_t>&(pod.read_bytes)) - (<intptr_t>&pod),
744 (<intptr_t>&(pod.read_bw_bytes_per_sec)) - (<intptr_t>&pod),
745 (<intptr_t>&(pod.read_utilization)) - (<intptr_t>&pod),
746 (<intptr_t>&(pod.read_duration_us)) - (<intptr_t>&pod),
747 (<intptr_t>&(pod.n_total_reads)) - (<intptr_t>&pod),
748 (<intptr_t>&(pod.n_p2p_reads)) - (<intptr_t>&pod),
749 (<intptr_t>&(pod.n_nvfs_reads)) - (<intptr_t>&pod),
750 (<intptr_t>&(pod.n_posix_reads)) - (<intptr_t>&pod),
751 (<intptr_t>&(pod.n_unaligned_reads)) - (<intptr_t>&pod),
752 (<intptr_t>&(pod.n_dr_reads)) - (<intptr_t>&pod),
753 (<intptr_t>&(pod.n_sparse_regions)) - (<intptr_t>&pod),
754 (<intptr_t>&(pod.n_inline_regions)) - (<intptr_t>&pod),
755 (<intptr_t>&(pod.n_reads_err)) - (<intptr_t>&pod),
756 (<intptr_t>&(pod.writes_bytes)) - (<intptr_t>&pod),
757 (<intptr_t>&(pod.write_bw_bytes_per_sec)) - (<intptr_t>&pod),
758 (<intptr_t>&(pod.write_utilization)) - (<intptr_t>&pod),
759 (<intptr_t>&(pod.write_duration_us)) - (<intptr_t>&pod),
760 (<intptr_t>&(pod.n_total_writes)) - (<intptr_t>&pod),
761 (<intptr_t>&(pod.n_p2p_writes)) - (<intptr_t>&pod),
762 (<intptr_t>&(pod.n_nvfs_writes)) - (<intptr_t>&pod),
763 (<intptr_t>&(pod.n_posix_writes)) - (<intptr_t>&pod),
764 (<intptr_t>&(pod.n_unaligned_writes)) - (<intptr_t>&pod),
765 (<intptr_t>&(pod.n_dr_writes)) - (<intptr_t>&pod),
766 (<intptr_t>&(pod.n_writes_err)) - (<intptr_t>&pod),
767 (<intptr_t>&(pod.n_mmap)) - (<intptr_t>&pod),
768 (<intptr_t>&(pod.n_mmap_ok)) - (<intptr_t>&pod),
769 (<intptr_t>&(pod.n_mmap_err)) - (<intptr_t>&pod),
770 (<intptr_t>&(pod.n_mmap_free)) - (<intptr_t>&pod),
771 (<intptr_t>&(pod.reg_bytes)) - (<intptr_t>&pod),
772 ],
773 'itemsize': sizeof(CUfilePerGpuStats_t),
774 })
776per_gpu_stats_dtype = _get_per_gpu_stats_dtype_offsets()
778cdef class PerGpuStats:
779 """Empty-initialize an array of `CUfilePerGpuStats_t`.
780 The resulting object is of length `size` and of dtype `per_gpu_stats_dtype`.
781 If default-constructed, the instance represents a single struct.
783 Args:
784 size (int): number of structs, default=1.
786 .. seealso:: `CUfilePerGpuStats_t`
787 """
788 cdef:
789 readonly object _data
790 object _owner
792 def __init__(self, size=1):
793 arr = _numpy.empty(size, dtype=per_gpu_stats_dtype)
794 self._data = arr.view(_numpy.recarray)
795 assert self._data.itemsize == sizeof(CUfilePerGpuStats_t), \
796 f"itemsize {self._data.itemsize} mismatches struct size { sizeof(CUfilePerGpuStats_t) }"
798 def __repr__(self):
799 if self._data.size > 1:
800 return f"<{__name__}.PerGpuStats_Array_{self._data.size} object at {hex(id(self))}>"
801 else:
802 return f"<{__name__}.PerGpuStats object at {hex(id(self))}>"
804 @property
805 def ptr(self):
806 """Get the pointer address to the data as Python :class:`int`."""
807 return self._data.ctypes.data
809 cdef intptr_t _get_ptr(self):
810 return self._data.ctypes.data
812 def __int__(self):
813 if self._data.size > 1 and not self._data.flags["C_CONTIGUOUS"]:
814 raise TypeError("int() argument must be a bytes-like object of size 1, or a "
815 "C-contiguous array. To get the pointer address of a "
816 "non-contiguous array, use .ptr")
817 return self._data.ctypes.data
819 def __len__(self):
820 return self._data.size
822 def __eq__(self, other):
823 cdef object self_data = self._data
824 if (not isinstance(other, PerGpuStats)) or self_data.size != other._data.size or self_data.dtype != other._data.dtype:
825 return False
826 return bool((self_data == other._data).all())
828 def __getbuffer__(self, Py_buffer *buffer, int flags):
829 _cyb_cpython.PyObject_GetBuffer(self._data, buffer, flags)
831 def __releasebuffer__(self, Py_buffer *buffer):
832 _cyb_cpython.PyBuffer_Release(buffer)
834 @property
835 def uuid(self):
836 """~_numpy.int8: (array of length 16)."""
837 return self._data.uuid
839 @uuid.setter
840 def uuid(self, val):
841 self._data.uuid = val
843 @property
844 def read_bytes(self):
845 """Union[~_numpy.uint64, int]: """
846 if self._data.size == 1:
847 return int(self._data.read_bytes[0])
848 return self._data.read_bytes
850 @read_bytes.setter
851 def read_bytes(self, val):
852 self._data.read_bytes = val
854 @property
855 def read_bw_bytes_per_sec(self):
856 """Union[~_numpy.uint64, int]: """
857 if self._data.size == 1:
858 return int(self._data.read_bw_bytes_per_sec[0])
859 return self._data.read_bw_bytes_per_sec
861 @read_bw_bytes_per_sec.setter
862 def read_bw_bytes_per_sec(self, val):
863 self._data.read_bw_bytes_per_sec = val
865 @property
866 def read_utilization(self):
867 """Union[~_numpy.uint64, int]: """
868 if self._data.size == 1:
869 return int(self._data.read_utilization[0])
870 return self._data.read_utilization
872 @read_utilization.setter
873 def read_utilization(self, val):
874 self._data.read_utilization = val
876 @property
877 def read_duration_us(self):
878 """Union[~_numpy.uint64, int]: """
879 if self._data.size == 1:
880 return int(self._data.read_duration_us[0])
881 return self._data.read_duration_us
883 @read_duration_us.setter
884 def read_duration_us(self, val):
885 self._data.read_duration_us = val
887 @property
888 def n_total_reads(self):
889 """Union[~_numpy.uint64, int]: """
890 if self._data.size == 1: 1c
891 return int(self._data.n_total_reads[0]) 1c
892 return self._data.n_total_reads
894 @n_total_reads.setter
895 def n_total_reads(self, val):
896 self._data.n_total_reads = val
898 @property
899 def n_p2p_reads(self):
900 """Union[~_numpy.uint64, int]: """
901 if self._data.size == 1:
902 return int(self._data.n_p2p_reads[0])
903 return self._data.n_p2p_reads
905 @n_p2p_reads.setter
906 def n_p2p_reads(self, val):
907 self._data.n_p2p_reads = val
909 @property
910 def n_nvfs_reads(self):
911 """Union[~_numpy.uint64, int]: """
912 if self._data.size == 1:
913 return int(self._data.n_nvfs_reads[0])
914 return self._data.n_nvfs_reads
916 @n_nvfs_reads.setter
917 def n_nvfs_reads(self, val):
918 self._data.n_nvfs_reads = val
920 @property
921 def n_posix_reads(self):
922 """Union[~_numpy.uint64, int]: """
923 if self._data.size == 1:
924 return int(self._data.n_posix_reads[0])
925 return self._data.n_posix_reads
927 @n_posix_reads.setter
928 def n_posix_reads(self, val):
929 self._data.n_posix_reads = val
931 @property
932 def n_unaligned_reads(self):
933 """Union[~_numpy.uint64, int]: """
934 if self._data.size == 1:
935 return int(self._data.n_unaligned_reads[0])
936 return self._data.n_unaligned_reads
938 @n_unaligned_reads.setter
939 def n_unaligned_reads(self, val):
940 self._data.n_unaligned_reads = val
942 @property
943 def n_dr_reads(self):
944 """Union[~_numpy.uint64, int]: """
945 if self._data.size == 1:
946 return int(self._data.n_dr_reads[0])
947 return self._data.n_dr_reads
949 @n_dr_reads.setter
950 def n_dr_reads(self, val):
951 self._data.n_dr_reads = val
953 @property
954 def n_sparse_regions(self):
955 """Union[~_numpy.uint64, int]: """
956 if self._data.size == 1:
957 return int(self._data.n_sparse_regions[0])
958 return self._data.n_sparse_regions
960 @n_sparse_regions.setter
961 def n_sparse_regions(self, val):
962 self._data.n_sparse_regions = val
964 @property
965 def n_inline_regions(self):
966 """Union[~_numpy.uint64, int]: """
967 if self._data.size == 1:
968 return int(self._data.n_inline_regions[0])
969 return self._data.n_inline_regions
971 @n_inline_regions.setter
972 def n_inline_regions(self, val):
973 self._data.n_inline_regions = val
975 @property
976 def n_reads_err(self):
977 """Union[~_numpy.uint64, int]: """
978 if self._data.size == 1:
979 return int(self._data.n_reads_err[0])
980 return self._data.n_reads_err
982 @n_reads_err.setter
983 def n_reads_err(self, val):
984 self._data.n_reads_err = val
986 @property
987 def writes_bytes(self):
988 """Union[~_numpy.uint64, int]: """
989 if self._data.size == 1:
990 return int(self._data.writes_bytes[0])
991 return self._data.writes_bytes
993 @writes_bytes.setter
994 def writes_bytes(self, val):
995 self._data.writes_bytes = val
997 @property
998 def write_bw_bytes_per_sec(self):
999 """Union[~_numpy.uint64, int]: """
1000 if self._data.size == 1:
1001 return int(self._data.write_bw_bytes_per_sec[0])
1002 return self._data.write_bw_bytes_per_sec
1004 @write_bw_bytes_per_sec.setter
1005 def write_bw_bytes_per_sec(self, val):
1006 self._data.write_bw_bytes_per_sec = val
1008 @property
1009 def write_utilization(self):
1010 """Union[~_numpy.uint64, int]: """
1011 if self._data.size == 1:
1012 return int(self._data.write_utilization[0])
1013 return self._data.write_utilization
1015 @write_utilization.setter
1016 def write_utilization(self, val):
1017 self._data.write_utilization = val
1019 @property
1020 def write_duration_us(self):
1021 """Union[~_numpy.uint64, int]: """
1022 if self._data.size == 1:
1023 return int(self._data.write_duration_us[0])
1024 return self._data.write_duration_us
1026 @write_duration_us.setter
1027 def write_duration_us(self, val):
1028 self._data.write_duration_us = val
1030 @property
1031 def n_total_writes(self):
1032 """Union[~_numpy.uint64, int]: """
1033 if self._data.size == 1:
1034 return int(self._data.n_total_writes[0])
1035 return self._data.n_total_writes
1037 @n_total_writes.setter
1038 def n_total_writes(self, val):
1039 self._data.n_total_writes = val
1041 @property
1042 def n_p2p_writes(self):
1043 """Union[~_numpy.uint64, int]: """
1044 if self._data.size == 1:
1045 return int(self._data.n_p2p_writes[0])
1046 return self._data.n_p2p_writes
1048 @n_p2p_writes.setter
1049 def n_p2p_writes(self, val):
1050 self._data.n_p2p_writes = val
1052 @property
1053 def n_nvfs_writes(self):
1054 """Union[~_numpy.uint64, int]: """
1055 if self._data.size == 1:
1056 return int(self._data.n_nvfs_writes[0])
1057 return self._data.n_nvfs_writes
1059 @n_nvfs_writes.setter
1060 def n_nvfs_writes(self, val):
1061 self._data.n_nvfs_writes = val
1063 @property
1064 def n_posix_writes(self):
1065 """Union[~_numpy.uint64, int]: """
1066 if self._data.size == 1:
1067 return int(self._data.n_posix_writes[0])
1068 return self._data.n_posix_writes
1070 @n_posix_writes.setter
1071 def n_posix_writes(self, val):
1072 self._data.n_posix_writes = val
1074 @property
1075 def n_unaligned_writes(self):
1076 """Union[~_numpy.uint64, int]: """
1077 if self._data.size == 1:
1078 return int(self._data.n_unaligned_writes[0])
1079 return self._data.n_unaligned_writes
1081 @n_unaligned_writes.setter
1082 def n_unaligned_writes(self, val):
1083 self._data.n_unaligned_writes = val
1085 @property
1086 def n_dr_writes(self):
1087 """Union[~_numpy.uint64, int]: """
1088 if self._data.size == 1:
1089 return int(self._data.n_dr_writes[0])
1090 return self._data.n_dr_writes
1092 @n_dr_writes.setter
1093 def n_dr_writes(self, val):
1094 self._data.n_dr_writes = val
1096 @property
1097 def n_writes_err(self):
1098 """Union[~_numpy.uint64, int]: """
1099 if self._data.size == 1:
1100 return int(self._data.n_writes_err[0])
1101 return self._data.n_writes_err
1103 @n_writes_err.setter
1104 def n_writes_err(self, val):
1105 self._data.n_writes_err = val
1107 @property
1108 def n_mmap(self):
1109 """Union[~_numpy.uint64, int]: """
1110 if self._data.size == 1:
1111 return int(self._data.n_mmap[0])
1112 return self._data.n_mmap
1114 @n_mmap.setter
1115 def n_mmap(self, val):
1116 self._data.n_mmap = val
1118 @property
1119 def n_mmap_ok(self):
1120 """Union[~_numpy.uint64, int]: """
1121 if self._data.size == 1:
1122 return int(self._data.n_mmap_ok[0])
1123 return self._data.n_mmap_ok
1125 @n_mmap_ok.setter
1126 def n_mmap_ok(self, val):
1127 self._data.n_mmap_ok = val
1129 @property
1130 def n_mmap_err(self):
1131 """Union[~_numpy.uint64, int]: """
1132 if self._data.size == 1:
1133 return int(self._data.n_mmap_err[0])
1134 return self._data.n_mmap_err
1136 @n_mmap_err.setter
1137 def n_mmap_err(self, val):
1138 self._data.n_mmap_err = val
1140 @property
1141 def n_mmap_free(self):
1142 """Union[~_numpy.uint64, int]: """
1143 if self._data.size == 1:
1144 return int(self._data.n_mmap_free[0])
1145 return self._data.n_mmap_free
1147 @n_mmap_free.setter
1148 def n_mmap_free(self, val):
1149 self._data.n_mmap_free = val
1151 @property
1152 def reg_bytes(self):
1153 """Union[~_numpy.uint64, int]: """
1154 if self._data.size == 1:
1155 return int(self._data.reg_bytes[0])
1156 return self._data.reg_bytes
1158 @reg_bytes.setter
1159 def reg_bytes(self, val):
1160 self._data.reg_bytes = val
1162 def __getitem__(self, key):
1163 cdef ssize_t key_
1164 cdef ssize_t size
1165 if isinstance(key, int): 1c
1166 key_ = key 1c
1167 size = self._data.size 1c
1168 if key_ >= size or key_ <= -(size+1): 1c
1169 raise IndexError("index is out of bounds")
1170 if key_ < 0: 1c
1171 key_ += size
1172 return PerGpuStats.from_data(self._data[key_:key_+1]) 1c
1173 out = self._data[key]
1174 if isinstance(out, _numpy.recarray) and out.dtype == per_gpu_stats_dtype:
1175 return PerGpuStats.from_data(out)
1176 return out
1178 def __setitem__(self, key, val):
1179 self._data[key] = val
1181 @staticmethod
1182 def from_buffer(buffer):
1183 """Create an PerGpuStats instance with the memory from the given buffer."""
1184 return PerGpuStats.from_data(_numpy.frombuffer(buffer, dtype=per_gpu_stats_dtype))
1186 @staticmethod
1187 def from_data(data):
1188 """Create an PerGpuStats instance wrapping the given NumPy array.
1190 Args:
1191 data (_numpy.ndarray): a 1D array of dtype `per_gpu_stats_dtype` holding the data.
1192 """
1193 cdef PerGpuStats obj = PerGpuStats.__new__(PerGpuStats) 1c
1194 if not isinstance(data, _numpy.ndarray): 1c
1195 raise TypeError("data argument must be a NumPy ndarray")
1196 if data.ndim != 1: 1c
1197 raise ValueError("data array must be 1D")
1198 if data.dtype != per_gpu_stats_dtype: 1c
1199 raise ValueError("data array must be of dtype per_gpu_stats_dtype")
1200 obj._data = data.view(_numpy.recarray) 1c
1202 return obj 1c
1204 @staticmethod
1205 def from_ptr(intptr_t ptr, size_t size=1, bint readonly=False, object owner=None):
1206 """Create an PerGpuStats instance wrapping the given pointer.
1208 Args:
1209 ptr (intptr_t): pointer address as Python :class:`int` to the data.
1210 size (int): number of structs, default=1.
1211 readonly (bool): whether the data is read-only (to the user). default is `False`.
1212 owner (object): object that owns the memory at *ptr*. A strong reference is
1213 kept so the backing storage outlives this wrapper.
1214 """
1215 if ptr == 0: 1c
1216 raise ValueError("ptr must not be null (0)")
1217 cdef PerGpuStats obj = PerGpuStats.__new__(PerGpuStats) 1c
1218 cdef flag = _cyb_cpython_buffer.PyBUF_READ if readonly else _cyb_cpython_buffer.PyBUF_WRITE 1c
1219 cdef object buf = _cyb_cpython_memoryview.PyMemoryView_FromMemory( 1c
1220 <char*>ptr, sizeof(CUfilePerGpuStats_t) * size, flag) 1c
1221 data = _numpy.ndarray(size, buffer=buf, dtype=per_gpu_stats_dtype) 1c
1222 obj._data = data.view(_numpy.recarray) 1c
1223 obj._owner = owner 1c
1225 return obj 1c
1228cdef _get_io_vec_dtype_offsets():
1229 cdef CUfileIOVec_t pod
1230 return _numpy.dtype({
1231 'names': ['base_', 'len'],
1232 'formats': [_numpy.intp, _numpy.uint64],
1233 'offsets': [
1234 (<intptr_t>&(pod.base)) - (<intptr_t>&pod),
1235 (<intptr_t>&(pod.len)) - (<intptr_t>&pod),
1236 ],
1237 'itemsize': sizeof(CUfileIOVec_t),
1238 })
1240io_vec_dtype = _get_io_vec_dtype_offsets()
1242cdef class IOVec:
1243 """Empty-initialize an array of `CUfileIOVec_t`.
1244 The resulting object is of length `size` and of dtype `io_vec_dtype`.
1245 If default-constructed, the instance represents a single struct.
1247 Args:
1248 size (int): number of structs, default=1.
1250 .. seealso:: `CUfileIOVec_t`
1251 """
1252 cdef:
1253 readonly object _data
1254 object _owner
1256 def __init__(self, size=1):
1257 arr = _numpy.empty(size, dtype=io_vec_dtype)
1258 self._data = arr.view(_numpy.recarray)
1259 assert self._data.itemsize == sizeof(CUfileIOVec_t), \
1260 f"itemsize {self._data.itemsize} mismatches struct size { sizeof(CUfileIOVec_t) }"
1262 def __repr__(self):
1263 if self._data.size > 1:
1264 return f"<{__name__}.IOVec_Array_{self._data.size} object at {hex(id(self))}>"
1265 else:
1266 return f"<{__name__}.IOVec object at {hex(id(self))}>"
1268 @property
1269 def ptr(self):
1270 """Get the pointer address to the data as Python :class:`int`."""
1271 return self._data.ctypes.data
1273 cdef intptr_t _get_ptr(self):
1274 return self._data.ctypes.data
1276 def __int__(self):
1277 if self._data.size > 1 and not self._data.flags["C_CONTIGUOUS"]:
1278 raise TypeError("int() argument must be a bytes-like object of size 1, or a "
1279 "C-contiguous array. To get the pointer address of a "
1280 "non-contiguous array, use .ptr")
1281 return self._data.ctypes.data
1283 def __len__(self):
1284 return self._data.size
1286 def __eq__(self, other):
1287 cdef object self_data = self._data
1288 if (not isinstance(other, IOVec)) or self_data.size != other._data.size or self_data.dtype != other._data.dtype:
1289 return False
1290 return bool((self_data == other._data).all())
1292 def __getbuffer__(self, Py_buffer *buffer, int flags):
1293 _cyb_cpython.PyObject_GetBuffer(self._data, buffer, flags)
1295 def __releasebuffer__(self, Py_buffer *buffer):
1296 _cyb_cpython.PyBuffer_Release(buffer)
1298 @property
1299 def base_(self):
1300 """Union[~_numpy.intp, int]: """
1301 if self._data.size == 1:
1302 return int(self._data.base_[0])
1303 return self._data.base_
1305 @base_.setter
1306 def base_(self, val):
1307 self._data.base_ = val
1309 @property
1310 def len(self):
1311 """Union[~_numpy.uint64, int]: """
1312 if self._data.size == 1:
1313 return int(self._data.len[0])
1314 return self._data.len
1316 @len.setter
1317 def len(self, val):
1318 self._data.len = val
1320 def __getitem__(self, key):
1321 cdef ssize_t key_
1322 cdef ssize_t size
1323 if isinstance(key, int):
1324 key_ = key
1325 size = self._data.size
1326 if key_ >= size or key_ <= -(size+1):
1327 raise IndexError("index is out of bounds")
1328 if key_ < 0:
1329 key_ += size
1330 return IOVec.from_data(self._data[key_:key_+1])
1331 out = self._data[key]
1332 if isinstance(out, _numpy.recarray) and out.dtype == io_vec_dtype:
1333 return IOVec.from_data(out)
1334 return out
1336 def __setitem__(self, key, val):
1337 self._data[key] = val
1339 @staticmethod
1340 def from_buffer(buffer):
1341 """Create an IOVec instance with the memory from the given buffer."""
1342 return IOVec.from_data(_numpy.frombuffer(buffer, dtype=io_vec_dtype))
1344 @staticmethod
1345 def from_data(data):
1346 """Create an IOVec instance wrapping the given NumPy array.
1348 Args:
1349 data (_numpy.ndarray): a 1D array of dtype `io_vec_dtype` holding the data.
1350 """
1351 cdef IOVec obj = IOVec.__new__(IOVec)
1352 if not isinstance(data, _numpy.ndarray):
1353 raise TypeError("data argument must be a NumPy ndarray")
1354 if data.ndim != 1:
1355 raise ValueError("data array must be 1D")
1356 if data.dtype != io_vec_dtype:
1357 raise ValueError("data array must be of dtype io_vec_dtype")
1358 obj._data = data.view(_numpy.recarray)
1360 return obj
1362 @staticmethod
1363 def from_ptr(intptr_t ptr, size_t size=1, bint readonly=False, object owner=None):
1364 """Create an IOVec instance wrapping the given pointer.
1366 Args:
1367 ptr (intptr_t): pointer address as Python :class:`int` to the data.
1368 size (int): number of structs, default=1.
1369 readonly (bool): whether the data is read-only (to the user). default is `False`.
1370 owner (object): object that owns the memory at *ptr*. A strong reference is
1371 kept so the backing storage outlives this wrapper.
1372 """
1373 if ptr == 0:
1374 raise ValueError("ptr must not be null (0)")
1375 cdef IOVec obj = IOVec.__new__(IOVec)
1376 cdef flag = _cyb_cpython_buffer.PyBUF_READ if readonly else _cyb_cpython_buffer.PyBUF_WRITE
1377 cdef object buf = _cyb_cpython_memoryview.PyMemoryView_FromMemory(
1378 <char*>ptr, sizeof(CUfileIOVec_t) * size, flag)
1379 data = _numpy.ndarray(size, buffer=buf, dtype=io_vec_dtype)
1380 obj._data = data.view(_numpy.recarray)
1381 obj._owner = owner
1383 return obj
1386cdef _get_descr_dtype_offsets():
1387 cdef CUfileDescr_t pod
1388 return _numpy.dtype({
1389 'names': ['type', 'handle', 'fs_ops'],
1390 'formats': [_numpy.int32, _py_anon_pod1_dtype, _numpy.intp],
1391 'offsets': [
1392 (<intptr_t>&(pod.type)) - (<intptr_t>&pod),
1393 (<intptr_t>&(pod.handle)) - (<intptr_t>&pod),
1394 (<intptr_t>&(pod.fs_ops)) - (<intptr_t>&pod),
1395 ],
1396 'itemsize': sizeof(CUfileDescr_t),
1397 })
1399descr_dtype = _get_descr_dtype_offsets()
1401cdef class Descr:
1402 """Empty-initialize an array of `CUfileDescr_t`.
1403 The resulting object is of length `size` and of dtype `descr_dtype`.
1404 If default-constructed, the instance represents a single struct.
1406 Args:
1407 size (int): number of structs, default=1.
1409 .. seealso:: `CUfileDescr_t`
1410 """
1411 cdef:
1412 readonly object _data
1413 object _owner
1415 def __init__(self, size=1):
1416 arr = _numpy.empty(size, dtype=descr_dtype) 1dgfhijklmebcr
1417 self._data = arr.view(_numpy.recarray) 1dgfhijklmebcr
1418 assert self._data.itemsize == sizeof(CUfileDescr_t), \ 1dgfhijklmebcr
1419 f"itemsize {self._data.itemsize} mismatches struct size { sizeof(CUfileDescr_t) }"
1421 def __repr__(self):
1422 if self._data.size > 1:
1423 return f"<{__name__}.Descr_Array_{self._data.size} object at {hex(id(self))}>"
1424 else:
1425 return f"<{__name__}.Descr object at {hex(id(self))}>"
1427 @property
1428 def ptr(self):
1429 """Get the pointer address to the data as Python :class:`int`."""
1430 return self._data.ctypes.data 1dgfhijklmebcr
1432 cdef intptr_t _get_ptr(self):
1433 return self._data.ctypes.data
1435 def __int__(self):
1436 if self._data.size > 1 and not self._data.flags["C_CONTIGUOUS"]:
1437 raise TypeError("int() argument must be a bytes-like object of size 1, or a "
1438 "C-contiguous array. To get the pointer address of a "
1439 "non-contiguous array, use .ptr")
1440 return self._data.ctypes.data
1442 def __len__(self):
1443 return self._data.size
1445 def __eq__(self, other):
1446 cdef object self_data = self._data
1447 if (not isinstance(other, Descr)) or self_data.size != other._data.size or self_data.dtype != other._data.dtype:
1448 return False
1449 return bool((self_data == other._data).all())
1451 def __getbuffer__(self, Py_buffer *buffer, int flags):
1452 _cyb_cpython.PyObject_GetBuffer(self._data, buffer, flags)
1454 def __releasebuffer__(self, Py_buffer *buffer):
1455 _cyb_cpython.PyBuffer_Release(buffer)
1457 @property
1458 def type(self):
1459 """Union[~_numpy.int32, int]: """
1460 if self._data.size == 1:
1461 return int(self._data.type[0])
1462 return self._data.type
1464 @type.setter
1465 def type(self, val):
1466 self._data.type = val 1dgfhijklmebcr
1468 @property
1469 def handle(self):
1470 """_py_anon_pod1_dtype: """
1471 return self._data.handle 1dgfhijklmebcr
1473 @handle.setter
1474 def handle(self, val):
1475 self._data.handle = val
1477 @property
1478 def fs_ops(self):
1479 """Union[~_numpy.intp, int]: """
1480 if self._data.size == 1:
1481 return int(self._data.fs_ops[0])
1482 return self._data.fs_ops
1484 @fs_ops.setter
1485 def fs_ops(self, val):
1486 self._data.fs_ops = val 1dgfhijklmebcr
1488 def __getitem__(self, key):
1489 cdef ssize_t key_
1490 cdef ssize_t size
1491 if isinstance(key, int):
1492 key_ = key
1493 size = self._data.size
1494 if key_ >= size or key_ <= -(size+1):
1495 raise IndexError("index is out of bounds")
1496 if key_ < 0:
1497 key_ += size
1498 return Descr.from_data(self._data[key_:key_+1])
1499 out = self._data[key]
1500 if isinstance(out, _numpy.recarray) and out.dtype == descr_dtype:
1501 return Descr.from_data(out)
1502 return out
1504 def __setitem__(self, key, val):
1505 self._data[key] = val
1507 @staticmethod
1508 def from_buffer(buffer):
1509 """Create an Descr instance with the memory from the given buffer."""
1510 return Descr.from_data(_numpy.frombuffer(buffer, dtype=descr_dtype))
1512 @staticmethod
1513 def from_data(data):
1514 """Create an Descr instance wrapping the given NumPy array.
1516 Args:
1517 data (_numpy.ndarray): a 1D array of dtype `descr_dtype` holding the data.
1518 """
1519 cdef Descr obj = Descr.__new__(Descr)
1520 if not isinstance(data, _numpy.ndarray):
1521 raise TypeError("data argument must be a NumPy ndarray")
1522 if data.ndim != 1:
1523 raise ValueError("data array must be 1D")
1524 if data.dtype != descr_dtype:
1525 raise ValueError("data array must be of dtype descr_dtype")
1526 obj._data = data.view(_numpy.recarray)
1528 return obj
1530 @staticmethod
1531 def from_ptr(intptr_t ptr, size_t size=1, bint readonly=False, object owner=None):
1532 """Create an Descr instance wrapping the given pointer.
1534 Args:
1535 ptr (intptr_t): pointer address as Python :class:`int` to the data.
1536 size (int): number of structs, default=1.
1537 readonly (bool): whether the data is read-only (to the user). default is `False`.
1538 owner (object): object that owns the memory at *ptr*. A strong reference is
1539 kept so the backing storage outlives this wrapper.
1540 """
1541 if ptr == 0:
1542 raise ValueError("ptr must not be null (0)")
1543 cdef Descr obj = Descr.__new__(Descr)
1544 cdef flag = _cyb_cpython_buffer.PyBUF_READ if readonly else _cyb_cpython_buffer.PyBUF_WRITE
1545 cdef object buf = _cyb_cpython_memoryview.PyMemoryView_FromMemory(
1546 <char*>ptr, sizeof(CUfileDescr_t) * size, flag)
1547 data = _numpy.ndarray(size, buffer=buf, dtype=descr_dtype)
1548 obj._data = data.view(_numpy.recarray)
1549 obj._owner = owner
1551 return obj
1554cdef _get__py_anon_pod2_dtype_offsets():
1555 cdef cuda_bindings_cufile__anon_pod2 pod
1556 return _numpy.dtype({
1557 'names': ['batch'],
1558 'formats': [_py_anon_pod3_dtype],
1559 'offsets': [
1560 (<intptr_t>&(pod.batch)) - (<intptr_t>&pod),
1561 ],
1562 'itemsize': sizeof(cuda_bindings_cufile__anon_pod2),
1563 })
1565_py_anon_pod2_dtype = _get__py_anon_pod2_dtype_offsets()
1567cdef class _py_anon_pod2:
1568 """Empty-initialize an instance of `cuda_bindings_cufile__anon_pod2`.
1571 .. seealso:: `cuda_bindings_cufile__anon_pod2`
1572 """
1573 cdef:
1574 cuda_bindings_cufile__anon_pod2 *_ptr
1575 object _owner
1576 bint _owns_ptr
1577 bint _readonly
1579 def __init__(self):
1580 self._ptr = <cuda_bindings_cufile__anon_pod2 *>_cyb_calloc(1, sizeof(cuda_bindings_cufile__anon_pod2))
1581 if self._ptr == NULL:
1582 raise MemoryError("Error allocating _py_anon_pod2")
1583 self._owns_ptr = True
1584 self._owner = None
1585 self._readonly = False
1587 def __dealloc__(self):
1588 cdef cuda_bindings_cufile__anon_pod2 *ptr
1589 if self._owns_ptr and self._ptr != NULL:
1590 ptr = self._ptr
1591 self._ptr = NULL
1592 _cyb_free(ptr)
1594 def __repr__(self):
1595 return f"<{__name__}._py_anon_pod2 object at {hex(id(self))}>"
1597 @property
1598 def ptr(self):
1599 """Get the pointer address to the data as Python :class:`int`."""
1600 return <intptr_t>(self._ptr)
1602 cdef intptr_t _get_ptr(self):
1603 return <intptr_t>(self._ptr)
1605 def __int__(self):
1606 return <intptr_t>(self._ptr)
1608 def __eq__(self, other):
1609 cdef _py_anon_pod2 other_
1610 if not isinstance(other, _py_anon_pod2):
1611 return False
1612 other_ = other
1613 return (_cyb_memcmp(<void *><intptr_t>(self._ptr), <void *><intptr_t>(other_._ptr), sizeof(cuda_bindings_cufile__anon_pod2)) == 0)
1615 def __getbuffer__(self, _cyb_cpython.Py_buffer *buffer, int flags):
1616 _cyb___getbuffer(self, buffer, <void *>self._ptr, sizeof(cuda_bindings_cufile__anon_pod2), self._readonly)
1618 def __releasebuffer__(self, Py_buffer *buffer):
1619 pass
1621 def __setitem__(self, key, val):
1622 cdef _cyb_Py_buffer view
1623 if key == 0:
1624 if self._readonly:
1625 raise ValueError("This _py_anon_pod2 instance is read-only")
1626 _cyb_PyObject_GetBuffer(val, &view, _cyb_PyBUF_SIMPLE)
1627 try:
1628 if <size_t>view.len < sizeof(cuda_bindings_cufile__anon_pod2):
1629 raise ValueError(
1630 "source buffer too small: expected at least %d bytes, got %d" % (sizeof(cuda_bindings_cufile__anon_pod2), view.len)
1631 )
1632 _cyb_memmove(<void*>self._ptr, view.buf, sizeof(cuda_bindings_cufile__anon_pod2))
1633 self._readonly = view.readonly != 0
1634 finally:
1635 _cyb_PyBuffer_Release(&view)
1636 else:
1637 setattr(self, key, val)
1639 @property
1640 def batch(self):
1641 """_py_anon_pod3: """
1642 return _py_anon_pod3.from_ptr(
1643 <intptr_t>&(self._ptr[0].batch),
1644 readonly=self._readonly,
1645 owner=self,
1646 )
1648 @batch.setter
1649 def batch(self, val):
1650 if self._readonly:
1651 raise ValueError("This _py_anon_pod2 instance is read-only")
1652 cdef _py_anon_pod3 val_ = val
1653 _cyb_memcpy(<void *>&(self._ptr[0].batch), <void *>(val_._get_ptr()), sizeof(cuda_bindings_cufile__anon_pod3) * 1)
1655 @staticmethod
1656 def from_buffer(buffer):
1657 """Create an _py_anon_pod2 instance with the memory from the given buffer."""
1658 return _cyb_from_buffer(buffer, sizeof(cuda_bindings_cufile__anon_pod2), _py_anon_pod2)
1660 @staticmethod
1661 def from_data(data):
1662 """Create an _py_anon_pod2 instance wrapping the given NumPy array.
1664 Args:
1665 data (_numpy.ndarray): a single-element array of dtype `_py_anon_pod2_dtype` holding the data.
1666 """
1667 return _cyb_from_data(data, "_py_anon_pod2_dtype", _py_anon_pod2_dtype, _py_anon_pod2)
1669 @staticmethod
1670 def from_ptr(intptr_t ptr, bint readonly=False, object owner=None):
1671 """Create an _py_anon_pod2 instance wrapping the given pointer.
1673 Args:
1674 ptr (intptr_t): pointer address as Python :class:`int` to the data.
1675 owner (object): The Python object that owns the pointer. If not provided, data will be copied.
1676 readonly (bool): whether the data is read-only (to the user). default is `False`.
1677 """
1678 if ptr == 0:
1679 raise ValueError("ptr must not be null (0)")
1680 cdef _py_anon_pod2 obj = _py_anon_pod2.__new__(_py_anon_pod2)
1681 if owner is None:
1682 obj._ptr = <cuda_bindings_cufile__anon_pod2 *>_cyb_malloc(sizeof(cuda_bindings_cufile__anon_pod2))
1683 if obj._ptr == NULL:
1684 raise MemoryError("Error allocating _py_anon_pod2")
1685 _cyb_memcpy(<void*>(obj._ptr), <void*>ptr, sizeof(cuda_bindings_cufile__anon_pod2))
1686 obj._owns_ptr = True
1687 obj._owner = None
1688 else:
1689 obj._ptr = <cuda_bindings_cufile__anon_pod2 *>ptr
1690 obj._owns_ptr = False
1691 obj._owner = owner
1692 obj._readonly = readonly
1693 return obj
1696cdef _get_stats_level1_dtype_offsets():
1697 cdef CUfileStatsLevel1_t pod
1698 return _numpy.dtype({
1699 'names': ['read_ops', 'write_ops', 'hdl_register_ops', 'hdl_deregister_ops', 'buf_register_ops', 'buf_deregister_ops', 'read_bytes', 'write_bytes', 'read_bw_bytes_per_sec', 'write_bw_bytes_per_sec', 'read_lat_avg_us', 'write_lat_avg_us', 'read_ops_per_sec', 'write_ops_per_sec', 'read_lat_sum_us', 'write_lat_sum_us', 'batch_submit_ops', 'batch_complete_ops', 'batch_setup_ops', 'batch_cancel_ops', 'batch_destroy_ops', 'batch_enqueued_ops', 'batch_posix_enqueued_ops', 'batch_processed_ops', 'batch_posix_processed_ops', 'batch_nvfs_submit_ops', 'batch_p2p_submit_ops', 'batch_aio_submit_ops', 'batch_iouring_submit_ops', 'batch_mixed_io_submit_ops', 'batch_total_submit_ops', 'batch_read_bytes', 'batch_write_bytes', 'batch_read_bw_bytes', 'batch_write_bw_bytes', 'batch_submit_lat_avg_us', 'batch_completion_lat_avg_us', 'batch_submit_ops_per_sec', 'batch_complete_ops_per_sec', 'batch_submit_lat_sum_us', 'batch_completion_lat_sum_us', 'last_batch_read_bytes', 'last_batch_write_bytes', 'readv_ops', 'writev_ops', 'readv_bytes', 'writev_bytes', 'readv_bw_bytes_per_sec', 'writev_bw_bytes_per_sec', 'readv_lat_avg_us', 'writev_lat_avg_us', 'readv_ops_per_sec', 'writev_ops_per_sec', 'readv_lat_sum_us', 'writev_lat_sum_us'],
1700 'formats': [op_counter_dtype, op_counter_dtype, op_counter_dtype, op_counter_dtype, op_counter_dtype, op_counter_dtype, _numpy.uint64, _numpy.uint64, _numpy.uint64, _numpy.uint64, _numpy.uint64, _numpy.uint64, _numpy.uint64, _numpy.uint64, _numpy.uint64, _numpy.uint64, op_counter_dtype, op_counter_dtype, op_counter_dtype, op_counter_dtype, op_counter_dtype, op_counter_dtype, op_counter_dtype, op_counter_dtype, op_counter_dtype, op_counter_dtype, op_counter_dtype, op_counter_dtype, op_counter_dtype, op_counter_dtype, op_counter_dtype, _numpy.uint64, _numpy.uint64, _numpy.uint64, _numpy.uint64, _numpy.uint64, _numpy.uint64, _numpy.uint64, _numpy.uint64, _numpy.uint64, _numpy.uint64, _numpy.uint64, _numpy.uint64, op_counter_dtype, op_counter_dtype, _numpy.uint64, _numpy.uint64, _numpy.uint64, _numpy.uint64, _numpy.uint64, _numpy.uint64, _numpy.uint64, _numpy.uint64, _numpy.uint64, _numpy.uint64],
1701 'offsets': [
1702 (<intptr_t>&(pod.read_ops)) - (<intptr_t>&pod),
1703 (<intptr_t>&(pod.write_ops)) - (<intptr_t>&pod),
1704 (<intptr_t>&(pod.hdl_register_ops)) - (<intptr_t>&pod),
1705 (<intptr_t>&(pod.hdl_deregister_ops)) - (<intptr_t>&pod),
1706 (<intptr_t>&(pod.buf_register_ops)) - (<intptr_t>&pod),
1707 (<intptr_t>&(pod.buf_deregister_ops)) - (<intptr_t>&pod),
1708 (<intptr_t>&(pod.read_bytes)) - (<intptr_t>&pod),
1709 (<intptr_t>&(pod.write_bytes)) - (<intptr_t>&pod),
1710 (<intptr_t>&(pod.read_bw_bytes_per_sec)) - (<intptr_t>&pod),
1711 (<intptr_t>&(pod.write_bw_bytes_per_sec)) - (<intptr_t>&pod),
1712 (<intptr_t>&(pod.read_lat_avg_us)) - (<intptr_t>&pod),
1713 (<intptr_t>&(pod.write_lat_avg_us)) - (<intptr_t>&pod),
1714 (<intptr_t>&(pod.read_ops_per_sec)) - (<intptr_t>&pod),
1715 (<intptr_t>&(pod.write_ops_per_sec)) - (<intptr_t>&pod),
1716 (<intptr_t>&(pod.read_lat_sum_us)) - (<intptr_t>&pod),
1717 (<intptr_t>&(pod.write_lat_sum_us)) - (<intptr_t>&pod),
1718 (<intptr_t>&(pod.batch_submit_ops)) - (<intptr_t>&pod),
1719 (<intptr_t>&(pod.batch_complete_ops)) - (<intptr_t>&pod),
1720 (<intptr_t>&(pod.batch_setup_ops)) - (<intptr_t>&pod),
1721 (<intptr_t>&(pod.batch_cancel_ops)) - (<intptr_t>&pod),
1722 (<intptr_t>&(pod.batch_destroy_ops)) - (<intptr_t>&pod),
1723 (<intptr_t>&(pod.batch_enqueued_ops)) - (<intptr_t>&pod),
1724 (<intptr_t>&(pod.batch_posix_enqueued_ops)) - (<intptr_t>&pod),
1725 (<intptr_t>&(pod.batch_processed_ops)) - (<intptr_t>&pod),
1726 (<intptr_t>&(pod.batch_posix_processed_ops)) - (<intptr_t>&pod),
1727 (<intptr_t>&(pod.batch_nvfs_submit_ops)) - (<intptr_t>&pod),
1728 (<intptr_t>&(pod.batch_p2p_submit_ops)) - (<intptr_t>&pod),
1729 (<intptr_t>&(pod.batch_aio_submit_ops)) - (<intptr_t>&pod),
1730 (<intptr_t>&(pod.batch_iouring_submit_ops)) - (<intptr_t>&pod),
1731 (<intptr_t>&(pod.batch_mixed_io_submit_ops)) - (<intptr_t>&pod),
1732 (<intptr_t>&(pod.batch_total_submit_ops)) - (<intptr_t>&pod),
1733 (<intptr_t>&(pod.batch_read_bytes)) - (<intptr_t>&pod),
1734 (<intptr_t>&(pod.batch_write_bytes)) - (<intptr_t>&pod),
1735 (<intptr_t>&(pod.batch_read_bw_bytes)) - (<intptr_t>&pod),
1736 (<intptr_t>&(pod.batch_write_bw_bytes)) - (<intptr_t>&pod),
1737 (<intptr_t>&(pod.batch_submit_lat_avg_us)) - (<intptr_t>&pod),
1738 (<intptr_t>&(pod.batch_completion_lat_avg_us)) - (<intptr_t>&pod),
1739 (<intptr_t>&(pod.batch_submit_ops_per_sec)) - (<intptr_t>&pod),
1740 (<intptr_t>&(pod.batch_complete_ops_per_sec)) - (<intptr_t>&pod),
1741 (<intptr_t>&(pod.batch_submit_lat_sum_us)) - (<intptr_t>&pod),
1742 (<intptr_t>&(pod.batch_completion_lat_sum_us)) - (<intptr_t>&pod),
1743 (<intptr_t>&(pod.last_batch_read_bytes)) - (<intptr_t>&pod),
1744 (<intptr_t>&(pod.last_batch_write_bytes)) - (<intptr_t>&pod),
1745 (<intptr_t>&(pod.readv_ops)) - (<intptr_t>&pod),
1746 (<intptr_t>&(pod.writev_ops)) - (<intptr_t>&pod),
1747 (<intptr_t>&(pod.readv_bytes)) - (<intptr_t>&pod),
1748 (<intptr_t>&(pod.writev_bytes)) - (<intptr_t>&pod),
1749 (<intptr_t>&(pod.readv_bw_bytes_per_sec)) - (<intptr_t>&pod),
1750 (<intptr_t>&(pod.writev_bw_bytes_per_sec)) - (<intptr_t>&pod),
1751 (<intptr_t>&(pod.readv_lat_avg_us)) - (<intptr_t>&pod),
1752 (<intptr_t>&(pod.writev_lat_avg_us)) - (<intptr_t>&pod),
1753 (<intptr_t>&(pod.readv_ops_per_sec)) - (<intptr_t>&pod),
1754 (<intptr_t>&(pod.writev_ops_per_sec)) - (<intptr_t>&pod),
1755 (<intptr_t>&(pod.readv_lat_sum_us)) - (<intptr_t>&pod),
1756 (<intptr_t>&(pod.writev_lat_sum_us)) - (<intptr_t>&pod),
1757 ],
1758 'itemsize': sizeof(CUfileStatsLevel1_t),
1759 })
1761stats_level1_dtype = _get_stats_level1_dtype_offsets()
1763cdef class StatsLevel1:
1764 """Empty-initialize an instance of `CUfileStatsLevel1_t`.
1767 .. seealso:: `CUfileStatsLevel1_t`
1768 """
1769 cdef:
1770 CUfileStatsLevel1_t *_ptr
1771 object _owner
1772 bint _owns_ptr
1773 bint _readonly
1775 def __init__(self):
1776 self._ptr = <CUfileStatsLevel1_t *>_cyb_calloc(1, sizeof(CUfileStatsLevel1_t)) 1e
1777 if self._ptr == NULL: 1e
1778 raise MemoryError("Error allocating StatsLevel1")
1779 self._owns_ptr = True 1e
1780 self._owner = None 1e
1781 self._readonly = False 1e
1783 def __dealloc__(self):
1784 cdef CUfileStatsLevel1_t *ptr
1785 if self._owns_ptr and self._ptr != NULL: 1eb
1786 ptr = self._ptr 1e
1787 self._ptr = NULL 1e
1788 _cyb_free(ptr) 1e
1790 def __repr__(self):
1791 return f"<{__name__}.StatsLevel1 object at {hex(id(self))}>"
1793 @property
1794 def ptr(self):
1795 """Get the pointer address to the data as Python :class:`int`."""
1796 return <intptr_t>(self._ptr) 1e
1798 cdef intptr_t _get_ptr(self):
1799 return <intptr_t>(self._ptr)
1801 def __int__(self):
1802 return <intptr_t>(self._ptr)
1804 def __eq__(self, other):
1805 cdef StatsLevel1 other_
1806 if not isinstance(other, StatsLevel1):
1807 return False
1808 other_ = other
1809 return (_cyb_memcmp(<void *><intptr_t>(self._ptr), <void *><intptr_t>(other_._ptr), sizeof(CUfileStatsLevel1_t)) == 0)
1811 def __getbuffer__(self, _cyb_cpython.Py_buffer *buffer, int flags):
1812 _cyb___getbuffer(self, buffer, <void *>self._ptr, sizeof(CUfileStatsLevel1_t), self._readonly)
1814 def __releasebuffer__(self, Py_buffer *buffer):
1815 pass
1817 def __setitem__(self, key, val):
1818 cdef _cyb_Py_buffer view
1819 if key == 0:
1820 if self._readonly:
1821 raise ValueError("This StatsLevel1 instance is read-only")
1822 _cyb_PyObject_GetBuffer(val, &view, _cyb_PyBUF_SIMPLE)
1823 try:
1824 if <size_t>view.len < sizeof(CUfileStatsLevel1_t):
1825 raise ValueError(
1826 "source buffer too small: expected at least %d bytes, got %d" % (sizeof(CUfileStatsLevel1_t), view.len)
1827 )
1828 _cyb_memmove(<void*>self._ptr, view.buf, sizeof(CUfileStatsLevel1_t))
1829 self._readonly = view.readonly != 0
1830 finally:
1831 _cyb_PyBuffer_Release(&view)
1832 else:
1833 setattr(self, key, val)
1835 @property
1836 def read_ops(self):
1837 """OpCounter: """
1838 return OpCounter.from_ptr( 1eb
1839 <intptr_t>&(self._ptr[0].read_ops), 1eb
1840 readonly=self._readonly, 1eb
1841 owner=self, 1eb
1842 )
1844 @read_ops.setter
1845 def read_ops(self, val):
1846 if self._readonly:
1847 raise ValueError("This StatsLevel1 instance is read-only")
1848 cdef OpCounter val_ = val
1849 _cyb_memcpy(<void *>&(self._ptr[0].read_ops), <void *>(val_._get_ptr()), sizeof(CUfileOpCounter_t) * 1)
1851 @property
1852 def write_ops(self):
1853 """OpCounter: """
1854 return OpCounter.from_ptr( 1eb
1855 <intptr_t>&(self._ptr[0].write_ops), 1eb
1856 readonly=self._readonly, 1eb
1857 owner=self, 1eb
1858 )
1860 @write_ops.setter
1861 def write_ops(self, val):
1862 if self._readonly:
1863 raise ValueError("This StatsLevel1 instance is read-only")
1864 cdef OpCounter val_ = val
1865 _cyb_memcpy(<void *>&(self._ptr[0].write_ops), <void *>(val_._get_ptr()), sizeof(CUfileOpCounter_t) * 1)
1867 @property
1868 def hdl_register_ops(self):
1869 """OpCounter: """
1870 return OpCounter.from_ptr(
1871 <intptr_t>&(self._ptr[0].hdl_register_ops),
1872 readonly=self._readonly,
1873 owner=self,
1874 )
1876 @hdl_register_ops.setter
1877 def hdl_register_ops(self, val):
1878 if self._readonly:
1879 raise ValueError("This StatsLevel1 instance is read-only")
1880 cdef OpCounter val_ = val
1881 _cyb_memcpy(<void *>&(self._ptr[0].hdl_register_ops), <void *>(val_._get_ptr()), sizeof(CUfileOpCounter_t) * 1)
1883 @property
1884 def hdl_deregister_ops(self):
1885 """OpCounter: """
1886 return OpCounter.from_ptr(
1887 <intptr_t>&(self._ptr[0].hdl_deregister_ops),
1888 readonly=self._readonly,
1889 owner=self,
1890 )
1892 @hdl_deregister_ops.setter
1893 def hdl_deregister_ops(self, val):
1894 if self._readonly:
1895 raise ValueError("This StatsLevel1 instance is read-only")
1896 cdef OpCounter val_ = val
1897 _cyb_memcpy(<void *>&(self._ptr[0].hdl_deregister_ops), <void *>(val_._get_ptr()), sizeof(CUfileOpCounter_t) * 1)
1899 @property
1900 def buf_register_ops(self):
1901 """OpCounter: """
1902 return OpCounter.from_ptr(
1903 <intptr_t>&(self._ptr[0].buf_register_ops),
1904 readonly=self._readonly,
1905 owner=self,
1906 )
1908 @buf_register_ops.setter
1909 def buf_register_ops(self, val):
1910 if self._readonly:
1911 raise ValueError("This StatsLevel1 instance is read-only")
1912 cdef OpCounter val_ = val
1913 _cyb_memcpy(<void *>&(self._ptr[0].buf_register_ops), <void *>(val_._get_ptr()), sizeof(CUfileOpCounter_t) * 1)
1915 @property
1916 def buf_deregister_ops(self):
1917 """OpCounter: """
1918 return OpCounter.from_ptr(
1919 <intptr_t>&(self._ptr[0].buf_deregister_ops),
1920 readonly=self._readonly,
1921 owner=self,
1922 )
1924 @buf_deregister_ops.setter
1925 def buf_deregister_ops(self, val):
1926 if self._readonly:
1927 raise ValueError("This StatsLevel1 instance is read-only")
1928 cdef OpCounter val_ = val
1929 _cyb_memcpy(<void *>&(self._ptr[0].buf_deregister_ops), <void *>(val_._get_ptr()), sizeof(CUfileOpCounter_t) * 1)
1931 @property
1932 def batch_submit_ops(self):
1933 """OpCounter: """
1934 return OpCounter.from_ptr(
1935 <intptr_t>&(self._ptr[0].batch_submit_ops),
1936 readonly=self._readonly,
1937 owner=self,
1938 )
1940 @batch_submit_ops.setter
1941 def batch_submit_ops(self, val):
1942 if self._readonly:
1943 raise ValueError("This StatsLevel1 instance is read-only")
1944 cdef OpCounter val_ = val
1945 _cyb_memcpy(<void *>&(self._ptr[0].batch_submit_ops), <void *>(val_._get_ptr()), sizeof(CUfileOpCounter_t) * 1)
1947 @property
1948 def batch_complete_ops(self):
1949 """OpCounter: """
1950 return OpCounter.from_ptr(
1951 <intptr_t>&(self._ptr[0].batch_complete_ops),
1952 readonly=self._readonly,
1953 owner=self,
1954 )
1956 @batch_complete_ops.setter
1957 def batch_complete_ops(self, val):
1958 if self._readonly:
1959 raise ValueError("This StatsLevel1 instance is read-only")
1960 cdef OpCounter val_ = val
1961 _cyb_memcpy(<void *>&(self._ptr[0].batch_complete_ops), <void *>(val_._get_ptr()), sizeof(CUfileOpCounter_t) * 1)
1963 @property
1964 def batch_setup_ops(self):
1965 """OpCounter: """
1966 return OpCounter.from_ptr(
1967 <intptr_t>&(self._ptr[0].batch_setup_ops),
1968 readonly=self._readonly,
1969 owner=self,
1970 )
1972 @batch_setup_ops.setter
1973 def batch_setup_ops(self, val):
1974 if self._readonly:
1975 raise ValueError("This StatsLevel1 instance is read-only")
1976 cdef OpCounter val_ = val
1977 _cyb_memcpy(<void *>&(self._ptr[0].batch_setup_ops), <void *>(val_._get_ptr()), sizeof(CUfileOpCounter_t) * 1)
1979 @property
1980 def batch_cancel_ops(self):
1981 """OpCounter: """
1982 return OpCounter.from_ptr(
1983 <intptr_t>&(self._ptr[0].batch_cancel_ops),
1984 readonly=self._readonly,
1985 owner=self,
1986 )
1988 @batch_cancel_ops.setter
1989 def batch_cancel_ops(self, val):
1990 if self._readonly:
1991 raise ValueError("This StatsLevel1 instance is read-only")
1992 cdef OpCounter val_ = val
1993 _cyb_memcpy(<void *>&(self._ptr[0].batch_cancel_ops), <void *>(val_._get_ptr()), sizeof(CUfileOpCounter_t) * 1)
1995 @property
1996 def batch_destroy_ops(self):
1997 """OpCounter: """
1998 return OpCounter.from_ptr(
1999 <intptr_t>&(self._ptr[0].batch_destroy_ops),
2000 readonly=self._readonly,
2001 owner=self,
2002 )
2004 @batch_destroy_ops.setter
2005 def batch_destroy_ops(self, val):
2006 if self._readonly:
2007 raise ValueError("This StatsLevel1 instance is read-only")
2008 cdef OpCounter val_ = val
2009 _cyb_memcpy(<void *>&(self._ptr[0].batch_destroy_ops), <void *>(val_._get_ptr()), sizeof(CUfileOpCounter_t) * 1)
2011 @property
2012 def batch_enqueued_ops(self):
2013 """OpCounter: """
2014 return OpCounter.from_ptr(
2015 <intptr_t>&(self._ptr[0].batch_enqueued_ops),
2016 readonly=self._readonly,
2017 owner=self,
2018 )
2020 @batch_enqueued_ops.setter
2021 def batch_enqueued_ops(self, val):
2022 if self._readonly:
2023 raise ValueError("This StatsLevel1 instance is read-only")
2024 cdef OpCounter val_ = val
2025 _cyb_memcpy(<void *>&(self._ptr[0].batch_enqueued_ops), <void *>(val_._get_ptr()), sizeof(CUfileOpCounter_t) * 1)
2027 @property
2028 def batch_posix_enqueued_ops(self):
2029 """OpCounter: """
2030 return OpCounter.from_ptr(
2031 <intptr_t>&(self._ptr[0].batch_posix_enqueued_ops),
2032 readonly=self._readonly,
2033 owner=self,
2034 )
2036 @batch_posix_enqueued_ops.setter
2037 def batch_posix_enqueued_ops(self, val):
2038 if self._readonly:
2039 raise ValueError("This StatsLevel1 instance is read-only")
2040 cdef OpCounter val_ = val
2041 _cyb_memcpy(<void *>&(self._ptr[0].batch_posix_enqueued_ops), <void *>(val_._get_ptr()), sizeof(CUfileOpCounter_t) * 1)
2043 @property
2044 def batch_processed_ops(self):
2045 """OpCounter: """
2046 return OpCounter.from_ptr(
2047 <intptr_t>&(self._ptr[0].batch_processed_ops),
2048 readonly=self._readonly,
2049 owner=self,
2050 )
2052 @batch_processed_ops.setter
2053 def batch_processed_ops(self, val):
2054 if self._readonly:
2055 raise ValueError("This StatsLevel1 instance is read-only")
2056 cdef OpCounter val_ = val
2057 _cyb_memcpy(<void *>&(self._ptr[0].batch_processed_ops), <void *>(val_._get_ptr()), sizeof(CUfileOpCounter_t) * 1)
2059 @property
2060 def batch_posix_processed_ops(self):
2061 """OpCounter: """
2062 return OpCounter.from_ptr(
2063 <intptr_t>&(self._ptr[0].batch_posix_processed_ops),
2064 readonly=self._readonly,
2065 owner=self,
2066 )
2068 @batch_posix_processed_ops.setter
2069 def batch_posix_processed_ops(self, val):
2070 if self._readonly:
2071 raise ValueError("This StatsLevel1 instance is read-only")
2072 cdef OpCounter val_ = val
2073 _cyb_memcpy(<void *>&(self._ptr[0].batch_posix_processed_ops), <void *>(val_._get_ptr()), sizeof(CUfileOpCounter_t) * 1)
2075 @property
2076 def batch_nvfs_submit_ops(self):
2077 """OpCounter: """
2078 return OpCounter.from_ptr(
2079 <intptr_t>&(self._ptr[0].batch_nvfs_submit_ops),
2080 readonly=self._readonly,
2081 owner=self,
2082 )
2084 @batch_nvfs_submit_ops.setter
2085 def batch_nvfs_submit_ops(self, val):
2086 if self._readonly:
2087 raise ValueError("This StatsLevel1 instance is read-only")
2088 cdef OpCounter val_ = val
2089 _cyb_memcpy(<void *>&(self._ptr[0].batch_nvfs_submit_ops), <void *>(val_._get_ptr()), sizeof(CUfileOpCounter_t) * 1)
2091 @property
2092 def batch_p2p_submit_ops(self):
2093 """OpCounter: """
2094 return OpCounter.from_ptr(
2095 <intptr_t>&(self._ptr[0].batch_p2p_submit_ops),
2096 readonly=self._readonly,
2097 owner=self,
2098 )
2100 @batch_p2p_submit_ops.setter
2101 def batch_p2p_submit_ops(self, val):
2102 if self._readonly:
2103 raise ValueError("This StatsLevel1 instance is read-only")
2104 cdef OpCounter val_ = val
2105 _cyb_memcpy(<void *>&(self._ptr[0].batch_p2p_submit_ops), <void *>(val_._get_ptr()), sizeof(CUfileOpCounter_t) * 1)
2107 @property
2108 def batch_aio_submit_ops(self):
2109 """OpCounter: """
2110 return OpCounter.from_ptr(
2111 <intptr_t>&(self._ptr[0].batch_aio_submit_ops),
2112 readonly=self._readonly,
2113 owner=self,
2114 )
2116 @batch_aio_submit_ops.setter
2117 def batch_aio_submit_ops(self, val):
2118 if self._readonly:
2119 raise ValueError("This StatsLevel1 instance is read-only")
2120 cdef OpCounter val_ = val
2121 _cyb_memcpy(<void *>&(self._ptr[0].batch_aio_submit_ops), <void *>(val_._get_ptr()), sizeof(CUfileOpCounter_t) * 1)
2123 @property
2124 def batch_iouring_submit_ops(self):
2125 """OpCounter: """
2126 return OpCounter.from_ptr(
2127 <intptr_t>&(self._ptr[0].batch_iouring_submit_ops),
2128 readonly=self._readonly,
2129 owner=self,
2130 )
2132 @batch_iouring_submit_ops.setter
2133 def batch_iouring_submit_ops(self, val):
2134 if self._readonly:
2135 raise ValueError("This StatsLevel1 instance is read-only")
2136 cdef OpCounter val_ = val
2137 _cyb_memcpy(<void *>&(self._ptr[0].batch_iouring_submit_ops), <void *>(val_._get_ptr()), sizeof(CUfileOpCounter_t) * 1)
2139 @property
2140 def batch_mixed_io_submit_ops(self):
2141 """OpCounter: """
2142 return OpCounter.from_ptr(
2143 <intptr_t>&(self._ptr[0].batch_mixed_io_submit_ops),
2144 readonly=self._readonly,
2145 owner=self,
2146 )
2148 @batch_mixed_io_submit_ops.setter
2149 def batch_mixed_io_submit_ops(self, val):
2150 if self._readonly:
2151 raise ValueError("This StatsLevel1 instance is read-only")
2152 cdef OpCounter val_ = val
2153 _cyb_memcpy(<void *>&(self._ptr[0].batch_mixed_io_submit_ops), <void *>(val_._get_ptr()), sizeof(CUfileOpCounter_t) * 1)
2155 @property
2156 def batch_total_submit_ops(self):
2157 """OpCounter: """
2158 return OpCounter.from_ptr(
2159 <intptr_t>&(self._ptr[0].batch_total_submit_ops),
2160 readonly=self._readonly,
2161 owner=self,
2162 )
2164 @batch_total_submit_ops.setter
2165 def batch_total_submit_ops(self, val):
2166 if self._readonly:
2167 raise ValueError("This StatsLevel1 instance is read-only")
2168 cdef OpCounter val_ = val
2169 _cyb_memcpy(<void *>&(self._ptr[0].batch_total_submit_ops), <void *>(val_._get_ptr()), sizeof(CUfileOpCounter_t) * 1)
2171 @property
2172 def readv_ops(self):
2173 """OpCounter: """
2174 return OpCounter.from_ptr(
2175 <intptr_t>&(self._ptr[0].readv_ops),
2176 readonly=self._readonly,
2177 owner=self,
2178 )
2180 @readv_ops.setter
2181 def readv_ops(self, val):
2182 if self._readonly:
2183 raise ValueError("This StatsLevel1 instance is read-only")
2184 cdef OpCounter val_ = val
2185 _cyb_memcpy(<void *>&(self._ptr[0].readv_ops), <void *>(val_._get_ptr()), sizeof(CUfileOpCounter_t) * 1)
2187 @property
2188 def writev_ops(self):
2189 """OpCounter: """
2190 return OpCounter.from_ptr(
2191 <intptr_t>&(self._ptr[0].writev_ops),
2192 readonly=self._readonly,
2193 owner=self,
2194 )
2196 @writev_ops.setter
2197 def writev_ops(self, val):
2198 if self._readonly:
2199 raise ValueError("This StatsLevel1 instance is read-only")
2200 cdef OpCounter val_ = val
2201 _cyb_memcpy(<void *>&(self._ptr[0].writev_ops), <void *>(val_._get_ptr()), sizeof(CUfileOpCounter_t) * 1)
2203 @property
2204 def read_bytes(self):
2205 """int: """
2206 return self._ptr[0].read_bytes 1e
2208 @read_bytes.setter
2209 def read_bytes(self, val):
2210 if self._readonly:
2211 raise ValueError("This StatsLevel1 instance is read-only")
2212 self._ptr[0].read_bytes = val
2214 @property
2215 def write_bytes(self):
2216 """int: """
2217 return self._ptr[0].write_bytes 1e
2219 @write_bytes.setter
2220 def write_bytes(self, val):
2221 if self._readonly:
2222 raise ValueError("This StatsLevel1 instance is read-only")
2223 self._ptr[0].write_bytes = val
2225 @property
2226 def read_bw_bytes_per_sec(self):
2227 """int: """
2228 return self._ptr[0].read_bw_bytes_per_sec
2230 @read_bw_bytes_per_sec.setter
2231 def read_bw_bytes_per_sec(self, val):
2232 if self._readonly:
2233 raise ValueError("This StatsLevel1 instance is read-only")
2234 self._ptr[0].read_bw_bytes_per_sec = val
2236 @property
2237 def write_bw_bytes_per_sec(self):
2238 """int: """
2239 return self._ptr[0].write_bw_bytes_per_sec
2241 @write_bw_bytes_per_sec.setter
2242 def write_bw_bytes_per_sec(self, val):
2243 if self._readonly:
2244 raise ValueError("This StatsLevel1 instance is read-only")
2245 self._ptr[0].write_bw_bytes_per_sec = val
2247 @property
2248 def read_lat_avg_us(self):
2249 """int: """
2250 return self._ptr[0].read_lat_avg_us
2252 @read_lat_avg_us.setter
2253 def read_lat_avg_us(self, val):
2254 if self._readonly:
2255 raise ValueError("This StatsLevel1 instance is read-only")
2256 self._ptr[0].read_lat_avg_us = val
2258 @property
2259 def write_lat_avg_us(self):
2260 """int: """
2261 return self._ptr[0].write_lat_avg_us
2263 @write_lat_avg_us.setter
2264 def write_lat_avg_us(self, val):
2265 if self._readonly:
2266 raise ValueError("This StatsLevel1 instance is read-only")
2267 self._ptr[0].write_lat_avg_us = val
2269 @property
2270 def read_ops_per_sec(self):
2271 """int: """
2272 return self._ptr[0].read_ops_per_sec
2274 @read_ops_per_sec.setter
2275 def read_ops_per_sec(self, val):
2276 if self._readonly:
2277 raise ValueError("This StatsLevel1 instance is read-only")
2278 self._ptr[0].read_ops_per_sec = val
2280 @property
2281 def write_ops_per_sec(self):
2282 """int: """
2283 return self._ptr[0].write_ops_per_sec
2285 @write_ops_per_sec.setter
2286 def write_ops_per_sec(self, val):
2287 if self._readonly:
2288 raise ValueError("This StatsLevel1 instance is read-only")
2289 self._ptr[0].write_ops_per_sec = val
2291 @property
2292 def read_lat_sum_us(self):
2293 """int: """
2294 return self._ptr[0].read_lat_sum_us
2296 @read_lat_sum_us.setter
2297 def read_lat_sum_us(self, val):
2298 if self._readonly:
2299 raise ValueError("This StatsLevel1 instance is read-only")
2300 self._ptr[0].read_lat_sum_us = val
2302 @property
2303 def write_lat_sum_us(self):
2304 """int: """
2305 return self._ptr[0].write_lat_sum_us
2307 @write_lat_sum_us.setter
2308 def write_lat_sum_us(self, val):
2309 if self._readonly:
2310 raise ValueError("This StatsLevel1 instance is read-only")
2311 self._ptr[0].write_lat_sum_us = val
2313 @property
2314 def batch_read_bytes(self):
2315 """int: """
2316 return self._ptr[0].batch_read_bytes
2318 @batch_read_bytes.setter
2319 def batch_read_bytes(self, val):
2320 if self._readonly:
2321 raise ValueError("This StatsLevel1 instance is read-only")
2322 self._ptr[0].batch_read_bytes = val
2324 @property
2325 def batch_write_bytes(self):
2326 """int: """
2327 return self._ptr[0].batch_write_bytes
2329 @batch_write_bytes.setter
2330 def batch_write_bytes(self, val):
2331 if self._readonly:
2332 raise ValueError("This StatsLevel1 instance is read-only")
2333 self._ptr[0].batch_write_bytes = val
2335 @property
2336 def batch_read_bw_bytes(self):
2337 """int: """
2338 return self._ptr[0].batch_read_bw_bytes
2340 @batch_read_bw_bytes.setter
2341 def batch_read_bw_bytes(self, val):
2342 if self._readonly:
2343 raise ValueError("This StatsLevel1 instance is read-only")
2344 self._ptr[0].batch_read_bw_bytes = val
2346 @property
2347 def batch_write_bw_bytes(self):
2348 """int: """
2349 return self._ptr[0].batch_write_bw_bytes
2351 @batch_write_bw_bytes.setter
2352 def batch_write_bw_bytes(self, val):
2353 if self._readonly:
2354 raise ValueError("This StatsLevel1 instance is read-only")
2355 self._ptr[0].batch_write_bw_bytes = val
2357 @property
2358 def batch_submit_lat_avg_us(self):
2359 """int: """
2360 return self._ptr[0].batch_submit_lat_avg_us
2362 @batch_submit_lat_avg_us.setter
2363 def batch_submit_lat_avg_us(self, val):
2364 if self._readonly:
2365 raise ValueError("This StatsLevel1 instance is read-only")
2366 self._ptr[0].batch_submit_lat_avg_us = val
2368 @property
2369 def batch_completion_lat_avg_us(self):
2370 """int: """
2371 return self._ptr[0].batch_completion_lat_avg_us
2373 @batch_completion_lat_avg_us.setter
2374 def batch_completion_lat_avg_us(self, val):
2375 if self._readonly:
2376 raise ValueError("This StatsLevel1 instance is read-only")
2377 self._ptr[0].batch_completion_lat_avg_us = val
2379 @property
2380 def batch_submit_ops_per_sec(self):
2381 """int: """
2382 return self._ptr[0].batch_submit_ops_per_sec
2384 @batch_submit_ops_per_sec.setter
2385 def batch_submit_ops_per_sec(self, val):
2386 if self._readonly:
2387 raise ValueError("This StatsLevel1 instance is read-only")
2388 self._ptr[0].batch_submit_ops_per_sec = val
2390 @property
2391 def batch_complete_ops_per_sec(self):
2392 """int: """
2393 return self._ptr[0].batch_complete_ops_per_sec
2395 @batch_complete_ops_per_sec.setter
2396 def batch_complete_ops_per_sec(self, val):
2397 if self._readonly:
2398 raise ValueError("This StatsLevel1 instance is read-only")
2399 self._ptr[0].batch_complete_ops_per_sec = val
2401 @property
2402 def batch_submit_lat_sum_us(self):
2403 """int: """
2404 return self._ptr[0].batch_submit_lat_sum_us
2406 @batch_submit_lat_sum_us.setter
2407 def batch_submit_lat_sum_us(self, val):
2408 if self._readonly:
2409 raise ValueError("This StatsLevel1 instance is read-only")
2410 self._ptr[0].batch_submit_lat_sum_us = val
2412 @property
2413 def batch_completion_lat_sum_us(self):
2414 """int: """
2415 return self._ptr[0].batch_completion_lat_sum_us
2417 @batch_completion_lat_sum_us.setter
2418 def batch_completion_lat_sum_us(self, val):
2419 if self._readonly:
2420 raise ValueError("This StatsLevel1 instance is read-only")
2421 self._ptr[0].batch_completion_lat_sum_us = val
2423 @property
2424 def last_batch_read_bytes(self):
2425 """int: """
2426 return self._ptr[0].last_batch_read_bytes
2428 @last_batch_read_bytes.setter
2429 def last_batch_read_bytes(self, val):
2430 if self._readonly:
2431 raise ValueError("This StatsLevel1 instance is read-only")
2432 self._ptr[0].last_batch_read_bytes = val
2434 @property
2435 def last_batch_write_bytes(self):
2436 """int: """
2437 return self._ptr[0].last_batch_write_bytes
2439 @last_batch_write_bytes.setter
2440 def last_batch_write_bytes(self, val):
2441 if self._readonly:
2442 raise ValueError("This StatsLevel1 instance is read-only")
2443 self._ptr[0].last_batch_write_bytes = val
2445 @property
2446 def readv_bytes(self):
2447 """int: """
2448 return self._ptr[0].readv_bytes
2450 @readv_bytes.setter
2451 def readv_bytes(self, val):
2452 if self._readonly:
2453 raise ValueError("This StatsLevel1 instance is read-only")
2454 self._ptr[0].readv_bytes = val
2456 @property
2457 def writev_bytes(self):
2458 """int: """
2459 return self._ptr[0].writev_bytes
2461 @writev_bytes.setter
2462 def writev_bytes(self, val):
2463 if self._readonly:
2464 raise ValueError("This StatsLevel1 instance is read-only")
2465 self._ptr[0].writev_bytes = val
2467 @property
2468 def readv_bw_bytes_per_sec(self):
2469 """int: """
2470 return self._ptr[0].readv_bw_bytes_per_sec
2472 @readv_bw_bytes_per_sec.setter
2473 def readv_bw_bytes_per_sec(self, val):
2474 if self._readonly:
2475 raise ValueError("This StatsLevel1 instance is read-only")
2476 self._ptr[0].readv_bw_bytes_per_sec = val
2478 @property
2479 def writev_bw_bytes_per_sec(self):
2480 """int: """
2481 return self._ptr[0].writev_bw_bytes_per_sec
2483 @writev_bw_bytes_per_sec.setter
2484 def writev_bw_bytes_per_sec(self, val):
2485 if self._readonly:
2486 raise ValueError("This StatsLevel1 instance is read-only")
2487 self._ptr[0].writev_bw_bytes_per_sec = val
2489 @property
2490 def readv_lat_avg_us(self):
2491 """int: """
2492 return self._ptr[0].readv_lat_avg_us
2494 @readv_lat_avg_us.setter
2495 def readv_lat_avg_us(self, val):
2496 if self._readonly:
2497 raise ValueError("This StatsLevel1 instance is read-only")
2498 self._ptr[0].readv_lat_avg_us = val
2500 @property
2501 def writev_lat_avg_us(self):
2502 """int: """
2503 return self._ptr[0].writev_lat_avg_us
2505 @writev_lat_avg_us.setter
2506 def writev_lat_avg_us(self, val):
2507 if self._readonly:
2508 raise ValueError("This StatsLevel1 instance is read-only")
2509 self._ptr[0].writev_lat_avg_us = val
2511 @property
2512 def readv_ops_per_sec(self):
2513 """int: """
2514 return self._ptr[0].readv_ops_per_sec
2516 @readv_ops_per_sec.setter
2517 def readv_ops_per_sec(self, val):
2518 if self._readonly:
2519 raise ValueError("This StatsLevel1 instance is read-only")
2520 self._ptr[0].readv_ops_per_sec = val
2522 @property
2523 def writev_ops_per_sec(self):
2524 """int: """
2525 return self._ptr[0].writev_ops_per_sec
2527 @writev_ops_per_sec.setter
2528 def writev_ops_per_sec(self, val):
2529 if self._readonly:
2530 raise ValueError("This StatsLevel1 instance is read-only")
2531 self._ptr[0].writev_ops_per_sec = val
2533 @property
2534 def readv_lat_sum_us(self):
2535 """int: """
2536 return self._ptr[0].readv_lat_sum_us
2538 @readv_lat_sum_us.setter
2539 def readv_lat_sum_us(self, val):
2540 if self._readonly:
2541 raise ValueError("This StatsLevel1 instance is read-only")
2542 self._ptr[0].readv_lat_sum_us = val
2544 @property
2545 def writev_lat_sum_us(self):
2546 """int: """
2547 return self._ptr[0].writev_lat_sum_us
2549 @writev_lat_sum_us.setter
2550 def writev_lat_sum_us(self, val):
2551 if self._readonly:
2552 raise ValueError("This StatsLevel1 instance is read-only")
2553 self._ptr[0].writev_lat_sum_us = val
2555 @staticmethod
2556 def from_buffer(buffer):
2557 """Create an StatsLevel1 instance with the memory from the given buffer."""
2558 return _cyb_from_buffer(buffer, sizeof(CUfileStatsLevel1_t), StatsLevel1)
2560 @staticmethod
2561 def from_data(data):
2562 """Create an StatsLevel1 instance wrapping the given NumPy array.
2564 Args:
2565 data (_numpy.ndarray): a single-element array of dtype `stats_level1_dtype` holding the data.
2566 """
2567 return _cyb_from_data(data, "stats_level1_dtype", stats_level1_dtype, StatsLevel1) 1b
2569 @staticmethod
2570 def from_ptr(intptr_t ptr, bint readonly=False, object owner=None):
2571 """Create an StatsLevel1 instance wrapping the given pointer.
2573 Args:
2574 ptr (intptr_t): pointer address as Python :class:`int` to the data.
2575 owner (object): The Python object that owns the pointer. If not provided, data will be copied.
2576 readonly (bool): whether the data is read-only (to the user). default is `False`.
2577 """
2578 if ptr == 0: 1b
2579 raise ValueError("ptr must not be null (0)")
2580 cdef StatsLevel1 obj = StatsLevel1.__new__(StatsLevel1) 1b
2581 if owner is None: 1b
2582 obj._ptr = <CUfileStatsLevel1_t *>_cyb_malloc(sizeof(CUfileStatsLevel1_t))
2583 if obj._ptr == NULL:
2584 raise MemoryError("Error allocating StatsLevel1")
2585 _cyb_memcpy(<void*>(obj._ptr), <void*>ptr, sizeof(CUfileStatsLevel1_t))
2586 obj._owns_ptr = True
2587 obj._owner = None
2588 else:
2589 obj._ptr = <CUfileStatsLevel1_t *>ptr 1b
2590 obj._owns_ptr = False 1b
2591 obj._owner = owner 1b
2592 obj._readonly = readonly 1b
2593 return obj 1b
2596cdef _get_io_params_dtype_offsets():
2597 cdef CUfileIOParams_t pod
2598 return _numpy.dtype({
2599 'names': ['mode', 'u', 'fh', 'opcode', 'cookie'],
2600 'formats': [_numpy.int32, _py_anon_pod2_dtype, _numpy.intp, _numpy.int32, _numpy.intp],
2601 'offsets': [
2602 (<intptr_t>&(pod.mode)) - (<intptr_t>&pod),
2603 (<intptr_t>&(pod.u)) - (<intptr_t>&pod),
2604 (<intptr_t>&(pod.fh)) - (<intptr_t>&pod),
2605 (<intptr_t>&(pod.opcode)) - (<intptr_t>&pod),
2606 (<intptr_t>&(pod.cookie)) - (<intptr_t>&pod),
2607 ],
2608 'itemsize': sizeof(CUfileIOParams_t),
2609 })
2611io_params_dtype = _get_io_params_dtype_offsets()
2613cdef class IOParams:
2614 """Empty-initialize an array of `CUfileIOParams_t`.
2615 The resulting object is of length `size` and of dtype `io_params_dtype`.
2616 If default-constructed, the instance represents a single struct.
2618 Args:
2619 size (int): number of structs, default=1.
2621 .. seealso:: `CUfileIOParams_t`
2622 """
2623 cdef:
2624 readonly object _data
2625 object _owner
2627 def __init__(self, size=1):
2628 arr = _numpy.empty(size, dtype=io_params_dtype) 1dgf
2629 self._data = arr.view(_numpy.recarray) 1dgf
2630 assert self._data.itemsize == sizeof(CUfileIOParams_t), \ 1dgf
2631 f"itemsize {self._data.itemsize} mismatches struct size { sizeof(CUfileIOParams_t) }"
2633 def __repr__(self):
2634 if self._data.size > 1:
2635 return f"<{__name__}.IOParams_Array_{self._data.size} object at {hex(id(self))}>"
2636 else:
2637 return f"<{__name__}.IOParams object at {hex(id(self))}>"
2639 @property
2640 def ptr(self):
2641 """Get the pointer address to the data as Python :class:`int`."""
2642 return self._data.ctypes.data 1dgf
2644 cdef intptr_t _get_ptr(self):
2645 return self._data.ctypes.data
2647 def __int__(self):
2648 if self._data.size > 1 and not self._data.flags["C_CONTIGUOUS"]:
2649 raise TypeError("int() argument must be a bytes-like object of size 1, or a "
2650 "C-contiguous array. To get the pointer address of a "
2651 "non-contiguous array, use .ptr")
2652 return self._data.ctypes.data
2654 def __len__(self):
2655 return self._data.size
2657 def __eq__(self, other):
2658 cdef object self_data = self._data
2659 if (not isinstance(other, IOParams)) or self_data.size != other._data.size or self_data.dtype != other._data.dtype:
2660 return False
2661 return bool((self_data == other._data).all())
2663 def __getbuffer__(self, Py_buffer *buffer, int flags):
2664 _cyb_cpython.PyObject_GetBuffer(self._data, buffer, flags)
2666 def __releasebuffer__(self, Py_buffer *buffer):
2667 _cyb_cpython.PyBuffer_Release(buffer)
2669 @property
2670 def mode(self):
2671 """Union[~_numpy.int32, int]: """
2672 if self._data.size == 1:
2673 return int(self._data.mode[0])
2674 return self._data.mode
2676 @mode.setter
2677 def mode(self, val):
2678 self._data.mode = val 1dgf
2680 @property
2681 def u(self):
2682 """_py_anon_pod2_dtype: """
2683 return self._data.u 1dgf
2685 @u.setter
2686 def u(self, val):
2687 self._data.u = val
2689 @property
2690 def fh(self):
2691 """Union[~_numpy.intp, int]: """
2692 if self._data.size == 1:
2693 return int(self._data.fh[0])
2694 return self._data.fh
2696 @fh.setter
2697 def fh(self, val):
2698 self._data.fh = val 1dgf
2700 @property
2701 def opcode(self):
2702 """Union[~_numpy.int32, int]: """
2703 if self._data.size == 1:
2704 return int(self._data.opcode[0])
2705 return self._data.opcode
2707 @opcode.setter
2708 def opcode(self, val):
2709 self._data.opcode = val 1dgf
2711 @property
2712 def cookie(self):
2713 """Union[~_numpy.intp, int]: """
2714 if self._data.size == 1:
2715 return int(self._data.cookie[0])
2716 return self._data.cookie
2718 @cookie.setter
2719 def cookie(self, val):
2720 self._data.cookie = val 1dgf
2722 def __getitem__(self, key):
2723 cdef ssize_t key_
2724 cdef ssize_t size
2725 if isinstance(key, int): 1dgf
2726 key_ = key 1dgf
2727 size = self._data.size 1dgf
2728 if key_ >= size or key_ <= -(size+1): 1dgf
2729 raise IndexError("index is out of bounds")
2730 if key_ < 0: 1dgf
2731 key_ += size
2732 return IOParams.from_data(self._data[key_:key_+1]) 1dgf
2733 out = self._data[key]
2734 if isinstance(out, _numpy.recarray) and out.dtype == io_params_dtype:
2735 return IOParams.from_data(out)
2736 return out
2738 def __setitem__(self, key, val):
2739 self._data[key] = val
2741 @staticmethod
2742 def from_buffer(buffer):
2743 """Create an IOParams instance with the memory from the given buffer."""
2744 return IOParams.from_data(_numpy.frombuffer(buffer, dtype=io_params_dtype))
2746 @staticmethod
2747 def from_data(data):
2748 """Create an IOParams instance wrapping the given NumPy array.
2750 Args:
2751 data (_numpy.ndarray): a 1D array of dtype `io_params_dtype` holding the data.
2752 """
2753 cdef IOParams obj = IOParams.__new__(IOParams) 1dgf
2754 if not isinstance(data, _numpy.ndarray): 1dgf
2755 raise TypeError("data argument must be a NumPy ndarray")
2756 if data.ndim != 1: 1dgf
2757 raise ValueError("data array must be 1D")
2758 if data.dtype != io_params_dtype: 1dgf
2759 raise ValueError("data array must be of dtype io_params_dtype")
2760 obj._data = data.view(_numpy.recarray) 1dgf
2762 return obj 1dgf
2764 @staticmethod
2765 def from_ptr(intptr_t ptr, size_t size=1, bint readonly=False, object owner=None):
2766 """Create an IOParams instance wrapping the given pointer.
2768 Args:
2769 ptr (intptr_t): pointer address as Python :class:`int` to the data.
2770 size (int): number of structs, default=1.
2771 readonly (bool): whether the data is read-only (to the user). default is `False`.
2772 owner (object): object that owns the memory at *ptr*. A strong reference is
2773 kept so the backing storage outlives this wrapper.
2774 """
2775 if ptr == 0:
2776 raise ValueError("ptr must not be null (0)")
2777 cdef IOParams obj = IOParams.__new__(IOParams)
2778 cdef flag = _cyb_cpython_buffer.PyBUF_READ if readonly else _cyb_cpython_buffer.PyBUF_WRITE
2779 cdef object buf = _cyb_cpython_memoryview.PyMemoryView_FromMemory(
2780 <char*>ptr, sizeof(CUfileIOParams_t) * size, flag)
2781 data = _numpy.ndarray(size, buffer=buf, dtype=io_params_dtype)
2782 obj._data = data.view(_numpy.recarray)
2783 obj._owner = owner
2785 return obj
2788cdef _get_stats_level2_dtype_offsets():
2789 cdef CUfileStatsLevel2_t pod
2790 return _numpy.dtype({
2791 'names': ['basic', 'read_size_kb_hist', 'write_size_kb_hist'],
2792 'formats': [stats_level1_dtype, (_numpy.uint64, 32), (_numpy.uint64, 32)],
2793 'offsets': [
2794 (<intptr_t>&(pod.basic)) - (<intptr_t>&pod),
2795 (<intptr_t>&(pod.read_size_kb_hist)) - (<intptr_t>&pod),
2796 (<intptr_t>&(pod.write_size_kb_hist)) - (<intptr_t>&pod),
2797 ],
2798 'itemsize': sizeof(CUfileStatsLevel2_t),
2799 })
2801stats_level2_dtype = _get_stats_level2_dtype_offsets()
2803cdef class StatsLevel2:
2804 """Empty-initialize an instance of `CUfileStatsLevel2_t`.
2807 .. seealso:: `CUfileStatsLevel2_t`
2808 """
2809 cdef:
2810 CUfileStatsLevel2_t *_ptr
2811 object _owner
2812 bint _owns_ptr
2813 bint _readonly
2815 def __init__(self):
2816 self._ptr = <CUfileStatsLevel2_t *>_cyb_calloc(1, sizeof(CUfileStatsLevel2_t)) 1b
2817 if self._ptr == NULL: 1b
2818 raise MemoryError("Error allocating StatsLevel2")
2819 self._owns_ptr = True 1b
2820 self._owner = None 1b
2821 self._readonly = False 1b
2823 def __dealloc__(self):
2824 cdef CUfileStatsLevel2_t *ptr
2825 if self._owns_ptr and self._ptr != NULL: 1bc
2826 ptr = self._ptr 1b
2827 self._ptr = NULL 1b
2828 _cyb_free(ptr) 1b
2830 def __repr__(self):
2831 return f"<{__name__}.StatsLevel2 object at {hex(id(self))}>"
2833 @property
2834 def ptr(self):
2835 """Get the pointer address to the data as Python :class:`int`."""
2836 return <intptr_t>(self._ptr) 1b
2838 cdef intptr_t _get_ptr(self):
2839 return <intptr_t>(self._ptr)
2841 def __int__(self):
2842 return <intptr_t>(self._ptr)
2844 def __eq__(self, other):
2845 cdef StatsLevel2 other_
2846 if not isinstance(other, StatsLevel2):
2847 return False
2848 other_ = other
2849 return (_cyb_memcmp(<void *><intptr_t>(self._ptr), <void *><intptr_t>(other_._ptr), sizeof(CUfileStatsLevel2_t)) == 0)
2851 def __getbuffer__(self, _cyb_cpython.Py_buffer *buffer, int flags):
2852 _cyb___getbuffer(self, buffer, <void *>self._ptr, sizeof(CUfileStatsLevel2_t), self._readonly)
2854 def __releasebuffer__(self, Py_buffer *buffer):
2855 pass
2857 def __setitem__(self, key, val):
2858 cdef _cyb_Py_buffer view
2859 if key == 0:
2860 if self._readonly:
2861 raise ValueError("This StatsLevel2 instance is read-only")
2862 _cyb_PyObject_GetBuffer(val, &view, _cyb_PyBUF_SIMPLE)
2863 try:
2864 if <size_t>view.len < sizeof(CUfileStatsLevel2_t):
2865 raise ValueError(
2866 "source buffer too small: expected at least %d bytes, got %d" % (sizeof(CUfileStatsLevel2_t), view.len)
2867 )
2868 _cyb_memmove(<void*>self._ptr, view.buf, sizeof(CUfileStatsLevel2_t))
2869 self._readonly = view.readonly != 0
2870 finally:
2871 _cyb_PyBuffer_Release(&view)
2872 else:
2873 setattr(self, key, val)
2875 @property
2876 def basic(self):
2877 """StatsLevel1: """
2878 return StatsLevel1.from_ptr( 1b
2879 <intptr_t>&(self._ptr[0].basic), 1b
2880 readonly=self._readonly, 1b
2881 owner=self, 1b
2882 )
2884 @basic.setter
2885 def basic(self, val):
2886 if self._readonly:
2887 raise ValueError("This StatsLevel2 instance is read-only")
2888 cdef StatsLevel1 val_ = val
2889 _cyb_memcpy(<void *>&(self._ptr[0].basic), <void *>(val_._get_ptr()), sizeof(CUfileStatsLevel1_t) * 1)
2891 @property
2892 def read_size_kb_hist(self):
2893 """~_numpy.uint64: (array of length 32)."""
2894 cdef _cyb_view.array arr = _cyb_view.array(shape=(32,), itemsize=sizeof(uint64_t), format="Q", mode="c", allocate_buffer=False) 1bc
2895 arr.data = <char *>(&(self._ptr[0].read_size_kb_hist)) 1bc
2896 return _numpy.asarray(arr) 1bc
2898 @read_size_kb_hist.setter
2899 def read_size_kb_hist(self, val):
2900 if self._readonly:
2901 raise ValueError("This StatsLevel2 instance is read-only")
2902 if len(val) != 32:
2903 raise ValueError(f"Expected length { 32 } for field read_size_kb_hist, got {len(val)}")
2904 cdef _cyb_view.array arr = _cyb_view.array(shape=(32,), itemsize=sizeof(uint64_t), format="Q", mode="c")
2905 arr[:] = _numpy.asarray(val, dtype=_numpy.uint64)
2906 _cyb_memcpy(<void *>(&(self._ptr[0].read_size_kb_hist)), <void *>(arr.data), sizeof(uint64_t) * len(val))
2908 @property
2909 def write_size_kb_hist(self):
2910 """~_numpy.uint64: (array of length 32)."""
2911 cdef _cyb_view.array arr = _cyb_view.array(shape=(32,), itemsize=sizeof(uint64_t), format="Q", mode="c", allocate_buffer=False) 1b
2912 arr.data = <char *>(&(self._ptr[0].write_size_kb_hist)) 1b
2913 return _numpy.asarray(arr) 1b
2915 @write_size_kb_hist.setter
2916 def write_size_kb_hist(self, val):
2917 if self._readonly:
2918 raise ValueError("This StatsLevel2 instance is read-only")
2919 if len(val) != 32:
2920 raise ValueError(f"Expected length { 32 } for field write_size_kb_hist, got {len(val)}")
2921 cdef _cyb_view.array arr = _cyb_view.array(shape=(32,), itemsize=sizeof(uint64_t), format="Q", mode="c")
2922 arr[:] = _numpy.asarray(val, dtype=_numpy.uint64)
2923 _cyb_memcpy(<void *>(&(self._ptr[0].write_size_kb_hist)), <void *>(arr.data), sizeof(uint64_t) * len(val))
2925 @staticmethod
2926 def from_buffer(buffer):
2927 """Create an StatsLevel2 instance with the memory from the given buffer."""
2928 return _cyb_from_buffer(buffer, sizeof(CUfileStatsLevel2_t), StatsLevel2)
2930 @staticmethod
2931 def from_data(data):
2932 """Create an StatsLevel2 instance wrapping the given NumPy array.
2934 Args:
2935 data (_numpy.ndarray): a single-element array of dtype `stats_level2_dtype` holding the data.
2936 """
2937 return _cyb_from_data(data, "stats_level2_dtype", stats_level2_dtype, StatsLevel2) 1c
2939 @staticmethod
2940 def from_ptr(intptr_t ptr, bint readonly=False, object owner=None):
2941 """Create an StatsLevel2 instance wrapping the given pointer.
2943 Args:
2944 ptr (intptr_t): pointer address as Python :class:`int` to the data.
2945 owner (object): The Python object that owns the pointer. If not provided, data will be copied.
2946 readonly (bool): whether the data is read-only (to the user). default is `False`.
2947 """
2948 if ptr == 0: 1c
2949 raise ValueError("ptr must not be null (0)")
2950 cdef StatsLevel2 obj = StatsLevel2.__new__(StatsLevel2) 1c
2951 if owner is None: 1c
2952 obj._ptr = <CUfileStatsLevel2_t *>_cyb_malloc(sizeof(CUfileStatsLevel2_t))
2953 if obj._ptr == NULL:
2954 raise MemoryError("Error allocating StatsLevel2")
2955 _cyb_memcpy(<void*>(obj._ptr), <void*>ptr, sizeof(CUfileStatsLevel2_t))
2956 obj._owns_ptr = True
2957 obj._owner = None
2958 else:
2959 obj._ptr = <CUfileStatsLevel2_t *>ptr 1c
2960 obj._owns_ptr = False 1c
2961 obj._owner = owner 1c
2962 obj._readonly = readonly 1c
2963 return obj 1c
2966cdef _get_stats_level3_dtype_offsets():
2967 cdef CUfileStatsLevel3_t pod
2968 return _numpy.dtype({
2969 'names': ['detailed', 'num_gpus', 'per_gpu_stats'],
2970 'formats': [stats_level2_dtype, _numpy.uint32, (per_gpu_stats_dtype, 16)],
2971 'offsets': [
2972 (<intptr_t>&(pod.detailed)) - (<intptr_t>&pod),
2973 (<intptr_t>&(pod.num_gpus)) - (<intptr_t>&pod),
2974 (<intptr_t>&(pod.per_gpu_stats)) - (<intptr_t>&pod),
2975 ],
2976 'itemsize': sizeof(CUfileStatsLevel3_t),
2977 })
2979stats_level3_dtype = _get_stats_level3_dtype_offsets()
2981cdef class StatsLevel3:
2982 """Empty-initialize an instance of `CUfileStatsLevel3_t`.
2985 .. seealso:: `CUfileStatsLevel3_t`
2986 """
2987 cdef:
2988 CUfileStatsLevel3_t _data
2989 CUfileStatsLevel3_t *_ptr
2990 object _owner
2991 bint _readonly
2993 def __init__(self):
2994 self._ptr = &self._data 1c
2995 self._owner = None 1c
2996 self._readonly = False 1c
2998 def __repr__(self):
2999 return f"<{__name__}.StatsLevel3 object at {hex(id(self))}>"
3001 @property
3002 def ptr(self):
3003 """Get the pointer address to the data as Python :class:`int`."""
3004 return <intptr_t>(self._ptr) 1c
3006 cdef intptr_t _get_ptr(self):
3007 return <intptr_t>(self._ptr)
3009 def __int__(self):
3010 return <intptr_t>(self._ptr)
3012 def __eq__(self, other):
3013 cdef StatsLevel3 other_
3014 if not isinstance(other, StatsLevel3):
3015 return False
3016 other_ = other
3017 return (_cyb_memcmp(<void *><intptr_t>(self._ptr), <void *><intptr_t>(other_._ptr), sizeof(CUfileStatsLevel3_t)) == 0)
3019 def __getbuffer__(self, _cyb_cpython.Py_buffer *buffer, int flags):
3020 _cyb___getbuffer(self, buffer, <void *>self._ptr, sizeof(CUfileStatsLevel3_t), self._readonly)
3022 def __releasebuffer__(self, Py_buffer *buffer):
3023 pass
3025 def __setitem__(self, key, val):
3026 cdef _cyb_Py_buffer view
3027 if key == 0:
3028 if self._readonly:
3029 raise ValueError("This StatsLevel3 instance is read-only")
3030 _cyb_PyObject_GetBuffer(val, &view, _cyb_PyBUF_SIMPLE)
3031 try:
3032 if <size_t>view.len < sizeof(CUfileStatsLevel3_t):
3033 raise ValueError(
3034 "source buffer too small: expected at least %d bytes, got %d" % (sizeof(CUfileStatsLevel3_t), view.len)
3035 )
3036 _cyb_memmove(<void*>&self._data, view.buf, sizeof(CUfileStatsLevel3_t))
3037 self._ptr = &self._data
3038 self._owner = None
3039 self._readonly = view.readonly != 0
3040 finally:
3041 _cyb_PyBuffer_Release(&view)
3042 else:
3043 setattr(self, key, val)
3045 @property
3046 def detailed(self):
3047 """StatsLevel2: """
3048 return StatsLevel2.from_ptr( 1c
3049 <intptr_t>&(self._ptr[0].detailed), 1c
3050 readonly=self._readonly, 1c
3051 owner=self, 1c
3052 )
3054 @detailed.setter
3055 def detailed(self, val):
3056 if self._readonly:
3057 raise ValueError("This StatsLevel3 instance is read-only")
3058 cdef StatsLevel2 val_ = val
3059 _cyb_memcpy(<void *>&(self._ptr[0].detailed), <void *>(val_._get_ptr()), sizeof(CUfileStatsLevel2_t) * 1)
3061 @property
3062 def per_gpu_stats(self):
3063 """PerGpuStats: """
3064 return PerGpuStats.from_ptr( 1c
3065 <intptr_t>&(self._ptr[0].per_gpu_stats), 1c
3066 16,
3067 readonly=self._readonly, 1c
3068 owner=self, 1c
3069 )
3071 @per_gpu_stats.setter
3072 def per_gpu_stats(self, val):
3073 if self._readonly:
3074 raise ValueError("This StatsLevel3 instance is read-only")
3075 cdef PerGpuStats val_ = val
3076 if len(val) != 16:
3077 raise ValueError(f"Expected length { 16 } for field per_gpu_stats, got {len(val)}")
3078 _cyb_memcpy(<void *>&(self._ptr[0].per_gpu_stats), <void *>(val_._get_ptr()), sizeof(CUfilePerGpuStats_t) * 16)
3080 @property
3081 def num_gpus(self):
3082 """int: """
3083 return self._ptr[0].num_gpus 1c
3085 @num_gpus.setter
3086 def num_gpus(self, val):
3087 if self._readonly:
3088 raise ValueError("This StatsLevel3 instance is read-only")
3089 self._ptr[0].num_gpus = val
3091 @staticmethod
3092 def from_buffer(buffer):
3093 """Create an StatsLevel3 instance with the memory from the given buffer."""
3094 return _cyb_from_buffer(buffer, sizeof(CUfileStatsLevel3_t), StatsLevel3)
3096 @staticmethod
3097 def from_data(data):
3098 """Create an StatsLevel3 instance wrapping the given NumPy array.
3100 Args:
3101 data (_numpy.ndarray): a single-element array of dtype `stats_level3_dtype` holding the data.
3102 """
3103 return _cyb_from_data(data, "stats_level3_dtype", stats_level3_dtype, StatsLevel3)
3105 @staticmethod
3106 def from_ptr(intptr_t ptr, bint readonly=False, object owner=None):
3107 """Create an StatsLevel3 instance wrapping the given pointer.
3109 Args:
3110 ptr (intptr_t): pointer address as Python :class:`int` to the data.
3111 owner (object): The Python object that owns the pointer. If not provided, data will be copied.
3112 readonly (bool): whether the data is read-only (to the user). default is `False`.
3113 """
3114 if ptr == 0:
3115 raise ValueError("ptr must not be null (0)")
3116 cdef StatsLevel3 obj = StatsLevel3.__new__(StatsLevel3)
3117 if owner is None:
3118 _cyb_memcpy(<void*>&obj._data, <void*>ptr, sizeof(CUfileStatsLevel3_t))
3119 obj._ptr = &obj._data
3120 obj._owner = None
3121 else:
3122 obj._ptr = <CUfileStatsLevel3_t *>ptr
3123 obj._owner = owner
3124 obj._readonly = readonly
3125 return obj
3128###############################################################################
3129# Enum
3130###############################################################################
3132class OpError(_cyb_FastEnum):
3133 """
3134 See `CUfileOpError`.
3135 """
3136 SUCCESS = CU_FILE_SUCCESS
3137 DRIVER_NOT_INITIALIZED = CU_FILE_DRIVER_NOT_INITIALIZED
3138 DRIVER_INVALID_PROPS = CU_FILE_DRIVER_INVALID_PROPS
3139 DRIVER_UNSUPPORTED_LIMIT = CU_FILE_DRIVER_UNSUPPORTED_LIMIT
3140 DRIVER_VERSION_MISMATCH = CU_FILE_DRIVER_VERSION_MISMATCH
3141 DRIVER_VERSION_READ_ERROR = CU_FILE_DRIVER_VERSION_READ_ERROR
3142 DRIVER_CLOSING = CU_FILE_DRIVER_CLOSING
3143 PLATFORM_NOT_SUPPORTED = CU_FILE_PLATFORM_NOT_SUPPORTED
3144 IO_NOT_SUPPORTED = CU_FILE_IO_NOT_SUPPORTED
3145 DEVICE_NOT_SUPPORTED = CU_FILE_DEVICE_NOT_SUPPORTED
3146 NVFS_DRIVER_ERROR = CU_FILE_NVFS_DRIVER_ERROR
3147 CUDA_DRIVER_ERROR = CU_FILE_CUDA_DRIVER_ERROR
3148 CUDA_POINTER_INVALID = CU_FILE_CUDA_POINTER_INVALID
3149 CUDA_MEMORY_TYPE_INVALID = CU_FILE_CUDA_MEMORY_TYPE_INVALID
3150 CUDA_POINTER_RANGE_ERROR = CU_FILE_CUDA_POINTER_RANGE_ERROR
3151 CUDA_CONTEXT_MISMATCH = CU_FILE_CUDA_CONTEXT_MISMATCH
3152 INVALID_MAPPING_SIZE = CU_FILE_INVALID_MAPPING_SIZE
3153 INVALID_MAPPING_RANGE = CU_FILE_INVALID_MAPPING_RANGE
3154 INVALID_FILE_TYPE = CU_FILE_INVALID_FILE_TYPE
3155 INVALID_FILE_OPEN_FLAG = CU_FILE_INVALID_FILE_OPEN_FLAG
3156 DIO_NOT_SET = CU_FILE_DIO_NOT_SET
3157 INVALID_VALUE = CU_FILE_INVALID_VALUE
3158 MEMORY_ALREADY_REGISTERED = CU_FILE_MEMORY_ALREADY_REGISTERED
3159 MEMORY_NOT_REGISTERED = CU_FILE_MEMORY_NOT_REGISTERED
3160 PERMISSION_DENIED = CU_FILE_PERMISSION_DENIED
3161 DRIVER_ALREADY_OPEN = CU_FILE_DRIVER_ALREADY_OPEN
3162 HANDLE_NOT_REGISTERED = CU_FILE_HANDLE_NOT_REGISTERED
3163 HANDLE_ALREADY_REGISTERED = CU_FILE_HANDLE_ALREADY_REGISTERED
3164 DEVICE_NOT_FOUND = CU_FILE_DEVICE_NOT_FOUND
3165 INTERNAL_ERROR = CU_FILE_INTERNAL_ERROR
3166 GETNEWFD_FAILED = CU_FILE_GETNEWFD_FAILED
3167 NVFS_SETUP_ERROR = CU_FILE_NVFS_SETUP_ERROR
3168 IO_DISABLED = CU_FILE_IO_DISABLED
3169 BATCH_SUBMIT_FAILED = CU_FILE_BATCH_SUBMIT_FAILED
3170 GPU_MEMORY_PINNING_FAILED = CU_FILE_GPU_MEMORY_PINNING_FAILED
3171 BATCH_FULL = CU_FILE_BATCH_FULL
3172 ASYNC_NOT_SUPPORTED = CU_FILE_ASYNC_NOT_SUPPORTED
3173 INTERNAL_BATCH_SETUP_ERROR = CU_FILE_INTERNAL_BATCH_SETUP_ERROR
3174 INTERNAL_BATCH_SUBMIT_ERROR = CU_FILE_INTERNAL_BATCH_SUBMIT_ERROR
3175 INTERNAL_BATCH_GETSTATUS_ERROR = CU_FILE_INTERNAL_BATCH_GETSTATUS_ERROR
3176 INTERNAL_BATCH_CANCEL_ERROR = CU_FILE_INTERNAL_BATCH_CANCEL_ERROR
3177 NOMEM_ERROR = CU_FILE_NOMEM_ERROR
3178 IO_ERROR = CU_FILE_IO_ERROR
3179 INTERNAL_BUF_REGISTER_ERROR = CU_FILE_INTERNAL_BUF_REGISTER_ERROR
3180 HASH_OPR_ERROR = CU_FILE_HASH_OPR_ERROR
3181 INVALID_CONTEXT_ERROR = CU_FILE_INVALID_CONTEXT_ERROR
3182 NVFS_INTERNAL_DRIVER_ERROR = CU_FILE_NVFS_INTERNAL_DRIVER_ERROR
3183 BATCH_NOCOMPAT_ERROR = CU_FILE_BATCH_NOCOMPAT_ERROR
3184 IO_MAX_ERROR = CU_FILE_IO_MAX_ERROR
3186class DriverStatusFlags(_cyb_FastEnum):
3187 """
3188 See `CUfileDriverStatusFlags_t`.
3189 """
3190 LUSTRE_SUPPORTED = (CU_FILE_LUSTRE_SUPPORTED, 'Support for DDN LUSTRE')
3191 WEKAFS_SUPPORTED = (CU_FILE_WEKAFS_SUPPORTED, 'Support for WEKAFS')
3192 NFS_SUPPORTED = (CU_FILE_NFS_SUPPORTED, 'Support for NFS')
3193 GPFS_SUPPORTED = CU_FILE_GPFS_SUPPORTED
3194 NVME_SUPPORTED = (CU_FILE_NVME_SUPPORTED, '< Support for GPFS Support for NVMe')
3195 NVMEOF_SUPPORTED = (CU_FILE_NVMEOF_SUPPORTED, 'Support for NVMeOF')
3196 SCSI_SUPPORTED = (CU_FILE_SCSI_SUPPORTED, 'Support for SCSI')
3197 SCALEFLUX_CSD_SUPPORTED = (CU_FILE_SCALEFLUX_CSD_SUPPORTED, 'Support for Scaleflux CSD')
3198 NVMESH_SUPPORTED = (CU_FILE_NVMESH_SUPPORTED, 'Support for NVMesh Block Dev')
3199 BEEGFS_SUPPORTED = (CU_FILE_BEEGFS_SUPPORTED, 'Support for BeeGFS')
3200 NVME_P2P_SUPPORTED = (CU_FILE_NVME_P2P_SUPPORTED, 'Do not use this macro. This is deprecated now')
3201 SCATEFS_SUPPORTED = (CU_FILE_SCATEFS_SUPPORTED, 'Support for ScateFS')
3202 VIRTIOFS_SUPPORTED = (CU_FILE_VIRTIOFS_SUPPORTED, 'Support for VirtioFS')
3203 MAX_TARGET_TYPES = (CU_FILE_MAX_TARGET_TYPES, 'Maximum FS supported')
3205class DriverControlFlags(_cyb_FastEnum):
3206 """
3207 See `CUfileDriverControlFlags_t`.
3208 """
3209 USE_POLL_MODE = (CU_FILE_USE_POLL_MODE, 'use POLL mode. properties.use_poll_mode')
3210 ALLOW_COMPAT_MODE = (CU_FILE_ALLOW_COMPAT_MODE, 'allow COMPATIBILITY mode. properties.allow_compat_mode')
3211 VANILLA_POSIX_IO_MODE = (CU_FILE_VANILLA_POSIX_IO_MODE, 'Vanilla posix io mode. properties.vanilla_posix_io_mode')
3212 POSIX_IO_MODE = (CU_FILE_POSIX_IO_MODE, 'alias for backward compatibility')
3213 FALLBACK_IO_MODE = (CU_FILE_FALLBACK_IO_MODE, 'Fallback io mode. properties.gds_fallback_io')
3215class FeatureFlags(_cyb_FastEnum):
3216 """
3217 See `CUfileFeatureFlags_t`.
3218 """
3219 DYN_ROUTING_SUPPORTED = (CU_FILE_DYN_ROUTING_SUPPORTED, 'Support for Dynamic routing to handle devices across the PCIe bridges')
3220 BATCH_IO_SUPPORTED = (CU_FILE_BATCH_IO_SUPPORTED, 'Supported')
3221 STREAMS_SUPPORTED = (CU_FILE_STREAMS_SUPPORTED, 'Supported')
3222 PARALLEL_IO_SUPPORTED = (CU_FILE_PARALLEL_IO_SUPPORTED, 'Supported')
3223 P2P_SUPPORTED = (CU_FILE_P2P_SUPPORTED, 'Support for PCI P2PDMA')
3225class FileHandleType(_cyb_FastEnum):
3226 """
3227 See `CUfileFileHandleType`.
3228 """
3229 OPAQUE_FD = (CU_FILE_HANDLE_TYPE_OPAQUE_FD, 'Linux based fd')
3230 OPAQUE_WIN32 = (CU_FILE_HANDLE_TYPE_OPAQUE_WIN32, 'Windows based handle (unsupported)')
3231 USERSPACE_FS = CU_FILE_HANDLE_TYPE_USERSPACE_FS
3233class Opcode(_cyb_FastEnum):
3234 """
3235 See `CUfileOpcode_t`.
3236 """
3237 READ = CUFILE_READ
3238 WRITE = CUFILE_WRITE
3240class Status(_cyb_FastEnum):
3241 """
3242 See `CUfileStatus_t`.
3243 """
3244 WAITING = CUFILE_WAITING
3245 PENDING = CUFILE_PENDING
3246 INVALID = CUFILE_INVALID
3247 CANCELED = CUFILE_CANCELED
3248 COMPLETE = CUFILE_COMPLETE
3249 TIMEOUT = CUFILE_TIMEOUT
3250 FAILED = CUFILE_FAILED
3252class BatchMode(_cyb_FastEnum):
3253 """
3254 See `CUfileBatchMode_t`.
3255 """
3256 BATCH = CUFILE_BATCH
3258class SizeTConfigParameter(_cyb_FastEnum):
3259 """
3260 See `CUFileSizeTConfigParameter_t`.
3261 """
3262 PROFILE_STATS = CUFILE_PARAM_PROFILE_STATS
3263 EXECUTION_MAX_IO_QUEUE_DEPTH = CUFILE_PARAM_EXECUTION_MAX_IO_QUEUE_DEPTH
3264 EXECUTION_MAX_IO_THREADS = CUFILE_PARAM_EXECUTION_MAX_IO_THREADS
3265 EXECUTION_MIN_IO_THRESHOLD_SIZE_KB = CUFILE_PARAM_EXECUTION_MIN_IO_THRESHOLD_SIZE_KB
3266 EXECUTION_MAX_REQUEST_PARALLELISM = CUFILE_PARAM_EXECUTION_MAX_REQUEST_PARALLELISM
3267 PROPERTIES_MAX_DIRECT_IO_SIZE_KB = CUFILE_PARAM_PROPERTIES_MAX_DIRECT_IO_SIZE_KB
3268 PROPERTIES_MAX_DEVICE_CACHE_SIZE_KB = CUFILE_PARAM_PROPERTIES_MAX_DEVICE_CACHE_SIZE_KB
3269 PROPERTIES_PER_BUFFER_CACHE_SIZE_KB = CUFILE_PARAM_PROPERTIES_PER_BUFFER_CACHE_SIZE_KB
3270 PROPERTIES_MAX_DEVICE_PINNED_MEM_SIZE_KB = CUFILE_PARAM_PROPERTIES_MAX_DEVICE_PINNED_MEM_SIZE_KB
3271 PROPERTIES_IO_BATCHSIZE = CUFILE_PARAM_PROPERTIES_IO_BATCHSIZE
3272 POLLTHRESHOLD_SIZE_KB = CUFILE_PARAM_POLLTHRESHOLD_SIZE_KB
3273 PROPERTIES_BATCH_IO_TIMEOUT_MS = CUFILE_PARAM_PROPERTIES_BATCH_IO_TIMEOUT_MS
3275class BoolConfigParameter(_cyb_FastEnum):
3276 """
3277 See `CUFileBoolConfigParameter_t`.
3278 """
3279 PROPERTIES_USE_POLL_MODE = CUFILE_PARAM_PROPERTIES_USE_POLL_MODE
3280 PROPERTIES_ALLOW_COMPAT_MODE = CUFILE_PARAM_PROPERTIES_ALLOW_COMPAT_MODE
3281 FORCE_COMPAT_MODE = CUFILE_PARAM_FORCE_COMPAT_MODE
3282 FS_MISC_API_CHECK_AGGRESSIVE = CUFILE_PARAM_FS_MISC_API_CHECK_AGGRESSIVE
3283 EXECUTION_PARALLEL_IO = CUFILE_PARAM_EXECUTION_PARALLEL_IO
3284 PROFILE_NVTX = CUFILE_PARAM_PROFILE_NVTX
3285 PROPERTIES_ALLOW_SYSTEM_MEMORY = CUFILE_PARAM_PROPERTIES_ALLOW_SYSTEM_MEMORY
3286 USE_PCIP2PDMA = CUFILE_PARAM_USE_PCIP2PDMA
3287 PREFER_IO_URING = CUFILE_PARAM_PREFER_IO_URING
3288 FORCE_ODIRECT_MODE = CUFILE_PARAM_FORCE_ODIRECT_MODE
3289 SKIP_TOPOLOGY_DETECTION = CUFILE_PARAM_SKIP_TOPOLOGY_DETECTION
3290 STREAM_MEMOPS_BYPASS = CUFILE_PARAM_STREAM_MEMOPS_BYPASS
3291 PROPERTIES_POSIX_IO_MODE = CUFILE_PARAM_PROPERTIES_POSIX_IO_MODE
3292 GDS_FALLBACK_IO = CUFILE_PARAM_GDS_FALLBACK_IO
3294class StringConfigParameter(_cyb_FastEnum):
3295 """
3296 See `CUFileStringConfigParameter_t`.
3297 """
3298 LOGGING_LEVEL = CUFILE_PARAM_LOGGING_LEVEL
3299 ENV_LOGFILE_PATH = CUFILE_PARAM_ENV_LOGFILE_PATH
3300 LOG_DIR = CUFILE_PARAM_LOG_DIR
3301 RDMA_TRANSPORT = CUFILE_PARAM_RDMA_TRANSPORT
3303class ArrayConfigParameter(_cyb_FastEnum):
3304 """
3305 See `CUFileArrayConfigParameter_t`.
3306 """
3307 POSIX_POOL_SLAB_SIZE_KB = CUFILE_PARAM_POSIX_POOL_SLAB_SIZE_KB
3308 POSIX_POOL_SLAB_COUNT = CUFILE_PARAM_POSIX_POOL_SLAB_COUNT
3309 GPU_BOUNCE_BUFFER_SLAB_SIZE_KB = CUFILE_PARAM_GPU_BOUNCE_BUFFER_SLAB_SIZE_KB
3310 GPU_BOUNCE_BUFFER_SLAB_COUNT = CUFILE_PARAM_GPU_BOUNCE_BUFFER_SLAB_COUNT
3312class P2PFlags(_cyb_FastEnum):
3313 """
3314 See `CUfileP2PFlags_t`.
3315 """
3316 P2PDMA = (CUFILE_P2PDMA, 'Support for PCI P2PDMA')
3317 NVFS = (CUFILE_NVFS, 'Support for nvidia-fs')
3318 DMABUF = (CUFILE_DMABUF, 'Support for DMA Buffer')
3319 C2C = (CUFILE_C2C, 'Support for Chip-to-Chip (Grace-based systems)')
3320 NVIDIA_PEERMEM = (CUFILE_NVIDIA_PEERMEM, 'Only for IBM Spectrum Scale and WekaFS')
3323###############################################################################
3324# Error handling
3325###############################################################################
3327ctypedef fused ReturnT:
3328 CUfileError_t
3329 ssize_t
3332class cuFileError(Exception):
3334 def __init__(self, status, cu_err=None):
3335 self.status = status 1qno
3336 self.cuda_error = cu_err 1qno
3337 s = OpError(status) 1qno
3338 cdef str err = f"{s.name} ({s.value}): {op_status_error(status)}" 1qno
3339 if cu_err is not None: 1qno
3340 e = pyCUresult(cu_err)
3341 err += f"; CUDA status: {e.name} ({e.value})"
3342 super(cuFileError, self).__init__(err) 1qno
3344 def __reduce__(self):
3345 return (type(self), (self.status, self.cuda_error))
3348@cython.profile(False)
3349cdef int check_status(ReturnT status) except 1 nogil:
3350 if ReturnT is CUfileError_t:
3351 if IS_CUDA_ERR(status): 1adNOgPQfRSqTUFVWGXYHZ0I12J34h56i78j9!k#$l%'m()L*+M,-eBubCvctwr./psnxK:oDyzEA
3352 with gil:
3353 raise cuFileError(status.err, status.cu_err)
3354 elif IS_CUFILE_ERR(status.err): 1adNOgPQfRSqTUFVWGXYHZ0I12J34h56i78j9!k#$l%'m()L*+M,-eBubCvctwr./psnxK:oDyzEA
3355 with gil: 1qno
3356 raise cuFileError(status.err) 1qno
3357 elif ReturnT is ssize_t:
3358 if status == -1: 1jklebc
3359 # note: this assumes cuFile already properly resets errno in each API
3360 with gil:
3361 raise cuFileError(errno.errno)
3362 return 0 1adNOgPQfRSqTUFVWGXYHZ0I12J34h56i78j9!k#$l%'m()L*+M,-eBubCvctwr./psnxK:oDyzEA
3365###############################################################################
3366# Wrapper functions
3367###############################################################################
3369cpdef intptr_t handle_register(descr) except? 0:
3370 """cuFileHandleRegister is required, and performs extra checking that is memoized to provide increased performance on later cuFile operations.
3372 Description cuFileHandleRegister registers the open file descriptor for use
3373 with cuFile IO operations.
3374 This API will ensure that the file's descriptor is checked for GPUDirect
3375 Storage support and returns a valid file handle on CU_FILE_SUCCESS.
3377 Args:
3378 descr (intptr_t): ``CUfileDescr_t`` file descriptor (OS agnostic).
3380 Returns:
3381 intptr_t: ``CUfileHandle_t`` opaque file handle for IO operations.
3383 .. note::
3384 the file needs to be opened in O_DIRECT mode to support GPUDirect Storage.
3385 .. seealso:: `cuFileHandleRegister`
3386 """
3387 cdef intptr_t _descr_ptr_ = int(descr) 1dgfhijklmebcr
3388 cdef Handle fh
3389 with nogil: 1dgfhijklmebcr
3390 __status__ = cuFileHandleRegister(&fh, <CUfileDescr_t*>_descr_ptr_) 1dgfhijklmebcr
3391 check_status(__status__) 1dgfhijklmebcr
3392 return <intptr_t>fh 1dgfhijklmebcr
3395cpdef void handle_deregister(intptr_t fh) except*:
3396 """releases a registered filehandle from cuFile.
3399 Args:
3400 fh (intptr_t): ``CUfileHandle_t`` file handle.
3402 .. seealso:: `cuFileHandleDeregister`
3403 """
3404 with nogil: 1dgfhijklmebcr
3405 cuFileHandleDeregister(<Handle>fh) 1dgfhijklmebcr
3408cpdef buf_register(intptr_t buf_ptr_base, size_t length, int flags):
3409 """register an existing cudaMalloced memory with cuFile to pin for GPUDirect Storage access or register host allocated memory with cuFile.
3412 Args:
3413 buf_ptr_base (intptr_t): buffer pointer allocated.
3414 length (size_t): size of memory region from the above specified
3415 bufPtr.
3416 flags (int): CU_FILE_RDMA_REGISTER.
3418 .. note::
3419 This memory will be use to perform GPU direct DMA from the supported storage.
3420 .. note::
3421 This API is intended for usecases where the memory is used as streaming buffer
3422 that is reused across multiple cuFile IO operations before calling
3423 ``cuFileBufDeregister``.
3424 .. seealso:: `cuFileBufRegister`
3425 """
3426 with nogil: 1dgfqFGHIJhijklmebc
3427 __status__ = cuFileBufRegister(<const void*>buf_ptr_base, length, flags) 1dgfqFGHIJhijklmebc
3428 check_status(__status__) 1dgfqFGHIJhijklmebc
3431cpdef buf_deregister(intptr_t buf_ptr_base):
3432 """deregister an already registered device or host memory from cuFile.
3435 Args:
3436 buf_ptr_base (intptr_t): buffer pointer to deregister.
3438 .. seealso:: `cuFileBufDeregister`
3439 """
3440 with nogil: 1dgfqFGHIJhijklmebc
3441 __status__ = cuFileBufDeregister(<const void*>buf_ptr_base) 1dgfqFGHIJhijklmebc
3442 check_status(__status__) 1dgfqFGHIJhijklmebc
3445cpdef driver_open():
3446 """Initialize the cuFile library and open the nvidia-fs driver.
3449 .. seealso:: `cuFileDriverOpen`
3450 """
3451 with nogil: 1NPRTVXZ13579#%(*,BCt.psnxKDE
3452 __status__ = cuFileDriverOpen() 1NPRTVXZ13579#%(*,BCt.psnxKDE
3453 check_status(__status__) 1NPRTVXZ13579#%(*,BCt.psnxKDE
3456cpdef use_count():
3457 """returns use count of cufile drivers at that moment by the process.
3460 .. seealso:: `cuFileUseCount`
3461 """
3462 with nogil:
3463 __status__ = cuFileUseCount()
3464 check_status(__status__)
3467cpdef driver_get_properties(intptr_t props):
3468 """Gets the Driver session properties If the driver is not opened, it will return the staged/default properties If the driver is opened, it will return the current properties.
3471 Args:
3472 props (intptr_t): Properties to get.
3474 .. seealso:: `cuFileDriverGetProperties`
3475 """
3476 with nogil:
3477 __status__ = cuFileDriverGetProperties(<CUfileDrvProps_t*>props)
3478 check_status(__status__)
3481cpdef driver_set_poll_mode(bint poll, size_t poll_threshold_size):
3482 """Sets whether the Read/Write APIs use polling to do IO operations This takes place before the driver is opened. No-op if driver is already open.
3485 Args:
3486 poll (bint): boolean to indicate whether to use poll mode or not.
3487 poll_threshold_size (size_t): max IO size to use for POLLING mode
3488 in KB.
3490 .. note::
3491 This is an advanced command and should be tuned based on available system
3492 memory.
3493 .. seealso:: `cuFileDriverSetPollMode`
3494 """
3495 with nogil:
3496 __status__ = cuFileDriverSetPollMode(<_cyb_bool>poll, poll_threshold_size)
3497 check_status(__status__)
3500cpdef driver_set_max_direct_io_size(size_t max_direct_io_size):
3501 """Control parameter to set max IO size(KB) used by the library to talk to nvidia-fs driver This takes place before the driver is opened. No-op if driver is already open.
3504 Args:
3505 max_direct_io_size (size_t): maximum allowed direct io size in KB.
3507 .. note::
3508 This is an advanced command and should be tuned based on available system
3509 memory.
3510 .. seealso:: `cuFileDriverSetMaxDirectIOSize`
3511 """
3512 with nogil:
3513 __status__ = cuFileDriverSetMaxDirectIOSize(max_direct_io_size)
3514 check_status(__status__)
3517cpdef driver_set_max_cache_size(size_t max_cache_size):
3518 """Control parameter to set maximum GPU memory reserved per device by the library for internal buffering This takes place before the driver is opened. No-op if driver is already open.
3521 Args:
3522 max_cache_size (size_t): The maximum GPU buffer space per device
3523 used for internal use in KB.
3525 .. note::
3526 This is an advanced command and should be tuned based on supported GPU memory.
3527 .. seealso:: `cuFileDriverSetMaxCacheSize`
3528 """
3529 with nogil:
3530 __status__ = cuFileDriverSetMaxCacheSize(max_cache_size)
3531 check_status(__status__)
3534cpdef driver_set_max_pinned_mem_size(size_t max_pinned_size):
3535 """Sets maximum buffer space that is pinned in KB for use by ``cuFileBufRegister`` This takes place before the driver is opened. No-op if driver is already open.
3538 Args:
3539 max_pinned_size (size_t): maximum buffer space that is pinned in
3540 KB.
3542 .. note::
3543 This is an advanced command and should be tuned based on supported GPU memory.
3544 .. seealso:: `cuFileDriverSetMaxPinnedMemSize`
3545 """
3546 with nogil:
3547 __status__ = cuFileDriverSetMaxPinnedMemSize(max_pinned_size)
3548 check_status(__status__)
3551cpdef intptr_t batch_io_set_up(unsigned nr) except? 0:
3552 cdef BatchHandle batch_idp
3553 with nogil: 1dgf
3554 __status__ = cuFileBatchIOSetUp(&batch_idp, nr) 1dgf
3555 check_status(__status__) 1dgf
3556 return <intptr_t>batch_idp 1dgf
3559cpdef batch_io_submit(intptr_t batch_idp, unsigned nr, iocbp, unsigned int flags):
3560 cdef intptr_t _iocbp_ptr_ = int(iocbp) 1dgf
3561 with nogil: 1dgf
3562 __status__ = cuFileBatchIOSubmit(<BatchHandle>batch_idp, nr, <CUfileIOParams_t*>_iocbp_ptr_, flags) 1dgf
3563 check_status(__status__) 1dgf
3566cpdef batch_io_get_status(intptr_t batch_idp, unsigned min_nr, intptr_t nr, iocbp, intptr_t timeout):
3567 cdef intptr_t _iocbp_ptr_ = int(iocbp) 1df
3568 with nogil: 1df
3569 __status__ = cuFileBatchIOGetStatus(<BatchHandle>batch_idp, min_nr, <unsigned*>nr, <CUfileIOEvents_t*>_iocbp_ptr_, <timespec*>timeout) 1df
3570 check_status(__status__) 1df
3573cpdef batch_io_cancel(intptr_t batch_idp):
3574 with nogil: 1g
3575 __status__ = cuFileBatchIOCancel(<BatchHandle>batch_idp) 1g
3576 check_status(__status__) 1g
3579cpdef void batch_io_destroy(intptr_t batch_idp) except*:
3580 with nogil: 1dgf
3581 cuFileBatchIODestroy(<BatchHandle>batch_idp) 1dgf
3584cpdef read_async(intptr_t fh, intptr_t buf_ptr_base, intptr_t size_p, intptr_t file_offset_p, intptr_t buf_ptr_offset_p, intptr_t bytes_read_p, intptr_t stream):
3585 with nogil: 1hi
3586 __status__ = cuFileReadAsync(<Handle>fh, <void*>buf_ptr_base, <size_t*>size_p, <off_t*>file_offset_p, <off_t*>buf_ptr_offset_p, <ssize_t*>bytes_read_p, <CUstream>stream) 1hi
3587 check_status(__status__) 1hi
3590cpdef write_async(intptr_t fh, intptr_t buf_ptr_base, intptr_t size_p, intptr_t file_offset_p, intptr_t buf_ptr_offset_p, intptr_t bytes_written_p, intptr_t stream):
3591 with nogil: 1hm
3592 __status__ = cuFileWriteAsync(<Handle>fh, <void*>buf_ptr_base, <size_t*>size_p, <off_t*>file_offset_p, <off_t*>buf_ptr_offset_p, <ssize_t*>bytes_written_p, <CUstream>stream) 1hm
3593 check_status(__status__) 1hm
3596cpdef stream_register(intptr_t stream, unsigned flags):
3597 with nogil: 1him
3598 __status__ = cuFileStreamRegister(<CUstream>stream, flags) 1him
3599 check_status(__status__) 1him
3602cpdef stream_deregister(intptr_t stream):
3603 with nogil: 1him
3604 __status__ = cuFileStreamDeregister(<CUstream>stream) 1him
3605 check_status(__status__) 1him
3608cpdef int get_version() except? 0:
3609 """Get the cuFile library version.
3611 The version is returned as (1000 major + 10 minor). For example, CUFILE 1.7.0
3612 would be represented by 1070.
3614 Returns:
3615 int: Pointer to an integer where the version will be stored.
3617 .. note::
3618 This is useful for applications that need to inquire the library.
3619 .. seealso:: `cuFileGetVersion`
3620 """
3621 cdef int version
3622 with nogil: 1ap
3623 __status__ = cuFileGetVersion(&version) 1ap
3624 check_status(__status__) 1ap
3625 return version 1ap
3628cpdef size_t get_parameter_size_t(int param) except? 0:
3629 cdef size_t value
3630 with nogil: 1s
3631 __status__ = cuFileGetParameterSizeT(<_SizeTConfigParameter>param, &value) 1s
3632 check_status(__status__) 1s
3633 return value 1s
3636cpdef bint get_parameter_bool(int param) except? 0:
3637 cdef _cyb_bool value
3638 with nogil: 1p
3639 __status__ = cuFileGetParameterBool(<_BoolConfigParameter>param, &value) 1p
3640 check_status(__status__) 1p
3641 return <bint>value 1p
3644cpdef str get_parameter_string(int param, int len):
3645 cdef bytes _desc_str_ = bytes(len) 1n
3646 cdef char* desc_str = _desc_str_ 1n
3647 with nogil: 1n
3648 __status__ = cuFileGetParameterString(<_StringConfigParameter>param, desc_str, len) 1n
3649 check_status(__status__) 1n
3650 return _cyb_cpython.PyUnicode_FromString(desc_str) 1n
3653cpdef set_parameter_size_t(int param, size_t value):
3654 with nogil: 1s
3655 __status__ = cuFileSetParameterSizeT(<_SizeTConfigParameter>param, value) 1s
3656 check_status(__status__) 1s
3659cpdef set_parameter_bool(int param, bint value):
3660 with nogil: 1p
3661 __status__ = cuFileSetParameterBool(<_BoolConfigParameter>param, <_cyb_bool>value) 1p
3662 check_status(__status__) 1p
3665cpdef set_parameter_string(int param, intptr_t desc_str):
3666 with nogil: 1n
3667 __status__ = cuFileSetParameterString(<_StringConfigParameter>param, <const char*>desc_str) 1n
3668 check_status(__status__) 1n
3671cpdef tuple get_parameter_min_max_value(int param):
3672 """Get both the minimum and maximum settable values for a given size_t parameter in a single call.
3675 Args:
3676 param (SizeTConfigParameter): CUfile SizeT configuration
3677 parameter.
3679 Returns:
3680 A 2-tuple containing:
3681 - size_t: Pointer to store the minimum value.
3682 - size_t: Pointer to store the maximum value.
3684 .. seealso:: `cuFileGetParameterMinMaxValue`
3685 """
3686 cdef size_t min_value
3687 cdef size_t max_value
3688 with nogil: 1M
3689 __status__ = cuFileGetParameterMinMaxValue(<_SizeTConfigParameter>param, &min_value, &max_value) 1M
3690 check_status(__status__) 1M
3691 return (min_value, max_value) 1M
3694cpdef set_stats_level(int level):
3695 """Set the level of statistics collection for cuFile operations. This will override the cufile.json settings for stats.
3698 Args:
3699 level (int): Statistics level (0 = disabled, 1 = basic, 2 =
3700 detailed, 3 = verbose).
3702 .. note::
3703 Higher stats levels may impact performance. Level 0 disables statistics.
3704 .. note::
3705 Changes to stats level take effect for future operations.
3706 .. seealso:: `cuFileSetStatsLevel`
3707 """
3708 with nogil: 1eubvcwoyzA
3709 __status__ = cuFileSetStatsLevel(level) 1eubvcwoyzA
3710 check_status(__status__) 1eubvcwoyzA
3713cpdef int get_stats_level() except? 0:
3714 """Get the current level of statistics collection for cuFile operations.
3717 Returns:
3718 int: Pointer to store the current statistics level.
3720 .. seealso:: `cuFileGetStatsLevel`
3721 """
3722 cdef int level
3723 with nogil: 1BCtoDE
3724 __status__ = cuFileGetStatsLevel(&level) 1BCtoDE
3725 check_status(__status__) 1BCtoDE
3726 return level 1BCtoDE
3729cpdef stats_start():
3730 """Start collecting cuFile statistics.
3733 .. note::
3734 Statistics level must be set using cuFileSetStatsLevel before calling this
3735 function.
3736 .. seealso:: `cuFileStatsStart`
3737 """
3738 with nogil: 1ebcz
3739 __status__ = cuFileStatsStart() 1ebcz
3740 check_status(__status__) 1ebcz
3743cpdef stats_stop():
3744 """Stop collecting cuFile statistics.
3747 .. seealso:: `cuFileStatsStop`
3748 """
3749 with nogil: 1ebcz
3750 __status__ = cuFileStatsStop() 1ebcz
3751 check_status(__status__) 1ebcz
3754cpdef stats_reset():
3755 """Reset all cuFile statistics counters.
3758 .. seealso:: `cuFileStatsReset`
3759 """
3760 with nogil: 1uvwyA
3761 __status__ = cuFileStatsReset() 1uvwyA
3762 check_status(__status__) 1uvwyA
3765cpdef get_stats_l1(stats):
3766 """Get Level 1 cuFile statistics.
3769 Args:
3770 stats (intptr_t): Pointer to ``CUfileStatsLevel1_t`` structure to
3771 be filled.
3773 .. seealso:: `cuFileGetStatsL1`
3774 """
3775 cdef intptr_t _stats_ptr_ = int(stats) 1e
3776 with nogil: 1e
3777 __status__ = cuFileGetStatsL1(<CUfileStatsLevel1_t*>_stats_ptr_) 1e
3778 check_status(__status__) 1e
3781cpdef get_stats_l2(stats):
3782 """Get Level 2 cuFile statistics.
3785 Args:
3786 stats (intptr_t): Pointer to ``CUfileStatsLevel2_t`` structure to
3787 be filled.
3789 .. seealso:: `cuFileGetStatsL2`
3790 """
3791 cdef intptr_t _stats_ptr_ = int(stats) 1b
3792 with nogil: 1b
3793 __status__ = cuFileGetStatsL2(<CUfileStatsLevel2_t*>_stats_ptr_) 1b
3794 check_status(__status__) 1b
3797cpdef get_stats_l3(stats):
3798 """Get Level 3 cuFile statistics.
3801 Args:
3802 stats (intptr_t): Pointer to ``CUfileStatsLevel3_t`` structure to
3803 be filled.
3805 .. seealso:: `cuFileGetStatsL3`
3806 """
3807 cdef intptr_t _stats_ptr_ = int(stats) 1c
3808 with nogil: 1c
3809 __status__ = cuFileGetStatsL3(<CUfileStatsLevel3_t*>_stats_ptr_) 1c
3810 check_status(__status__) 1c
3813cpdef size_t get_bar_size_in_kb(int gpu_index) except? 0:
3814 cdef size_t bar_size
3815 with nogil: 1L
3816 __status__ = cuFileGetBARSizeInKB(gpu_index, &bar_size) 1L
3817 check_status(__status__) 1L
3818 return bar_size 1L
3821cpdef set_parameter_posix_pool_slab_array(intptr_t size_values, intptr_t count_values, int len):
3822 """Set both POSIX pool slab size and count parameters as a pair.
3825 Args:
3826 size_values (intptr_t): Array of slab sizes in KB.
3827 count_values (intptr_t): Array of slab counts.
3828 len (int): Length of both arrays (must be the same).
3830 .. seealso:: `cuFileSetParameterPosixPoolSlabArray`
3831 """
3832 with nogil: 1K
3833 __status__ = cuFileSetParameterPosixPoolSlabArray(<const size_t*>size_values, <const size_t*>count_values, len) 1K
3834 check_status(__status__) 1K
3837cpdef get_parameter_posix_pool_slab_array(intptr_t size_values, intptr_t count_values, int len):
3838 """Get both POSIX pool slab size and count parameters as a pair.
3841 Args:
3842 size_values (intptr_t): Buffer to receive slab sizes in KB.
3843 count_values (intptr_t): Buffer to receive slab counts.
3844 len (int): Buffer size (must match the actual parameter length).
3846 .. seealso:: `cuFileGetParameterPosixPoolSlabArray`
3847 """
3848 with nogil: 1x
3849 __status__ = cuFileGetParameterPosixPoolSlabArray(<size_t*>size_values, <size_t*>count_values, len) 1x
3850 check_status(__status__) 1x
3855cpdef str op_status_error(int status):
3856 """cufileop status string.
3858 Args:
3859 status (OpError): the error status to query.
3861 .. seealso:: `cufileop_status_error`
3862 """
3863 cdef bytes _output_
3864 _output_ = cufileop_status_error(<_OpError>status) 1qno
3865 return _output_.decode() 1qno
3868cpdef driver_close():
3869 """reset the cuFile library and release the nvidia-fs driver
3870 """
3871 with nogil: 1OQSUWY02468!$')+-uvtw/psnx:yA
3872 status = cuFileDriverClose_v2() 1OQSUWY02468!$')+-uvtw/psnx:yA
3873 check_status(status) 1OQSUWY02468!$')+-uvtw/psnx:yA
3875cpdef read(intptr_t fh, intptr_t buf_ptr_base, size_t size, off_t file_offset, off_t buf_ptr_offset):
3876 """read data from a registered file handle to a specified device or host memory.
3878 Args:
3879 fh (intptr_t): ``CUfileHandle_t`` opaque file handle.
3880 buf_ptr_base (intptr_t): base address of buffer in device or host memory.
3881 size (size_t): size bytes to read.
3882 file_offset (off_t): file-offset from begining of the file.
3883 buf_ptr_offset (off_t): offset relative to the buf_ptr_base pointer to read into.
3885 Returns:
3886 ssize_t: number of bytes read on success.
3888 .. seealso:: `cuFileRead`
3889 """
3890 with nogil: 1jklebc
3891 status = cuFileRead(<Handle>fh, <void*>buf_ptr_base, size, file_offset, buf_ptr_offset) 1jklebc
3892 check_status(status) 1jklebc
3893 return status 1jklebc
3896cpdef write(intptr_t fh, intptr_t buf_ptr_base, size_t size, off_t file_offset, off_t buf_ptr_offset):
3897 """write data from a specified device or host memory to a registered file handle.
3899 Args:
3900 fh (intptr_t): ``CUfileHandle_t`` opaque file handle.
3901 buf_ptr_base (intptr_t): base address of buffer in device or host memory.
3902 size (size_t): size bytes to write.
3903 file_offset (off_t): file-offset from begining of the file.
3904 buf_ptr_offset (off_t): offset relative to the buf_ptr_base pointer to write from.
3906 Returns:
3907 ssize_t: number of bytes written on success.
3909 .. seealso:: `cuFileWrite`
3910 """
3911 with nogil: 1jklebc
3912 status = cuFileWrite(<Handle>fh, <const void*>buf_ptr_base, size, file_offset, buf_ptr_offset) 1jklebc
3913 check_status(status) 1jklebc
3914 return status 1jklebc
3917cpdef readv(intptr_t fh, IOVec iov, off_t file_offset, unsigned int flags=0):
3918 """Read data from a registered file handle into a scatter list of device or host buffers.
3920 Args:
3921 fh (intptr_t): ``CUfileHandle_t`` opaque file handle.
3922 iov (IOVec): scatter/gather descriptor array; each element specifies a
3923 base pointer (device or host) and a byte length.
3924 file_offset (off_t): file offset from the beginning of the file.
3925 flags (unsigned int): reserved; must be 0.
3927 Returns:
3928 ssize_t: number of bytes read on success.
3930 .. seealso:: `cuFileReadv`
3931 """
3932 cdef intptr_t iov_ptr = (<IOVec>iov)._get_ptr()
3933 cdef size_t iovcnt = len(iov)
3934 with nogil:
3935 status = cuFileReadv(<Handle>fh, <const CUfileIOVec_t*>iov_ptr, iovcnt, file_offset, flags)
3936 check_status(status)
3937 return status
3940cpdef writev(intptr_t fh, IOVec iov, off_t file_offset, unsigned int flags=0):
3941 """Write data to a registered file handle from a gather list of device or host buffers.
3943 Args:
3944 fh (intptr_t): ``CUfileHandle_t`` opaque file handle.
3945 iov (IOVec): scatter/gather descriptor array; each element specifies a
3946 base pointer (device or host) and a byte length.
3947 file_offset (off_t): file offset from the beginning of the file.
3948 flags (unsigned int): reserved; must be 0.
3950 Returns:
3951 ssize_t: number of bytes written on success.
3953 .. seealso:: `cuFileWritev`
3954 """
3955 cdef intptr_t iov_ptr = (<IOVec>iov)._get_ptr()
3956 cdef size_t iovcnt = len(iov)
3957 with nogil:
3958 status = cuFileWritev(<Handle>fh, <const CUfileIOVec_t*>iov_ptr, iovcnt, file_offset, flags)
3959 check_status(status)
3960 return status
3961del _cyb_FastEnum