Loading neuralnetworks/aidl/aidl_api/android.hardware.neuralnetworks/current/android/hardware/neuralnetworks/DataLocation.aidl +1 −0 Original line number Original line Diff line number Diff line Loading @@ -36,4 +36,5 @@ parcelable DataLocation { int poolIndex; int poolIndex; long offset; long offset; long length; long length; long padding; } } neuralnetworks/aidl/android/hardware/neuralnetworks/DataLocation.aidl +21 −0 Original line number Original line Diff line number Diff line Loading @@ -18,6 +18,23 @@ package android.hardware.neuralnetworks; /** /** * Describes the location of a data object. * 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 @VintfStability parcelable DataLocation { parcelable DataLocation { Loading @@ -33,4 +50,8 @@ parcelable DataLocation { * The length of the data in bytes. * The length of the data in bytes. */ */ long length; long length; /** * The end padding of the specified memory region in bytes. */ long padding; } } neuralnetworks/aidl/utils/src/Conversions.cpp +6 −0 Original line number Original line Diff line number Diff line Loading @@ -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.poolIndex) << "DataLocation: pool index must not be negative"; VERIFY_NON_NEGATIVE(location.offset) << "DataLocation: offset 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.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()) { if (location.offset > std::numeric_limits<uint32_t>::max()) { return NN_ERROR() << "DataLocation: offset must be <= 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()) { if (location.length > std::numeric_limits<uint32_t>::max()) { return NN_ERROR() << "DataLocation: length must be <= 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{ return DataLocation{ .poolIndex = static_cast<uint32_t>(location.poolIndex), .poolIndex = static_cast<uint32_t>(location.poolIndex), .offset = static_cast<uint32_t>(location.offset), .offset = static_cast<uint32_t>(location.offset), .length = static_cast<uint32_t>(location.length), .length = static_cast<uint32_t>(location.length), .padding = static_cast<uint32_t>(location.padding), }; }; } } Loading neuralnetworks/aidl/vts/functional/MemoryDomainTests.cpp +6 −3 Original line number Original line Diff line number Diff line Loading @@ -1125,12 +1125,15 @@ TEST_P(MemoryDomainExecutionTest, InvalidDimensions) { utils::toSigned(kTestOperand.dimensions).value()); utils::toSigned(kTestOperand.dimensions).value()); if (deviceBuffer.buffer == nullptr) return; if (deviceBuffer.buffer == nullptr) return; RequestMemoryPool sharedMemory = createSharedMemoryPool(kTestOperandDataSize); // Use an incompatible dimension and make sure the length matches with the bad dimension. RequestMemoryPool deviceMemory = createDeviceMemoryPool(deviceBuffer.token); auto badDimensions = utils::toSigned(kTestOperand.dimensions).value(); auto badDimensions = utils::toSigned(kTestOperand.dimensions).value(); badDimensions[0] = 2; badDimensions[0] = 2; const uint32_t badTestOperandDataSize = kTestOperandDataSize * 2; RequestMemoryPool sharedMemory = createSharedMemoryPool(badTestOperandDataSize); RequestMemoryPool deviceMemory = createDeviceMemoryPool(deviceBuffer.token); RequestArgument sharedMemoryArg = { RequestArgument sharedMemoryArg = { .location = {.poolIndex = 0, .offset = 0, .length = kTestOperandDataSize}, .location = {.poolIndex = 0, .offset = 0, .length = badTestOperandDataSize}, .dimensions = badDimensions}; .dimensions = badDimensions}; RequestArgument deviceMemoryArg = {.location = {.poolIndex = 1}}; RequestArgument deviceMemoryArg = {.location = {.poolIndex = 1}}; RequestArgument deviceMemoryArgWithBadDimensions = {.location = {.poolIndex = 1}, RequestArgument deviceMemoryArgWithBadDimensions = {.location = {.poolIndex = 1}, Loading Loading
neuralnetworks/aidl/aidl_api/android.hardware.neuralnetworks/current/android/hardware/neuralnetworks/DataLocation.aidl +1 −0 Original line number Original line Diff line number Diff line Loading @@ -36,4 +36,5 @@ parcelable DataLocation { int poolIndex; int poolIndex; long offset; long offset; long length; long length; long padding; } }
neuralnetworks/aidl/android/hardware/neuralnetworks/DataLocation.aidl +21 −0 Original line number Original line Diff line number Diff line Loading @@ -18,6 +18,23 @@ package android.hardware.neuralnetworks; /** /** * Describes the location of a data object. * 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 @VintfStability parcelable DataLocation { parcelable DataLocation { Loading @@ -33,4 +50,8 @@ parcelable DataLocation { * The length of the data in bytes. * The length of the data in bytes. */ */ long length; long length; /** * The end padding of the specified memory region in bytes. */ long padding; } }
neuralnetworks/aidl/utils/src/Conversions.cpp +6 −0 Original line number Original line Diff line number Diff line Loading @@ -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.poolIndex) << "DataLocation: pool index must not be negative"; VERIFY_NON_NEGATIVE(location.offset) << "DataLocation: offset 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.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()) { if (location.offset > std::numeric_limits<uint32_t>::max()) { return NN_ERROR() << "DataLocation: offset must be <= 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()) { if (location.length > std::numeric_limits<uint32_t>::max()) { return NN_ERROR() << "DataLocation: length must be <= 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{ return DataLocation{ .poolIndex = static_cast<uint32_t>(location.poolIndex), .poolIndex = static_cast<uint32_t>(location.poolIndex), .offset = static_cast<uint32_t>(location.offset), .offset = static_cast<uint32_t>(location.offset), .length = static_cast<uint32_t>(location.length), .length = static_cast<uint32_t>(location.length), .padding = static_cast<uint32_t>(location.padding), }; }; } } Loading
neuralnetworks/aidl/vts/functional/MemoryDomainTests.cpp +6 −3 Original line number Original line Diff line number Diff line Loading @@ -1125,12 +1125,15 @@ TEST_P(MemoryDomainExecutionTest, InvalidDimensions) { utils::toSigned(kTestOperand.dimensions).value()); utils::toSigned(kTestOperand.dimensions).value()); if (deviceBuffer.buffer == nullptr) return; if (deviceBuffer.buffer == nullptr) return; RequestMemoryPool sharedMemory = createSharedMemoryPool(kTestOperandDataSize); // Use an incompatible dimension and make sure the length matches with the bad dimension. RequestMemoryPool deviceMemory = createDeviceMemoryPool(deviceBuffer.token); auto badDimensions = utils::toSigned(kTestOperand.dimensions).value(); auto badDimensions = utils::toSigned(kTestOperand.dimensions).value(); badDimensions[0] = 2; badDimensions[0] = 2; const uint32_t badTestOperandDataSize = kTestOperandDataSize * 2; RequestMemoryPool sharedMemory = createSharedMemoryPool(badTestOperandDataSize); RequestMemoryPool deviceMemory = createDeviceMemoryPool(deviceBuffer.token); RequestArgument sharedMemoryArg = { RequestArgument sharedMemoryArg = { .location = {.poolIndex = 0, .offset = 0, .length = kTestOperandDataSize}, .location = {.poolIndex = 0, .offset = 0, .length = badTestOperandDataSize}, .dimensions = badDimensions}; .dimensions = badDimensions}; RequestArgument deviceMemoryArg = {.location = {.poolIndex = 1}}; RequestArgument deviceMemoryArg = {.location = {.poolIndex = 1}}; RequestArgument deviceMemoryArgWithBadDimensions = {.location = {.poolIndex = 1}, RequestArgument deviceMemoryArgWithBadDimensions = {.location = {.poolIndex = 1}, Loading