|
| 1 | +/* |
| 2 | + * Copyright (c) 2026 Arm Limited. |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: MIT |
| 5 | + * |
| 6 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | + * of this software and associated documentation files (the "Software"), to |
| 8 | + * deal in the Software without restriction, including without limitation the |
| 9 | + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 10 | + * sell copies of the Software, and to permit persons to whom the Software is |
| 11 | + * furnished to do so, subject to the following conditions: |
| 12 | + * |
| 13 | + * The above copyright notice and this permission notice shall be included in all |
| 14 | + * copies or substantial portions of the Software. |
| 15 | + * |
| 16 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | + * SOFTWARE. |
| 23 | + */ |
| 24 | +#ifndef ACL_ARM_COMPUTE_RUNTIME_NEON_FUNCTIONS_NETOPKV_H |
| 25 | +#define ACL_ARM_COMPUTE_RUNTIME_NEON_FUNCTIONS_NETOPKV_H |
| 26 | + |
| 27 | +/** @file |
| 28 | + * @publicapi |
| 29 | + */ |
| 30 | + |
| 31 | +#include "arm_compute/core/Error.h" |
| 32 | +#include "arm_compute/runtime/IFunction.h" |
| 33 | + |
| 34 | +#include <memory> |
| 35 | + |
| 36 | +namespace arm_compute |
| 37 | +{ |
| 38 | +// Forward declarations |
| 39 | +class ITensor; |
| 40 | +class ITensorInfo; |
| 41 | + |
| 42 | +/** Basic function to run cpu::kernels::CpuTopKVKernel |
| 43 | + * |
| 44 | + */ |
| 45 | +class NETopKV : public IFunction |
| 46 | +{ |
| 47 | +public: |
| 48 | + /** Constructor */ |
| 49 | + NETopKV(); |
| 50 | + /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 51 | + NETopKV(const NETopKV &) = delete; |
| 52 | + /** Default move constructor */ |
| 53 | + NETopKV(NETopKV &&); |
| 54 | + /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 55 | + NETopKV &operator=(const NETopKV &) = delete; |
| 56 | + /** Default move assignment operator */ |
| 57 | + NETopKV &operator=(NETopKV &&); |
| 58 | + /** Destructor */ |
| 59 | + ~NETopKV(); |
| 60 | + /** Set the input and output of the kernel. |
| 61 | + * |
| 62 | + * Valid data layouts: |
| 63 | + * - All |
| 64 | + * |
| 65 | + * Valid data type configurations: |
| 66 | + * |src1 |src2 |dst | |
| 67 | + * |:--------------|:--------------|:--------------| |
| 68 | + * |QASYMM8 |U32 |U8 | |
| 69 | + * |QASYMM8_SIGNED |U32 |U8 | |
| 70 | + * |S32 |U32 |U8 | |
| 71 | + * |F16 |U32 |U8 | |
| 72 | + * |F32 |U32 |U8 | |
| 73 | + * |
| 74 | + * @param[in] predictions A batch_size x classes tensor. Data types supported: F16/F32/QASYMM8/QASYMM8_SIGNED/S32 |
| 75 | + * @param[in] targets A batch_size 1D tensor of class ids. Data types supported: U32 |
| 76 | + * @param[out] output Computed precision at @p k as a bool 1D tensor. Data types supported: U8 |
| 77 | + * @param[in] k Number of top elements to look at for computing precision. |
| 78 | + */ |
| 79 | + void configure(const ITensor *predictions, const ITensor *targets, ITensor *output, const unsigned int k); |
| 80 | + |
| 81 | + /** Static function to check if given info will lead to a valid configuration. |
| 82 | + * |
| 83 | + * Similar to @ref NETopKV::configure() |
| 84 | + * |
| 85 | + * @return a status |
| 86 | + */ |
| 87 | + static Status |
| 88 | + validate(const ITensorInfo *predictions, const ITensorInfo *targets, ITensorInfo *output, const unsigned int k); |
| 89 | + |
| 90 | + // Inherited methods overridden |
| 91 | + void run() override; |
| 92 | + |
| 93 | +private: |
| 94 | + struct Impl; |
| 95 | + std::unique_ptr<Impl> _impl; |
| 96 | +}; |
| 97 | +} // namespace arm_compute |
| 98 | +#endif // ACL_ARM_COMPUTE_RUNTIME_NEON_FUNCTIONS_NETOPKV_H |
0 commit comments