blob: 3d4ee3ef947395d08d0d02e65af9daee9fd57d0f [file] [log] [blame]
Won Jeon64e4bfe2024-01-18 06:31:55 +00001// Copyright (c) 2024, ARM Limited.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14#include "generate.h"
15#include "generate_utils.h"
16
17#include <algorithm>
18#include <array>
19#include <iterator>
20#include <type_traits>
21#include <vector>
22
23namespace TosaReference
24{
25bool generateFixedData(const GenerateConfig& cfg, void* data, size_t size)
26{
27 // Check we support the operator
28 if (cfg.opType == Op::Op_UNKNOWN)
29 {
30 WARNING("[Generator][FD] Unknown operator.");
31 return false;
32 }
33
34 switch (cfg.dataType)
35 {
36 case DType::DType_SHAPE: {
37 int32_t* outData = reinterpret_cast<int32_t*>(data);
38 std::vector<int32_t> inData = cfg.fixedDataInfo.data;
39 const auto T = TosaReference::numElementsFromShape(cfg.shape);
Jeremy Johnsone4c89eb2024-02-22 09:57:45 +000040 if (T != static_cast<int64_t>(inData.size()))
Won Jeon64e4bfe2024-01-18 06:31:55 +000041 {
42 WARNING("[Generator][FD] Size does not match.");
43 return false;
44 }
45 for (auto t = 0; t < T; t++)
46 {
47 outData[t] = inData[t];
48 }
49 return true;
50 }
51 default:
52 WARNING("[Generator][FD] Unsupported type.");
53 return false;
54 }
55}
56} // namespace TosaReference