• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2021 The TensorFlow Authors. All Rights Reserved.
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 ==============================================================================*/
15 
16 #ifndef TENSORFLOW_LITE_NNAPI_SL_INCLUDE_SUPPORT_LIBRARY_H_
17 #define TENSORFLOW_LITE_NNAPI_SL_INCLUDE_SUPPORT_LIBRARY_H_
18 
19 #include <memory>
20 #include <string>
21 
22 // Changed when importing from AOSP
23 #include "tensorflow/lite/nnapi/NeuralNetworksTypes.h"
24 #include "tensorflow/lite/nnapi/sl/public/NeuralNetworksSupportLibraryImpl.h"
25 
26 namespace tflite {
27 namespace nnapi {
28 
29 /**
30  * Helper struct, derived from the latest NnApiSLDriverImpl.
31  *
32  * Owns the .so handle, and will close it in destructor.
33  * Sets proper implStructFeatureLevel in constructor.
34  *
35  * It's derived from the latest NnApiSLDriverImplFL* struct,
36  * so it contains all possible functionality.
37  *
38  * When a new NnApiSLDriverImpl is introduced, this class
39  * has to switch base class to it and provide constructors for
40  * all existing NnApiSLDriverImplFL* structs.
41  *
42  * There's expectation that for M>N, NnApiSLDriverImplFL(M) is
43  * a strict superset of NnApiSLDriverImplFL(N), and *NnApiSLDriverImplFL(M) can
44  * be reinterpret_cast to *NnApiSLDriverImplFL(N) safely.
45  *
46  * The base->implFeatureLevel is set to the actual Feature Level
47  * implemented by the SLDriverImpl,
48  */
49 struct NnApiSupportLibrary : NnApiSLDriverImplFL5 {
50   NnApiSupportLibrary(const NnApiSLDriverImplFL5& impl, void* libHandle);
51   ~NnApiSupportLibrary();
52 
53   void* libHandle = nullptr;
54 };
55 
56 /**
57  * Loads the NNAPI support library.
58  * The NnApiSupportLibrary structure is filled with all the pointers. If one
59  * function doesn't exist, a null pointer is stored.
60  */
61 std::unique_ptr<const NnApiSupportLibrary> loadNnApiSupportLibrary(
62     const std::string& libName);
63 std::unique_ptr<const NnApiSupportLibrary> loadNnApiSupportLibrary(
64     void* libHandle);
65 
66 }  // namespace nnapi
67 }  // namespace tflite
68 
69 #endif  // TENSORFLOW_LITE_NNAPI_SL_INCLUDE_SUPPORT_LIBRARY_H_
70