Skip to content

[examples][xegpu] Add gridsearch and genetic algorithm autotuners#79

Open
tkarna wants to merge 2 commits intollvm:mainfrom
tkarna:xegpu-autotune
Open

[examples][xegpu] Add gridsearch and genetic algorithm autotuners#79
tkarna wants to merge 2 commits intollvm:mainfrom
tkarna:xegpu-autotune

Conversation

@tkarna
Copy link
Contributor

@tkarna tkarna commented Mar 16, 2026

Adds tune_matmul_gridsearch.py and tune_matmul_ga.py methods. See README.md for instructions.

@tkarna tkarna force-pushed the xegpu-autotune branch 3 times, most recently from 71b7980 to 513f36b Compare March 20, 2026 12:51
@tkarna tkarna marked this pull request as ready for review March 20, 2026 12:56
@tkarna
Copy link
Contributor Author

tkarna commented Mar 20, 2026

Thanks to #63 we can now trace the schedule module to construct the search space, enumerate it, and also automatically check the validity of a given set of parameters (what check_constraints does in the present implementation). This PR does not use this functionality yet, it will be addressed in a forthcoming PR.

self.logger.setLevel(logging.INFO)
handler = logging.StreamHandler()
handler.setFormatter(logging.Formatter("%(message)s"))
if not self.logger.hasHandlers():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can it have handler here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logging.getLogger("csv_logger") gives you an existing logger instance.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds two autotuning entrypoints for the XeGPU matmul example (exhaustive grid search + genetic algorithm), along with shared utilities and documentation updates to support running/recording tuning experiments.

Changes:

  • Add tune_matmul_gridsearch.py for exhaustive parameter search and CSV logging.
  • Add tune_matmul_ga.py + genetic_algorithm.py for GA-based adaptive sampling.
  • Refactor matmul.py CLI parsing to share args with tuners and add JSON parameter loading; update README and lit excludes.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 13 comments.

Show a summary per file
File Description
examples/xegpu/tune_matmul_gridsearch.py Implements exhaustive search, constraints filtering, timed execution, CSV logging, and JSON dumping.
examples/xegpu/tune_matmul_ga.py Implements GA-driven tuning using the shared search-space + logging utilities.
examples/xegpu/matmul.py Extracts shared CLI parser and adds --json parameter loading path.
examples/xegpu/lit.local.cfg Excludes non-test helper/tuner scripts from lit discovery.
examples/xegpu/genetic_algorithm.py New GA + population/search-space utility implementation.
examples/xegpu/csv_logger.py New small CSV logger utility used by both tuners.
examples/xegpu/README.md Documents new tuning workflows and updates matmul CLI usage examples.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

)
parser.add_argument(
"--json",
help="Read problem sizes and tile parameters from a JSON file.",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe mention that this will ignore most of the other args

Comment on lines +359 to +365
if args.json:
with open(args.json, "r") as f:
params = json.load(f)
else:
M, N, K = args.sizes
params = {
"m": M,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, the individual args could overwrite the defaults from json

Comment on lines +18 to +20
assert not os.path.exists(self.filename), (
f"CSV file '{self.filename}' already exists"
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assert not os.path.exists(self.filename), (
f"CSV file '{self.filename}' already exists"
)
def uniquify(path):
base, ext = os.path.splitext(path)
i = 1
new_path = path
while os.path.exists(new_path):
new_path = f"{base}_{i}{ext}"
i += 1
return new_path
self.filename = uniquify(self.filename)

Comment on lines +11 to +15
from tune_matmul_gridsearch import (
construct_search_space,
execute_and_log,
dump_configs_json,
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: common features could go in a separate file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants