From a536e231e8161875450f96e7433c0dd61bc7169b Mon Sep 17 00:00:00 2001 From: Richard Barnes Date: Wed, 23 Apr 2025 15:58:48 -0700 Subject: [PATCH] Fix `numel()` downcast in executorch/backends/vulkan/test/utils/test_utils.cpp +2 Summary: `numel()` has type `int64_t`. The implicit downcasts fix in this change artificially truncate data ranges which can lead to hard-to-debug errors and SEVs. Using `auto` ensures that the correct data type is used. Reviewed By: dtolnay Differential Revision: D73534006 --- backends/vulkan/test/utils/test_utils.cpp | 2 +- backends/xnnpack/runtime/utils/utils.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/backends/vulkan/test/utils/test_utils.cpp b/backends/vulkan/test/utils/test_utils.cpp index 3b6195a5c26..79fd5ab9445 100644 --- a/backends/vulkan/test/utils/test_utils.cpp +++ b/backends/vulkan/test/utils/test_utils.cpp @@ -114,7 +114,7 @@ void record_bitw8_image_to_nchw_nobitw8buffer_op( api::vTensor& v_src, api::StagingBuffer& dst_buffer) { vkapi::PipelineBarrier pipeline_barrier{}; - uint32_t buffer_len = utils::safe_downcast(dst_buffer.numel() / 4); + auto buffer_len = utils::safe_downcast(dst_buffer.numel() / 4); utils::uvec3 global_wg_size = {buffer_len, 1, 1}; std::string kernel_name = "bitw8_image_to_nchw_nobitw8buffer"; diff --git a/backends/xnnpack/runtime/utils/utils.h b/backends/xnnpack/runtime/utils/utils.h index 2eb079f0b0c..01e909816a5 100644 --- a/backends/xnnpack/runtime/utils/utils.h +++ b/backends/xnnpack/runtime/utils/utils.h @@ -132,7 +132,7 @@ executorch::runtime::Error QuantizePerTensor( double scale, int zero_point) { const float* rdata = rtensor.const_data_ptr(); - int numel = rtensor.numel(); + auto numel = rtensor.numel(); ET_CHECK_OR_RETURN_ERROR( (std::is_same::value || std::is_same::value), Internal,