test/nextgen/format/plain_format.hpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // | ||
| 2 | // SPDX-FileCopyrightText: Copyright 2025 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 <ostream> | ||
| 11 | |||
| 12 | #include "test/common/buffer.hpp" | ||
| 13 | #include "test/common/compare.hpp" | ||
| 14 | #include "test/common/data_type.hpp" | ||
| 15 | #include "test/common/span.hpp" | ||
| 16 | #include "test/nextgen/common/random.hpp" | ||
| 17 | #include "test/nextgen/format/format.hpp" | ||
| 18 | |||
| 19 | namespace kai::test { | ||
| 20 | |||
| 21 | /// Multidimensional array with elements being stored in row-major order. | ||
| 22 | /// | ||
| 23 | /// For example: | ||
| 24 | /// A data buffer with the shape of (2, 3), i.e. 2 rows and 3 columns: | ||
| 25 | /// a00 a01 a02 | ||
| 26 | /// a10 a11 a12 | ||
| 27 | /// It is stored in the memory as follows: | ||
| 28 | /// a00 a01 a02 a10 a11 a12 | ||
| 29 | class PlainFormat final : public Format { | ||
| 30 | public: | ||
| 31 | /// Creates a new plain data format. | ||
| 32 | /// | ||
| 33 | /// @param[in] dtype The element data type. | ||
| 34 | 5648 | explicit PlainFormat(DataType dtype) : m_dtype(dtype) { | |
| 35 | 5648 | } | |
| 36 | |||
| 37 | 800 | [[nodiscard]] DataType dtype() const override { | |
| 38 | 800 | return m_dtype; | |
| 39 | } | ||
| 40 | |||
| 41 | [[nodiscard]] size_t compute_offset(Span<const size_t> shape, Span<const size_t> indices) const override; | ||
| 42 | [[nodiscard]] size_t compute_size(Span<const size_t> shape) const override; | ||
| 43 | [[nodiscard]] Buffer generate_random(Span<const size_t> shape, Rng& rng) const override; | ||
| 44 | [[nodiscard]] Buffer pack(Span<const size_t> shape, Span<const Span<const std::byte>> buffers) const override; | ||
| 45 | [[nodiscard]] bool compare( | ||
| 46 | Span<const size_t> shape, Span<const size_t> tile_coords, Span<const size_t> tile_shape, | ||
| 47 | Span<const std::byte> imp_buffer, Span<const std::byte> ref_buffer, MismatchHandler& handler) const override; | ||
| 48 | void print(std::ostream& os, Span<const size_t> shape, Span<const std::byte> data) const override; | ||
| 49 | [[nodiscard]] bool operator==(const Format& other) const override; | ||
| 50 | |||
| 51 | private: | ||
| 52 | DataType m_dtype; | ||
| 53 | }; | ||
| 54 | |||
| 55 | } // namespace kai::test | ||
| 56 |