Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
94 commits
Select commit Hold shift + click to select a range
3ac3f15
Merge branch 'master' of https://github.com/KernelTuner/kernel_tuner
fjwillemsen Jun 6, 2024
5e32707
Implemented basic PyATF searchspace builder
fjwillemsen Jun 6, 2024
2214394
Minor changes
fjwillemsen Jul 25, 2024
0fa30a0
Setup structure for cross-searchspace hyperparameter tuning using met…
fjwillemsen Jul 30, 2024
2636245
Further integration of Hypertuner device functions
fjwillemsen Jul 30, 2024
af88572
Finalized new cross-searchspace hyperparameter tuning in Kernel Tuner
fjwillemsen Jul 30, 2024
4f0a4aa
Added T1 schema and command line interface for T1 input files
fjwillemsen Oct 5, 2024
1e7e54d
Implemented T1 input in interface
fjwillemsen Oct 7, 2024
fa11cfd
Merge with master
fjwillemsen Oct 8, 2024
a83fcd3
Fixed an issue that caused the T4 schema to point to a non-existing a…
fjwillemsen Oct 8, 2024
5f191da
Hypertuner tests are skipped without Methodology dependency installed
fjwillemsen Oct 8, 2024
0c0fbed
Added error message to Nox development environment check in case of f…
fjwillemsen Oct 8, 2024
a081772
Added type hints
fjwillemsen Oct 8, 2024
34d0755
Added T1 input file for testing
fjwillemsen Oct 8, 2024
61405fb
Added T1 input schema for validation
fjwillemsen Oct 8, 2024
bbdbc89
Setup tests for T1 input file
fjwillemsen Oct 8, 2024
1887fcd
Merge branch 'searchspace_experiments' of https://github.com/benvanwe…
fjwillemsen Oct 8, 2024
07bc8b0
Fixed an error reading the T1 format
fjwillemsen Oct 8, 2024
8242403
Fixed an error reading the T1 format
fjwillemsen Oct 8, 2024
0c4c76f
Interface accepts Path-type as kernel_source argument to resolve to file
fjwillemsen Oct 9, 2024
6c2476b
Added type hints
fjwillemsen Oct 9, 2024
f773dff
Changed test to Kernel Tuner example
fjwillemsen Oct 9, 2024
3cbf19a
Added functionality to have dynamic vector sizes based on tunable par…
fjwillemsen Oct 9, 2024
3398320
Added coonversion of grid divisions and constant arguments
fjwillemsen Oct 9, 2024
6711968
Added support for cachefiles in T1 interface
fjwillemsen Oct 9, 2024
814b155
Expose T1 interface function in package
fjwillemsen Oct 11, 2024
6ca0f69
Extended T1 tuning interface, formatting
fjwillemsen Oct 11, 2024
cb1a755
Convert single problem size to array, improved error messages
fjwillemsen Oct 11, 2024
a15ac3b
Split T4 output function to have either Python value or file returned
fjwillemsen Oct 11, 2024
74d5bba
Implemented return of T4 output, additional arguments
fjwillemsen Oct 11, 2024
3ea8c75
Further intergration of experiments file generation and hyperparamete…
fjwillemsen Oct 16, 2024
f17fcbe
Generate an experiments file using provided values and defaults from …
fjwillemsen Oct 16, 2024
1c9db4a
Fixed a function name error
fjwillemsen Oct 16, 2024
94995b4
Fixed an interface error in test
fjwillemsen Oct 16, 2024
b3e0f1d
Implemented sonarlint suggestions
fjwillemsen Oct 16, 2024
e7fd95a
Implemented benchmarkobserver for reporting hyperparameter tuning res…
fjwillemsen Oct 16, 2024
fd823aa
Limited the max_feval size to at most the size of the searchspace
fjwillemsen Oct 17, 2024
e04906e
Succesfully implemented hyperparameter tuning
fjwillemsen Oct 17, 2024
6062e50
Avoid duplicate execution, resolved an issue which sometimes led to h…
fjwillemsen Oct 22, 2024
11a86eb
Added time unit metadata to T4 output
fjwillemsen Oct 23, 2024
abaf90d
Set up hyperparamtuning cache, made cache names hyperparam-unique
fjwillemsen Oct 23, 2024
3be5685
Changed hyperparameter tuning defaults
fjwillemsen Oct 23, 2024
31ad0c8
Added per-parameter restrictions registration for pyATF
fjwillemsen Jan 9, 2025
f2a0f03
Generating intervals for pyATF where possible
fjwillemsen Jan 9, 2025
8c416ad
pyATF restrictions needed to be recombined in cases where multiple re…
fjwillemsen Jan 11, 2025
5e77fe4
Prevent pyATF from using Intervals where step size is 0
fjwillemsen Jan 11, 2025
41cd741
Restriction sources are passed back after compilation to aid pyATF
fjwillemsen Jan 14, 2025
39b5f01
Added default blocksize restriction for pyATF, as well as raising an …
fjwillemsen Jan 14, 2025
33c291d
Implemented automatic removal of functionally equivalent restrictions
fjwillemsen Jan 14, 2025
160a81f
Minor bug fixes
fjwillemsen Jan 14, 2025
5b6a0be
Improved the detection of whether an interval can be used
fjwillemsen Jan 16, 2025
f3b9991
Added parallel solver support
fjwillemsen Feb 9, 2025
df7d487
Updated dev-environment, changelog, dependencies
fjwillemsen Feb 11, 2025
97ca48b
Bumped version number does not belong in PR
fjwillemsen Feb 11, 2025
5b64b2c
Merged with master
fjwillemsen Feb 11, 2025
4401b03
Used new pyip name
fjwillemsen Feb 11, 2025
2eda1ba
Dropped Python 3.9 support for incompatibility with newer scipy versions
fjwillemsen Feb 11, 2025
deab9d8
Temporarily disabled ParallelSolver
fjwillemsen Mar 5, 2025
b0b477c
Updated pyproject to resolve hip-python error
fjwillemsen Mar 7, 2025
1e05d1a
Merge with master
fjwillemsen Mar 7, 2025
1d1e29b
Updated dependencies, required python version and bumped version
fjwillemsen Mar 25, 2025
246146f
Merge branch 'master' into searchspace_experiments
fjwillemsen Mar 25, 2025
94ce705
Updated documentation dependencies
fjwillemsen Mar 25, 2025
686ec2c
Added startup overhead to StopCriterion
fjwillemsen Apr 3, 2025
7dc9b63
Added profiling files to gitignore
fjwillemsen Apr 3, 2025
5c5ff1a
Added special runtime exception in case all tuning budget is exceeded…
fjwillemsen Apr 3, 2025
0e4facc
Raise an exception if the time budget is exceeded before the actual t…
fjwillemsen Apr 3, 2025
b1c8240
Removed redundant hyperparameter tuning tests
fjwillemsen Apr 3, 2025
c1b447c
Raise an exception if the time budget is exceeded before the actual t…
fjwillemsen Apr 3, 2025
9ce7cd2
Added tests for time budget
fjwillemsen Apr 3, 2025
bd1b4c3
Bug fix due to brackets in f-string
fjwillemsen Apr 3, 2025
c1acc3b
Merge remote-tracking branch 'origin/master' into searchspace_experim…
fjwillemsen Apr 3, 2025
3b9f5df
Updated pyproject to use more recent hip-python from testpypi
fjwillemsen Apr 3, 2025
01e1007
Updated pyproject to new project instead of poetry based information
fjwillemsen Apr 3, 2025
ee23629
Added passing of searchspace_construction_options via strategy_option…
fjwillemsen Apr 7, 2025
27f3731
Improved searchspace construction options handling, bumped version
fjwillemsen Apr 7, 2025
e89ae72
Improved searchspace construction options handling, bumped version
fjwillemsen Apr 7, 2025
1dbe54b
Updated pyproject file to avoid merge conflict after 1.1.0 release
fjwillemsen Apr 7, 2025
0de0530
Merge with recent commits to master
fjwillemsen Apr 8, 2025
13f61ec
add support for lambdas
benvanwerkhoven Apr 16, 2025
85a4f81
add support for compiling lambda constraints
benvanwerkhoven Apr 16, 2025
8c8f5d6
add sanity check
benvanwerkhoven Apr 16, 2025
b9f5595
additional test
benvanwerkhoven Apr 16, 2025
9ab2085
Resolved merge conflicts
fjwillemsen May 30, 2025
4f300b2
Completed merge with master
fjwillemsen May 30, 2025
1513d44
Updated documentation dependencies
fjwillemsen Jun 17, 2025
4d19f2e
Merge branch 'master' into searchspace_experiments
fjwillemsen Jun 17, 2025
4a70343
Update hyper.py; removed TODO
fjwillemsen Jun 17, 2025
1d71c9e
Updated python-constraint2 version in pyproject.toml
fjwillemsen Jun 17, 2025
5b5dbdb
Updated pyproject.toml to include new version of python-constraint2
fjwillemsen Jun 17, 2025
faeb52e
Moved compiling and parsing of restrictions to python-constraint wher…
fjwillemsen Jun 23, 2025
bae800e
Basic implementation to use Searchspace in Bayesian Optimization
fjwillemsen Jun 25, 2025
6c804ff
Merge with master
fjwillemsen Jun 25, 2025
3c6b96e
The Searchspace neighbor cache now caches for all neighbor methods se…
fjwillemsen Jun 25, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
poetry.lock
noxenv.txt
noxsettings.toml
hyperparamtuning/
*.prof

### Python ###
*.pyc
Expand All @@ -16,6 +18,8 @@ push_to_pypi.sh
.nfs*
*.log
*.json
!kernel_tuner/schema/T1/1.0.0/input-schema.json
!test/test_T1_input.json
*.csv
.cache
*.ipynb_checkpoints
Expand Down
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@ All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## Unreleased
<!-- ## [1.1.0] - 2025 ?? -->
- Additional improvements to search space construction
- changed HIP python bindings from pyhip-interface to the official hip-python
- Added Python 3.13 and experimental 3.14 support
- Dropped Python 3.8 and 3.9 support (due to incompatibility with newer scipy versions)

## [1.0.0] - 2024-04-04
- HIP backend to support tuning HIP kernels on AMD GPUs
- Experimental features for mixed-precision and accuracy tuning
- Experimental features for OpenACC tuning
- Major speedup due to new parser and using revamped python-constraint for searchspace building
- Major speedup due to new parser and using revamped python-constraint for search space construction
- Implemented ability to use `PySMT` and `ATF` for searchspace building
- Added Poetry for dependency and build management
- Switched from `setup.py` and `setup.cfg` to `pyproject.toml` for centralized metadata, added relevant tests
Expand Down
2 changes: 1 addition & 1 deletion INSTALL.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Linux users could type the following to download and install Python 3 using Mini
wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh
bash Miniconda3-latest-Linux-x86_64.sh
You are of course also free to use your own Python installation, and the Kernel Tuner is developed to be fully compatible with Python 3.9 and newer.
You are of course also free to use your own Python installation, and the Kernel Tuner is developed to be fully compatible with Python 3.10 and newer.

Installing Python Packages
--------------------------
Expand Down
455 changes: 291 additions & 164 deletions doc/requirements_test.txt

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions doc/source/dev-environment.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ Steps with :bash:`sudo` access (e.g. on a local device):
* After installation, restart your shell.
#. Install the required Python versions:
* On some systems, additional packages may be needed to build Python versions. For example on Ubuntu: :bash:`sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev wget libbz2-dev liblzma-dev lzma`.
* Install the Python versions with: :bash:`pyenv install 3.9 3.10 3.11 3.12`. The reason we're installing all these versions as opposed to just one, is so we can test against all supported Python versions.
#. Set the Python versions so they can be found: :bash:`pyenv local 3.9 3.10 3.11 3.12` (replace :bash:`local` with :bash:`global` when not using the virtualenv).
* Install the Python versions with: :bash:`pyenv install 3.9 3.10 3.11 3.12 3.13`. The reason we're installing all these versions as opposed to just one, is so we can test against all supported Python versions.
#. Set the Python versions so they can be found: :bash:`pyenv local 3.9 3.10 3.11 3.12 3.13` (replace :bash:`local` with :bash:`global` when not using the virtualenv).
#. Setup a local virtual environment in the folder: :bash:`pyenv virtualenv 3.11 kerneltuner` (or whatever environment name and Python version you prefer).
#. `Install Poetry <https://python-poetry.org/docs/#installing-with-the-official-installer>`__.
* Use :bash:`curl -sSL https://install.python-poetry.org | python3 -` to install Poetry.
Expand Down
2 changes: 1 addition & 1 deletion kernel_tuner/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from kernel_tuner.integration import store_results, create_device_targets
from kernel_tuner.interface import tune_kernel, run_kernel
from kernel_tuner.interface import tune_kernel, tune_kernel_T1, run_kernel

from importlib.metadata import version

Expand Down
10 changes: 5 additions & 5 deletions kernel_tuner/backends/backend.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
"""This module contains the interface of all kernel_tuner backends"""
"""This module contains the interface of all kernel_tuner backends."""
from __future__ import print_function

from abc import ABC, abstractmethod


class Backend(ABC):
"""Base class for kernel_tuner backends"""
"""Base class for kernel_tuner backends."""

@abstractmethod
def ready_argument_list(self, arguments):
"""This method must implement the allocation of the arguments on device memory."""
pass
return arguments

@abstractmethod
def compile(self, kernel_instance):
Expand Down Expand Up @@ -64,7 +64,7 @@ def refresh_memory(self, device_memory, host_arguments, should_sync):


class GPUBackend(Backend):
"""Base class for GPU backends"""
"""Base class for GPU backends."""

@abstractmethod
def __init__(self, device, iterations, compiler_options, observers):
Expand Down Expand Up @@ -93,7 +93,7 @@ def refresh_memory(self, gpu_memory, host_arguments, should_sync):


class CompilerBackend(Backend):
"""Base class for compiler backends"""
"""Base class for compiler backends."""

@abstractmethod
def __init__(self, iterations, compiler_options, compiler):
Expand Down
131 changes: 131 additions & 0 deletions kernel_tuner/backends/hypertuner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
"""This module contains a 'device' for hyperparameter tuning using the autotuning methodology."""

import platform
from pathlib import Path

from numpy import mean

from kernel_tuner.backends.backend import Backend
from kernel_tuner.observers.observer import BenchmarkObserver

try:
methodology_available = True
from autotuning_methodology.experiments import generate_experiment_file
from autotuning_methodology.report_experiments import get_strategy_scores
except ImportError:
methodology_available = False


class ScoreObserver(BenchmarkObserver):
def __init__(self, dev):
self.dev = dev
self.scores = []

def after_finish(self):
self.scores.append(self.dev.last_score)

def get_results(self):
results = {'score': mean(self.scores), 'scores': self.scores.copy()}
self.scores = []
return results

class HypertunerFunctions(Backend):
"""Class for executing hyperparameter tuning."""
units = {}

def __init__(self, iterations):
self.iterations = iterations
self.observers = [ScoreObserver(self)]
self.name = platform.processor()
self.max_threads = 1024
self.last_score = None

# set the environment options
env = dict()
env["iterations"] = self.iterations
self.env = env

# check for the methodology package
if methodology_available is not True:
raise ImportError("Unable to import the autotuning methodology, run `pip install autotuning_methodology`.")

def ready_argument_list(self, arguments):
arglist = super().ready_argument_list(arguments)
if arglist is None:
arglist = []
return arglist

def compile(self, kernel_instance):
super().compile(kernel_instance)
path = Path(__file__).parent.parent.parent / "hyperparamtuning"
path.mkdir(exist_ok=True)

# TODO get applications & GPUs args from benchmark
gpus = ["RTX_3090", "RTX_2080_Ti"]
applications = None
# applications = [
# {
# "name": "convolution",
# "folder": "./cached_data_used/kernels",
# "input_file": "convolution.json"
# },
# {
# "name": "pnpoly",
# "folder": "./cached_data_used/kernels",
# "input_file": "pnpoly.json"
# }
# ]

# strategy settings
strategy: str = kernel_instance.arguments[0]
hyperparams = [{'name': k, 'value': v} for k, v in kernel_instance.params.items()]
hyperparams_string = "_".join(f"{k}={str(v)}" for k, v in kernel_instance.params.items())
searchspace_strategies = [{
"autotuner": "KernelTuner",
"name": f"{strategy.lower()}_{hyperparams_string}",
"display_name": strategy.replace('_', ' ').capitalize(),
"search_method": strategy.lower(),
'search_method_hyperparameters': hyperparams
}]

# any additional settings
override = {
"experimental_groups_defaults": {
"samples": self.iterations
}
}

name = kernel_instance.name if len(kernel_instance.name) > 0 else kernel_instance.kernel_source.kernel_name
experiments_filepath = generate_experiment_file(name, path, searchspace_strategies, applications, gpus,
override=override, overwrite_existing_file=True)
return str(experiments_filepath)

def start_event(self):
return super().start_event()

def stop_event(self):
return super().stop_event()

def kernel_finished(self):
super().kernel_finished()
return True

def synchronize(self):
return super().synchronize()

def run_kernel(self, func, gpu_args=None, threads=None, grid=None, stream=None):
# generate the experiments file
experiments_filepath = Path(func)

# run the methodology to get a fitness score for this configuration
scores = get_strategy_scores(str(experiments_filepath))
self.last_score = scores[list(scores.keys())[0]]['score']

def memset(self, allocation, value, size):
return super().memset(allocation, value, size)

def memcpy_dtoh(self, dest, src):
return super().memcpy_dtoh(dest, src)

def memcpy_htod(self, dest, src):
return super().memcpy_htod(dest, src)
Loading