Rename BufferRole.frequency -> probability -- HAL.

"Frenquency" often refers to the number of occurrences over a period of
time, while "probability" refers to the number of occurrences of one
event over the number of occurrences of all events. "Probability" is a
better name for this field.

Fixes: 183117895
Test: VtsHalNeuralnetworksTargetTest
Test: NNT_static
Change-Id: Ic86f73b8be2aed567ae4ca17bdb3a57c658fb349
This commit is contained in:
Xusong Wang 2021-03-19 13:58:24 -07:00
parent b8838659c8
commit 46bf892f46
6 changed files with 40 additions and 40 deletions

View file

@ -244,7 +244,7 @@ GeneralResult<BufferRole> unvalidatedConvert(const hal::V1_3::BufferRole& buffer
return BufferRole{
.modelIndex = bufferRole.modelIndex,
.ioIndex = bufferRole.ioIndex,
.frequency = bufferRole.frequency,
.probability = bufferRole.frequency,
};
}
@ -577,7 +577,7 @@ nn::GeneralResult<BufferRole> unvalidatedConvert(const nn::BufferRole& bufferRol
return BufferRole{
.modelIndex = bufferRole.modelIndex,
.ioIndex = bufferRole.ioIndex,
.frequency = bufferRole.frequency,
.frequency = bufferRole.probability,
};
}

View file

@ -35,5 +35,5 @@ package android.hardware.neuralnetworks;
parcelable BufferRole {
int modelIndex;
int ioIndex;
float frequency;
float probability;
}

View file

@ -35,5 +35,5 @@ parcelable BufferRole {
* used in the specified role. This is provided as a hint to optimize the case when multiple
* roles prefer different buffer locations or data layouts.
*/
float frequency;
float probability;
}

View file

@ -472,7 +472,7 @@ GeneralResult<BufferRole> unvalidatedConvert(const aidl_hal::BufferRole& bufferR
return BufferRole{
.modelIndex = static_cast<uint32_t>(bufferRole.modelIndex),
.ioIndex = static_cast<uint32_t>(bufferRole.ioIndex),
.frequency = bufferRole.frequency,
.probability = bufferRole.probability,
};
}
@ -718,7 +718,7 @@ nn::GeneralResult<BufferRole> unvalidatedConvert(const nn::BufferRole& bufferRol
return BufferRole{
.modelIndex = static_cast<int32_t>(bufferRole.modelIndex),
.ioIndex = static_cast<int32_t>(bufferRole.ioIndex),
.frequency = bufferRole.frequency,
.probability = bufferRole.probability,
};
}

View file

@ -101,7 +101,7 @@ class DeviceMemoryAllocator {
ASSERT_NE(result, nullptr);
// Prepare arguments.
BufferRole role = {.modelIndex = 0, .ioIndex = index, .frequency = 1.0f};
BufferRole role = {.modelIndex = 0, .ioIndex = index, .probability = 1.0f};
std::vector<BufferRole> inputRoles, outputRoles;
if constexpr (ioType == IOType::INPUT) {
inputRoles = {role};

View file

@ -333,18 +333,18 @@ class MemoryDomainAllocateTest : public MemoryDomainTestBase,
const std::shared_ptr<IPreparedModel>& model2) {
validateAllocate({
.preparedModels = {model1, model2},
.inputRoles = {{.modelIndex = 0, .ioIndex = 0, .frequency = 1.0f},
{.modelIndex = 1, .ioIndex = 0, .frequency = 1.0f}},
.inputRoles = {{.modelIndex = 0, .ioIndex = 0, .probability = 1.0f},
{.modelIndex = 1, .ioIndex = 0, .probability = 1.0f}},
});
validateAllocate({
.preparedModels = {model1, model2},
.inputRoles = {{.modelIndex = 0, .ioIndex = 0, .frequency = 1.0f}},
.outputRoles = {{.modelIndex = 1, .ioIndex = 0, .frequency = 1.0f}},
.inputRoles = {{.modelIndex = 0, .ioIndex = 0, .probability = 1.0f}},
.outputRoles = {{.modelIndex = 1, .ioIndex = 0, .probability = 1.0f}},
});
validateAllocate({
.preparedModels = {model1, model2},
.outputRoles = {{.modelIndex = 0, .ioIndex = 0, .frequency = 1.0f},
{.modelIndex = 1, .ioIndex = 0, .frequency = 1.0f}},
.outputRoles = {{.modelIndex = 0, .ioIndex = 0, .probability = 1.0f},
{.modelIndex = 1, .ioIndex = 0, .probability = 1.0f}},
});
}
};
@ -366,13 +366,13 @@ TEST_P(MemoryDomainAllocateTest, NullptrPreparedModel) {
// Test with nullptr prepared model as input role.
validateAllocate({
.preparedModels = {nullptr},
.inputRoles = {{.modelIndex = 0, .ioIndex = 0, .frequency = 1.0f}},
.inputRoles = {{.modelIndex = 0, .ioIndex = 0, .probability = 1.0f}},
});
// Test with nullptr prepared model as output role.
validateAllocate({
.preparedModels = {nullptr},
.outputRoles = {{.modelIndex = 0, .ioIndex = 0, .frequency = 1.0f}},
.outputRoles = {{.modelIndex = 0, .ioIndex = 0, .probability = 1.0f}},
});
}
@ -383,13 +383,13 @@ TEST_P(MemoryDomainAllocateTest, InvalidPreparedModel) {
// Test with invalid prepared model as input role.
validateAllocate({
.preparedModels = {invalidPreparedModel},
.inputRoles = {{.modelIndex = 0, .ioIndex = 0, .frequency = 1.0f}},
.inputRoles = {{.modelIndex = 0, .ioIndex = 0, .probability = 1.0f}},
});
// Test with invalid prepared model as output role.
validateAllocate({
.preparedModels = {invalidPreparedModel},
.outputRoles = {{.modelIndex = 0, .ioIndex = 0, .frequency = 1.0f}},
.outputRoles = {{.modelIndex = 0, .ioIndex = 0, .probability = 1.0f}},
});
}
@ -400,13 +400,13 @@ TEST_P(MemoryDomainAllocateTest, InvalidModelIndex) {
// This should fail, because the model index is out of bound.
validateAllocate({
.preparedModels = {preparedModel},
.inputRoles = {{.modelIndex = 1, .ioIndex = 0, .frequency = 1.0f}},
.inputRoles = {{.modelIndex = 1, .ioIndex = 0, .probability = 1.0f}},
});
// This should fail, because the model index is out of bound.
validateAllocate({
.preparedModels = {preparedModel},
.outputRoles = {{.modelIndex = 1, .ioIndex = 0, .frequency = 1.0f}},
.outputRoles = {{.modelIndex = 1, .ioIndex = 0, .probability = 1.0f}},
});
}
@ -417,30 +417,30 @@ TEST_P(MemoryDomainAllocateTest, InvalidIOIndex) {
// This should fail, because the model only has one input.
validateAllocate({
.preparedModels = {preparedModel},
.inputRoles = {{.modelIndex = 0, .ioIndex = 1, .frequency = 1.0f}},
.inputRoles = {{.modelIndex = 0, .ioIndex = 1, .probability = 1.0f}},
});
// This should fail, because the model only has one output.
validateAllocate({
.preparedModels = {preparedModel},
.outputRoles = {{.modelIndex = 0, .ioIndex = 1, .frequency = 1.0f}},
.outputRoles = {{.modelIndex = 0, .ioIndex = 1, .probability = 1.0f}},
});
}
TEST_P(MemoryDomainAllocateTest, InvalidFrequency) {
TEST_P(MemoryDomainAllocateTest, InvalidProbability) {
auto preparedModel = createConvPreparedModel(kTestOperand);
if (preparedModel == nullptr) return;
for (float invalidFreq : {10.0f, 0.0f, -0.5f}) {
// Test with invalid frequency for input roles.
// Test with invalid probability for input roles.
validateAllocate({
.preparedModels = {preparedModel},
.inputRoles = {{.modelIndex = 0, .ioIndex = 0, .frequency = invalidFreq}},
.inputRoles = {{.modelIndex = 0, .ioIndex = 0, .probability = invalidFreq}},
});
// Test with invalid frequency for output roles.
// Test with invalid probability for output roles.
validateAllocate({
.preparedModels = {preparedModel},
.outputRoles = {{.modelIndex = 0, .ioIndex = 0, .frequency = invalidFreq}},
.outputRoles = {{.modelIndex = 0, .ioIndex = 0, .probability = invalidFreq}},
});
}
}
@ -452,25 +452,25 @@ TEST_P(MemoryDomainAllocateTest, SameRoleSpecifiedTwice) {
// Same role with same model index.
validateAllocate({
.preparedModels = {preparedModel},
.inputRoles = {{.modelIndex = 0, .ioIndex = 0, .frequency = 1.0f},
{.modelIndex = 0, .ioIndex = 0, .frequency = 1.0f}},
.inputRoles = {{.modelIndex = 0, .ioIndex = 0, .probability = 1.0f},
{.modelIndex = 0, .ioIndex = 0, .probability = 1.0f}},
});
validateAllocate({
.preparedModels = {preparedModel},
.outputRoles = {{.modelIndex = 0, .ioIndex = 0, .frequency = 1.0f},
{.modelIndex = 0, .ioIndex = 0, .frequency = 1.0f}},
.outputRoles = {{.modelIndex = 0, .ioIndex = 0, .probability = 1.0f},
{.modelIndex = 0, .ioIndex = 0, .probability = 1.0f}},
});
// Different model indexes, but logically referring to the same role.
validateAllocate({
.preparedModels = {preparedModel, preparedModel},
.inputRoles = {{.modelIndex = 0, .ioIndex = 0, .frequency = 1.0f},
{.modelIndex = 1, .ioIndex = 0, .frequency = 1.0f}},
.inputRoles = {{.modelIndex = 0, .ioIndex = 0, .probability = 1.0f},
{.modelIndex = 1, .ioIndex = 0, .probability = 1.0f}},
});
validateAllocate({
.preparedModels = {preparedModel, preparedModel},
.outputRoles = {{.modelIndex = 0, .ioIndex = 0, .frequency = 1.0f},
{.modelIndex = 1, .ioIndex = 0, .frequency = 1.0f}},
.outputRoles = {{.modelIndex = 0, .ioIndex = 0, .probability = 1.0f},
{.modelIndex = 1, .ioIndex = 0, .probability = 1.0f}},
});
}
@ -549,12 +549,12 @@ TEST_P(MemoryDomainAllocateTest, ConflictRankBetweenRoleAndDesc) {
validateAllocate({
.dimensions = badDimensions,
.preparedModels = {preparedModel},
.inputRoles = {{.modelIndex = 0, .ioIndex = 0, .frequency = 1.0f}},
.inputRoles = {{.modelIndex = 0, .ioIndex = 0, .probability = 1.0f}},
});
validateAllocate({
.dimensions = badDimensions,
.preparedModels = {preparedModel},
.outputRoles = {{.modelIndex = 0, .ioIndex = 0, .frequency = 1.0f}},
.outputRoles = {{.modelIndex = 0, .ioIndex = 0, .probability = 1.0f}},
});
}
@ -568,12 +568,12 @@ TEST_P(MemoryDomainAllocateTest, ConflictDimensionsBetweenRoleAndDesc) {
validateAllocate({
.dimensions = badDimensions,
.preparedModels = {preparedModel},
.inputRoles = {{.modelIndex = 0, .ioIndex = 0, .frequency = 1.0f}},
.inputRoles = {{.modelIndex = 0, .ioIndex = 0, .probability = 1.0f}},
});
validateAllocate({
.dimensions = badDimensions,
.preparedModels = {preparedModel},
.outputRoles = {{.modelIndex = 0, .ioIndex = 0, .frequency = 1.0f}},
.outputRoles = {{.modelIndex = 0, .ioIndex = 0, .probability = 1.0f}},
});
}
@ -586,7 +586,7 @@ TEST_P(MemoryDomainAllocateTest, ConflictRankWithScalarRole) {
validateAllocate({
.dimensions = {1},
.preparedModels = {preparedModel},
.inputRoles = {{.modelIndex = 0, .ioIndex = 2, .frequency = 1.0f}},
.inputRoles = {{.modelIndex = 0, .ioIndex = 2, .probability = 1.0f}},
});
}
@ -620,7 +620,7 @@ class MemoryDomainCopyTestBase : public MemoryDomainTestBase {
std::vector<BufferRole> inputRoles(inputIndexes.size()), outputRoles(outputIndexes.size());
auto trans = [](int32_t ind) -> BufferRole {
return {.modelIndex = 0, .ioIndex = ind, .frequency = 1.0f};
return {.modelIndex = 0, .ioIndex = ind, .probability = 1.0f};
};
std::transform(inputIndexes.begin(), inputIndexes.end(), inputRoles.begin(), trans);
std::transform(outputIndexes.begin(), outputIndexes.end(), outputRoles.begin(), trans);