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