MCPcopy Create free account
hub / github.com/cupy/cupy / DummyObjectWithCudaArrayInterface

Class DummyObjectWithCudaArrayInterface

cupy/testing/_protocol_helpers.py:10–71  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8
9
10class DummyObjectWithCudaArrayInterface:
11 # Private helper used for testing cuda array interface support.
12 def __init__(
13 self, a, ver=3, include_strides=False, mask=None, stream=None
14 ):
15 assert ver in tuple(range(max_cuda_array_interface_version+1))
16 self.a = None
17 if isinstance(a, cupy.ndarray):
18 self.a = a
19 else:
20 self.shape, self.strides, self.typestr, self.descr, self.data = a
21 self.ver = ver
22 self.include_strides = include_strides
23 self.mask = mask
24 self.stream = stream
25
26 @property
27 def __cuda_array_interface__(self):
28 if self.a is not None:
29 desc = {
30 'shape': self.a.shape,
31 'typestr': self.a.dtype.str,
32 'descr': self.a.dtype.descr,
33 'data': (self.a.data.ptr, False),
34 'version': self.ver,
35 }
36 if self.a.flags.c_contiguous:
37 if self.include_strides is True:
38 desc['strides'] = self.a.strides
39 elif self.include_strides is None:
40 desc['strides'] = None
41 else: # self.include_strides is False
42 pass
43 else: # F contiguous or neither
44 desc['strides'] = self.a.strides
45 else:
46 desc = {
47 'shape': self.shape,
48 'typestr': self.typestr,
49 'descr': self.descr,
50 'data': (self.data, False),
51 'version': self.ver,
52 }
53 if self.include_strides is True:
54 desc['strides'] = self.strides
55 elif self.include_strides is None:
56 desc['strides'] = None
57 else: # self.include_strides is False
58 pass
59 if self.mask is not None:
60 desc['mask'] = self.mask
61 # The stream field is kept here for compliance. However, since the
62 # synchronization is done via calling a cpdef function, which cannot
63 # be mock-tested.
64 if self.stream is not None:
65 if self.stream is cuda.Stream.null:
66 desc['stream'] = cuda.runtime.streamLegacy
67 elif (not cuda.runtime.is_hip) and self.stream is cuda.Stream.ptds:

Callers 13

test_baseMethod · 0.90
test_not_copiedMethod · 0.90
test_orderMethod · 0.90
test_with_stridesMethod · 0.90
test_asnumpyMethod · 0.90
test_big_endianMethod · 0.90
test_structuredMethod · 0.90
test_datetime64_viewMethod · 0.90
test_masked_arrayMethod · 0.90

Calls

no outgoing calls

Tested by 13

test_baseMethod · 0.72
test_not_copiedMethod · 0.72
test_orderMethod · 0.72
test_with_stridesMethod · 0.72
test_asnumpyMethod · 0.72
test_big_endianMethod · 0.72
test_structuredMethod · 0.72
test_datetime64_viewMethod · 0.72
test_masked_arrayMethod · 0.72