Skip to content

Commit 42c603e

Browse files
committed
Updates for numeric array
1 parent f01c309 commit 42c603e

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

cuda_bindings/cuda/bindings/cufile.pyx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import cython
1616
from cuda.bindings.driver import CUresult as pyCUresult
1717

1818
from libc.stdlib cimport calloc, free, malloc
19-
cimport cpython
19+
from cython cimport view
2020
cimport cpython.buffer
2121
cimport cpython.memoryview
2222
from libc.string cimport memcmp, memcpy
@@ -2185,24 +2185,32 @@ cdef class StatsLevel2:
21852185
@property
21862186
def read_size_kb_hist(self):
21872187
"""~_numpy.uint64: (array of length 32)."""
2188-
return self._ptr[0].read_size_kb_hist
2188+
cdef view.array arr = view.array(shape=(32,), itemsize=sizeof(uint64_t), format="Q", mode="c", allocate_buffer=False)
2189+
arr.data = <char *>(&(self._ptr[0].read_size_kb_hist))
2190+
return arr
21892191

21902192
@read_size_kb_hist.setter
21912193
def read_size_kb_hist(self, val):
21922194
if self._readonly:
21932195
raise ValueError("This StatsLevel2 instance is read-only")
2194-
self._ptr[0].read_size_kb_hist = val
2196+
cdef view.array arr = view.array(shape=(len(val),), itemsize=sizeof(uint64_t), format="Q", mode="c")
2197+
arr[:] = _numpy.asarray(val, dtype=_numpy.uint64)
2198+
memcpy(<void *>(&(self._ptr[0].read_size_kb_hist)), <void *>(arr.data), sizeof(uint64_t) * len(val))
21952199

21962200
@property
21972201
def write_size_kb_hist(self):
21982202
"""~_numpy.uint64: (array of length 32)."""
2199-
return self._ptr[0].write_size_kb_hist
2203+
cdef view.array arr = view.array(shape=(32,), itemsize=sizeof(uint64_t), format="Q", mode="c", allocate_buffer=False)
2204+
arr.data = <char *>(&(self._ptr[0].write_size_kb_hist))
2205+
return arr
22002206

22012207
@write_size_kb_hist.setter
22022208
def write_size_kb_hist(self, val):
22032209
if self._readonly:
22042210
raise ValueError("This StatsLevel2 instance is read-only")
2205-
self._ptr[0].write_size_kb_hist = val
2211+
cdef view.array arr = view.array(shape=(len(val),), itemsize=sizeof(uint64_t), format="Q", mode="c")
2212+
arr[:] = _numpy.asarray(val, dtype=_numpy.uint64)
2213+
memcpy(<void *>(&(self._ptr[0].write_size_kb_hist)), <void *>(arr.data), sizeof(uint64_t) * len(val))
22062214

22072215
@staticmethod
22082216
def from_data(data):

cuda_bindings/cuda/bindings/cycufile.pxd

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,42 +185,50 @@ cdef extern from '<cufile.h>':
185185
ctypedef struct CUfileError_t 'CUfileError_t':
186186
CUfileOpError err
187187
CUresult cu_err
188+
188189
cdef struct _anon_pod0 '_anon_pod0':
189190
unsigned int major_version
190191
unsigned int minor_version
191192
size_t poll_thresh_size
192193
size_t max_direct_io_size
193194
unsigned int dstatusflags
194195
unsigned int dcontrolflags
196+
195197
cdef extern from '<cufile.h>':
196198
ctypedef struct cufileRDMAInfo_t 'cufileRDMAInfo_t':
197199
int version
198200
int desc_len
199201
char* desc_str
202+
200203
cdef extern from '<cufile.h>':
201204
ctypedef struct CUfileFSOps_t 'CUfileFSOps_t':
202205
char* (*fs_type)(void*)
203206
int (*getRDMADeviceList)(void*, sockaddr_t**)
204207
int (*getRDMADevicePriority)(void*, char*, size_t, loff_t, sockaddr_t*)
205208
ssize_t (*read)(void*, char*, size_t, loff_t, cufileRDMAInfo_t*)
206209
ssize_t (*write)(void*, const char*, size_t, loff_t, cufileRDMAInfo_t*)
210+
207211
cdef union _anon_pod1 '_anon_pod1':
208212
int fd
209213
void* handle
214+
210215
cdef struct _anon_pod3 '_anon_pod3':
211216
void* devPtr_base
212217
off_t file_offset
213218
off_t devPtr_offset
214219
size_t size
220+
215221
cdef extern from '<cufile.h>':
216222
ctypedef struct CUfileIOEvents_t 'CUfileIOEvents_t':
217223
void* cookie
218224
CUfileStatus_t status
219225
size_t ret
226+
220227
cdef extern from '<cufile.h>':
221228
ctypedef struct CUfileOpCounter_t 'CUfileOpCounter_t':
222229
uint64_t ok
223230
uint64_t err
231+
224232
cdef extern from '<cufile.h>':
225233
ctypedef struct CUfilePerGpuStats_t 'CUfilePerGpuStats_t':
226234
char uuid[16]
@@ -253,6 +261,7 @@ cdef extern from '<cufile.h>':
253261
uint64_t n_mmap_err
254262
uint64_t n_mmap_free
255263
uint64_t reg_bytes
264+
256265
cdef extern from '<cufile.h>':
257266
ctypedef struct CUfileDrvProps_t 'CUfileDrvProps_t':
258267
_anon_pod0 nvfs
@@ -262,13 +271,16 @@ cdef extern from '<cufile.h>':
262271
unsigned int max_device_pinned_mem_size
263272
unsigned int max_batch_io_size
264273
unsigned int max_batch_io_timeout_msecs
274+
265275
cdef extern from '<cufile.h>':
266276
ctypedef struct CUfileDescr_t 'CUfileDescr_t':
267277
CUfileFileHandleType type
268278
_anon_pod1 handle
269279
CUfileFSOps_t* fs_ops
280+
270281
cdef union _anon_pod2 '_anon_pod2':
271282
_anon_pod3 batch
283+
272284
cdef extern from '<cufile.h>':
273285
ctypedef struct CUfileStatsLevel1_t 'CUfileStatsLevel1_t':
274286
CUfileOpCounter_t read_ops
@@ -314,25 +326,29 @@ cdef extern from '<cufile.h>':
314326
uint64_t batch_completion_lat_sum_us
315327
uint64_t last_batch_read_bytes
316328
uint64_t last_batch_write_bytes
329+
317330
cdef extern from '<cufile.h>':
318331
ctypedef struct CUfileIOParams_t 'CUfileIOParams_t':
319332
CUfileBatchMode_t mode
320333
_anon_pod2 u
321334
CUfileHandle_t fh
322335
CUfileOpcode_t opcode
323336
void* cookie
337+
324338
cdef extern from '<cufile.h>':
325339
ctypedef struct CUfileStatsLevel2_t 'CUfileStatsLevel2_t':
326340
CUfileStatsLevel1_t basic
327341
uint64_t read_size_kb_hist[32]
328342
uint64_t write_size_kb_hist[32]
343+
329344
cdef extern from '<cufile.h>':
330345
ctypedef struct CUfileStatsLevel3_t 'CUfileStatsLevel3_t':
331346
CUfileStatsLevel2_t detailed
332347
uint32_t num_gpus
333348
CUfilePerGpuStats_t per_gpu_stats[16]
334349

335350

351+
336352
cdef extern from *:
337353
"""
338354
// This is the missing piece we need to supply to help Cython & C++ compilers.

0 commit comments

Comments
 (0)