Skip to content

Commit 588d93f

Browse files
Merge pull request #184 from KernelTuner/add_runner_test
add a test to illustrate use of runner
2 parents 359fe95 + 821851e commit 588d93f

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

test/test_runners.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
import kernel_tuner
99
from kernel_tuner import util
10+
from kernel_tuner import core
11+
from kernel_tuner.interface import Options, _kernel_options, _device_options, _tuning_options
12+
from kernel_tuner.runners.sequential import SequentialRunner
1013

1114
from .context import skip_if_no_pycuda
1215

@@ -186,3 +189,44 @@ def test_interface_handles_compile_failures(env):
186189

187190
failed_config = [record for record in results if record["block_size_x"] == 256][0]
188191
assert isinstance(failed_config["time"], util.CompilationFailedConfig)
192+
193+
194+
@skip_if_no_pycuda
195+
def test_runner(env):
196+
197+
kernel_name, kernel_source, problem_size, arguments, tune_params = env
198+
199+
# create KernelSource
200+
kernelsource = core.KernelSource(kernel_name, kernel_source, lang=None, defines=None)
201+
202+
# create option bags
203+
device=0
204+
atol=1e-6
205+
platform=0
206+
iterations=7
207+
verbose=False
208+
objective="time"
209+
opts = locals()
210+
kernel_options = Options([(k, opts.get(k, None)) for k in _kernel_options.keys()])
211+
tuning_options = Options([(k, opts.get(k, None)) for k in _tuning_options.keys()])
212+
device_options = Options([(k, opts.get(k, None)) for k in _device_options.keys()])
213+
tuning_options.cachefile = None
214+
215+
# create runner
216+
runner = SequentialRunner(kernelsource, kernel_options, device_options, iterations, observers=None)
217+
runner.warmed_up = True # disable warm up for this test
218+
219+
# select a config to run
220+
searchspace = []
221+
222+
# insert configurations to run with this runner in this list
223+
# each configuration is described as a list of values, one for each tunable parameter
224+
# the order should correspond to the order of parameters specified in tune_params
225+
searchspace.append([32]) # vector_add only has one tunable parameter (block_size_x)
226+
227+
# call the runner
228+
results, _ = runner.run(searchspace, kernel_options, tuning_options)
229+
230+
assert len(results) == 1
231+
assert results[0]['block_size_x'] == 32
232+
assert len(results[0]['times']) == iterations

0 commit comments

Comments
 (0)