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_RUNTIME_SERVER_FLAG_H
18 #define ANDROID_PACKAGES_MODULES_NEURALNETWORKS_RUNTIME_SERVER_FLAG_H
19 
20 #include <nnapi/Types.h>
21 #include <stdint.h>
22 
23 #include <functional>
24 #include <string>
25 
26 #include "NeuralNetworks.h"
27 
28 namespace android::nn {
29 
30 // Keep these values consistent with server side configuration in
31 // google3/googledata/experiments/mobile/android_platform/nnapi_native/features/
32 //   feature_level.gcl and telemetry.gcl.
33 constexpr char kExprCategoryName[] = "nnapi_native";
34 constexpr char kCurrentFeatureLevelFlagName[] = "current_feature_level";
35 constexpr char kTelemetryEnableFlagName[] = "telemetry_enable";
36 constexpr int64_t kDefaultFeatureLevelNum = 8;
37 // When this value is updated, update kMinFeatureLevelCode in runtime/test/TestUpdatability.cpp with
38 // the corresponding ANEURALNETWORKS_FEATURE_LEVEL_* version.
39 constexpr int64_t kMinFeatureLevelNum = 8;
40 constexpr int64_t kMaxFeatureLevelNum = 8;
41 constexpr bool kDefaultTelemetryEnableValue = false;
42 
43 #ifndef NN_COMPATIBILITY_LIBRARY_BUILD
44 #ifndef NN_EXPERIMENTAL_FEATURE
45 // Function to get server feature level flag. Note that this function should NOT be used directly.
46 // Instead, clients are expected to use DeviceManager::getRuntimeVersion or
47 // DeviceManager::getRuntimeFeatureLevel in runtime/Manager.h.
48 int64_t getServerFeatureLevelFlag();
49 
50 // Function to get server telemetry enable flag. Note that this function should NOT be used
51 // directly. Instead, clients are expected to use DeviceManager::isPlatformTelemetryEnabled in
52 // runtime/Manager.h.
53 bool getServerTelemetryEnableFlag();
54 #endif  // NN_EXPERIMENTAL_FEATURE
55 
56 // Testing-only.
57 using GetServerConfigurableFlagFunc =
58         std::function<std::string(const std::string&, const std::string&, const std::string&)>;
59 int64_t getServerFeatureLevelFlag(GetServerConfigurableFlagFunc serverFunc);
60 bool getServerTelemetryEnableFlag(GetServerConfigurableFlagFunc serverFunc);
61 #endif  // NN_COMPATIBILITY_LIBRARY_BUILD
62 
63 // Get the runtime version corresponding to the server feature flag value.
64 Version serverFeatureLevelToVersion(int64_t serverFeatureLevel);
65 
66 }  // namespace android::nn
67 
68 #endif  // ANDROID_PACKAGES_MODULES_NEURALNETWORKS_RUNTIME_SERVER_FLAG_H
69