Elffuss BraidHub

kikocis/kleidiai public

main · 2.8 KiBRawPermalink
1//
2// SPDX-FileCopyrightText: Copyright 2025-2026 Arm Limited and/or its affiliates <open-source-office@arm.com>
3//
4// SPDX-License-Identifier: Apache-2.0
5//
6
7#pragma once
8
9#include <cstddef>
10#include <string_view>
11#include <vector>
12
13#include "test/nextgen/common/shape.hpp"
14#include "test/nextgen/harness/tensor.hpp"
15#include "test/nextgen/operators/matmul/matmul_slots.hpp"
16
17namespace kai::test {
18
19/// Wrapper to provide unified API for all micro-kernels.
20template <typename ShapeT>
21class KernelWrapper {
22public:
23 KernelWrapper() = default; ///< Default constructor.
24 virtual ~KernelWrapper() = default; ///< Destructor.
25 KernelWrapper(const KernelWrapper&) = delete; ///< No copy constructor.
26 KernelWrapper& operator=(const KernelWrapper&) = delete; ///< No copy assignment.
27 KernelWrapper(KernelWrapper&&) = default; ///< Move constructor.
28 KernelWrapper& operator=(KernelWrapper&&) = default; ///< Move assignment.
29
30 /// Gets the micro-kernel name.
31 [[nodiscard]] virtual std::string_view name() const = 0;
32
33 /// Gets the list of input tensors required to run the micro-kernel.
34 ///
35 /// @param[in] tensors The data pool.
36 ///
37 /// @return The list of tensor IDs.
38 [[nodiscard]] virtual std::vector<MatMulSlot> run_inputs(ConstTensorSet tensors) const = 0;
39
40 /// Gets the list of input tensors required to run the reference implementation.
41 ///
42 /// @param[in] tensors The data pool.
43 ///
44 /// @return The list of tensor IDs.
45 [[nodiscard]] virtual std::vector<MatMulSlot> ref_inputs(ConstTensorSet tensors) const = 0;
46
47 /// Gets the scheduling steps in each dimension.
48 ///
49 /// @param[in] shape The full problem shape.
50 /// @param[in] tensors The data pool.
51 ///
52 /// @return The step in each dimension.
53 [[nodiscard]] virtual std::vector<size_t> steps(ShapeT shape, ConstTensorSet tensors) const = 0;
54
55 /// Populates the data pool with constant information.
56 ///
57 /// @param[in, out] tensors The data pool.
58 virtual void populate_constant_info(TensorSet tensors) const = 0;
59
60 /// Runs the micro-kernel to process a tile of the problem shape.
61 ///
62 /// @param[in] full_shape The full problem shape.
63 /// @param[in] tile_coords The starting coordinate of the tile to be processed by the kernel.
64 /// @param[in] tile_shape The size of the tile to be processed by the kernel.
65 /// @param[in, out] tensors The data pool.
66 virtual void run(ShapeT full_shape, Span<const size_t> tile_coords, ShapeT tile_shape, TensorSet tensors) const = 0;
67
68 /// Computes the reference data.
69 ///
70 /// @param[in] shape The problem shape.
71 /// @param[in, out] tensors The data pool.
72 virtual void compute_reference(ShapeT shape, TensorSet tensors) const = 0;
73};
74
75} // namespace kai::test