From b3e022a79652050692b6b52b1850069a3e51706f Mon Sep 17 00:00:00 2001 From: Jake Stevens Date: Mon, 3 Mar 2025 07:48:30 -0800 Subject: [PATCH] Address various warnings as errors (#8581) Summary: Pull Request resolved: https://github.com/pytorch/executorch/pull/8581 Some projects uses more restrictive build options than currently used in ET CI. This means we encountered a number of errors when enabling for a microcontroller. Reviewed By: digantdesai, swolchok Differential Revision: D69139962 --- extension/threadpool/cpuinfo_utils.cpp | 7 ++-- extension/threadpool/targets.bzl | 1 + .../portable/cpu/op__to_dim_order_copy.cpp | 6 ++- kernels/portable/cpu/op_amax.cpp | 3 +- kernels/portable/cpu/op_amin.cpp | 4 +- kernels/portable/cpu/op_argmax.cpp | 3 +- kernels/portable/cpu/op_argmin.cpp | 3 +- kernels/portable/cpu/op_expand_copy.cpp | 3 +- .../portable/cpu/util/activation_ops_util.cpp | 2 +- kernels/portable/cpu/util/broadcast_util.cpp | 6 ++- kernels/portable/cpu/util/copy_ops_util.h | 7 ++-- kernels/portable/cpu/util/functional_util.h | 8 ++-- kernels/portable/cpu/util/reduce_util.cpp | 19 ++++----- kernels/portable/cpu/util/reduce_util.h | 4 +- kernels/portable/cpu/util/repeat_util.cpp | 17 ++++---- kernels/portable/cpu/util/targets.bzl | 2 - kernels/prim_ops/et_view.cpp | 3 +- runtime/core/data_loader.h | 12 +++--- runtime/core/exec_aten/util/dim_order_util.h | 18 ++++----- .../util/tensor_shape_to_c_string.cpp | 4 +- runtime/core/exec_aten/util/tensor_util.h | 32 +++++++++------ .../exec_aten/util/tensor_util_portable.cpp | 17 ++++---- .../core/portable_type/c10/c10/util/irange.h | 2 +- runtime/core/portable_type/tensor_impl.cpp | 8 ++-- runtime/core/tensor_layout.cpp | 2 +- runtime/executor/method.cpp | 40 +++++++++++-------- runtime/executor/method_meta.cpp | 20 +++++----- runtime/executor/program.cpp | 22 +++++----- runtime/executor/targets.bzl | 4 ++ runtime/executor/tensor_parser.h | 2 +- runtime/executor/tensor_parser_exec_aten.cpp | 11 +++-- runtime/executor/tensor_parser_portable.cpp | 6 +-- runtime/kernel/operator_registry.cpp | 4 +- runtime/kernel/operator_registry.h | 4 +- runtime/platform/log.cpp | 3 +- runtime/platform/log.h | 9 +++++ runtime/platform/profiler.cpp | 6 ++- schema/extended_header.cpp | 2 - test/build_size_test.sh | 3 +- 39 files changed, 186 insertions(+), 143 deletions(-) diff --git a/extension/threadpool/cpuinfo_utils.cpp b/extension/threadpool/cpuinfo_utils.cpp index 5dc3fa7fae5..21862fbd4aa 100644 --- a/extension/threadpool/cpuinfo_utils.cpp +++ b/extension/threadpool/cpuinfo_utils.cpp @@ -6,6 +6,7 @@ * LICENSE file in the root directory of this source tree. */ +#include #include #include @@ -84,7 +85,7 @@ bool populate_available_cpu_mids() { cpu_midrs->resize(num_possible_cores); const std::string kMidrFilePathPrefix = "/sys/devices/system/cpu/cpu"; const std::string kMidrFilePathSuffix = "/regs/identification/midr_el1"; - for (int32_t i = 0; i < num_possible_cores; ++i) { + for (const auto i : c10::irange(num_possible_cores)) { std::string midr_file_path = kMidrFilePathPrefix + std::to_string(i) + kMidrFilePathSuffix; ET_LOG(Info, "Reading file %s", midr_file_path.c_str()); @@ -115,7 +116,7 @@ uint32_t _get_num_performant_cores() { ET_LOG(Info, "CPU info and manual query on # of cpus dont match."); return 0; } - for (int32_t i = 0; i < cpu_midrs->size(); ++i) { + for (const auto i : c10::irange(cpu_midrs->size())) { uint32_t masked_midr = (*cpu_midrs)[i] & RIVISION_MASK; switch (masked_midr) { case CPUINFO_ARM_MIDR_CORTEX_A520: @@ -148,7 +149,7 @@ uint32_t get_num_performant_cores() { uint32_t num_possible_cores = cpuinfo_get_processors_count(); uint32_t num_non_performant_core = 0; if (uarch_count > 1) { - for (int32_t i = 0; i < uarch_count; ++i) { + for (const auto i : c10::irange(uarch_count)) { const struct cpuinfo_uarch_info* uarch_info = cpuinfo_get_uarch(i); if (is_non_performant_core(uarch_info)) { num_non_performant_core += uarch_info->processor_count; diff --git a/extension/threadpool/targets.bzl b/extension/threadpool/targets.bzl index 4a7185ce972..8bb0398b385 100644 --- a/extension/threadpool/targets.bzl +++ b/extension/threadpool/targets.bzl @@ -23,6 +23,7 @@ def define_common_targets(): srcs = _THREADPOOL_SRCS, deps = [ "//executorch/runtime/core:core", + "//executorch/runtime/core/portable_type/c10/c10:c10", ], exported_headers = _THREADPOOL_HEADERS, exported_deps = [ diff --git a/kernels/portable/cpu/op__to_dim_order_copy.cpp b/kernels/portable/cpu/op__to_dim_order_copy.cpp index efb74e3a01f..40ce86e8fdc 100644 --- a/kernels/portable/cpu/op__to_dim_order_copy.cpp +++ b/kernels/portable/cpu/op__to_dim_order_copy.cpp @@ -6,6 +6,8 @@ * LICENSE file in the root directory of this source tree. */ +#include + #include #include #include @@ -41,7 +43,7 @@ int64_t coordinateToIndexWithDimOrder( dim_order_to_stride_nocheck( sizes.data(), dim_order.data(), sizes.size(), strides); - for (size_t i = 0; i < self.dim(); ++i) { + for (const auto i : c10::irange(self.dim())) { index += cur_indices[i] * strides[i]; } return index; @@ -59,7 +61,7 @@ void _to_dim_order_copy_impl(const Tensor& self, Tensor& out) { for (ssize_t i = 0; i < self.numel(); i++) { // Update the current indices. for (ssize_t j = self.dim() - 1; j >= 0; j--) { - if (coordinate[j] + 1 < self.size(j)) { + if (coordinate[j] + 1 < static_cast(self.size(j))) { coordinate[j]++; break; } else { diff --git a/kernels/portable/cpu/op_amax.cpp b/kernels/portable/cpu/op_amax.cpp index 9f879179ec6..d36f416c7b4 100644 --- a/kernels/portable/cpu/op_amax.cpp +++ b/kernels/portable/cpu/op_amax.cpp @@ -6,6 +6,7 @@ * LICENSE file in the root directory of this source tree. */ +#include #include #include @@ -44,7 +45,7 @@ Tensor& amax_out( ET_SWITCH_REALHBBF16_TYPES(in.scalar_type(), ctx, "amax.out", CTYPE, [&]() { CTYPE* out_data = out.mutable_data_ptr(); - for (size_t out_ix = 0; out_ix < out.numel(); ++out_ix) { + for (const auto out_ix : c10::irange(out.numel())) { out_data[out_ix] = reduce_over_dim_list( [](CTYPE v, CTYPE max_v) { return std::isnan(v) || v > max_v ? v : max_v; diff --git a/kernels/portable/cpu/op_amin.cpp b/kernels/portable/cpu/op_amin.cpp index 4f6f3ce52e5..7c4c8186e59 100644 --- a/kernels/portable/cpu/op_amin.cpp +++ b/kernels/portable/cpu/op_amin.cpp @@ -5,7 +5,7 @@ * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. */ - +#include #include #include @@ -44,7 +44,7 @@ Tensor& amin_out( ET_SWITCH_REALHBBF16_TYPES(in.scalar_type(), ctx, "amin.out", CTYPE, [&]() { CTYPE* out_data = out.mutable_data_ptr(); - for (size_t out_ix = 0; out_ix < out.numel(); ++out_ix) { + for (const auto out_ix : c10::irange(out.numel())) { out_data[out_ix] = reduce_over_dim_list( [](CTYPE v, CTYPE min_v) { return std::isnan(v) || v < min_v ? v : min_v; diff --git a/kernels/portable/cpu/op_argmax.cpp b/kernels/portable/cpu/op_argmax.cpp index 5eb656d5b76..39ad0171d5d 100644 --- a/kernels/portable/cpu/op_argmax.cpp +++ b/kernels/portable/cpu/op_argmax.cpp @@ -6,6 +6,7 @@ * LICENSE file in the root directory of this source tree. */ +#include #include #include @@ -46,7 +47,7 @@ Tensor& argmax_out( ET_SWITCH_REALHBF16_TYPES(in.scalar_type(), ctx, "argmax.out", CTYPE, [&] { long* out_data = out.mutable_data_ptr(); - for (size_t out_ix = 0; out_ix < out.numel(); ++out_ix) { + for (const auto out_ix : c10::irange(out.numel())) { std::tuple acc = reduce_over_dim( [](CTYPE v, long ix, CTYPE acc_val, long acc_ix) { if (!std::isnan(acc_val) && (std::isnan(v) || v > acc_val)) { diff --git a/kernels/portable/cpu/op_argmin.cpp b/kernels/portable/cpu/op_argmin.cpp index 1c4a2572ea8..8148efa6264 100644 --- a/kernels/portable/cpu/op_argmin.cpp +++ b/kernels/portable/cpu/op_argmin.cpp @@ -6,6 +6,7 @@ * LICENSE file in the root directory of this source tree. */ +#include #include #include @@ -46,7 +47,7 @@ Tensor& argmin_out( ET_SWITCH_REALHBF16_TYPES(in.scalar_type(), ctx, "argmin.out", CTYPE, [&] { long* out_data = out.mutable_data_ptr(); - for (size_t out_ix = 0; out_ix < out.numel(); ++out_ix) { + for (const auto out_ix : c10::irange(out.numel())) { std::tuple acc = reduce_over_dim( [](CTYPE v, long ix, CTYPE acc_val, long acc_ix) { if (!std::isnan(acc_val) && (std::isnan(v) || v < acc_val)) { diff --git a/kernels/portable/cpu/op_expand_copy.cpp b/kernels/portable/cpu/op_expand_copy.cpp index f1a7bfbf1fb..6c8685dd867 100644 --- a/kernels/portable/cpu/op_expand_copy.cpp +++ b/kernels/portable/cpu/op_expand_copy.cpp @@ -96,7 +96,8 @@ Tensor& expand_copy_out( ET_KERNEL_CHECK( ctx, - repeat_tensor(self, {repeats, repeats_size}, out) == Error::Ok, + repeat_tensor(self, makeArrayRef(repeats, repeats_size), out) == + Error::Ok, InvalidArgument, out); diff --git a/kernels/portable/cpu/util/activation_ops_util.cpp b/kernels/portable/cpu/util/activation_ops_util.cpp index fe26d4fda04..abde15f8740 100644 --- a/kernels/portable/cpu/util/activation_ops_util.cpp +++ b/kernels/portable/cpu/util/activation_ops_util.cpp @@ -31,7 +31,7 @@ bool check_glu_args(const Tensor& in, int64_t dim, Tensor& out) { ET_LOG_AND_RETURN_IF_FALSE(tensor_is_floating_type(in)); const size_t non_negative_dim = dim < 0 ? dim + in.dim() : dim; - const size_t dim_size = in.size(non_negative_dim); + const ssize_t dim_size = in.size(non_negative_dim); ET_CHECK_OR_RETURN_FALSE( dim_size % 2 == 0, diff --git a/kernels/portable/cpu/util/broadcast_util.cpp b/kernels/portable/cpu/util/broadcast_util.cpp index d8569d23c2f..381e07cbe30 100644 --- a/kernels/portable/cpu/util/broadcast_util.cpp +++ b/kernels/portable/cpu/util/broadcast_util.cpp @@ -6,6 +6,7 @@ * LICENSE file in the root directory of this source tree. */ +#include #include #include #include @@ -274,7 +275,7 @@ void delinearize_index( size_t* out_indexes, const size_t out_indexes_len) { ET_CHECK(shape.size() <= out_indexes_len); - for (auto i = 0; i < shape.size(); ++i) { + for (size_t i = 0; i < shape.size(); ++i) { auto dim = shape.size() - 1 - i; auto dim_size = shape[dim]; out_indexes[dim] = linear_index % dim_size; @@ -304,7 +305,8 @@ size_t linearize_access_indexes( size_t linear_index = 0; for (size_t i = 0; i < indexes_broadcast_from.size(); ++i) { // If this dimension is broadcasted, add zero to the linear address. - if (indexes_broadcast_from[i] >= broadcast_from_shape[i]) { + if (indexes_broadcast_from[i] >= + static_cast(broadcast_from_shape[i])) { ET_CHECK_MSG( broadcast_from_shape[i] == 1, "Expected dim size == 1 if broadcasted, but actual dim size is %zu", diff --git a/kernels/portable/cpu/util/copy_ops_util.h b/kernels/portable/cpu/util/copy_ops_util.h index 8efd6057dba..e7399ae0956 100644 --- a/kernels/portable/cpu/util/copy_ops_util.h +++ b/kernels/portable/cpu/util/copy_ops_util.h @@ -7,6 +7,7 @@ */ #pragma once +#include #include @@ -26,8 +27,8 @@ void _as_strided_copy( ArrayRef stride, int64_t dim) { // the last dimension, copy data - if (dim == size.size() - 1) { - for (size_t i = 0; i < size.at(dim); ++i) { + if (dim == static_cast(size.size()) - 1) { + for (const auto i : c10::irange(size.at(dim))) { output_data[i] = *input_data; input_data += stride.at(dim); } @@ -35,7 +36,7 @@ void _as_strided_copy( } size_t trailing_dims = getTrailingDims(out, dim); // recursively set data for the next dimension - for (size_t i = 0; i < size.at(dim); ++i) { + for ([[maybe_unused]] const auto i : c10::irange(size.at(dim))) { _as_strided_copy( input_data, output_data, out, size, stride, dim + 1); input_data += stride.at(dim); diff --git a/kernels/portable/cpu/util/functional_util.h b/kernels/portable/cpu/util/functional_util.h index cdf90813772..609a1a26fa5 100644 --- a/kernels/portable/cpu/util/functional_util.h +++ b/kernels/portable/cpu/util/functional_util.h @@ -8,6 +8,8 @@ #pragma once +#include + #include #include @@ -30,7 +32,7 @@ inline CTYPE apply_unary_reduce_fn( const int64_t size, const int64_t stride = 1) { CTYPE acc_val = data_in[0]; - for (size_t i = 1; i < size; i++) { + for (const auto i : c10::irange(1, size)) { acc_val = reduce_fun(data_in[i * stride], acc_val); } return acc_val; @@ -51,7 +53,7 @@ inline void apply_unary_map_fn( CTYPE_OUT* const data_out, const int64_t size, const int64_t stride = 1) { - for (size_t i = 0; i < size; i++) { + for (const auto i : c10::irange(size)) { data_out[i * stride] = map_fun(data_in[i * stride]); } } @@ -77,7 +79,7 @@ inline CTYPE_OUT apply_unary_map_reduce_fn( const int64_t size, const int64_t stride = 1) { CTYPE_OUT acc_val = map_fun(data_in[0]); - for (size_t i = 1; i < size; ++i) { + for (const auto i : c10::irange(1, size)) { acc_val = reduce_fun(map_fun(data_in[i * stride]), acc_val); } return acc_val; diff --git a/kernels/portable/cpu/util/reduce_util.cpp b/kernels/portable/cpu/util/reduce_util.cpp index 2902cbfc138..09ba508a31d 100644 --- a/kernels/portable/cpu/util/reduce_util.cpp +++ b/kernels/portable/cpu/util/reduce_util.cpp @@ -48,8 +48,7 @@ ET_NODISCARD bool check_dim_list_is_valid( } const size_t non_neg_d = _normalize_non_neg_d(d, in.dim()); - ET_LOG_AND_RETURN_IF_FALSE( - non_neg_d < kTensorDimensionLimit && non_neg_d >= 0); + ET_LOG_AND_RETURN_IF_FALSE(non_neg_d < kTensorDimensionLimit); ET_CHECK_OR_RETURN_FALSE( dim_exist[non_neg_d] == false, @@ -86,7 +85,7 @@ size_t get_reduced_dim_product( } size_t dim_product = 1; if (!dim.has_value()) { - for (size_t i = 0; i < in.dim(); ++i) { + for (size_t i = 0; i < static_cast(in.dim()); ++i) { dim_product *= in.size(i); } return dim_product; @@ -108,7 +107,7 @@ size_t get_reduced_dim_product( size_t dim_product = 1; const size_t in_dim = in.dim(); if (!dim_list.has_value() || dim_list.value().size() == 0) { - for (size_t i = 0; i < in.dim(); ++i) { + for (size_t i = 0; i < static_cast(in.dim()); ++i) { dim_product *= in.size(i); } return dim_product; @@ -136,7 +135,7 @@ size_t get_out_numel( ET_CHECK_VALID_DIM(dim_val, in.dim()); } const size_t non_neg_dim = _normalize_non_neg_d(dim_val, in.dim()); - for (size_t d = 0; d < in.dim(); ++d) { + for (size_t d = 0; d < static_cast(in.dim()); ++d) { if (d != non_neg_dim) { out_numel *= in.size(d); } @@ -155,7 +154,7 @@ size_t get_out_numel( dim_list) { size_t out_numel = 1; if (dim_list.has_value() && dim_list.value().size() != 0) { - for (size_t d = 0; d < in.dim(); ++d) { + for (size_t d = 0; d < static_cast(in.dim()); ++d) { if (!check_dim_in_dim_list(d, in.dim(), dim_list.value())) { out_numel *= in.size(d); } @@ -234,7 +233,7 @@ size_t compute_reduced_out_size( if (dim.has_value()) { const auto dim_val = dim.value(); const size_t non_neg_dim = _normalize_non_neg_d(dim_val, in_dim); - for (ssize_t i = 0; i < non_neg_dim; ++i) { + for (size_t i = 0; i < non_neg_dim; ++i) { sizes_arr[i] = in.size(i); } if (keepdim) { @@ -250,7 +249,7 @@ size_t compute_reduced_out_size( } } else { if (keepdim) { - for (size_t i = 0; i < in_dim; ++i) { + for (size_t i = 0; i < static_cast(in_dim); ++i) { sizes_arr[i] = 1; } } else { @@ -266,7 +265,9 @@ size_t compute_reduced_out_size( dim_list, bool keepdim, executorch::aten::SizesType* sizes_arr) { - const auto in_dim = in.dim(); + // check_dim_in_dim_list and later comparisons + // expect in_dim to be size_t, so cast it here + const size_t in_dim = static_cast(in.dim()); size_t out_dim = in_dim; if (dim_list.has_value() && dim_list.value().size() != 0) { diff --git a/kernels/portable/cpu/util/reduce_util.h b/kernels/portable/cpu/util/reduce_util.h index 25a2c0b44c4..35cfdfbaa72 100644 --- a/kernels/portable/cpu/util/reduce_util.h +++ b/kernels/portable/cpu/util/reduce_util.h @@ -50,7 +50,7 @@ void apply_on_flat_ix_with_dim_mask_and_base( const size_t start, const size_t end) { // Compute innermost dim from dim list - size_t inner_dim = in.dim() - 1; + int64_t inner_dim = in.dim() - 1; while (!dim_mask[inner_dim]) { inner_dim--; } @@ -58,7 +58,7 @@ void apply_on_flat_ix_with_dim_mask_and_base( // Initialize array of indices per dimension. This array is used to maintain // the per-dimension index of the element in `in` that is being reduced over // Only the dims that are in the dim list are relevant. - size_t dim_index[kTensorDimensionLimit]; + int64_t dim_index[kTensorDimensionLimit]; for (int64_t d = 0; d < in.dim(); d++) { dim_index[d] = 0; } diff --git a/kernels/portable/cpu/util/repeat_util.cpp b/kernels/portable/cpu/util/repeat_util.cpp index 925fda9f793..be7231cb621 100644 --- a/kernels/portable/cpu/util/repeat_util.cpp +++ b/kernels/portable/cpu/util/repeat_util.cpp @@ -8,6 +8,7 @@ #include +#include #include #include #include @@ -26,7 +27,7 @@ bool check_repeat_args( Tensor& out) { // Ensure the self tensors list is non-empty. ET_CHECK_OR_RETURN_FALSE( - repeats.size() >= self.dim(), + static_cast(repeats.size()) >= self.dim(), "Number of dimensions of repeat dims can not be smaller than number of dimensions of tensor"); // Repeat arrayref shall not contain negative element. @@ -39,7 +40,7 @@ bool check_repeat_args( /// Check if out.size() is legal. ET_CHECK_OR_RETURN_FALSE( - out.dim() == repeats.size(), + static_cast(out.dim()) == repeats.size(), "The dimension of out shall equal size of repeats, but now is %zd and %zd", out.dim(), repeats.size()); @@ -48,7 +49,7 @@ bool check_repeat_args( // kTensorDimensionLimit. Only check out tensor because the number of // dimension of out tensor shall have more than or equal to self tensor ET_CHECK_OR_RETURN_FALSE( - out.dim() <= kTensorDimensionLimit, + static_cast(out.dim()) <= kTensorDimensionLimit, "The dimension of input and output should not be larger than %zd", kTensorDimensionLimit); @@ -58,7 +59,7 @@ bool check_repeat_args( // repeats, and called it reformat_self_size. We then make point-to-point mul // of reformat_self_size and repeats. The result should equal out.size(). size_t reformat_self_size[kTensorDimensionLimit]; - for (size_t i = 0; i < out.dim() - self.dim(); i++) { + for (ssize_t i = 0; i < out.dim() - self.dim(); i++) { reformat_self_size[i] = 1; } @@ -131,7 +132,7 @@ void repeat_internal( // The increment along index of slot array to reach the next possible valid // value. int64_t incr[kTensorDimensionLimit]; - for (size_t i = 0; i < self_dim; i++) { + for (size_t i = 0; i < static_cast(self_dim); i++) { incr[i] = self_size[i]; } @@ -141,7 +142,7 @@ void repeat_internal( // than self). size_t index = self_dim - 1; size_t start = out.dim() - self_dim; - while (slots[0] != out.size(start)) { + while (slots[0] != static_cast(out.size(start))) { // Compute the offset (from origin) in the out tensor where this self // data will be copied to. size_t offset = compute_access_offset(slots, strides, self_dim); @@ -151,7 +152,7 @@ void repeat_internal( slots[index] += incr[index]; // If we have reached the limit in the innermost dimension, successively // increment the slot index of outer dimensions. - while (slots[index] == out.size(start + index)) { + while (slots[index] == static_cast(out.size(start + index))) { if (index == 0) { break; } @@ -227,7 +228,7 @@ Error repeat_tensor( // so we reset the upper bound of innermost dim to 1. 'in_incr' indicates // the size (in bytes) of the self data. int64_t limits[kTensorDimensionLimit]; - for (size_t i = 0; i < self_dim; i++) { + for (ssize_t i = 0; i < self_dim; i++) { limits[i] = self_size[i]; } diff --git a/kernels/portable/cpu/util/targets.bzl b/kernels/portable/cpu/util/targets.bzl index eef765d5eec..2b22687274f 100644 --- a/kernels/portable/cpu/util/targets.bzl +++ b/kernels/portable/cpu/util/targets.bzl @@ -61,7 +61,6 @@ def define_common_targets(): "//executorch/runtime/core/exec_aten/util:scalar_type_util", "//executorch/runtime/core/exec_aten/util:tensor_util", ], - compiler_flags = ["-Wno-missing-prototypes"], visibility = ["//executorch/kernels/portable/cpu/..."], ) @@ -71,7 +70,6 @@ def define_common_targets(): exported_headers = [ "broadcast_util.h", ], - compiler_flags = ["-Wno-missing-prototypes"], deps = [ ":repeat_util", "//executorch/runtime/kernel:kernel_includes", diff --git a/kernels/prim_ops/et_view.cpp b/kernels/prim_ops/et_view.cpp index 0f041dae00f..7f66bca1725 100644 --- a/kernels/prim_ops/et_view.cpp +++ b/kernels/prim_ops/et_view.cpp @@ -32,7 +32,8 @@ bool get_view_target_size( executorch::aten::ArrayRef size, int64_t dim, executorch::aten::SizesType* out_size) { - ET_LOG_AND_RETURN_IF_FALSE(size.size() == dim); + ET_LOG_AND_RETURN_IF_FALSE( + dim >= 0 && size.size() == static_cast(dim)); int minus1_dim = -1; int n_zero = 0; int64_t numel_without_minus_1 = 1; diff --git a/runtime/core/data_loader.h b/runtime/core/data_loader.h index 45fd1bc8189..3dda5516908 100644 --- a/runtime/core/data_loader.h +++ b/runtime/core/data_loader.h @@ -69,12 +69,12 @@ class DataLoader { SegmentInfo() = default; explicit SegmentInfo( - Type segment_type, - size_t segment_index = 0, - const char* descriptor = nullptr) - : segment_type(segment_type), - segment_index(segment_index), - descriptor(descriptor) {} + Type segment_type_, + size_t segment_index_ = 0, + const char* descriptor_ = nullptr) + : segment_type(segment_type_), + segment_index(segment_index_), + descriptor(descriptor_) {} }; virtual ~DataLoader() = default; diff --git a/runtime/core/exec_aten/util/dim_order_util.h b/runtime/core/exec_aten/util/dim_order_util.h index 7a31db9d6ad..07b3d5c2a97 100644 --- a/runtime/core/exec_aten/util/dim_order_util.h +++ b/runtime/core/exec_aten/util/dim_order_util.h @@ -23,8 +23,8 @@ namespace runtime { namespace { template bool validate_dim_order(const DimOrderType* dim_order, const size_t dims) { - for (int32_t i = 0; i < dims; ++i) { - if (dim_order[i] >= dims) { + for (size_t i = 0; i < dims; ++i) { + if (dim_order[i] >= static_cast(dims)) { return false; } } @@ -43,8 +43,8 @@ template inline bool is_contiguous_dim_order( const DimOrderType* dim_order, const size_t dims) { - for (int i = 0; i < dims; ++i) { - if (dim_order[i] != i) { + for (size_t i = 0; i < dims; ++i) { + if (dim_order[i] != static_cast(i)) { return false; } } @@ -66,7 +66,7 @@ bool is_channels_last_dim_order( return false; } // 4-dim tensor is interpreted as NCHW, 5-dim tensor is interpreted as NCHWD - size_t channels_dim = 1; + DimOrderType channels_dim = 1; // Last value in the dim order should be the channels dim if (dim_order[dims - 1] != channels_dim) { return false; @@ -75,8 +75,8 @@ bool is_channels_last_dim_order( if (dim_order[0] != 0) { return false; } - int d = 1; - while (d < dims - 1) { + DimOrderType d = 1; + while (d < static_cast(dims) - 1) { if (dim_order[d] != d + 1) { return false; } @@ -163,8 +163,8 @@ struct StrideDimOrder { StridesType stride; DimOrderType dim_order; - StrideDimOrder(StridesType stride, DimOrderType dim_order) - : stride(stride), dim_order(dim_order) {} + StrideDimOrder(StridesType stride_, DimOrderType dim_order_) + : stride(stride_), dim_order(dim_order_) {} StrideDimOrder() = default; bool operator>(const StrideDimOrder& other) const { // descending order diff --git a/runtime/core/exec_aten/util/tensor_shape_to_c_string.cpp b/runtime/core/exec_aten/util/tensor_shape_to_c_string.cpp index cfd416285c5..02155a4d9b4 100644 --- a/runtime/core/exec_aten/util/tensor_shape_to_c_string.cpp +++ b/runtime/core/exec_aten/util/tensor_shape_to_c_string.cpp @@ -30,7 +30,9 @@ std::array tensor_shape_to_c_string_impl( } *p++ = '('; for (const auto elem : shape) { - if (elem < 0 || elem > internal::kMaximumPrintableTensorShapeElement) { + if (elem < 0 || + static_cast(elem) > + internal::kMaximumPrintableTensorShapeElement) { static_assert( internal::kMaximumPrintableTensorShapeElement > 99999, "must have room for error string!"); diff --git a/runtime/core/exec_aten/util/tensor_util.h b/runtime/core/exec_aten/util/tensor_util.h index eb5ce10b6f3..fcc08ebf98d 100644 --- a/runtime/core/exec_aten/util/tensor_util.h +++ b/runtime/core/exec_aten/util/tensor_util.h @@ -584,7 +584,7 @@ inline bool tensors_have_same_dtype( inline bool tensor_is_rank(executorch::aten::Tensor t, size_t rank) { ET_CHECK_OR_RETURN_FALSE( - t.dim() == rank, + static_cast(t.dim()) == rank, "Expected tensor.dim() to be %zu, but got %zu", static_cast(rank), static_cast(t.dim())); @@ -596,7 +596,7 @@ inline bool tensor_has_rank_greater_or_equal_to( executorch::aten::Tensor t, size_t rank) { ET_CHECK_OR_RETURN_FALSE( - t.dim() >= rank, + static_cast(t.dim()) >= rank, "Expected tensor.dim() to be >= %zu, but got %zu", static_cast(rank), static_cast(t.dim())); @@ -608,7 +608,7 @@ inline bool tensor_has_rank_smaller_or_equal_to( executorch::aten::Tensor t, size_t rank) { ET_CHECK_OR_RETURN_FALSE( - t.dim() <= rank, + static_cast(t.dim()) <= rank, "Expected tensor.dim() to be <= %zu, but got %zu", static_cast(rank), static_cast(t.dim())); @@ -665,12 +665,12 @@ inline bool tensors_have_same_size_at_dims( executorch::aten::Tensor b, size_t dim_b) { ET_CHECK_OR_RETURN_FALSE( - dim_a < a.dim(), + dim_a < static_cast(a.dim()), "Cannot retrieve dim %zu from tensor with dim %zu", static_cast(dim_a), static_cast(a.dim())); ET_CHECK_OR_RETURN_FALSE( - dim_b < b.dim(), + dim_b < static_cast(b.dim()), "Cannot retrieve dim %zu from tensor with dim %zu", static_cast(dim_b), static_cast(b.dim())); @@ -702,7 +702,9 @@ inline bool tensors_have_same_shape( static_cast(b.numel()), static_cast(a.dim()), static_cast(b.dim())); - for (size_t d = 0; d < ET_MIN2(a.dim(), b.dim()); ++d) { + // Using [[maybe_unused]] as ET_LOG may not trigger based on verbosity + for ([[maybe_unused]] const auto d : + c10::irange(ET_MIN2(a.dim(), b.dim()))) { ET_LOG( Error, " size(%zu): (%zu, %zu)", @@ -739,7 +741,8 @@ inline bool tensors_have_same_shape( static_cast(a.dim()), static_cast(b.dim()), static_cast(c.dim())); - for (size_t d = 0; d < ET_MIN3(a.dim(), b.dim(), c.dim()); ++d) { + for ([[maybe_unused]] const auto d : + c10::irange(ET_MIN3(a.dim(), b.dim(), c.dim()))) { ET_LOG( Error, " size(%zu): (%zu, %zu, %zu)", @@ -779,7 +782,8 @@ inline bool tensor_has_expected_size( static_cast(expected_sizes.size())); size_t a_dim = static_cast(a.dim()); size_t expected_dim = static_cast(expected_sizes.size()); - for (size_t d = 0; d < ET_MIN2(a_dim, expected_dim); ++d) { + for ([[maybe_unused]] const auto d : + c10::irange(ET_MIN2(a_dim, expected_dim))) { ET_LOG( Error, " size(%zu): (%zu, %zu)", @@ -802,7 +806,8 @@ inline bool tensors_have_same_strides( ET_TENSOR_CHECK_PREFIX__ ": dim=(%zu, %zu)", static_cast(a.dim()), static_cast(b.dim())); - for (size_t d = 0; d < ET_MIN2(a.dim(), b.dim()); ++d) { + for ([[maybe_unused]] const auto d : + c10::irange(ET_MIN2(a.dim(), b.dim()))) { ET_LOG( Error, " stride(%zu): (%zu, %zu)", @@ -827,7 +832,8 @@ inline bool tensors_have_same_strides( static_cast(a.dim()), static_cast(b.dim()), static_cast(c.dim())); - for (size_t d = 0; d < ET_MIN3(a.dim(), b.dim(), c.dim()); ++d) { + for ([[maybe_unused]] const auto d : + c10::irange(ET_MIN3(a.dim(), b.dim(), c.dim()))) { ET_LOG( Error, " stride(%zu): (%zu, %zu, %zu)", @@ -894,7 +900,7 @@ inline size_t getLeadingDims( dim, ssize_t(tensor.dim())); size_t dims = 1; - for (size_t i = 0; i < dim; ++i) { + for (const auto i : c10::irange(dim)) { dims *= static_cast(tensor.size(i)); } return dims; @@ -911,7 +917,7 @@ inline size_t getTrailingDims( dim, ssize_t(tensor.dim())); size_t dims = 1; - for (size_t i = dim + 1; i < tensor.dim(); ++i) { + for (size_t i = dim + 1; i < static_cast(tensor.dim()); ++i) { dims *= static_cast(tensor.size(i)); } return dims; @@ -984,7 +990,7 @@ inline void indexToCoordinate( const executorch::aten::Tensor& tensor, size_t index, size_t* coordinate) { - ET_CHECK(index < tensor.numel()); + ET_CHECK(index < static_cast(tensor.numel())); for (auto i = 0; i < tensor.dim(); ++i) { auto dim = tensor.dim() - 1 - i; size_t dim_size = tensor.size(dim); diff --git a/runtime/core/exec_aten/util/tensor_util_portable.cpp b/runtime/core/exec_aten/util/tensor_util_portable.cpp index c1cbcfb6064..e4aa875aed4 100644 --- a/runtime/core/exec_aten/util/tensor_util_portable.cpp +++ b/runtime/core/exec_aten/util/tensor_util_portable.cpp @@ -8,6 +8,7 @@ #include +#include #include #include @@ -41,11 +42,11 @@ Error get_dim_order( bool tensor_has_valid_dim_order(torch::executor::Tensor t) { if (!validate_dim_order(t.dim_order().data(), t.dim_order().size())) { ET_LOG(Error, "Tensor dim order is not valid:"); - for (size_t d = 0; d < t.dim(); ++d) { + for (size_t d = 0; d < static_cast(t.dim()); ++d) { ET_LOG( Error, " dim_order(%zu): %zu", - static_cast(d), + d, static_cast(t.dim_order()[d])); } return false; @@ -62,11 +63,11 @@ bool tensor_is_default_or_channels_last_dim_order(torch::executor::Tensor t) { ET_LOG( Error, "Expected tensor to have default or channels last dim order, but got"); - for (size_t d = 0; d < t.dim(); ++d) { + for (size_t d = 0; d < static_cast(t.dim()); ++d) { ET_LOG( Error, " dim_order(%zu): %zu", - static_cast(d), + d, static_cast(t.dim_order()[d])); } } @@ -79,11 +80,11 @@ bool tensor_is_default_dim_order(torch::executor::Tensor t) { if (!ret_val) { ET_LOG(Error, "Expected tensor to have default dim order, but got"); - for (size_t d = 0; d < t.dim(); ++d) { + for (size_t d = 0; d < static_cast(t.dim()); ++d) { ET_LOG( Error, " dim_order(%zu): %zu", - static_cast(d), + d, static_cast(t.dim_order()[d])); } } @@ -96,11 +97,11 @@ bool tensor_is_channels_last_dim_order(torch::executor::Tensor t) { if (!ret_val) { ET_LOG(Error, "Expected tensor to have channels last dim order, but got"); - for (size_t d = 0; d < t.dim(); ++d) { + for (size_t d = 0; d < static_cast(t.dim()); ++d) { ET_LOG( Error, " dim_order(%zu): %zu", - static_cast(d), + d, static_cast(t.dim_order()[d])); } } diff --git a/runtime/core/portable_type/c10/c10/util/irange.h b/runtime/core/portable_type/c10/c10/util/irange.h index 3249bdfa5cf..81104d9568f 100644 --- a/runtime/core/portable_type/c10/c10/util/irange.h +++ b/runtime/core/portable_type/c10/c10/util/irange.h @@ -24,7 +24,7 @@ struct integer_iterator { using pointer = I*; using reference = I&; - explicit constexpr integer_iterator(I value) : value(value) {} + explicit constexpr integer_iterator(I value_) : value(value_) {} constexpr I operator*() const { return value; diff --git a/runtime/core/portable_type/tensor_impl.cpp b/runtime/core/portable_type/tensor_impl.cpp index 6366a8eac28..ede5a3d4101 100644 --- a/runtime/core/portable_type/tensor_impl.cpp +++ b/runtime/core/portable_type/tensor_impl.cpp @@ -35,8 +35,8 @@ ssize_t compute_numel(const TensorImpl::SizesType* sizes, ssize_t dim) { for (const auto i : c10::irange(dim)) { ET_CHECK_MSG( sizes[i] >= 0, - "Size must be non-negative, got %d at dimension %zd", - sizes[i], + "Size must be non-negative, got %zd at dimension %zd", + static_cast(sizes[i]), i); numel *= sizes[i]; } @@ -76,7 +76,7 @@ ssize_t TensorImpl::element_size() const { Error TensorImpl::internal_resize_contiguous(ArrayRef new_sizes) { ET_CHECK_OR_RETURN_ERROR( - new_sizes.size() == dim_, + static_cast(new_sizes.size()) == dim_, NotSupported, "Attempted to change the tensor rank which is immutable: old=%zu, new=%zu", dim_, @@ -120,7 +120,7 @@ Error TensorImpl::internal_resize_contiguous(ArrayRef new_sizes) { const auto new_numel = compute_numel(new_sizes.data(), dim_); ET_CHECK_OR_RETURN_ERROR( - new_numel <= numel_bound_, + static_cast(new_numel) <= numel_bound_, NotSupported, "Attempted to resize a bounded tensor with a maximum capacity of %zu elements to %zu elements.", numel_bound_, diff --git a/runtime/core/tensor_layout.cpp b/runtime/core/tensor_layout.cpp index f0fac442e20..2b862e6dc14 100644 --- a/runtime/core/tensor_layout.cpp +++ b/runtime/core/tensor_layout.cpp @@ -20,7 +20,7 @@ Result calculate_nbytes( const Span& sizes, const executorch::aten::ScalarType& scalar_type) { ssize_t n = 1; - for (ssize_t i = 0; i < sizes.size(); i++) { + for (const auto i : c10::irange(sizes.size())) { if (sizes[i] < 0) { return Error::InvalidArgument; } diff --git a/runtime/executor/method.cpp b/runtime/executor/method.cpp index 0857bc1c976..7da7bafd3e5 100644 --- a/runtime/executor/method.cpp +++ b/runtime/executor/method.cpp @@ -8,6 +8,7 @@ #include +#include #include #include // @donotremove #include @@ -239,10 +240,10 @@ Result gen_instruction_arguments( for (size_t i = 0; i < num_args; ++i) { int32_t arg_idx = arg_idxs[i]; ET_CHECK_OR_RETURN_ERROR( - arg_idx < num_values, + static_cast(arg_idx) < num_values, InvalidProgram, - "Arg index %d >= %" ET_PRIsize_t, - arg_idx, + "Arg index %zd >= %" ET_PRIsize_t, + static_cast(arg_idx), num_values); arg_list[i] = &values[arg_idx]; } @@ -270,7 +271,7 @@ Result parse_cond_value(const EValue& cond_value) { static_cast(cond_val.scalar_type())); const bool* cond_data = cond_val.const_data_ptr(); - for (size_t i = 0; i < cond_val.numel(); i++) { + for (size_t i = 0; i < static_cast(cond_val.numel()); i++) { if (!cond_data[i]) { return false; } @@ -481,7 +482,7 @@ Error Method::parse_values(const NamedDataMap* named_data_map) { for (size_t j = 0; j < items->size(); j++) { auto value_index = items->Get(j); ET_CHECK_OR_RETURN_ERROR( - value_index >= 0 && value_index < n_value, + value_index >= 0 && static_cast(value_index) < n_value, InvalidProgram, "Invalid value index %" PRId64 " for IntList %" ET_PRIsize_t " index %" ET_PRIsize_t, @@ -644,7 +645,7 @@ Error populate_operator_name( has_overload ? op->overload()->c_str() : ""); ET_CHECK_OR_RETURN_ERROR(cx >= 0, Internal, "snprintf failed: %d", cx); ET_CHECK_OR_RETURN_ERROR( - cx < operator_name_size, + static_cast(cx) < operator_name_size, Internal, "Operator name %s%s%s with length %d " "truncated to %" ET_PRIsize_t " due to internal buffer limit.", @@ -672,7 +673,8 @@ Error Method::resolve_operator( char operator_name[kTempBufferSizeForName]; const auto ops = serialization_plan_->operators(); ET_CHECK_OR_RETURN_ERROR( - ops != nullptr && op_index < ops->size(), + ops != nullptr && + static_cast(op_index) < ops->size(), InvalidProgram, "Op index %" PRIu32 " out of range", op_index); @@ -721,7 +723,11 @@ Error Method::resolve_operator( Result op_function = get_op_function_from_registry(operator_name, {meta, count}); if (!op_function.ok()) { - ET_LOG(Error, "Missing operator: [%d] %s", op_index, operator_name); + ET_LOG( + Error, + "Missing operator: [%zd] %s", + static_cast(op_index), + operator_name); return op_function.error(); } kernels[kernel_index] = op_function.get(); @@ -923,10 +929,10 @@ Error Method::init( instr_args) ->cond_value_index(); ET_CHECK_OR_RETURN_ERROR( - index >= 0 && index < n_value_, + index >= 0 && static_cast(index) < n_value_, InvalidProgram, - "Index %d negative or >= %" ET_PRIsize_t, - index, + "Index %zd negative or >= %" ET_PRIsize_t, + static_cast(index), n_value_); chain_instruction_arg_lists[instr_idx] = InstructionArgs(); } break; @@ -944,9 +950,9 @@ Error Method::init( ET_CHECK_OR_RETURN_ERROR( num_instructions_missing_op == 0, OperatorMissing, - "There are %d instructions don't have corresponding operator registered. " + "There are %zu instructions don't have corresponding operator registered. " "See logs for details", - num_instructions_missing_op); + static_cast(num_instructions_missing_op)); if (delayed_error != Error::Ok) { return delayed_error; } @@ -1315,7 +1321,7 @@ Error Method::execute_instruction() { auto delegate_idx = instruction->instr_args_as_DelegateCall()->delegate_index(); ET_CHECK_OR_RETURN_ERROR( - delegate_idx < n_delegate_, + static_cast(delegate_idx) < n_delegate_, Internal, "DELEGATE_CALL index %" PRIu32 " >= num delegates %" ET_PRIsize_t " at instruction %" ET_PRIsize_t, @@ -1609,18 +1615,18 @@ Method::~Method() { // Destroy the values. It's necessary in ATen mode, where the refcount of // Tensors needs to be decremented properly. if (values_ != nullptr) { - for (int i = 0; i < n_value_; ++i) { + for (size_t i = 0; i < n_value_; ++i) { values_[i].~EValue(); } } // Free any resources associated with delegate backends. if (delegates_ != nullptr) { - for (int i = 0; i < n_delegate_; i++) { + for (size_t i = 0; i < n_delegate_; i++) { delegates_[i].~BackendDelegate(); } } // Free resources associated with external constants. - for (int i = 0; i < n_external_constants_; i++) { + for (const auto i : c10::irange(n_external_constants_)) { external_constants_[i].buffer.~FreeableBuffer(); } // All other fields are trivially destructible. diff --git a/runtime/executor/method_meta.cpp b/runtime/executor/method_meta.cpp index bcc2390d2bd..651a815c335 100644 --- a/runtime/executor/method_meta.cpp +++ b/runtime/executor/method_meta.cpp @@ -56,7 +56,7 @@ size_t calculate_nbytes( Span sizes, executorch::aten::ScalarType scalar_type) { ssize_t n = 1; - for (ssize_t i = 0; i < sizes.size(); i++) { + for (size_t i = 0; i < sizes.size(); i++) { n *= sizes[i]; } // Use the full namespace to disambiguate from c10::elementSize. @@ -110,7 +110,7 @@ size_t MethodMeta::num_inputs() const { Result MethodMeta::input_tag(size_t index) const { auto num_inputs = this->num_inputs(); ET_CHECK_OR_RETURN_ERROR( - index >= 0 && index < num_inputs, + index < num_inputs, InvalidArgument, "index %zu out of range. num_inputs: %zu", index, @@ -118,10 +118,10 @@ Result MethodMeta::input_tag(size_t index) const { auto input_index = s_plan_->inputs()->Get(index); size_t num_values = s_plan_->values()->size(); ET_CHECK_OR_RETURN_ERROR( - input_index >= 0 && input_index < num_values, + input_index >= 0 && static_cast(input_index) < num_values, InvalidProgram, - "internal value index %d out of range [0,%zu) for input %zu", - input_index, + "internal value index %zd out of range [0,%zu) for input %zu", + static_cast(input_index), num_values, index); auto serialization_value = s_plan_->values()->Get(input_index); @@ -160,7 +160,7 @@ size_t MethodMeta::num_outputs() const { Result MethodMeta::output_tag(size_t index) const { auto num_outputs = this->num_outputs(); ET_CHECK_OR_RETURN_ERROR( - index >= 0 && index < num_outputs, + index < num_outputs, InvalidArgument, "index %zu out of range. num_outputs: %zu", index, @@ -168,10 +168,10 @@ Result MethodMeta::output_tag(size_t index) const { auto output_index = s_plan_->outputs()->Get(index); size_t num_values = s_plan_->values()->size(); ET_CHECK_OR_RETURN_ERROR( - output_index >= 0 && output_index < num_values, + output_index >= 0 && static_cast(output_index) < num_values, InvalidProgram, - "internal value index %d out of range [0,%zu) for output %zu", - output_index, + "internal value index %zd out of range [0,%zu) for output %zu", + static_cast(output_index), num_values, index); auto serialization_value = s_plan_->values()->Get(output_index); @@ -218,7 +218,7 @@ size_t MethodMeta::num_memory_planned_buffers() const { Result MethodMeta::memory_planned_buffer_size(size_t index) const { auto num_buffers = this->num_memory_planned_buffers(); ET_CHECK_OR_RETURN_ERROR( - index >= 0 && index < num_buffers, + index < num_buffers, InvalidArgument, "index %zu out of range. num_buffers: %zu", index, diff --git a/runtime/executor/program.cpp b/runtime/executor/program.cpp index 964b8c8bdac..67f1edd4df3 100644 --- a/runtime/executor/program.cpp +++ b/runtime/executor/program.cpp @@ -163,10 +163,10 @@ Result get_execution_plan( ET_CHECK_OR_RETURN_ERROR( constant_buffer == nullptr || constant_buffer->size() == 0, InvalidProgram, - "constant_buffer contains %u items, " - "constant_segment.offsets contains %u items. Only one should be used.", - constant_buffer->size(), - constant_segment->offsets()->size()); + "constant_buffer contains %zu items, " + "constant_segment.offsets contains %zu items. Only one should be used.", + static_cast(constant_buffer->size()), + static_cast(constant_segment->offsets()->size())); const auto* segments = flatbuffer_program->segments(); ET_CHECK_OR_RETURN_ERROR( segments != nullptr, InvalidProgram, "No segments in program"); @@ -176,9 +176,9 @@ Result get_execution_plan( ET_CHECK_OR_RETURN_ERROR( constant_segment->segment_index() < segments->size(), InvalidProgram, - "Constant segment index %d invalid for program segments range %d", - constant_segment->segment_index(), - segments->size()); + "Constant segment index %zu invalid for program segments range %zu", + static_cast(constant_segment->segment_index()), + static_cast(segments->size())); const executorch_flatbuffer::DataSegment* data_segment = segments->Get(constant_segment->segment_index()); @@ -347,8 +347,8 @@ Result Program::get_constant_buffer_data( ET_CHECK_OR_RETURN_ERROR( storage_size <= nbytes, InvalidArgument, - "Constant buffer size %u larger than allocated nbytes %zu", - storage_size, + "Constant buffer size %zu larger than allocated nbytes %zu", + static_cast(constant_buffer[buffer_index]->storage()->size()), nbytes); return storage->data(); @@ -479,8 +479,8 @@ Error Program::load_mutable_subsegment_into( if (segment_offsets->segment_index() >= num_segments) { ET_LOG( Error, - "Segment index %u out of range (>= %zu)", - segment_offsets->segment_index(), + "Segment index %zu out of range (>= %zu)", + static_cast(segment_offsets->segment_index()), num_segments); return Error::NotFound; } diff --git a/runtime/executor/targets.bzl b/runtime/executor/targets.bzl index c5d07448a06..8993c5dc473 100644 --- a/runtime/executor/targets.bzl +++ b/runtime/executor/targets.bzl @@ -74,6 +74,10 @@ def define_common_targets(): "program.h", "tensor_parser.h", ], + compiler_flags = select({ + "ovr_config//os:windows": [], + "DEFAULT" :["-Wno-error=deprecated-declarations"] + }), preprocessor_flags = _program_preprocessor_flags(), exported_deps = [ ":memory_manager", diff --git a/runtime/executor/tensor_parser.h b/runtime/executor/tensor_parser.h index cfd711713ac..362f0b11e20 100644 --- a/runtime/executor/tensor_parser.h +++ b/runtime/executor/tensor_parser.h @@ -91,7 +91,7 @@ parseListOptionalType( evalp_list[output_idx] = nullptr; } else { ET_CHECK_OR_RETURN_ERROR( - index >= 0 && index < values_len, + index >= 0 && static_cast(index) < values_len, InvalidProgram, "Invalid value index %" PRId32 " for ListOptional", index); diff --git a/runtime/executor/tensor_parser_exec_aten.cpp b/runtime/executor/tensor_parser_exec_aten.cpp index de809ee09cc..002c7366be6 100644 --- a/runtime/executor/tensor_parser_exec_aten.cpp +++ b/runtime/executor/tensor_parser_exec_aten.cpp @@ -64,7 +64,8 @@ ET_NODISCARD Result getMemPlannedPtr( "size_t cannot hold memory offset 0x%08" PRIx32 ".%08" PRIx32, memory_offset_high, memory_offset_low); - memory_offset |= static_cast(memory_offset_high) << 32; + memory_offset |= static_cast(memory_offset_high) + << (sizeof(size_t) - sizeof(uint32_t)); } return allocator->get_offset_address(memory_id, memory_offset, nbytes); } @@ -94,7 +95,7 @@ ET_NODISCARD Result> parseTensorList( size_t output_idx = 0; for (int32_t tensor_index : *tensor_indices) { ET_CHECK_OR_RETURN_ERROR( - tensor_index >= 0 && tensor_index < values_len, + tensor_index >= 0 && static_cast(tensor_index) < values_len, InvalidProgram, "Invalid value index %" PRId32 " for TensorList", tensor_index); @@ -123,7 +124,9 @@ ET_NODISCARD Error validateTensorLayout( static_cast(expected_layout.scalar_type())); int dim = s_tensor->sizes()->size(); ET_CHECK_OR_RETURN_ERROR( - dim == expected_layout.sizes().size(), + dim >= 0, InvalidExternalData, "Dim is negative: %d", dim) + ET_CHECK_OR_RETURN_ERROR( + static_cast(dim) == expected_layout.sizes().size(), InvalidExternalData, "Dim mismatch. Expected %d, got %zu.", dim, @@ -150,7 +153,7 @@ ET_NODISCARD Error validateTensorLayout( // Check if key exists in entries. If it does, return a pointer to the entry // otherwise return a nullptr. NamedData* get_data_by_key(const char* key, Span entries) { - for (int i = 0; i < entries.size(); i++) { + for (const auto i : c10::irange(entries.size())) { if (strcmp(key, entries[i].key) == 0) { return &entries[i]; } diff --git a/runtime/executor/tensor_parser_portable.cpp b/runtime/executor/tensor_parser_portable.cpp index b72fedc5eee..4b424b29f5c 100644 --- a/runtime/executor/tensor_parser_portable.cpp +++ b/runtime/executor/tensor_parser_portable.cpp @@ -107,12 +107,12 @@ Result parseTensor( // detect bad positive values, but we can reject negative values, which would // otherwise panic in the TensorImpl ctor. dim_order_to_stride() will validate // dim_order. - for (int i = 0; i < dim; i++) { + for (flatbuffers::uoffset_t i = 0; i < dim; i++) { ET_CHECK_OR_RETURN_ERROR( sizes[i] >= 0, InvalidProgram, - "Negative size[%d] %" PRId32, - i, + "Negative size[%zu] %" PRId32, + static_cast(i), sizes[i]); } diff --git a/runtime/kernel/operator_registry.cpp b/runtime/kernel/operator_registry.cpp index b51c2567f0a..85705e5b3fd 100644 --- a/runtime/kernel/operator_registry.cpp +++ b/runtime/kernel/operator_registry.cpp @@ -79,7 +79,7 @@ Error register_kernels_internal(const Span kernels) { for (const auto& kernel : kernels) { // Linear search. This is fine if the number of kernels is small. - for (int32_t i = 0; i < num_registered_kernels; i++) { + for (size_t i = 0; i < num_registered_kernels; i++) { Kernel k = registered_kernels[i]; if (strcmp(kernel.name_, k.name_) == 0 && kernel.kernel_key_ == k.kernel_key_) { @@ -188,7 +188,7 @@ Error make_kernel_key_string( buf_size -= 1; // Add dim order. - for (int j = 0; j < meta.dim_order_.size(); j++) { + for (size_t j = 0; j < meta.dim_order_.size(); j++) { n = copy_char_as_number_to_buf((int)meta.dim_order_[j], buf, buf_size); if (n < 0) { return Error::InvalidArgument; diff --git a/runtime/kernel/operator_registry.h b/runtime/kernel/operator_registry.h index 82815852e6f..8e1eaca9981 100644 --- a/runtime/kernel/operator_registry.h +++ b/runtime/kernel/operator_registry.h @@ -33,7 +33,7 @@ #define ET_LOG_TENSOR_META(meta_list) \ for (const auto& meta : meta_list) { \ ET_LOG(Error, "dtype: %d | dim order: [", int(meta.dtype_)); \ - for (int i = 0; i < meta.dim_order_.size(); i++) { \ + for (size_t i = 0; i < meta.dim_order_.size(); i++) { \ ET_LOG(Error, "%d,", static_cast(meta.dim_order_[i])); \ } \ ET_LOG(Error, "]"); \ @@ -74,7 +74,7 @@ struct TensorMeta { if (dim_order_.size() != other.dim_order_.size()) { return false; } - for (int i = 0; i < dim_order_.size(); i++) { + for (size_t i = 0; i < dim_order_.size(); i++) { if (dim_order_[i] != other.dim_order_[i]) { return false; } diff --git a/runtime/platform/log.cpp b/runtime/platform/log.cpp index c1ad6ddcc0d..6529c73b238 100644 --- a/runtime/platform/log.cpp +++ b/runtime/platform/log.cpp @@ -92,8 +92,7 @@ void vlogf( } buf[kMaxLogMessageLength - 1] = 0; - et_pal_log_level_t pal_level = - (int(level) >= 0 && level < LogLevel::NumLevels) + et_pal_log_level_t pal_level = (level < LogLevel::NumLevels) ? kLevelToPal[size_t(level)] : et_pal_log_level_t::kUnknown; diff --git a/runtime/platform/log.h b/runtime/platform/log.h index 9ad234b2520..72ea8528442 100644 --- a/runtime/platform/log.h +++ b/runtime/platform/log.h @@ -33,6 +33,15 @@ #define ET_LOG_ENABLED 1 #endif // !defined(ET_LOG_ENABLED) +// Even though it is supposed to be "portable" some toolchains +// do not define, so providing a definition here +#ifndef PRIu64 +#define PRIu64 "llu" +#endif +#ifndef PRId64 +#define PRId64 "lld" +#endif + namespace executorch { namespace runtime { diff --git a/runtime/platform/profiler.cpp b/runtime/platform/profiler.cpp index 2f514286aa1..21f68963c78 100644 --- a/runtime/platform/profiler.cpp +++ b/runtime/platform/profiler.cpp @@ -129,7 +129,8 @@ void track_allocation(int32_t id, uint32_t size) { uint32_t track_allocator(const char* name) { ET_CHECK_MSG( prof_header->allocator_entries < MEM_PROFILE_MAX_ALLOCATORS, - "Out of allocator tracking space, %d is needed. Increase MEM_PROFILE_MAX_ALLOCATORS and re-compile", + "Out of allocator tracking space, %" PRIu32 + " is needed. Increase MEM_PROFILE_MAX_ALLOCATORS and re-compile", prof_header->allocator_entries); size_t str_len = strlen(name); size_t num_allocators = prof_header->allocator_entries; @@ -151,7 +152,8 @@ void profiling_create_block(const char* name) { num_blocks += 1; ET_CHECK_MSG( num_blocks <= MAX_PROFILE_BLOCKS, - "Only %d blocks are supported and they've all been used up but %d is used. Increment MAX_PROFILE_BLOCKS and re-run", + "Only %d blocks are supported and they've all been used up but %" PRIu32 + " is used. Increment MAX_PROFILE_BLOCKS and re-run", MAX_PROFILE_BLOCKS, num_blocks); } diff --git a/schema/extended_header.cpp b/schema/extended_header.cpp index fdc463207ba..3236b040c49 100644 --- a/schema/extended_header.cpp +++ b/schema/extended_header.cpp @@ -14,8 +14,6 @@ #include #include -#pragma clang diagnostic ignored "-Wdeprecated" - namespace executorch { namespace runtime { diff --git a/test/build_size_test.sh b/test/build_size_test.sh index 823b399fe34..09c0188ff9b 100644 --- a/test/build_size_test.sh +++ b/test/build_size_test.sh @@ -11,9 +11,8 @@ set -e # shellcheck source=/dev/null source "$(dirname "${BASH_SOURCE[0]}")/../.ci/scripts/utils.sh" -# TODO(#8149): Remove -Wno-sign-compare # TODO(#8357): Remove -Wno-int-in-bool-context -COMMON_CXXFLAGS="-fno-exceptions -fno-rtti -Wall -Werror -Wno-sign-compare -Wno-unknown-pragmas -Wno-int-in-bool-context" +COMMON_CXXFLAGS="-fno-exceptions -fno-rtti -Wall -Werror -Wno-int-in-bool-context" cmake_install_executorch_lib() { echo "Installing libexecutorch.a"