Line | Count | Source (jump to first uncovered line) |
1 | | /* Copyright 2023 Google LLC |
2 | | Licensed under the Apache License, Version 2.0 (the "License"); |
3 | | you may not use this file except in compliance with the License. |
4 | | You may obtain a copy of the License at |
5 | | http://www.apache.org/licenses/LICENSE-2.0 |
6 | | Unless required by applicable law or agreed to in writing, software |
7 | | distributed under the License is distributed on an "AS IS" BASIS, |
8 | | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
9 | | See the License for the specific language governing permissions and |
10 | | limitations under the License. |
11 | | */ |
12 | | |
13 | | #include <stdint.h> |
14 | | #include <stdio.h> |
15 | | #include <stdlib.h> |
16 | | |
17 | | #include <fuzzer/FuzzedDataProvider.h> |
18 | | |
19 | | #include <xnnpack.h> |
20 | | |
21 | | #include <algorithm> |
22 | | #include <array> |
23 | | #include <functional> |
24 | | #include <iostream> |
25 | | #include <limits> |
26 | | |
27 | 180 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { |
28 | 180 | FuzzedDataProvider provider(data, size); |
29 | 180 | xnn_status status = xnn_initialize(nullptr); |
30 | 180 | if (status != xnn_status_success) { |
31 | 0 | return 0; |
32 | 0 | } |
33 | | |
34 | | /* Prepare a set of input arrays with fuzzer-generated data */ |
35 | 180 | alignas(16) static std::array<int8_t, 864 + XNN_EXTRA_BYTES / sizeof(int8_t)> |
36 | 180 | w1; |
37 | 180 | alignas(16) static std::array<int32_t, 32 + XNN_EXTRA_BYTES / sizeof(int8_t)> |
38 | 180 | w2; |
39 | 180 | std::generate(w1.begin(), w1.end(), |
40 | 158k | [&]() mutable { return provider.ConsumeIntegral<uint8_t>(); }); |
41 | 180 | std::generate(w2.begin(), w2.end(), |
42 | 8.64k | [&]() mutable { return provider.ConsumeIntegral<uint32_t>(); }); |
43 | | |
44 | 180 | xnn_operator_t op0 = nullptr; |
45 | 180 | status = xnn_create_convolution2d_nhwc_qs8( |
46 | 180 | 0 /* top padding */, 1 /* right padding */, 1 /* bottom padding */, |
47 | 180 | 0 /* left padding */, 3 /* kernel height */, 3 /* kernel width */, |
48 | 180 | 2 /* subsampling height */, 2 /* subsampling width */, |
49 | 180 | 1 /* dilation_height */, 1 /* dilation_width */, 1 /* groups */, |
50 | 180 | 3 /* input channels per group */, 32 /* output_channels_per_group */, |
51 | 180 | 3 /* input pixel stride */, 32 /* output pixel stride */, |
52 | 180 | -1 /* input zero point */, |
53 | 180 | provider.ConsumeFloatingPoint<float>() /* input scale */, |
54 | 180 | provider.ConsumeFloatingPoint<float>() /* kernel scale */, w1.data(), |
55 | 180 | w2.data(), -1 /* output zero point */, |
56 | 180 | provider.ConsumeFloatingPoint<float>() /* output scale */, |
57 | 180 | -126 /* output min */, 126 /* output max */, 0 /* flags */, nullptr, |
58 | 180 | nullptr, &op0); |
59 | | |
60 | 180 | xnn_deinitialize(); |
61 | 180 | return 0; |
62 | 180 | } |