Xusong Wang | 52d2df8 | 2019-07-02 13:53:25 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 The Android Open Source Project |
| 3 | * |
| 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 |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 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. |
| 15 | */ |
| 16 | |
| 17 | #ifndef ANDROID_FRAMEWORKS_ML_NN_RUNTIME_MODEL_ARGUMENT_INFO_H |
| 18 | #define ANDROID_FRAMEWORKS_ML_NN_RUNTIME_MODEL_ARGUMENT_INFO_H |
| 19 | |
| 20 | #include <vector> |
| 21 | |
| 22 | #include "HalInterfaces.h" |
| 23 | #include "NeuralNetworks.h" |
| 24 | |
| 25 | namespace android { |
| 26 | namespace nn { |
| 27 | |
| 28 | // TODO move length out of DataLocation |
| 29 | struct ModelArgumentInfo { |
| 30 | // Whether the argument was specified as being in a Memory, as a pointer, |
| 31 | // has no value, or has not been specified. |
| 32 | // If POINTER then: |
| 33 | // locationAndLength.length is valid. |
| 34 | // dimensions is valid. |
| 35 | // buffer is valid |
| 36 | // If MEMORY then: |
| 37 | // locationAndLength.{poolIndex, offset, length} is valid. |
| 38 | // dimensions is valid. |
| 39 | enum { POINTER, MEMORY, HAS_NO_VALUE, UNSPECIFIED } state = UNSPECIFIED; |
| 40 | hal::DataLocation locationAndLength; |
| 41 | std::vector<uint32_t> dimensions; |
| 42 | void* buffer; |
| 43 | bool isSufficient = true; |
| 44 | |
| 45 | int setFromPointer(const hal::Operand& operand, const ANeuralNetworksOperandType* type, |
| 46 | void* buffer, uint32_t length); |
| 47 | int setFromMemory(const hal::Operand& operand, const ANeuralNetworksOperandType* type, |
| 48 | uint32_t poolIndex, uint32_t offset, uint32_t length); |
| 49 | int setFromTemporaryMemory(const hal::Operand& operand, uint32_t poolIndex, uint32_t offset, |
| 50 | uint32_t length); |
| 51 | int updateDimensionInfo(const hal::Operand& operand, const ANeuralNetworksOperandType* newType); |
| 52 | }; |
| 53 | |
Michael Butler | 4753567 | 2019-11-08 17:06:54 -0800 | [diff] [blame^] | 54 | // Convert ModelArgumentInfo to HIDL RequestArgument. For pointer arguments, use the location |
| 55 | // information in ptrArgsLocations. |
| 56 | hal::hidl_vec<hal::RequestArgument> createRequestArguments( |
| 57 | const std::vector<ModelArgumentInfo>& argumentInfos, |
| 58 | const std::vector<hal::DataLocation>& ptrArgsLocations); |
| 59 | |
Xusong Wang | 52d2df8 | 2019-07-02 13:53:25 -0700 | [diff] [blame] | 60 | } // namespace nn |
| 61 | } // namespace android |
| 62 | |
Michael Butler | 4753567 | 2019-11-08 17:06:54 -0800 | [diff] [blame^] | 63 | #endif // ANDROID_FRAMEWORKS_ML_NN_RUNTIME_MODEL_ARGUMENT_INFO_H |