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