int ModelBuilder::setOperandValueFromMemory(uint32_t index, const Memory* memory, uint32_t offset,
size_t length) {
VLOG(MODEL) << __func__ << " for operand " << index << " offset " << offset << " size " << length;
+ if (badState("setOperandValueFromMemory")) {
+ return ANEURALNETWORKS_BAD_STATE;
+ }
+
if (index >= operandCount()) {
LOG(ERROR) << "ANeuralNetworksModel_setOperandValueFromMemory setting operand " << index
<< " of " << operandCount();
<< " bytes when needing " << neededLength;
return ANEURALNETWORKS_BAD_DATA;
}
+ if (!memory->validateSize(offset, length)) {
+ return ANEURALNETWORKS_BAD_DATA;
+ }
// TODO validate does not exceed length of memory
operand.lifetime = OperandLifeTime::CONSTANT_REFERENCE;
operand.location = {
#include "NeuralNetworksOEM.h"
#include <android/sharedmem.h>
#endif
+#include <cutils/ashmem.h>
#include <gtest/gtest.h>
#include <string>
#include <sys/mman.h>
EXPECT_EQ(ANeuralNetworksModel_setOperandValue(mModel, 0, buffer, sizeof(float)),
ANEURALNETWORKS_BAD_STATE);
}
-#if 0 // TODO-NNRT : Enable if we support 'ASharedMemory_create'
TEST_F(ValidationTestModel, SetOperandValueFromMemory) {
uint32_t dimensions[]{1};
ANeuralNetworksOperandType floatType{
.dimensions = dimensions};
EXPECT_EQ(ANeuralNetworksModel_addOperand(mModel, &floatType), ANEURALNETWORKS_NO_ERROR);
const size_t memorySize = 20;
- int memoryFd = ASharedMemory_create("nnMemory", memorySize);
+ int memoryFd = ashmem_create_region("nnMemory", memorySize);
ASSERT_GT(memoryFd, 0);
ANeuralNetworksMemory* memory;
EXPECT_EQ(ANeuralNetworksMemory_createFromFd(memorySize, PROT_READ | PROT_WRITE,
sizeof(float)),
ANEURALNETWORKS_BAD_STATE);
}
-#endif // TODO-NNRT
#if 0 // TODO-NNRT : Enable if we support OEM OP.
TEST_F(ValidationTestModel, AddOEMOperand) {
ANeuralNetworksOperandType OEMScalarType{
EXPECT_EQ(ANeuralNetworksExecution_setOutput(execution, -1, nullptr, buffer, sizeof(float)),
ANEURALNETWORKS_BAD_DATA);
}
-#if 0 // TODO-NNRT : Enable if we support 'ASharedMemory_create'
TEST_F(ValidationTestExecution, SetInputFromMemory) {
ANeuralNetworksExecution* execution;
EXPECT_EQ(ANeuralNetworksExecution_create(mCompilation, &execution), ANEURALNETWORKS_NO_ERROR);
const size_t memorySize = 20;
- int memoryFd = ASharedMemory_create("nnMemory", memorySize);
+ int memoryFd = ashmem_create_region("nnMemory", memorySize);
ASSERT_GT(memoryFd, 0);
ANeuralNetworksMemory* memory;
EXPECT_EQ(ANeuralNetworksMemory_createFromFd(memorySize, PROT_READ | PROT_WRITE,
ANeuralNetworksExecution* execution;
EXPECT_EQ(ANeuralNetworksExecution_create(mCompilation, &execution), ANEURALNETWORKS_NO_ERROR);
const size_t memorySize = 20;
- int memoryFd = ASharedMemory_create("nnMemory", memorySize);
+ int memoryFd = ashmem_create_region("nnMemory", memorySize);
ASSERT_GT(memoryFd, 0);
ANeuralNetworksMemory* memory;
EXPECT_EQ(ANeuralNetworksMemory_createFromFd(memorySize, PROT_READ | PROT_WRITE,
memory, memorySize - 3, sizeof(float)),
ANEURALNETWORKS_BAD_DATA);
}
-#endif // TODO-NNRT
TEST_F(ValidationTestExecution, StartCompute) {
ANeuralNetworksExecution* execution;
EXPECT_EQ(ANeuralNetworksExecution_create(mCompilation, &execution), ANEURALNETWORKS_NO_ERROR);