1 /*
2 * Copyright (C) 2019 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include "fuzzing/operation_signatures/OperationSignatureUtils.h"
18
19 using namespace std::placeholders;
20
21 namespace android {
22 namespace nn {
23 namespace fuzzing_test {
24
fullyConnectedConstructor(TestOperandType,uint32_t rank,TestHalVersion ver,RandomOperation * op)25 static void fullyConnectedConstructor(TestOperandType, uint32_t rank, TestHalVersion ver,
26 RandomOperation* op) {
27 // Inputs, flattened to [batch_size, input_size]
28 op->inputs[0]->dimensions.resize(rank);
29 RandomVariable numElements = 1;
30 for (uint32_t i = 0; i < rank; i++) {
31 op->inputs[0]->dimensions[i] = RandomVariableType::FREE;
32 numElements = numElements * op->inputs[0]->dimensions[i];
33 }
34
35 // Weights, [num_units, input_size]
36 op->inputs[1]->dimensions = {RandomVariableType::FREE, RandomVariableType::FREE};
37
38 // Bias, [num_units]
39 op->inputs[2]->dimensions = {op->inputs[1]->dimensions[0]};
40
41 // Output, [batch_size, num_units]
42 op->outputs[0]->dimensions = {numElements.exactDiv(op->inputs[1]->dimensions[1]),
43 op->inputs[1]->dimensions[0]};
44
45 setConvFCScale(/*applyOutputScaleBound=*/ver == TestHalVersion::V1_0, op);
46 }
47
DEFINE_OPERATION_SIGNATURE(signature_FULLY_CONNECTED_V1_0)48 DEFINE_OPERATION_SIGNATURE(signature_FULLY_CONNECTED_V1_0){
49 .opType = TestOperationType::FULLY_CONNECTED,
50 .supportedDataTypes = {TestOperandType::TENSOR_FLOAT32,
51 TestOperandType::TENSOR_QUANT8_ASYMM},
52 .supportedRanks = {2, 3, 4},
53 .version = TestHalVersion::V1_0,
54 .inputs = {INPUT_DEFAULT, INPUT_DEFAULT, INPUT_BIAS,
55 PARAMETER_CHOICE(TestOperandType::INT32, 0, 1, 2, 3)},
56 .outputs = {OUTPUT_DEFAULT},
57 .constructor = std::bind(fullyConnectedConstructor, _1, _2, TestHalVersion::V1_0, _3)};
58
DEFINE_OPERATION_SIGNATURE(signature_FULLY_CONNECTED_V1_2)59 DEFINE_OPERATION_SIGNATURE(signature_FULLY_CONNECTED_V1_2){
60 .opType = TestOperationType::FULLY_CONNECTED,
61 .supportedDataTypes = {TestOperandType::TENSOR_QUANT8_ASYMM,
62 TestOperandType::TENSOR_FLOAT16},
63 .supportedRanks = {2, 3, 4},
64 .version = TestHalVersion::V1_2,
65 .inputs = {INPUT_DEFAULT, INPUT_DEFAULT, INPUT_BIAS,
66 PARAMETER_CHOICE(TestOperandType::INT32, 0, 1, 2, 3)},
67 .outputs = {OUTPUT_DEFAULT},
68 .constructor = std::bind(fullyConnectedConstructor, _1, _2, TestHalVersion::V1_2, _3)};
69
DEFINE_OPERATION_SIGNATURE(signature_FULLY_CONNECTED_V1_3)70 DEFINE_OPERATION_SIGNATURE(signature_FULLY_CONNECTED_V1_3){
71 .opType = TestOperationType::FULLY_CONNECTED,
72 .supportedDataTypes = {TestOperandType::TENSOR_QUANT8_ASYMM_SIGNED},
73 .supportedRanks = {2, 3, 4},
74 .version = TestHalVersion::V1_3,
75 .inputs = {INPUT_DEFAULT, INPUT_DEFAULT, INPUT_BIAS,
76 PARAMETER_CHOICE(TestOperandType::INT32, 0, 1, 2, 3)},
77 .outputs = {OUTPUT_DEFAULT},
78 .constructor = std::bind(fullyConnectedConstructor, _1, _2, TestHalVersion::V1_3, _3)};
79
80 } // namespace fuzzing_test
81 } // namespace nn
82 } // namespace android
83