Skip to content

Commit a1c87db

Browse files
committed
Add support for KERNEL_TUNER_PARALLEL environment variable
1 parent 2c33501 commit a1c87db

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

doc/source/parallel.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,14 @@ To enable parallel tuning, pass the ``parallel`` argument to ``tune_kernel``:
3131
)
3232
3333
If ``parallel`` is set to ``True``, Kernel Tuner will use all available Ray workers for tuning.
34-
Alternatively, ``parallel`` can be set to an integer ``n`` to use exactly ``n`` workers.
34+
The ``parallel`` option can also be set to an integer ``n`` to use exactly ``n`` workers.
35+
36+
Alternatively, define the environment variable ``KERNEL_TUNER_PARALLEL`` to enable parallel execution without modifying your Python code.
37+
38+
.. code-block:: bash
39+
40+
$ KERNEL_TUNER_PARALLEL=true python3 my_tuning_script.py
41+
3542
3643
3744
Parallel tuning and optimization strategies

kernel_tuner/interface.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from argparse import ArgumentParser
2929
from ast import literal_eval
3030
from datetime import datetime
31+
import os
3132
from pathlib import Path
3233
from time import perf_counter
3334
from copy import deepcopy
@@ -67,6 +68,8 @@
6768
)
6869
from kernel_tuner.strategies.wrapper import OptAlgWrapper
6970

71+
environment_key_parallel = "KERNEL_TUNER_PARALLEL"
72+
7073
strategy_map = {
7174
"brute_force": brute_force,
7275
"random_sample": random_sample,
@@ -585,7 +588,7 @@ def tune_kernel(
585588
strategy_options=None,
586589
cache=None,
587590
metrics=None,
588-
simulation_mode=False,
591+
simulation_mode=None,
589592
parallel=None,
590593
observers=None,
591594
objective=None,
@@ -662,6 +665,12 @@ def tune_kernel(
662665
# TODO: we could use the "match case" syntax when removing support for 3.9
663666
tuning_options.simulated_time = 0
664667

668+
# Get runner from environment if possible
669+
if parallel is None:
670+
parallel = bool(os.environ.get(environment_key_parallel))
671+
672+
673+
# Create runner
665674
if parallel and simulation_mode:
666675
raise ValueError("Enabling `parallel` and `simulation_mode` together is not supported")
667676
elif simulation_mode:

0 commit comments

Comments
 (0)