* limitations under the License.
*/
-#define LOG_TAG "Utils"
-
#include "Utils.h"
#include "NeuralNetworks.h"
-#if 0 // REF-ANN
-#include <android-base/logging.h>
-#include <android-base/properties.h>
-#include <android-base/strings.h>
-#include <sys/system_properties.h>
-#include <unordered_map>
-using ::android::hidl::allocator::V1_0::IAllocator;
-#endif // REF-ANN
namespace android {
namespace nn {
-#if 0 // REF-ANN
-const char kVLogPropKey[] = "debug.nn.vlog";
-int vLogMask = ~0;
-
-// Split the space separated list of tags from verbose log setting and build the
-// logging mask from it. note that '1' and 'all' are special cases to enable all
-// verbose logging.
-//
-// NN API verbose logging setting comes from system property debug.nn.vlog.
-// Example:
-// setprop debug.nn.vlog 1 : enable all logging tags.
-// setprop debug.nn.vlog "model compilation" : only enable logging for MODEL and
-// COMPILATION tags.
-void initVLogMask() {
- vLogMask = 0;
- const std::string vLogSetting = android::base::GetProperty(kVLogPropKey, "");
- if (vLogSetting.empty()) {
- return;
- }
-
- std::unordered_map<std::string, int> vLogFlags = {
- {"1", -1},
- {"all", -1},
- {"model", MODEL},
- {"compilation", COMPILATION},
- {"execution", EXECUTION},
- {"cpuexe", CPUEXE},
- {"manager", MANAGER},
- {"driver", DRIVER}};
-
- std::vector<std::string> elements = android::base::Split(vLogSetting, " ");
- for (const auto& elem : elements) {
- const auto& flag = vLogFlags.find(elem);
- if (flag == vLogFlags.end()) {
- LOG(ERROR) << "Unknown trace flag: " << elem;
- continue;
- }
- if (flag->second == -1) {
- // -1 is used for the special values "1" and "all" that enable all
- // tracing.
- vLogMask = ~0;
- return;
- } else {
- vLogMask |= 1 << flag->second;
- }
- }
-}
-#endif // REF-ANN
#define COUNT(X) (sizeof(X) / sizeof(X[0]))
const char* kTypeNames[kNumberOfDataTypes] = {
uint32_t extra = (~(index - 1)) & pattern;
return extra;
}
-#if 0 // REF-ANN
-void logModelToInfo(const Model& model) {
- LOG(INFO) << "Model start";
- LOG(INFO) << "operands" << toString(model.operands);
- LOG(INFO) << "operations" << toString(model.operations);
- LOG(INFO) << "inputIndexes" << toString(model.inputIndexes);
- LOG(INFO) << "outputIndexes" << toString(model.outputIndexes);
- LOG(INFO) << "operandValues size" << model.operandValues.size();
- LOG(INFO) << "pools" << toString(model.pools);
-}
-#endif // REF-ANN
+
// Validates the type. The used dimensions can be underspecified.
int validateOperandType(const ANeuralNetworksOperandType& type, const char* tag,
bool allowPartial) {
}
return ANEURALNETWORKS_NO_ERROR;
}
-#if 0 // REF-ANN
+
static bool validOperandIndexes(const hidl_vec<uint32_t> indexes, size_t operandCount) {
for (uint32_t i : indexes) {
if (i >= operandCount) {
for (auto& operand : operands) {
if (!validCode(kNumberOfDataTypes, kNumberOfDataTypesOEM,
static_cast<uint32_t>(operand.type))) {
- LOG(ERROR) << "Invalid operand type " << toString(operand.type);
+ LOG(ERROR) << "Invalid operand type ";
return false;
}
/* TODO validate dim with type
for (auto& op : operations) {
if (!validCode(kNumberOfOperationTypes, kNumberOfOperationTypesOEM,
static_cast<uint32_t>(op.type))) {
- LOG(ERROR) << "Invalid operation type " << toString(op.type);
+ LOG(ERROR) << "Invalid operation type ";
return false;
}
if (!validOperandIndexes(op.inputs, operandCount) ||
"output"));
}
-#ifdef NN_DEBUGGABLE
-uint32_t getProp(const char* str, uint32_t defaultValue) {
- const std::string propStr = android::base::GetProperty(str, "");
- if (propStr.size() > 0) {
- return std::stoi(propStr);
- } else {
- return defaultValue;
- }
-}
-#endif // NN_DEBUGGABLE
-#endif // REF-ANN
-
} // namespace nn
} // namespace android
// The lowest number assigned to any OEM Code in NeuralNetworksOEM.h.
const int kOEMCodeBase = 10000;
-#if 0 // REF-ANN
-/* IMPORTANT: if you change the following list, don't
- * forget to update the corresponding 'tags' table in
- * the initVlogMask() function implemented in Utils.cpp.
- */
-enum VLogFlags {
- MODEL = 0,
- COMPILATION,
- EXECUTION,
- CPUEXE,
- MANAGER,
- DRIVER
-};
-
-#define VLOG_IS_ON(TAG) \
- ((vLogMask & (1 << (TAG))) != 0)
-
-#define VLOG(TAG) \
- if (LIKELY(!VLOG_IS_ON(TAG))) \
- ; \
- else \
- LOG(INFO)
-
-extern int vLogMask;
-void initVLogMask();
-#endif // REF-ANN
// Assert macro, as Android does not generally support assert.
#define nnAssert(v) \
do { \
// TODO: This is arbitrary, more a proof of concept. We need
// to determine what this should be.
uint32_t alignBytesNeeded(uint32_t index, size_t length);
-#if 0 // REF-ANN
-// Does a detailed LOG(INFO) of the model
-void logModelToInfo(const Model& model);
-#endif // REF-ANN
+
inline void setFromIntList(hidl_vec<uint32_t>* vec, uint32_t count, const uint32_t* data) {
vec->resize(count);
for (uint32_t i = 0; i < count; i++) {
(*vec)[i] = data[i];
}
}
-#if 0 // REF-ANN
+
inline std::string toString(uint32_t obj) {
return std::to_string(obj);
}
}
return os += "]";
}
-#endif // REF-ANN
+
inline bool validCode(uint32_t codeCount, uint32_t codeCountOEM, uint32_t code) {
return (code < codeCount) || (code >= kOEMCodeBase && (code - kOEMCodeBase) < codeCountOEM);
}
int validateOperandType(const ANeuralNetworksOperandType& type, const char* tag, bool allowPartial);
int validateOperandList(uint32_t count, const uint32_t* list, uint32_t operandCount,
const char* tag);
-#if 0 // REF-ANN
+
bool validateModel(const Model& model);
bool validateRequest(const Request& request, const Model& model);
-#endif // REF-ANN
+
inline size_t getSizeFromInts(int lower, int higher) {
return (uint32_t)(lower) + ((uint64_t)(uint32_t)(higher) << 32);
}
-#if 0 // REF-ANN
-#ifdef NN_DEBUGGABLE
-uint32_t getProp(const char* str, uint32_t defaultValue = 0);
-#endif // NN_DEBUGGABLE
-
-#endif // REF-ANN
} // namespace nn
} // namespace android