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

Commit 15cc44d7 authored by Xusong Wang's avatar Xusong Wang Committed by Automerger Merge Worker
Browse files

Merge "Passing padding information to the driver -- hal." am: 5e4453f6 am: af57c4d0

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

Change-Id: I1f174a5add49b9e873f4c406bb23ca4bcc50913f
parents 2080fc05 af57c4d0
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -36,4 +36,5 @@ parcelable DataLocation {
  int poolIndex;
  long offset;
  long length;
  long padding;
}
+21 −0
Original line number Diff line number Diff line
@@ -18,6 +18,23 @@ package android.hardware.neuralnetworks;

/**
 * Describes the location of a data object.
 *
 * If the data object is an omitted operand, all of the fields must be 0. If the poolIndex refers to
 * a driver-managed buffer allocated from IDevice::allocate, or an AHardwareBuffer of a format other
 * than AHARDWAREBUFFER_FORMAT_BLOB, the offset, length, and padding must be set to 0 indicating
 * the entire pool is used.
 *
 * Otherwise, the offset, length, and padding specify a sub-region of a memory pool. The sum of
 * offset, length, and padding must not exceed the total size of the specified memory pool. If the
 * data object is a scalar operand or a tensor operand with fully specified dimensions, the value of
 * length must be equal to the raw size of the operand (i.e. the size of an element multiplied
 * by the number of elements). When used in Operand, the value of padding must be 0. When used in
 * RequestArgument, the value of padding specifies the extra bytes at the end of the memory region
 * that may be used by the device to access memory in chunks, for efficiency. If the data object is
 * a Request output whose dimensions are not fully specified, the value of length specifies the
 * total size of the writable region of the output data, and padding specifies the extra bytes at
 * the end of the memory region that may be used by the device to access memory in chunks, for
 * efficiency, but must not be used to hold any output data.
 */
@VintfStability
parcelable DataLocation {
@@ -33,4 +50,8 @@ parcelable DataLocation {
     * The length of the data in bytes.
     */
    long length;
    /**
     * The end padding of the specified memory region in bytes.
     */
    long padding;
}
+6 −0
Original line number Diff line number Diff line
@@ -250,16 +250,22 @@ GeneralResult<DataLocation> unvalidatedConvert(const aidl_hal::DataLocation& loc
    VERIFY_NON_NEGATIVE(location.poolIndex) << "DataLocation: pool index must not be negative";
    VERIFY_NON_NEGATIVE(location.offset) << "DataLocation: offset must not be negative";
    VERIFY_NON_NEGATIVE(location.length) << "DataLocation: length must not be negative";
    VERIFY_NON_NEGATIVE(location.padding) << "DataLocation: padding must not be negative";
    if (location.offset > std::numeric_limits<uint32_t>::max()) {
        return NN_ERROR() << "DataLocation: offset must be <= std::numeric_limits<uint32_t>::max()";
    }
    if (location.length > std::numeric_limits<uint32_t>::max()) {
        return NN_ERROR() << "DataLocation: length must be <= std::numeric_limits<uint32_t>::max()";
    }
    if (location.padding > std::numeric_limits<uint32_t>::max()) {
        return NN_ERROR()
               << "DataLocation: padding must be <= std::numeric_limits<uint32_t>::max()";
    }
    return DataLocation{
            .poolIndex = static_cast<uint32_t>(location.poolIndex),
            .offset = static_cast<uint32_t>(location.offset),
            .length = static_cast<uint32_t>(location.length),
            .padding = static_cast<uint32_t>(location.padding),
    };
}

+6 −3
Original line number Diff line number Diff line
@@ -1125,12 +1125,15 @@ TEST_P(MemoryDomainExecutionTest, InvalidDimensions) {
                                       utils::toSigned(kTestOperand.dimensions).value());
    if (deviceBuffer.buffer == nullptr) return;

    RequestMemoryPool sharedMemory = createSharedMemoryPool(kTestOperandDataSize);
    RequestMemoryPool deviceMemory = createDeviceMemoryPool(deviceBuffer.token);
    // Use an incompatible dimension and make sure the length matches with the bad dimension.
    auto badDimensions = utils::toSigned(kTestOperand.dimensions).value();
    badDimensions[0] = 2;
    const uint32_t badTestOperandDataSize = kTestOperandDataSize * 2;

    RequestMemoryPool sharedMemory = createSharedMemoryPool(badTestOperandDataSize);
    RequestMemoryPool deviceMemory = createDeviceMemoryPool(deviceBuffer.token);
    RequestArgument sharedMemoryArg = {
            .location = {.poolIndex = 0, .offset = 0, .length = kTestOperandDataSize},
            .location = {.poolIndex = 0, .offset = 0, .length = badTestOperandDataSize},
            .dimensions = badDimensions};
    RequestArgument deviceMemoryArg = {.location = {.poolIndex = 1}};
    RequestArgument deviceMemoryArgWithBadDimensions = {.location = {.poolIndex = 1},