summaryrefslogtreecommitdiff
path: root/nn/runtime/test/fuzzing
diff options
context:
space:
mode:
authorXusong Wang <xusongw@google.com>2020-03-10 11:58:03 -0700
committerXusong Wang <xusongw@google.com>2020-03-12 10:58:19 -0700
commite978068c5f9eda95000ce31c9d7c762a4d6b4923 (patch)
tree5c21c6967b1e2d3c289af3261b14c3d47db09281 /nn/runtime/test/fuzzing
parent8735e145a9f429a1b3ed0db73ec42103f5c51569 (diff)
downloadml-e978068c5f9eda95000ce31c9d7c762a4d6b4923.tar.gz
Resolve or temporarily disable new RGG failures.
This CL made the following changes: - Generate non-zero values for divisors of DIV - Skip float16 accuracy check when golden value is larger than 100. This is because some drivers may produce inf for float16 RSQRT with small values. - Temporarily skip some RGG tests, these failures are tracked by bugs. - Improve debuggability by logging out failing output indexes. Bug: 141704517 Test: NNT_static_fuzzing Change-Id: I4b36fe70c4fa96b4ccb046c7a9886b1b6e511aeb
Diffstat (limited to 'nn/runtime/test/fuzzing')
-rw-r--r--nn/runtime/test/fuzzing/RandomGraphGeneratorUtils.h7
-rw-r--r--nn/runtime/test/fuzzing/TestRandomGraph.cpp17
-rw-r--r--nn/runtime/test/fuzzing/operation_signatures/Broadcast.cpp6
-rw-r--r--nn/runtime/test/fuzzing/operation_signatures/OperationSignatureUtils.h19
4 files changed, 45 insertions, 4 deletions
diff --git a/nn/runtime/test/fuzzing/RandomGraphGeneratorUtils.h b/nn/runtime/test/fuzzing/RandomGraphGeneratorUtils.h
index 5eb41389d..af155a859 100644
--- a/nn/runtime/test/fuzzing/RandomGraphGeneratorUtils.h
+++ b/nn/runtime/test/fuzzing/RandomGraphGeneratorUtils.h
@@ -283,6 +283,13 @@ inline std::enable_if_t<std::is_integral_v<T>, T> getUniform(T lower, T upper) {
std::uniform_int_distribution<T> dis(lower, upper);
return dis(RandomNumberGenerator::generator);
}
+template <typename T>
+inline std::enable_if_t<std::is_integral_v<T>, T> getUniformNonZero(T lower, T upper, T zeroPoint) {
+ if (upper >= zeroPoint) upper--;
+ std::uniform_int_distribution<T> dis(lower, upper);
+ const T value = dis(RandomNumberGenerator::generator);
+ return value >= zeroPoint ? value + 1 : value;
+}
template <typename T>
inline const T& getRandomChoice(const std::vector<T>& choices) {
diff --git a/nn/runtime/test/fuzzing/TestRandomGraph.cpp b/nn/runtime/test/fuzzing/TestRandomGraph.cpp
index 4b051502f..f0e229bcd 100644
--- a/nn/runtime/test/fuzzing/TestRandomGraph.cpp
+++ b/nn/runtime/test/fuzzing/TestRandomGraph.cpp
@@ -195,15 +195,24 @@ class RandomGraphTest : public ::testing::TestWithParam<uint32_t> {
// TODO: Currently quantized buffer values are uniformly distributed within
// [0, 255]. We should investigate on a better buffer value generation
// algorithm that represents the real-world cases.
- "TestRandomGraph_SingleOperationTest_CONV_2D_V1_2_12",
+ "TestRandomGraph_SingleOperationTest_CONV_2D_V1_2_40",
+ // TODO(xusongw): Remove after b/151325288 is resolved.
+ "TestRandomGraph_RandomGraphTest_LargeGraph_TENSOR_FLOAT32_Rank4_9",
+ // TODO(xusongw): Remove after b/151327288 is resolved.
+ "TestRandomGraph_RandomGraphTest_LargeGraph_TENSOR_FLOAT32_Rank1_4",
};
if (kDisabledTests.find(mTestName) != kDisabledTests.end()) return true;
- if (featureLevel >= __ANDROID_API_Q__) return false;
for (const auto& op : mTestModel.main.operations) {
// Skip if testing BATCH_TO_SPACE_ND with batch dimension == 1.
if (op.type == TestOperationType::BATCH_TO_SPACE_ND &&
- mTestModel.main.operands[op.inputs[0]].dimensions[0] == 1)
+ mTestModel.main.operands[op.inputs[0]].dimensions[0] == 1 &&
+ featureLevel <= __ANDROID_API_Q__) {
return true;
+ }
+ // TODO(xusongw): Remove after b/151328024 is resolved.
+ if (op.type == TestOperationType::ROI_ALIGN) {
+ return true;
+ }
}
return false;
}
@@ -236,7 +245,7 @@ class RandomGraphTest : public ::testing::TestWithParam<uint32_t> {
int64_t featureLevel;
ASSERT_EQ(ANeuralNetworksDevice_getFeatureLevel(device, &featureLevel),
ANEURALNETWORKS_NO_ERROR);
- if (shouldSkipTest(featureLevel)) return;
+ if (!isRef && shouldSkipTest(featureLevel)) return;
// Create compilation for device.
test_wrapper::Compilation compilation;
diff --git a/nn/runtime/test/fuzzing/operation_signatures/Broadcast.cpp b/nn/runtime/test/fuzzing/operation_signatures/Broadcast.cpp
index babae5d15..4d380128c 100644
--- a/nn/runtime/test/fuzzing/operation_signatures/Broadcast.cpp
+++ b/nn/runtime/test/fuzzing/operation_signatures/Broadcast.cpp
@@ -60,6 +60,12 @@ static void broadcastOpConstructor(TestOperandType dataType, uint32_t rank, Rand
dataType == TestOperandType::TENSOR_INT32) {
op->inputs[2]->setScalarValue(0);
}
+
+ // TODO(b/151151830): TENSOR_INT32 DIV will crash with 0 as divisor.
+ if (op->opType == TestOperationType::DIV && dataType == TestOperandType::TENSOR_INT32) {
+ op->inputs[1]->doNotConnect = true;
+ op->inputs[1]->finalizer = nonZeroUniformFinalizer;
+ }
}
// For broadcast operations with fused activation.
diff --git a/nn/runtime/test/fuzzing/operation_signatures/OperationSignatureUtils.h b/nn/runtime/test/fuzzing/operation_signatures/OperationSignatureUtils.h
index fbeb96a89..7e7bd333b 100644
--- a/nn/runtime/test/fuzzing/operation_signatures/OperationSignatureUtils.h
+++ b/nn/runtime/test/fuzzing/operation_signatures/OperationSignatureUtils.h
@@ -111,6 +111,14 @@ inline void uniform<bool8>(bool8, bool8, RandomOperand* op) {
uint32_t len = op->getNumberOfElements();
for (uint32_t i = 0; i < len; i++) data[i] = getBernoulli(0.5f);
}
+template <typename T>
+inline void uniformNonZero(T low, T up, T zeroPoint, RandomOperand* op) {
+ T* data = reinterpret_cast<T*>(op->buffer.data());
+ uint32_t len = op->getNumberOfElements();
+ for (uint32_t i = 0; i < len; i++) {
+ data[i] = getUniformNonZero(low, up, zeroPoint);
+ }
+}
// Generate random buffer values with uniform distribution.
// Dispatch to different generators by operand dataType.
@@ -151,6 +159,17 @@ inline void uniformFinalizer(RandomOperand* op) {
}
}
+// Generate non-zero random buffer values with uniform distribution.
+inline void nonZeroUniformFinalizer(RandomOperand* op) {
+ switch (op->dataType) {
+ case TestOperandType::TENSOR_INT32:
+ uniformNonZero<int32_t>(0, 255, op->zeroPoint, op);
+ break;
+ default:
+ NN_FUZZER_CHECK(false) << "Unsupported data type.";
+ }
+}
+
// A helper struct for DEFINE_OPERATION_SIGNATURE macro.
struct OperationSignatureHelper {
std::string name;