Skip to content

Commit e20f5e0

Browse files
committed
[kernels/quantized] Enable -Werror and fix format specifier warnings
Summary: Enable -Werror for kernels/quantized and fix format specifier mismatches that were causing -Wformat warnings when tensor dimension/size values (int64_t in ATen mode) were formatted with %zd (for ssize_t). Changes: - Add -Werror to _common_compile_options in kernels/quantized/CMakeLists.txt - Replace %zd with ET_PRI_TENSOR_DIM for tensor .dim(), .size(), and .numel() calls in: - op_embedding.cpp - embeddingxb.cpp - op_choose_qparams.cpp - op_quantize.cpp - Fix ET_CHECK_VALID_DIM macro in tensor_util.h to use ET_PRI_TENSOR_DIM ET_PRI_TENSOR_DIM is the portable format specifier macro that adapts to the build mode (PRId64 for ATen mode, "zd" for portable mode). Test Plan: Build with: cmake --build cmake-out -j9 --target quantized_kernels Verify no -Wformat errors with -Werror enabled.
1 parent 4839b28 commit e20f5e0

6 files changed

Lines changed: 32 additions & 32 deletions

File tree

kernels/quantized/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ if(NOT EXECUTORCH_ROOT)
2121
set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../..)
2222
endif()
2323

24-
set(_common_compile_options -Wno-deprecated-declarations)
24+
set(_common_compile_options -Wno-deprecated-declarations -Werror)
2525

2626
include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake)
2727
include(${EXECUTORCH_ROOT}/tools/cmake/Codegen.cmake)

kernels/quantized/cpu/embeddingxb.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,17 @@ void check_embedding_xbit_args(
7272
ET_CHECK_MSG(8 % weight_nbit == 0, "nbit must divide 8");
7373

7474
ET_CHECK_MSG(
75-
weight.dim() == 2, "weight must be 2D but got() %zd dims", weight.dim());
75+
weight.dim() == 2, "weight must be 2D but got() %" ET_PRI_TENSOR_DIM " dims", weight.dim());
7676

7777
ET_CHECK_MSG(
7878
weight_scales.dim() == 1 || weight_scales.dim() == 2,
79-
"weight_scales must be 1D or 2D but got() %zd dims",
79+
"weight_scales must be 1D or 2D but got() %" ET_PRI_TENSOR_DIM " dims",
8080
weight_scales.dim());
8181

8282
ET_CHECK_MSG(
8383
weight_scales.size(0) == weight.size(0),
84-
"Number of scales must be == weight.size(0)=%zd"
85-
", but got %zd",
84+
"Number of scales must be == weight.size(0)=%" ET_PRI_TENSOR_DIM
85+
", but got %" ET_PRI_TENSOR_DIM,
8686
weight_scales.size(0),
8787
weight.size(0));
8888

@@ -91,8 +91,8 @@ void check_embedding_xbit_args(
9191
ET_CHECK_MSG(
9292
// each 8b uint8 column is packed_values_per_byte columns
9393
get_embedding_dim(weight.size(1), weight_nbit) % num_groups == 0,
94-
"Number of groups must divide weight.size(1)=%zd"
95-
", but got # of groups = %zd",
94+
"Number of groups must divide weight.size(1)=%" ET_PRI_TENSOR_DIM
95+
", but got # of groups = %" ET_PRI_TENSOR_DIM,
9696
weight.size(1),
9797
num_groups);
9898
}
@@ -132,8 +132,8 @@ void check_embedding_xbit_args(
132132
ET_CHECK_MSG(
133133
opt_weight_zero_points.value().size(i) == weight_scales.size(i),
134134
"Dimension size misatch at dim %" PRIi32
135-
"Weight_zero_point size = %zd"
136-
", weight_scales size = %zd.",
135+
" Weight_zero_point size = %" ET_PRI_TENSOR_DIM
136+
", weight_scales size = %" ET_PRI_TENSOR_DIM ".",
137137
i,
138138
opt_weight_zero_points.value().size(i),
139139
weight_scales.size(i));

kernels/quantized/cpu/op_choose_qparams.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,23 +63,23 @@ void check_quantize_per_tensor_args(
6363
for (auto i = 0; i < input.dim() - 1; i++) {
6464
ET_CHECK_MSG(
6565
scale_out.size(i) == input.size(i),
66-
"Exepcted scale to have the same number of elements at dimentions %d got %zd",
66+
"Exepcted scale to have the same number of elements at dimentions %d got %" ET_PRI_TENSOR_DIM,
6767
i,
6868
scale_out.size(i));
6969
ET_CHECK_MSG(
7070
zero_point_out.size(i) == input.size(i),
71-
"Exepcted zero pont to have the same number of elements at dimentions %d got %zd",
71+
"Exepcted zero pont to have the same number of elements at dimentions %d got %" ET_PRI_TENSOR_DIM,
7272
i,
7373
zero_point_out.size(i));
7474
}
7575
ET_CHECK_MSG(
7676
scale_out.size(input.dim() - 1) == 1,
77-
"Exepcted scale to have only one element at dimentions %zd but got %zd",
77+
"Exepcted scale to have only one element at dimentions %" ET_PRI_TENSOR_DIM " but got %" ET_PRI_TENSOR_DIM,
7878
input.dim() - 1,
7979
scale_out.size(input.dim() - 1));
8080
ET_CHECK_MSG(
8181
zero_point_out.size(input.dim() - 1) == 1,
82-
"Exepcted zero point to have only one element at dimentions %zd but got %zd",
82+
"Exepcted zero point to have only one element at dimentions %" ET_PRI_TENSOR_DIM " but got %" ET_PRI_TENSOR_DIM,
8383
input.dim() - 1,
8484
zero_point_out.size(input.dim() - 1));
8585
} else {

kernels/quantized/cpu/op_embedding.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,26 +34,26 @@ void check_embedding_byte_args(
3434
std::optional<ScalarType> out_dtype,
3535
Tensor& out) {
3636
ET_CHECK_MSG(
37-
weight.dim() == 2, "weight must be 2D but got() %zd dims", weight.dim());
37+
weight.dim() == 2, "weight must be 2D but got() %" ET_PRI_TENSOR_DIM " dims", weight.dim());
3838

3939
ET_CHECK_MSG(
4040
weight_scales.dim() == 1 || weight_scales.dim() == 2,
41-
"weight_scales must be 1D or 2D but got() %zd dims",
41+
"weight_scales must be 1D or 2D but got() %" ET_PRI_TENSOR_DIM " dims",
4242
weight_scales.dim());
4343

4444
ET_CHECK_MSG(
4545
weight_scales.size(0) == weight.size(0),
46-
"Number of scales must be == weight.size(0)=%zd"
47-
", but got %zd",
46+
"Number of scales must be == weight.size(0)=%" ET_PRI_TENSOR_DIM
47+
", but got %" ET_PRI_TENSOR_DIM,
4848
weight_scales.size(0),
4949
weight.size(0));
5050

5151
if (weight_scales.dim() == 2) {
5252
auto num_groups = weight_scales.size(1);
5353
ET_CHECK_MSG(
5454
weight.size(1) % num_groups == 0,
55-
"Number of groups must divide weight.size(1)=%zd"
56-
", but got # of groups = %zd",
55+
"Number of groups must divide weight.size(1)=%" ET_PRI_TENSOR_DIM
56+
", but got # of groups = %" ET_PRI_TENSOR_DIM,
5757
weight.size(1),
5858
num_groups);
5959
}
@@ -94,8 +94,8 @@ void check_embedding_byte_args(
9494
ET_CHECK_MSG(
9595
opt_weight_zero_points.value().size(i) == weight_scales.size(i),
9696
"Dimension size misatch at dim %" PRIi32
97-
"Weight_zero_point size = %zd"
98-
", weight_scales size = %zd.",
97+
" Weight_zero_point size = %" ET_PRI_TENSOR_DIM
98+
", weight_scales size = %" ET_PRI_TENSOR_DIM ".",
9999
i,
100100
opt_weight_zero_points.value().size(i),
101101
weight_scales.size(i));
@@ -158,14 +158,14 @@ void embedding_byte_per_channel(
158158
ET_CHECK_MSG(
159159
index >= 0 && index < weight.size(0),
160160
"Index out of bounds for weight: index %" PRId64
161-
" must be in range [0, %zd)",
161+
" must be in range [0, %" ET_PRI_TENSOR_DIM ")",
162162
index,
163163
weight.size(0));
164164

165165
ET_CHECK_MSG(
166166
index >= 0 && index < weight_scales.size(0),
167167
"Index out of bounds for weight_scales: index %" PRId64
168-
" must be in range [0, %zd)",
168+
" must be in range [0, %" ET_PRI_TENSOR_DIM ")",
169169
index,
170170
weight_scales.size(0));
171171

kernels/quantized/cpu/op_quantize.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ Tensor& quantize_per_channel_out(
431431

432432
ET_CHECK_MSG(
433433
scale.numel() == input.size(axis),
434-
"scale.numel() %zd != input.size(axis) %zd",
434+
"scale.numel() %" ET_PRI_TENSOR_DIM " != input.size(axis) %" ET_PRI_TENSOR_DIM,
435435
scale.numel(),
436436
input.size(axis));
437437

@@ -442,7 +442,7 @@ Tensor& quantize_per_channel_out(
442442

443443
ET_CHECK_MSG(
444444
zero_point.numel() == input.size(axis),
445-
"zero_point.numel() %zd != input.size(axis) %zd",
445+
"zero_point.numel() %" ET_PRI_TENSOR_DIM " != input.size(axis) %" ET_PRI_TENSOR_DIM,
446446
zero_point.numel(),
447447
input.size(axis));
448448

runtime/core/exec_aten/util/tensor_util.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@
4444
UPPER_BOUND, \
4545
UPPER_BOUND)
4646

47-
#define ET_CHECK_VALID_DIM(DIM, UPPER_BOUND) \
48-
ET_CHECK_MSG( \
49-
DIM >= -static_cast<int64_t>(UPPER_BOUND) && \
50-
DIM < static_cast<int64_t>(UPPER_BOUND), \
51-
"dim %" PRId64 " must be within range [-%zd, %zd)", \
52-
DIM, \
53-
UPPER_BOUND, \
47+
#define ET_CHECK_VALID_DIM(DIM, UPPER_BOUND) \
48+
ET_CHECK_MSG( \
49+
DIM >= -static_cast<int64_t>(UPPER_BOUND) && \
50+
DIM < static_cast<int64_t>(UPPER_BOUND), \
51+
"dim %" PRId64 " must be within range [-%" ET_PRI_TENSOR_DIM ", %" ET_PRI_TENSOR_DIM ")", \
52+
DIM, \
53+
UPPER_BOUND, \
5454
UPPER_BOUND)
5555

5656
#define ET_CHECK_NON_ZERO_DIM_SIZE(DIM, T) \

0 commit comments

Comments
 (0)