summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSlava Shklyaev <slavash@google.com>2019-11-04 11:24:03 +0000
committerSlava Shklyaev <slavash@google.com>2019-11-08 13:19:13 +0000
commitfa3390a948fb2b5f627f13460601c48038ca8ad1 (patch)
tree731b92575984385b938f213d411ad5a134d50c60
parentb9869c6834fde4173f4b3f5c74210ce53c529200 (diff)
downloadml-fa3390a948fb2b5f627f13460601c48038ca8ad1.tar.gz
Add convenience helpers to TestNeuralNetworksWrapper
Before: ASSERT_EQ(execution.setInput(0, &matrix, sizeof(matrix)), Result::NO_ERROR); After: ASSERT_EQ(execution.setInput(0, &matrix), Result::NO_ERROR); Bug: 139181916 Test: NNT_static Change-Id: I2fc1bac806dbc97e3728c572e687a6d3c92bc4b0 Merged-In: I2fc1bac806dbc97e3728c572e687a6d3c92bc4b0 (cherry picked from commit a722a8bac80e4a07112d7b403920c74b007d8384)
-rw-r--r--nn/runtime/test/TestNeuralNetworksWrapper.h23
1 files changed, 20 insertions, 3 deletions
diff --git a/nn/runtime/test/TestNeuralNetworksWrapper.h b/nn/runtime/test/TestNeuralNetworksWrapper.h
index 6f362e7da..05e68ace2 100644
--- a/nn/runtime/test/TestNeuralNetworksWrapper.h
+++ b/nn/runtime/test/TestNeuralNetworksWrapper.h
@@ -151,13 +151,11 @@ class Model {
template <typename T>
uint32_t addConstantOperand(const OperandType* type, const T& value) {
- static_assert(!std::is_pointer_v<T>,
- "Pointer value type not supported because sizeof(T) is wrong");
static_assert(sizeof(T) <= ANEURALNETWORKS_MAX_SIZE_OF_IMMEDIATELY_COPIED_VALUES,
"Values larger than ANEURALNETWORKS_MAX_SIZE_OF_IMMEDIATELY_COPIED_VALUES "
"not supported");
uint32_t index = addOperand(type);
- setOperandValue(index, &value, sizeof(T));
+ setOperandValue(index, &value);
return index;
}
@@ -168,6 +166,12 @@ class Model {
}
}
+ template <typename T>
+ void setOperandValue(uint32_t index, const T* value) {
+ static_assert(!std::is_pointer<T>(), "No operand may have a pointer as its value");
+ return setOperandValue(index, value, sizeof(T));
+ }
+
void setOperandValueFromMemory(uint32_t index, const Memory* memory, uint32_t offset,
size_t length) {
if (ANeuralNetworksModel_setOperandValueFromMemory(mModel, index, memory->get(), offset,
@@ -304,6 +308,13 @@ class Execution {
ANeuralNetworksExecution_setInput(mExecution, index, type, buffer, length));
}
+ template <typename T>
+ Result setInput(uint32_t index, const T* value,
+ const ANeuralNetworksOperandType* type = nullptr) {
+ static_assert(!std::is_pointer<T>(), "No operand may have a pointer as its value");
+ return setInput(index, value, sizeof(T), type);
+ }
+
Result setInputFromMemory(uint32_t index, const Memory* memory, uint32_t offset,
uint32_t length, const ANeuralNetworksOperandType* type = nullptr) {
return static_cast<Result>(ANeuralNetworksExecution_setInputFromMemory(
@@ -316,6 +327,12 @@ class Execution {
ANeuralNetworksExecution_setOutput(mExecution, index, type, buffer, length));
}
+ template <typename T>
+ Result setOutput(uint32_t index, T* value, const ANeuralNetworksOperandType* type = nullptr) {
+ static_assert(!std::is_pointer<T>(), "No operand may have a pointer as its value");
+ return setOutput(index, value, sizeof(T), type);
+ }
+
Result setOutputFromMemory(uint32_t index, const Memory* memory, uint32_t offset,
uint32_t length, const ANeuralNetworksOperandType* type = nullptr) {
return static_cast<Result>(ANeuralNetworksExecution_setOutputFromMemory(