Memory Domain Runtime: Explicit memory copying.
- Implement ANNMemory_copy.
- Add validation tests.
Bug: 141353602
Bug: 141363565
Test: NNT_static
Change-Id: Id0ec2431cf9cfff650cd8885de4d15abee306a9c
Merged-In: Id0ec2431cf9cfff650cd8885de4d15abee306a9c
(cherry picked from commit 9af11e783aadacf78330a5e6e4e8255f41789c13)
diff --git a/runtime/NeuralNetworks.cpp b/runtime/NeuralNetworks.cpp
index f9d60d0..6b4114e 100644
--- a/runtime/NeuralNetworks.cpp
+++ b/runtime/NeuralNetworks.cpp
@@ -909,10 +909,15 @@
return ANEURALNETWORKS_NO_ERROR;
}
-int ANeuralNetworksMemory_copy(const ANeuralNetworksMemory* /*src*/,
- const ANeuralNetworksMemory* /*dst*/) {
- // TODO(xusongw): Implement.
- return ANEURALNETWORKS_OP_FAILED;
+int ANeuralNetworksMemory_copy(const ANeuralNetworksMemory* src, const ANeuralNetworksMemory* dst) {
+ NNTRACE_RT(NNTRACE_PHASE_EXECUTION, "ANeuralNetworksMemory_copy");
+ if (!src || !dst) {
+ LOG(ERROR) << "ANeuralNetworksMemory_copy passed a nullptr";
+ return ANEURALNETWORKS_UNEXPECTED_NULL;
+ }
+ const Memory* s = reinterpret_cast<const Memory*>(src);
+ const Memory* d = reinterpret_cast<const Memory*>(dst);
+ return Memory::copy(*s, *d);
}
int ANeuralNetworksMemory_createFromFd(size_t size, int prot, int fd, size_t offset,