Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6b9d882a authored by Xusong Wang's avatar Xusong Wang Committed by Automerger Merge Worker
Browse files

Merge "Test padded request memories in VTS generated tests." am: dfefe265 am: e0469f86

Original change: https://android-review.googlesource.com/c/platform/hardware/interfaces/+/1645926

Change-Id: If75739c68def2cca2b23e8d2b0301dbf962a2ef5
parents 73bf7229 e0469f86
Loading
Loading
Loading
Loading
+21 −7
Original line number Diff line number Diff line
@@ -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<std::shared_ptr<IBuffer>> 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<Request> ExecutionContext::createRequest(const TestModel& testModel,
                                                       MemoryType memoryType) {
    // Memory pools are organized as:
@@ -370,10 +378,13 @@ std::optional<Request> 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<int64_t>(inputSize),
                            .length = static_cast<int64_t>(op.data.size())};
        inputSize += op.data.alignedSize();
                            .length = static_cast<int64_t>(op.data.size()),
                            .padding = static_cast<int64_t>(padding)};
        inputSize += (op.data.size() + padding);
        inputs[i] = {.hasNoValue = false, .location = loc, .dimensions = {}};
    }

@@ -404,10 +415,13 @@ std::optional<Request> ExecutionContext::createRequest(const TestModel& testMode
        size_t bufferSize = std::max<size_t>(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<int64_t>(outputSize),
                            .length = static_cast<int64_t>(bufferSize)};
        outputSize += op.data.size() == 0 ? TestBuffer::kAlignment : op.data.alignedSize();
                            .length = static_cast<int64_t>(bufferSize),
                            .padding = static_cast<int64_t>(padding)};
        outputSize += (bufferSize + padding);
        outputs[i] = {.hasNoValue = false, .location = loc, .dimensions = {}};
    }