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

Method test_static_array

tests/cupy_tests/core_tests/test_function.py:84–115  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

82 testing.assert_array_equal(x, expected)
83
84 def test_static_array(self):
85 code = '''
86struct double5 {
87 double value[5];
88 __device__ const double& operator[](size_t i) const { return value[i]; }
89};
90
91extern "C" __global__ void test_kernel(const double* a, double5 b, double* x) {
92 int i = threadIdx.x;
93 x[i] = a[i] + b[0] + b[1] + b[2] + b[3] + b[4];
94}
95'''
96
97 a_cpu = numpy.arange(24, dtype=numpy.float64)
98 a = cupy.array(a_cpu)
99 x = cupy.empty_like(a)
100
101 func = _compile_func('test_kernel', code)
102
103 # We cannot pass np.ndarray kernel arguments of size > 1
104 b = numpy.arange(5).astype(numpy.float64)
105 with pytest.raises(TypeError):
106 func.linear_launch(a.size, (a, b, x))
107
108 double5 = numpy.dtype({
109 'names': ['dummy'],
110 'formats': [(numpy.float64, (5,))]
111 })
112 func.linear_launch(a.size, (a, b.view(double5), x))
113
114 expected = a_cpu + b.sum()
115 testing.assert_array_equal(x, expected)
116
117 def test_custom_user_struct(self):
118 struct_definition = '''

Callers

nothing calls this directly

Calls 5

_compile_funcFunction · 0.85
viewMethod · 0.80
astypeMethod · 0.45
dtypeMethod · 0.45
sumMethod · 0.45

Tested by

no test coverage detected