diff options
author | Xusong Wang <xusongw@google.com> | 2020-03-19 12:15:10 -0700 |
---|---|---|
committer | Xusong Wang <xusongw@google.com> | 2020-03-19 13:13:40 -0700 |
commit | 8136419ad3b1025fa383b3a4510abd4d427d7a4f (patch) | |
tree | 411052f3baa5f7e654688daa2d780ddb83a6e807 | |
parent | 28bc28712ef9ae5fc2be41ae53582560c88d3f70 (diff) | |
download | ml-8136419ad3b1025fa383b3a4510abd4d427d7a4f.tar.gz |
Fix SQUEEZE with optional squeeze dims.
Also added tests.
Fixes: 116355758
Fixes: 151775127
Test: NNT_static
Change-Id: I8904d7caf381970fc3b8869aa6aa09c03acbc6df
8 files changed, 824 insertions, 24 deletions
diff --git a/nn/common/operations/Squeeze.cpp b/nn/common/operations/Squeeze.cpp index 8785a8f19..ca09703fd 100644 --- a/nn/common/operations/Squeeze.cpp +++ b/nn/common/operations/Squeeze.cpp @@ -66,6 +66,10 @@ bool validate(const IOperationValidationContext* context) { } bool prepare(IOperationExecutionContext* context) { + // Only the squeeze dims tensor can be omitted. + NN_RET_CHECK(!context->isOmittedInput(kInputTensor)); + NN_RET_CHECK(!context->isOmittedOutput(kOutputTensor)); + const int32_t* squeezeDims = context->getInputBuffer<int32_t>(kSqueezeDims); const Shape inputShape = context->getInputShape(kInputTensor); const Shape squeezeDimsShape = context->getInputShape(kSqueezeDims); @@ -75,12 +79,11 @@ bool prepare(IOperationExecutionContext* context) { NN_OPS_CHECK(squeezeDimsShape.type == OperandType::TENSOR_INT32); NN_OPS_CHECK(getNumberOfDimensions(squeezeDimsShape) == 1); - int32_t squeezeDimsSize = static_cast<int32_t>(getSizeOfDimension(squeezeDimsShape, 0)); std::vector<bool> shouldSqueeze(numInputDims, false); int32_t numDimsSqueezed = 0; - if (squeezeDimsSize == 0) { - // If squeezeDimsSize is 0, all dims with value 1 will be squeezed. + if (context->isOmittedInput(kSqueezeDims)) { + // If squeezeDims is omitted, all dims with value 1 will be squeezed. for (int32_t idx = 0; idx < numInputDims; ++idx) { if (getSizeOfDimension(inputShape, idx) == 1) { shouldSqueeze[idx] = true; @@ -88,6 +91,7 @@ bool prepare(IOperationExecutionContext* context) { } } } else { + int32_t squeezeDimsSize = static_cast<int32_t>(getSizeOfDimension(squeezeDimsShape, 0)); for (int32_t idx = 0; idx < squeezeDimsSize; ++idx) { int32_t current = squeezeDims[idx] < 0 ? squeezeDims[idx] + numInputDims : squeezeDims[idx]; @@ -127,7 +131,8 @@ bool execute(IOperationExecutionContext* context) { } } // namespace squeeze -NN_REGISTER_OPERATION(SQUEEZE, "SQUEEZE", squeeze::validate, squeeze::prepare, squeeze::execute); +NN_REGISTER_OPERATION(SQUEEZE, "SQUEEZE", squeeze::validate, squeeze::prepare, squeeze::execute, + .allowOmittedOperand = true); } // namespace nn } // namespace android diff --git a/nn/runtime/test/generated/spec_V1_1/squeeze_omitted.example.cpp b/nn/runtime/test/generated/spec_V1_1/squeeze_omitted.example.cpp new file mode 100644 index 000000000..ab214369c --- /dev/null +++ b/nn/runtime/test/generated/spec_V1_1/squeeze_omitted.example.cpp @@ -0,0 +1,450 @@ +// Generated from squeeze_omitted.mod.py +// DO NOT EDIT +// clang-format off +#include "TestHarness.h" +using namespace test_helper; + +namespace generated_tests::squeeze_omitted { + +const TestModel& get_test_model() { + static TestModel model = { + .expectFailure = false, + .expectedMultinomialDistributionTolerance = 0, + .isRelaxed = false, + .main = { + .inputIndexes = {0}, + .operands = {{ + .channelQuant = {}, + .data = TestBuffer::createFromVector<float>({1.4f, 2.3f, 3.2f, 4.1f, 5.4f, 6.3f, 7.2f, 8.1f}), + .dimensions = {4, 1, 1, 2}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::SUBGRAPH_INPUT, + .numberOfConsumers = 1, + .scale = 0.0f, + .type = TestOperandType::TENSOR_FLOAT32, + .zeroPoint = 0 + }, { + .channelQuant = {}, + .data = TestBuffer::createFromVector<int32_t>({}), + .dimensions = {0}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::NO_VALUE, + .numberOfConsumers = 1, + .scale = 0.0f, + .type = TestOperandType::TENSOR_INT32, + .zeroPoint = 0 + }, { + .channelQuant = {}, + .data = TestBuffer::createFromVector<float>({1.4f, 2.3f, 3.2f, 4.1f, 5.4f, 6.3f, 7.2f, 8.1f}), + .dimensions = {4, 2}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::SUBGRAPH_OUTPUT, + .numberOfConsumers = 0, + .scale = 0.0f, + .type = TestOperandType::TENSOR_FLOAT32, + .zeroPoint = 0 + }}, + .operations = {{ + .inputs = {0, 1}, + .outputs = {2}, + .type = TestOperationType::SQUEEZE + }}, + .outputIndexes = {2} + }, + .minSupportedVersion = TestHalVersion::V1_1, + .referenced = {} + }; + return model; +} + +const auto dummy_test_model = TestModelManager::get().add("squeeze_omitted", get_test_model()); + +} // namespace generated_tests::squeeze_omitted + +namespace generated_tests::squeeze_omitted { + +const TestModel& get_test_model_all_inputs_as_internal() { + static TestModel model = { + .expectFailure = false, + .expectedMultinomialDistributionTolerance = 0, + .isRelaxed = false, + .main = { + .inputIndexes = {3}, + .operands = {{ + .channelQuant = {}, + .data = TestBuffer::createFromVector<float>({}), + .dimensions = {4, 1, 1, 2}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::TEMPORARY_VARIABLE, + .numberOfConsumers = 1, + .scale = 0.0f, + .type = TestOperandType::TENSOR_FLOAT32, + .zeroPoint = 0 + }, { + .channelQuant = {}, + .data = TestBuffer::createFromVector<int32_t>({}), + .dimensions = {0}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::NO_VALUE, + .numberOfConsumers = 1, + .scale = 0.0f, + .type = TestOperandType::TENSOR_INT32, + .zeroPoint = 0 + }, { + .channelQuant = {}, + .data = TestBuffer::createFromVector<float>({1.4f, 2.3f, 3.2f, 4.1f, 5.4f, 6.3f, 7.2f, 8.1f}), + .dimensions = {4, 2}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::SUBGRAPH_OUTPUT, + .numberOfConsumers = 0, + .scale = 0.0f, + .type = TestOperandType::TENSOR_FLOAT32, + .zeroPoint = 0 + }, { + .channelQuant = {}, + .data = TestBuffer::createFromVector<float>({1.4f, 2.3f, 3.2f, 4.1f, 5.4f, 6.3f, 7.2f, 8.1f}), + .dimensions = {4, 1, 1, 2}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::SUBGRAPH_INPUT, + .numberOfConsumers = 1, + .scale = 0.0f, + .type = TestOperandType::TENSOR_FLOAT32, + .zeroPoint = 0 + }, { + .channelQuant = {}, + .data = TestBuffer::createFromVector<float>({0.0f}), + .dimensions = {1}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::CONSTANT_COPY, + .numberOfConsumers = 1, + .scale = 0.0f, + .type = TestOperandType::TENSOR_FLOAT32, + .zeroPoint = 0 + }, { + .channelQuant = {}, + .data = TestBuffer::createFromVector<int32_t>({0}), + .dimensions = {}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::CONSTANT_COPY, + .numberOfConsumers = 1, + .scale = 0.0f, + .type = TestOperandType::INT32, + .zeroPoint = 0 + }}, + .operations = {{ + .inputs = {3, 4, 5}, + .outputs = {0}, + .type = TestOperationType::ADD + }, { + .inputs = {0, 1}, + .outputs = {2}, + .type = TestOperationType::SQUEEZE + }}, + .outputIndexes = {2} + }, + .minSupportedVersion = TestHalVersion::V1_1, + .referenced = {} + }; + return model; +} + +const auto dummy_test_model_all_inputs_as_internal = TestModelManager::get().add("squeeze_omitted_all_inputs_as_internal", get_test_model_all_inputs_as_internal()); + +} // namespace generated_tests::squeeze_omitted + +namespace generated_tests::squeeze_omitted { + +const TestModel& get_test_model_relaxed() { + static TestModel model = { + .expectFailure = false, + .expectedMultinomialDistributionTolerance = 0, + .isRelaxed = true, + .main = { + .inputIndexes = {0}, + .operands = {{ + .channelQuant = {}, + .data = TestBuffer::createFromVector<float>({1.4f, 2.3f, 3.2f, 4.1f, 5.4f, 6.3f, 7.2f, 8.1f}), + .dimensions = {4, 1, 1, 2}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::SUBGRAPH_INPUT, + .numberOfConsumers = 1, + .scale = 0.0f, + .type = TestOperandType::TENSOR_FLOAT32, + .zeroPoint = 0 + }, { + .channelQuant = {}, + .data = TestBuffer::createFromVector<int32_t>({}), + .dimensions = {0}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::NO_VALUE, + .numberOfConsumers = 1, + .scale = 0.0f, + .type = TestOperandType::TENSOR_INT32, + .zeroPoint = 0 + }, { + .channelQuant = {}, + .data = TestBuffer::createFromVector<float>({1.4f, 2.3f, 3.2f, 4.1f, 5.4f, 6.3f, 7.2f, 8.1f}), + .dimensions = {4, 2}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::SUBGRAPH_OUTPUT, + .numberOfConsumers = 0, + .scale = 0.0f, + .type = TestOperandType::TENSOR_FLOAT32, + .zeroPoint = 0 + }}, + .operations = {{ + .inputs = {0, 1}, + .outputs = {2}, + .type = TestOperationType::SQUEEZE + }}, + .outputIndexes = {2} + }, + .minSupportedVersion = TestHalVersion::UNKNOWN, + .referenced = {} + }; + return model; +} + +const auto dummy_test_model_relaxed = TestModelManager::get().add("squeeze_omitted_relaxed", get_test_model_relaxed()); + +} // namespace generated_tests::squeeze_omitted + +namespace generated_tests::squeeze_omitted { + +const TestModel& get_test_model_relaxed_all_inputs_as_internal() { + static TestModel model = { + .expectFailure = false, + .expectedMultinomialDistributionTolerance = 0, + .isRelaxed = true, + .main = { + .inputIndexes = {3}, + .operands = {{ + .channelQuant = {}, + .data = TestBuffer::createFromVector<float>({}), + .dimensions = {4, 1, 1, 2}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::TEMPORARY_VARIABLE, + .numberOfConsumers = 1, + .scale = 0.0f, + .type = TestOperandType::TENSOR_FLOAT32, + .zeroPoint = 0 + }, { + .channelQuant = {}, + .data = TestBuffer::createFromVector<int32_t>({}), + .dimensions = {0}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::NO_VALUE, + .numberOfConsumers = 1, + .scale = 0.0f, + .type = TestOperandType::TENSOR_INT32, + .zeroPoint = 0 + }, { + .channelQuant = {}, + .data = TestBuffer::createFromVector<float>({1.4f, 2.3f, 3.2f, 4.1f, 5.4f, 6.3f, 7.2f, 8.1f}), + .dimensions = {4, 2}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::SUBGRAPH_OUTPUT, + .numberOfConsumers = 0, + .scale = 0.0f, + .type = TestOperandType::TENSOR_FLOAT32, + .zeroPoint = 0 + }, { + .channelQuant = {}, + .data = TestBuffer::createFromVector<float>({1.4f, 2.3f, 3.2f, 4.1f, 5.4f, 6.3f, 7.2f, 8.1f}), + .dimensions = {4, 1, 1, 2}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::SUBGRAPH_INPUT, + .numberOfConsumers = 1, + .scale = 0.0f, + .type = TestOperandType::TENSOR_FLOAT32, + .zeroPoint = 0 + }, { + .channelQuant = {}, + .data = TestBuffer::createFromVector<float>({0.0f}), + .dimensions = {1}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::CONSTANT_COPY, + .numberOfConsumers = 1, + .scale = 0.0f, + .type = TestOperandType::TENSOR_FLOAT32, + .zeroPoint = 0 + }, { + .channelQuant = {}, + .data = TestBuffer::createFromVector<int32_t>({0}), + .dimensions = {}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::CONSTANT_COPY, + .numberOfConsumers = 1, + .scale = 0.0f, + .type = TestOperandType::INT32, + .zeroPoint = 0 + }}, + .operations = {{ + .inputs = {3, 4, 5}, + .outputs = {0}, + .type = TestOperationType::ADD + }, { + .inputs = {0, 1}, + .outputs = {2}, + .type = TestOperationType::SQUEEZE + }}, + .outputIndexes = {2} + }, + .minSupportedVersion = TestHalVersion::UNKNOWN, + .referenced = {} + }; + return model; +} + +const auto dummy_test_model_relaxed_all_inputs_as_internal = TestModelManager::get().add("squeeze_omitted_relaxed_all_inputs_as_internal", get_test_model_relaxed_all_inputs_as_internal()); + +} // namespace generated_tests::squeeze_omitted + +namespace generated_tests::squeeze_omitted { + +const TestModel& get_test_model_quant8() { + static TestModel model = { + .expectFailure = false, + .expectedMultinomialDistributionTolerance = 0, + .isRelaxed = false, + .main = { + .inputIndexes = {0}, + .operands = {{ + .channelQuant = {}, + .data = TestBuffer::createFromVector<uint8_t>({3, 5, 6, 8, 11, 13, 14, 16}), + .dimensions = {4, 1, 1, 2}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::SUBGRAPH_INPUT, + .numberOfConsumers = 1, + .scale = 0.5f, + .type = TestOperandType::TENSOR_QUANT8_ASYMM, + .zeroPoint = 0 + }, { + .channelQuant = {}, + .data = TestBuffer::createFromVector<int32_t>({}), + .dimensions = {0}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::NO_VALUE, + .numberOfConsumers = 1, + .scale = 0.0f, + .type = TestOperandType::TENSOR_INT32, + .zeroPoint = 0 + }, { + .channelQuant = {}, + .data = TestBuffer::createFromVector<uint8_t>({3, 5, 6, 8, 11, 13, 14, 16}), + .dimensions = {4, 2}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::SUBGRAPH_OUTPUT, + .numberOfConsumers = 0, + .scale = 0.5f, + .type = TestOperandType::TENSOR_QUANT8_ASYMM, + .zeroPoint = 0 + }}, + .operations = {{ + .inputs = {0, 1}, + .outputs = {2}, + .type = TestOperationType::SQUEEZE + }}, + .outputIndexes = {2} + }, + .minSupportedVersion = TestHalVersion::V1_1, + .referenced = {} + }; + return model; +} + +const auto dummy_test_model_quant8 = TestModelManager::get().add("squeeze_omitted_quant8", get_test_model_quant8()); + +} // namespace generated_tests::squeeze_omitted + +namespace generated_tests::squeeze_omitted { + +const TestModel& get_test_model_quant8_all_inputs_as_internal() { + static TestModel model = { + .expectFailure = false, + .expectedMultinomialDistributionTolerance = 0, + .isRelaxed = false, + .main = { + .inputIndexes = {3}, + .operands = {{ + .channelQuant = {}, + .data = TestBuffer::createFromVector<uint8_t>({}), + .dimensions = {4, 1, 1, 2}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::TEMPORARY_VARIABLE, + .numberOfConsumers = 1, + .scale = 0.5f, + .type = TestOperandType::TENSOR_QUANT8_ASYMM, + .zeroPoint = 0 + }, { + .channelQuant = {}, + .data = TestBuffer::createFromVector<int32_t>({}), + .dimensions = {0}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::NO_VALUE, + .numberOfConsumers = 1, + .scale = 0.0f, + .type = TestOperandType::TENSOR_INT32, + .zeroPoint = 0 + }, { + .channelQuant = {}, + .data = TestBuffer::createFromVector<uint8_t>({3, 5, 6, 8, 11, 13, 14, 16}), + .dimensions = {4, 2}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::SUBGRAPH_OUTPUT, + .numberOfConsumers = 0, + .scale = 0.5f, + .type = TestOperandType::TENSOR_QUANT8_ASYMM, + .zeroPoint = 0 + }, { + .channelQuant = {}, + .data = TestBuffer::createFromVector<uint8_t>({3, 5, 6, 8, 11, 13, 14, 16}), + .dimensions = {4, 1, 1, 2}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::SUBGRAPH_INPUT, + .numberOfConsumers = 1, + .scale = 0.5f, + .type = TestOperandType::TENSOR_QUANT8_ASYMM, + .zeroPoint = 0 + }, { + .channelQuant = {}, + .data = TestBuffer::createFromVector<uint8_t>({0}), + .dimensions = {1}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::CONSTANT_COPY, + .numberOfConsumers = 1, + .scale = 0.5f, + .type = TestOperandType::TENSOR_QUANT8_ASYMM, + .zeroPoint = 0 + }, { + .channelQuant = {}, + .data = TestBuffer::createFromVector<int32_t>({0}), + .dimensions = {}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::CONSTANT_COPY, + .numberOfConsumers = 1, + .scale = 0.0f, + .type = TestOperandType::INT32, + .zeroPoint = 0 + }}, + .operations = {{ + .inputs = {3, 4, 5}, + .outputs = {0}, + .type = TestOperationType::ADD + }, { + .inputs = {0, 1}, + .outputs = {2}, + .type = TestOperationType::SQUEEZE + }}, + .outputIndexes = {2} + }, + .minSupportedVersion = TestHalVersion::V1_1, + .referenced = {} + }; + return model; +} + +const auto dummy_test_model_quant8_all_inputs_as_internal = TestModelManager::get().add("squeeze_omitted_quant8_all_inputs_as_internal", get_test_model_quant8_all_inputs_as_internal()); + +} // namespace generated_tests::squeeze_omitted + diff --git a/nn/runtime/test/generated/spec_V1_2/squeeze_float16.example.cpp b/nn/runtime/test/generated/spec_V1_2/squeeze_float16.example.cpp index a74263d8e..773bc0e29 100644 --- a/nn/runtime/test/generated/spec_V1_2/squeeze_float16.example.cpp +++ b/nn/runtime/test/generated/spec_V1_2/squeeze_float16.example.cpp @@ -152,3 +152,151 @@ const auto dummy_test_model_all_inputs_as_internal = TestModelManager::get().add } // namespace generated_tests::squeeze_float16 +namespace generated_tests::squeeze_float16 { + +const TestModel& get_test_model_omitted() { + static TestModel model = { + .expectFailure = false, + .expectedMultinomialDistributionTolerance = 0, + .isRelaxed = false, + .main = { + .inputIndexes = {0}, + .operands = {{ + .channelQuant = {}, + .data = TestBuffer::createFromVector<_Float16>({1.4f, 2.3f, 3.2f, 4.1f, 5.4f, 6.3f, 7.2f, 8.1f}), + .dimensions = {4, 1, 1, 2}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::SUBGRAPH_INPUT, + .numberOfConsumers = 1, + .scale = 0.0f, + .type = TestOperandType::TENSOR_FLOAT16, + .zeroPoint = 0 + }, { + .channelQuant = {}, + .data = TestBuffer::createFromVector<int32_t>({}), + .dimensions = {0}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::NO_VALUE, + .numberOfConsumers = 1, + .scale = 0.0f, + .type = TestOperandType::TENSOR_INT32, + .zeroPoint = 0 + }, { + .channelQuant = {}, + .data = TestBuffer::createFromVector<_Float16>({1.4f, 2.3f, 3.2f, 4.1f, 5.4f, 6.3f, 7.2f, 8.1f}), + .dimensions = {4, 2}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::SUBGRAPH_OUTPUT, + .numberOfConsumers = 0, + .scale = 0.0f, + .type = TestOperandType::TENSOR_FLOAT16, + .zeroPoint = 0 + }}, + .operations = {{ + .inputs = {0, 1}, + .outputs = {2}, + .type = TestOperationType::SQUEEZE + }}, + .outputIndexes = {2} + }, + .minSupportedVersion = TestHalVersion::V1_2, + .referenced = {} + }; + return model; +} + +const auto dummy_test_model_omitted = TestModelManager::get().add("squeeze_float16_omitted", get_test_model_omitted()); + +} // namespace generated_tests::squeeze_float16 + +namespace generated_tests::squeeze_float16 { + +const TestModel& get_test_model_omitted_all_inputs_as_internal() { + static TestModel model = { + .expectFailure = false, + .expectedMultinomialDistributionTolerance = 0, + .isRelaxed = false, + .main = { + .inputIndexes = {3}, + .operands = {{ + .channelQuant = {}, + .data = TestBuffer::createFromVector<_Float16>({}), + .dimensions = {4, 1, 1, 2}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::TEMPORARY_VARIABLE, + .numberOfConsumers = 1, + .scale = 0.0f, + .type = TestOperandType::TENSOR_FLOAT16, + .zeroPoint = 0 + }, { + .channelQuant = {}, + .data = TestBuffer::createFromVector<int32_t>({}), + .dimensions = {0}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::NO_VALUE, + .numberOfConsumers = 1, + .scale = 0.0f, + .type = TestOperandType::TENSOR_INT32, + .zeroPoint = 0 + }, { + .channelQuant = {}, + .data = TestBuffer::createFromVector<_Float16>({1.4f, 2.3f, 3.2f, 4.1f, 5.4f, 6.3f, 7.2f, 8.1f}), + .dimensions = {4, 2}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::SUBGRAPH_OUTPUT, + .numberOfConsumers = 0, + .scale = 0.0f, + .type = TestOperandType::TENSOR_FLOAT16, + .zeroPoint = 0 + }, { + .channelQuant = {}, + .data = TestBuffer::createFromVector<_Float16>({1.4f, 2.3f, 3.2f, 4.1f, 5.4f, 6.3f, 7.2f, 8.1f}), + .dimensions = {4, 1, 1, 2}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::SUBGRAPH_INPUT, + .numberOfConsumers = 1, + .scale = 0.0f, + .type = TestOperandType::TENSOR_FLOAT16, + .zeroPoint = 0 + }, { + .channelQuant = {}, + .data = TestBuffer::createFromVector<_Float16>({0.0f}), + .dimensions = {1}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::CONSTANT_COPY, + .numberOfConsumers = 1, + .scale = 0.0f, + .type = TestOperandType::TENSOR_FLOAT16, + .zeroPoint = 0 + }, { + .channelQuant = {}, + .data = TestBuffer::createFromVector<int32_t>({0}), + .dimensions = {}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::CONSTANT_COPY, + .numberOfConsumers = 1, + .scale = 0.0f, + .type = TestOperandType::INT32, + .zeroPoint = 0 + }}, + .operations = {{ + .inputs = {3, 4, 5}, + .outputs = {0}, + .type = TestOperationType::ADD + }, { + .inputs = {0, 1}, + .outputs = {2}, + .type = TestOperationType::SQUEEZE + }}, + .outputIndexes = {2} + }, + .minSupportedVersion = TestHalVersion::V1_2, + .referenced = {} + }; + return model; +} + +const auto dummy_test_model_omitted_all_inputs_as_internal = TestModelManager::get().add("squeeze_float16_omitted_all_inputs_as_internal", get_test_model_omitted_all_inputs_as_internal()); + +} // namespace generated_tests::squeeze_float16 + diff --git a/nn/runtime/test/generated/spec_V1_3/squeeze_quant8_signed.example.cpp b/nn/runtime/test/generated/spec_V1_3/squeeze_quant8_signed.example.cpp index 06c6aa5cd..08eae8681 100644 --- a/nn/runtime/test/generated/spec_V1_3/squeeze_quant8_signed.example.cpp +++ b/nn/runtime/test/generated/spec_V1_3/squeeze_quant8_signed.example.cpp @@ -152,3 +152,151 @@ const auto dummy_test_model_all_inputs_as_internal = TestModelManager::get().add } // namespace generated_tests::squeeze_quant8_signed +namespace generated_tests::squeeze_quant8_signed { + +const TestModel& get_test_model_omitted() { + static TestModel model = { + .expectFailure = false, + .expectedMultinomialDistributionTolerance = 0, + .isRelaxed = false, + .main = { + .inputIndexes = {0}, + .operands = {{ + .channelQuant = {}, + .data = TestBuffer::createFromVector<int8_t>({-127, -126, -125, -124, -123, -122, -121, -120, -119, -118, -117, -116, -115, -114, -113, -112, -111, -110, -109, -108, -107, -106, -105, -104}), + .dimensions = {1, 24, 1}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::SUBGRAPH_INPUT, + .numberOfConsumers = 1, + .scale = 1.0f, + .type = TestOperandType::TENSOR_QUANT8_ASYMM_SIGNED, + .zeroPoint = -128 + }, { + .channelQuant = {}, + .data = TestBuffer::createFromVector<int32_t>({}), + .dimensions = {0}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::NO_VALUE, + .numberOfConsumers = 1, + .scale = 0.0f, + .type = TestOperandType::TENSOR_INT32, + .zeroPoint = 0 + }, { + .channelQuant = {}, + .data = TestBuffer::createFromVector<int8_t>({-127, -126, -125, -124, -123, -122, -121, -120, -119, -118, -117, -116, -115, -114, -113, -112, -111, -110, -109, -108, -107, -106, -105, -104}), + .dimensions = {24}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::SUBGRAPH_OUTPUT, + .numberOfConsumers = 0, + .scale = 1.0f, + .type = TestOperandType::TENSOR_QUANT8_ASYMM_SIGNED, + .zeroPoint = -128 + }}, + .operations = {{ + .inputs = {0, 1}, + .outputs = {2}, + .type = TestOperationType::SQUEEZE + }}, + .outputIndexes = {2} + }, + .minSupportedVersion = TestHalVersion::V1_3, + .referenced = {} + }; + return model; +} + +const auto dummy_test_model_omitted = TestModelManager::get().add("squeeze_quant8_signed_omitted", get_test_model_omitted()); + +} // namespace generated_tests::squeeze_quant8_signed + +namespace generated_tests::squeeze_quant8_signed { + +const TestModel& get_test_model_omitted_all_inputs_as_internal() { + static TestModel model = { + .expectFailure = false, + .expectedMultinomialDistributionTolerance = 0, + .isRelaxed = false, + .main = { + .inputIndexes = {3}, + .operands = {{ + .channelQuant = {}, + .data = TestBuffer::createFromVector<int8_t>({}), + .dimensions = {1, 24, 1}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::TEMPORARY_VARIABLE, + .numberOfConsumers = 1, + .scale = 1.0f, + .type = TestOperandType::TENSOR_QUANT8_ASYMM_SIGNED, + .zeroPoint = -128 + }, { + .channelQuant = {}, + .data = TestBuffer::createFromVector<int32_t>({}), + .dimensions = {0}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::NO_VALUE, + .numberOfConsumers = 1, + .scale = 0.0f, + .type = TestOperandType::TENSOR_INT32, + .zeroPoint = 0 + }, { + .channelQuant = {}, + .data = TestBuffer::createFromVector<int8_t>({-127, -126, -125, -124, -123, -122, -121, -120, -119, -118, -117, -116, -115, -114, -113, -112, -111, -110, -109, -108, -107, -106, -105, -104}), + .dimensions = {24}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::SUBGRAPH_OUTPUT, + .numberOfConsumers = 0, + .scale = 1.0f, + .type = TestOperandType::TENSOR_QUANT8_ASYMM_SIGNED, + .zeroPoint = -128 + }, { + .channelQuant = {}, + .data = TestBuffer::createFromVector<int8_t>({-127, -126, -125, -124, -123, -122, -121, -120, -119, -118, -117, -116, -115, -114, -113, -112, -111, -110, -109, -108, -107, -106, -105, -104}), + .dimensions = {1, 24, 1}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::SUBGRAPH_INPUT, + .numberOfConsumers = 1, + .scale = 1.0f, + .type = TestOperandType::TENSOR_QUANT8_ASYMM_SIGNED, + .zeroPoint = -128 + }, { + .channelQuant = {}, + .data = TestBuffer::createFromVector<int8_t>({-128}), + .dimensions = {1}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::CONSTANT_COPY, + .numberOfConsumers = 1, + .scale = 1.0f, + .type = TestOperandType::TENSOR_QUANT8_ASYMM_SIGNED, + .zeroPoint = -128 + }, { + .channelQuant = {}, + .data = TestBuffer::createFromVector<int32_t>({0}), + .dimensions = {}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::CONSTANT_COPY, + .numberOfConsumers = 1, + .scale = 0.0f, + .type = TestOperandType::INT32, + .zeroPoint = 0 + }}, + .operations = {{ + .inputs = {3, 4, 5}, + .outputs = {0}, + .type = TestOperationType::ADD + }, { + .inputs = {0, 1}, + .outputs = {2}, + .type = TestOperationType::SQUEEZE + }}, + .outputIndexes = {2} + }, + .minSupportedVersion = TestHalVersion::V1_3, + .referenced = {} + }; + return model; +} + +const auto dummy_test_model_omitted_all_inputs_as_internal = TestModelManager::get().add("squeeze_quant8_signed_omitted_all_inputs_as_internal", get_test_model_omitted_all_inputs_as_internal()); + +} // namespace generated_tests::squeeze_quant8_signed + diff --git a/nn/runtime/test/specs/V1_1/squeeze_omitted.mod.py b/nn/runtime/test/specs/V1_1/squeeze_omitted.mod.py new file mode 100644 index 000000000..77f02466d --- /dev/null +++ b/nn/runtime/test/specs/V1_1/squeeze_omitted.mod.py @@ -0,0 +1,31 @@ +# +# Copyright (C) 2020 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +i1 = Input("input", "TENSOR_FLOAT32", "{4, 1, 1, 2}") +squeezeDims = Parameter("squeezeDims", ["TENSOR_INT32", [0]], value=None) +o1 = Output("output", "TENSOR_FLOAT32", "{4, 2}") +Model().Operation("SQUEEZE", i1, squeezeDims).To(o1) + +quant8 = DataTypeConverter().Identify({ + i1: ("TENSOR_QUANT8_ASYMM", 0.5, 0), + o1: ("TENSOR_QUANT8_ASYMM", 0.5, 0) +}) + +# Instantiate an example +Example({ + i1: [1.4, 2.3, 3.2, 4.1, 5.4, 6.3, 7.2, 8.1], + o1: [1.4, 2.3, 3.2, 4.1, 5.4, 6.3, 7.2, 8.1] +}).AddVariations("relaxed", quant8) diff --git a/nn/runtime/test/specs/V1_2/squeeze_float16.mod.py b/nn/runtime/test/specs/V1_2/squeeze_float16.mod.py index e5f18a524..f2ad4b3d1 100644 --- a/nn/runtime/test/specs/V1_2/squeeze_float16.mod.py +++ b/nn/runtime/test/specs/V1_2/squeeze_float16.mod.py @@ -1,3 +1,19 @@ +# +# Copyright (C) 2020 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + model = Model() i1 = Input("input", "TENSOR_FLOAT16", "{4, 1, 1, 2}") squeezeDims = Parameter("squeezeDims", "TENSOR_INT32", "{2}", [1, 2]) @@ -14,3 +30,8 @@ output0 = {output: # output 0 # Instantiate an example Example((input0, output0)) + +# Test with omitted squeeze dims +squeezeDims = Parameter("squeezeDims", ["TENSOR_INT32", [0]], value=None) +Model("omitted").Operation("SQUEEZE", i1, squeezeDims).To(output) +Example((input0, output0)) diff --git a/nn/runtime/test/specs/V1_3/squeeze_quant8_signed.mod.py b/nn/runtime/test/specs/V1_3/squeeze_quant8_signed.mod.py index e4fcb72e8..fac9bea89 100644 --- a/nn/runtime/test/specs/V1_3/squeeze_quant8_signed.mod.py +++ b/nn/runtime/test/specs/V1_3/squeeze_quant8_signed.mod.py @@ -21,24 +21,16 @@ output = Output("output", "TENSOR_QUANT8_ASYMM_SIGNED", "{1, 24}, 1.0, -128") model = model.Operation("SQUEEZE", i1, squeezeDims).To(output) -# Example 1. Input in operand 0, -input0 = { - i1: # input 0 - [ - -127, -126, -125, -124, -123, -122, -121, -120, -119, -118, -117, - -116, -115, -114, -113, -112, -111, -110, -109, -108, -107, -106, - -105, -104 - ] -} - -output0 = { - output: # output 0 - [ - -127, -126, -125, -124, -123, -122, -121, -120, -119, -118, -117, - -116, -115, -114, -113, -112, -111, -110, -109, -108, -107, -106, - -105, -104 - ] -} +data = [ + -127, -126, -125, -124, -123, -122, -121, -120, -119, -118, -117, -116, -115, -114, -113, -112, + -111, -110, -109, -108, -107, -106, -105, -104 +] # Instantiate an example -Example((input0, output0)) +Example({i1: data, output: data}) + +# Test with omitted squeeze dims +squeezeDims = Parameter("squeezeDims", ["TENSOR_INT32", [0]], value=None) +output = Output("output", "TENSOR_QUANT8_ASYMM_SIGNED", "{24}, 1.0, -128") +Model("omitted").Operation("SQUEEZE", i1, squeezeDims).To(output) +Example({i1: data, output: data}) diff --git a/nn/tools/test_generator/test_generator.py b/nn/tools/test_generator/test_generator.py index 688ce984c..51a822b42 100755 --- a/nn/tools/test_generator/test_generator.py +++ b/nn/tools/test_generator/test_generator.py @@ -372,7 +372,12 @@ class Parameter(Operand): Operand.__init__(self, name, opType, value, backward, skipRenaming=skipRenaming, extraParams=extraParams) self.initializer = NamedVariable(str(self) + "_init") - self.lifetime = "CONSTANT_REFERENCE" if Configuration.useSHM() else "CONSTANT_COPY" + if value is None: + self.lifetime = "NO_VALUE" + elif Configuration.useSHM(): + self.lifetime = "CONSTANT_REFERENCE" + else: + self.lifetime = "CONSTANT_COPY" # A shortcut for parameters of INT32 class Int32Scalar(Parameter, ImplicitParameter): |