blob: ea95049c9e8914e230d72c296a7ea8c036445716 [file] [log] [blame]
Gunes Bayir806b8e82023-08-23 23:28:31 +01001/*
2 * Copyright (c) 2023 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 CKW_INCLUDE_CKW_TYPES_CONSTANTDATA_H
26#define CKW_INCLUDE_CKW_TYPES_CONSTANTDATA_H
27
28#include "ckw/Error.h"
29#include "ckw/types/DataType.h"
30
31#include <algorithm>
32#include <cstdint>
33#include <initializer_list>
34#include <iomanip>
35#include <iterator>
36#include <sstream>
37#include <string>
38#include <type_traits>
39#include <vector>
40
41namespace ckw
42{
43// Forward Declarations
44class KernelWriter;
45
46class ConstantData
47{
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010048 using String = std::string;
Gunes Bayir806b8e82023-08-23 23:28:31 +010049 using StringVector = std::vector<String>;
50
51public:
52 /** Templated constructor */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010053 template <typename T>
Gunes Bayir806b8e82023-08-23 23:28:31 +010054 ConstantData(std::initializer_list<std::initializer_list<T>> values, DataType data_type);
55
Gunes Bayir2b9fa592024-01-17 16:07:03 +000056 /** Templated constructor */
57 template <typename T>
58 ConstantData(const std::vector<std::vector<T>> &values, DataType data_type);
59
Gunes Bayir806b8e82023-08-23 23:28:31 +010060private:
61 /** Validate the given data type and the template type
62 *
63 * @param[in] data_type data type
64 *
65 * @return true if user provided data type and the template type are conformant
66 */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010067 template <typename T>
Gunes Bayir806b8e82023-08-23 23:28:31 +010068 bool validate(DataType data_type);
69
70 /** Get the constant data as a 2d vector of string values
71 *
72 * @return a 2d vector of strings that has the string-converted values
73 */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010074 const std::vector<StringVector> &values() const;
Gunes Bayir806b8e82023-08-23 23:28:31 +010075
76 /** Get the underlying data type of the constant values
77 *
78 * @return a @ref ckw::DataType object that represents the underlying data type
79 */
80 DataType data_type() const;
81
82 // Friends
83 friend class KernelWriter;
84
85private:
86 // Data members
87 std::vector<StringVector> _values{};
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010088 DataType _data_type{};
Gunes Bayir806b8e82023-08-23 23:28:31 +010089};
90
91} // namespace ckw
92
93#endif // CKW_INCLUDE_CKW_TYPES_CONSTANTDATA_H