blob: 4e13ead7e379e14b04cb0a9c98e4038ea667ef07 [file] [log] [blame]
Mohammed Suhail Munshi7467ba82023-12-05 14:27:31 +00001/*
2 * Copyright (c) 2024 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
25#ifndef ACL_SRC_CORE_HELPERS_LUTMANAGER_H
26#define ACL_SRC_CORE_HELPERS_LUTMANAGER_H
27
28#include "arm_compute/core/CoreTypes.h"
29#include "arm_compute/core/QuantizationInfo.h"
30#include "arm_compute/function_info/ActivationLayerInfo.h"
31
32#include <map>
33#include <memory>
34
35namespace arm_compute
36{
37
38struct LUTInfo
39{
40 ActivationLayerInfo::ActivationFunction act;
41 DataType dt;
42 QuantizationInfo qinfo;
43 // Operators enable use of map with Lutinfo as key
44 friend bool operator<(const LUTInfo &l, const LUTInfo &r)
45 {
46 return (l.act < r.act) || ((l.act == r.act) && (l.dt < r.dt)) ||
47 ((l.act == r.act) && (l.dt == r.dt) && (l.qinfo.scale() < r.qinfo.scale())) ||
48 ((l.act == r.act) && (l.dt == r.dt) && (l.qinfo.scale() == r.qinfo.scale()) &&
49 (l.qinfo.offset() < l.qinfo.offset()));
50 }
51 bool operator==(const LUTInfo &l)
52 {
53 return this->act == l.act && this->dt == l.dt && this->qinfo == l.qinfo;
54 }
55};
56
57/* Class to handle getting look up table */
58class LUTManager
59{
60public:
61 LUTManager() = default;
62
63 static LUTManager &get_instance();
64#ifdef __aarch64__
65 std::shared_ptr<ActivationLayerInfo::LookupTable65536> get_lut_table(LUTInfo info);
66
67private:
68 std::map<LUTInfo, std::weak_ptr<ActivationLayerInfo::LookupTable65536>> map_fp16{};
69#endif // __aarch64__
70};
71
72} // namespace arm_compute
73#endif // ACL_SRC_CORE_HELPERS_LUTMANAGER_H