kernelfoundry.test_base¶
Base class for custom task tests from which all tests must derive.
Derive a test class from TestBase in your task.py file and define tests as
methods on that class.
Classes
|
Base class from which kernel task tests must derive. |
- class kernelfoundry.test_base.TestBase[source]¶
Base class from which kernel task tests must derive.
Example
The following shows how to define a test by deriving from TestBase:
# This is a partial example; see templates for a complete task. from pathlib import Path import torch import pytest from kernelfoundry import TestBase # ... pytest fixtures for device/kernel/data are omitted for brevity. class TestRelu(TestBase): def build(self, gpu_arch) -> list[str]: return self.compile_torch_extension( extension_name="relu_kernel", src="relu_kernel.sycl", output_dir=Path(__file__).parent, gpu_arch=gpu_arch, ) def test_correctness(self, data, kernel, device): x, y = data assert torch.allclose(kernel(x), y, rtol=1e-4, atol=1e-4) @pytest.mark.performance def test_benchmark(self, data, kernel, device, measure_runtime_torch): # measure_runtime_torch fixture is provided by kernelfoundry/conftest.py x, _ = data measure_runtime_torch(kernel, device, args=(x,))
- build(gpu_arch) list[str][source]¶
Builds the kernel and returns a list of build artifacts required for running the tests.
- build_reference(gpu_arch) list[str][source]¶
Builds the reference code and returns a list of build artifacts required for running the tests.
- static compile_torch_extension(extension_name: str, src: str | Path, output_dir: str | Path, gpu_arch: str, timeout: int = 120, backend: str = 'torch') list[str][source]¶
Compiles the source file to a PyTorch extension.
- Parameters:
extension_name (str) – Name of the PyTorch extension to build.
src (str) – Path to the source file.
output_dir (str) – Directory to store the compiled outputs.
gpu_arch (str) – GPU architecture string.
timeout (int) – Timeout for each compilation step in seconds.
backend (str) – The backend to use for compilation. This is either ‘torch’ (default) or ‘icpx’.
- Returns:
List of paths to the compiled extensions.
- Return type: