Coverage for cuda / bindings / cufile.pyx: 32.58%
1544 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-29 01:27 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-29 01:27 +0000
1# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2#
3# SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE
4#
5# This code was automatically generated across versions from 12.9.1 to 13.2.0, generator version 0.3.1.dev1568+g289771de9.d20260413. Do not modify it directly.
7cimport cython # NOQA
8from libc cimport errno
9from ._internal.utils cimport (get_buffer_pointer, get_nested_resource_ptr,
10 nested_resource)
11from cuda.bindings._internal._fast_enum import FastEnum as _FastEnum
13import cython
15from cuda.bindings.driver import CUresult as pyCUresult
17from libc.stdlib cimport calloc, free, malloc
18from cython cimport view
19cimport cpython.buffer
20cimport cpython.memoryview
21cimport cpython
22from libc.string cimport memcmp, memcpy
23import numpy as _numpy
26cdef __from_data(data, dtype_name, expected_dtype, lowpp_type):
27 # _numpy.recarray is a subclass of _numpy.ndarray, so implicitly handled here.
28 if isinstance(data, lowpp_type):
29 return data
30 if not isinstance(data, _numpy.ndarray):
31 raise TypeError("data argument must be a NumPy ndarray")
32 if data.size != 1:
33 raise ValueError("data array must have a size of 1")
34 if data.dtype != expected_dtype:
35 raise ValueError(f"data array must be of dtype {dtype_name}")
36 return lowpp_type.from_ptr(data.ctypes.data, not data.flags.writeable, data)
39cdef __from_buffer(buffer, size, lowpp_type):
40 cdef Py_buffer view
41 if cpython.PyObject_GetBuffer(buffer, &view, cpython.PyBUF_SIMPLE) != 0:
42 raise TypeError("buffer argument does not support the buffer protocol")
43 try:
44 if view.itemsize != 1:
45 raise ValueError("buffer itemsize must be 1 byte")
46 if view.len != size:
47 raise ValueError(f"buffer length must be {size} bytes")
48 return lowpp_type.from_ptr(<intptr_t><void *>view.buf, not view.readonly, buffer)
49 finally:
50 cpython.PyBuffer_Release(&view)
53cdef __getbuffer(object self, cpython.Py_buffer *buffer, void *ptr, int size, bint readonly):
54 buffer.buf = <char *>ptr
55 buffer.format = 'b'
56 buffer.internal = NULL
57 buffer.itemsize = 1
58 buffer.len = size
59 buffer.ndim = 1
60 buffer.obj = self
61 buffer.readonly = readonly
62 buffer.shape = &buffer.len
63 buffer.strides = &buffer.itemsize
64 buffer.suboffsets = NULL
66###############################################################################
67# POD
68###############################################################################
70_py_anon_pod1_dtype = _numpy.dtype((
71 _numpy.dtype((_numpy.void, sizeof((<CUfileDescr_t*>NULL).handle))),
72 {
73 "fd": (_numpy.int32, 0),
74 "handle": (_numpy.intp, 0),
75 }
76 ))
78cdef class _py_anon_pod1:
79 """Empty-initialize an instance of `cuda_bindings_cufile__anon_pod1`.
82 .. seealso:: `cuda_bindings_cufile__anon_pod1`
83 """
84 cdef:
85 cuda_bindings_cufile__anon_pod1 *_ptr
86 object _owner
87 bint _owned
88 bint _readonly
90 def __init__(self):
91 self._ptr = <cuda_bindings_cufile__anon_pod1 *>calloc(1, sizeof((<CUfileDescr_t*>NULL).handle))
92 if self._ptr == NULL:
93 raise MemoryError("Error allocating _py_anon_pod1")
94 self._owner = None
95 self._owned = True
96 self._readonly = False
98 def __dealloc__(self):
99 cdef cuda_bindings_cufile__anon_pod1 *ptr
100 if self._owned and self._ptr != NULL:
101 ptr = self._ptr
102 self._ptr = NULL
103 free(ptr)
105 def __repr__(self):
106 return f"<{__name__}._py_anon_pod1 object at {hex(id(self))}>"
108 @property
109 def ptr(self):
110 """Get the pointer address to the data as Python :class:`int`."""
111 return <intptr_t>(self._ptr)
113 cdef intptr_t _get_ptr(self):
114 return <intptr_t>(self._ptr)
116 def __int__(self):
117 return <intptr_t>(self._ptr)
119 def __eq__(self, other):
120 cdef _py_anon_pod1 other_
121 if not isinstance(other, _py_anon_pod1):
122 return False
123 other_ = other
124 return (memcmp(<void *><intptr_t>(self._ptr), <void *><intptr_t>(other_._ptr), sizeof((<CUfileDescr_t*>NULL).handle)) == 0)
126 def __getbuffer__(self, Py_buffer *buffer, int flags):
127 __getbuffer(self, buffer, <void *>self._ptr, sizeof((<CUfileDescr_t*>NULL).handle), self._readonly)
129 def __releasebuffer__(self, Py_buffer *buffer):
130 pass
132 def __setitem__(self, key, val):
133 if key == 0 and isinstance(val, _numpy.ndarray):
134 self._ptr = <cuda_bindings_cufile__anon_pod1 *>malloc(sizeof((<CUfileDescr_t*>NULL).handle))
135 if self._ptr == NULL:
136 raise MemoryError("Error allocating _py_anon_pod1")
137 memcpy(<void*>self._ptr, <void*><intptr_t>val.ctypes.data, sizeof((<CUfileDescr_t*>NULL).handle))
138 self._owner = None
139 self._owned = True
140 self._readonly = not val.flags.writeable
141 else:
142 setattr(self, key, val)
144 @property
145 def fd(self):
146 """int: """
147 return self._ptr[0].fd
149 @fd.setter
150 def fd(self, val):
151 if self._readonly:
152 raise ValueError("This _py_anon_pod1 instance is read-only")
153 self._ptr[0].fd = val
155 @property
156 def handle(self):
157 """int: """
158 return <intptr_t>(self._ptr[0].handle)
160 @handle.setter
161 def handle(self, val):
162 if self._readonly:
163 raise ValueError("This _py_anon_pod1 instance is read-only")
164 self._ptr[0].handle = <void *><intptr_t>val
166 @staticmethod
167 def from_buffer(buffer):
168 """Create an _py_anon_pod1 instance with the memory from the given buffer."""
169 return __from_buffer(buffer, sizeof((<CUfileDescr_t*>NULL).handle), _py_anon_pod1)
171 @staticmethod
172 def from_data(data):
173 """Create an _py_anon_pod1 instance wrapping the given NumPy array.
175 Args:
176 data (_numpy.ndarray): a single-element array of dtype `_py_anon_pod1_dtype` holding the data.
177 """
178 return __from_data(data, "_py_anon_pod1_dtype", _py_anon_pod1_dtype, _py_anon_pod1)
180 @staticmethod
181 def from_ptr(intptr_t ptr, bint readonly=False, object owner=None):
182 """Create an _py_anon_pod1 instance wrapping the given pointer.
184 Args:
185 ptr (intptr_t): pointer address as Python :class:`int` to the data.
186 owner (object): The Python object that owns the pointer. If not provided, data will be copied.
187 readonly (bool): whether the data is read-only (to the user). default is `False`.
188 """
189 if ptr == 0:
190 raise ValueError("ptr must not be null (0)")
191 cdef _py_anon_pod1 obj = _py_anon_pod1.__new__(_py_anon_pod1)
192 if owner is None:
193 obj._ptr = <cuda_bindings_cufile__anon_pod1 *>malloc(sizeof((<CUfileDescr_t*>NULL).handle))
194 if obj._ptr == NULL:
195 raise MemoryError("Error allocating _py_anon_pod1")
196 memcpy(<void*>(obj._ptr), <void*>ptr, sizeof((<CUfileDescr_t*>NULL).handle))
197 obj._owner = None
198 obj._owned = True
199 else:
200 obj._ptr = <cuda_bindings_cufile__anon_pod1 *>ptr
201 obj._owner = owner
202 obj._owned = False
203 obj._readonly = readonly
204 return obj
207cdef _get__py_anon_pod3_dtype_offsets():
208 cdef cuda_bindings_cufile__anon_pod3 pod = cuda_bindings_cufile__anon_pod3()
209 return _numpy.dtype({
210 'names': ['dev_ptr_base', 'file_offset', 'dev_ptr_offset', 'size_'],
211 'formats': [_numpy.intp, _numpy.int64, _numpy.int64, _numpy.uint64],
212 'offsets': [
213 (<intptr_t>&(pod.devPtr_base)) - (<intptr_t>&pod),
214 (<intptr_t>&(pod.file_offset)) - (<intptr_t>&pod),
215 (<intptr_t>&(pod.devPtr_offset)) - (<intptr_t>&pod),
216 (<intptr_t>&(pod.size)) - (<intptr_t>&pod),
217 ],
218 'itemsize': sizeof((<CUfileIOParams_t*>NULL).u.batch),
219 })
221_py_anon_pod3_dtype = _get__py_anon_pod3_dtype_offsets()
223cdef class _py_anon_pod3:
224 """Empty-initialize an instance of `cuda_bindings_cufile__anon_pod3`.
227 .. seealso:: `cuda_bindings_cufile__anon_pod3`
228 """
229 cdef:
230 cuda_bindings_cufile__anon_pod3 *_ptr
231 object _owner
232 bint _owned
233 bint _readonly
235 def __init__(self):
236 self._ptr = <cuda_bindings_cufile__anon_pod3 *>calloc(1, sizeof((<CUfileIOParams_t*>NULL).u.batch))
237 if self._ptr == NULL:
238 raise MemoryError("Error allocating _py_anon_pod3")
239 self._owner = None
240 self._owned = True
241 self._readonly = False
243 def __dealloc__(self):
244 cdef cuda_bindings_cufile__anon_pod3 *ptr
245 if self._owned and self._ptr != NULL:
246 ptr = self._ptr
247 self._ptr = NULL
248 free(ptr)
250 def __repr__(self):
251 return f"<{__name__}._py_anon_pod3 object at {hex(id(self))}>"
253 @property
254 def ptr(self):
255 """Get the pointer address to the data as Python :class:`int`."""
256 return <intptr_t>(self._ptr)
258 cdef intptr_t _get_ptr(self):
259 return <intptr_t>(self._ptr)
261 def __int__(self):
262 return <intptr_t>(self._ptr)
264 def __eq__(self, other):
265 cdef _py_anon_pod3 other_
266 if not isinstance(other, _py_anon_pod3):
267 return False
268 other_ = other
269 return (memcmp(<void *><intptr_t>(self._ptr), <void *><intptr_t>(other_._ptr), sizeof((<CUfileIOParams_t*>NULL).u.batch)) == 0)
271 def __getbuffer__(self, Py_buffer *buffer, int flags):
272 __getbuffer(self, buffer, <void *>self._ptr, sizeof((<CUfileIOParams_t*>NULL).u.batch), self._readonly)
274 def __releasebuffer__(self, Py_buffer *buffer):
275 pass
277 def __setitem__(self, key, val):
278 if key == 0 and isinstance(val, _numpy.ndarray):
279 self._ptr = <cuda_bindings_cufile__anon_pod3 *>malloc(sizeof((<CUfileIOParams_t*>NULL).u.batch))
280 if self._ptr == NULL:
281 raise MemoryError("Error allocating _py_anon_pod3")
282 memcpy(<void*>self._ptr, <void*><intptr_t>val.ctypes.data, sizeof((<CUfileIOParams_t*>NULL).u.batch))
283 self._owner = None
284 self._owned = True
285 self._readonly = not val.flags.writeable
286 else:
287 setattr(self, key, val)
289 @property
290 def dev_ptr_base(self):
291 """int: """
292 return <intptr_t>(self._ptr[0].devPtr_base)
294 @dev_ptr_base.setter
295 def dev_ptr_base(self, val):
296 if self._readonly:
297 raise ValueError("This _py_anon_pod3 instance is read-only")
298 self._ptr[0].devPtr_base = <void *><intptr_t>val
300 @property
301 def file_offset(self):
302 """int: """
303 return self._ptr[0].file_offset
305 @file_offset.setter
306 def file_offset(self, val):
307 if self._readonly:
308 raise ValueError("This _py_anon_pod3 instance is read-only")
309 self._ptr[0].file_offset = val
311 @property
312 def dev_ptr_offset(self):
313 """int: """
314 return self._ptr[0].devPtr_offset
316 @dev_ptr_offset.setter
317 def dev_ptr_offset(self, val):
318 if self._readonly:
319 raise ValueError("This _py_anon_pod3 instance is read-only")
320 self._ptr[0].devPtr_offset = val
322 @property
323 def size_(self):
324 """int: """
325 return self._ptr[0].size
327 @size_.setter
328 def size_(self, val):
329 if self._readonly:
330 raise ValueError("This _py_anon_pod3 instance is read-only")
331 self._ptr[0].size = val
333 @staticmethod
334 def from_buffer(buffer):
335 """Create an _py_anon_pod3 instance with the memory from the given buffer."""
336 return __from_buffer(buffer, sizeof((<CUfileIOParams_t*>NULL).u.batch), _py_anon_pod3)
338 @staticmethod
339 def from_data(data):
340 """Create an _py_anon_pod3 instance wrapping the given NumPy array.
342 Args:
343 data (_numpy.ndarray): a single-element array of dtype `_py_anon_pod3_dtype` holding the data.
344 """
345 return __from_data(data, "_py_anon_pod3_dtype", _py_anon_pod3_dtype, _py_anon_pod3)
347 @staticmethod
348 def from_ptr(intptr_t ptr, bint readonly=False, object owner=None):
349 """Create an _py_anon_pod3 instance wrapping the given pointer.
351 Args:
352 ptr (intptr_t): pointer address as Python :class:`int` to the data.
353 owner (object): The Python object that owns the pointer. If not provided, data will be copied.
354 readonly (bool): whether the data is read-only (to the user). default is `False`.
355 """
356 if ptr == 0:
357 raise ValueError("ptr must not be null (0)")
358 cdef _py_anon_pod3 obj = _py_anon_pod3.__new__(_py_anon_pod3)
359 if owner is None:
360 obj._ptr = <cuda_bindings_cufile__anon_pod3 *>malloc(sizeof((<CUfileIOParams_t*>NULL).u.batch))
361 if obj._ptr == NULL:
362 raise MemoryError("Error allocating _py_anon_pod3")
363 memcpy(<void*>(obj._ptr), <void*>ptr, sizeof((<CUfileIOParams_t*>NULL).u.batch))
364 obj._owner = None
365 obj._owned = True
366 else:
367 obj._ptr = <cuda_bindings_cufile__anon_pod3 *>ptr
368 obj._owner = owner
369 obj._owned = False
370 obj._readonly = readonly
371 return obj
374cdef _get_io_events_dtype_offsets():
375 cdef CUfileIOEvents_t pod = CUfileIOEvents_t()
376 return _numpy.dtype({
377 'names': ['cookie', 'status', 'ret'],
378 'formats': [_numpy.intp, _numpy.int32, _numpy.uint64],
379 'offsets': [
380 (<intptr_t>&(pod.cookie)) - (<intptr_t>&pod),
381 (<intptr_t>&(pod.status)) - (<intptr_t>&pod),
382 (<intptr_t>&(pod.ret)) - (<intptr_t>&pod),
383 ],
384 'itemsize': sizeof(CUfileIOEvents_t),
385 })
387io_events_dtype = _get_io_events_dtype_offsets()
389cdef class IOEvents:
390 """Empty-initialize an array of `CUfileIOEvents_t`.
391 The resulting object is of length `size` and of dtype `io_events_dtype`.
392 If default-constructed, the instance represents a single struct.
394 Args:
395 size (int): number of structs, default=1.
397 .. seealso:: `CUfileIOEvents_t`
398 """
399 cdef:
400 readonly object _data
402 def __init__(self, size=1):
403 arr = _numpy.empty(size, dtype=io_events_dtype)
404 self._data = arr.view(_numpy.recarray)
405 assert self._data.itemsize == sizeof(CUfileIOEvents_t), \
406 f"itemsize {self._data.itemsize} mismatches struct size { sizeof(CUfileIOEvents_t) }"
408 def __repr__(self):
409 if self._data.size > 1:
410 return f"<{__name__}.IOEvents_Array_{self._data.size} object at {hex(id(self))}>"
411 else:
412 return f"<{__name__}.IOEvents object at {hex(id(self))}>"
414 @property
415 def ptr(self):
416 """Get the pointer address to the data as Python :class:`int`."""
417 return self._data.ctypes.data
419 cdef intptr_t _get_ptr(self):
420 return self._data.ctypes.data
422 def __int__(self):
423 if self._data.size > 1:
424 raise TypeError("int() argument must be a bytes-like object of size 1. "
425 "To get the pointer address of an array, use .ptr")
426 return self._data.ctypes.data
428 def __len__(self):
429 return self._data.size
431 def __eq__(self, other):
432 cdef object self_data = self._data
433 if (not isinstance(other, IOEvents)) or self_data.size != other._data.size or self_data.dtype != other._data.dtype:
434 return False
435 return bool((self_data == other._data).all())
437 def __getbuffer__(self, Py_buffer *buffer, int flags):
438 cpython.PyObject_GetBuffer(self._data, buffer, flags)
440 def __releasebuffer__(self, Py_buffer *buffer):
441 cpython.PyBuffer_Release(buffer)
443 @property
444 def cookie(self):
445 """Union[~_numpy.intp, int]: """
446 if self._data.size == 1:
447 return int(self._data.cookie[0])
448 return self._data.cookie
450 @cookie.setter
451 def cookie(self, val):
452 self._data.cookie = val
454 @property
455 def status(self):
456 """Union[~_numpy.int32, int]: """
457 if self._data.size == 1:
458 return int(self._data.status[0])
459 return self._data.status
461 @status.setter
462 def status(self, val):
463 self._data.status = val
465 @property
466 def ret(self):
467 """Union[~_numpy.uint64, int]: """
468 if self._data.size == 1:
469 return int(self._data.ret[0])
470 return self._data.ret
472 @ret.setter
473 def ret(self, val):
474 self._data.ret = val
476 def __getitem__(self, key):
477 cdef ssize_t key_
478 cdef ssize_t size
479 if isinstance(key, int):
480 key_ = key
481 size = self._data.size
482 if key_ >= size or key_ <= -(size+1):
483 raise IndexError("index is out of bounds")
484 if key_ < 0:
485 key_ += size
486 return IOEvents.from_data(self._data[key_:key_+1])
487 out = self._data[key]
488 if isinstance(out, _numpy.recarray) and out.dtype == io_events_dtype:
489 return IOEvents.from_data(out)
490 return out
492 def __setitem__(self, key, val):
493 self._data[key] = val
495 @staticmethod
496 def from_buffer(buffer):
497 """Create an IOEvents instance with the memory from the given buffer."""
498 return IOEvents.from_data(_numpy.frombuffer(buffer, dtype=io_events_dtype))
500 @staticmethod
501 def from_data(data):
502 """Create an IOEvents instance wrapping the given NumPy array.
504 Args:
505 data (_numpy.ndarray): a 1D array of dtype `io_events_dtype` holding the data.
506 """
507 cdef IOEvents obj = IOEvents.__new__(IOEvents)
508 if not isinstance(data, _numpy.ndarray):
509 raise TypeError("data argument must be a NumPy ndarray")
510 if data.ndim != 1:
511 raise ValueError("data array must be 1D")
512 if data.dtype != io_events_dtype:
513 raise ValueError("data array must be of dtype io_events_dtype")
514 obj._data = data.view(_numpy.recarray)
516 return obj
518 @staticmethod
519 def from_ptr(intptr_t ptr, size_t size=1, bint readonly=False):
520 """Create an IOEvents instance wrapping the given pointer.
522 Args:
523 ptr (intptr_t): pointer address as Python :class:`int` to the data.
524 size (int): number of structs, default=1.
525 readonly (bool): whether the data is read-only (to the user). default is `False`.
526 """
527 if ptr == 0:
528 raise ValueError("ptr must not be null (0)")
529 cdef IOEvents obj = IOEvents.__new__(IOEvents)
530 cdef flag = cpython.buffer.PyBUF_READ if readonly else cpython.buffer.PyBUF_WRITE
531 cdef object buf = cpython.memoryview.PyMemoryView_FromMemory(
532 <char*>ptr, sizeof(CUfileIOEvents_t) * size, flag)
533 data = _numpy.ndarray(size, buffer=buf, dtype=io_events_dtype)
534 obj._data = data.view(_numpy.recarray)
536 return obj
539cdef _get_op_counter_dtype_offsets():
540 cdef CUfileOpCounter_t pod = CUfileOpCounter_t()
541 return _numpy.dtype({
542 'names': ['ok', 'err'],
543 'formats': [_numpy.uint64, _numpy.uint64],
544 'offsets': [
545 (<intptr_t>&(pod.ok)) - (<intptr_t>&pod),
546 (<intptr_t>&(pod.err)) - (<intptr_t>&pod),
547 ],
548 'itemsize': sizeof(CUfileOpCounter_t),
549 })
551op_counter_dtype = _get_op_counter_dtype_offsets()
553cdef class OpCounter:
554 """Empty-initialize an instance of `CUfileOpCounter_t`.
557 .. seealso:: `CUfileOpCounter_t`
558 """
559 cdef:
560 CUfileOpCounter_t *_ptr
561 object _owner
562 bint _owned
563 bint _readonly
565 def __init__(self):
566 self._ptr = <CUfileOpCounter_t *>calloc(1, sizeof(CUfileOpCounter_t))
567 if self._ptr == NULL:
568 raise MemoryError("Error allocating OpCounter")
569 self._owner = None
570 self._owned = True
571 self._readonly = False
573 def __dealloc__(self):
574 cdef CUfileOpCounter_t *ptr
575 if self._owned and self._ptr != NULL:
576 ptr = self._ptr
577 self._ptr = NULL
578 free(ptr)
580 def __repr__(self):
581 return f"<{__name__}.OpCounter object at {hex(id(self))}>"
583 @property
584 def ptr(self):
585 """Get the pointer address to the data as Python :class:`int`."""
586 return <intptr_t>(self._ptr)
588 cdef intptr_t _get_ptr(self):
589 return <intptr_t>(self._ptr)
591 def __int__(self):
592 return <intptr_t>(self._ptr)
594 def __eq__(self, other):
595 cdef OpCounter other_
596 if not isinstance(other, OpCounter):
597 return False
598 other_ = other
599 return (memcmp(<void *><intptr_t>(self._ptr), <void *><intptr_t>(other_._ptr), sizeof(CUfileOpCounter_t)) == 0)
601 def __getbuffer__(self, Py_buffer *buffer, int flags):
602 __getbuffer(self, buffer, <void *>self._ptr, sizeof(CUfileOpCounter_t), self._readonly)
604 def __releasebuffer__(self, Py_buffer *buffer):
605 pass
607 def __setitem__(self, key, val):
608 if key == 0 and isinstance(val, _numpy.ndarray):
609 self._ptr = <CUfileOpCounter_t *>malloc(sizeof(CUfileOpCounter_t))
610 if self._ptr == NULL:
611 raise MemoryError("Error allocating OpCounter")
612 memcpy(<void*>self._ptr, <void*><intptr_t>val.ctypes.data, sizeof(CUfileOpCounter_t))
613 self._owner = None
614 self._owned = True
615 self._readonly = not val.flags.writeable
616 else:
617 setattr(self, key, val)
619 @property
620 def ok(self):
621 """int: """
622 return self._ptr[0].ok
624 @ok.setter
625 def ok(self, val):
626 if self._readonly:
627 raise ValueError("This OpCounter instance is read-only")
628 self._ptr[0].ok = val
630 @property
631 def err(self):
632 """int: """
633 return self._ptr[0].err
635 @err.setter
636 def err(self, val):
637 if self._readonly:
638 raise ValueError("This OpCounter instance is read-only")
639 self._ptr[0].err = val
641 @staticmethod
642 def from_buffer(buffer):
643 """Create an OpCounter instance with the memory from the given buffer."""
644 return __from_buffer(buffer, sizeof(CUfileOpCounter_t), OpCounter)
646 @staticmethod
647 def from_data(data):
648 """Create an OpCounter instance wrapping the given NumPy array.
650 Args:
651 data (_numpy.ndarray): a single-element array of dtype `op_counter_dtype` holding the data.
652 """
653 return __from_data(data, "op_counter_dtype", op_counter_dtype, OpCounter)
655 @staticmethod
656 def from_ptr(intptr_t ptr, bint readonly=False, object owner=None):
657 """Create an OpCounter instance wrapping the given pointer.
659 Args:
660 ptr (intptr_t): pointer address as Python :class:`int` to the data.
661 owner (object): The Python object that owns the pointer. If not provided, data will be copied.
662 readonly (bool): whether the data is read-only (to the user). default is `False`.
663 """
664 if ptr == 0:
665 raise ValueError("ptr must not be null (0)")
666 cdef OpCounter obj = OpCounter.__new__(OpCounter)
667 if owner is None:
668 obj._ptr = <CUfileOpCounter_t *>malloc(sizeof(CUfileOpCounter_t))
669 if obj._ptr == NULL:
670 raise MemoryError("Error allocating OpCounter")
671 memcpy(<void*>(obj._ptr), <void*>ptr, sizeof(CUfileOpCounter_t))
672 obj._owner = None
673 obj._owned = True
674 else:
675 obj._ptr = <CUfileOpCounter_t *>ptr
676 obj._owner = owner
677 obj._owned = False
678 obj._readonly = readonly
679 return obj
682cdef _get_per_gpu_stats_dtype_offsets():
683 cdef CUfilePerGpuStats_t pod = CUfilePerGpuStats_t()
684 return _numpy.dtype({
685 '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'],
686 '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],
687 'offsets': [
688 (<intptr_t>&(pod.uuid)) - (<intptr_t>&pod),
689 (<intptr_t>&(pod.read_bytes)) - (<intptr_t>&pod),
690 (<intptr_t>&(pod.read_bw_bytes_per_sec)) - (<intptr_t>&pod),
691 (<intptr_t>&(pod.read_utilization)) - (<intptr_t>&pod),
692 (<intptr_t>&(pod.read_duration_us)) - (<intptr_t>&pod),
693 (<intptr_t>&(pod.n_total_reads)) - (<intptr_t>&pod),
694 (<intptr_t>&(pod.n_p2p_reads)) - (<intptr_t>&pod),
695 (<intptr_t>&(pod.n_nvfs_reads)) - (<intptr_t>&pod),
696 (<intptr_t>&(pod.n_posix_reads)) - (<intptr_t>&pod),
697 (<intptr_t>&(pod.n_unaligned_reads)) - (<intptr_t>&pod),
698 (<intptr_t>&(pod.n_dr_reads)) - (<intptr_t>&pod),
699 (<intptr_t>&(pod.n_sparse_regions)) - (<intptr_t>&pod),
700 (<intptr_t>&(pod.n_inline_regions)) - (<intptr_t>&pod),
701 (<intptr_t>&(pod.n_reads_err)) - (<intptr_t>&pod),
702 (<intptr_t>&(pod.writes_bytes)) - (<intptr_t>&pod),
703 (<intptr_t>&(pod.write_bw_bytes_per_sec)) - (<intptr_t>&pod),
704 (<intptr_t>&(pod.write_utilization)) - (<intptr_t>&pod),
705 (<intptr_t>&(pod.write_duration_us)) - (<intptr_t>&pod),
706 (<intptr_t>&(pod.n_total_writes)) - (<intptr_t>&pod),
707 (<intptr_t>&(pod.n_p2p_writes)) - (<intptr_t>&pod),
708 (<intptr_t>&(pod.n_nvfs_writes)) - (<intptr_t>&pod),
709 (<intptr_t>&(pod.n_posix_writes)) - (<intptr_t>&pod),
710 (<intptr_t>&(pod.n_unaligned_writes)) - (<intptr_t>&pod),
711 (<intptr_t>&(pod.n_dr_writes)) - (<intptr_t>&pod),
712 (<intptr_t>&(pod.n_writes_err)) - (<intptr_t>&pod),
713 (<intptr_t>&(pod.n_mmap)) - (<intptr_t>&pod),
714 (<intptr_t>&(pod.n_mmap_ok)) - (<intptr_t>&pod),
715 (<intptr_t>&(pod.n_mmap_err)) - (<intptr_t>&pod),
716 (<intptr_t>&(pod.n_mmap_free)) - (<intptr_t>&pod),
717 (<intptr_t>&(pod.reg_bytes)) - (<intptr_t>&pod),
718 ],
719 'itemsize': sizeof(CUfilePerGpuStats_t),
720 })
722per_gpu_stats_dtype = _get_per_gpu_stats_dtype_offsets()
724cdef class PerGpuStats:
725 """Empty-initialize an array of `CUfilePerGpuStats_t`.
726 The resulting object is of length `size` and of dtype `per_gpu_stats_dtype`.
727 If default-constructed, the instance represents a single struct.
729 Args:
730 size (int): number of structs, default=1.
732 .. seealso:: `CUfilePerGpuStats_t`
733 """
734 cdef:
735 readonly object _data
737 def __init__(self, size=1):
738 arr = _numpy.empty(size, dtype=per_gpu_stats_dtype)
739 self._data = arr.view(_numpy.recarray)
740 assert self._data.itemsize == sizeof(CUfilePerGpuStats_t), \
741 f"itemsize {self._data.itemsize} mismatches struct size { sizeof(CUfilePerGpuStats_t) }"
743 def __repr__(self):
744 if self._data.size > 1:
745 return f"<{__name__}.PerGpuStats_Array_{self._data.size} object at {hex(id(self))}>"
746 else:
747 return f"<{__name__}.PerGpuStats object at {hex(id(self))}>"
749 @property
750 def ptr(self):
751 """Get the pointer address to the data as Python :class:`int`."""
752 return self._data.ctypes.data
754 cdef intptr_t _get_ptr(self):
755 return self._data.ctypes.data
757 def __int__(self):
758 if self._data.size > 1:
759 raise TypeError("int() argument must be a bytes-like object of size 1. "
760 "To get the pointer address of an array, use .ptr")
761 return self._data.ctypes.data
763 def __len__(self):
764 return self._data.size
766 def __eq__(self, other):
767 cdef object self_data = self._data
768 if (not isinstance(other, PerGpuStats)) or self_data.size != other._data.size or self_data.dtype != other._data.dtype:
769 return False
770 return bool((self_data == other._data).all())
772 def __getbuffer__(self, Py_buffer *buffer, int flags):
773 cpython.PyObject_GetBuffer(self._data, buffer, flags)
775 def __releasebuffer__(self, Py_buffer *buffer):
776 cpython.PyBuffer_Release(buffer)
778 @property
779 def uuid(self):
780 """~_numpy.int8: (array of length 16)."""
781 return self._data.uuid
783 @uuid.setter
784 def uuid(self, val):
785 self._data.uuid = val
787 @property
788 def read_bytes(self):
789 """Union[~_numpy.uint64, int]: """
790 if self._data.size == 1:
791 return int(self._data.read_bytes[0])
792 return self._data.read_bytes
794 @read_bytes.setter
795 def read_bytes(self, val):
796 self._data.read_bytes = val
798 @property
799 def read_bw_bytes_per_sec(self):
800 """Union[~_numpy.uint64, int]: """
801 if self._data.size == 1:
802 return int(self._data.read_bw_bytes_per_sec[0])
803 return self._data.read_bw_bytes_per_sec
805 @read_bw_bytes_per_sec.setter
806 def read_bw_bytes_per_sec(self, val):
807 self._data.read_bw_bytes_per_sec = val
809 @property
810 def read_utilization(self):
811 """Union[~_numpy.uint64, int]: """
812 if self._data.size == 1:
813 return int(self._data.read_utilization[0])
814 return self._data.read_utilization
816 @read_utilization.setter
817 def read_utilization(self, val):
818 self._data.read_utilization = val
820 @property
821 def read_duration_us(self):
822 """Union[~_numpy.uint64, int]: """
823 if self._data.size == 1:
824 return int(self._data.read_duration_us[0])
825 return self._data.read_duration_us
827 @read_duration_us.setter
828 def read_duration_us(self, val):
829 self._data.read_duration_us = val
831 @property
832 def n_total_reads(self):
833 """Union[~_numpy.uint64, int]: """
834 if self._data.size == 1:
835 return int(self._data.n_total_reads[0])
836 return self._data.n_total_reads
838 @n_total_reads.setter
839 def n_total_reads(self, val):
840 self._data.n_total_reads = val
842 @property
843 def n_p2p_reads(self):
844 """Union[~_numpy.uint64, int]: """
845 if self._data.size == 1:
846 return int(self._data.n_p2p_reads[0])
847 return self._data.n_p2p_reads
849 @n_p2p_reads.setter
850 def n_p2p_reads(self, val):
851 self._data.n_p2p_reads = val
853 @property
854 def n_nvfs_reads(self):
855 """Union[~_numpy.uint64, int]: """
856 if self._data.size == 1:
857 return int(self._data.n_nvfs_reads[0])
858 return self._data.n_nvfs_reads
860 @n_nvfs_reads.setter
861 def n_nvfs_reads(self, val):
862 self._data.n_nvfs_reads = val
864 @property
865 def n_posix_reads(self):
866 """Union[~_numpy.uint64, int]: """
867 if self._data.size == 1:
868 return int(self._data.n_posix_reads[0])
869 return self._data.n_posix_reads
871 @n_posix_reads.setter
872 def n_posix_reads(self, val):
873 self._data.n_posix_reads = val
875 @property
876 def n_unaligned_reads(self):
877 """Union[~_numpy.uint64, int]: """
878 if self._data.size == 1:
879 return int(self._data.n_unaligned_reads[0])
880 return self._data.n_unaligned_reads
882 @n_unaligned_reads.setter
883 def n_unaligned_reads(self, val):
884 self._data.n_unaligned_reads = val
886 @property
887 def n_dr_reads(self):
888 """Union[~_numpy.uint64, int]: """
889 if self._data.size == 1:
890 return int(self._data.n_dr_reads[0])
891 return self._data.n_dr_reads
893 @n_dr_reads.setter
894 def n_dr_reads(self, val):
895 self._data.n_dr_reads = val
897 @property
898 def n_sparse_regions(self):
899 """Union[~_numpy.uint64, int]: """
900 if self._data.size == 1:
901 return int(self._data.n_sparse_regions[0])
902 return self._data.n_sparse_regions
904 @n_sparse_regions.setter
905 def n_sparse_regions(self, val):
906 self._data.n_sparse_regions = val
908 @property
909 def n_inline_regions(self):
910 """Union[~_numpy.uint64, int]: """
911 if self._data.size == 1:
912 return int(self._data.n_inline_regions[0])
913 return self._data.n_inline_regions
915 @n_inline_regions.setter
916 def n_inline_regions(self, val):
917 self._data.n_inline_regions = val
919 @property
920 def n_reads_err(self):
921 """Union[~_numpy.uint64, int]: """
922 if self._data.size == 1:
923 return int(self._data.n_reads_err[0])
924 return self._data.n_reads_err
926 @n_reads_err.setter
927 def n_reads_err(self, val):
928 self._data.n_reads_err = val
930 @property
931 def writes_bytes(self):
932 """Union[~_numpy.uint64, int]: """
933 if self._data.size == 1:
934 return int(self._data.writes_bytes[0])
935 return self._data.writes_bytes
937 @writes_bytes.setter
938 def writes_bytes(self, val):
939 self._data.writes_bytes = val
941 @property
942 def write_bw_bytes_per_sec(self):
943 """Union[~_numpy.uint64, int]: """
944 if self._data.size == 1:
945 return int(self._data.write_bw_bytes_per_sec[0])
946 return self._data.write_bw_bytes_per_sec
948 @write_bw_bytes_per_sec.setter
949 def write_bw_bytes_per_sec(self, val):
950 self._data.write_bw_bytes_per_sec = val
952 @property
953 def write_utilization(self):
954 """Union[~_numpy.uint64, int]: """
955 if self._data.size == 1:
956 return int(self._data.write_utilization[0])
957 return self._data.write_utilization
959 @write_utilization.setter
960 def write_utilization(self, val):
961 self._data.write_utilization = val
963 @property
964 def write_duration_us(self):
965 """Union[~_numpy.uint64, int]: """
966 if self._data.size == 1:
967 return int(self._data.write_duration_us[0])
968 return self._data.write_duration_us
970 @write_duration_us.setter
971 def write_duration_us(self, val):
972 self._data.write_duration_us = val
974 @property
975 def n_total_writes(self):
976 """Union[~_numpy.uint64, int]: """
977 if self._data.size == 1:
978 return int(self._data.n_total_writes[0])
979 return self._data.n_total_writes
981 @n_total_writes.setter
982 def n_total_writes(self, val):
983 self._data.n_total_writes = val
985 @property
986 def n_p2p_writes(self):
987 """Union[~_numpy.uint64, int]: """
988 if self._data.size == 1:
989 return int(self._data.n_p2p_writes[0])
990 return self._data.n_p2p_writes
992 @n_p2p_writes.setter
993 def n_p2p_writes(self, val):
994 self._data.n_p2p_writes = val
996 @property
997 def n_nvfs_writes(self):
998 """Union[~_numpy.uint64, int]: """
999 if self._data.size == 1:
1000 return int(self._data.n_nvfs_writes[0])
1001 return self._data.n_nvfs_writes
1003 @n_nvfs_writes.setter
1004 def n_nvfs_writes(self, val):
1005 self._data.n_nvfs_writes = val
1007 @property
1008 def n_posix_writes(self):
1009 """Union[~_numpy.uint64, int]: """
1010 if self._data.size == 1:
1011 return int(self._data.n_posix_writes[0])
1012 return self._data.n_posix_writes
1014 @n_posix_writes.setter
1015 def n_posix_writes(self, val):
1016 self._data.n_posix_writes = val
1018 @property
1019 def n_unaligned_writes(self):
1020 """Union[~_numpy.uint64, int]: """
1021 if self._data.size == 1:
1022 return int(self._data.n_unaligned_writes[0])
1023 return self._data.n_unaligned_writes
1025 @n_unaligned_writes.setter
1026 def n_unaligned_writes(self, val):
1027 self._data.n_unaligned_writes = val
1029 @property
1030 def n_dr_writes(self):
1031 """Union[~_numpy.uint64, int]: """
1032 if self._data.size == 1:
1033 return int(self._data.n_dr_writes[0])
1034 return self._data.n_dr_writes
1036 @n_dr_writes.setter
1037 def n_dr_writes(self, val):
1038 self._data.n_dr_writes = val
1040 @property
1041 def n_writes_err(self):
1042 """Union[~_numpy.uint64, int]: """
1043 if self._data.size == 1:
1044 return int(self._data.n_writes_err[0])
1045 return self._data.n_writes_err
1047 @n_writes_err.setter
1048 def n_writes_err(self, val):
1049 self._data.n_writes_err = val
1051 @property
1052 def n_mmap(self):
1053 """Union[~_numpy.uint64, int]: """
1054 if self._data.size == 1:
1055 return int(self._data.n_mmap[0])
1056 return self._data.n_mmap
1058 @n_mmap.setter
1059 def n_mmap(self, val):
1060 self._data.n_mmap = val
1062 @property
1063 def n_mmap_ok(self):
1064 """Union[~_numpy.uint64, int]: """
1065 if self._data.size == 1:
1066 return int(self._data.n_mmap_ok[0])
1067 return self._data.n_mmap_ok
1069 @n_mmap_ok.setter
1070 def n_mmap_ok(self, val):
1071 self._data.n_mmap_ok = val
1073 @property
1074 def n_mmap_err(self):
1075 """Union[~_numpy.uint64, int]: """
1076 if self._data.size == 1:
1077 return int(self._data.n_mmap_err[0])
1078 return self._data.n_mmap_err
1080 @n_mmap_err.setter
1081 def n_mmap_err(self, val):
1082 self._data.n_mmap_err = val
1084 @property
1085 def n_mmap_free(self):
1086 """Union[~_numpy.uint64, int]: """
1087 if self._data.size == 1:
1088 return int(self._data.n_mmap_free[0])
1089 return self._data.n_mmap_free
1091 @n_mmap_free.setter
1092 def n_mmap_free(self, val):
1093 self._data.n_mmap_free = val
1095 @property
1096 def reg_bytes(self):
1097 """Union[~_numpy.uint64, int]: """
1098 if self._data.size == 1:
1099 return int(self._data.reg_bytes[0])
1100 return self._data.reg_bytes
1102 @reg_bytes.setter
1103 def reg_bytes(self, val):
1104 self._data.reg_bytes = val
1106 def __getitem__(self, key):
1107 cdef ssize_t key_
1108 cdef ssize_t size
1109 if isinstance(key, int):
1110 key_ = key
1111 size = self._data.size
1112 if key_ >= size or key_ <= -(size+1):
1113 raise IndexError("index is out of bounds")
1114 if key_ < 0:
1115 key_ += size
1116 return PerGpuStats.from_data(self._data[key_:key_+1])
1117 out = self._data[key]
1118 if isinstance(out, _numpy.recarray) and out.dtype == per_gpu_stats_dtype:
1119 return PerGpuStats.from_data(out)
1120 return out
1122 def __setitem__(self, key, val):
1123 self._data[key] = val
1125 @staticmethod
1126 def from_buffer(buffer):
1127 """Create an PerGpuStats instance with the memory from the given buffer."""
1128 return PerGpuStats.from_data(_numpy.frombuffer(buffer, dtype=per_gpu_stats_dtype))
1130 @staticmethod
1131 def from_data(data):
1132 """Create an PerGpuStats instance wrapping the given NumPy array.
1134 Args:
1135 data (_numpy.ndarray): a 1D array of dtype `per_gpu_stats_dtype` holding the data.
1136 """
1137 cdef PerGpuStats obj = PerGpuStats.__new__(PerGpuStats)
1138 if not isinstance(data, _numpy.ndarray):
1139 raise TypeError("data argument must be a NumPy ndarray")
1140 if data.ndim != 1:
1141 raise ValueError("data array must be 1D")
1142 if data.dtype != per_gpu_stats_dtype:
1143 raise ValueError("data array must be of dtype per_gpu_stats_dtype")
1144 obj._data = data.view(_numpy.recarray)
1146 return obj
1148 @staticmethod
1149 def from_ptr(intptr_t ptr, size_t size=1, bint readonly=False):
1150 """Create an PerGpuStats instance wrapping the given pointer.
1152 Args:
1153 ptr (intptr_t): pointer address as Python :class:`int` to the data.
1154 size (int): number of structs, default=1.
1155 readonly (bool): whether the data is read-only (to the user). default is `False`.
1156 """
1157 if ptr == 0:
1158 raise ValueError("ptr must not be null (0)")
1159 cdef PerGpuStats obj = PerGpuStats.__new__(PerGpuStats)
1160 cdef flag = cpython.buffer.PyBUF_READ if readonly else cpython.buffer.PyBUF_WRITE
1161 cdef object buf = cpython.memoryview.PyMemoryView_FromMemory(
1162 <char*>ptr, sizeof(CUfilePerGpuStats_t) * size, flag)
1163 data = _numpy.ndarray(size, buffer=buf, dtype=per_gpu_stats_dtype)
1164 obj._data = data.view(_numpy.recarray)
1166 return obj
1169cdef _get_descr_dtype_offsets():
1170 cdef CUfileDescr_t pod = CUfileDescr_t()
1171 return _numpy.dtype({
1172 'names': ['type', 'handle', 'fs_ops'],
1173 'formats': [_numpy.int32, _py_anon_pod1_dtype, _numpy.intp],
1174 'offsets': [
1175 (<intptr_t>&(pod.type)) - (<intptr_t>&pod),
1176 (<intptr_t>&(pod.handle)) - (<intptr_t>&pod),
1177 (<intptr_t>&(pod.fs_ops)) - (<intptr_t>&pod),
1178 ],
1179 'itemsize': sizeof(CUfileDescr_t),
1180 })
1182descr_dtype = _get_descr_dtype_offsets()
1184cdef class Descr:
1185 """Empty-initialize an array of `CUfileDescr_t`.
1186 The resulting object is of length `size` and of dtype `descr_dtype`.
1187 If default-constructed, the instance represents a single struct.
1189 Args:
1190 size (int): number of structs, default=1.
1192 .. seealso:: `CUfileDescr_t`
1193 """
1194 cdef:
1195 readonly object _data
1197 def __init__(self, size=1):
1198 arr = _numpy.empty(size, dtype=descr_dtype) 1efgklhijmbcdn
1199 self._data = arr.view(_numpy.recarray) 1efgklhijmbcdn
1200 assert self._data.itemsize == sizeof(CUfileDescr_t), \ 1efgklhijmbcdn
1201 f"itemsize {self._data.itemsize} mismatches struct size { sizeof(CUfileDescr_t) }"
1203 def __repr__(self):
1204 if self._data.size > 1: 1efgklhijmbcdn
1205 return f"<{__name__}.Descr_Array_{self._data.size} object at {hex(id(self))}>"
1206 else:
1207 return f"<{__name__}.Descr object at {hex(id(self))}>" 1efgklhijmbcdn
1209 @property
1210 def ptr(self):
1211 """Get the pointer address to the data as Python :class:`int`."""
1212 return self._data.ctypes.data 1efgklhijmbcdn
1214 cdef intptr_t _get_ptr(self):
1215 return self._data.ctypes.data
1217 def __int__(self):
1218 if self._data.size > 1:
1219 raise TypeError("int() argument must be a bytes-like object of size 1. "
1220 "To get the pointer address of an array, use .ptr")
1221 return self._data.ctypes.data
1223 def __len__(self):
1224 return self._data.size
1226 def __eq__(self, other):
1227 cdef object self_data = self._data
1228 if (not isinstance(other, Descr)) or self_data.size != other._data.size or self_data.dtype != other._data.dtype:
1229 return False
1230 return bool((self_data == other._data).all())
1232 def __getbuffer__(self, Py_buffer *buffer, int flags):
1233 cpython.PyObject_GetBuffer(self._data, buffer, flags)
1235 def __releasebuffer__(self, Py_buffer *buffer):
1236 cpython.PyBuffer_Release(buffer)
1238 @property
1239 def type(self):
1240 """Union[~_numpy.int32, int]: """
1241 if self._data.size == 1:
1242 return int(self._data.type[0])
1243 return self._data.type
1245 @type.setter
1246 def type(self, val):
1247 self._data.type = val 1efgklhijmbcdn
1249 @property
1250 def handle(self):
1251 """_py_anon_pod1_dtype: """
1252 return self._data.handle 1efgklhijmbcdn
1254 @handle.setter
1255 def handle(self, val):
1256 self._data.handle = val
1258 @property
1259 def fs_ops(self):
1260 """Union[~_numpy.intp, int]: """
1261 if self._data.size == 1:
1262 return int(self._data.fs_ops[0])
1263 return self._data.fs_ops
1265 @fs_ops.setter
1266 def fs_ops(self, val):
1267 self._data.fs_ops = val 1efgklhijmbcdn
1269 def __getitem__(self, key):
1270 cdef ssize_t key_
1271 cdef ssize_t size
1272 if isinstance(key, int):
1273 key_ = key
1274 size = self._data.size
1275 if key_ >= size or key_ <= -(size+1):
1276 raise IndexError("index is out of bounds")
1277 if key_ < 0:
1278 key_ += size
1279 return Descr.from_data(self._data[key_:key_+1])
1280 out = self._data[key]
1281 if isinstance(out, _numpy.recarray) and out.dtype == descr_dtype:
1282 return Descr.from_data(out)
1283 return out
1285 def __setitem__(self, key, val):
1286 self._data[key] = val
1288 @staticmethod
1289 def from_buffer(buffer):
1290 """Create an Descr instance with the memory from the given buffer."""
1291 return Descr.from_data(_numpy.frombuffer(buffer, dtype=descr_dtype))
1293 @staticmethod
1294 def from_data(data):
1295 """Create an Descr instance wrapping the given NumPy array.
1297 Args:
1298 data (_numpy.ndarray): a 1D array of dtype `descr_dtype` holding the data.
1299 """
1300 cdef Descr obj = Descr.__new__(Descr)
1301 if not isinstance(data, _numpy.ndarray):
1302 raise TypeError("data argument must be a NumPy ndarray")
1303 if data.ndim != 1:
1304 raise ValueError("data array must be 1D")
1305 if data.dtype != descr_dtype:
1306 raise ValueError("data array must be of dtype descr_dtype")
1307 obj._data = data.view(_numpy.recarray)
1309 return obj
1311 @staticmethod
1312 def from_ptr(intptr_t ptr, size_t size=1, bint readonly=False):
1313 """Create an Descr instance wrapping the given pointer.
1315 Args:
1316 ptr (intptr_t): pointer address as Python :class:`int` to the data.
1317 size (int): number of structs, default=1.
1318 readonly (bool): whether the data is read-only (to the user). default is `False`.
1319 """
1320 if ptr == 0:
1321 raise ValueError("ptr must not be null (0)")
1322 cdef Descr obj = Descr.__new__(Descr)
1323 cdef flag = cpython.buffer.PyBUF_READ if readonly else cpython.buffer.PyBUF_WRITE
1324 cdef object buf = cpython.memoryview.PyMemoryView_FromMemory(
1325 <char*>ptr, sizeof(CUfileDescr_t) * size, flag)
1326 data = _numpy.ndarray(size, buffer=buf, dtype=descr_dtype)
1327 obj._data = data.view(_numpy.recarray)
1329 return obj
1332_py_anon_pod2_dtype = _numpy.dtype((
1333 _numpy.dtype((_numpy.void, sizeof((<CUfileIOParams_t*>NULL).u))),
1334 {
1335 "batch": (_py_anon_pod3_dtype, 0),
1336 }
1337 ))
1339cdef class _py_anon_pod2:
1340 """Empty-initialize an instance of `cuda_bindings_cufile__anon_pod2`.
1343 .. seealso:: `cuda_bindings_cufile__anon_pod2`
1344 """
1345 cdef:
1346 cuda_bindings_cufile__anon_pod2 *_ptr
1347 object _owner
1348 bint _owned
1349 bint _readonly
1351 def __init__(self):
1352 self._ptr = <cuda_bindings_cufile__anon_pod2 *>calloc(1, sizeof((<CUfileIOParams_t*>NULL).u))
1353 if self._ptr == NULL:
1354 raise MemoryError("Error allocating _py_anon_pod2")
1355 self._owner = None
1356 self._owned = True
1357 self._readonly = False
1359 def __dealloc__(self):
1360 cdef cuda_bindings_cufile__anon_pod2 *ptr
1361 if self._owned and self._ptr != NULL:
1362 ptr = self._ptr
1363 self._ptr = NULL
1364 free(ptr)
1366 def __repr__(self):
1367 return f"<{__name__}._py_anon_pod2 object at {hex(id(self))}>"
1369 @property
1370 def ptr(self):
1371 """Get the pointer address to the data as Python :class:`int`."""
1372 return <intptr_t>(self._ptr)
1374 cdef intptr_t _get_ptr(self):
1375 return <intptr_t>(self._ptr)
1377 def __int__(self):
1378 return <intptr_t>(self._ptr)
1380 def __eq__(self, other):
1381 cdef _py_anon_pod2 other_
1382 if not isinstance(other, _py_anon_pod2):
1383 return False
1384 other_ = other
1385 return (memcmp(<void *><intptr_t>(self._ptr), <void *><intptr_t>(other_._ptr), sizeof((<CUfileIOParams_t*>NULL).u)) == 0)
1387 def __getbuffer__(self, Py_buffer *buffer, int flags):
1388 __getbuffer(self, buffer, <void *>self._ptr, sizeof((<CUfileIOParams_t*>NULL).u), self._readonly)
1390 def __releasebuffer__(self, Py_buffer *buffer):
1391 pass
1393 def __setitem__(self, key, val):
1394 if key == 0 and isinstance(val, _numpy.ndarray):
1395 self._ptr = <cuda_bindings_cufile__anon_pod2 *>malloc(sizeof((<CUfileIOParams_t*>NULL).u))
1396 if self._ptr == NULL:
1397 raise MemoryError("Error allocating _py_anon_pod2")
1398 memcpy(<void*>self._ptr, <void*><intptr_t>val.ctypes.data, sizeof((<CUfileIOParams_t*>NULL).u))
1399 self._owner = None
1400 self._owned = True
1401 self._readonly = not val.flags.writeable
1402 else:
1403 setattr(self, key, val)
1405 @property
1406 def batch(self):
1407 """_py_anon_pod3: """
1408 return _py_anon_pod3.from_ptr(<intptr_t>&(self._ptr[0].batch), self._readonly, self)
1410 @batch.setter
1411 def batch(self, val):
1412 if self._readonly:
1413 raise ValueError("This _py_anon_pod2 instance is read-only")
1414 cdef _py_anon_pod3 val_ = val
1415 memcpy(<void *>&(self._ptr[0].batch), <void *>(val_._get_ptr()), sizeof(cuda_bindings_cufile__anon_pod3) * 1)
1417 @staticmethod
1418 def from_buffer(buffer):
1419 """Create an _py_anon_pod2 instance with the memory from the given buffer."""
1420 return __from_buffer(buffer, sizeof((<CUfileIOParams_t*>NULL).u), _py_anon_pod2)
1422 @staticmethod
1423 def from_data(data):
1424 """Create an _py_anon_pod2 instance wrapping the given NumPy array.
1426 Args:
1427 data (_numpy.ndarray): a single-element array of dtype `_py_anon_pod2_dtype` holding the data.
1428 """
1429 return __from_data(data, "_py_anon_pod2_dtype", _py_anon_pod2_dtype, _py_anon_pod2)
1431 @staticmethod
1432 def from_ptr(intptr_t ptr, bint readonly=False, object owner=None):
1433 """Create an _py_anon_pod2 instance wrapping the given pointer.
1435 Args:
1436 ptr (intptr_t): pointer address as Python :class:`int` to the data.
1437 owner (object): The Python object that owns the pointer. If not provided, data will be copied.
1438 readonly (bool): whether the data is read-only (to the user). default is `False`.
1439 """
1440 if ptr == 0:
1441 raise ValueError("ptr must not be null (0)")
1442 cdef _py_anon_pod2 obj = _py_anon_pod2.__new__(_py_anon_pod2)
1443 if owner is None:
1444 obj._ptr = <cuda_bindings_cufile__anon_pod2 *>malloc(sizeof((<CUfileIOParams_t*>NULL).u))
1445 if obj._ptr == NULL:
1446 raise MemoryError("Error allocating _py_anon_pod2")
1447 memcpy(<void*>(obj._ptr), <void*>ptr, sizeof((<CUfileIOParams_t*>NULL).u))
1448 obj._owner = None
1449 obj._owned = True
1450 else:
1451 obj._ptr = <cuda_bindings_cufile__anon_pod2 *>ptr
1452 obj._owner = owner
1453 obj._owned = False
1454 obj._readonly = readonly
1455 return obj
1458cdef _get_stats_level1_dtype_offsets():
1459 cdef CUfileStatsLevel1_t pod = CUfileStatsLevel1_t()
1460 return _numpy.dtype({
1461 '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'],
1462 '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],
1463 'offsets': [
1464 (<intptr_t>&(pod.read_ops)) - (<intptr_t>&pod),
1465 (<intptr_t>&(pod.write_ops)) - (<intptr_t>&pod),
1466 (<intptr_t>&(pod.hdl_register_ops)) - (<intptr_t>&pod),
1467 (<intptr_t>&(pod.hdl_deregister_ops)) - (<intptr_t>&pod),
1468 (<intptr_t>&(pod.buf_register_ops)) - (<intptr_t>&pod),
1469 (<intptr_t>&(pod.buf_deregister_ops)) - (<intptr_t>&pod),
1470 (<intptr_t>&(pod.read_bytes)) - (<intptr_t>&pod),
1471 (<intptr_t>&(pod.write_bytes)) - (<intptr_t>&pod),
1472 (<intptr_t>&(pod.read_bw_bytes_per_sec)) - (<intptr_t>&pod),
1473 (<intptr_t>&(pod.write_bw_bytes_per_sec)) - (<intptr_t>&pod),
1474 (<intptr_t>&(pod.read_lat_avg_us)) - (<intptr_t>&pod),
1475 (<intptr_t>&(pod.write_lat_avg_us)) - (<intptr_t>&pod),
1476 (<intptr_t>&(pod.read_ops_per_sec)) - (<intptr_t>&pod),
1477 (<intptr_t>&(pod.write_ops_per_sec)) - (<intptr_t>&pod),
1478 (<intptr_t>&(pod.read_lat_sum_us)) - (<intptr_t>&pod),
1479 (<intptr_t>&(pod.write_lat_sum_us)) - (<intptr_t>&pod),
1480 (<intptr_t>&(pod.batch_submit_ops)) - (<intptr_t>&pod),
1481 (<intptr_t>&(pod.batch_complete_ops)) - (<intptr_t>&pod),
1482 (<intptr_t>&(pod.batch_setup_ops)) - (<intptr_t>&pod),
1483 (<intptr_t>&(pod.batch_cancel_ops)) - (<intptr_t>&pod),
1484 (<intptr_t>&(pod.batch_destroy_ops)) - (<intptr_t>&pod),
1485 (<intptr_t>&(pod.batch_enqueued_ops)) - (<intptr_t>&pod),
1486 (<intptr_t>&(pod.batch_posix_enqueued_ops)) - (<intptr_t>&pod),
1487 (<intptr_t>&(pod.batch_processed_ops)) - (<intptr_t>&pod),
1488 (<intptr_t>&(pod.batch_posix_processed_ops)) - (<intptr_t>&pod),
1489 (<intptr_t>&(pod.batch_nvfs_submit_ops)) - (<intptr_t>&pod),
1490 (<intptr_t>&(pod.batch_p2p_submit_ops)) - (<intptr_t>&pod),
1491 (<intptr_t>&(pod.batch_aio_submit_ops)) - (<intptr_t>&pod),
1492 (<intptr_t>&(pod.batch_iouring_submit_ops)) - (<intptr_t>&pod),
1493 (<intptr_t>&(pod.batch_mixed_io_submit_ops)) - (<intptr_t>&pod),
1494 (<intptr_t>&(pod.batch_total_submit_ops)) - (<intptr_t>&pod),
1495 (<intptr_t>&(pod.batch_read_bytes)) - (<intptr_t>&pod),
1496 (<intptr_t>&(pod.batch_write_bytes)) - (<intptr_t>&pod),
1497 (<intptr_t>&(pod.batch_read_bw_bytes)) - (<intptr_t>&pod),
1498 (<intptr_t>&(pod.batch_write_bw_bytes)) - (<intptr_t>&pod),
1499 (<intptr_t>&(pod.batch_submit_lat_avg_us)) - (<intptr_t>&pod),
1500 (<intptr_t>&(pod.batch_completion_lat_avg_us)) - (<intptr_t>&pod),
1501 (<intptr_t>&(pod.batch_submit_ops_per_sec)) - (<intptr_t>&pod),
1502 (<intptr_t>&(pod.batch_complete_ops_per_sec)) - (<intptr_t>&pod),
1503 (<intptr_t>&(pod.batch_submit_lat_sum_us)) - (<intptr_t>&pod),
1504 (<intptr_t>&(pod.batch_completion_lat_sum_us)) - (<intptr_t>&pod),
1505 (<intptr_t>&(pod.last_batch_read_bytes)) - (<intptr_t>&pod),
1506 (<intptr_t>&(pod.last_batch_write_bytes)) - (<intptr_t>&pod),
1507 ],
1508 'itemsize': sizeof(CUfileStatsLevel1_t),
1509 })
1511stats_level1_dtype = _get_stats_level1_dtype_offsets()
1513cdef class StatsLevel1:
1514 """Empty-initialize an instance of `CUfileStatsLevel1_t`.
1517 .. seealso:: `CUfileStatsLevel1_t`
1518 """
1519 cdef:
1520 CUfileStatsLevel1_t *_ptr
1521 object _owner
1522 bint _owned
1523 bint _readonly
1525 def __init__(self):
1526 self._ptr = <CUfileStatsLevel1_t *>calloc(1, sizeof(CUfileStatsLevel1_t))
1527 if self._ptr == NULL:
1528 raise MemoryError("Error allocating StatsLevel1")
1529 self._owner = None
1530 self._owned = True
1531 self._readonly = False
1533 def __dealloc__(self):
1534 cdef CUfileStatsLevel1_t *ptr
1535 if self._owned and self._ptr != NULL:
1536 ptr = self._ptr
1537 self._ptr = NULL
1538 free(ptr)
1540 def __repr__(self):
1541 return f"<{__name__}.StatsLevel1 object at {hex(id(self))}>"
1543 @property
1544 def ptr(self):
1545 """Get the pointer address to the data as Python :class:`int`."""
1546 return <intptr_t>(self._ptr)
1548 cdef intptr_t _get_ptr(self):
1549 return <intptr_t>(self._ptr)
1551 def __int__(self):
1552 return <intptr_t>(self._ptr)
1554 def __eq__(self, other):
1555 cdef StatsLevel1 other_
1556 if not isinstance(other, StatsLevel1):
1557 return False
1558 other_ = other
1559 return (memcmp(<void *><intptr_t>(self._ptr), <void *><intptr_t>(other_._ptr), sizeof(CUfileStatsLevel1_t)) == 0)
1561 def __getbuffer__(self, Py_buffer *buffer, int flags):
1562 __getbuffer(self, buffer, <void *>self._ptr, sizeof(CUfileStatsLevel1_t), self._readonly)
1564 def __releasebuffer__(self, Py_buffer *buffer):
1565 pass
1567 def __setitem__(self, key, val):
1568 if key == 0 and isinstance(val, _numpy.ndarray):
1569 self._ptr = <CUfileStatsLevel1_t *>malloc(sizeof(CUfileStatsLevel1_t))
1570 if self._ptr == NULL:
1571 raise MemoryError("Error allocating StatsLevel1")
1572 memcpy(<void*>self._ptr, <void*><intptr_t>val.ctypes.data, sizeof(CUfileStatsLevel1_t))
1573 self._owner = None
1574 self._owned = True
1575 self._readonly = not val.flags.writeable
1576 else:
1577 setattr(self, key, val)
1579 @property
1580 def read_ops(self):
1581 """OpCounter: """
1582 return OpCounter.from_ptr(<intptr_t>&(self._ptr[0].read_ops), self._readonly, self)
1584 @read_ops.setter
1585 def read_ops(self, val):
1586 if self._readonly:
1587 raise ValueError("This StatsLevel1 instance is read-only")
1588 cdef OpCounter val_ = val
1589 memcpy(<void *>&(self._ptr[0].read_ops), <void *>(val_._get_ptr()), sizeof(CUfileOpCounter_t) * 1)
1591 @property
1592 def write_ops(self):
1593 """OpCounter: """
1594 return OpCounter.from_ptr(<intptr_t>&(self._ptr[0].write_ops), self._readonly, self)
1596 @write_ops.setter
1597 def write_ops(self, val):
1598 if self._readonly:
1599 raise ValueError("This StatsLevel1 instance is read-only")
1600 cdef OpCounter val_ = val
1601 memcpy(<void *>&(self._ptr[0].write_ops), <void *>(val_._get_ptr()), sizeof(CUfileOpCounter_t) * 1)
1603 @property
1604 def hdl_register_ops(self):
1605 """OpCounter: """
1606 return OpCounter.from_ptr(<intptr_t>&(self._ptr[0].hdl_register_ops), self._readonly, self)
1608 @hdl_register_ops.setter
1609 def hdl_register_ops(self, val):
1610 if self._readonly:
1611 raise ValueError("This StatsLevel1 instance is read-only")
1612 cdef OpCounter val_ = val
1613 memcpy(<void *>&(self._ptr[0].hdl_register_ops), <void *>(val_._get_ptr()), sizeof(CUfileOpCounter_t) * 1)
1615 @property
1616 def hdl_deregister_ops(self):
1617 """OpCounter: """
1618 return OpCounter.from_ptr(<intptr_t>&(self._ptr[0].hdl_deregister_ops), self._readonly, self)
1620 @hdl_deregister_ops.setter
1621 def hdl_deregister_ops(self, val):
1622 if self._readonly:
1623 raise ValueError("This StatsLevel1 instance is read-only")
1624 cdef OpCounter val_ = val
1625 memcpy(<void *>&(self._ptr[0].hdl_deregister_ops), <void *>(val_._get_ptr()), sizeof(CUfileOpCounter_t) * 1)
1627 @property
1628 def buf_register_ops(self):
1629 """OpCounter: """
1630 return OpCounter.from_ptr(<intptr_t>&(self._ptr[0].buf_register_ops), self._readonly, self)
1632 @buf_register_ops.setter
1633 def buf_register_ops(self, val):
1634 if self._readonly:
1635 raise ValueError("This StatsLevel1 instance is read-only")
1636 cdef OpCounter val_ = val
1637 memcpy(<void *>&(self._ptr[0].buf_register_ops), <void *>(val_._get_ptr()), sizeof(CUfileOpCounter_t) * 1)
1639 @property
1640 def buf_deregister_ops(self):
1641 """OpCounter: """
1642 return OpCounter.from_ptr(<intptr_t>&(self._ptr[0].buf_deregister_ops), self._readonly, self)
1644 @buf_deregister_ops.setter
1645 def buf_deregister_ops(self, val):
1646 if self._readonly:
1647 raise ValueError("This StatsLevel1 instance is read-only")
1648 cdef OpCounter val_ = val
1649 memcpy(<void *>&(self._ptr[0].buf_deregister_ops), <void *>(val_._get_ptr()), sizeof(CUfileOpCounter_t) * 1)
1651 @property
1652 def batch_submit_ops(self):
1653 """OpCounter: """
1654 return OpCounter.from_ptr(<intptr_t>&(self._ptr[0].batch_submit_ops), self._readonly, self)
1656 @batch_submit_ops.setter
1657 def batch_submit_ops(self, val):
1658 if self._readonly:
1659 raise ValueError("This StatsLevel1 instance is read-only")
1660 cdef OpCounter val_ = val
1661 memcpy(<void *>&(self._ptr[0].batch_submit_ops), <void *>(val_._get_ptr()), sizeof(CUfileOpCounter_t) * 1)
1663 @property
1664 def batch_complete_ops(self):
1665 """OpCounter: """
1666 return OpCounter.from_ptr(<intptr_t>&(self._ptr[0].batch_complete_ops), self._readonly, self)
1668 @batch_complete_ops.setter
1669 def batch_complete_ops(self, val):
1670 if self._readonly:
1671 raise ValueError("This StatsLevel1 instance is read-only")
1672 cdef OpCounter val_ = val
1673 memcpy(<void *>&(self._ptr[0].batch_complete_ops), <void *>(val_._get_ptr()), sizeof(CUfileOpCounter_t) * 1)
1675 @property
1676 def batch_setup_ops(self):
1677 """OpCounter: """
1678 return OpCounter.from_ptr(<intptr_t>&(self._ptr[0].batch_setup_ops), self._readonly, self)
1680 @batch_setup_ops.setter
1681 def batch_setup_ops(self, val):
1682 if self._readonly:
1683 raise ValueError("This StatsLevel1 instance is read-only")
1684 cdef OpCounter val_ = val
1685 memcpy(<void *>&(self._ptr[0].batch_setup_ops), <void *>(val_._get_ptr()), sizeof(CUfileOpCounter_t) * 1)
1687 @property
1688 def batch_cancel_ops(self):
1689 """OpCounter: """
1690 return OpCounter.from_ptr(<intptr_t>&(self._ptr[0].batch_cancel_ops), self._readonly, self)
1692 @batch_cancel_ops.setter
1693 def batch_cancel_ops(self, val):
1694 if self._readonly:
1695 raise ValueError("This StatsLevel1 instance is read-only")
1696 cdef OpCounter val_ = val
1697 memcpy(<void *>&(self._ptr[0].batch_cancel_ops), <void *>(val_._get_ptr()), sizeof(CUfileOpCounter_t) * 1)
1699 @property
1700 def batch_destroy_ops(self):
1701 """OpCounter: """
1702 return OpCounter.from_ptr(<intptr_t>&(self._ptr[0].batch_destroy_ops), self._readonly, self)
1704 @batch_destroy_ops.setter
1705 def batch_destroy_ops(self, val):
1706 if self._readonly:
1707 raise ValueError("This StatsLevel1 instance is read-only")
1708 cdef OpCounter val_ = val
1709 memcpy(<void *>&(self._ptr[0].batch_destroy_ops), <void *>(val_._get_ptr()), sizeof(CUfileOpCounter_t) * 1)
1711 @property
1712 def batch_enqueued_ops(self):
1713 """OpCounter: """
1714 return OpCounter.from_ptr(<intptr_t>&(self._ptr[0].batch_enqueued_ops), self._readonly, self)
1716 @batch_enqueued_ops.setter
1717 def batch_enqueued_ops(self, val):
1718 if self._readonly:
1719 raise ValueError("This StatsLevel1 instance is read-only")
1720 cdef OpCounter val_ = val
1721 memcpy(<void *>&(self._ptr[0].batch_enqueued_ops), <void *>(val_._get_ptr()), sizeof(CUfileOpCounter_t) * 1)
1723 @property
1724 def batch_posix_enqueued_ops(self):
1725 """OpCounter: """
1726 return OpCounter.from_ptr(<intptr_t>&(self._ptr[0].batch_posix_enqueued_ops), self._readonly, self)
1728 @batch_posix_enqueued_ops.setter
1729 def batch_posix_enqueued_ops(self, val):
1730 if self._readonly:
1731 raise ValueError("This StatsLevel1 instance is read-only")
1732 cdef OpCounter val_ = val
1733 memcpy(<void *>&(self._ptr[0].batch_posix_enqueued_ops), <void *>(val_._get_ptr()), sizeof(CUfileOpCounter_t) * 1)
1735 @property
1736 def batch_processed_ops(self):
1737 """OpCounter: """
1738 return OpCounter.from_ptr(<intptr_t>&(self._ptr[0].batch_processed_ops), self._readonly, self)
1740 @batch_processed_ops.setter
1741 def batch_processed_ops(self, val):
1742 if self._readonly:
1743 raise ValueError("This StatsLevel1 instance is read-only")
1744 cdef OpCounter val_ = val
1745 memcpy(<void *>&(self._ptr[0].batch_processed_ops), <void *>(val_._get_ptr()), sizeof(CUfileOpCounter_t) * 1)
1747 @property
1748 def batch_posix_processed_ops(self):
1749 """OpCounter: """
1750 return OpCounter.from_ptr(<intptr_t>&(self._ptr[0].batch_posix_processed_ops), self._readonly, self)
1752 @batch_posix_processed_ops.setter
1753 def batch_posix_processed_ops(self, val):
1754 if self._readonly:
1755 raise ValueError("This StatsLevel1 instance is read-only")
1756 cdef OpCounter val_ = val
1757 memcpy(<void *>&(self._ptr[0].batch_posix_processed_ops), <void *>(val_._get_ptr()), sizeof(CUfileOpCounter_t) * 1)
1759 @property
1760 def batch_nvfs_submit_ops(self):
1761 """OpCounter: """
1762 return OpCounter.from_ptr(<intptr_t>&(self._ptr[0].batch_nvfs_submit_ops), self._readonly, self)
1764 @batch_nvfs_submit_ops.setter
1765 def batch_nvfs_submit_ops(self, val):
1766 if self._readonly:
1767 raise ValueError("This StatsLevel1 instance is read-only")
1768 cdef OpCounter val_ = val
1769 memcpy(<void *>&(self._ptr[0].batch_nvfs_submit_ops), <void *>(val_._get_ptr()), sizeof(CUfileOpCounter_t) * 1)
1771 @property
1772 def batch_p2p_submit_ops(self):
1773 """OpCounter: """
1774 return OpCounter.from_ptr(<intptr_t>&(self._ptr[0].batch_p2p_submit_ops), self._readonly, self)
1776 @batch_p2p_submit_ops.setter
1777 def batch_p2p_submit_ops(self, val):
1778 if self._readonly:
1779 raise ValueError("This StatsLevel1 instance is read-only")
1780 cdef OpCounter val_ = val
1781 memcpy(<void *>&(self._ptr[0].batch_p2p_submit_ops), <void *>(val_._get_ptr()), sizeof(CUfileOpCounter_t) * 1)
1783 @property
1784 def batch_aio_submit_ops(self):
1785 """OpCounter: """
1786 return OpCounter.from_ptr(<intptr_t>&(self._ptr[0].batch_aio_submit_ops), self._readonly, self)
1788 @batch_aio_submit_ops.setter
1789 def batch_aio_submit_ops(self, val):
1790 if self._readonly:
1791 raise ValueError("This StatsLevel1 instance is read-only")
1792 cdef OpCounter val_ = val
1793 memcpy(<void *>&(self._ptr[0].batch_aio_submit_ops), <void *>(val_._get_ptr()), sizeof(CUfileOpCounter_t) * 1)
1795 @property
1796 def batch_iouring_submit_ops(self):
1797 """OpCounter: """
1798 return OpCounter.from_ptr(<intptr_t>&(self._ptr[0].batch_iouring_submit_ops), self._readonly, self)
1800 @batch_iouring_submit_ops.setter
1801 def batch_iouring_submit_ops(self, val):
1802 if self._readonly:
1803 raise ValueError("This StatsLevel1 instance is read-only")
1804 cdef OpCounter val_ = val
1805 memcpy(<void *>&(self._ptr[0].batch_iouring_submit_ops), <void *>(val_._get_ptr()), sizeof(CUfileOpCounter_t) * 1)
1807 @property
1808 def batch_mixed_io_submit_ops(self):
1809 """OpCounter: """
1810 return OpCounter.from_ptr(<intptr_t>&(self._ptr[0].batch_mixed_io_submit_ops), self._readonly, self)
1812 @batch_mixed_io_submit_ops.setter
1813 def batch_mixed_io_submit_ops(self, val):
1814 if self._readonly:
1815 raise ValueError("This StatsLevel1 instance is read-only")
1816 cdef OpCounter val_ = val
1817 memcpy(<void *>&(self._ptr[0].batch_mixed_io_submit_ops), <void *>(val_._get_ptr()), sizeof(CUfileOpCounter_t) * 1)
1819 @property
1820 def batch_total_submit_ops(self):
1821 """OpCounter: """
1822 return OpCounter.from_ptr(<intptr_t>&(self._ptr[0].batch_total_submit_ops), self._readonly, self)
1824 @batch_total_submit_ops.setter
1825 def batch_total_submit_ops(self, val):
1826 if self._readonly:
1827 raise ValueError("This StatsLevel1 instance is read-only")
1828 cdef OpCounter val_ = val
1829 memcpy(<void *>&(self._ptr[0].batch_total_submit_ops), <void *>(val_._get_ptr()), sizeof(CUfileOpCounter_t) * 1)
1831 @property
1832 def read_bytes(self):
1833 """int: """
1834 return self._ptr[0].read_bytes
1836 @read_bytes.setter
1837 def read_bytes(self, val):
1838 if self._readonly:
1839 raise ValueError("This StatsLevel1 instance is read-only")
1840 self._ptr[0].read_bytes = val
1842 @property
1843 def write_bytes(self):
1844 """int: """
1845 return self._ptr[0].write_bytes
1847 @write_bytes.setter
1848 def write_bytes(self, val):
1849 if self._readonly:
1850 raise ValueError("This StatsLevel1 instance is read-only")
1851 self._ptr[0].write_bytes = val
1853 @property
1854 def read_bw_bytes_per_sec(self):
1855 """int: """
1856 return self._ptr[0].read_bw_bytes_per_sec
1858 @read_bw_bytes_per_sec.setter
1859 def read_bw_bytes_per_sec(self, val):
1860 if self._readonly:
1861 raise ValueError("This StatsLevel1 instance is read-only")
1862 self._ptr[0].read_bw_bytes_per_sec = val
1864 @property
1865 def write_bw_bytes_per_sec(self):
1866 """int: """
1867 return self._ptr[0].write_bw_bytes_per_sec
1869 @write_bw_bytes_per_sec.setter
1870 def write_bw_bytes_per_sec(self, val):
1871 if self._readonly:
1872 raise ValueError("This StatsLevel1 instance is read-only")
1873 self._ptr[0].write_bw_bytes_per_sec = val
1875 @property
1876 def read_lat_avg_us(self):
1877 """int: """
1878 return self._ptr[0].read_lat_avg_us
1880 @read_lat_avg_us.setter
1881 def read_lat_avg_us(self, val):
1882 if self._readonly:
1883 raise ValueError("This StatsLevel1 instance is read-only")
1884 self._ptr[0].read_lat_avg_us = val
1886 @property
1887 def write_lat_avg_us(self):
1888 """int: """
1889 return self._ptr[0].write_lat_avg_us
1891 @write_lat_avg_us.setter
1892 def write_lat_avg_us(self, val):
1893 if self._readonly:
1894 raise ValueError("This StatsLevel1 instance is read-only")
1895 self._ptr[0].write_lat_avg_us = val
1897 @property
1898 def read_ops_per_sec(self):
1899 """int: """
1900 return self._ptr[0].read_ops_per_sec
1902 @read_ops_per_sec.setter
1903 def read_ops_per_sec(self, val):
1904 if self._readonly:
1905 raise ValueError("This StatsLevel1 instance is read-only")
1906 self._ptr[0].read_ops_per_sec = val
1908 @property
1909 def write_ops_per_sec(self):
1910 """int: """
1911 return self._ptr[0].write_ops_per_sec
1913 @write_ops_per_sec.setter
1914 def write_ops_per_sec(self, val):
1915 if self._readonly:
1916 raise ValueError("This StatsLevel1 instance is read-only")
1917 self._ptr[0].write_ops_per_sec = val
1919 @property
1920 def read_lat_sum_us(self):
1921 """int: """
1922 return self._ptr[0].read_lat_sum_us
1924 @read_lat_sum_us.setter
1925 def read_lat_sum_us(self, val):
1926 if self._readonly:
1927 raise ValueError("This StatsLevel1 instance is read-only")
1928 self._ptr[0].read_lat_sum_us = val
1930 @property
1931 def write_lat_sum_us(self):
1932 """int: """
1933 return self._ptr[0].write_lat_sum_us
1935 @write_lat_sum_us.setter
1936 def write_lat_sum_us(self, val):
1937 if self._readonly:
1938 raise ValueError("This StatsLevel1 instance is read-only")
1939 self._ptr[0].write_lat_sum_us = val
1941 @property
1942 def batch_read_bytes(self):
1943 """int: """
1944 return self._ptr[0].batch_read_bytes
1946 @batch_read_bytes.setter
1947 def batch_read_bytes(self, val):
1948 if self._readonly:
1949 raise ValueError("This StatsLevel1 instance is read-only")
1950 self._ptr[0].batch_read_bytes = val
1952 @property
1953 def batch_write_bytes(self):
1954 """int: """
1955 return self._ptr[0].batch_write_bytes
1957 @batch_write_bytes.setter
1958 def batch_write_bytes(self, val):
1959 if self._readonly:
1960 raise ValueError("This StatsLevel1 instance is read-only")
1961 self._ptr[0].batch_write_bytes = val
1963 @property
1964 def batch_read_bw_bytes(self):
1965 """int: """
1966 return self._ptr[0].batch_read_bw_bytes
1968 @batch_read_bw_bytes.setter
1969 def batch_read_bw_bytes(self, val):
1970 if self._readonly:
1971 raise ValueError("This StatsLevel1 instance is read-only")
1972 self._ptr[0].batch_read_bw_bytes = val
1974 @property
1975 def batch_write_bw_bytes(self):
1976 """int: """
1977 return self._ptr[0].batch_write_bw_bytes
1979 @batch_write_bw_bytes.setter
1980 def batch_write_bw_bytes(self, val):
1981 if self._readonly:
1982 raise ValueError("This StatsLevel1 instance is read-only")
1983 self._ptr[0].batch_write_bw_bytes = val
1985 @property
1986 def batch_submit_lat_avg_us(self):
1987 """int: """
1988 return self._ptr[0].batch_submit_lat_avg_us
1990 @batch_submit_lat_avg_us.setter
1991 def batch_submit_lat_avg_us(self, val):
1992 if self._readonly:
1993 raise ValueError("This StatsLevel1 instance is read-only")
1994 self._ptr[0].batch_submit_lat_avg_us = val
1996 @property
1997 def batch_completion_lat_avg_us(self):
1998 """int: """
1999 return self._ptr[0].batch_completion_lat_avg_us
2001 @batch_completion_lat_avg_us.setter
2002 def batch_completion_lat_avg_us(self, val):
2003 if self._readonly:
2004 raise ValueError("This StatsLevel1 instance is read-only")
2005 self._ptr[0].batch_completion_lat_avg_us = val
2007 @property
2008 def batch_submit_ops_per_sec(self):
2009 """int: """
2010 return self._ptr[0].batch_submit_ops_per_sec
2012 @batch_submit_ops_per_sec.setter
2013 def batch_submit_ops_per_sec(self, val):
2014 if self._readonly:
2015 raise ValueError("This StatsLevel1 instance is read-only")
2016 self._ptr[0].batch_submit_ops_per_sec = val
2018 @property
2019 def batch_complete_ops_per_sec(self):
2020 """int: """
2021 return self._ptr[0].batch_complete_ops_per_sec
2023 @batch_complete_ops_per_sec.setter
2024 def batch_complete_ops_per_sec(self, val):
2025 if self._readonly:
2026 raise ValueError("This StatsLevel1 instance is read-only")
2027 self._ptr[0].batch_complete_ops_per_sec = val
2029 @property
2030 def batch_submit_lat_sum_us(self):
2031 """int: """
2032 return self._ptr[0].batch_submit_lat_sum_us
2034 @batch_submit_lat_sum_us.setter
2035 def batch_submit_lat_sum_us(self, val):
2036 if self._readonly:
2037 raise ValueError("This StatsLevel1 instance is read-only")
2038 self._ptr[0].batch_submit_lat_sum_us = val
2040 @property
2041 def batch_completion_lat_sum_us(self):
2042 """int: """
2043 return self._ptr[0].batch_completion_lat_sum_us
2045 @batch_completion_lat_sum_us.setter
2046 def batch_completion_lat_sum_us(self, val):
2047 if self._readonly:
2048 raise ValueError("This StatsLevel1 instance is read-only")
2049 self._ptr[0].batch_completion_lat_sum_us = val
2051 @property
2052 def last_batch_read_bytes(self):
2053 """int: """
2054 return self._ptr[0].last_batch_read_bytes
2056 @last_batch_read_bytes.setter
2057 def last_batch_read_bytes(self, val):
2058 if self._readonly:
2059 raise ValueError("This StatsLevel1 instance is read-only")
2060 self._ptr[0].last_batch_read_bytes = val
2062 @property
2063 def last_batch_write_bytes(self):
2064 """int: """
2065 return self._ptr[0].last_batch_write_bytes
2067 @last_batch_write_bytes.setter
2068 def last_batch_write_bytes(self, val):
2069 if self._readonly:
2070 raise ValueError("This StatsLevel1 instance is read-only")
2071 self._ptr[0].last_batch_write_bytes = val
2073 @staticmethod
2074 def from_buffer(buffer):
2075 """Create an StatsLevel1 instance with the memory from the given buffer."""
2076 return __from_buffer(buffer, sizeof(CUfileStatsLevel1_t), StatsLevel1)
2078 @staticmethod
2079 def from_data(data):
2080 """Create an StatsLevel1 instance wrapping the given NumPy array.
2082 Args:
2083 data (_numpy.ndarray): a single-element array of dtype `stats_level1_dtype` holding the data.
2084 """
2085 return __from_data(data, "stats_level1_dtype", stats_level1_dtype, StatsLevel1)
2087 @staticmethod
2088 def from_ptr(intptr_t ptr, bint readonly=False, object owner=None):
2089 """Create an StatsLevel1 instance wrapping the given pointer.
2091 Args:
2092 ptr (intptr_t): pointer address as Python :class:`int` to the data.
2093 owner (object): The Python object that owns the pointer. If not provided, data will be copied.
2094 readonly (bool): whether the data is read-only (to the user). default is `False`.
2095 """
2096 if ptr == 0:
2097 raise ValueError("ptr must not be null (0)")
2098 cdef StatsLevel1 obj = StatsLevel1.__new__(StatsLevel1)
2099 if owner is None:
2100 obj._ptr = <CUfileStatsLevel1_t *>malloc(sizeof(CUfileStatsLevel1_t))
2101 if obj._ptr == NULL:
2102 raise MemoryError("Error allocating StatsLevel1")
2103 memcpy(<void*>(obj._ptr), <void*>ptr, sizeof(CUfileStatsLevel1_t))
2104 obj._owner = None
2105 obj._owned = True
2106 else:
2107 obj._ptr = <CUfileStatsLevel1_t *>ptr
2108 obj._owner = owner
2109 obj._owned = False
2110 obj._readonly = readonly
2111 return obj
2114cdef _get_io_params_dtype_offsets():
2115 cdef CUfileIOParams_t pod = CUfileIOParams_t()
2116 return _numpy.dtype({
2117 'names': ['mode', 'u', 'fh', 'opcode', 'cookie'],
2118 'formats': [_numpy.int32, _py_anon_pod2_dtype, _numpy.intp, _numpy.int32, _numpy.intp],
2119 'offsets': [
2120 (<intptr_t>&(pod.mode)) - (<intptr_t>&pod),
2121 (<intptr_t>&(pod.u)) - (<intptr_t>&pod),
2122 (<intptr_t>&(pod.fh)) - (<intptr_t>&pod),
2123 (<intptr_t>&(pod.opcode)) - (<intptr_t>&pod),
2124 (<intptr_t>&(pod.cookie)) - (<intptr_t>&pod),
2125 ],
2126 'itemsize': sizeof(CUfileIOParams_t),
2127 })
2129io_params_dtype = _get_io_params_dtype_offsets()
2131cdef class IOParams:
2132 """Empty-initialize an array of `CUfileIOParams_t`.
2133 The resulting object is of length `size` and of dtype `io_params_dtype`.
2134 If default-constructed, the instance represents a single struct.
2136 Args:
2137 size (int): number of structs, default=1.
2139 .. seealso:: `CUfileIOParams_t`
2140 """
2141 cdef:
2142 readonly object _data
2144 def __init__(self, size=1):
2145 arr = _numpy.empty(size, dtype=io_params_dtype)
2146 self._data = arr.view(_numpy.recarray)
2147 assert self._data.itemsize == sizeof(CUfileIOParams_t), \
2148 f"itemsize {self._data.itemsize} mismatches struct size { sizeof(CUfileIOParams_t) }"
2150 def __repr__(self):
2151 if self._data.size > 1:
2152 return f"<{__name__}.IOParams_Array_{self._data.size} object at {hex(id(self))}>"
2153 else:
2154 return f"<{__name__}.IOParams object at {hex(id(self))}>"
2156 @property
2157 def ptr(self):
2158 """Get the pointer address to the data as Python :class:`int`."""
2159 return self._data.ctypes.data
2161 cdef intptr_t _get_ptr(self):
2162 return self._data.ctypes.data
2164 def __int__(self):
2165 if self._data.size > 1:
2166 raise TypeError("int() argument must be a bytes-like object of size 1. "
2167 "To get the pointer address of an array, use .ptr")
2168 return self._data.ctypes.data
2170 def __len__(self):
2171 return self._data.size
2173 def __eq__(self, other):
2174 cdef object self_data = self._data
2175 if (not isinstance(other, IOParams)) or self_data.size != other._data.size or self_data.dtype != other._data.dtype:
2176 return False
2177 return bool((self_data == other._data).all())
2179 def __getbuffer__(self, Py_buffer *buffer, int flags):
2180 cpython.PyObject_GetBuffer(self._data, buffer, flags)
2182 def __releasebuffer__(self, Py_buffer *buffer):
2183 cpython.PyBuffer_Release(buffer)
2185 @property
2186 def mode(self):
2187 """Union[~_numpy.int32, int]: """
2188 if self._data.size == 1:
2189 return int(self._data.mode[0])
2190 return self._data.mode
2192 @mode.setter
2193 def mode(self, val):
2194 self._data.mode = val
2196 @property
2197 def u(self):
2198 """_py_anon_pod2_dtype: """
2199 return self._data.u
2201 @u.setter
2202 def u(self, val):
2203 self._data.u = val
2205 @property
2206 def fh(self):
2207 """Union[~_numpy.intp, int]: """
2208 if self._data.size == 1:
2209 return int(self._data.fh[0])
2210 return self._data.fh
2212 @fh.setter
2213 def fh(self, val):
2214 self._data.fh = val
2216 @property
2217 def opcode(self):
2218 """Union[~_numpy.int32, int]: """
2219 if self._data.size == 1:
2220 return int(self._data.opcode[0])
2221 return self._data.opcode
2223 @opcode.setter
2224 def opcode(self, val):
2225 self._data.opcode = val
2227 @property
2228 def cookie(self):
2229 """Union[~_numpy.intp, int]: """
2230 if self._data.size == 1:
2231 return int(self._data.cookie[0])
2232 return self._data.cookie
2234 @cookie.setter
2235 def cookie(self, val):
2236 self._data.cookie = val
2238 def __getitem__(self, key):
2239 cdef ssize_t key_
2240 cdef ssize_t size
2241 if isinstance(key, int):
2242 key_ = key
2243 size = self._data.size
2244 if key_ >= size or key_ <= -(size+1):
2245 raise IndexError("index is out of bounds")
2246 if key_ < 0:
2247 key_ += size
2248 return IOParams.from_data(self._data[key_:key_+1])
2249 out = self._data[key]
2250 if isinstance(out, _numpy.recarray) and out.dtype == io_params_dtype:
2251 return IOParams.from_data(out)
2252 return out
2254 def __setitem__(self, key, val):
2255 self._data[key] = val
2257 @staticmethod
2258 def from_buffer(buffer):
2259 """Create an IOParams instance with the memory from the given buffer."""
2260 return IOParams.from_data(_numpy.frombuffer(buffer, dtype=io_params_dtype))
2262 @staticmethod
2263 def from_data(data):
2264 """Create an IOParams instance wrapping the given NumPy array.
2266 Args:
2267 data (_numpy.ndarray): a 1D array of dtype `io_params_dtype` holding the data.
2268 """
2269 cdef IOParams obj = IOParams.__new__(IOParams)
2270 if not isinstance(data, _numpy.ndarray):
2271 raise TypeError("data argument must be a NumPy ndarray")
2272 if data.ndim != 1:
2273 raise ValueError("data array must be 1D")
2274 if data.dtype != io_params_dtype:
2275 raise ValueError("data array must be of dtype io_params_dtype")
2276 obj._data = data.view(_numpy.recarray)
2278 return obj
2280 @staticmethod
2281 def from_ptr(intptr_t ptr, size_t size=1, bint readonly=False):
2282 """Create an IOParams instance wrapping the given pointer.
2284 Args:
2285 ptr (intptr_t): pointer address as Python :class:`int` to the data.
2286 size (int): number of structs, default=1.
2287 readonly (bool): whether the data is read-only (to the user). default is `False`.
2288 """
2289 if ptr == 0:
2290 raise ValueError("ptr must not be null (0)")
2291 cdef IOParams obj = IOParams.__new__(IOParams)
2292 cdef flag = cpython.buffer.PyBUF_READ if readonly else cpython.buffer.PyBUF_WRITE
2293 cdef object buf = cpython.memoryview.PyMemoryView_FromMemory(
2294 <char*>ptr, sizeof(CUfileIOParams_t) * size, flag)
2295 data = _numpy.ndarray(size, buffer=buf, dtype=io_params_dtype)
2296 obj._data = data.view(_numpy.recarray)
2298 return obj
2301cdef _get_stats_level2_dtype_offsets():
2302 cdef CUfileStatsLevel2_t pod = CUfileStatsLevel2_t()
2303 return _numpy.dtype({
2304 'names': ['basic', 'read_size_kb_hist', 'write_size_kb_hist'],
2305 'formats': [stats_level1_dtype, (_numpy.uint64, 32), (_numpy.uint64, 32)],
2306 'offsets': [
2307 (<intptr_t>&(pod.basic)) - (<intptr_t>&pod),
2308 (<intptr_t>&(pod.read_size_kb_hist)) - (<intptr_t>&pod),
2309 (<intptr_t>&(pod.write_size_kb_hist)) - (<intptr_t>&pod),
2310 ],
2311 'itemsize': sizeof(CUfileStatsLevel2_t),
2312 })
2314stats_level2_dtype = _get_stats_level2_dtype_offsets()
2316cdef class StatsLevel2:
2317 """Empty-initialize an instance of `CUfileStatsLevel2_t`.
2320 .. seealso:: `CUfileStatsLevel2_t`
2321 """
2322 cdef:
2323 CUfileStatsLevel2_t *_ptr
2324 object _owner
2325 bint _owned
2326 bint _readonly
2328 def __init__(self):
2329 self._ptr = <CUfileStatsLevel2_t *>calloc(1, sizeof(CUfileStatsLevel2_t))
2330 if self._ptr == NULL:
2331 raise MemoryError("Error allocating StatsLevel2")
2332 self._owner = None
2333 self._owned = True
2334 self._readonly = False
2336 def __dealloc__(self):
2337 cdef CUfileStatsLevel2_t *ptr
2338 if self._owned and self._ptr != NULL:
2339 ptr = self._ptr
2340 self._ptr = NULL
2341 free(ptr)
2343 def __repr__(self):
2344 return f"<{__name__}.StatsLevel2 object at {hex(id(self))}>"
2346 @property
2347 def ptr(self):
2348 """Get the pointer address to the data as Python :class:`int`."""
2349 return <intptr_t>(self._ptr)
2351 cdef intptr_t _get_ptr(self):
2352 return <intptr_t>(self._ptr)
2354 def __int__(self):
2355 return <intptr_t>(self._ptr)
2357 def __eq__(self, other):
2358 cdef StatsLevel2 other_
2359 if not isinstance(other, StatsLevel2):
2360 return False
2361 other_ = other
2362 return (memcmp(<void *><intptr_t>(self._ptr), <void *><intptr_t>(other_._ptr), sizeof(CUfileStatsLevel2_t)) == 0)
2364 def __getbuffer__(self, Py_buffer *buffer, int flags):
2365 __getbuffer(self, buffer, <void *>self._ptr, sizeof(CUfileStatsLevel2_t), self._readonly)
2367 def __releasebuffer__(self, Py_buffer *buffer):
2368 pass
2370 def __setitem__(self, key, val):
2371 if key == 0 and isinstance(val, _numpy.ndarray):
2372 self._ptr = <CUfileStatsLevel2_t *>malloc(sizeof(CUfileStatsLevel2_t))
2373 if self._ptr == NULL:
2374 raise MemoryError("Error allocating StatsLevel2")
2375 memcpy(<void*>self._ptr, <void*><intptr_t>val.ctypes.data, sizeof(CUfileStatsLevel2_t))
2376 self._owner = None
2377 self._owned = True
2378 self._readonly = not val.flags.writeable
2379 else:
2380 setattr(self, key, val)
2382 @property
2383 def basic(self):
2384 """StatsLevel1: """
2385 return StatsLevel1.from_ptr(<intptr_t>&(self._ptr[0].basic), self._readonly, self)
2387 @basic.setter
2388 def basic(self, val):
2389 if self._readonly:
2390 raise ValueError("This StatsLevel2 instance is read-only")
2391 cdef StatsLevel1 val_ = val
2392 memcpy(<void *>&(self._ptr[0].basic), <void *>(val_._get_ptr()), sizeof(CUfileStatsLevel1_t) * 1)
2394 @property
2395 def read_size_kb_hist(self):
2396 """~_numpy.uint64: (array of length 32)."""
2397 cdef view.array arr = view.array(shape=(32,), itemsize=sizeof(uint64_t), format="Q", mode="c", allocate_buffer=False)
2398 arr.data = <char *>(&(self._ptr[0].read_size_kb_hist))
2399 return _numpy.asarray(arr)
2401 @read_size_kb_hist.setter
2402 def read_size_kb_hist(self, val):
2403 if self._readonly:
2404 raise ValueError("This StatsLevel2 instance is read-only")
2405 if len(val) != 32:
2406 raise ValueError(f"Expected length { 32 } for field read_size_kb_hist, got {len(val)}")
2407 cdef view.array arr = view.array(shape=(32,), itemsize=sizeof(uint64_t), format="Q", mode="c")
2408 arr[:] = _numpy.asarray(val, dtype=_numpy.uint64)
2409 memcpy(<void *>(&(self._ptr[0].read_size_kb_hist)), <void *>(arr.data), sizeof(uint64_t) * len(val))
2411 @property
2412 def write_size_kb_hist(self):
2413 """~_numpy.uint64: (array of length 32)."""
2414 cdef view.array arr = view.array(shape=(32,), itemsize=sizeof(uint64_t), format="Q", mode="c", allocate_buffer=False)
2415 arr.data = <char *>(&(self._ptr[0].write_size_kb_hist))
2416 return _numpy.asarray(arr)
2418 @write_size_kb_hist.setter
2419 def write_size_kb_hist(self, val):
2420 if self._readonly:
2421 raise ValueError("This StatsLevel2 instance is read-only")
2422 if len(val) != 32:
2423 raise ValueError(f"Expected length { 32 } for field write_size_kb_hist, got {len(val)}")
2424 cdef view.array arr = view.array(shape=(32,), itemsize=sizeof(uint64_t), format="Q", mode="c")
2425 arr[:] = _numpy.asarray(val, dtype=_numpy.uint64)
2426 memcpy(<void *>(&(self._ptr[0].write_size_kb_hist)), <void *>(arr.data), sizeof(uint64_t) * len(val))
2428 @staticmethod
2429 def from_buffer(buffer):
2430 """Create an StatsLevel2 instance with the memory from the given buffer."""
2431 return __from_buffer(buffer, sizeof(CUfileStatsLevel2_t), StatsLevel2)
2433 @staticmethod
2434 def from_data(data):
2435 """Create an StatsLevel2 instance wrapping the given NumPy array.
2437 Args:
2438 data (_numpy.ndarray): a single-element array of dtype `stats_level2_dtype` holding the data.
2439 """
2440 return __from_data(data, "stats_level2_dtype", stats_level2_dtype, StatsLevel2)
2442 @staticmethod
2443 def from_ptr(intptr_t ptr, bint readonly=False, object owner=None):
2444 """Create an StatsLevel2 instance wrapping the given pointer.
2446 Args:
2447 ptr (intptr_t): pointer address as Python :class:`int` to the data.
2448 owner (object): The Python object that owns the pointer. If not provided, data will be copied.
2449 readonly (bool): whether the data is read-only (to the user). default is `False`.
2450 """
2451 if ptr == 0:
2452 raise ValueError("ptr must not be null (0)")
2453 cdef StatsLevel2 obj = StatsLevel2.__new__(StatsLevel2)
2454 if owner is None:
2455 obj._ptr = <CUfileStatsLevel2_t *>malloc(sizeof(CUfileStatsLevel2_t))
2456 if obj._ptr == NULL:
2457 raise MemoryError("Error allocating StatsLevel2")
2458 memcpy(<void*>(obj._ptr), <void*>ptr, sizeof(CUfileStatsLevel2_t))
2459 obj._owner = None
2460 obj._owned = True
2461 else:
2462 obj._ptr = <CUfileStatsLevel2_t *>ptr
2463 obj._owner = owner
2464 obj._owned = False
2465 obj._readonly = readonly
2466 return obj
2469cdef _get_stats_level3_dtype_offsets():
2470 cdef CUfileStatsLevel3_t pod = CUfileStatsLevel3_t()
2471 return _numpy.dtype({
2472 'names': ['detailed', 'num_gpus', 'per_gpu_stats'],
2473 'formats': [stats_level2_dtype, _numpy.uint32, (per_gpu_stats_dtype, 16)],
2474 'offsets': [
2475 (<intptr_t>&(pod.detailed)) - (<intptr_t>&pod),
2476 (<intptr_t>&(pod.num_gpus)) - (<intptr_t>&pod),
2477 (<intptr_t>&(pod.per_gpu_stats)) - (<intptr_t>&pod),
2478 ],
2479 'itemsize': sizeof(CUfileStatsLevel3_t),
2480 })
2482stats_level3_dtype = _get_stats_level3_dtype_offsets()
2484cdef class StatsLevel3:
2485 """Empty-initialize an instance of `CUfileStatsLevel3_t`.
2488 .. seealso:: `CUfileStatsLevel3_t`
2489 """
2490 cdef:
2491 CUfileStatsLevel3_t *_ptr
2492 object _owner
2493 bint _owned
2494 bint _readonly
2496 def __init__(self):
2497 self._ptr = <CUfileStatsLevel3_t *>calloc(1, sizeof(CUfileStatsLevel3_t))
2498 if self._ptr == NULL:
2499 raise MemoryError("Error allocating StatsLevel3")
2500 self._owner = None
2501 self._owned = True
2502 self._readonly = False
2504 def __dealloc__(self):
2505 cdef CUfileStatsLevel3_t *ptr
2506 if self._owned and self._ptr != NULL:
2507 ptr = self._ptr
2508 self._ptr = NULL
2509 free(ptr)
2511 def __repr__(self):
2512 return f"<{__name__}.StatsLevel3 object at {hex(id(self))}>"
2514 @property
2515 def ptr(self):
2516 """Get the pointer address to the data as Python :class:`int`."""
2517 return <intptr_t>(self._ptr)
2519 cdef intptr_t _get_ptr(self):
2520 return <intptr_t>(self._ptr)
2522 def __int__(self):
2523 return <intptr_t>(self._ptr)
2525 def __eq__(self, other):
2526 cdef StatsLevel3 other_
2527 if not isinstance(other, StatsLevel3):
2528 return False
2529 other_ = other
2530 return (memcmp(<void *><intptr_t>(self._ptr), <void *><intptr_t>(other_._ptr), sizeof(CUfileStatsLevel3_t)) == 0)
2532 def __getbuffer__(self, Py_buffer *buffer, int flags):
2533 __getbuffer(self, buffer, <void *>self._ptr, sizeof(CUfileStatsLevel3_t), self._readonly)
2535 def __releasebuffer__(self, Py_buffer *buffer):
2536 pass
2538 def __setitem__(self, key, val):
2539 if key == 0 and isinstance(val, _numpy.ndarray):
2540 self._ptr = <CUfileStatsLevel3_t *>malloc(sizeof(CUfileStatsLevel3_t))
2541 if self._ptr == NULL:
2542 raise MemoryError("Error allocating StatsLevel3")
2543 memcpy(<void*>self._ptr, <void*><intptr_t>val.ctypes.data, sizeof(CUfileStatsLevel3_t))
2544 self._owner = None
2545 self._owned = True
2546 self._readonly = not val.flags.writeable
2547 else:
2548 setattr(self, key, val)
2550 @property
2551 def detailed(self):
2552 """StatsLevel2: """
2553 return StatsLevel2.from_ptr(<intptr_t>&(self._ptr[0].detailed), self._readonly, self)
2555 @detailed.setter
2556 def detailed(self, val):
2557 if self._readonly:
2558 raise ValueError("This StatsLevel3 instance is read-only")
2559 cdef StatsLevel2 val_ = val
2560 memcpy(<void *>&(self._ptr[0].detailed), <void *>(val_._get_ptr()), sizeof(CUfileStatsLevel2_t) * 1)
2562 @property
2563 def per_gpu_stats(self):
2564 """PerGpuStats: """
2565 return PerGpuStats.from_ptr(<intptr_t>&(self._ptr[0].per_gpu_stats), 16, self._readonly)
2567 @per_gpu_stats.setter
2568 def per_gpu_stats(self, val):
2569 if self._readonly:
2570 raise ValueError("This StatsLevel3 instance is read-only")
2571 cdef PerGpuStats val_ = val
2572 if len(val) != 16:
2573 raise ValueError(f"Expected length { 16 } for field per_gpu_stats, got {len(val)}")
2574 memcpy(<void *>&(self._ptr[0].per_gpu_stats), <void *>(val_._get_ptr()), sizeof(CUfilePerGpuStats_t) * 16)
2576 @property
2577 def num_gpus(self):
2578 """int: """
2579 return self._ptr[0].num_gpus
2581 @num_gpus.setter
2582 def num_gpus(self, val):
2583 if self._readonly:
2584 raise ValueError("This StatsLevel3 instance is read-only")
2585 self._ptr[0].num_gpus = val
2587 @staticmethod
2588 def from_buffer(buffer):
2589 """Create an StatsLevel3 instance with the memory from the given buffer."""
2590 return __from_buffer(buffer, sizeof(CUfileStatsLevel3_t), StatsLevel3)
2592 @staticmethod
2593 def from_data(data):
2594 """Create an StatsLevel3 instance wrapping the given NumPy array.
2596 Args:
2597 data (_numpy.ndarray): a single-element array of dtype `stats_level3_dtype` holding the data.
2598 """
2599 return __from_data(data, "stats_level3_dtype", stats_level3_dtype, StatsLevel3)
2601 @staticmethod
2602 def from_ptr(intptr_t ptr, bint readonly=False, object owner=None):
2603 """Create an StatsLevel3 instance wrapping the given pointer.
2605 Args:
2606 ptr (intptr_t): pointer address as Python :class:`int` to the data.
2607 owner (object): The Python object that owns the pointer. If not provided, data will be copied.
2608 readonly (bool): whether the data is read-only (to the user). default is `False`.
2609 """
2610 if ptr == 0:
2611 raise ValueError("ptr must not be null (0)")
2612 cdef StatsLevel3 obj = StatsLevel3.__new__(StatsLevel3)
2613 if owner is None:
2614 obj._ptr = <CUfileStatsLevel3_t *>malloc(sizeof(CUfileStatsLevel3_t))
2615 if obj._ptr == NULL:
2616 raise MemoryError("Error allocating StatsLevel3")
2617 memcpy(<void*>(obj._ptr), <void*>ptr, sizeof(CUfileStatsLevel3_t))
2618 obj._owner = None
2619 obj._owned = True
2620 else:
2621 obj._ptr = <CUfileStatsLevel3_t *>ptr
2622 obj._owner = owner
2623 obj._owned = False
2624 obj._readonly = readonly
2625 return obj
2628###############################################################################
2629# Enum
2630###############################################################################
2632class OpError(_FastEnum):
2633 """
2634 See `CUfileOpError`.
2635 """
2636 SUCCESS = CU_FILE_SUCCESS
2637 DRIVER_NOT_INITIALIZED = CU_FILE_DRIVER_NOT_INITIALIZED
2638 DRIVER_INVALID_PROPS = CU_FILE_DRIVER_INVALID_PROPS
2639 DRIVER_UNSUPPORTED_LIMIT = CU_FILE_DRIVER_UNSUPPORTED_LIMIT
2640 DRIVER_VERSION_MISMATCH = CU_FILE_DRIVER_VERSION_MISMATCH
2641 DRIVER_VERSION_READ_ERROR = CU_FILE_DRIVER_VERSION_READ_ERROR
2642 DRIVER_CLOSING = CU_FILE_DRIVER_CLOSING
2643 PLATFORM_NOT_SUPPORTED = CU_FILE_PLATFORM_NOT_SUPPORTED
2644 IO_NOT_SUPPORTED = CU_FILE_IO_NOT_SUPPORTED
2645 DEVICE_NOT_SUPPORTED = CU_FILE_DEVICE_NOT_SUPPORTED
2646 NVFS_DRIVER_ERROR = CU_FILE_NVFS_DRIVER_ERROR
2647 CUDA_DRIVER_ERROR = CU_FILE_CUDA_DRIVER_ERROR
2648 CUDA_POINTER_INVALID = CU_FILE_CUDA_POINTER_INVALID
2649 CUDA_MEMORY_TYPE_INVALID = CU_FILE_CUDA_MEMORY_TYPE_INVALID
2650 CUDA_POINTER_RANGE_ERROR = CU_FILE_CUDA_POINTER_RANGE_ERROR
2651 CUDA_CONTEXT_MISMATCH = CU_FILE_CUDA_CONTEXT_MISMATCH
2652 INVALID_MAPPING_SIZE = CU_FILE_INVALID_MAPPING_SIZE
2653 INVALID_MAPPING_RANGE = CU_FILE_INVALID_MAPPING_RANGE
2654 INVALID_FILE_TYPE = CU_FILE_INVALID_FILE_TYPE
2655 INVALID_FILE_OPEN_FLAG = CU_FILE_INVALID_FILE_OPEN_FLAG
2656 DIO_NOT_SET = CU_FILE_DIO_NOT_SET
2657 INVALID_VALUE = CU_FILE_INVALID_VALUE
2658 MEMORY_ALREADY_REGISTERED = CU_FILE_MEMORY_ALREADY_REGISTERED
2659 MEMORY_NOT_REGISTERED = CU_FILE_MEMORY_NOT_REGISTERED
2660 PERMISSION_DENIED = CU_FILE_PERMISSION_DENIED
2661 DRIVER_ALREADY_OPEN = CU_FILE_DRIVER_ALREADY_OPEN
2662 HANDLE_NOT_REGISTERED = CU_FILE_HANDLE_NOT_REGISTERED
2663 HANDLE_ALREADY_REGISTERED = CU_FILE_HANDLE_ALREADY_REGISTERED
2664 DEVICE_NOT_FOUND = CU_FILE_DEVICE_NOT_FOUND
2665 INTERNAL_ERROR = CU_FILE_INTERNAL_ERROR
2666 GETNEWFD_FAILED = CU_FILE_GETNEWFD_FAILED
2667 NVFS_SETUP_ERROR = CU_FILE_NVFS_SETUP_ERROR
2668 IO_DISABLED = CU_FILE_IO_DISABLED
2669 BATCH_SUBMIT_FAILED = CU_FILE_BATCH_SUBMIT_FAILED
2670 GPU_MEMORY_PINNING_FAILED = CU_FILE_GPU_MEMORY_PINNING_FAILED
2671 BATCH_FULL = CU_FILE_BATCH_FULL
2672 ASYNC_NOT_SUPPORTED = CU_FILE_ASYNC_NOT_SUPPORTED
2673 INTERNAL_BATCH_SETUP_ERROR = CU_FILE_INTERNAL_BATCH_SETUP_ERROR
2674 INTERNAL_BATCH_SUBMIT_ERROR = CU_FILE_INTERNAL_BATCH_SUBMIT_ERROR
2675 INTERNAL_BATCH_GETSTATUS_ERROR = CU_FILE_INTERNAL_BATCH_GETSTATUS_ERROR
2676 INTERNAL_BATCH_CANCEL_ERROR = CU_FILE_INTERNAL_BATCH_CANCEL_ERROR
2677 NOMEM_ERROR = CU_FILE_NOMEM_ERROR
2678 IO_ERROR = CU_FILE_IO_ERROR
2679 INTERNAL_BUF_REGISTER_ERROR = CU_FILE_INTERNAL_BUF_REGISTER_ERROR
2680 HASH_OPR_ERROR = CU_FILE_HASH_OPR_ERROR
2681 INVALID_CONTEXT_ERROR = CU_FILE_INVALID_CONTEXT_ERROR
2682 NVFS_INTERNAL_DRIVER_ERROR = CU_FILE_NVFS_INTERNAL_DRIVER_ERROR
2683 BATCH_NOCOMPAT_ERROR = CU_FILE_BATCH_NOCOMPAT_ERROR
2684 IO_MAX_ERROR = CU_FILE_IO_MAX_ERROR
2686class DriverStatusFlags(_FastEnum):
2687 """
2688 See `CUfileDriverStatusFlags_t`.
2689 """
2690 LUSTRE_SUPPORTED = (CU_FILE_LUSTRE_SUPPORTED, 'Support for DDN LUSTRE')
2691 WEKAFS_SUPPORTED = (CU_FILE_WEKAFS_SUPPORTED, 'Support for WEKAFS')
2692 NFS_SUPPORTED = (CU_FILE_NFS_SUPPORTED, 'Support for NFS')
2693 GPFS_SUPPORTED = CU_FILE_GPFS_SUPPORTED
2694 NVME_SUPPORTED = (CU_FILE_NVME_SUPPORTED, '< Support for GPFS Support for NVMe')
2695 NVMEOF_SUPPORTED = (CU_FILE_NVMEOF_SUPPORTED, 'Support for NVMeOF')
2696 SCSI_SUPPORTED = (CU_FILE_SCSI_SUPPORTED, 'Support for SCSI')
2697 SCALEFLUX_CSD_SUPPORTED = (CU_FILE_SCALEFLUX_CSD_SUPPORTED, 'Support for Scaleflux CSD')
2698 NVMESH_SUPPORTED = (CU_FILE_NVMESH_SUPPORTED, 'Support for NVMesh Block Dev')
2699 BEEGFS_SUPPORTED = (CU_FILE_BEEGFS_SUPPORTED, 'Support for BeeGFS')
2700 NVME_P2P_SUPPORTED = (CU_FILE_NVME_P2P_SUPPORTED, 'Do not use this macro. This is deprecated now')
2701 SCATEFS_SUPPORTED = (CU_FILE_SCATEFS_SUPPORTED, 'Support for ScateFS')
2702 VIRTIOFS_SUPPORTED = (CU_FILE_VIRTIOFS_SUPPORTED, 'Support for VirtioFS')
2703 MAX_TARGET_TYPES = (CU_FILE_MAX_TARGET_TYPES, 'Maximum FS supported')
2705class DriverControlFlags(_FastEnum):
2706 """
2707 See `CUfileDriverControlFlags_t`.
2708 """
2709 USE_POLL_MODE = (CU_FILE_USE_POLL_MODE, 'use POLL mode. properties.use_poll_mode')
2710 ALLOW_COMPAT_MODE = (CU_FILE_ALLOW_COMPAT_MODE, 'allow COMPATIBILITY mode. properties.allow_compat_mode')
2711 POSIX_IO_MODE = (CU_FILE_POSIX_IO_MODE, 'Vanilla posix io mode. properties.posix_io_mode')
2712 FALLBACK_IO_MODE = (CU_FILE_FALLBACK_IO_MODE, 'Fallback io mode. properties.gds_fallback_io')
2714class FeatureFlags(_FastEnum):
2715 """
2716 See `CUfileFeatureFlags_t`.
2717 """
2718 DYN_ROUTING_SUPPORTED = (CU_FILE_DYN_ROUTING_SUPPORTED, 'Support for Dynamic routing to handle devices across the PCIe bridges')
2719 BATCH_IO_SUPPORTED = (CU_FILE_BATCH_IO_SUPPORTED, 'Supported')
2720 STREAMS_SUPPORTED = (CU_FILE_STREAMS_SUPPORTED, 'Supported')
2721 PARALLEL_IO_SUPPORTED = (CU_FILE_PARALLEL_IO_SUPPORTED, 'Supported')
2722 P2P_SUPPORTED = (CU_FILE_P2P_SUPPORTED, 'Support for PCI P2PDMA')
2724class FileHandleType(_FastEnum):
2725 """
2726 See `CUfileFileHandleType`.
2727 """
2728 OPAQUE_FD = (CU_FILE_HANDLE_TYPE_OPAQUE_FD, 'Linux based fd')
2729 OPAQUE_WIN32 = (CU_FILE_HANDLE_TYPE_OPAQUE_WIN32, 'Windows based handle (unsupported)')
2730 USERSPACE_FS = CU_FILE_HANDLE_TYPE_USERSPACE_FS
2732class Opcode(_FastEnum):
2733 """
2734 See `CUfileOpcode_t`.
2735 """
2736 READ = CUFILE_READ
2737 WRITE = CUFILE_WRITE
2739class Status(_FastEnum):
2740 """
2741 See `CUfileStatus_t`.
2742 """
2743 WAITING = CUFILE_WAITING
2744 PENDING = CUFILE_PENDING
2745 INVALID = CUFILE_INVALID
2746 CANCELED = CUFILE_CANCELED
2747 COMPLETE = CUFILE_COMPLETE
2748 TIMEOUT = CUFILE_TIMEOUT
2749 FAILED = CUFILE_FAILED
2751class BatchMode(_FastEnum):
2752 """
2753 See `CUfileBatchMode_t`.
2754 """
2755 BATCH = CUFILE_BATCH
2757class SizeTConfigParameter(_FastEnum):
2758 """
2759 See `CUFileSizeTConfigParameter_t`.
2760 """
2761 PROFILE_STATS = CUFILE_PARAM_PROFILE_STATS
2762 EXECUTION_MAX_IO_QUEUE_DEPTH = CUFILE_PARAM_EXECUTION_MAX_IO_QUEUE_DEPTH
2763 EXECUTION_MAX_IO_THREADS = CUFILE_PARAM_EXECUTION_MAX_IO_THREADS
2764 EXECUTION_MIN_IO_THRESHOLD_SIZE_KB = CUFILE_PARAM_EXECUTION_MIN_IO_THRESHOLD_SIZE_KB
2765 EXECUTION_MAX_REQUEST_PARALLELISM = CUFILE_PARAM_EXECUTION_MAX_REQUEST_PARALLELISM
2766 PROPERTIES_MAX_DIRECT_IO_SIZE_KB = CUFILE_PARAM_PROPERTIES_MAX_DIRECT_IO_SIZE_KB
2767 PROPERTIES_MAX_DEVICE_CACHE_SIZE_KB = CUFILE_PARAM_PROPERTIES_MAX_DEVICE_CACHE_SIZE_KB
2768 PROPERTIES_PER_BUFFER_CACHE_SIZE_KB = CUFILE_PARAM_PROPERTIES_PER_BUFFER_CACHE_SIZE_KB
2769 PROPERTIES_MAX_DEVICE_PINNED_MEM_SIZE_KB = CUFILE_PARAM_PROPERTIES_MAX_DEVICE_PINNED_MEM_SIZE_KB
2770 PROPERTIES_IO_BATCHSIZE = CUFILE_PARAM_PROPERTIES_IO_BATCHSIZE
2771 POLLTHRESHOLD_SIZE_KB = CUFILE_PARAM_POLLTHRESHOLD_SIZE_KB
2772 PROPERTIES_BATCH_IO_TIMEOUT_MS = CUFILE_PARAM_PROPERTIES_BATCH_IO_TIMEOUT_MS
2774class BoolConfigParameter(_FastEnum):
2775 """
2776 See `CUFileBoolConfigParameter_t`.
2777 """
2778 PROPERTIES_USE_POLL_MODE = CUFILE_PARAM_PROPERTIES_USE_POLL_MODE
2779 PROPERTIES_ALLOW_COMPAT_MODE = CUFILE_PARAM_PROPERTIES_ALLOW_COMPAT_MODE
2780 FORCE_COMPAT_MODE = CUFILE_PARAM_FORCE_COMPAT_MODE
2781 FS_MISC_API_CHECK_AGGRESSIVE = CUFILE_PARAM_FS_MISC_API_CHECK_AGGRESSIVE
2782 EXECUTION_PARALLEL_IO = CUFILE_PARAM_EXECUTION_PARALLEL_IO
2783 PROFILE_NVTX = CUFILE_PARAM_PROFILE_NVTX
2784 PROPERTIES_ALLOW_SYSTEM_MEMORY = CUFILE_PARAM_PROPERTIES_ALLOW_SYSTEM_MEMORY
2785 USE_PCIP2PDMA = CUFILE_PARAM_USE_PCIP2PDMA
2786 PREFER_IO_URING = CUFILE_PARAM_PREFER_IO_URING
2787 FORCE_ODIRECT_MODE = CUFILE_PARAM_FORCE_ODIRECT_MODE
2788 SKIP_TOPOLOGY_DETECTION = CUFILE_PARAM_SKIP_TOPOLOGY_DETECTION
2789 STREAM_MEMOPS_BYPASS = CUFILE_PARAM_STREAM_MEMOPS_BYPASS
2791class StringConfigParameter(_FastEnum):
2792 """
2793 See `CUFileStringConfigParameter_t`.
2794 """
2795 LOGGING_LEVEL = CUFILE_PARAM_LOGGING_LEVEL
2796 ENV_LOGFILE_PATH = CUFILE_PARAM_ENV_LOGFILE_PATH
2797 LOG_DIR = CUFILE_PARAM_LOG_DIR
2799class ArrayConfigParameter(_FastEnum):
2800 """
2801 See `CUFileArrayConfigParameter_t`.
2802 """
2803 POSIX_POOL_SLAB_SIZE_KB = CUFILE_PARAM_POSIX_POOL_SLAB_SIZE_KB
2804 POSIX_POOL_SLAB_COUNT = CUFILE_PARAM_POSIX_POOL_SLAB_COUNT
2805 GPU_BOUNCE_BUFFER_SLAB_SIZE_KB = CUFILE_PARAM_GPU_BOUNCE_BUFFER_SLAB_SIZE_KB
2806 GPU_BOUNCE_BUFFER_SLAB_COUNT = CUFILE_PARAM_GPU_BOUNCE_BUFFER_SLAB_COUNT
2808class P2PFlags(_FastEnum):
2809 """
2810 See `CUfileP2PFlags_t`.
2811 """
2812 P2PDMA = (CUFILE_P2PDMA, 'Support for PCI P2PDMA')
2813 NVFS = (CUFILE_NVFS, 'Support for nvidia-fs')
2814 DMABUF = (CUFILE_DMABUF, 'Support for DMA Buffer')
2815 C2C = (CUFILE_C2C, 'Support for Chip-to-Chip (Grace-based systems)')
2816 NVIDIA_PEERMEM = (CUFILE_NVIDIA_PEERMEM, 'Only for IBM Spectrum Scale and WekaFS')
2819###############################################################################
2820# Error handling
2821###############################################################################
2823ctypedef fused ReturnT:
2824 CUfileError_t
2825 ssize_t
2828class cuFileError(Exception):
2830 def __init__(self, status, cu_err=None):
2831 self.status = status 1efgrklhijmbcdnopq
2832 self.cuda_error = cu_err 1efgrklhijmbcdnopq
2833 s = OpError(status) 1efgrklhijmbcdnopq
2834 cdef str err = f"{s.name} ({s.value}): {op_status_error(status)}" 1efgrklhijmbcdnopq
2835 if cu_err is not None: 1efgrklhijmbcdnopq
2836 e = pyCUresult(cu_err) 1efgrklhijmbcdnopq
2837 err += f"; CUDA status: {e.name} ({e.value})" 1efgrklhijmbcdnopq
2838 super(cuFileError, self).__init__(err) 1efgrklhijmbcdnopq
2840 def __reduce__(self):
2841 return (type(self), (self.status, self.cuda_error))
2844@cython.profile(False)
2845cdef int check_status(ReturnT status) except 1 nogil:
2846 if ReturnT is CUfileError_t:
2847 if status.err != 0 or status.cu_err != 0: 1aeNOfPQgRSrTUEVWFXYGZ0H12I34k56l78hJ9i!#j$%m'(L)*M+,byscztdAun-.oBp/K:qCvwDx
2848 with gil: 1efgrklhijmbcdnopq
2849 raise cuFileError(status.err, status.cu_err) 1efgrklhijmbcdnopq
2850 elif ReturnT is ssize_t:
2851 if status == -1:
2852 # note: this assumes cuFile already properly resets errno in each API
2853 with gil:
2854 raise cuFileError(errno.errno)
2855 return 0 1aeNOfPQgRSrTUEVWFXYGZ0H12I345678hJ9i!#j$%'(L)*M+,byscztdAu-.oBp/K:qCvwDx
2858###############################################################################
2859# Wrapper functions
2860###############################################################################
2862cpdef intptr_t handle_register(intptr_t descr) except? 0:
2863 """cuFileHandleRegister is required, and performs extra checking that is memoized to provide increased performance on later cuFile operations.
2865 Args:
2866 descr (intptr_t): ``CUfileDescr_t`` file descriptor (OS agnostic).
2868 Returns:
2869 intptr_t: ``CUfileHandle_t`` opaque file handle for IO operations.
2871 .. seealso:: `cuFileHandleRegister`
2872 """
2873 cdef Handle fh
2874 with nogil: 1efgklhijmbcdn
2875 __status__ = cuFileHandleRegister(&fh, <CUfileDescr_t*>descr) 1efgklhijmbcdn
2876 check_status(__status__) 1efgklhijmbcdn
2877 return <intptr_t>fh
2880cpdef void handle_deregister(intptr_t fh) except*:
2881 """releases a registered filehandle from cuFile.
2883 Args:
2884 fh (intptr_t): ``CUfileHandle_t`` file handle.
2886 .. seealso:: `cuFileHandleDeregister`
2887 """
2888 cuFileHandleDeregister(<Handle>fh)
2891cpdef buf_register(intptr_t buf_ptr_base, size_t length, int flags):
2892 """register an existing cudaMalloced memory with cuFile to pin for GPUDirect Storage access or register host allocated memory with cuFile.
2894 Args:
2895 buf_ptr_base (intptr_t): buffer pointer allocated.
2896 length (size_t): size of memory region from the above specified bufPtr.
2897 flags (int): CU_FILE_RDMA_REGISTER.
2899 .. seealso:: `cuFileBufRegister`
2900 """
2901 with nogil: 1efgrEFGHIhij
2902 __status__ = cuFileBufRegister(<const void*>buf_ptr_base, length, flags) 1efgrEFGHIhij
2903 check_status(__status__) 1efgrEFGHIhij
2906cpdef buf_deregister(intptr_t buf_ptr_base):
2907 """deregister an already registered device or host memory from cuFile.
2909 Args:
2910 buf_ptr_base (intptr_t): buffer pointer to deregister.
2912 .. seealso:: `cuFileBufDeregister`
2913 """
2914 with nogil: 1rEFGHI
2915 __status__ = cuFileBufDeregister(<const void*>buf_ptr_base) 1rEFGHI
2916 check_status(__status__) 1rEFGHI
2919cpdef driver_open():
2920 """Initialize the cuFile library and open the nvidia-fs driver.
2922 .. seealso:: `cuFileDriverOpen`
2923 """
2924 with nogil: 1NPRTVXZ1357J!$')+yzA-KCD
2925 __status__ = cuFileDriverOpen() 1NPRTVXZ1357J!$')+yzA-KCD
2926 check_status(__status__) 1NPRTVXZ1357J!$')+yzA-KCD
2929cpdef use_count():
2930 """returns use count of cufile drivers at that moment by the process.
2932 .. seealso:: `cuFileUseCount`
2933 """
2934 with nogil:
2935 __status__ = cuFileUseCount()
2936 check_status(__status__)
2939cpdef driver_get_properties(intptr_t props):
2940 """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.
2942 Args:
2943 props (intptr_t): Properties to get.
2945 .. seealso:: `cuFileDriverGetProperties`
2946 """
2947 with nogil:
2948 __status__ = cuFileDriverGetProperties(<CUfileDrvProps_t*>props)
2949 check_status(__status__)
2952cpdef driver_set_poll_mode(bint poll, size_t poll_threshold_size):
2953 """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.
2955 Args:
2956 poll (bint): boolean to indicate whether to use poll mode or not.
2957 poll_threshold_size (size_t): max IO size to use for POLLING mode in KB.
2959 .. seealso:: `cuFileDriverSetPollMode`
2960 """
2961 with nogil:
2962 __status__ = cuFileDriverSetPollMode(<cpp_bool>poll, poll_threshold_size)
2963 check_status(__status__)
2966cpdef driver_set_max_direct_io_size(size_t max_direct_io_size):
2967 """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.
2969 Args:
2970 max_direct_io_size (size_t): maximum allowed direct io size in KB.
2972 .. seealso:: `cuFileDriverSetMaxDirectIOSize`
2973 """
2974 with nogil:
2975 __status__ = cuFileDriverSetMaxDirectIOSize(max_direct_io_size)
2976 check_status(__status__)
2979cpdef driver_set_max_cache_size(size_t max_cache_size):
2980 """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.
2982 Args:
2983 max_cache_size (size_t): The maximum GPU buffer space per device used for internal use in KB.
2985 .. seealso:: `cuFileDriverSetMaxCacheSize`
2986 """
2987 with nogil:
2988 __status__ = cuFileDriverSetMaxCacheSize(max_cache_size)
2989 check_status(__status__)
2992cpdef driver_set_max_pinned_mem_size(size_t max_pinned_size):
2993 """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.
2995 Args:
2996 max_pinned_size (size_t): maximum buffer space that is pinned in KB.
2998 .. seealso:: `cuFileDriverSetMaxPinnedMemSize`
2999 """
3000 with nogil:
3001 __status__ = cuFileDriverSetMaxPinnedMemSize(max_pinned_size)
3002 check_status(__status__)
3005cpdef intptr_t batch_io_set_up(unsigned nr) except? 0:
3006 cdef BatchHandle batch_idp
3007 with nogil:
3008 __status__ = cuFileBatchIOSetUp(&batch_idp, nr)
3009 check_status(__status__)
3010 return <intptr_t>batch_idp
3013cpdef batch_io_submit(intptr_t batch_idp, unsigned nr, intptr_t iocbp, unsigned int flags):
3014 with nogil:
3015 __status__ = cuFileBatchIOSubmit(<BatchHandle>batch_idp, nr, <CUfileIOParams_t*>iocbp, flags)
3016 check_status(__status__)
3019cpdef batch_io_get_status(intptr_t batch_idp, unsigned min_nr, intptr_t nr, intptr_t iocbp, intptr_t timeout):
3020 with nogil:
3021 __status__ = cuFileBatchIOGetStatus(<BatchHandle>batch_idp, min_nr, <unsigned*>nr, <CUfileIOEvents_t*>iocbp, <timespec*>timeout)
3022 check_status(__status__)
3025cpdef batch_io_cancel(intptr_t batch_idp):
3026 with nogil:
3027 __status__ = cuFileBatchIOCancel(<BatchHandle>batch_idp)
3028 check_status(__status__)
3031cpdef void batch_io_destroy(intptr_t batch_idp) except*:
3032 cuFileBatchIODestroy(<BatchHandle>batch_idp)
3035cpdef 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):
3036 with nogil:
3037 __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)
3038 check_status(__status__)
3041cpdef 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):
3042 with nogil:
3043 __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)
3044 check_status(__status__)
3047cpdef stream_register(intptr_t stream, unsigned flags):
3048 with nogil:
3049 __status__ = cuFileStreamRegister(<CUstream>stream, flags)
3050 check_status(__status__)
3053cpdef stream_deregister(intptr_t stream):
3054 with nogil:
3055 __status__ = cuFileStreamDeregister(<CUstream>stream)
3056 check_status(__status__)
3059cpdef int get_version() except? 0:
3060 """Get the cuFile library version.
3062 Returns:
3063 int: Pointer to an integer where the version will be stored.
3065 .. seealso:: `cuFileGetVersion`
3066 """
3067 cdef int version
3068 with nogil: 1ao
3069 __status__ = cuFileGetVersion(&version) 1ao
3070 check_status(__status__) 1ao
3071 return version 1ao
3074cpdef size_t get_parameter_size_t(int param) except? 0:
3075 cdef size_t value
3076 with nogil: 1B
3077 __status__ = cuFileGetParameterSizeT(<_SizeTConfigParameter>param, &value) 1B
3078 check_status(__status__) 1B
3079 return value 1B
3082cpdef bint get_parameter_bool(int param) except? 0:
3083 cdef cpp_bool value
3084 with nogil: 1o
3085 __status__ = cuFileGetParameterBool(<_BoolConfigParameter>param, &value) 1o
3086 check_status(__status__) 1o
3087 return <bint>value 1o
3090cpdef str get_parameter_string(int param, int len):
3091 cdef bytes _desc_str_ = bytes(len) 1p
3092 cdef char* desc_str = _desc_str_ 1p
3093 with nogil: 1p
3094 __status__ = cuFileGetParameterString(<_StringConfigParameter>param, desc_str, len) 1p
3095 check_status(__status__) 1p
3096 return cpython.PyUnicode_FromString(desc_str) 1p
3099cpdef set_parameter_size_t(int param, size_t value):
3100 with nogil: 1B
3101 __status__ = cuFileSetParameterSizeT(<_SizeTConfigParameter>param, value) 1B
3102 check_status(__status__) 1B
3105cpdef set_parameter_bool(int param, bint value):
3106 with nogil: 1o
3107 __status__ = cuFileSetParameterBool(<_BoolConfigParameter>param, <cpp_bool>value) 1o
3108 check_status(__status__) 1o
3111cpdef set_parameter_string(int param, intptr_t desc_str):
3112 with nogil: 1p
3113 __status__ = cuFileSetParameterString(<_StringConfigParameter>param, <const char*>desc_str) 1p
3114 check_status(__status__) 1p
3117cpdef tuple get_parameter_min_max_value(int param):
3118 """Get both the minimum and maximum settable values for a given size_t parameter in a single call.
3120 Args:
3121 param (SizeTConfigParameter): CUfile SizeT configuration parameter.
3123 Returns:
3124 A 2-tuple containing:
3126 - size_t: Pointer to store the minimum value.
3127 - size_t: Pointer to store the maximum value.
3129 .. seealso:: `cuFileGetParameterMinMaxValue`
3130 """
3131 cdef size_t min_value
3132 cdef size_t max_value
3133 with nogil: 1M
3134 __status__ = cuFileGetParameterMinMaxValue(<_SizeTConfigParameter>param, &min_value, &max_value) 1M
3135 check_status(__status__) 1M
3136 return (min_value, max_value) 1M
3139cpdef set_stats_level(int level):
3140 """Set the level of statistics collection for cuFile operations. This will override the cufile.json settings for stats.
3142 Args:
3143 level (int): Statistics level (0 = disabled, 1 = basic, 2 = detailed, 3 = verbose).
3145 .. seealso:: `cuFileSetStatsLevel`
3146 """
3147 with nogil: 1bsctduqvwx
3148 __status__ = cuFileSetStatsLevel(level) 1bsctduqvwx
3149 check_status(__status__) 1bsctduqvwx
3152cpdef int get_stats_level() except? 0:
3153 """Get the current level of statistics collection for cuFile operations.
3155 Returns:
3156 int: Pointer to store the current statistics level.
3158 .. seealso:: `cuFileGetStatsLevel`
3159 """
3160 cdef int level
3161 with nogil: 1yzAqCD
3162 __status__ = cuFileGetStatsLevel(&level) 1yzAqCD
3163 check_status(__status__) 1yzAqCD
3164 return level 1yzAqCD
3167cpdef stats_start():
3168 """Start collecting cuFile statistics.
3170 .. seealso:: `cuFileStatsStart`
3171 """
3172 with nogil: 1bcdw
3173 __status__ = cuFileStatsStart() 1bcdw
3174 check_status(__status__) 1bcdw
3177cpdef stats_stop():
3178 """Stop collecting cuFile statistics.
3180 .. seealso:: `cuFileStatsStop`
3181 """
3182 with nogil: 1w
3183 __status__ = cuFileStatsStop() 1w
3184 check_status(__status__) 1w
3187cpdef stats_reset():
3188 """Reset all cuFile statistics counters.
3190 .. seealso:: `cuFileStatsReset`
3191 """
3192 with nogil: 1stuvx
3193 __status__ = cuFileStatsReset() 1stuvx
3194 check_status(__status__) 1stuvx
3197cpdef get_stats_l1(intptr_t stats):
3198 """Get Level 1 cuFile statistics.
3200 Args:
3201 stats (intptr_t): Pointer to CUfileStatsLevel1_t structure to be filled.
3203 .. seealso:: `cuFileGetStatsL1`
3204 """
3205 with nogil:
3206 __status__ = cuFileGetStatsL1(<CUfileStatsLevel1_t*>stats)
3207 check_status(__status__)
3210cpdef get_stats_l2(intptr_t stats):
3211 """Get Level 2 cuFile statistics.
3213 Args:
3214 stats (intptr_t): Pointer to CUfileStatsLevel2_t structure to be filled.
3216 .. seealso:: `cuFileGetStatsL2`
3217 """
3218 with nogil:
3219 __status__ = cuFileGetStatsL2(<CUfileStatsLevel2_t*>stats)
3220 check_status(__status__)
3223cpdef get_stats_l3(intptr_t stats):
3224 """Get Level 3 cuFile statistics.
3226 Args:
3227 stats (intptr_t): Pointer to CUfileStatsLevel3_t structure to be filled.
3229 .. seealso:: `cuFileGetStatsL3`
3230 """
3231 with nogil:
3232 __status__ = cuFileGetStatsL3(<CUfileStatsLevel3_t*>stats)
3233 check_status(__status__)
3236cpdef size_t get_bar_size_in_kb(int gpu_index) except? 0:
3237 cdef size_t bar_size
3238 with nogil: 1L
3239 __status__ = cuFileGetBARSizeInKB(gpu_index, &bar_size) 1L
3240 check_status(__status__) 1L
3241 return bar_size 1L
3244cpdef set_parameter_posix_pool_slab_array(intptr_t size_values, intptr_t count_values, int len):
3245 """Set both POSIX pool slab size and count parameters as a pair.
3247 Args:
3248 size_values (intptr_t): Array of slab sizes in KB.
3249 count_values (intptr_t): Array of slab counts.
3250 len (int): Length of both arrays (must be the same).
3252 .. seealso:: `cuFileSetParameterPosixPoolSlabArray`
3253 """
3254 with nogil: 1K
3255 __status__ = cuFileSetParameterPosixPoolSlabArray(<const size_t*>size_values, <const size_t*>count_values, len) 1K
3256 check_status(__status__) 1K
3259cpdef get_parameter_posix_pool_slab_array(intptr_t size_values, intptr_t count_values, int len):
3260 """Get both POSIX pool slab size and count parameters as a pair.
3262 Args:
3263 size_values (intptr_t): Buffer to receive slab sizes in KB.
3264 count_values (intptr_t): Buffer to receive slab counts.
3265 len (int): Buffer size (must match the actual parameter length).
3267 .. seealso:: `cuFileGetParameterPosixPoolSlabArray`
3268 """
3269 with nogil: 1/
3270 __status__ = cuFileGetParameterPosixPoolSlabArray(<size_t*>size_values, <size_t*>count_values, len) 1/
3271 check_status(__status__) 1/
3274cpdef str op_status_error(int status):
3275 """cufileop status string.
3277 Args:
3278 status (OpError): the error status to query.
3280 .. seealso:: `cufileop_status_error`
3281 """
3282 cdef bytes _output_
3283 _output_ = cufileop_status_error(<_OpError>status) 1efgrklhijmbcdnopq
3284 return _output_.decode() 1efgrklhijmbcdnopq
3287cpdef driver_close():
3288 """reset the cuFile library and release the nvidia-fs driver
3289 """
3290 with nogil: 1OQSUWY02468J9#%(*,stu.:vx
3291 status = cuFileDriverClose_v2() 1OQSUWY02468J9#%(*,stu.:vx
3292 check_status(status) 1OQSUWY02468J9#%(*,stu.:vx
3294cpdef read(intptr_t fh, intptr_t buf_ptr_base, size_t size, off_t file_offset, off_t buf_ptr_offset):
3295 """read data from a registered file handle to a specified device or host memory.
3297 Args:
3298 fh (intptr_t): ``CUfileHandle_t`` opaque file handle.
3299 buf_ptr_base (intptr_t): base address of buffer in device or host memory.
3300 size (size_t): size bytes to read.
3301 file_offset (off_t): file-offset from begining of the file.
3302 buf_ptr_offset (off_t): offset relative to the buf_ptr_base pointer to read into.
3304 Returns:
3305 ssize_t: number of bytes read on success.
3307 .. seealso:: `cuFileRead`
3308 """
3309 with nogil:
3310 status = cuFileRead(<Handle>fh, <void*>buf_ptr_base, size, file_offset, buf_ptr_offset)
3311 check_status(status)
3312 return status
3315cpdef write(intptr_t fh, intptr_t buf_ptr_base, size_t size, off_t file_offset, off_t buf_ptr_offset):
3316 """write data from a specified device or host memory to a registered file handle.
3318 Args:
3319 fh (intptr_t): ``CUfileHandle_t`` opaque file handle.
3320 buf_ptr_base (intptr_t): base address of buffer in device or host memory.
3321 size (size_t): size bytes to write.
3322 file_offset (off_t): file-offset from begining of the file.
3323 buf_ptr_offset (off_t): offset relative to the buf_ptr_base pointer to write from.
3325 Returns:
3326 ssize_t: number of bytes written on success.
3328 .. seealso:: `cuFileWrite`
3329 """
3330 with nogil:
3331 status = cuFileWrite(<Handle>fh, <const void*>buf_ptr_base, size, file_offset, buf_ptr_offset)
3332 check_status(status)
3333 return status