-
Notifications
You must be signed in to change notification settings - Fork 293
Expand file tree
/
Copy pathtest_cupy.py
More file actions
206 lines (152 loc) · 6.32 KB
/
test_cupy.py
File metadata and controls
206 lines (152 loc) · 6.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# Copyright 2021-2024 NVIDIA Corporation. All rights reserved.
#
# Please refer to the NVIDIA end user license agreement (EULA) associated
# with this source code for terms and conditions that govern your use of
# this software. Any use, reproduction, disclosure, or distribution of
# this software and related documentation outside the terms of the EULA
# is strictly prohibited.
import ctypes
import pytest
# Always skip since cupy is not CTK 12.x yet
skip_tests = True
if not skip_tests:
try:
import cupy
skip_tests = False
except ImportError:
skip_tests = True
from .kernels import kernel_string
def launch(kernel, args=()):
kernel((1,), (1,), args)
# Measure launch latency with no parmaeters
@pytest.mark.skipif(skip_tests, reason="cupy is not installed")
@pytest.mark.benchmark(group="cupy")
def test_launch_latency_empty_kernel(benchmark):
module = cupy.RawModule(code=kernel_string)
kernel = module.get_function("empty_kernel")
stream = cupy.cuda.stream.Stream(non_blocking=True)
with stream:
benchmark(launch, kernel)
stream.synchronize()
# Measure launch latency with a single parameter
@pytest.mark.skipif(skip_tests, reason="cupy is not installed")
@pytest.mark.benchmark(group="cupy")
def test_launch_latency_small_kernel(benchmark):
module = cupy.RawModule(code=kernel_string)
kernel = module.get_function("small_kernel")
cupy.cuda.set_allocator()
arg = cupy.cuda.alloc(ctypes.sizeof(ctypes.c_float))
stream = cupy.cuda.stream.Stream(non_blocking=True)
with stream:
benchmark(launch, kernel, (arg,))
stream.synchronize()
# Measure launch latency with many parameters using builtin parameter packing
@pytest.mark.skipif(skip_tests, reason="cupy is not installed")
@pytest.mark.benchmark(group="cupy")
def test_launch_latency_small_kernel_512_args(benchmark):
module = cupy.RawModule(code=kernel_string)
kernel = module.get_function("small_kernel_512_args")
cupy.cuda.set_allocator()
args = []
for _ in range(512):
args.append(cupy.cuda.alloc(ctypes.sizeof(ctypes.c_int)))
args = tuple(args)
stream = cupy.cuda.stream.Stream(non_blocking=True)
with stream:
benchmark(launch, kernel, args)
stream.synchronize()
# Measure launch latency with many parameters using builtin parameter packing
@pytest.mark.skipif(skip_tests, reason="cupy is not installed")
@pytest.mark.benchmark(group="cupy")
def test_launch_latency_small_kernel_512_bools(benchmark):
module = cupy.RawModule(code=kernel_string)
kernel = module.get_function("small_kernel_512_bools")
cupy.cuda.set_allocator()
args = [True] * 512
args = tuple(args)
stream = cupy.cuda.stream.Stream(non_blocking=True)
with stream:
benchmark(launch, kernel, args)
stream.synchronize()
# Measure launch latency with many parameters using builtin parameter packing
@pytest.mark.skipif(skip_tests, reason="cupy is not installed")
@pytest.mark.benchmark(group="cupy")
def test_launch_latency_small_kernel_512_doubles(benchmark):
module = cupy.RawModule(code=kernel_string)
kernel = module.get_function("small_kernel_512_doubles")
cupy.cuda.set_allocator()
args = [1.2345] * 512
args = tuple(args)
stream = cupy.cuda.stream.Stream(non_blocking=True)
with stream:
benchmark(launch, kernel, args)
stream.synchronize()
# Measure launch latency with many parameters using builtin parameter packing
@pytest.mark.skipif(skip_tests, reason="cupy is not installed")
@pytest.mark.benchmark(group="cupy")
def test_launch_latency_small_kernel_512_ints(benchmark):
module = cupy.RawModule(code=kernel_string)
kernel = module.get_function("small_kernel_512_ints")
cupy.cuda.set_allocator()
args = [123] * 512
args = tuple(args)
stream = cupy.cuda.stream.Stream(non_blocking=True)
with stream:
benchmark(launch, kernel, args)
stream.synchronize()
# Measure launch latency with many parameters using builtin parameter packing
@pytest.mark.skipif(skip_tests, reason="cupy is not installed")
@pytest.mark.benchmark(group="cupy")
def test_launch_latency_small_kernel_512_bytes(benchmark):
module = cupy.RawModule(code=kernel_string)
kernel = module.get_function("small_kernel_512_chars")
cupy.cuda.set_allocator()
args = [127] * 512
args = tuple(args)
stream = cupy.cuda.stream.Stream(non_blocking=True)
with stream:
benchmark(launch, kernel, args)
stream.synchronize()
# Measure launch latency with many parameters using builtin parameter packing
@pytest.mark.skipif(skip_tests, reason="cupy is not installed")
@pytest.mark.benchmark(group="cupy")
def test_launch_latency_small_kernel_512_longlongs(benchmark):
module = cupy.RawModule(code=kernel_string)
kernel = module.get_function("small_kernel_512_longlongs")
cupy.cuda.set_allocator()
args = [9223372036854775806] * 512
args = tuple(args)
stream = cupy.cuda.stream.Stream(non_blocking=True)
with stream:
benchmark(launch, kernel, args)
stream.synchronize()
# Measure launch latency with many parameters using builtin parameter packing
@pytest.mark.skipif(skip_tests, reason="cupy is not installed")
@pytest.mark.benchmark(group="cupy")
def test_launch_latency_small_kernel_256_args(benchmark):
module = cupy.RawModule(code=kernel_string)
kernel = module.get_function("small_kernel_256_args")
cupy.cuda.set_allocator()
args = []
for _ in range(256):
args.append(cupy.cuda.alloc(ctypes.sizeof(ctypes.c_int)))
args = tuple(args)
stream = cupy.cuda.stream.Stream(non_blocking=True)
with stream:
benchmark(launch, kernel, args)
stream.synchronize()
# Measure launch latency with many parameters using builtin parameter packing
@pytest.mark.skipif(skip_tests, reason="cupy is not installed")
@pytest.mark.benchmark(group="cupy")
def test_launch_latency_small_kernel_16_args(benchmark):
module = cupy.RawModule(code=kernel_string)
kernel = module.get_function("small_kernel_16_args")
cupy.cuda.set_allocator()
args = []
for _ in range(16):
args.append(cupy.cuda.alloc(ctypes.sizeof(ctypes.c_int)))
args = tuple(args)
stream = cupy.cuda.stream.Stream(non_blocking=True)
with stream:
benchmark(launch, kernel, args)
stream.synchronize()