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_PACKAGES_MODULES_NEURALNETWORKS_RUNTIME_NEURAL_NETWORKS_EXTENSIONS_H 18 #define ANDROID_PACKAGES_MODULES_NEURALNETWORKS_RUNTIME_NEURAL_NETWORKS_EXTENSIONS_H 19 20 #include "NeuralNetworks.h" 21 22 /****************************************************************** 23 * 24 * IMPORTANT NOTICE: 25 * 26 * This file is not intended for use by general developers -- only 27 * by OEM applications. 28 * 29 * Extensions source AND binary code relies on the definitions 30 * here to be FROZEN ON ALL UPCOMING PLATFORM RELEASES. 31 * 32 * - DO NOT MODIFY ENUMS (EXCEPT IF YOU ADD NEW 32-BIT VALUES) 33 * - DO NOT MODIFY CONSTANTS OR FUNCTIONAL MACROS 34 * - DO NOT CHANGE THE SIGNATURE OF FUNCTIONS IN ANY WAY 35 * - DO NOT CHANGE THE LAYOUT OR SIZE OF STRUCTURES 36 */ 37 38 __BEGIN_DECLS 39 40 /** 41 * Queries whether an extension is supported by the driver implementation of the specified device. 42 * 43 * @param device The representation of the specified device. 44 * @param extension The extension name. 45 * @param isExtensionSupported The boolean value indicating whether the extension is supported. 46 * 47 * @return ANEURALNETWORKS_NO_ERROR if successful. 48 * 49 * Available since API level 29. 50 */ 51 int ANeuralNetworksDevice_getExtensionSupport(const ANeuralNetworksDevice* device, 52 const char* extensionName, bool* isExtensionSupported) 53 __INTRODUCED_IN(29); 54 55 /** 56 * Creates an operand type from an extension name and an extension operand code. 57 * 58 * See {@link ANeuralNetworksModel} for information on multithreaded usage. 59 * 60 * Available since API level 29. 61 * 62 * @param model The model to contain the operand. 63 * @param extensionName The extension name. 64 * @param operandCodeWithinExtension The extension operand code. 65 * @param type The operand type. 66 * 67 * @return ANEURALNETWORKS_NO_ERROR if successful. 68 */ 69 int ANeuralNetworksModel_getExtensionOperandType(ANeuralNetworksModel* model, 70 const char* extensionName, 71 uint16_t operandCodeWithinExtension, int32_t* type) 72 __INTRODUCED_IN(29); 73 74 /** 75 * Creates an operation type from an extension name and an extension operation code. 76 * 77 * See {@link ANeuralNetworksModel} for information on multithreaded usage. 78 * 79 * Available since API level 29. 80 * 81 * @param model The model to contain the operation. 82 * @param extensionName The extension name. 83 * @param operationCodeWithinExtension The extension operation code. 84 * @param type The operation type. 85 * 86 * @return ANEURALNETWORKS_NO_ERROR if successful. 87 */ 88 int ANeuralNetworksModel_getExtensionOperationType(ANeuralNetworksModel* model, 89 const char* extensionName, 90 uint16_t operationCodeWithinExtension, 91 ANeuralNetworksOperationType* type) 92 __INTRODUCED_IN(29); 93 94 /** 95 * Sets extension operand parameters. 96 * 97 * Available since API level 29. 98 * 99 * @param model The model to be modified. 100 * @param index The index of the model operand we're setting. 101 * @param data A pointer to the extension operand data. 102 * The data does not have to outlive the call to this function. 103 * @param length The size in bytes of the data value. 104 * 105 * @return ANEURALNETWORKS_NO_ERROR if successful. 106 */ 107 int ANeuralNetworksModel_setOperandExtensionData(ANeuralNetworksModel* model, int32_t index, 108 const void* data, size_t length) 109 __INTRODUCED_IN(29); 110 111 /** 112 * Add additional vendor-specific metadata to the compilation object. 113 * 114 * The metadata is intended to provide additional hints to help the driver compile the model. 115 * 116 * The {@link ANeuralNetworksCompilation} must have been created with 117 * {@link ANeuralNetworksCompilation_createForDevices} with numDevices = 1, 118 * otherwise this function will fail with ANEURALNETWORKS_BAD_DATA. 119 * 120 * The driver must validate the data and ignore invalid attribute data. It is up to the driver to 121 * decide whether to respect the provided attribute or not. 122 * 123 * Available since NNAPI Feature Level 8. 124 * 125 * @param compilation The compilation object to be modified. 126 * @param extensionName The extension name. 127 * @param attributeCodeWithinExtension The integer code defined within the extension. 128 * @param data A pointer to the extension attribute data. 129 *. The data does not have to outlive the call to this function. 130 * @param length The size in bytes of the data value. 131 * 132 * @return ANEURALNETWORKS_NO_ERROR if successful. 133 * ANEURALNETWORKS_BAD_STATE if compilation has started. 134 * ANEURALNETWORKS_UNEXPECTED_NULL if compilation or extensionName is NULL, or data is NULL 135 * but length is non-zero. 136 * ANEURALNETWORKS_BAD_DATA if the compilation is not created with a single device, or 137 * the same attribute is added more than once. 138 */ 139 int ANeuralNetworksCompilation_addExtensionAttribute(ANeuralNetworksCompilation* compilation, 140 const char* extensionName, 141 uint16_t attributeCodeWithinExtension, 142 const void* data, size_t length); 143 144 /** 145 * Add additional vendor-specific metadata to the execution object. 146 * 147 * The metadata is intended to provide additional hints to help the driver plan the execution. 148 * 149 * The {@link ANeuralNetworksExecution} must have been created from an 150 * {@link ANeuralNetworksCompilation} which in turn was created from 151 * {@link ANeuralNetworksCompilation_createForDevices} with numDevices = 1, 152 * otherwise this function will fail with ANEURALNETWORKS_BAD_DATA. 153 * 154 * The driver must validate the data and ignore invalid attribute data. It is up to the driver to 155 * decide whether to respect the provided attribute or not. 156 * 157 * Available since NNAPI Feature Level 8. 158 * 159 * @param execution The execution object to be modified. 160 * @param extensionName The extension name. 161 * @param attributeCodeWithinExtension The integer code defined within the extension. 162 * @param data A pointer to the extension attribute data. 163 * The data does not have to outlive the call to this function. 164 * @param length The size in bytes of the data value. 165 * 166 * @return ANEURALNETWORKS_NO_ERROR if successful. 167 * ANEURALNETWORKS_BAD_STATE if execution has started. 168 * ANEURALNETWORKS_UNEXPECTED_NULL if compilation or extensionName is NULL, or data is NULL 169 * but length is non-zero. 170 * ANEURALNETWORKS_BAD_DATA if the compilation is not created with a single device, or 171 * the same attribute is added more than once. 172 */ 173 int ANeuralNetworksExecution_addExtensionAttribute(ANeuralNetworksExecution* execution, 174 const char* extensionName, 175 uint16_t attributeCodeWithinExtension, 176 const void* data, size_t length); 177 178 __END_DECLS 179 180 #endif // ANDROID_PACKAGES_MODULES_NEURALNETWORKS_RUNTIME_NEURAL_NETWORKS_EXTENSIONS_H 181