summaryrefslogtreecommitdiff
path: root/nn/runtime/test/TestNeuralNetworksWrapper.h
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 10:49:07 +0000
commita722a8bac80e4a07112d7b403920c74b007d8384 (patch)
tree678c3b77a6a0026fe9da0ec43de6527822a49f33 /nn/runtime/test/TestNeuralNetworksWrapper.h
parent586e4b9f3e2946b50c0773205c18ace1c56430d2 (diff)
downloadml-a722a8bac80e4a07112d7b403920c74b007d8384.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
Diffstat (limited to 'nn/runtime/test/TestNeuralNetworksWrapper.h')
-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(