diff options
Diffstat (limited to 'runtimes/nn/common/include/Utils.h')
-rw-r--r-- | runtimes/nn/common/include/Utils.h | 128 |
1 files changed, 0 insertions, 128 deletions
diff --git a/runtimes/nn/common/include/Utils.h b/runtimes/nn/common/include/Utils.h deleted file mode 100644 index aae4cff90..000000000 --- a/runtimes/nn/common/include/Utils.h +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved - * Copyright (C) 2017 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __NNFW_RT_UTILS_H__ -#define __NNFW_RT_UTILS_H__ - -#include "HalInterfaces.h" -#include "NeuralNetworks.h" -#include "Logging.h" - -#include <vector> - -namespace nnfw { -namespace rt { - -// The number of data types (OperandCode) defined in NeuralNetworks.h. -const int kNumberOfDataTypes = 6; - -// The number of operation types (OperationCode) defined in NeuralNetworks.h. -const int kNumberOfOperationTypes = 30; - -// The number of execution preferences defined in NeuralNetworks.h. -const int kNumberOfPreferences = 3; - -// The number of data types (OperandCode) defined in NeuralNetworksOEM.h. -const int kNumberOfDataTypesOEM = 2; - -// The number of operation types (OperationCode) defined in NeuralNetworksOEM.h. -const int kNumberOfOperationTypesOEM = 1; - -// The lowest number assigned to any OEM Code in NeuralNetworksOEM.h. -const int kOEMCodeBase = 10000; - -// Assert macro, as Android does not generally support assert. -#define nnAssert(v) \ - do { \ - if (!(v)) { \ - LOG(ERROR) << "nnAssert failed at " << __FILE__ << ":" << __LINE__ << " - '" << #v \ - << "'\n"; \ - abort(); \ - } \ - } while (0) -// Returns the amount of space needed to store a value of the specified -// dimensions and type. -uint32_t sizeOfData(OperandType type, const std::vector<uint32_t>& dimensions); - -// Returns the amount of space needed to store a value of the dimensions and -// type of this operand. -inline uint32_t sizeOfData(const Operand& operand) { - return sizeOfData(operand.type, operand.dimensions); -} - -// Returns the name of the operation in ASCII. -const char* getOperationName(OperationType opCode); -// Memory is unmapped. -// Memory is reference counted by hidl_memory instances, and is deallocated -// once there are no more references. -hidl_memory allocateSharedMemory(int64_t size); - -// Returns the number of padding bytes needed to align data of the -// specified length. It aligns object of length: -// 2, 3 on a 2 byte boundary, -// 4+ on a 4 byte boundary. -// We may want to have different alignments for tensors. -// TODO: This is arbitrary, more a proof of concept. We need -// to determine what this should be. -uint32_t alignBytesNeeded(uint32_t index, size_t length); - -inline void setFromIntList(hidl_vec<uint32_t>* vec, uint32_t count, const uint32_t* data) { - vec->resize(count); - for (uint32_t i = 0; i < count; i++) { - (*vec)[i] = data[i]; - } -} - -inline void setFromIntList(std::vector<uint32_t>* vec, uint32_t count, const uint32_t* data) { - vec->resize(count); - for (uint32_t i = 0; i < count; i++) { - (*vec)[i] = data[i]; - } -} - -inline std::string toString(uint32_t obj) { - return std::to_string(obj); -} - -template <typename Type> -std::string toString(const std::vector<Type>& range) { - std::string os = "["; - for (size_t i = 0; i < range.size(); ++i) { - os += (i == 0 ? "" : ", ") + toString(range[i]); - } - return os += "]"; -} - -inline bool validCode(uint32_t codeCount, uint32_t codeCountOEM, uint32_t code) { - return (code < codeCount) || (code >= kOEMCodeBase && (code - kOEMCodeBase) < codeCountOEM); -} - -int validateOperandType(const ANeuralNetworksOperandType& type, const char* tag, bool allowPartial); -int validateOperandList(uint32_t count, const uint32_t* list, uint32_t operandCount, - const char* tag); - -bool validateModel(const Model& model); -bool validateRequest(const Request& request, const Model& model); - -inline size_t getSizeFromInts(int lower, int higher) { - return (uint32_t)(lower) + ((uint64_t)(uint32_t)(higher) << 32); -} - -} // namespace rt -} // namespace nnfw - -#endif // __NNFW_RT_UTILS_H__ |