Skip to content

Commit a89f1b4

Browse files
committed
Arm backend: Enable CPPCHECK for Cortex-M
Enable CPPCHECK for Cortex-M sources and headers. The Cortex-M kernels are registered through generated wrappers, so cppcheck cannot see direct call sites for the exported *_out entry points and reports them as unused. Keep narrow unusedFunction suppressions for those registration-visible functions. The scratch buffer context header is linted as a standalone header but currently exposes helper API without in-tree call sites, so suppress unusedFunction at file scope there instead of dropping Cortex-M header coverage. Keep the quantize and dequantize context parameters non-const to match the generated kernel ABI; changing them to const changes the mangled symbols used by registration. Signed-off-by: Per Held <per.held@arm.com> Change-Id: I3bcb6e5d3f125ae400005d1b033b24a07eb7924f
1 parent c5e3e2b commit a89f1b4

19 files changed

Lines changed: 25 additions & 8 deletions

.lintrunner.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ include_patterns = [
112112
'backends/arm/**/*.cpp',
113113
'backends/arm/**/*.h',
114114
'backends/arm/**/*.hpp',
115+
'backends/cortex_m/**/*.cpp',
116+
'backends/cortex_m/**/*.h',
115117
'examples/arm/**/*.cpp',
116118
'examples/arm/**/*.h',
117119
'examples/arm/**/*.hpp',

backends/cortex_m/ops/cmsis_scratch_buffer_context.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// cppcheck-suppress-file unusedFunction
12
/*
23
* Copyright (c) Meta Platforms, Inc. and affiliates.
34
* All rights reserved.

backends/cortex_m/ops/cortex_m_ops_common.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,7 @@ inline void validate_quantization_params(
113113
const int64_t shift2,
114114
const int64_t output_zero_point,
115115
const int64_t output_multiplier,
116-
const int64_t output_shift,
117-
Tensor& output) {
116+
const int64_t output_shift) {
118117
validate_single_quant_params(
119118
zero_point1, multiplier1, shift1, "Single quant Input1");
120119
validate_single_quant_params(
@@ -346,6 +345,7 @@ inline bool prepare_cmsis_pool2d_config(
346345
// https://github.com/ARM-software/CMSIS-NN/blob/main/Include/arm_nnsupportfunctions.h#L1625
347346
// multiplier: Range {ARM_NN_Q31_MIN + 1, Q32_MAX}
348347
// shift : Range {-31, 30}
348+
// cppcheck-suppress unusedFunction
349349
inline bool validate_per_channel_quant_params(
350350
const Int64ArrayRef multipliers,
351351
const Int64ArrayRef shifts,

backends/cortex_m/ops/op_dequantize_per_tensor.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ F dequantize_val(float scale, int32_t zero_point, Q qvalue) {
100100
} // namespace
101101

102102
Tensor& dequantize_per_tensor_out(
103+
// cppcheck-suppress constParameterReference
103104
KernelRuntimeContext& context,
104105
const Tensor& input,
105106
double scale,

backends/cortex_m/ops/op_maximum.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2025 Arm Limited and/or its affiliates.
2+
* Copyright 2025-2026 Arm Limited and/or its affiliates.
33
*
44
* This source code is licensed under the BSD-style license found in the
55
* LICENSE file in the root directory of this source tree.
@@ -12,6 +12,7 @@ namespace native {
1212

1313
using KernelRuntimeContext = torch::executor::KernelRuntimeContext;
1414

15+
// cppcheck-suppress unusedFunction
1516
Tensor& maximum_out(
1617
KernelRuntimeContext& context,
1718
const Tensor& input1,

backends/cortex_m/ops/op_minimum.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* Copyright (c) Meta Platforms, Inc. and affiliates.
33
* All rights reserved.
4-
* Copyright 2025 Arm Limited and/or its affiliates.
4+
* Copyright 2025-2026 Arm Limited and/or its affiliates.
55
*
66
* This source code is licensed under the BSD-style license found in the
77
* LICENSE file in the root directory of this source tree.
@@ -14,6 +14,7 @@ namespace native {
1414

1515
using KernelRuntimeContext = torch::executor::KernelRuntimeContext;
1616

17+
// cppcheck-suppress unusedFunction
1718
Tensor& minimum_out(
1819
KernelRuntimeContext& context,
1920
const Tensor& input1,

backends/cortex_m/ops/op_pad.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ constexpr size_t kMaxSupportedDims = 4;
1919

2020
} // namespace
2121

22+
// cppcheck-suppress unusedFunction
2223
Tensor& pad_out(
2324
KernelRuntimeContext& context,
2425
const Tensor& input,

backends/cortex_m/ops/op_quantize_per_tensor.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ Q quantize_val(
9797
} // namespace
9898

9999
Tensor& quantize_per_tensor_out(
100+
// cppcheck-suppress constParameterReference
100101
KernelRuntimeContext& context,
101102
const Tensor& input,
102103
double scale,

backends/cortex_m/ops/op_quantized_add.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ namespace cortex_m {
1313
namespace native {
1414
using KernelRuntimeContext = torch::executor::KernelRuntimeContext;
1515

16+
// cppcheck-suppress unusedFunction
1617
Tensor& quantized_add_out(
1718
KernelRuntimeContext& context,
1819
const Tensor& input1_int8,
@@ -49,8 +50,7 @@ Tensor& quantized_add_out(
4950
input2_shift,
5051
output_zero_point,
5152
output_multiplier,
52-
output_shift,
53-
out);
53+
output_shift);
5454

5555
ET_LOG(
5656
Debug,

backends/cortex_m/ops/op_quantized_avg_pool2d.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ namespace native {
1212

1313
using KernelRuntimeContext = torch::executor::KernelRuntimeContext;
1414

15+
// cppcheck-suppress unusedFunction
1516
Tensor& quantized_avg_pool2d_out(
1617
KernelRuntimeContext& context,
1718
const Tensor& input,

0 commit comments

Comments
 (0)