| 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 | #include <cstddef> |
| 9 | |
| 10 | #include "test/common/buffer.hpp" |
| 11 | #include "test/common/data_type.hpp" |
| 12 | #include "test/common/memory.hpp" |
| 13 | |
| 14 | namespace kai::test { |
| 15 | |
| 16 | struct Padding2D { |
| 17 | size_t left; |
| 18 | size_t right; |
| 19 | size_t top; |
| 20 | size_t bottom; |
| 21 | |
| 22 | struct Hash { |
| 23 | size_t operator()(const Padding2D pad) const { |
| 24 | return // |
| 25 | (std::hash<size_t>{}(pad.left) << 0) ^ // |
| 26 | (std::hash<size_t>{}(pad.right) << 1) ^ // |
| 27 | (std::hash<size_t>{}(pad.top) << 2) ^ // |
| 28 | (std::hash<size_t>{}(pad.bottom) << 3); |
| 29 | } |
| 30 | }; |
| 31 | |
| 32 | private: |
| 33 | friend bool operator==(const Padding2D& lhs, const Padding2D& rhs) { |
| 34 | return // |
| 35 | lhs.left == rhs.left && lhs.right == rhs.right && lhs.top == rhs.top && lhs.bottom == rhs.bottom; |
| 36 | } |
| 37 | |
| 38 | friend std::ostream& operator<<(std::ostream& os, const Padding2D& pad); |
| 39 | }; |
| 40 | |
| 41 | void PrintTo(const Padding2D& pad, std::ostream* os); |
| 42 | |
| 43 | /// Depthwise Convolution function |
| 44 | /// |
| 45 | /// @tparam T Data type. |
| 46 | /// |
| 47 | /// @param[in] batches Batch dimension of feature map. |
| 48 | /// @param[in] in_height height of feature map. |
| 49 | /// @param[in] in_width width of feature map. |
| 50 | /// @param[in] channels Number of channels in feature map. |
| 51 | /// @param[in] filter_height Height dimension in filter. |
| 52 | /// @param[in] filter_width Width of convolution filter. |
| 53 | /// @param[in] feature_map Ptr to start of feature map. |
| 54 | /// @param[in] weights Ptr to start of weights buffer/tensor. |
| 55 | /// @param[in] bias Ptr to start of bias buffer. |
| 56 | /// @param[in] pad Padding object. |
| 57 | /// |
| 58 | /// @return The result data buffer. |
| 59 | template <typename T> |
| 60 | Buffer depthwise_reference( |
| 61 | const size_t batches, const size_t in_height, const size_t in_width, const size_t channels, |
| 62 | const size_t filter_height, const size_t filter_width, const void* feature_map, const void* weights, |
| 63 | const void* bias, const Padding2D& pad); |
| 64 | |
| 65 | } // namespace kai::test |