diff options
author | Xusong Wang <xusongw@google.com> | 2020-03-06 14:19:39 -0800 |
---|---|---|
committer | Xusong Wang <xusongw@google.com> | 2020-03-09 16:09:28 -0700 |
commit | 4bceb192ebcb6f9e395d2094af7c4b18a9404384 (patch) | |
tree | 16b04b5ac31951e7a78031850c90d30ffed64b2e /nn/runtime/test/fuzzing | |
parent | d1648f33bd3a5a7a267c916a4e4f697f3638a4b2 (diff) | |
download | ml-4bceb192ebcb6f9e395d2094af7c4b18a9404384.tar.gz |
Add 1.3 new operations to RGG.
Bug: 141704517
Test: NNT_static_fuzzing
Change-Id: Id9a94bc3d2fb1ab24b34baaafdb77d760e0f6d48
Diffstat (limited to 'nn/runtime/test/fuzzing')
4 files changed, 88 insertions, 0 deletions
diff --git a/nn/runtime/test/fuzzing/TestRandomGraph.cpp b/nn/runtime/test/fuzzing/TestRandomGraph.cpp index f4c893314..702f1d5e5 100644 --- a/nn/runtime/test/fuzzing/TestRandomGraph.cpp +++ b/nn/runtime/test/fuzzing/TestRandomGraph.cpp @@ -613,6 +613,18 @@ TEST_SINGLE_OPERATION(ROI_ALIGN, V1_2, kRelaxedCriteria); TEST_SINGLE_OPERATION(ROI_POOLING, V1_2, kRelaxedCriteria); TEST_SINGLE_OPERATION(HEATMAP_MAX_KEYPOINT, V1_2, kRelaxedCriteria); +/*-- NNAPI 1.3 Operations ---------------------------------------------------*/ + +// TODO: The following 1.3 operation signatures are currently not defined: +// - ANEURALNETWORKS_QUANTIZED_LSTM +// - ANEURALNETWORKS_IF +// - ANEURALNETWORKS_WHILE + +TEST_SINGLE_OPERATION(ELU, V1_3, kMediumCriteria); +TEST_SINGLE_OPERATION(HARD_SWISH, V1_3, kMediumCriteria); +TEST_SINGLE_OPERATION(FILL, V1_3, kStrictCriteria); +TEST_SINGLE_OPERATION(RANK, V1_3, kStrictCriteria); + const AccuracyCriteria kSmallGraphCriteria = { .float32 = {.bias = 4e-4f, .mse = 1e-5f, .atol = 1e-2f, .rtol = 1e-2f}, .float16 = {.bias = 5e-2f, .mse = 1e-2f, .atol = 1.0f, .rtol = 1.0f}, diff --git a/nn/runtime/test/fuzzing/operation_signatures/Elementwise.cpp b/nn/runtime/test/fuzzing/operation_signatures/Elementwise.cpp index b85176d2e..d55b7fa6d 100644 --- a/nn/runtime/test/fuzzing/operation_signatures/Elementwise.cpp +++ b/nn/runtime/test/fuzzing/operation_signatures/Elementwise.cpp @@ -42,6 +42,8 @@ DEFINE_ELEMENTWISE_SIGNATURE(LOGISTIC, V1_2, TestOperandType::TENSOR_FLOAT16); DEFINE_ELEMENTWISE_SIGNATURE(RELU, V1_2, TestOperandType::TENSOR_FLOAT16); DEFINE_ELEMENTWISE_SIGNATURE(RELU1, V1_2, TestOperandType::TENSOR_FLOAT16); DEFINE_ELEMENTWISE_SIGNATURE(RELU6, V1_2, TestOperandType::TENSOR_FLOAT16); +DEFINE_ELEMENTWISE_SIGNATURE(HARD_SWISH, V1_3, TestOperandType::TENSOR_FLOAT32, + TestOperandType::TENSOR_FLOAT16, TestOperandType::TENSOR_QUANT8_ASYMM); #define DEFINE_ELEMENTWISE_SIGNATURE_WITH_RANK5(op, ver, ...) \ DEFINE_OPERATION_SIGNATURE(op##_##ver){.opType = TestOperationType::op, \ @@ -155,6 +157,15 @@ DEFINE_CAST_SIGNATURE(V1_2, /*outType=*/TENSOR_INT32, TestOperandType::TENSOR_FL TestOperandType::TENSOR_FLOAT16, TestOperandType::TENSOR_QUANT8_ASYMM, TestOperandType::TENSOR_INT32); +DEFINE_OPERATION_SIGNATURE(ELU_V1_3){ + .opType = TestOperationType::ELU, + .supportedDataTypes = {TestOperandType::TENSOR_FLOAT32, TestOperandType::TENSOR_FLOAT16}, + .supportedRanks = {1, 2, 3, 4, 5}, + .version = TestHalVersion::V1_3, + .inputs = {INPUT_DEFAULT, PARAMETER_FLOAT_RANGE(0.0f, 10.0f)}, + .outputs = {OUTPUT_DEFAULT}, + .constructor = sameDimensionOpConstructor}; + } // namespace fuzzing_test } // namespace nn } // namespace android diff --git a/nn/runtime/test/fuzzing/operation_signatures/OperationSignatureUtils.h b/nn/runtime/test/fuzzing/operation_signatures/OperationSignatureUtils.h index 36efa4712..1dd14fc4d 100644 --- a/nn/runtime/test/fuzzing/operation_signatures/OperationSignatureUtils.h +++ b/nn/runtime/test/fuzzing/operation_signatures/OperationSignatureUtils.h @@ -113,9 +113,11 @@ inline void uniform<bool8>(bool8, bool8, RandomOperand* op) { inline void uniformFinalizer(RandomOperand* op) { switch (op->dataType) { case TestOperandType::TENSOR_FLOAT32: + case TestOperandType::FLOAT32: uniform<float>(kMinFloat32, kMaxFloat32, op); break; case TestOperandType::TENSOR_INT32: + case TestOperandType::INT32: uniform<int32_t>(0, 255, op); break; case TestOperandType::TENSOR_QUANT8_ASYMM: @@ -128,6 +130,7 @@ inline void uniformFinalizer(RandomOperand* op) { uniform<bool8>(true, false, op); break; case TestOperandType::TENSOR_FLOAT16: + case TestOperandType::FLOAT16: uniform<_Float16>(kMinFloat32, kMaxFloat32, op); break; default: @@ -243,6 +246,29 @@ inline void defaultOperandConstructor(TestOperandType dataType, uint32_t, Random } } +inline void defaultScalarOperandConstructor(TestOperandType dataType, uint32_t, RandomOperand* op) { + switch (dataType) { + case TestOperandType::TENSOR_FLOAT32: + op->dataType = TestOperandType::FLOAT32; + op->scale = 0.0f; + op->zeroPoint = 0; + break; + case TestOperandType::TENSOR_FLOAT16: + op->dataType = TestOperandType::FLOAT16; + op->scale = 0.0f; + op->zeroPoint = 0; + break; + case TestOperandType::TENSOR_INT32: + op->dataType = TestOperandType::INT32; + op->scale = 0.0f; + op->zeroPoint = 0; + break; + default: + NN_FUZZER_CHECK(false) << "Data type " << toString(dataType) + << " is not supported in defaultScalarOperandConstructor."; + } +} + // An INPUT operand with uniformly distributed buffer values. The operand's data type is set the // same as the operation's primary data type. In the case of quantized data type, the quantization // parameters are chosen randomly and uniformly. @@ -252,6 +278,14 @@ inline void defaultOperandConstructor(TestOperandType dataType, uint32_t, Random .finalizer = uniformFinalizer \ } +// A scalar operand with an uniformly distributed value. The operand's data type is set to the +// corresponding scalar type of the operation's primary data type (which is always a tensor type). +#define INPUT_SCALAR \ + { \ + .type = RandomOperandType::INPUT, .constructor = defaultScalarOperandConstructor, \ + .finalizer = uniformFinalizer \ + } + // An INPUT operand with a specified data type and uniformly distributed buffer values. In the case // of quantized data type, the quantization parameters are chosen randomly and uniformly. #define INPUT_TYPED(opType) \ diff --git a/nn/runtime/test/fuzzing/operation_signatures/Reshape.cpp b/nn/runtime/test/fuzzing/operation_signatures/Reshape.cpp index 86a9f67c3..e8c5d1ab8 100644 --- a/nn/runtime/test/fuzzing/operation_signatures/Reshape.cpp +++ b/nn/runtime/test/fuzzing/operation_signatures/Reshape.cpp @@ -527,6 +527,37 @@ DEFINE_OPERATION_SIGNATURE(TILE_V1_2){ .outputs = {OUTPUT_DEFAULT}, .constructor = tileConstructor}; +static void fillConstructor(TestOperandType, uint32_t rank, RandomOperation* op) { + op->inputs[0]->dimensions = {rank}; + setFreeDimensions(op->outputs[0], rank); + op->inputs[0]->randomBuffer = op->outputs[0]->dimensions; +} + +DEFINE_OPERATION_SIGNATURE(FILL_V1_3){ + .opType = TestOperationType::FILL, + .supportedDataTypes = {TestOperandType::TENSOR_FLOAT32, TestOperandType::TENSOR_FLOAT16, + TestOperandType::TENSOR_INT32}, + .supportedRanks = {1, 2, 3, 4, 5}, + .version = TestHalVersion::V1_3, + .inputs = {PARAMETER_NONE(TestOperandType::TENSOR_INT32), INPUT_SCALAR}, + .outputs = {OUTPUT_DEFAULT}, + .constructor = fillConstructor}; + +static void rankConstructor(TestOperandType, uint32_t rank, RandomOperation* op) { + setFreeDimensions(op->inputs[0], rank); +} + +DEFINE_OPERATION_SIGNATURE(RANK_V1_3){ + .opType = TestOperationType::RANK, + .supportedDataTypes = {TestOperandType::TENSOR_FLOAT32, TestOperandType::TENSOR_FLOAT16, + TestOperandType::TENSOR_INT32, TestOperandType::TENSOR_QUANT8_ASYMM, + TestOperandType::TENSOR_BOOL8}, + .supportedRanks = {1, 2, 3, 4, 5}, + .version = TestHalVersion::V1_3, + .inputs = {INPUT_DEFAULT}, + .outputs = {OUTPUT_TYPED(TestOperandType::INT32)}, + .constructor = rankConstructor}; + } // namespace fuzzing_test } // namespace nn } // namespace android |