mirror of
https://github.com/Evolution-X/hardware_interfaces
synced 2026-02-01 16:50:18 +00:00
Passing padding information to the driver -- hal.
This CL changes the sAIDL interface to enable passing padding
information of the shared memory pool to the driver.
The sAIDL interface defines the padding field explicitly in DataLocation
to make it easy to convert to/from the canonical request.
Bug: 179691454
Test: NNT_static
Test: VtsHalNeuralnetworksTargetTest
Change-Id: Ie13b421531ee4df48822086b027d94a622a3518c
Merged-In: Ie13b421531ee4df48822086b027d94a622a3518c
(cherry picked from commit 6365ea1dbb)
This commit is contained in:
committed by
Przemysław Szczepaniak
parent
df3a0dcaeb
commit
5e36ca05e7
@@ -36,4 +36,5 @@ parcelable DataLocation {
|
||||
int poolIndex;
|
||||
long offset;
|
||||
long length;
|
||||
long padding;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -254,16 +254,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),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -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},
|
||||
|
||||
Reference in New Issue
Block a user