diff --git a/neuralnetworks/aidl/vts/functional/GeneratedTestHarness.cpp b/neuralnetworks/aidl/vts/functional/GeneratedTestHarness.cpp index 4eb704b6e0..7a042ed37e 100644 --- a/neuralnetworks/aidl/vts/functional/GeneratedTestHarness.cpp +++ b/neuralnetworks/aidl/vts/functional/GeneratedTestHarness.cpp @@ -299,9 +299,11 @@ static bool isOutputSizeGreaterThanOne(const TestModel& testModel, uint32_t inde } static void makeOutputInsufficientSize(uint32_t outputIndex, Request* request) { - auto& length = request->outputs[outputIndex].location.length; - ASSERT_GT(length, 1u); - length -= 1u; + auto& loc = request->outputs[outputIndex].location; + ASSERT_GT(loc.length, 1u); + loc.length -= 1u; + // Test that the padding is not used for output data. + loc.padding += 1u; } static void makeOutputDimensionsUnspecified(Model* model) { @@ -336,6 +338,12 @@ class ExecutionContext { std::vector> mBuffers; }; +// Returns the number of bytes needed to round up "size" to the nearest multiple of "multiple". +static uint32_t roundUpBytesNeeded(uint32_t size, uint32_t multiple) { + CHECK(multiple != 0); + return ((size + multiple - 1) / multiple) * multiple - size; +} + std::optional ExecutionContext::createRequest(const TestModel& testModel, MemoryType memoryType) { // Memory pools are organized as: @@ -370,10 +378,13 @@ std::optional ExecutionContext::createRequest(const TestModel& testMode } // Reserve shared memory for input. + inputSize += roundUpBytesNeeded(inputSize, nn::kDefaultRequestMemoryAlignment); + const auto padding = roundUpBytesNeeded(op.data.size(), nn::kDefaultRequestMemoryPadding); DataLocation loc = {.poolIndex = kInputPoolIndex, .offset = static_cast(inputSize), - .length = static_cast(op.data.size())}; - inputSize += op.data.alignedSize(); + .length = static_cast(op.data.size()), + .padding = static_cast(padding)}; + inputSize += (op.data.size() + padding); inputs[i] = {.hasNoValue = false, .location = loc, .dimensions = {}}; } @@ -404,10 +415,13 @@ std::optional ExecutionContext::createRequest(const TestModel& testMode size_t bufferSize = std::max(op.data.size(), 1); // Reserve shared memory for output. + outputSize += roundUpBytesNeeded(outputSize, nn::kDefaultRequestMemoryAlignment); + const auto padding = roundUpBytesNeeded(bufferSize, nn::kDefaultRequestMemoryPadding); DataLocation loc = {.poolIndex = kOutputPoolIndex, .offset = static_cast(outputSize), - .length = static_cast(bufferSize)}; - outputSize += op.data.size() == 0 ? TestBuffer::kAlignment : op.data.alignedSize(); + .length = static_cast(bufferSize), + .padding = static_cast(padding)}; + outputSize += (bufferSize + padding); outputs[i] = {.hasNoValue = false, .location = loc, .dimensions = {}}; }