@@ -186,9 +186,6 @@ def split(self, section, stream=0):
186
186
end = min (begin + section , self .size )
187
187
shape = (end - begin ,)
188
188
gpu_data = self .gpu_data .view (begin * itemsize , end * itemsize )
189
- # gpu_head = _allocate_head(1)
190
- # ndarray_populate_head(gpu_head, gpu_data, shape, strides,
191
- # stream=stream)
192
189
yield DeviceNDArray (shape , strides , dtype = self .dtype , stream = stream ,
193
190
gpu_data = gpu_data )
194
191
@@ -253,6 +250,10 @@ def __getitem__(self, item):
253
250
254
251
255
252
class MappedNDArray (DeviceNDArrayBase , np .ndarray ):
253
+ """
254
+ A host array that uses CUDA mapped memory.
255
+ """
256
+
256
257
def device_setup (self , gpu_data , stream = 0 ):
257
258
self .gpu_mem = ArrayHeaderManager (devices .get_context ())
258
259
@@ -279,17 +280,23 @@ def from_array_like(ary, stream=0, gpu_head=None, gpu_data=None):
279
280
gpu_data = gpu_data )
280
281
281
282
283
+ errmsg_contiguous_buffer = ("Array contains non-contiguous buffer and cannot "
284
+ "be transferred as a single memory region. Please "
285
+ "ensure contiguous buffer with numpy "
286
+ ".ascontiguousarray()" )
287
+
288
+
289
+ def sentry_contiguous (ary ):
290
+ if not ary .flags ['C_CONTIGUOUS' ] and not ary .flags ['F_CONTIGUOUS' ]:
291
+ if ary .ndim != 1 or ary .shape [0 ] != 1 or ary .strides [0 ] != 0 :
292
+ raise ValueError (errmsg_contiguous_buffer )
293
+
294
+
282
295
def auto_device (ary , stream = 0 , copy = True ):
283
296
if _driver .is_device_memory (ary ):
284
297
return ary , False
285
298
else :
286
- if not ary .flags ['C_CONTIGUOUS' ] and not ary .flags ['F_CONTIGUOUS' ]:
287
- if ary .ndim != 1 or ary .shape [0 ] != 1 or ary .strides [0 ] != 0 :
288
- raise ValueError (
289
- "Array contains non-contiguous buffer and cannot "
290
- "be transferred as a single memory region. "
291
- "Please ensure contiguous buffer with numpy"
292
- ".ascontiguousarray()" )
299
+ sentry_contiguous (ary )
293
300
devarray = from_array_like (ary , stream = stream )
294
301
if copy :
295
302
devarray .copy_to_device (ary , stream = stream )
0 commit comments