2 * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "backend/cpu_common/ConstantInitializerBase.h"
30 void ConstantInitializerBase::registerCopyInitializer(const ir::OperandIndex &index,
31 const ir::Operand &obj)
34 // TODO Add to check if tensor has been allocated
35 if (!obj.isConstant())
38 const auto type = obj.typeInfo().type();
43 case DataType::FLOAT32:
44 _init_map[index] = copyInit<float>;
47 _init_map[index] = copyInit<int32_t>;
49 case DataType::UINT32:
50 _init_map[index] = copyInit<uint32_t>;
53 case DataType::QUANT_UINT8_ASYMM:
54 _init_map[index] = copyInit<uint8_t>;
56 case DataType::QUANT_INT8_SYMM:
57 case DataType::QUANT_INT8_ASYMM:
58 _init_map[index] = copyInit<int8_t>;
60 case DataType::FLOAT16:
61 _init_map[index] = copyInit<float16>;
64 _init_map[index] = copyInit<int64_t>;
67 throw std::runtime_error("Not supported, yet");
72 void ConstantInitializerBase::registerPermuteInitializer(const ir::OperandIndex &index,
73 const ir::Operand &obj)
76 // TODO Add to check if tensor has been allocated
77 if (!obj.isConstant())
80 const auto type = obj.typeInfo().type();
82 using namespace std::placeholders;
86 case DataType::FLOAT32:
87 _init_map[index] = std::bind(permuteInit<float>, _1, _2, _current_layout);
90 _init_map[index] = std::bind(permuteInit<int32_t>, _1, _2, _current_layout);
92 case DataType::UINT32:
93 _init_map[index] = std::bind(permuteInit<uint32_t>, _1, _2, _current_layout);
96 case DataType::QUANT_UINT8_ASYMM:
97 _init_map[index] = std::bind(permuteInit<uint8_t>, _1, _2, _current_layout);
99 case DataType::QUANT_INT8_SYMM:
100 case DataType::QUANT_INT8_ASYMM:
101 _init_map[index] = std::bind(permuteInit<int8_t>, _1, _2, _current_layout);
103 case DataType::FLOAT16:
104 _init_map[index] = std::bind(permuteInit<float16>, _1, _2, _current_layout);
106 case DataType::INT64:
107 _init_map[index] = std::bind(permuteInit<int64_t>, _1, _2, _current_layout);
110 throw std::runtime_error("Not supported, yet");
115 } // namespace cpu_common
116 } // namespace backend