Coverage for cuda / bindings / cufile.pyx: 32.40%
1540 statements
« prev ^ index » next coverage.py v7.13.4, created at 2026-03-08 01:07 +0000
« prev ^ index » next coverage.py v7.13.4, created at 2026-03-08 01:07 +0000
1# SPDX-FileCopyrightText: Copyright (c) 2025 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.1.1, generator version 0.3.1.dev1322+g646ce84ec. 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 ))
79cdef class _py_anon_pod1:
80 """Empty-initialize an instance of `_anon_pod1`.
83 .. seealso:: `_anon_pod1`
84 """
85 cdef:
86 _anon_pod1 *_ptr
87 object _owner
88 bint _owned
89 bint _readonly
91 def __init__(self):
92 self._ptr = <_anon_pod1 *>calloc(1, sizeof((<CUfileDescr_t*>NULL).handle))
93 if self._ptr == NULL:
94 raise MemoryError("Error allocating _py_anon_pod1")
95 self._owner = None
96 self._owned = True
97 self._readonly = False
99 def __dealloc__(self):
100 cdef _anon_pod1 *ptr
101 if self._owned and self._ptr != NULL:
102 ptr = self._ptr
103 self._ptr = NULL
104 free(ptr)
106 def __repr__(self):
107 return f"<{__name__}._py_anon_pod1 object at {hex(id(self))}>"
109 @property
110 def ptr(self):
111 """Get the pointer address to the data as Python :class:`int`."""
112 return <intptr_t>(self._ptr)
114 cdef intptr_t _get_ptr(self):
115 return <intptr_t>(self._ptr)
117 def __int__(self):
118 return <intptr_t>(self._ptr)
120 def __eq__(self, other):
121 cdef _py_anon_pod1 other_
122 if not isinstance(other, _py_anon_pod1):
123 return False
124 other_ = other
125 return (memcmp(<void *><intptr_t>(self._ptr), <void *><intptr_t>(other_._ptr), sizeof((<CUfileDescr_t*>NULL).handle)) == 0)
127 def __getbuffer__(self, Py_buffer *buffer, int flags):
128 __getbuffer(self, buffer, <void *>self._ptr, sizeof((<CUfileDescr_t*>NULL).handle), self._readonly)
130 def __releasebuffer__(self, Py_buffer *buffer):
131 pass
133 def __setitem__(self, key, val):
134 if key == 0 and isinstance(val, _numpy.ndarray):
135 self._ptr = <_anon_pod1 *>malloc(sizeof((<CUfileDescr_t*>NULL).handle))
136 if self._ptr == NULL:
137 raise MemoryError("Error allocating _py_anon_pod1")
138 memcpy(<void*>self._ptr, <void*><intptr_t>val.ctypes.data, sizeof((<CUfileDescr_t*>NULL).handle))
139 self._owner = None
140 self._owned = True
141 self._readonly = not val.flags.writeable
142 else:
143 setattr(self, key, val)
145 @property
146 def fd(self):
147 """int: """
148 return self._ptr[0].fd
150 @fd.setter
151 def fd(self, val):
152 if self._readonly:
153 raise ValueError("This _py_anon_pod1 instance is read-only")
154 self._ptr[0].fd = val
156 @property
157 def handle(self):
158 """int: """
159 return <intptr_t>(self._ptr[0].handle)
161 @handle.setter
162 def handle(self, val):
163 if self._readonly:
164 raise ValueError("This _py_anon_pod1 instance is read-only")
165 self._ptr[0].handle = <void *><intptr_t>val
167 @staticmethod
168 def from_buffer(buffer):
169 """Create an _py_anon_pod1 instance with the memory from the given buffer."""
170 return __from_buffer(buffer, sizeof((<CUfileDescr_t*>NULL).handle), _py_anon_pod1)
172 @staticmethod
173 def from_data(data):
174 """Create an _py_anon_pod1 instance wrapping the given NumPy array.
176 Args:
177 data (_numpy.ndarray): a single-element array of dtype `_py_anon_pod1_dtype` holding the data.
178 """
179 return __from_data(data, "_py_anon_pod1_dtype", _py_anon_pod1_dtype, _py_anon_pod1)
181 @staticmethod
182 def from_ptr(intptr_t ptr, bint readonly=False, object owner=None):
183 """Create an _py_anon_pod1 instance wrapping the given pointer.
185 Args:
186 ptr (intptr_t): pointer address as Python :class:`int` to the data.
187 owner (object): The Python object that owns the pointer. If not provided, data will be copied.
188 readonly (bool): whether the data is read-only (to the user). default is `False`.
189 """
190 if ptr == 0:
191 raise ValueError("ptr must not be null (0)")
192 cdef _py_anon_pod1 obj = _py_anon_pod1.__new__(_py_anon_pod1)
193 if owner is None:
194 obj._ptr = <_anon_pod1 *>malloc(sizeof((<CUfileDescr_t*>NULL).handle))
195 if obj._ptr == NULL:
196 raise MemoryError("Error allocating _py_anon_pod1")
197 memcpy(<void*>(obj._ptr), <void*>ptr, sizeof((<CUfileDescr_t*>NULL).handle))
198 obj._owner = None
199 obj._owned = True
200 else:
201 obj._ptr = <_anon_pod1 *>ptr
202 obj._owner = owner
203 obj._owned = False
204 obj._readonly = readonly
205 return obj
208cdef _get__py_anon_pod3_dtype_offsets():
209 cdef _anon_pod3 pod = _anon_pod3()
210 return _numpy.dtype({
211 'names': ['dev_ptr_base', 'file_offset', 'dev_ptr_offset', 'size_'],
212 'formats': [_numpy.intp, _numpy.int64, _numpy.int64, _numpy.uint64],
213 'offsets': [
214 (<intptr_t>&(pod.devPtr_base)) - (<intptr_t>&pod),
215 (<intptr_t>&(pod.file_offset)) - (<intptr_t>&pod),
216 (<intptr_t>&(pod.devPtr_offset)) - (<intptr_t>&pod),
217 (<intptr_t>&(pod.size)) - (<intptr_t>&pod),
218 ],
219 'itemsize': sizeof((<CUfileIOParams_t*>NULL).u.batch),
220 })
222_py_anon_pod3_dtype = _get__py_anon_pod3_dtype_offsets()
224cdef class _py_anon_pod3:
225 """Empty-initialize an instance of `_anon_pod3`.
228 .. seealso:: `_anon_pod3`
229 """
230 cdef:
231 _anon_pod3 *_ptr
232 object _owner
233 bint _owned
234 bint _readonly
236 def __init__(self):
237 self._ptr = <_anon_pod3 *>calloc(1, sizeof((<CUfileIOParams_t*>NULL).u.batch))
238 if self._ptr == NULL:
239 raise MemoryError("Error allocating _py_anon_pod3")
240 self._owner = None
241 self._owned = True
242 self._readonly = False
244 def __dealloc__(self):
245 cdef _anon_pod3 *ptr
246 if self._owned and self._ptr != NULL:
247 ptr = self._ptr
248 self._ptr = NULL
249 free(ptr)
251 def __repr__(self):
252 return f"<{__name__}._py_anon_pod3 object at {hex(id(self))}>"
254 @property
255 def ptr(self):
256 """Get the pointer address to the data as Python :class:`int`."""
257 return <intptr_t>(self._ptr)
259 cdef intptr_t _get_ptr(self):
260 return <intptr_t>(self._ptr)
262 def __int__(self):
263 return <intptr_t>(self._ptr)
265 def __eq__(self, other):
266 cdef _py_anon_pod3 other_
267 if not isinstance(other, _py_anon_pod3):
268 return False
269 other_ = other
270 return (memcmp(<void *><intptr_t>(self._ptr), <void *><intptr_t>(other_._ptr), sizeof((<CUfileIOParams_t*>NULL).u.batch)) == 0)
272 def __getbuffer__(self, Py_buffer *buffer, int flags):
273 __getbuffer(self, buffer, <void *>self._ptr, sizeof((<CUfileIOParams_t*>NULL).u.batch), self._readonly)
275 def __releasebuffer__(self, Py_buffer *buffer):
276 pass
278 def __setitem__(self, key, val):
279 if key == 0 and isinstance(val, _numpy.ndarray):
280 self._ptr = <_anon_pod3 *>malloc(sizeof((<CUfileIOParams_t*>NULL).u.batch))
281 if self._ptr == NULL:
282 raise MemoryError("Error allocating _py_anon_pod3")
283 memcpy(<void*>self._ptr, <void*><intptr_t>val.ctypes.data, sizeof((<CUfileIOParams_t*>NULL).u.batch))
284 self._owner = None
285 self._owned = True
286 self._readonly = not val.flags.writeable
287 else:
288 setattr(self, key, val)
290 @property
291 def dev_ptr_base(self):
292 """int: """
293 return <intptr_t>(self._ptr[0].devPtr_base)
295 @dev_ptr_base.setter
296 def dev_ptr_base(self, val):
297 if self._readonly:
298 raise ValueError("This _py_anon_pod3 instance is read-only")
299 self._ptr[0].devPtr_base = <void *><intptr_t>val
301 @property
302 def file_offset(self):
303 """int: """
304 return self._ptr[0].file_offset
306 @file_offset.setter
307 def file_offset(self, val):
308 if self._readonly:
309 raise ValueError("This _py_anon_pod3 instance is read-only")
310 self._ptr[0].file_offset = val
312 @property
313 def dev_ptr_offset(self):
314 """int: """
315 return self._ptr[0].devPtr_offset
317 @dev_ptr_offset.setter
318 def dev_ptr_offset(self, val):
319 if self._readonly:
320 raise ValueError("This _py_anon_pod3 instance is read-only")
321 self._ptr[0].devPtr_offset = val
323 @property
324 def size_(self):
325 """int: """
326 return self._ptr[0].size
328 @size_.setter
329 def size_(self, val):
330 if self._readonly:
331 raise ValueError("This _py_anon_pod3 instance is read-only")
332 self._ptr[0].size = val
334 @staticmethod
335 def from_buffer(buffer):
336 """Create an _py_anon_pod3 instance with the memory from the given buffer."""
337 return __from_buffer(buffer, sizeof((<CUfileIOParams_t*>NULL).u.batch), _py_anon_pod3)
339 @staticmethod
340 def from_data(data):
341 """Create an _py_anon_pod3 instance wrapping the given NumPy array.
343 Args:
344 data (_numpy.ndarray): a single-element array of dtype `_py_anon_pod3_dtype` holding the data.
345 """
346 return __from_data(data, "_py_anon_pod3_dtype", _py_anon_pod3_dtype, _py_anon_pod3)
348 @staticmethod
349 def from_ptr(intptr_t ptr, bint readonly=False, object owner=None):
350 """Create an _py_anon_pod3 instance wrapping the given pointer.
352 Args:
353 ptr (intptr_t): pointer address as Python :class:`int` to the data.
354 owner (object): The Python object that owns the pointer. If not provided, data will be copied.
355 readonly (bool): whether the data is read-only (to the user). default is `False`.
356 """
357 if ptr == 0:
358 raise ValueError("ptr must not be null (0)")
359 cdef _py_anon_pod3 obj = _py_anon_pod3.__new__(_py_anon_pod3)
360 if owner is None:
361 obj._ptr = <_anon_pod3 *>malloc(sizeof((<CUfileIOParams_t*>NULL).u.batch))
362 if obj._ptr == NULL:
363 raise MemoryError("Error allocating _py_anon_pod3")
364 memcpy(<void*>(obj._ptr), <void*>ptr, sizeof((<CUfileIOParams_t*>NULL).u.batch))
365 obj._owner = None
366 obj._owned = True
367 else:
368 obj._ptr = <_anon_pod3 *>ptr
369 obj._owner = owner
370 obj._owned = False
371 obj._readonly = readonly
372 return obj
375cdef _get_io_events_dtype_offsets():
376 cdef CUfileIOEvents_t pod = CUfileIOEvents_t()
377 return _numpy.dtype({
378 'names': ['cookie', 'status', 'ret'],
379 'formats': [_numpy.intp, _numpy.int32, _numpy.uint64],
380 'offsets': [
381 (<intptr_t>&(pod.cookie)) - (<intptr_t>&pod),
382 (<intptr_t>&(pod.status)) - (<intptr_t>&pod),
383 (<intptr_t>&(pod.ret)) - (<intptr_t>&pod),
384 ],
385 'itemsize': sizeof(CUfileIOEvents_t),
386 })
388io_events_dtype = _get_io_events_dtype_offsets()
390cdef class IOEvents:
391 """Empty-initialize an array of `CUfileIOEvents_t`.
393 The resulting object is of length `size` and of dtype `io_events_dtype`.
394 If default-constructed, the instance represents a single struct.
396 Args:
397 size (int): number of structs, default=1.
400 .. seealso:: `CUfileIOEvents_t`
401 """
402 cdef:
403 readonly object _data
407 def __init__(self, size=1):
408 arr = _numpy.empty(size, dtype=io_events_dtype)
409 self._data = arr.view(_numpy.recarray)
410 assert self._data.itemsize == sizeof(CUfileIOEvents_t), \
411 f"itemsize {self._data.itemsize} mismatches struct size { sizeof(CUfileIOEvents_t) }"
413 def __repr__(self):
414 if self._data.size > 1:
415 return f"<{__name__}.IOEvents_Array_{self._data.size} object at {hex(id(self))}>"
416 else:
417 return f"<{__name__}.IOEvents object at {hex(id(self))}>"
419 @property
420 def ptr(self):
421 """Get the pointer address to the data as Python :class:`int`."""
422 return self._data.ctypes.data
424 cdef intptr_t _get_ptr(self):
425 return self._data.ctypes.data
427 def __int__(self):
428 if self._data.size > 1:
429 raise TypeError("int() argument must be a bytes-like object of size 1. "
430 "To get the pointer address of an array, use .ptr")
431 return self._data.ctypes.data
433 def __len__(self):
434 return self._data.size
436 def __eq__(self, other):
437 cdef object self_data = self._data
438 if (not isinstance(other, IOEvents)) or self_data.size != other._data.size or self_data.dtype != other._data.dtype:
439 return False
440 return bool((self_data == other._data).all())
442 def __getbuffer__(self, Py_buffer *buffer, int flags):
443 cpython.PyObject_GetBuffer(self._data, buffer, flags)
445 def __releasebuffer__(self, Py_buffer *buffer):
446 cpython.PyBuffer_Release(buffer)
448 @property
449 def cookie(self):
450 """Union[~_numpy.intp, int]: """
451 if self._data.size == 1:
452 return int(self._data.cookie[0])
453 return self._data.cookie
455 @cookie.setter
456 def cookie(self, val):
457 self._data.cookie = val
459 @property
460 def status(self):
461 """Union[~_numpy.int32, int]: """
462 if self._data.size == 1:
463 return int(self._data.status[0])
464 return self._data.status
466 @status.setter
467 def status(self, val):
468 self._data.status = val
470 @property
471 def ret(self):
472 """Union[~_numpy.uint64, int]: """
473 if self._data.size == 1:
474 return int(self._data.ret[0])
475 return self._data.ret
477 @ret.setter
478 def ret(self, val):
479 self._data.ret = val
481 def __getitem__(self, key):
482 cdef ssize_t key_
483 cdef ssize_t size
484 if isinstance(key, int):
485 key_ = key
486 size = self._data.size
487 if key_ >= size or key_ <= -(size+1):
488 raise IndexError("index is out of bounds")
489 if key_ < 0:
490 key_ += size
491 return IOEvents.from_data(self._data[key_:key_+1])
492 out = self._data[key]
493 if isinstance(out, _numpy.recarray) and out.dtype == io_events_dtype:
494 return IOEvents.from_data(out)
495 return out
497 def __setitem__(self, key, val):
498 self._data[key] = val
500 @staticmethod
501 def from_buffer(buffer):
502 """Create an IOEvents instance with the memory from the given buffer."""
503 return IOEvents.from_data(_numpy.frombuffer(buffer, dtype=io_events_dtype))
505 @staticmethod
506 def from_data(data):
507 """Create an IOEvents instance wrapping the given NumPy array.
509 Args:
510 data (_numpy.ndarray): a 1D array of dtype `io_events_dtype` holding the data.
511 """
512 cdef IOEvents obj = IOEvents.__new__(IOEvents)
513 if not isinstance(data, _numpy.ndarray):
514 raise TypeError("data argument must be a NumPy ndarray")
515 if data.ndim != 1:
516 raise ValueError("data array must be 1D")
517 if data.dtype != io_events_dtype:
518 raise ValueError("data array must be of dtype io_events_dtype")
519 obj._data = data.view(_numpy.recarray)
521 return obj
523 @staticmethod
524 def from_ptr(intptr_t ptr, size_t size=1, bint readonly=False):
525 """Create an IOEvents instance wrapping the given pointer.
527 Args:
528 ptr (intptr_t): pointer address as Python :class:`int` to the data.
529 size (int): number of structs, default=1.
530 readonly (bool): whether the data is read-only (to the user). default is `False`.
531 """
532 if ptr == 0:
533 raise ValueError("ptr must not be null (0)")
534 cdef IOEvents obj = IOEvents.__new__(IOEvents)
535 cdef flag = cpython.buffer.PyBUF_READ if readonly else cpython.buffer.PyBUF_WRITE
536 cdef object buf = cpython.memoryview.PyMemoryView_FromMemory(
537 <char*>ptr, sizeof(CUfileIOEvents_t) * size, flag)
538 data = _numpy.ndarray(size, buffer=buf, dtype=io_events_dtype)
539 obj._data = data.view(_numpy.recarray)
541 return obj
544cdef _get_op_counter_dtype_offsets():
545 cdef CUfileOpCounter_t pod = CUfileOpCounter_t()
546 return _numpy.dtype({
547 'names': ['ok', 'err'],
548 'formats': [_numpy.uint64, _numpy.uint64],
549 'offsets': [
550 (<intptr_t>&(pod.ok)) - (<intptr_t>&pod),
551 (<intptr_t>&(pod.err)) - (<intptr_t>&pod),
552 ],
553 'itemsize': sizeof(CUfileOpCounter_t),
554 })
556op_counter_dtype = _get_op_counter_dtype_offsets()
558cdef class OpCounter:
559 """Empty-initialize an instance of `CUfileOpCounter_t`.
562 .. seealso:: `CUfileOpCounter_t`
563 """
564 cdef:
565 CUfileOpCounter_t *_ptr
566 object _owner
567 bint _owned
568 bint _readonly
570 def __init__(self):
571 self._ptr = <CUfileOpCounter_t *>calloc(1, sizeof(CUfileOpCounter_t))
572 if self._ptr == NULL:
573 raise MemoryError("Error allocating OpCounter")
574 self._owner = None
575 self._owned = True
576 self._readonly = False
578 def __dealloc__(self):
579 cdef CUfileOpCounter_t *ptr
580 if self._owned and self._ptr != NULL:
581 ptr = self._ptr
582 self._ptr = NULL
583 free(ptr)
585 def __repr__(self):
586 return f"<{__name__}.OpCounter object at {hex(id(self))}>"
588 @property
589 def ptr(self):
590 """Get the pointer address to the data as Python :class:`int`."""
591 return <intptr_t>(self._ptr)
593 cdef intptr_t _get_ptr(self):
594 return <intptr_t>(self._ptr)
596 def __int__(self):
597 return <intptr_t>(self._ptr)
599 def __eq__(self, other):
600 cdef OpCounter other_
601 if not isinstance(other, OpCounter):
602 return False
603 other_ = other
604 return (memcmp(<void *><intptr_t>(self._ptr), <void *><intptr_t>(other_._ptr), sizeof(CUfileOpCounter_t)) == 0)
606 def __getbuffer__(self, Py_buffer *buffer, int flags):
607 __getbuffer(self, buffer, <void *>self._ptr, sizeof(CUfileOpCounter_t), self._readonly)
609 def __releasebuffer__(self, Py_buffer *buffer):
610 pass
612 def __setitem__(self, key, val):
613 if key == 0 and isinstance(val, _numpy.ndarray):
614 self._ptr = <CUfileOpCounter_t *>malloc(sizeof(CUfileOpCounter_t))
615 if self._ptr == NULL:
616 raise MemoryError("Error allocating OpCounter")
617 memcpy(<void*>self._ptr, <void*><intptr_t>val.ctypes.data, sizeof(CUfileOpCounter_t))
618 self._owner = None
619 self._owned = True
620 self._readonly = not val.flags.writeable
621 else:
622 setattr(self, key, val)
624 @property
625 def ok(self):
626 """int: """
627 return self._ptr[0].ok
629 @ok.setter
630 def ok(self, val):
631 if self._readonly:
632 raise ValueError("This OpCounter instance is read-only")
633 self._ptr[0].ok = val
635 @property
636 def err(self):
637 """int: """
638 return self._ptr[0].err
640 @err.setter
641 def err(self, val):
642 if self._readonly:
643 raise ValueError("This OpCounter instance is read-only")
644 self._ptr[0].err = val
646 @staticmethod
647 def from_buffer(buffer):
648 """Create an OpCounter instance with the memory from the given buffer."""
649 return __from_buffer(buffer, sizeof(CUfileOpCounter_t), OpCounter)
651 @staticmethod
652 def from_data(data):
653 """Create an OpCounter instance wrapping the given NumPy array.
655 Args:
656 data (_numpy.ndarray): a single-element array of dtype `op_counter_dtype` holding the data.
657 """
658 return __from_data(data, "op_counter_dtype", op_counter_dtype, OpCounter)
660 @staticmethod
661 def from_ptr(intptr_t ptr, bint readonly=False, object owner=None):
662 """Create an OpCounter instance wrapping the given pointer.
664 Args:
665 ptr (intptr_t): pointer address as Python :class:`int` to the data.
666 owner (object): The Python object that owns the pointer. If not provided, data will be copied.
667 readonly (bool): whether the data is read-only (to the user). default is `False`.
668 """
669 if ptr == 0:
670 raise ValueError("ptr must not be null (0)")
671 cdef OpCounter obj = OpCounter.__new__(OpCounter)
672 if owner is None:
673 obj._ptr = <CUfileOpCounter_t *>malloc(sizeof(CUfileOpCounter_t))
674 if obj._ptr == NULL:
675 raise MemoryError("Error allocating OpCounter")
676 memcpy(<void*>(obj._ptr), <void*>ptr, sizeof(CUfileOpCounter_t))
677 obj._owner = None
678 obj._owned = True
679 else:
680 obj._ptr = <CUfileOpCounter_t *>ptr
681 obj._owner = owner
682 obj._owned = False
683 obj._readonly = readonly
684 return obj
687cdef _get_per_gpu_stats_dtype_offsets():
688 cdef CUfilePerGpuStats_t pod = CUfilePerGpuStats_t()
689 return _numpy.dtype({
690 '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'],
691 '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],
692 'offsets': [
693 (<intptr_t>&(pod.uuid)) - (<intptr_t>&pod),
694 (<intptr_t>&(pod.read_bytes)) - (<intptr_t>&pod),
695 (<intptr_t>&(pod.read_bw_bytes_per_sec)) - (<intptr_t>&pod),
696 (<intptr_t>&(pod.read_utilization)) - (<intptr_t>&pod),
697 (<intptr_t>&(pod.read_duration_us)) - (<intptr_t>&pod),
698 (<intptr_t>&(pod.n_total_reads)) - (<intptr_t>&pod),
699 (<intptr_t>&(pod.n_p2p_reads)) - (<intptr_t>&pod),
700 (<intptr_t>&(pod.n_nvfs_reads)) - (<intptr_t>&pod),
701 (<intptr_t>&(pod.n_posix_reads)) - (<intptr_t>&pod),
702 (<intptr_t>&(pod.n_unaligned_reads)) - (<intptr_t>&pod),
703 (<intptr_t>&(pod.n_dr_reads)) - (<intptr_t>&pod),
704 (<intptr_t>&(pod.n_sparse_regions)) - (<intptr_t>&pod),
705 (<intptr_t>&(pod.n_inline_regions)) - (<intptr_t>&pod),
706 (<intptr_t>&(pod.n_reads_err)) - (<intptr_t>&pod),
707 (<intptr_t>&(pod.writes_bytes)) - (<intptr_t>&pod),
708 (<intptr_t>&(pod.write_bw_bytes_per_sec)) - (<intptr_t>&pod),
709 (<intptr_t>&(pod.write_utilization)) - (<intptr_t>&pod),
710 (<intptr_t>&(pod.write_duration_us)) - (<intptr_t>&pod),
711 (<intptr_t>&(pod.n_total_writes)) - (<intptr_t>&pod),
712 (<intptr_t>&(pod.n_p2p_writes)) - (<intptr_t>&pod),
713 (<intptr_t>&(pod.n_nvfs_writes)) - (<intptr_t>&pod),
714 (<intptr_t>&(pod.n_posix_writes)) - (<intptr_t>&pod),
715 (<intptr_t>&(pod.n_unaligned_writes)) - (<intptr_t>&pod),
716 (<intptr_t>&(pod.n_dr_writes)) - (<intptr_t>&pod),
717 (<intptr_t>&(pod.n_writes_err)) - (<intptr_t>&pod),
718 (<intptr_t>&(pod.n_mmap)) - (<intptr_t>&pod),
719 (<intptr_t>&(pod.n_mmap_ok)) - (<intptr_t>&pod),
720 (<intptr_t>&(pod.n_mmap_err)) - (<intptr_t>&pod),
721 (<intptr_t>&(pod.n_mmap_free)) - (<intptr_t>&pod),
722 (<intptr_t>&(pod.reg_bytes)) - (<intptr_t>&pod),
723 ],
724 'itemsize': sizeof(CUfilePerGpuStats_t),
725 })
727per_gpu_stats_dtype = _get_per_gpu_stats_dtype_offsets()
729cdef class PerGpuStats:
730 """Empty-initialize an array of `CUfilePerGpuStats_t`.
732 The resulting object is of length `size` and of dtype `per_gpu_stats_dtype`.
733 If default-constructed, the instance represents a single struct.
735 Args:
736 size (int): number of structs, default=1.
739 .. seealso:: `CUfilePerGpuStats_t`
740 """
741 cdef:
742 readonly object _data
746 def __init__(self, size=1):
747 arr = _numpy.empty(size, dtype=per_gpu_stats_dtype)
748 self._data = arr.view(_numpy.recarray)
749 assert self._data.itemsize == sizeof(CUfilePerGpuStats_t), \
750 f"itemsize {self._data.itemsize} mismatches struct size { sizeof(CUfilePerGpuStats_t) }"
752 def __repr__(self):
753 if self._data.size > 1:
754 return f"<{__name__}.PerGpuStats_Array_{self._data.size} object at {hex(id(self))}>"
755 else:
756 return f"<{__name__}.PerGpuStats object at {hex(id(self))}>"
758 @property
759 def ptr(self):
760 """Get the pointer address to the data as Python :class:`int`."""
761 return self._data.ctypes.data
763 cdef intptr_t _get_ptr(self):
764 return self._data.ctypes.data
766 def __int__(self):
767 if self._data.size > 1:
768 raise TypeError("int() argument must be a bytes-like object of size 1. "
769 "To get the pointer address of an array, use .ptr")
770 return self._data.ctypes.data
772 def __len__(self):
773 return self._data.size
775 def __eq__(self, other):
776 cdef object self_data = self._data
777 if (not isinstance(other, PerGpuStats)) or self_data.size != other._data.size or self_data.dtype != other._data.dtype:
778 return False
779 return bool((self_data == other._data).all())
781 def __getbuffer__(self, Py_buffer *buffer, int flags):
782 cpython.PyObject_GetBuffer(self._data, buffer, flags)
784 def __releasebuffer__(self, Py_buffer *buffer):
785 cpython.PyBuffer_Release(buffer)
787 @property
788 def uuid(self):
789 """~_numpy.int8: (array of length 16)."""
790 return self._data.uuid
792 @uuid.setter
793 def uuid(self, val):
794 self._data.uuid = val
796 @property
797 def read_bytes(self):
798 """Union[~_numpy.uint64, int]: """
799 if self._data.size == 1:
800 return int(self._data.read_bytes[0])
801 return self._data.read_bytes
803 @read_bytes.setter
804 def read_bytes(self, val):
805 self._data.read_bytes = val
807 @property
808 def read_bw_bytes_per_sec(self):
809 """Union[~_numpy.uint64, int]: """
810 if self._data.size == 1:
811 return int(self._data.read_bw_bytes_per_sec[0])
812 return self._data.read_bw_bytes_per_sec
814 @read_bw_bytes_per_sec.setter
815 def read_bw_bytes_per_sec(self, val):
816 self._data.read_bw_bytes_per_sec = val
818 @property
819 def read_utilization(self):
820 """Union[~_numpy.uint64, int]: """
821 if self._data.size == 1:
822 return int(self._data.read_utilization[0])
823 return self._data.read_utilization
825 @read_utilization.setter
826 def read_utilization(self, val):
827 self._data.read_utilization = val
829 @property
830 def read_duration_us(self):
831 """Union[~_numpy.uint64, int]: """
832 if self._data.size == 1:
833 return int(self._data.read_duration_us[0])
834 return self._data.read_duration_us
836 @read_duration_us.setter
837 def read_duration_us(self, val):
838 self._data.read_duration_us = val
840 @property
841 def n_total_reads(self):
842 """Union[~_numpy.uint64, int]: """
843 if self._data.size == 1:
844 return int(self._data.n_total_reads[0])
845 return self._data.n_total_reads
847 @n_total_reads.setter
848 def n_total_reads(self, val):
849 self._data.n_total_reads = val
851 @property
852 def n_p2p_reads(self):
853 """Union[~_numpy.uint64, int]: """
854 if self._data.size == 1:
855 return int(self._data.n_p2p_reads[0])
856 return self._data.n_p2p_reads
858 @n_p2p_reads.setter
859 def n_p2p_reads(self, val):
860 self._data.n_p2p_reads = val
862 @property
863 def n_nvfs_reads(self):
864 """Union[~_numpy.uint64, int]: """
865 if self._data.size == 1:
866 return int(self._data.n_nvfs_reads[0])
867 return self._data.n_nvfs_reads
869 @n_nvfs_reads.setter
870 def n_nvfs_reads(self, val):
871 self._data.n_nvfs_reads = val
873 @property
874 def n_posix_reads(self):
875 """Union[~_numpy.uint64, int]: """
876 if self._data.size == 1:
877 return int(self._data.n_posix_reads[0])
878 return self._data.n_posix_reads
880 @n_posix_reads.setter
881 def n_posix_reads(self, val):
882 self._data.n_posix_reads = val
884 @property
885 def n_unaligned_reads(self):
886 """Union[~_numpy.uint64, int]: """
887 if self._data.size == 1:
888 return int(self._data.n_unaligned_reads[0])
889 return self._data.n_unaligned_reads
891 @n_unaligned_reads.setter
892 def n_unaligned_reads(self, val):
893 self._data.n_unaligned_reads = val
895 @property
896 def n_dr_reads(self):
897 """Union[~_numpy.uint64, int]: """
898 if self._data.size == 1:
899 return int(self._data.n_dr_reads[0])
900 return self._data.n_dr_reads
902 @n_dr_reads.setter
903 def n_dr_reads(self, val):
904 self._data.n_dr_reads = val
906 @property
907 def n_sparse_regions(self):
908 """Union[~_numpy.uint64, int]: """
909 if self._data.size == 1:
910 return int(self._data.n_sparse_regions[0])
911 return self._data.n_sparse_regions
913 @n_sparse_regions.setter
914 def n_sparse_regions(self, val):
915 self._data.n_sparse_regions = val
917 @property
918 def n_inline_regions(self):
919 """Union[~_numpy.uint64, int]: """
920 if self._data.size == 1:
921 return int(self._data.n_inline_regions[0])
922 return self._data.n_inline_regions
924 @n_inline_regions.setter
925 def n_inline_regions(self, val):
926 self._data.n_inline_regions = val
928 @property
929 def n_reads_err(self):
930 """Union[~_numpy.uint64, int]: """
931 if self._data.size == 1:
932 return int(self._data.n_reads_err[0])
933 return self._data.n_reads_err
935 @n_reads_err.setter
936 def n_reads_err(self, val):
937 self._data.n_reads_err = val
939 @property
940 def writes_bytes(self):
941 """Union[~_numpy.uint64, int]: """
942 if self._data.size == 1:
943 return int(self._data.writes_bytes[0])
944 return self._data.writes_bytes
946 @writes_bytes.setter
947 def writes_bytes(self, val):
948 self._data.writes_bytes = val
950 @property
951 def write_bw_bytes_per_sec(self):
952 """Union[~_numpy.uint64, int]: """
953 if self._data.size == 1:
954 return int(self._data.write_bw_bytes_per_sec[0])
955 return self._data.write_bw_bytes_per_sec
957 @write_bw_bytes_per_sec.setter
958 def write_bw_bytes_per_sec(self, val):
959 self._data.write_bw_bytes_per_sec = val
961 @property
962 def write_utilization(self):
963 """Union[~_numpy.uint64, int]: """
964 if self._data.size == 1:
965 return int(self._data.write_utilization[0])
966 return self._data.write_utilization
968 @write_utilization.setter
969 def write_utilization(self, val):
970 self._data.write_utilization = val
972 @property
973 def write_duration_us(self):
974 """Union[~_numpy.uint64, int]: """
975 if self._data.size == 1:
976 return int(self._data.write_duration_us[0])
977 return self._data.write_duration_us
979 @write_duration_us.setter
980 def write_duration_us(self, val):
981 self._data.write_duration_us = val
983 @property
984 def n_total_writes(self):
985 """Union[~_numpy.uint64, int]: """
986 if self._data.size == 1:
987 return int(self._data.n_total_writes[0])
988 return self._data.n_total_writes
990 @n_total_writes.setter
991 def n_total_writes(self, val):
992 self._data.n_total_writes = val
994 @property
995 def n_p2p_writes(self):
996 """Union[~_numpy.uint64, int]: """
997 if self._data.size == 1:
998 return int(self._data.n_p2p_writes[0])
999 return self._data.n_p2p_writes
1001 @n_p2p_writes.setter
1002 def n_p2p_writes(self, val):
1003 self._data.n_p2p_writes = val
1005 @property
1006 def n_nvfs_writes(self):
1007 """Union[~_numpy.uint64, int]: """
1008 if self._data.size == 1:
1009 return int(self._data.n_nvfs_writes[0])
1010 return self._data.n_nvfs_writes
1012 @n_nvfs_writes.setter
1013 def n_nvfs_writes(self, val):
1014 self._data.n_nvfs_writes = val
1016 @property
1017 def n_posix_writes(self):
1018 """Union[~_numpy.uint64, int]: """
1019 if self._data.size == 1:
1020 return int(self._data.n_posix_writes[0])
1021 return self._data.n_posix_writes
1023 @n_posix_writes.setter
1024 def n_posix_writes(self, val):
1025 self._data.n_posix_writes = val
1027 @property
1028 def n_unaligned_writes(self):
1029 """Union[~_numpy.uint64, int]: """
1030 if self._data.size == 1:
1031 return int(self._data.n_unaligned_writes[0])
1032 return self._data.n_unaligned_writes
1034 @n_unaligned_writes.setter
1035 def n_unaligned_writes(self, val):
1036 self._data.n_unaligned_writes = val
1038 @property
1039 def n_dr_writes(self):
1040 """Union[~_numpy.uint64, int]: """
1041 if self._data.size == 1:
1042 return int(self._data.n_dr_writes[0])
1043 return self._data.n_dr_writes
1045 @n_dr_writes.setter
1046 def n_dr_writes(self, val):
1047 self._data.n_dr_writes = val
1049 @property
1050 def n_writes_err(self):
1051 """Union[~_numpy.uint64, int]: """
1052 if self._data.size == 1:
1053 return int(self._data.n_writes_err[0])
1054 return self._data.n_writes_err
1056 @n_writes_err.setter
1057 def n_writes_err(self, val):
1058 self._data.n_writes_err = val
1060 @property
1061 def n_mmap(self):
1062 """Union[~_numpy.uint64, int]: """
1063 if self._data.size == 1:
1064 return int(self._data.n_mmap[0])
1065 return self._data.n_mmap
1067 @n_mmap.setter
1068 def n_mmap(self, val):
1069 self._data.n_mmap = val
1071 @property
1072 def n_mmap_ok(self):
1073 """Union[~_numpy.uint64, int]: """
1074 if self._data.size == 1:
1075 return int(self._data.n_mmap_ok[0])
1076 return self._data.n_mmap_ok
1078 @n_mmap_ok.setter
1079 def n_mmap_ok(self, val):
1080 self._data.n_mmap_ok = val
1082 @property
1083 def n_mmap_err(self):
1084 """Union[~_numpy.uint64, int]: """
1085 if self._data.size == 1:
1086 return int(self._data.n_mmap_err[0])
1087 return self._data.n_mmap_err
1089 @n_mmap_err.setter
1090 def n_mmap_err(self, val):
1091 self._data.n_mmap_err = val
1093 @property
1094 def n_mmap_free(self):
1095 """Union[~_numpy.uint64, int]: """
1096 if self._data.size == 1:
1097 return int(self._data.n_mmap_free[0])
1098 return self._data.n_mmap_free
1100 @n_mmap_free.setter
1101 def n_mmap_free(self, val):
1102 self._data.n_mmap_free = val
1104 @property
1105 def reg_bytes(self):
1106 """Union[~_numpy.uint64, int]: """
1107 if self._data.size == 1:
1108 return int(self._data.reg_bytes[0])
1109 return self._data.reg_bytes
1111 @reg_bytes.setter
1112 def reg_bytes(self, val):
1113 self._data.reg_bytes = val
1115 def __getitem__(self, key):
1116 cdef ssize_t key_
1117 cdef ssize_t size
1118 if isinstance(key, int):
1119 key_ = key
1120 size = self._data.size
1121 if key_ >= size or key_ <= -(size+1):
1122 raise IndexError("index is out of bounds")
1123 if key_ < 0:
1124 key_ += size
1125 return PerGpuStats.from_data(self._data[key_:key_+1])
1126 out = self._data[key]
1127 if isinstance(out, _numpy.recarray) and out.dtype == per_gpu_stats_dtype:
1128 return PerGpuStats.from_data(out)
1129 return out
1131 def __setitem__(self, key, val):
1132 self._data[key] = val
1134 @staticmethod
1135 def from_buffer(buffer):
1136 """Create an PerGpuStats instance with the memory from the given buffer."""
1137 return PerGpuStats.from_data(_numpy.frombuffer(buffer, dtype=per_gpu_stats_dtype))
1139 @staticmethod
1140 def from_data(data):
1141 """Create an PerGpuStats instance wrapping the given NumPy array.
1143 Args:
1144 data (_numpy.ndarray): a 1D array of dtype `per_gpu_stats_dtype` holding the data.
1145 """
1146 cdef PerGpuStats obj = PerGpuStats.__new__(PerGpuStats)
1147 if not isinstance(data, _numpy.ndarray):
1148 raise TypeError("data argument must be a NumPy ndarray")
1149 if data.ndim != 1:
1150 raise ValueError("data array must be 1D")
1151 if data.dtype != per_gpu_stats_dtype:
1152 raise ValueError("data array must be of dtype per_gpu_stats_dtype")
1153 obj._data = data.view(_numpy.recarray)
1155 return obj
1157 @staticmethod
1158 def from_ptr(intptr_t ptr, size_t size=1, bint readonly=False):
1159 """Create an PerGpuStats instance wrapping the given pointer.
1161 Args:
1162 ptr (intptr_t): pointer address as Python :class:`int` to the data.
1163 size (int): number of structs, default=1.
1164 readonly (bool): whether the data is read-only (to the user). default is `False`.
1165 """
1166 if ptr == 0:
1167 raise ValueError("ptr must not be null (0)")
1168 cdef PerGpuStats obj = PerGpuStats.__new__(PerGpuStats)
1169 cdef flag = cpython.buffer.PyBUF_READ if readonly else cpython.buffer.PyBUF_WRITE
1170 cdef object buf = cpython.memoryview.PyMemoryView_FromMemory(
1171 <char*>ptr, sizeof(CUfilePerGpuStats_t) * size, flag)
1172 data = _numpy.ndarray(size, buffer=buf, dtype=per_gpu_stats_dtype)
1173 obj._data = data.view(_numpy.recarray)
1175 return obj
1178cdef _get_descr_dtype_offsets():
1179 cdef CUfileDescr_t pod = CUfileDescr_t()
1180 return _numpy.dtype({
1181 'names': ['type', 'handle', 'fs_ops'],
1182 'formats': [_numpy.int32, _py_anon_pod1_dtype, _numpy.intp],
1183 'offsets': [
1184 (<intptr_t>&(pod.type)) - (<intptr_t>&pod),
1185 (<intptr_t>&(pod.handle)) - (<intptr_t>&pod),
1186 (<intptr_t>&(pod.fs_ops)) - (<intptr_t>&pod),
1187 ],
1188 'itemsize': sizeof(CUfileDescr_t),
1189 })
1191descr_dtype = _get_descr_dtype_offsets()
1193cdef class Descr:
1194 """Empty-initialize an array of `CUfileDescr_t`.
1196 The resulting object is of length `size` and of dtype `descr_dtype`.
1197 If default-constructed, the instance represents a single struct.
1199 Args:
1200 size (int): number of structs, default=1.
1203 .. seealso:: `CUfileDescr_t`
1204 """
1205 cdef:
1206 readonly object _data
1210 def __init__(self, size=1):
1211 arr = _numpy.empty(size, dtype=descr_dtype) 1efgklhijmbcdn
1212 self._data = arr.view(_numpy.recarray) 1efgklhijmbcdn
1213 assert self._data.itemsize == sizeof(CUfileDescr_t), \ 1efgklhijmbcdn
1214 f"itemsize {self._data.itemsize} mismatches struct size { sizeof(CUfileDescr_t) }"
1216 def __repr__(self):
1217 if self._data.size > 1: 1efgklhijmbcdn
1218 return f"<{__name__}.Descr_Array_{self._data.size} object at {hex(id(self))}>"
1219 else:
1220 return f"<{__name__}.Descr object at {hex(id(self))}>" 1efgklhijmbcdn
1222 @property
1223 def ptr(self):
1224 """Get the pointer address to the data as Python :class:`int`."""
1225 return self._data.ctypes.data 1efgklhijmbcdn
1227 cdef intptr_t _get_ptr(self):
1228 return self._data.ctypes.data
1230 def __int__(self):
1231 if self._data.size > 1:
1232 raise TypeError("int() argument must be a bytes-like object of size 1. "
1233 "To get the pointer address of an array, use .ptr")
1234 return self._data.ctypes.data
1236 def __len__(self):
1237 return self._data.size
1239 def __eq__(self, other):
1240 cdef object self_data = self._data
1241 if (not isinstance(other, Descr)) or self_data.size != other._data.size or self_data.dtype != other._data.dtype:
1242 return False
1243 return bool((self_data == other._data).all())
1245 def __getbuffer__(self, Py_buffer *buffer, int flags):
1246 cpython.PyObject_GetBuffer(self._data, buffer, flags)
1248 def __releasebuffer__(self, Py_buffer *buffer):
1249 cpython.PyBuffer_Release(buffer)
1251 @property
1252 def type(self):
1253 """Union[~_numpy.int32, int]: """
1254 if self._data.size == 1:
1255 return int(self._data.type[0])
1256 return self._data.type
1258 @type.setter
1259 def type(self, val):
1260 self._data.type = val 1efgklhijmbcdn
1262 @property
1263 def handle(self):
1264 """_py_anon_pod1_dtype: """
1265 return self._data.handle 1efgklhijmbcdn
1267 @handle.setter
1268 def handle(self, val):
1269 self._data.handle = val
1271 @property
1272 def fs_ops(self):
1273 """Union[~_numpy.intp, int]: """
1274 if self._data.size == 1:
1275 return int(self._data.fs_ops[0])
1276 return self._data.fs_ops
1278 @fs_ops.setter
1279 def fs_ops(self, val):
1280 self._data.fs_ops = val 1efgklhijmbcdn
1282 def __getitem__(self, key):
1283 cdef ssize_t key_
1284 cdef ssize_t size
1285 if isinstance(key, int):
1286 key_ = key
1287 size = self._data.size
1288 if key_ >= size or key_ <= -(size+1):
1289 raise IndexError("index is out of bounds")
1290 if key_ < 0:
1291 key_ += size
1292 return Descr.from_data(self._data[key_:key_+1])
1293 out = self._data[key]
1294 if isinstance(out, _numpy.recarray) and out.dtype == descr_dtype:
1295 return Descr.from_data(out)
1296 return out
1298 def __setitem__(self, key, val):
1299 self._data[key] = val
1301 @staticmethod
1302 def from_buffer(buffer):
1303 """Create an Descr instance with the memory from the given buffer."""
1304 return Descr.from_data(_numpy.frombuffer(buffer, dtype=descr_dtype))
1306 @staticmethod
1307 def from_data(data):
1308 """Create an Descr instance wrapping the given NumPy array.
1310 Args:
1311 data (_numpy.ndarray): a 1D array of dtype `descr_dtype` holding the data.
1312 """
1313 cdef Descr obj = Descr.__new__(Descr)
1314 if not isinstance(data, _numpy.ndarray):
1315 raise TypeError("data argument must be a NumPy ndarray")
1316 if data.ndim != 1:
1317 raise ValueError("data array must be 1D")
1318 if data.dtype != descr_dtype:
1319 raise ValueError("data array must be of dtype descr_dtype")
1320 obj._data = data.view(_numpy.recarray)
1322 return obj
1324 @staticmethod
1325 def from_ptr(intptr_t ptr, size_t size=1, bint readonly=False):
1326 """Create an Descr instance wrapping the given pointer.
1328 Args:
1329 ptr (intptr_t): pointer address as Python :class:`int` to the data.
1330 size (int): number of structs, default=1.
1331 readonly (bool): whether the data is read-only (to the user). default is `False`.
1332 """
1333 if ptr == 0:
1334 raise ValueError("ptr must not be null (0)")
1335 cdef Descr obj = Descr.__new__(Descr)
1336 cdef flag = cpython.buffer.PyBUF_READ if readonly else cpython.buffer.PyBUF_WRITE
1337 cdef object buf = cpython.memoryview.PyMemoryView_FromMemory(
1338 <char*>ptr, sizeof(CUfileDescr_t) * size, flag)
1339 data = _numpy.ndarray(size, buffer=buf, dtype=descr_dtype)
1340 obj._data = data.view(_numpy.recarray)
1342 return obj
1345_py_anon_pod2_dtype = _numpy.dtype((
1346 _numpy.dtype((_numpy.void, sizeof((<CUfileIOParams_t*>NULL).u))),
1347 {
1348 "batch": (_py_anon_pod3_dtype, 0),
1349 }
1350 ))
1353cdef class _py_anon_pod2:
1354 """Empty-initialize an instance of `_anon_pod2`.
1357 .. seealso:: `_anon_pod2`
1358 """
1359 cdef:
1360 _anon_pod2 *_ptr
1361 object _owner
1362 bint _owned
1363 bint _readonly
1365 def __init__(self):
1366 self._ptr = <_anon_pod2 *>calloc(1, sizeof((<CUfileIOParams_t*>NULL).u))
1367 if self._ptr == NULL:
1368 raise MemoryError("Error allocating _py_anon_pod2")
1369 self._owner = None
1370 self._owned = True
1371 self._readonly = False
1373 def __dealloc__(self):
1374 cdef _anon_pod2 *ptr
1375 if self._owned and self._ptr != NULL:
1376 ptr = self._ptr
1377 self._ptr = NULL
1378 free(ptr)
1380 def __repr__(self):
1381 return f"<{__name__}._py_anon_pod2 object at {hex(id(self))}>"
1383 @property
1384 def ptr(self):
1385 """Get the pointer address to the data as Python :class:`int`."""
1386 return <intptr_t>(self._ptr)
1388 cdef intptr_t _get_ptr(self):
1389 return <intptr_t>(self._ptr)
1391 def __int__(self):
1392 return <intptr_t>(self._ptr)
1394 def __eq__(self, other):
1395 cdef _py_anon_pod2 other_
1396 if not isinstance(other, _py_anon_pod2):
1397 return False
1398 other_ = other
1399 return (memcmp(<void *><intptr_t>(self._ptr), <void *><intptr_t>(other_._ptr), sizeof((<CUfileIOParams_t*>NULL).u)) == 0)
1401 def __getbuffer__(self, Py_buffer *buffer, int flags):
1402 __getbuffer(self, buffer, <void *>self._ptr, sizeof((<CUfileIOParams_t*>NULL).u), self._readonly)
1404 def __releasebuffer__(self, Py_buffer *buffer):
1405 pass
1407 def __setitem__(self, key, val):
1408 if key == 0 and isinstance(val, _numpy.ndarray):
1409 self._ptr = <_anon_pod2 *>malloc(sizeof((<CUfileIOParams_t*>NULL).u))
1410 if self._ptr == NULL:
1411 raise MemoryError("Error allocating _py_anon_pod2")
1412 memcpy(<void*>self._ptr, <void*><intptr_t>val.ctypes.data, sizeof((<CUfileIOParams_t*>NULL).u))
1413 self._owner = None
1414 self._owned = True
1415 self._readonly = not val.flags.writeable
1416 else:
1417 setattr(self, key, val)
1419 @property
1420 def batch(self):
1421 """_py_anon_pod3: """
1422 return _py_anon_pod3.from_ptr(<intptr_t>&(self._ptr[0].batch), self._readonly, self)
1424 @batch.setter
1425 def batch(self, val):
1426 if self._readonly:
1427 raise ValueError("This _py_anon_pod2 instance is read-only")
1428 cdef _py_anon_pod3 val_ = val
1429 memcpy(<void *>&(self._ptr[0].batch), <void *>(val_._get_ptr()), sizeof(_anon_pod3) * 1)
1431 @staticmethod
1432 def from_buffer(buffer):
1433 """Create an _py_anon_pod2 instance with the memory from the given buffer."""
1434 return __from_buffer(buffer, sizeof((<CUfileIOParams_t*>NULL).u), _py_anon_pod2)
1436 @staticmethod
1437 def from_data(data):
1438 """Create an _py_anon_pod2 instance wrapping the given NumPy array.
1440 Args:
1441 data (_numpy.ndarray): a single-element array of dtype `_py_anon_pod2_dtype` holding the data.
1442 """
1443 return __from_data(data, "_py_anon_pod2_dtype", _py_anon_pod2_dtype, _py_anon_pod2)
1445 @staticmethod
1446 def from_ptr(intptr_t ptr, bint readonly=False, object owner=None):
1447 """Create an _py_anon_pod2 instance wrapping the given pointer.
1449 Args:
1450 ptr (intptr_t): pointer address as Python :class:`int` to the data.
1451 owner (object): The Python object that owns the pointer. If not provided, data will be copied.
1452 readonly (bool): whether the data is read-only (to the user). default is `False`.
1453 """
1454 if ptr == 0:
1455 raise ValueError("ptr must not be null (0)")
1456 cdef _py_anon_pod2 obj = _py_anon_pod2.__new__(_py_anon_pod2)
1457 if owner is None:
1458 obj._ptr = <_anon_pod2 *>malloc(sizeof((<CUfileIOParams_t*>NULL).u))
1459 if obj._ptr == NULL:
1460 raise MemoryError("Error allocating _py_anon_pod2")
1461 memcpy(<void*>(obj._ptr), <void*>ptr, sizeof((<CUfileIOParams_t*>NULL).u))
1462 obj._owner = None
1463 obj._owned = True
1464 else:
1465 obj._ptr = <_anon_pod2 *>ptr
1466 obj._owner = owner
1467 obj._owned = False
1468 obj._readonly = readonly
1469 return obj
1472cdef _get_stats_level1_dtype_offsets():
1473 cdef CUfileStatsLevel1_t pod = CUfileStatsLevel1_t()
1474 return _numpy.dtype({
1475 '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'],
1476 '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],
1477 'offsets': [
1478 (<intptr_t>&(pod.read_ops)) - (<intptr_t>&pod),
1479 (<intptr_t>&(pod.write_ops)) - (<intptr_t>&pod),
1480 (<intptr_t>&(pod.hdl_register_ops)) - (<intptr_t>&pod),
1481 (<intptr_t>&(pod.hdl_deregister_ops)) - (<intptr_t>&pod),
1482 (<intptr_t>&(pod.buf_register_ops)) - (<intptr_t>&pod),
1483 (<intptr_t>&(pod.buf_deregister_ops)) - (<intptr_t>&pod),
1484 (<intptr_t>&(pod.read_bytes)) - (<intptr_t>&pod),
1485 (<intptr_t>&(pod.write_bytes)) - (<intptr_t>&pod),
1486 (<intptr_t>&(pod.read_bw_bytes_per_sec)) - (<intptr_t>&pod),
1487 (<intptr_t>&(pod.write_bw_bytes_per_sec)) - (<intptr_t>&pod),
1488 (<intptr_t>&(pod.read_lat_avg_us)) - (<intptr_t>&pod),
1489 (<intptr_t>&(pod.write_lat_avg_us)) - (<intptr_t>&pod),
1490 (<intptr_t>&(pod.read_ops_per_sec)) - (<intptr_t>&pod),
1491 (<intptr_t>&(pod.write_ops_per_sec)) - (<intptr_t>&pod),
1492 (<intptr_t>&(pod.read_lat_sum_us)) - (<intptr_t>&pod),
1493 (<intptr_t>&(pod.write_lat_sum_us)) - (<intptr_t>&pod),
1494 (<intptr_t>&(pod.batch_submit_ops)) - (<intptr_t>&pod),
1495 (<intptr_t>&(pod.batch_complete_ops)) - (<intptr_t>&pod),
1496 (<intptr_t>&(pod.batch_setup_ops)) - (<intptr_t>&pod),
1497 (<intptr_t>&(pod.batch_cancel_ops)) - (<intptr_t>&pod),
1498 (<intptr_t>&(pod.batch_destroy_ops)) - (<intptr_t>&pod),
1499 (<intptr_t>&(pod.batch_enqueued_ops)) - (<intptr_t>&pod),
1500 (<intptr_t>&(pod.batch_posix_enqueued_ops)) - (<intptr_t>&pod),
1501 (<intptr_t>&(pod.batch_processed_ops)) - (<intptr_t>&pod),
1502 (<intptr_t>&(pod.batch_posix_processed_ops)) - (<intptr_t>&pod),
1503 (<intptr_t>&(pod.batch_nvfs_submit_ops)) - (<intptr_t>&pod),
1504 (<intptr_t>&(pod.batch_p2p_submit_ops)) - (<intptr_t>&pod),
1505 (<intptr_t>&(pod.batch_aio_submit_ops)) - (<intptr_t>&pod),
1506 (<intptr_t>&(pod.batch_iouring_submit_ops)) - (<intptr_t>&pod),
1507 (<intptr_t>&(pod.batch_mixed_io_submit_ops)) - (<intptr_t>&pod),
1508 (<intptr_t>&(pod.batch_total_submit_ops)) - (<intptr_t>&pod),
1509 (<intptr_t>&(pod.batch_read_bytes)) - (<intptr_t>&pod),
1510 (<intptr_t>&(pod.batch_write_bytes)) - (<intptr_t>&pod),
1511 (<intptr_t>&(pod.batch_read_bw_bytes)) - (<intptr_t>&pod),
1512 (<intptr_t>&(pod.batch_write_bw_bytes)) - (<intptr_t>&pod),
1513 (<intptr_t>&(pod.batch_submit_lat_avg_us)) - (<intptr_t>&pod),
1514 (<intptr_t>&(pod.batch_completion_lat_avg_us)) - (<intptr_t>&pod),
1515 (<intptr_t>&(pod.batch_submit_ops_per_sec)) - (<intptr_t>&pod),
1516 (<intptr_t>&(pod.batch_complete_ops_per_sec)) - (<intptr_t>&pod),
1517 (<intptr_t>&(pod.batch_submit_lat_sum_us)) - (<intptr_t>&pod),
1518 (<intptr_t>&(pod.batch_completion_lat_sum_us)) - (<intptr_t>&pod),
1519 (<intptr_t>&(pod.last_batch_read_bytes)) - (<intptr_t>&pod),
1520 (<intptr_t>&(pod.last_batch_write_bytes)) - (<intptr_t>&pod),
1521 ],
1522 'itemsize': sizeof(CUfileStatsLevel1_t),
1523 })
1525stats_level1_dtype = _get_stats_level1_dtype_offsets()
1527cdef class StatsLevel1:
1528 """Empty-initialize an instance of `CUfileStatsLevel1_t`.
1531 .. seealso:: `CUfileStatsLevel1_t`
1532 """
1533 cdef:
1534 CUfileStatsLevel1_t *_ptr
1535 object _owner
1536 bint _owned
1537 bint _readonly
1539 def __init__(self):
1540 self._ptr = <CUfileStatsLevel1_t *>calloc(1, sizeof(CUfileStatsLevel1_t))
1541 if self._ptr == NULL:
1542 raise MemoryError("Error allocating StatsLevel1")
1543 self._owner = None
1544 self._owned = True
1545 self._readonly = False
1547 def __dealloc__(self):
1548 cdef CUfileStatsLevel1_t *ptr
1549 if self._owned and self._ptr != NULL:
1550 ptr = self._ptr
1551 self._ptr = NULL
1552 free(ptr)
1554 def __repr__(self):
1555 return f"<{__name__}.StatsLevel1 object at {hex(id(self))}>"
1557 @property
1558 def ptr(self):
1559 """Get the pointer address to the data as Python :class:`int`."""
1560 return <intptr_t>(self._ptr)
1562 cdef intptr_t _get_ptr(self):
1563 return <intptr_t>(self._ptr)
1565 def __int__(self):
1566 return <intptr_t>(self._ptr)
1568 def __eq__(self, other):
1569 cdef StatsLevel1 other_
1570 if not isinstance(other, StatsLevel1):
1571 return False
1572 other_ = other
1573 return (memcmp(<void *><intptr_t>(self._ptr), <void *><intptr_t>(other_._ptr), sizeof(CUfileStatsLevel1_t)) == 0)
1575 def __getbuffer__(self, Py_buffer *buffer, int flags):
1576 __getbuffer(self, buffer, <void *>self._ptr, sizeof(CUfileStatsLevel1_t), self._readonly)
1578 def __releasebuffer__(self, Py_buffer *buffer):
1579 pass
1581 def __setitem__(self, key, val):
1582 if key == 0 and isinstance(val, _numpy.ndarray):
1583 self._ptr = <CUfileStatsLevel1_t *>malloc(sizeof(CUfileStatsLevel1_t))
1584 if self._ptr == NULL:
1585 raise MemoryError("Error allocating StatsLevel1")
1586 memcpy(<void*>self._ptr, <void*><intptr_t>val.ctypes.data, sizeof(CUfileStatsLevel1_t))
1587 self._owner = None
1588 self._owned = True
1589 self._readonly = not val.flags.writeable
1590 else:
1591 setattr(self, key, val)
1593 @property
1594 def read_ops(self):
1595 """OpCounter: """
1596 return OpCounter.from_ptr(<intptr_t>&(self._ptr[0].read_ops), self._readonly, self)
1598 @read_ops.setter
1599 def read_ops(self, val):
1600 if self._readonly:
1601 raise ValueError("This StatsLevel1 instance is read-only")
1602 cdef OpCounter val_ = val
1603 memcpy(<void *>&(self._ptr[0].read_ops), <void *>(val_._get_ptr()), sizeof(CUfileOpCounter_t) * 1)
1605 @property
1606 def write_ops(self):
1607 """OpCounter: """
1608 return OpCounter.from_ptr(<intptr_t>&(self._ptr[0].write_ops), self._readonly, self)
1610 @write_ops.setter
1611 def write_ops(self, val):
1612 if self._readonly:
1613 raise ValueError("This StatsLevel1 instance is read-only")
1614 cdef OpCounter val_ = val
1615 memcpy(<void *>&(self._ptr[0].write_ops), <void *>(val_._get_ptr()), sizeof(CUfileOpCounter_t) * 1)
1617 @property
1618 def hdl_register_ops(self):
1619 """OpCounter: """
1620 return OpCounter.from_ptr(<intptr_t>&(self._ptr[0].hdl_register_ops), self._readonly, self)
1622 @hdl_register_ops.setter
1623 def hdl_register_ops(self, val):
1624 if self._readonly:
1625 raise ValueError("This StatsLevel1 instance is read-only")
1626 cdef OpCounter val_ = val
1627 memcpy(<void *>&(self._ptr[0].hdl_register_ops), <void *>(val_._get_ptr()), sizeof(CUfileOpCounter_t) * 1)
1629 @property
1630 def hdl_deregister_ops(self):
1631 """OpCounter: """
1632 return OpCounter.from_ptr(<intptr_t>&(self._ptr[0].hdl_deregister_ops), self._readonly, self)
1634 @hdl_deregister_ops.setter
1635 def hdl_deregister_ops(self, val):
1636 if self._readonly:
1637 raise ValueError("This StatsLevel1 instance is read-only")
1638 cdef OpCounter val_ = val
1639 memcpy(<void *>&(self._ptr[0].hdl_deregister_ops), <void *>(val_._get_ptr()), sizeof(CUfileOpCounter_t) * 1)
1641 @property
1642 def buf_register_ops(self):
1643 """OpCounter: """
1644 return OpCounter.from_ptr(<intptr_t>&(self._ptr[0].buf_register_ops), self._readonly, self)
1646 @buf_register_ops.setter
1647 def buf_register_ops(self, val):
1648 if self._readonly:
1649 raise ValueError("This StatsLevel1 instance is read-only")
1650 cdef OpCounter val_ = val
1651 memcpy(<void *>&(self._ptr[0].buf_register_ops), <void *>(val_._get_ptr()), sizeof(CUfileOpCounter_t) * 1)
1653 @property
1654 def buf_deregister_ops(self):
1655 """OpCounter: """
1656 return OpCounter.from_ptr(<intptr_t>&(self._ptr[0].buf_deregister_ops), self._readonly, self)
1658 @buf_deregister_ops.setter
1659 def buf_deregister_ops(self, val):
1660 if self._readonly:
1661 raise ValueError("This StatsLevel1 instance is read-only")
1662 cdef OpCounter val_ = val
1663 memcpy(<void *>&(self._ptr[0].buf_deregister_ops), <void *>(val_._get_ptr()), sizeof(CUfileOpCounter_t) * 1)
1665 @property
1666 def batch_submit_ops(self):
1667 """OpCounter: """
1668 return OpCounter.from_ptr(<intptr_t>&(self._ptr[0].batch_submit_ops), self._readonly, self)
1670 @batch_submit_ops.setter
1671 def batch_submit_ops(self, val):
1672 if self._readonly:
1673 raise ValueError("This StatsLevel1 instance is read-only")
1674 cdef OpCounter val_ = val
1675 memcpy(<void *>&(self._ptr[0].batch_submit_ops), <void *>(val_._get_ptr()), sizeof(CUfileOpCounter_t) * 1)
1677 @property
1678 def batch_complete_ops(self):
1679 """OpCounter: """
1680 return OpCounter.from_ptr(<intptr_t>&(self._ptr[0].batch_complete_ops), self._readonly, self)
1682 @batch_complete_ops.setter
1683 def batch_complete_ops(self, val):
1684 if self._readonly:
1685 raise ValueError("This StatsLevel1 instance is read-only")
1686 cdef OpCounter val_ = val
1687 memcpy(<void *>&(self._ptr[0].batch_complete_ops), <void *>(val_._get_ptr()), sizeof(CUfileOpCounter_t) * 1)
1689 @property
1690 def batch_setup_ops(self):
1691 """OpCounter: """
1692 return OpCounter.from_ptr(<intptr_t>&(self._ptr[0].batch_setup_ops), self._readonly, self)
1694 @batch_setup_ops.setter
1695 def batch_setup_ops(self, val):
1696 if self._readonly:
1697 raise ValueError("This StatsLevel1 instance is read-only")
1698 cdef OpCounter val_ = val
1699 memcpy(<void *>&(self._ptr[0].batch_setup_ops), <void *>(val_._get_ptr()), sizeof(CUfileOpCounter_t) * 1)
1701 @property
1702 def batch_cancel_ops(self):
1703 """OpCounter: """
1704 return OpCounter.from_ptr(<intptr_t>&(self._ptr[0].batch_cancel_ops), self._readonly, self)
1706 @batch_cancel_ops.setter
1707 def batch_cancel_ops(self, val):
1708 if self._readonly:
1709 raise ValueError("This StatsLevel1 instance is read-only")
1710 cdef OpCounter val_ = val
1711 memcpy(<void *>&(self._ptr[0].batch_cancel_ops), <void *>(val_._get_ptr()), sizeof(CUfileOpCounter_t) * 1)
1713 @property
1714 def batch_destroy_ops(self):
1715 """OpCounter: """
1716 return OpCounter.from_ptr(<intptr_t>&(self._ptr[0].batch_destroy_ops), self._readonly, self)
1718 @batch_destroy_ops.setter
1719 def batch_destroy_ops(self, val):
1720 if self._readonly:
1721 raise ValueError("This StatsLevel1 instance is read-only")
1722 cdef OpCounter val_ = val
1723 memcpy(<void *>&(self._ptr[0].batch_destroy_ops), <void *>(val_._get_ptr()), sizeof(CUfileOpCounter_t) * 1)
1725 @property
1726 def batch_enqueued_ops(self):
1727 """OpCounter: """
1728 return OpCounter.from_ptr(<intptr_t>&(self._ptr[0].batch_enqueued_ops), self._readonly, self)
1730 @batch_enqueued_ops.setter
1731 def batch_enqueued_ops(self, val):
1732 if self._readonly:
1733 raise ValueError("This StatsLevel1 instance is read-only")
1734 cdef OpCounter val_ = val
1735 memcpy(<void *>&(self._ptr[0].batch_enqueued_ops), <void *>(val_._get_ptr()), sizeof(CUfileOpCounter_t) * 1)
1737 @property
1738 def batch_posix_enqueued_ops(self):
1739 """OpCounter: """
1740 return OpCounter.from_ptr(<intptr_t>&(self._ptr[0].batch_posix_enqueued_ops), self._readonly, self)
1742 @batch_posix_enqueued_ops.setter
1743 def batch_posix_enqueued_ops(self, val):
1744 if self._readonly:
1745 raise ValueError("This StatsLevel1 instance is read-only")
1746 cdef OpCounter val_ = val
1747 memcpy(<void *>&(self._ptr[0].batch_posix_enqueued_ops), <void *>(val_._get_ptr()), sizeof(CUfileOpCounter_t) * 1)
1749 @property
1750 def batch_processed_ops(self):
1751 """OpCounter: """
1752 return OpCounter.from_ptr(<intptr_t>&(self._ptr[0].batch_processed_ops), self._readonly, self)
1754 @batch_processed_ops.setter
1755 def batch_processed_ops(self, val):
1756 if self._readonly:
1757 raise ValueError("This StatsLevel1 instance is read-only")
1758 cdef OpCounter val_ = val
1759 memcpy(<void *>&(self._ptr[0].batch_processed_ops), <void *>(val_._get_ptr()), sizeof(CUfileOpCounter_t) * 1)
1761 @property
1762 def batch_posix_processed_ops(self):
1763 """OpCounter: """
1764 return OpCounter.from_ptr(<intptr_t>&(self._ptr[0].batch_posix_processed_ops), self._readonly, self)
1766 @batch_posix_processed_ops.setter
1767 def batch_posix_processed_ops(self, val):
1768 if self._readonly:
1769 raise ValueError("This StatsLevel1 instance is read-only")
1770 cdef OpCounter val_ = val
1771 memcpy(<void *>&(self._ptr[0].batch_posix_processed_ops), <void *>(val_._get_ptr()), sizeof(CUfileOpCounter_t) * 1)
1773 @property
1774 def batch_nvfs_submit_ops(self):
1775 """OpCounter: """
1776 return OpCounter.from_ptr(<intptr_t>&(self._ptr[0].batch_nvfs_submit_ops), self._readonly, self)
1778 @batch_nvfs_submit_ops.setter
1779 def batch_nvfs_submit_ops(self, val):
1780 if self._readonly:
1781 raise ValueError("This StatsLevel1 instance is read-only")
1782 cdef OpCounter val_ = val
1783 memcpy(<void *>&(self._ptr[0].batch_nvfs_submit_ops), <void *>(val_._get_ptr()), sizeof(CUfileOpCounter_t) * 1)
1785 @property
1786 def batch_p2p_submit_ops(self):
1787 """OpCounter: """
1788 return OpCounter.from_ptr(<intptr_t>&(self._ptr[0].batch_p2p_submit_ops), self._readonly, self)
1790 @batch_p2p_submit_ops.setter
1791 def batch_p2p_submit_ops(self, val):
1792 if self._readonly:
1793 raise ValueError("This StatsLevel1 instance is read-only")
1794 cdef OpCounter val_ = val
1795 memcpy(<void *>&(self._ptr[0].batch_p2p_submit_ops), <void *>(val_._get_ptr()), sizeof(CUfileOpCounter_t) * 1)
1797 @property
1798 def batch_aio_submit_ops(self):
1799 """OpCounter: """
1800 return OpCounter.from_ptr(<intptr_t>&(self._ptr[0].batch_aio_submit_ops), self._readonly, self)
1802 @batch_aio_submit_ops.setter
1803 def batch_aio_submit_ops(self, val):
1804 if self._readonly:
1805 raise ValueError("This StatsLevel1 instance is read-only")
1806 cdef OpCounter val_ = val
1807 memcpy(<void *>&(self._ptr[0].batch_aio_submit_ops), <void *>(val_._get_ptr()), sizeof(CUfileOpCounter_t) * 1)
1809 @property
1810 def batch_iouring_submit_ops(self):
1811 """OpCounter: """
1812 return OpCounter.from_ptr(<intptr_t>&(self._ptr[0].batch_iouring_submit_ops), self._readonly, self)
1814 @batch_iouring_submit_ops.setter
1815 def batch_iouring_submit_ops(self, val):
1816 if self._readonly:
1817 raise ValueError("This StatsLevel1 instance is read-only")
1818 cdef OpCounter val_ = val
1819 memcpy(<void *>&(self._ptr[0].batch_iouring_submit_ops), <void *>(val_._get_ptr()), sizeof(CUfileOpCounter_t) * 1)
1821 @property
1822 def batch_mixed_io_submit_ops(self):
1823 """OpCounter: """
1824 return OpCounter.from_ptr(<intptr_t>&(self._ptr[0].batch_mixed_io_submit_ops), self._readonly, self)
1826 @batch_mixed_io_submit_ops.setter
1827 def batch_mixed_io_submit_ops(self, val):
1828 if self._readonly:
1829 raise ValueError("This StatsLevel1 instance is read-only")
1830 cdef OpCounter val_ = val
1831 memcpy(<void *>&(self._ptr[0].batch_mixed_io_submit_ops), <void *>(val_._get_ptr()), sizeof(CUfileOpCounter_t) * 1)
1833 @property
1834 def batch_total_submit_ops(self):
1835 """OpCounter: """
1836 return OpCounter.from_ptr(<intptr_t>&(self._ptr[0].batch_total_submit_ops), self._readonly, self)
1838 @batch_total_submit_ops.setter
1839 def batch_total_submit_ops(self, val):
1840 if self._readonly:
1841 raise ValueError("This StatsLevel1 instance is read-only")
1842 cdef OpCounter val_ = val
1843 memcpy(<void *>&(self._ptr[0].batch_total_submit_ops), <void *>(val_._get_ptr()), sizeof(CUfileOpCounter_t) * 1)
1845 @property
1846 def read_bytes(self):
1847 """int: """
1848 return self._ptr[0].read_bytes
1850 @read_bytes.setter
1851 def read_bytes(self, val):
1852 if self._readonly:
1853 raise ValueError("This StatsLevel1 instance is read-only")
1854 self._ptr[0].read_bytes = val
1856 @property
1857 def write_bytes(self):
1858 """int: """
1859 return self._ptr[0].write_bytes
1861 @write_bytes.setter
1862 def write_bytes(self, val):
1863 if self._readonly:
1864 raise ValueError("This StatsLevel1 instance is read-only")
1865 self._ptr[0].write_bytes = val
1867 @property
1868 def read_bw_bytes_per_sec(self):
1869 """int: """
1870 return self._ptr[0].read_bw_bytes_per_sec
1872 @read_bw_bytes_per_sec.setter
1873 def read_bw_bytes_per_sec(self, val):
1874 if self._readonly:
1875 raise ValueError("This StatsLevel1 instance is read-only")
1876 self._ptr[0].read_bw_bytes_per_sec = val
1878 @property
1879 def write_bw_bytes_per_sec(self):
1880 """int: """
1881 return self._ptr[0].write_bw_bytes_per_sec
1883 @write_bw_bytes_per_sec.setter
1884 def write_bw_bytes_per_sec(self, val):
1885 if self._readonly:
1886 raise ValueError("This StatsLevel1 instance is read-only")
1887 self._ptr[0].write_bw_bytes_per_sec = val
1889 @property
1890 def read_lat_avg_us(self):
1891 """int: """
1892 return self._ptr[0].read_lat_avg_us
1894 @read_lat_avg_us.setter
1895 def read_lat_avg_us(self, val):
1896 if self._readonly:
1897 raise ValueError("This StatsLevel1 instance is read-only")
1898 self._ptr[0].read_lat_avg_us = val
1900 @property
1901 def write_lat_avg_us(self):
1902 """int: """
1903 return self._ptr[0].write_lat_avg_us
1905 @write_lat_avg_us.setter
1906 def write_lat_avg_us(self, val):
1907 if self._readonly:
1908 raise ValueError("This StatsLevel1 instance is read-only")
1909 self._ptr[0].write_lat_avg_us = val
1911 @property
1912 def read_ops_per_sec(self):
1913 """int: """
1914 return self._ptr[0].read_ops_per_sec
1916 @read_ops_per_sec.setter
1917 def read_ops_per_sec(self, val):
1918 if self._readonly:
1919 raise ValueError("This StatsLevel1 instance is read-only")
1920 self._ptr[0].read_ops_per_sec = val
1922 @property
1923 def write_ops_per_sec(self):
1924 """int: """
1925 return self._ptr[0].write_ops_per_sec
1927 @write_ops_per_sec.setter
1928 def write_ops_per_sec(self, val):
1929 if self._readonly:
1930 raise ValueError("This StatsLevel1 instance is read-only")
1931 self._ptr[0].write_ops_per_sec = val
1933 @property
1934 def read_lat_sum_us(self):
1935 """int: """
1936 return self._ptr[0].read_lat_sum_us
1938 @read_lat_sum_us.setter
1939 def read_lat_sum_us(self, val):
1940 if self._readonly:
1941 raise ValueError("This StatsLevel1 instance is read-only")
1942 self._ptr[0].read_lat_sum_us = val
1944 @property
1945 def write_lat_sum_us(self):
1946 """int: """
1947 return self._ptr[0].write_lat_sum_us
1949 @write_lat_sum_us.setter
1950 def write_lat_sum_us(self, val):
1951 if self._readonly:
1952 raise ValueError("This StatsLevel1 instance is read-only")
1953 self._ptr[0].write_lat_sum_us = val
1955 @property
1956 def batch_read_bytes(self):
1957 """int: """
1958 return self._ptr[0].batch_read_bytes
1960 @batch_read_bytes.setter
1961 def batch_read_bytes(self, val):
1962 if self._readonly:
1963 raise ValueError("This StatsLevel1 instance is read-only")
1964 self._ptr[0].batch_read_bytes = val
1966 @property
1967 def batch_write_bytes(self):
1968 """int: """
1969 return self._ptr[0].batch_write_bytes
1971 @batch_write_bytes.setter
1972 def batch_write_bytes(self, val):
1973 if self._readonly:
1974 raise ValueError("This StatsLevel1 instance is read-only")
1975 self._ptr[0].batch_write_bytes = val
1977 @property
1978 def batch_read_bw_bytes(self):
1979 """int: """
1980 return self._ptr[0].batch_read_bw_bytes
1982 @batch_read_bw_bytes.setter
1983 def batch_read_bw_bytes(self, val):
1984 if self._readonly:
1985 raise ValueError("This StatsLevel1 instance is read-only")
1986 self._ptr[0].batch_read_bw_bytes = val
1988 @property
1989 def batch_write_bw_bytes(self):
1990 """int: """
1991 return self._ptr[0].batch_write_bw_bytes
1993 @batch_write_bw_bytes.setter
1994 def batch_write_bw_bytes(self, val):
1995 if self._readonly:
1996 raise ValueError("This StatsLevel1 instance is read-only")
1997 self._ptr[0].batch_write_bw_bytes = val
1999 @property
2000 def batch_submit_lat_avg_us(self):
2001 """int: """
2002 return self._ptr[0].batch_submit_lat_avg_us
2004 @batch_submit_lat_avg_us.setter
2005 def batch_submit_lat_avg_us(self, val):
2006 if self._readonly:
2007 raise ValueError("This StatsLevel1 instance is read-only")
2008 self._ptr[0].batch_submit_lat_avg_us = val
2010 @property
2011 def batch_completion_lat_avg_us(self):
2012 """int: """
2013 return self._ptr[0].batch_completion_lat_avg_us
2015 @batch_completion_lat_avg_us.setter
2016 def batch_completion_lat_avg_us(self, val):
2017 if self._readonly:
2018 raise ValueError("This StatsLevel1 instance is read-only")
2019 self._ptr[0].batch_completion_lat_avg_us = val
2021 @property
2022 def batch_submit_ops_per_sec(self):
2023 """int: """
2024 return self._ptr[0].batch_submit_ops_per_sec
2026 @batch_submit_ops_per_sec.setter
2027 def batch_submit_ops_per_sec(self, val):
2028 if self._readonly:
2029 raise ValueError("This StatsLevel1 instance is read-only")
2030 self._ptr[0].batch_submit_ops_per_sec = val
2032 @property
2033 def batch_complete_ops_per_sec(self):
2034 """int: """
2035 return self._ptr[0].batch_complete_ops_per_sec
2037 @batch_complete_ops_per_sec.setter
2038 def batch_complete_ops_per_sec(self, val):
2039 if self._readonly:
2040 raise ValueError("This StatsLevel1 instance is read-only")
2041 self._ptr[0].batch_complete_ops_per_sec = val
2043 @property
2044 def batch_submit_lat_sum_us(self):
2045 """int: """
2046 return self._ptr[0].batch_submit_lat_sum_us
2048 @batch_submit_lat_sum_us.setter
2049 def batch_submit_lat_sum_us(self, val):
2050 if self._readonly:
2051 raise ValueError("This StatsLevel1 instance is read-only")
2052 self._ptr[0].batch_submit_lat_sum_us = val
2054 @property
2055 def batch_completion_lat_sum_us(self):
2056 """int: """
2057 return self._ptr[0].batch_completion_lat_sum_us
2059 @batch_completion_lat_sum_us.setter
2060 def batch_completion_lat_sum_us(self, val):
2061 if self._readonly:
2062 raise ValueError("This StatsLevel1 instance is read-only")
2063 self._ptr[0].batch_completion_lat_sum_us = val
2065 @property
2066 def last_batch_read_bytes(self):
2067 """int: """
2068 return self._ptr[0].last_batch_read_bytes
2070 @last_batch_read_bytes.setter
2071 def last_batch_read_bytes(self, val):
2072 if self._readonly:
2073 raise ValueError("This StatsLevel1 instance is read-only")
2074 self._ptr[0].last_batch_read_bytes = val
2076 @property
2077 def last_batch_write_bytes(self):
2078 """int: """
2079 return self._ptr[0].last_batch_write_bytes
2081 @last_batch_write_bytes.setter
2082 def last_batch_write_bytes(self, val):
2083 if self._readonly:
2084 raise ValueError("This StatsLevel1 instance is read-only")
2085 self._ptr[0].last_batch_write_bytes = val
2087 @staticmethod
2088 def from_buffer(buffer):
2089 """Create an StatsLevel1 instance with the memory from the given buffer."""
2090 return __from_buffer(buffer, sizeof(CUfileStatsLevel1_t), StatsLevel1)
2092 @staticmethod
2093 def from_data(data):
2094 """Create an StatsLevel1 instance wrapping the given NumPy array.
2096 Args:
2097 data (_numpy.ndarray): a single-element array of dtype `stats_level1_dtype` holding the data.
2098 """
2099 return __from_data(data, "stats_level1_dtype", stats_level1_dtype, StatsLevel1)
2101 @staticmethod
2102 def from_ptr(intptr_t ptr, bint readonly=False, object owner=None):
2103 """Create an StatsLevel1 instance wrapping the given pointer.
2105 Args:
2106 ptr (intptr_t): pointer address as Python :class:`int` to the data.
2107 owner (object): The Python object that owns the pointer. If not provided, data will be copied.
2108 readonly (bool): whether the data is read-only (to the user). default is `False`.
2109 """
2110 if ptr == 0:
2111 raise ValueError("ptr must not be null (0)")
2112 cdef StatsLevel1 obj = StatsLevel1.__new__(StatsLevel1)
2113 if owner is None:
2114 obj._ptr = <CUfileStatsLevel1_t *>malloc(sizeof(CUfileStatsLevel1_t))
2115 if obj._ptr == NULL:
2116 raise MemoryError("Error allocating StatsLevel1")
2117 memcpy(<void*>(obj._ptr), <void*>ptr, sizeof(CUfileStatsLevel1_t))
2118 obj._owner = None
2119 obj._owned = True
2120 else:
2121 obj._ptr = <CUfileStatsLevel1_t *>ptr
2122 obj._owner = owner
2123 obj._owned = False
2124 obj._readonly = readonly
2125 return obj
2128cdef _get_io_params_dtype_offsets():
2129 cdef CUfileIOParams_t pod = CUfileIOParams_t()
2130 return _numpy.dtype({
2131 'names': ['mode', 'u', 'fh', 'opcode', 'cookie'],
2132 'formats': [_numpy.int32, _py_anon_pod2_dtype, _numpy.intp, _numpy.int32, _numpy.intp],
2133 'offsets': [
2134 (<intptr_t>&(pod.mode)) - (<intptr_t>&pod),
2135 (<intptr_t>&(pod.u)) - (<intptr_t>&pod),
2136 (<intptr_t>&(pod.fh)) - (<intptr_t>&pod),
2137 (<intptr_t>&(pod.opcode)) - (<intptr_t>&pod),
2138 (<intptr_t>&(pod.cookie)) - (<intptr_t>&pod),
2139 ],
2140 'itemsize': sizeof(CUfileIOParams_t),
2141 })
2143io_params_dtype = _get_io_params_dtype_offsets()
2145cdef class IOParams:
2146 """Empty-initialize an array of `CUfileIOParams_t`.
2148 The resulting object is of length `size` and of dtype `io_params_dtype`.
2149 If default-constructed, the instance represents a single struct.
2151 Args:
2152 size (int): number of structs, default=1.
2155 .. seealso:: `CUfileIOParams_t`
2156 """
2157 cdef:
2158 readonly object _data
2162 def __init__(self, size=1):
2163 arr = _numpy.empty(size, dtype=io_params_dtype)
2164 self._data = arr.view(_numpy.recarray)
2165 assert self._data.itemsize == sizeof(CUfileIOParams_t), \
2166 f"itemsize {self._data.itemsize} mismatches struct size { sizeof(CUfileIOParams_t) }"
2168 def __repr__(self):
2169 if self._data.size > 1:
2170 return f"<{__name__}.IOParams_Array_{self._data.size} object at {hex(id(self))}>"
2171 else:
2172 return f"<{__name__}.IOParams object at {hex(id(self))}>"
2174 @property
2175 def ptr(self):
2176 """Get the pointer address to the data as Python :class:`int`."""
2177 return self._data.ctypes.data
2179 cdef intptr_t _get_ptr(self):
2180 return self._data.ctypes.data
2182 def __int__(self):
2183 if self._data.size > 1:
2184 raise TypeError("int() argument must be a bytes-like object of size 1. "
2185 "To get the pointer address of an array, use .ptr")
2186 return self._data.ctypes.data
2188 def __len__(self):
2189 return self._data.size
2191 def __eq__(self, other):
2192 cdef object self_data = self._data
2193 if (not isinstance(other, IOParams)) or self_data.size != other._data.size or self_data.dtype != other._data.dtype:
2194 return False
2195 return bool((self_data == other._data).all())
2197 def __getbuffer__(self, Py_buffer *buffer, int flags):
2198 cpython.PyObject_GetBuffer(self._data, buffer, flags)
2200 def __releasebuffer__(self, Py_buffer *buffer):
2201 cpython.PyBuffer_Release(buffer)
2203 @property
2204 def mode(self):
2205 """Union[~_numpy.int32, int]: """
2206 if self._data.size == 1:
2207 return int(self._data.mode[0])
2208 return self._data.mode
2210 @mode.setter
2211 def mode(self, val):
2212 self._data.mode = val
2214 @property
2215 def u(self):
2216 """_py_anon_pod2_dtype: """
2217 return self._data.u
2219 @u.setter
2220 def u(self, val):
2221 self._data.u = val
2223 @property
2224 def fh(self):
2225 """Union[~_numpy.intp, int]: """
2226 if self._data.size == 1:
2227 return int(self._data.fh[0])
2228 return self._data.fh
2230 @fh.setter
2231 def fh(self, val):
2232 self._data.fh = val
2234 @property
2235 def opcode(self):
2236 """Union[~_numpy.int32, int]: """
2237 if self._data.size == 1:
2238 return int(self._data.opcode[0])
2239 return self._data.opcode
2241 @opcode.setter
2242 def opcode(self, val):
2243 self._data.opcode = val
2245 @property
2246 def cookie(self):
2247 """Union[~_numpy.intp, int]: """
2248 if self._data.size == 1:
2249 return int(self._data.cookie[0])
2250 return self._data.cookie
2252 @cookie.setter
2253 def cookie(self, val):
2254 self._data.cookie = val
2256 def __getitem__(self, key):
2257 cdef ssize_t key_
2258 cdef ssize_t size
2259 if isinstance(key, int):
2260 key_ = key
2261 size = self._data.size
2262 if key_ >= size or key_ <= -(size+1):
2263 raise IndexError("index is out of bounds")
2264 if key_ < 0:
2265 key_ += size
2266 return IOParams.from_data(self._data[key_:key_+1])
2267 out = self._data[key]
2268 if isinstance(out, _numpy.recarray) and out.dtype == io_params_dtype:
2269 return IOParams.from_data(out)
2270 return out
2272 def __setitem__(self, key, val):
2273 self._data[key] = val
2275 @staticmethod
2276 def from_buffer(buffer):
2277 """Create an IOParams instance with the memory from the given buffer."""
2278 return IOParams.from_data(_numpy.frombuffer(buffer, dtype=io_params_dtype))
2280 @staticmethod
2281 def from_data(data):
2282 """Create an IOParams instance wrapping the given NumPy array.
2284 Args:
2285 data (_numpy.ndarray): a 1D array of dtype `io_params_dtype` holding the data.
2286 """
2287 cdef IOParams obj = IOParams.__new__(IOParams)
2288 if not isinstance(data, _numpy.ndarray):
2289 raise TypeError("data argument must be a NumPy ndarray")
2290 if data.ndim != 1:
2291 raise ValueError("data array must be 1D")
2292 if data.dtype != io_params_dtype:
2293 raise ValueError("data array must be of dtype io_params_dtype")
2294 obj._data = data.view(_numpy.recarray)
2296 return obj
2298 @staticmethod
2299 def from_ptr(intptr_t ptr, size_t size=1, bint readonly=False):
2300 """Create an IOParams instance wrapping the given pointer.
2302 Args:
2303 ptr (intptr_t): pointer address as Python :class:`int` to the data.
2304 size (int): number of structs, default=1.
2305 readonly (bool): whether the data is read-only (to the user). default is `False`.
2306 """
2307 if ptr == 0:
2308 raise ValueError("ptr must not be null (0)")
2309 cdef IOParams obj = IOParams.__new__(IOParams)
2310 cdef flag = cpython.buffer.PyBUF_READ if readonly else cpython.buffer.PyBUF_WRITE
2311 cdef object buf = cpython.memoryview.PyMemoryView_FromMemory(
2312 <char*>ptr, sizeof(CUfileIOParams_t) * size, flag)
2313 data = _numpy.ndarray(size, buffer=buf, dtype=io_params_dtype)
2314 obj._data = data.view(_numpy.recarray)
2316 return obj
2319cdef _get_stats_level2_dtype_offsets():
2320 cdef CUfileStatsLevel2_t pod = CUfileStatsLevel2_t()
2321 return _numpy.dtype({
2322 'names': ['basic', 'read_size_kb_hist', 'write_size_kb_hist'],
2323 'formats': [stats_level1_dtype, (_numpy.uint64, 32), (_numpy.uint64, 32)],
2324 'offsets': [
2325 (<intptr_t>&(pod.basic)) - (<intptr_t>&pod),
2326 (<intptr_t>&(pod.read_size_kb_hist)) - (<intptr_t>&pod),
2327 (<intptr_t>&(pod.write_size_kb_hist)) - (<intptr_t>&pod),
2328 ],
2329 'itemsize': sizeof(CUfileStatsLevel2_t),
2330 })
2332stats_level2_dtype = _get_stats_level2_dtype_offsets()
2334cdef class StatsLevel2:
2335 """Empty-initialize an instance of `CUfileStatsLevel2_t`.
2338 .. seealso:: `CUfileStatsLevel2_t`
2339 """
2340 cdef:
2341 CUfileStatsLevel2_t *_ptr
2342 object _owner
2343 bint _owned
2344 bint _readonly
2346 def __init__(self):
2347 self._ptr = <CUfileStatsLevel2_t *>calloc(1, sizeof(CUfileStatsLevel2_t))
2348 if self._ptr == NULL:
2349 raise MemoryError("Error allocating StatsLevel2")
2350 self._owner = None
2351 self._owned = True
2352 self._readonly = False
2354 def __dealloc__(self):
2355 cdef CUfileStatsLevel2_t *ptr
2356 if self._owned and self._ptr != NULL:
2357 ptr = self._ptr
2358 self._ptr = NULL
2359 free(ptr)
2361 def __repr__(self):
2362 return f"<{__name__}.StatsLevel2 object at {hex(id(self))}>"
2364 @property
2365 def ptr(self):
2366 """Get the pointer address to the data as Python :class:`int`."""
2367 return <intptr_t>(self._ptr)
2369 cdef intptr_t _get_ptr(self):
2370 return <intptr_t>(self._ptr)
2372 def __int__(self):
2373 return <intptr_t>(self._ptr)
2375 def __eq__(self, other):
2376 cdef StatsLevel2 other_
2377 if not isinstance(other, StatsLevel2):
2378 return False
2379 other_ = other
2380 return (memcmp(<void *><intptr_t>(self._ptr), <void *><intptr_t>(other_._ptr), sizeof(CUfileStatsLevel2_t)) == 0)
2382 def __getbuffer__(self, Py_buffer *buffer, int flags):
2383 __getbuffer(self, buffer, <void *>self._ptr, sizeof(CUfileStatsLevel2_t), self._readonly)
2385 def __releasebuffer__(self, Py_buffer *buffer):
2386 pass
2388 def __setitem__(self, key, val):
2389 if key == 0 and isinstance(val, _numpy.ndarray):
2390 self._ptr = <CUfileStatsLevel2_t *>malloc(sizeof(CUfileStatsLevel2_t))
2391 if self._ptr == NULL:
2392 raise MemoryError("Error allocating StatsLevel2")
2393 memcpy(<void*>self._ptr, <void*><intptr_t>val.ctypes.data, sizeof(CUfileStatsLevel2_t))
2394 self._owner = None
2395 self._owned = True
2396 self._readonly = not val.flags.writeable
2397 else:
2398 setattr(self, key, val)
2400 @property
2401 def basic(self):
2402 """StatsLevel1: """
2403 return StatsLevel1.from_ptr(<intptr_t>&(self._ptr[0].basic), self._readonly, self)
2405 @basic.setter
2406 def basic(self, val):
2407 if self._readonly:
2408 raise ValueError("This StatsLevel2 instance is read-only")
2409 cdef StatsLevel1 val_ = val
2410 memcpy(<void *>&(self._ptr[0].basic), <void *>(val_._get_ptr()), sizeof(CUfileStatsLevel1_t) * 1)
2412 @property
2413 def read_size_kb_hist(self):
2414 """~_numpy.uint64: (array of length 32)."""
2415 cdef view.array arr = view.array(shape=(32,), itemsize=sizeof(uint64_t), format="Q", mode="c", allocate_buffer=False)
2416 arr.data = <char *>(&(self._ptr[0].read_size_kb_hist))
2417 return _numpy.asarray(arr)
2419 @read_size_kb_hist.setter
2420 def read_size_kb_hist(self, val):
2421 if self._readonly:
2422 raise ValueError("This StatsLevel2 instance is read-only")
2423 if len(val) != 32:
2424 raise ValueError(f"Expected length { 32 } for field read_size_kb_hist, got {len(val)}")
2425 cdef view.array arr = view.array(shape=(32,), itemsize=sizeof(uint64_t), format="Q", mode="c")
2426 arr[:] = _numpy.asarray(val, dtype=_numpy.uint64)
2427 memcpy(<void *>(&(self._ptr[0].read_size_kb_hist)), <void *>(arr.data), sizeof(uint64_t) * len(val))
2429 @property
2430 def write_size_kb_hist(self):
2431 """~_numpy.uint64: (array of length 32)."""
2432 cdef view.array arr = view.array(shape=(32,), itemsize=sizeof(uint64_t), format="Q", mode="c", allocate_buffer=False)
2433 arr.data = <char *>(&(self._ptr[0].write_size_kb_hist))
2434 return _numpy.asarray(arr)
2436 @write_size_kb_hist.setter
2437 def write_size_kb_hist(self, val):
2438 if self._readonly:
2439 raise ValueError("This StatsLevel2 instance is read-only")
2440 if len(val) != 32:
2441 raise ValueError(f"Expected length { 32 } for field write_size_kb_hist, got {len(val)}")
2442 cdef view.array arr = view.array(shape=(32,), itemsize=sizeof(uint64_t), format="Q", mode="c")
2443 arr[:] = _numpy.asarray(val, dtype=_numpy.uint64)
2444 memcpy(<void *>(&(self._ptr[0].write_size_kb_hist)), <void *>(arr.data), sizeof(uint64_t) * len(val))
2446 @staticmethod
2447 def from_buffer(buffer):
2448 """Create an StatsLevel2 instance with the memory from the given buffer."""
2449 return __from_buffer(buffer, sizeof(CUfileStatsLevel2_t), StatsLevel2)
2451 @staticmethod
2452 def from_data(data):
2453 """Create an StatsLevel2 instance wrapping the given NumPy array.
2455 Args:
2456 data (_numpy.ndarray): a single-element array of dtype `stats_level2_dtype` holding the data.
2457 """
2458 return __from_data(data, "stats_level2_dtype", stats_level2_dtype, StatsLevel2)
2460 @staticmethod
2461 def from_ptr(intptr_t ptr, bint readonly=False, object owner=None):
2462 """Create an StatsLevel2 instance wrapping the given pointer.
2464 Args:
2465 ptr (intptr_t): pointer address as Python :class:`int` to the data.
2466 owner (object): The Python object that owns the pointer. If not provided, data will be copied.
2467 readonly (bool): whether the data is read-only (to the user). default is `False`.
2468 """
2469 if ptr == 0:
2470 raise ValueError("ptr must not be null (0)")
2471 cdef StatsLevel2 obj = StatsLevel2.__new__(StatsLevel2)
2472 if owner is None:
2473 obj._ptr = <CUfileStatsLevel2_t *>malloc(sizeof(CUfileStatsLevel2_t))
2474 if obj._ptr == NULL:
2475 raise MemoryError("Error allocating StatsLevel2")
2476 memcpy(<void*>(obj._ptr), <void*>ptr, sizeof(CUfileStatsLevel2_t))
2477 obj._owner = None
2478 obj._owned = True
2479 else:
2480 obj._ptr = <CUfileStatsLevel2_t *>ptr
2481 obj._owner = owner
2482 obj._owned = False
2483 obj._readonly = readonly
2484 return obj
2487cdef _get_stats_level3_dtype_offsets():
2488 cdef CUfileStatsLevel3_t pod = CUfileStatsLevel3_t()
2489 return _numpy.dtype({
2490 'names': ['detailed', 'num_gpus', 'per_gpu_stats'],
2491 'formats': [stats_level2_dtype, _numpy.uint32, (per_gpu_stats_dtype, 16)],
2492 'offsets': [
2493 (<intptr_t>&(pod.detailed)) - (<intptr_t>&pod),
2494 (<intptr_t>&(pod.num_gpus)) - (<intptr_t>&pod),
2495 (<intptr_t>&(pod.per_gpu_stats)) - (<intptr_t>&pod),
2496 ],
2497 'itemsize': sizeof(CUfileStatsLevel3_t),
2498 })
2500stats_level3_dtype = _get_stats_level3_dtype_offsets()
2502cdef class StatsLevel3:
2503 """Empty-initialize an instance of `CUfileStatsLevel3_t`.
2506 .. seealso:: `CUfileStatsLevel3_t`
2507 """
2508 cdef:
2509 CUfileStatsLevel3_t *_ptr
2510 object _owner
2511 bint _owned
2512 bint _readonly
2514 def __init__(self):
2515 self._ptr = <CUfileStatsLevel3_t *>calloc(1, sizeof(CUfileStatsLevel3_t))
2516 if self._ptr == NULL:
2517 raise MemoryError("Error allocating StatsLevel3")
2518 self._owner = None
2519 self._owned = True
2520 self._readonly = False
2522 def __dealloc__(self):
2523 cdef CUfileStatsLevel3_t *ptr
2524 if self._owned and self._ptr != NULL:
2525 ptr = self._ptr
2526 self._ptr = NULL
2527 free(ptr)
2529 def __repr__(self):
2530 return f"<{__name__}.StatsLevel3 object at {hex(id(self))}>"
2532 @property
2533 def ptr(self):
2534 """Get the pointer address to the data as Python :class:`int`."""
2535 return <intptr_t>(self._ptr)
2537 cdef intptr_t _get_ptr(self):
2538 return <intptr_t>(self._ptr)
2540 def __int__(self):
2541 return <intptr_t>(self._ptr)
2543 def __eq__(self, other):
2544 cdef StatsLevel3 other_
2545 if not isinstance(other, StatsLevel3):
2546 return False
2547 other_ = other
2548 return (memcmp(<void *><intptr_t>(self._ptr), <void *><intptr_t>(other_._ptr), sizeof(CUfileStatsLevel3_t)) == 0)
2550 def __getbuffer__(self, Py_buffer *buffer, int flags):
2551 __getbuffer(self, buffer, <void *>self._ptr, sizeof(CUfileStatsLevel3_t), self._readonly)
2553 def __releasebuffer__(self, Py_buffer *buffer):
2554 pass
2556 def __setitem__(self, key, val):
2557 if key == 0 and isinstance(val, _numpy.ndarray):
2558 self._ptr = <CUfileStatsLevel3_t *>malloc(sizeof(CUfileStatsLevel3_t))
2559 if self._ptr == NULL:
2560 raise MemoryError("Error allocating StatsLevel3")
2561 memcpy(<void*>self._ptr, <void*><intptr_t>val.ctypes.data, sizeof(CUfileStatsLevel3_t))
2562 self._owner = None
2563 self._owned = True
2564 self._readonly = not val.flags.writeable
2565 else:
2566 setattr(self, key, val)
2568 @property
2569 def detailed(self):
2570 """StatsLevel2: """
2571 return StatsLevel2.from_ptr(<intptr_t>&(self._ptr[0].detailed), self._readonly, self)
2573 @detailed.setter
2574 def detailed(self, val):
2575 if self._readonly:
2576 raise ValueError("This StatsLevel3 instance is read-only")
2577 cdef StatsLevel2 val_ = val
2578 memcpy(<void *>&(self._ptr[0].detailed), <void *>(val_._get_ptr()), sizeof(CUfileStatsLevel2_t) * 1)
2580 @property
2581 def per_gpu_stats(self):
2582 """PerGpuStats: """
2583 return PerGpuStats.from_ptr(<intptr_t>&(self._ptr[0].per_gpu_stats), 16, self._readonly)
2585 @per_gpu_stats.setter
2586 def per_gpu_stats(self, val):
2587 if self._readonly:
2588 raise ValueError("This StatsLevel3 instance is read-only")
2589 cdef PerGpuStats val_ = val
2590 if len(val) != 16:
2591 raise ValueError(f"Expected length { 16 } for field per_gpu_stats, got {len(val)}")
2592 memcpy(<void *>&(self._ptr[0].per_gpu_stats), <void *>(val_._get_ptr()), sizeof(CUfilePerGpuStats_t) * 16)
2594 @property
2595 def num_gpus(self):
2596 """int: """
2597 return self._ptr[0].num_gpus
2599 @num_gpus.setter
2600 def num_gpus(self, val):
2601 if self._readonly:
2602 raise ValueError("This StatsLevel3 instance is read-only")
2603 self._ptr[0].num_gpus = val
2605 @staticmethod
2606 def from_buffer(buffer):
2607 """Create an StatsLevel3 instance with the memory from the given buffer."""
2608 return __from_buffer(buffer, sizeof(CUfileStatsLevel3_t), StatsLevel3)
2610 @staticmethod
2611 def from_data(data):
2612 """Create an StatsLevel3 instance wrapping the given NumPy array.
2614 Args:
2615 data (_numpy.ndarray): a single-element array of dtype `stats_level3_dtype` holding the data.
2616 """
2617 return __from_data(data, "stats_level3_dtype", stats_level3_dtype, StatsLevel3)
2619 @staticmethod
2620 def from_ptr(intptr_t ptr, bint readonly=False, object owner=None):
2621 """Create an StatsLevel3 instance wrapping the given pointer.
2623 Args:
2624 ptr (intptr_t): pointer address as Python :class:`int` to the data.
2625 owner (object): The Python object that owns the pointer. If not provided, data will be copied.
2626 readonly (bool): whether the data is read-only (to the user). default is `False`.
2627 """
2628 if ptr == 0:
2629 raise ValueError("ptr must not be null (0)")
2630 cdef StatsLevel3 obj = StatsLevel3.__new__(StatsLevel3)
2631 if owner is None:
2632 obj._ptr = <CUfileStatsLevel3_t *>malloc(sizeof(CUfileStatsLevel3_t))
2633 if obj._ptr == NULL:
2634 raise MemoryError("Error allocating StatsLevel3")
2635 memcpy(<void*>(obj._ptr), <void*>ptr, sizeof(CUfileStatsLevel3_t))
2636 obj._owner = None
2637 obj._owned = True
2638 else:
2639 obj._ptr = <CUfileStatsLevel3_t *>ptr
2640 obj._owner = owner
2641 obj._owned = False
2642 obj._readonly = readonly
2643 return obj
2647###############################################################################
2648# Enum
2649###############################################################################
2651class OpError(_FastEnum):
2652 """
2653 See `CUfileOpError`.
2654 """
2655 SUCCESS = CU_FILE_SUCCESS
2656 DRIVER_NOT_INITIALIZED = CU_FILE_DRIVER_NOT_INITIALIZED
2657 DRIVER_INVALID_PROPS = CU_FILE_DRIVER_INVALID_PROPS
2658 DRIVER_UNSUPPORTED_LIMIT = CU_FILE_DRIVER_UNSUPPORTED_LIMIT
2659 DRIVER_VERSION_MISMATCH = CU_FILE_DRIVER_VERSION_MISMATCH
2660 DRIVER_VERSION_READ_ERROR = CU_FILE_DRIVER_VERSION_READ_ERROR
2661 DRIVER_CLOSING = CU_FILE_DRIVER_CLOSING
2662 PLATFORM_NOT_SUPPORTED = CU_FILE_PLATFORM_NOT_SUPPORTED
2663 IO_NOT_SUPPORTED = CU_FILE_IO_NOT_SUPPORTED
2664 DEVICE_NOT_SUPPORTED = CU_FILE_DEVICE_NOT_SUPPORTED
2665 NVFS_DRIVER_ERROR = CU_FILE_NVFS_DRIVER_ERROR
2666 CUDA_DRIVER_ERROR = CU_FILE_CUDA_DRIVER_ERROR
2667 CUDA_POINTER_INVALID = CU_FILE_CUDA_POINTER_INVALID
2668 CUDA_MEMORY_TYPE_INVALID = CU_FILE_CUDA_MEMORY_TYPE_INVALID
2669 CUDA_POINTER_RANGE_ERROR = CU_FILE_CUDA_POINTER_RANGE_ERROR
2670 CUDA_CONTEXT_MISMATCH = CU_FILE_CUDA_CONTEXT_MISMATCH
2671 INVALID_MAPPING_SIZE = CU_FILE_INVALID_MAPPING_SIZE
2672 INVALID_MAPPING_RANGE = CU_FILE_INVALID_MAPPING_RANGE
2673 INVALID_FILE_TYPE = CU_FILE_INVALID_FILE_TYPE
2674 INVALID_FILE_OPEN_FLAG = CU_FILE_INVALID_FILE_OPEN_FLAG
2675 DIO_NOT_SET = CU_FILE_DIO_NOT_SET
2676 INVALID_VALUE = CU_FILE_INVALID_VALUE
2677 MEMORY_ALREADY_REGISTERED = CU_FILE_MEMORY_ALREADY_REGISTERED
2678 MEMORY_NOT_REGISTERED = CU_FILE_MEMORY_NOT_REGISTERED
2679 PERMISSION_DENIED = CU_FILE_PERMISSION_DENIED
2680 DRIVER_ALREADY_OPEN = CU_FILE_DRIVER_ALREADY_OPEN
2681 HANDLE_NOT_REGISTERED = CU_FILE_HANDLE_NOT_REGISTERED
2682 HANDLE_ALREADY_REGISTERED = CU_FILE_HANDLE_ALREADY_REGISTERED
2683 DEVICE_NOT_FOUND = CU_FILE_DEVICE_NOT_FOUND
2684 INTERNAL_ERROR = CU_FILE_INTERNAL_ERROR
2685 GETNEWFD_FAILED = CU_FILE_GETNEWFD_FAILED
2686 NVFS_SETUP_ERROR = CU_FILE_NVFS_SETUP_ERROR
2687 IO_DISABLED = CU_FILE_IO_DISABLED
2688 BATCH_SUBMIT_FAILED = CU_FILE_BATCH_SUBMIT_FAILED
2689 GPU_MEMORY_PINNING_FAILED = CU_FILE_GPU_MEMORY_PINNING_FAILED
2690 BATCH_FULL = CU_FILE_BATCH_FULL
2691 ASYNC_NOT_SUPPORTED = CU_FILE_ASYNC_NOT_SUPPORTED
2692 INTERNAL_BATCH_SETUP_ERROR = CU_FILE_INTERNAL_BATCH_SETUP_ERROR
2693 INTERNAL_BATCH_SUBMIT_ERROR = CU_FILE_INTERNAL_BATCH_SUBMIT_ERROR
2694 INTERNAL_BATCH_GETSTATUS_ERROR = CU_FILE_INTERNAL_BATCH_GETSTATUS_ERROR
2695 INTERNAL_BATCH_CANCEL_ERROR = CU_FILE_INTERNAL_BATCH_CANCEL_ERROR
2696 NOMEM_ERROR = CU_FILE_NOMEM_ERROR
2697 IO_ERROR = CU_FILE_IO_ERROR
2698 INTERNAL_BUF_REGISTER_ERROR = CU_FILE_INTERNAL_BUF_REGISTER_ERROR
2699 HASH_OPR_ERROR = CU_FILE_HASH_OPR_ERROR
2700 INVALID_CONTEXT_ERROR = CU_FILE_INVALID_CONTEXT_ERROR
2701 NVFS_INTERNAL_DRIVER_ERROR = CU_FILE_NVFS_INTERNAL_DRIVER_ERROR
2702 BATCH_NOCOMPAT_ERROR = CU_FILE_BATCH_NOCOMPAT_ERROR
2703 IO_MAX_ERROR = CU_FILE_IO_MAX_ERROR
2705class DriverStatusFlags(_FastEnum):
2706 """
2707 See `CUfileDriverStatusFlags_t`.
2708 """
2709 LUSTRE_SUPPORTED = (CU_FILE_LUSTRE_SUPPORTED, 'Support for DDN LUSTRE')
2710 WEKAFS_SUPPORTED = (CU_FILE_WEKAFS_SUPPORTED, 'Support for WEKAFS')
2711 NFS_SUPPORTED = (CU_FILE_NFS_SUPPORTED, 'Support for NFS')
2712 GPFS_SUPPORTED = CU_FILE_GPFS_SUPPORTED
2713 NVME_SUPPORTED = (CU_FILE_NVME_SUPPORTED, '< Support for GPFS Support for NVMe')
2714 NVMEOF_SUPPORTED = (CU_FILE_NVMEOF_SUPPORTED, 'Support for NVMeOF')
2715 SCSI_SUPPORTED = (CU_FILE_SCSI_SUPPORTED, 'Support for SCSI')
2716 SCALEFLUX_CSD_SUPPORTED = (CU_FILE_SCALEFLUX_CSD_SUPPORTED, 'Support for Scaleflux CSD')
2717 NVMESH_SUPPORTED = (CU_FILE_NVMESH_SUPPORTED, 'Support for NVMesh Block Dev')
2718 BEEGFS_SUPPORTED = (CU_FILE_BEEGFS_SUPPORTED, 'Support for BeeGFS')
2719 NVME_P2P_SUPPORTED = (CU_FILE_NVME_P2P_SUPPORTED, 'Do not use this macro. This is deprecated now')
2720 SCATEFS_SUPPORTED = (CU_FILE_SCATEFS_SUPPORTED, 'Support for ScateFS')
2721 VIRTIOFS_SUPPORTED = (CU_FILE_VIRTIOFS_SUPPORTED, 'Support for VirtioFS')
2722 MAX_TARGET_TYPES = (CU_FILE_MAX_TARGET_TYPES, 'Maximum FS supported')
2724class DriverControlFlags(_FastEnum):
2725 """
2726 See `CUfileDriverControlFlags_t`.
2727 """
2728 USE_POLL_MODE = (CU_FILE_USE_POLL_MODE, 'use POLL mode. properties.use_poll_mode')
2729 ALLOW_COMPAT_MODE = (CU_FILE_ALLOW_COMPAT_MODE, 'allow COMPATIBILITY mode. properties.allow_compat_mode')
2731class FeatureFlags(_FastEnum):
2732 """
2733 See `CUfileFeatureFlags_t`.
2734 """
2735 DYN_ROUTING_SUPPORTED = (CU_FILE_DYN_ROUTING_SUPPORTED, 'Support for Dynamic routing to handle devices across the PCIe bridges')
2736 BATCH_IO_SUPPORTED = (CU_FILE_BATCH_IO_SUPPORTED, 'Supported')
2737 STREAMS_SUPPORTED = (CU_FILE_STREAMS_SUPPORTED, 'Supported')
2738 PARALLEL_IO_SUPPORTED = (CU_FILE_PARALLEL_IO_SUPPORTED, 'Supported')
2739 P2P_SUPPORTED = (CU_FILE_P2P_SUPPORTED, 'Support for PCI P2PDMA')
2741class FileHandleType(_FastEnum):
2742 """
2743 See `CUfileFileHandleType`.
2744 """
2745 OPAQUE_FD = (CU_FILE_HANDLE_TYPE_OPAQUE_FD, 'Linux based fd')
2746 OPAQUE_WIN32 = (CU_FILE_HANDLE_TYPE_OPAQUE_WIN32, 'Windows based handle (unsupported)')
2747 USERSPACE_FS = CU_FILE_HANDLE_TYPE_USERSPACE_FS
2749class Opcode(_FastEnum):
2750 """
2751 See `CUfileOpcode_t`.
2752 """
2753 READ = CUFILE_READ
2754 WRITE = CUFILE_WRITE
2756class Status(_FastEnum):
2757 """
2758 See `CUfileStatus_t`.
2759 """
2760 WAITING = CUFILE_WAITING
2761 PENDING = CUFILE_PENDING
2762 INVALID = CUFILE_INVALID
2763 CANCELED = CUFILE_CANCELED
2764 COMPLETE = CUFILE_COMPLETE
2765 TIMEOUT = CUFILE_TIMEOUT
2766 FAILED = CUFILE_FAILED
2768class BatchMode(_FastEnum):
2769 """
2770 See `CUfileBatchMode_t`.
2771 """
2772 BATCH = CUFILE_BATCH
2774class SizeTConfigParameter(_FastEnum):
2775 """
2776 See `CUFileSizeTConfigParameter_t`.
2777 """
2778 PROFILE_STATS = CUFILE_PARAM_PROFILE_STATS
2779 EXECUTION_MAX_IO_QUEUE_DEPTH = CUFILE_PARAM_EXECUTION_MAX_IO_QUEUE_DEPTH
2780 EXECUTION_MAX_IO_THREADS = CUFILE_PARAM_EXECUTION_MAX_IO_THREADS
2781 EXECUTION_MIN_IO_THRESHOLD_SIZE_KB = CUFILE_PARAM_EXECUTION_MIN_IO_THRESHOLD_SIZE_KB
2782 EXECUTION_MAX_REQUEST_PARALLELISM = CUFILE_PARAM_EXECUTION_MAX_REQUEST_PARALLELISM
2783 PROPERTIES_MAX_DIRECT_IO_SIZE_KB = CUFILE_PARAM_PROPERTIES_MAX_DIRECT_IO_SIZE_KB
2784 PROPERTIES_MAX_DEVICE_CACHE_SIZE_KB = CUFILE_PARAM_PROPERTIES_MAX_DEVICE_CACHE_SIZE_KB
2785 PROPERTIES_PER_BUFFER_CACHE_SIZE_KB = CUFILE_PARAM_PROPERTIES_PER_BUFFER_CACHE_SIZE_KB
2786 PROPERTIES_MAX_DEVICE_PINNED_MEM_SIZE_KB = CUFILE_PARAM_PROPERTIES_MAX_DEVICE_PINNED_MEM_SIZE_KB
2787 PROPERTIES_IO_BATCHSIZE = CUFILE_PARAM_PROPERTIES_IO_BATCHSIZE
2788 POLLTHRESHOLD_SIZE_KB = CUFILE_PARAM_POLLTHRESHOLD_SIZE_KB
2789 PROPERTIES_BATCH_IO_TIMEOUT_MS = CUFILE_PARAM_PROPERTIES_BATCH_IO_TIMEOUT_MS
2791class BoolConfigParameter(_FastEnum):
2792 """
2793 See `CUFileBoolConfigParameter_t`.
2794 """
2795 PROPERTIES_USE_POLL_MODE = CUFILE_PARAM_PROPERTIES_USE_POLL_MODE
2796 PROPERTIES_ALLOW_COMPAT_MODE = CUFILE_PARAM_PROPERTIES_ALLOW_COMPAT_MODE
2797 FORCE_COMPAT_MODE = CUFILE_PARAM_FORCE_COMPAT_MODE
2798 FS_MISC_API_CHECK_AGGRESSIVE = CUFILE_PARAM_FS_MISC_API_CHECK_AGGRESSIVE
2799 EXECUTION_PARALLEL_IO = CUFILE_PARAM_EXECUTION_PARALLEL_IO
2800 PROFILE_NVTX = CUFILE_PARAM_PROFILE_NVTX
2801 PROPERTIES_ALLOW_SYSTEM_MEMORY = CUFILE_PARAM_PROPERTIES_ALLOW_SYSTEM_MEMORY
2802 USE_PCIP2PDMA = CUFILE_PARAM_USE_PCIP2PDMA
2803 PREFER_IO_URING = CUFILE_PARAM_PREFER_IO_URING
2804 FORCE_ODIRECT_MODE = CUFILE_PARAM_FORCE_ODIRECT_MODE
2805 SKIP_TOPOLOGY_DETECTION = CUFILE_PARAM_SKIP_TOPOLOGY_DETECTION
2806 STREAM_MEMOPS_BYPASS = CUFILE_PARAM_STREAM_MEMOPS_BYPASS
2808class StringConfigParameter(_FastEnum):
2809 """
2810 See `CUFileStringConfigParameter_t`.
2811 """
2812 LOGGING_LEVEL = CUFILE_PARAM_LOGGING_LEVEL
2813 ENV_LOGFILE_PATH = CUFILE_PARAM_ENV_LOGFILE_PATH
2814 LOG_DIR = CUFILE_PARAM_LOG_DIR
2816class ArrayConfigParameter(_FastEnum):
2817 """
2818 See `CUFileArrayConfigParameter_t`.
2819 """
2820 POSIX_POOL_SLAB_SIZE_KB = CUFILE_PARAM_POSIX_POOL_SLAB_SIZE_KB
2821 POSIX_POOL_SLAB_COUNT = CUFILE_PARAM_POSIX_POOL_SLAB_COUNT
2823class P2PFlags(_FastEnum):
2824 """
2825 See `CUfileP2PFlags_t`.
2826 """
2827 P2PDMA = (CUFILE_P2PDMA, 'Support for PCI P2PDMA')
2828 NVFS = (CUFILE_NVFS, 'Support for nvidia-fs')
2829 DMABUF = (CUFILE_DMABUF, 'Support for DMA Buffer')
2830 C2C = (CUFILE_C2C, 'Support for Chip-to-Chip (Grace-based systems)')
2831 NVIDIA_PEERMEM = (CUFILE_NVIDIA_PEERMEM, 'Only for IBM Spectrum Scale and WekaFS')
2834###############################################################################
2835# Error handling
2836###############################################################################
2838ctypedef fused ReturnT:
2839 CUfileError_t
2840 ssize_t
2843class cuFileError(Exception):
2845 def __init__(self, status, cu_err=None):
2846 self.status = status 1efgrklhijmbcdnopq
2847 self.cuda_error = cu_err 1efgrklhijmbcdnopq
2848 s = OpError(status) 1efgrklhijmbcdnopq
2849 cdef str err = f"{s.name} ({s.value}): {op_status_error(status)}" 1efgrklhijmbcdnopq
2850 if cu_err is not None: 1efgrklhijmbcdnopq
2851 e = pyCUresult(cu_err) 1efgrklhijmbcdnopq
2852 err += f"; CUDA status: {e.name} ({e.value})" 1efgrklhijmbcdnopq
2853 super(cuFileError, self).__init__(err) 1efgrklhijmbcdnopq
2855 def __reduce__(self):
2856 return (type(self), (self.status, self.cuda_error))
2859@cython.profile(False)
2860cdef int check_status(ReturnT status) except 1 nogil:
2861 if ReturnT is CUfileError_t:
2862 if status.err != 0 or status.cu_err != 0: 1aeMNfOPgQRrSTFUVGWXHYZI01J23k45l67h89i!#j$%m'(K)*L+,bzscAtdBun-.oCpv/qDwxEy
2863 with gil: 1efgrklhijmbcdnopq
2864 raise cuFileError(status.err, status.cu_err) 1efgrklhijmbcdnopq
2865 elif ReturnT is ssize_t:
2866 if status == -1:
2867 # note: this assumes cuFile already properly resets errno in each API
2868 with gil:
2869 raise cuFileError(errno.errno)
2870 return 0 1aeMNfOPgQRrSTFUVGWXHYZI01J234567h89i!#j$%'(K)*L+,bzscAtdBu-.oCpv/qDwxEy
2873###############################################################################
2874# Wrapper functions
2875###############################################################################
2877cpdef intptr_t handle_register(intptr_t descr) except? 0:
2878 """cuFileHandleRegister is required, and performs extra checking that is memoized to provide increased performance on later cuFile operations.
2880 Args:
2881 descr (intptr_t): ``CUfileDescr_t`` file descriptor (OS agnostic).
2883 Returns:
2884 intptr_t: ``CUfileHandle_t`` opaque file handle for IO operations.
2886 .. seealso:: `cuFileHandleRegister`
2887 """
2888 cdef Handle fh
2889 with nogil: 1efgklhijmbcdn
2890 __status__ = cuFileHandleRegister(&fh, <CUfileDescr_t*>descr) 1efgklhijmbcdn
2891 check_status(__status__) 1efgklhijmbcdn
2892 return <intptr_t>fh
2895cpdef void handle_deregister(intptr_t fh) except*:
2896 """releases a registered filehandle from cuFile.
2898 Args:
2899 fh (intptr_t): ``CUfileHandle_t`` file handle.
2901 .. seealso:: `cuFileHandleDeregister`
2902 """
2903 cuFileHandleDeregister(<Handle>fh)
2906cpdef buf_register(intptr_t buf_ptr_base, size_t length, int flags):
2907 """register an existing cudaMalloced memory with cuFile to pin for GPUDirect Storage access or register host allocated memory with cuFile.
2909 Args:
2910 buf_ptr_base (intptr_t): buffer pointer allocated.
2911 length (size_t): size of memory region from the above specified bufPtr.
2912 flags (int): CU_FILE_RDMA_REGISTER.
2914 .. seealso:: `cuFileBufRegister`
2915 """
2916 with nogil: 1efgrFGHIJhij
2917 __status__ = cuFileBufRegister(<const void*>buf_ptr_base, length, flags) 1efgrFGHIJhij
2918 check_status(__status__) 1efgrFGHIJhij
2921cpdef buf_deregister(intptr_t buf_ptr_base):
2922 """deregister an already registered device or host memory from cuFile.
2924 Args:
2925 buf_ptr_base (intptr_t): buffer pointer to deregister.
2927 .. seealso:: `cuFileBufDeregister`
2928 """
2929 with nogil: 1rFGHIJ
2930 __status__ = cuFileBufDeregister(<const void*>buf_ptr_base) 1rFGHIJ
2931 check_status(__status__) 1rFGHIJ
2934cpdef driver_open():
2935 """Initialize the cuFile library and open the nvidia-fs driver.
2937 .. seealso:: `cuFileDriverOpen`
2938 """
2939 with nogil: 1MOQSUWY02468!$')+zAB-vDE
2940 __status__ = cuFileDriverOpen() 1MOQSUWY02468!$')+zAB-vDE
2941 check_status(__status__) 1MOQSUWY02468!$')+zAB-vDE
2944cpdef use_count():
2945 """returns use count of cufile drivers at that moment by the process.
2947 .. seealso:: `cuFileUseCount`
2948 """
2949 with nogil:
2950 __status__ = cuFileUseCount()
2951 check_status(__status__)
2954cpdef driver_get_properties(intptr_t props):
2955 """Gets the Driver session properties.
2957 Args:
2958 props (intptr_t): Properties to set.
2960 .. seealso:: `cuFileDriverGetProperties`
2961 """
2962 with nogil:
2963 __status__ = cuFileDriverGetProperties(<CUfileDrvProps_t*>props)
2964 check_status(__status__)
2967cpdef driver_set_poll_mode(bint poll, size_t poll_threshold_size):
2968 """Sets whether the Read/Write APIs use polling to do IO operations.
2970 Args:
2971 poll (bint): boolean to indicate whether to use poll mode or not.
2972 poll_threshold_size (size_t): max IO size to use for POLLING mode in KB.
2974 .. seealso:: `cuFileDriverSetPollMode`
2975 """
2976 with nogil:
2977 __status__ = cuFileDriverSetPollMode(<cpp_bool>poll, poll_threshold_size)
2978 check_status(__status__)
2981cpdef driver_set_max_direct_io_size(size_t max_direct_io_size):
2982 """Control parameter to set max IO size(KB) used by the library to talk to nvidia-fs driver.
2984 Args:
2985 max_direct_io_size (size_t): maximum allowed direct io size in KB.
2987 .. seealso:: `cuFileDriverSetMaxDirectIOSize`
2988 """
2989 with nogil:
2990 __status__ = cuFileDriverSetMaxDirectIOSize(max_direct_io_size)
2991 check_status(__status__)
2994cpdef driver_set_max_cache_size(size_t max_cache_size):
2995 """Control parameter to set maximum GPU memory reserved per device by the library for internal buffering.
2997 Args:
2998 max_cache_size (size_t): The maximum GPU buffer space per device used for internal use in KB.
3000 .. seealso:: `cuFileDriverSetMaxCacheSize`
3001 """
3002 with nogil:
3003 __status__ = cuFileDriverSetMaxCacheSize(max_cache_size)
3004 check_status(__status__)
3007cpdef driver_set_max_pinned_mem_size(size_t max_pinned_size):
3008 """Sets maximum buffer space that is pinned in KB for use by ``cuFileBufRegister``.
3010 Args:
3011 max_pinned_size (size_t): maximum buffer space that is pinned in KB.
3013 .. seealso:: `cuFileDriverSetMaxPinnedMemSize`
3014 """
3015 with nogil:
3016 __status__ = cuFileDriverSetMaxPinnedMemSize(max_pinned_size)
3017 check_status(__status__)
3020cpdef intptr_t batch_io_set_up(unsigned nr) except? 0:
3021 cdef BatchHandle batch_idp
3022 with nogil:
3023 __status__ = cuFileBatchIOSetUp(&batch_idp, nr)
3024 check_status(__status__)
3025 return <intptr_t>batch_idp
3028cpdef batch_io_submit(intptr_t batch_idp, unsigned nr, intptr_t iocbp, unsigned int flags):
3029 with nogil:
3030 __status__ = cuFileBatchIOSubmit(<BatchHandle>batch_idp, nr, <CUfileIOParams_t*>iocbp, flags)
3031 check_status(__status__)
3034cpdef batch_io_get_status(intptr_t batch_idp, unsigned min_nr, intptr_t nr, intptr_t iocbp, intptr_t timeout):
3035 with nogil:
3036 __status__ = cuFileBatchIOGetStatus(<BatchHandle>batch_idp, min_nr, <unsigned*>nr, <CUfileIOEvents_t*>iocbp, <timespec*>timeout)
3037 check_status(__status__)
3040cpdef batch_io_cancel(intptr_t batch_idp):
3041 with nogil:
3042 __status__ = cuFileBatchIOCancel(<BatchHandle>batch_idp)
3043 check_status(__status__)
3046cpdef void batch_io_destroy(intptr_t batch_idp) except*:
3047 cuFileBatchIODestroy(<BatchHandle>batch_idp)
3050cpdef 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):
3051 with nogil:
3052 __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)
3053 check_status(__status__)
3056cpdef 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):
3057 with nogil:
3058 __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)
3059 check_status(__status__)
3062cpdef stream_register(intptr_t stream, unsigned flags):
3063 with nogil:
3064 __status__ = cuFileStreamRegister(<CUstream>stream, flags)
3065 check_status(__status__)
3068cpdef stream_deregister(intptr_t stream):
3069 with nogil:
3070 __status__ = cuFileStreamDeregister(<CUstream>stream)
3071 check_status(__status__)
3074cpdef int get_version() except? 0:
3075 """Get the cuFile library version.
3077 Returns:
3078 int: Pointer to an integer where the version will be stored.
3080 .. seealso:: `cuFileGetVersion`
3081 """
3082 cdef int version
3083 with nogil: 1ao
3084 __status__ = cuFileGetVersion(&version) 1ao
3085 check_status(__status__) 1ao
3086 return version 1ao
3089cpdef size_t get_parameter_size_t(int param) except? 0:
3090 cdef size_t value
3091 with nogil: 1C
3092 __status__ = cuFileGetParameterSizeT(<_SizeTConfigParameter>param, &value) 1C
3093 check_status(__status__) 1C
3094 return value 1C
3097cpdef bint get_parameter_bool(int param) except? 0:
3098 cdef cpp_bool value
3099 with nogil: 1o
3100 __status__ = cuFileGetParameterBool(<_BoolConfigParameter>param, &value) 1o
3101 check_status(__status__) 1o
3102 return <bint>value 1o
3105cpdef str get_parameter_string(int param, int len):
3106 cdef bytes _desc_str_ = bytes(len) 1p
3107 cdef char* desc_str = _desc_str_ 1p
3108 with nogil: 1p
3109 __status__ = cuFileGetParameterString(<_StringConfigParameter>param, desc_str, len) 1p
3110 check_status(__status__) 1p
3111 return cpython.PyUnicode_FromString(desc_str) 1p
3114cpdef set_parameter_size_t(int param, size_t value):
3115 with nogil: 1C
3116 __status__ = cuFileSetParameterSizeT(<_SizeTConfigParameter>param, value) 1C
3117 check_status(__status__) 1C
3120cpdef set_parameter_bool(int param, bint value):
3121 with nogil: 1o
3122 __status__ = cuFileSetParameterBool(<_BoolConfigParameter>param, <cpp_bool>value) 1o
3123 check_status(__status__) 1o
3126cpdef set_parameter_string(int param, intptr_t desc_str):
3127 with nogil: 1p
3128 __status__ = cuFileSetParameterString(<_StringConfigParameter>param, <const char*>desc_str) 1p
3129 check_status(__status__) 1p
3132cpdef tuple get_parameter_min_max_value(int param):
3133 """Get both the minimum and maximum settable values for a given size_t parameter in a single call.
3135 Args:
3136 param (SizeTConfigParameter): CUfile SizeT configuration parameter.
3138 Returns:
3139 A 2-tuple containing:
3141 - size_t: Pointer to store the minimum value.
3142 - size_t: Pointer to store the maximum value.
3144 .. seealso:: `cuFileGetParameterMinMaxValue`
3145 """
3146 cdef size_t min_value
3147 cdef size_t max_value
3148 with nogil: 1L
3149 __status__ = cuFileGetParameterMinMaxValue(<_SizeTConfigParameter>param, &min_value, &max_value) 1L
3150 check_status(__status__) 1L
3151 return (min_value, max_value) 1L
3154cpdef set_stats_level(int level):
3155 """Set the level of statistics collection for cuFile operations. This will override the cufile.json settings for stats.
3157 Args:
3158 level (int): Statistics level (0 = disabled, 1 = basic, 2 = detailed, 3 = verbose).
3160 .. seealso:: `cuFileSetStatsLevel`
3161 """
3162 with nogil: 1bsctduqwxy
3163 __status__ = cuFileSetStatsLevel(level) 1bsctduqwxy
3164 check_status(__status__) 1bsctduqwxy
3167cpdef int get_stats_level() except? 0:
3168 """Get the current level of statistics collection for cuFile operations.
3170 Returns:
3171 int: Pointer to store the current statistics level.
3173 .. seealso:: `cuFileGetStatsLevel`
3174 """
3175 cdef int level
3176 with nogil: 1zABqDE
3177 __status__ = cuFileGetStatsLevel(&level) 1zABqDE
3178 check_status(__status__) 1zABqDE
3179 return level 1zABqDE
3182cpdef stats_start():
3183 """Start collecting cuFile statistics.
3185 .. seealso:: `cuFileStatsStart`
3186 """
3187 with nogil: 1bcdx
3188 __status__ = cuFileStatsStart() 1bcdx
3189 check_status(__status__) 1bcdx
3192cpdef stats_stop():
3193 """Stop collecting cuFile statistics.
3195 .. seealso:: `cuFileStatsStop`
3196 """
3197 with nogil: 1x
3198 __status__ = cuFileStatsStop() 1x
3199 check_status(__status__) 1x
3202cpdef stats_reset():
3203 """Reset all cuFile statistics counters.
3205 .. seealso:: `cuFileStatsReset`
3206 """
3207 with nogil: 1stuwy
3208 __status__ = cuFileStatsReset() 1stuwy
3209 check_status(__status__) 1stuwy
3212cpdef get_stats_l1(intptr_t stats):
3213 """Get Level 1 cuFile statistics.
3215 Args:
3216 stats (intptr_t): Pointer to CUfileStatsLevel1_t structure to be filled.
3218 .. seealso:: `cuFileGetStatsL1`
3219 """
3220 with nogil:
3221 __status__ = cuFileGetStatsL1(<CUfileStatsLevel1_t*>stats)
3222 check_status(__status__)
3225cpdef get_stats_l2(intptr_t stats):
3226 """Get Level 2 cuFile statistics.
3228 Args:
3229 stats (intptr_t): Pointer to CUfileStatsLevel2_t structure to be filled.
3231 .. seealso:: `cuFileGetStatsL2`
3232 """
3233 with nogil:
3234 __status__ = cuFileGetStatsL2(<CUfileStatsLevel2_t*>stats)
3235 check_status(__status__)
3238cpdef get_stats_l3(intptr_t stats):
3239 """Get Level 3 cuFile statistics.
3241 Args:
3242 stats (intptr_t): Pointer to CUfileStatsLevel3_t structure to be filled.
3244 .. seealso:: `cuFileGetStatsL3`
3245 """
3246 with nogil:
3247 __status__ = cuFileGetStatsL3(<CUfileStatsLevel3_t*>stats)
3248 check_status(__status__)
3251cpdef size_t get_bar_size_in_kb(int gpu_ind_ex) except? 0:
3252 cdef size_t bar_size
3253 with nogil: 1K
3254 __status__ = cuFileGetBARSizeInKB(gpu_ind_ex, &bar_size) 1K
3255 check_status(__status__) 1K
3256 return bar_size 1K
3259cpdef set_parameter_posix_pool_slab_array(intptr_t size_values, intptr_t count_values, int len):
3260 """Set both POSIX pool slab size and count parameters as a pair.
3262 Args:
3263 size_values (intptr_t): Array of slab sizes in KB.
3264 count_values (intptr_t): Array of slab counts.
3265 len (int): Length of both arrays (must be the same).
3267 .. seealso:: `cuFileSetParameterPosixPoolSlabArray`
3268 """
3269 with nogil: 1/
3270 __status__ = cuFileSetParameterPosixPoolSlabArray(<const size_t*>size_values, <const size_t*>count_values, len) 1/
3271 check_status(__status__) 1/
3274cpdef get_parameter_posix_pool_slab_array(intptr_t size_values, intptr_t count_values, int len):
3275 """Get both POSIX pool slab size and count parameters as a pair.
3277 Args:
3278 size_values (intptr_t): Buffer to receive slab sizes in KB.
3279 count_values (intptr_t): Buffer to receive slab counts.
3280 len (int): Buffer size (must match the actual parameter length).
3282 .. seealso:: `cuFileGetParameterPosixPoolSlabArray`
3283 """
3284 with nogil: 1v
3285 __status__ = cuFileGetParameterPosixPoolSlabArray(<size_t*>size_values, <size_t*>count_values, len) 1v
3286 check_status(__status__) 1v
3289cpdef str op_status_error(int status):
3290 """cufileop status string.
3292 Args:
3293 status (OpError): the error status to query.
3295 .. seealso:: `cufileop_status_error`
3296 """
3297 cdef bytes _output_
3298 _output_ = cufileop_status_error(<_OpError>status) 1efgrklhijmbcdnopq
3299 return _output_.decode() 1efgrklhijmbcdnopq
3302cpdef driver_close():
3303 """reset the cuFile library and release the nvidia-fs driver
3304 """
3305 with nogil: 1NPRTVXZ13579#%(*,stu.vwy
3306 status = cuFileDriverClose_v2() 1NPRTVXZ13579#%(*,stu.vwy
3307 check_status(status) 1NPRTVXZ13579#%(*,stu.vwy
3309cpdef read(intptr_t fh, intptr_t buf_ptr_base, size_t size, off_t file_offset, off_t buf_ptr_offset):
3310 """read data from a registered file handle to a specified device or host memory.
3312 Args:
3313 fh (intptr_t): ``CUfileHandle_t`` opaque file handle.
3314 buf_ptr_base (intptr_t): base address of buffer in device or host memory.
3315 size (size_t): size bytes to read.
3316 file_offset (off_t): file-offset from begining of the file.
3317 buf_ptr_offset (off_t): offset relative to the buf_ptr_base pointer to read into.
3319 Returns:
3320 ssize_t: number of bytes read on success.
3322 .. seealso:: `cuFileRead`
3323 """
3324 with nogil:
3325 status = cuFileRead(<Handle>fh, <void*>buf_ptr_base, size, file_offset, buf_ptr_offset)
3326 check_status(status)
3327 return status
3330cpdef write(intptr_t fh, intptr_t buf_ptr_base, size_t size, off_t file_offset, off_t buf_ptr_offset):
3331 """write data from a specified device or host memory to a registered file handle.
3333 Args:
3334 fh (intptr_t): ``CUfileHandle_t`` opaque file handle.
3335 buf_ptr_base (intptr_t): base address of buffer in device or host memory.
3336 size (size_t): size bytes to write.
3337 file_offset (off_t): file-offset from begining of the file.
3338 buf_ptr_offset (off_t): offset relative to the buf_ptr_base pointer to write from.
3340 Returns:
3341 ssize_t: number of bytes written on success.
3343 .. seealso:: `cuFileWrite`
3344 """
3345 with nogil:
3346 status = cuFileWrite(<Handle>fh, <const void*>buf_ptr_base, size, file_offset, buf_ptr_offset)
3347 check_status(status)
3348 return status