From 29e964ad1defeabef7f2d59221026f141c862a77 Mon Sep 17 00:00:00 2001 From: Scott Wolchok Date: Thu, 26 Jun 2025 13:00:24 -0700 Subject: [PATCH 1/6] Update [ghstack-poisoned] --- kernels/portable/cpu/util/normalization_ops_util.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/kernels/portable/cpu/util/normalization_ops_util.cpp b/kernels/portable/cpu/util/normalization_ops_util.cpp index 4adcf02b303..dedab427ae7 100644 --- a/kernels/portable/cpu/util/normalization_ops_util.cpp +++ b/kernels/portable/cpu/util/normalization_ops_util.cpp @@ -7,6 +7,7 @@ */ #include +#include #include #include @@ -92,6 +93,11 @@ bool check_layer_norm_args( ", ndim = %zu", in.dim(), ndim); + ET_CHECK_OR_RETURN_FALSE( + ndim <= kTensorDimensionLimit, + "Expected normalized shape to have at most %zu dimensions but it had %zu", + kTensorDimensionLimit, + ndim); size_t shift = in.dim() - ndim; for (const auto d : c10::irange(ndim)) { ET_CHECK_OR_RETURN_FALSE( @@ -103,7 +109,7 @@ bool check_layer_norm_args( d, normalized_shape[d]); } - executorch::aten::SizesType shape[ndim]; + std::array shape; for (const auto i : c10::irange(ndim)) { shape[i] = static_cast(normalized_shape[i]); } @@ -111,12 +117,12 @@ bool check_layer_norm_args( if (weight.has_value()) { ET_LOG_AND_RETURN_IF_FALSE(tensors_have_same_dtype(in, weight.value())); ET_LOG_AND_RETURN_IF_FALSE( - tensor_has_expected_size(weight.value(), {shape, ndim})); + tensor_has_expected_size(weight.value(), {shape.data(), ndim})); } if (bias.has_value()) { ET_LOG_AND_RETURN_IF_FALSE(tensors_have_same_dtype(in, bias.value())); ET_LOG_AND_RETURN_IF_FALSE( - tensor_has_expected_size(bias.value(), {shape, ndim})); + tensor_has_expected_size(bias.value(), {shape.data(), ndim})); } ET_LOG_AND_RETURN_IF_FALSE(tensors_have_same_dtype(in, out)); ET_LOG_AND_RETURN_IF_FALSE(tensors_have_same_dtype(in, mean_out)); From 1ae275b372315b031e206fbe979f13ab155009ef Mon Sep 17 00:00:00 2001 From: Scott Wolchok Date: Thu, 26 Jun 2025 13:00:28 -0700 Subject: [PATCH 2/6] Update [ghstack-poisoned] --- test/build_optimized_size_test.sh | 3 +++ test/build_size_test.sh | 2 ++ 2 files changed, 5 insertions(+) diff --git a/test/build_optimized_size_test.sh b/test/build_optimized_size_test.sh index d7b055559f0..3141a29e9f1 100644 --- a/test/build_optimized_size_test.sh +++ b/test/build_optimized_size_test.sh @@ -41,12 +41,15 @@ test_cmake_size_test() { echo 'ExecuTorch with no ops binary size, unstripped:' ls -al cmake-out/test/size_test + size cmake-out/test/size_test echo 'ExecuTorch with portable ops binary size, unstripped:' ls -al cmake-out/test/size_test_all_ops + size cmake-out/test/size_test_all_ops echo 'ExecuTorch with optimized ops binary size, unstripped:' ls -al cmake-out/test/size_test_all_optimized_ops + size cmake-out/test/size_test_all_optimized_ops } if [[ -z $PYTHON_EXECUTABLE ]]; then diff --git a/test/build_size_test.sh b/test/build_size_test.sh index d020ab58c95..baeef5a849e 100644 --- a/test/build_size_test.sh +++ b/test/build_size_test.sh @@ -46,9 +46,11 @@ test_cmake_size_test() { echo 'ExecuTorch with no ops binary size, unstripped:' ls -al cmake-out/test/size_test + size cmake-out/test/size_test echo 'ExecuTorch with portable ops binary size, unstripped:' ls -al cmake-out/test/size_test_all_ops + size cmake-out/test/size_test_all_ops } if [[ -z $PYTHON_EXECUTABLE ]]; then From e0f20e4010b7bde1dc4c110b87d658f00915083c Mon Sep 17 00:00:00 2001 From: Scott Wolchok Date: Thu, 26 Jun 2025 13:00:32 -0700 Subject: [PATCH 3/6] Update [ghstack-poisoned] --- test/build_size_test.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/build_size_test.sh b/test/build_size_test.sh index baeef5a849e..8b7c37fb020 100644 --- a/test/build_size_test.sh +++ b/test/build_size_test.sh @@ -26,23 +26,23 @@ cmake_install_executorch_lib() { CXXFLAGS="$COMMON_CXXFLAGS" retry cmake -DBUCK2="$BUCK2" \ -DCMAKE_CXX_STANDARD_REQUIRED=ON \ -DCMAKE_INSTALL_PREFIX=cmake-out \ - -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_BUILD_TYPE=RelWithDebInfo \ -DEXECUTORCH_BUILD_EXECUTOR_RUNNER=OFF \ -DEXECUTORCH_OPTIMIZE_SIZE=ON \ -DPYTHON_EXECUTABLE="$PYTHON_EXECUTABLE" \ ${EXTRA_BUILD_ARGS} \ -Bcmake-out . - cmake --build cmake-out -j9 --target install --config Release + cmake --build cmake-out -j9 --target install --config RelWithDebInfo } test_cmake_size_test() { - CXXFLAGS="$COMMON_CXXFLAGS" retry cmake -DCMAKE_BUILD_TYPE=Release \ + CXXFLAGS="$COMMON_CXXFLAGS" retry cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo \ -DCMAKE_INSTALL_PREFIX=cmake-out \ ${EXTRA_BUILD_ARGS} \ -Bcmake-out/test test echo "Build size test" - cmake --build cmake-out/test -j9 --config Release + cmake --build cmake-out/test -j9 --config RelWithDebInfo echo 'ExecuTorch with no ops binary size, unstripped:' ls -al cmake-out/test/size_test From bd87af0a64ff3259dd2b886e9d3c632ab72e2c94 Mon Sep 17 00:00:00 2001 From: Scott Wolchok Date: Thu, 26 Jun 2025 14:52:21 -0700 Subject: [PATCH 4/6] Update [ghstack-poisoned] --- .github/workflows/pull.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/pull.yml b/.github/workflows/pull.yml index df254b7f409..7659b178ec7 100644 --- a/.github/workflows/pull.yml +++ b/.github/workflows/pull.yml @@ -366,6 +366,7 @@ jobs: # build module for executorch.extension.pybindings.portable_lib bash test/build_size_test.sh strip cmake-out/test/size_test + strip --strip-debug cmake-out/test/size_test output=$(ls -la cmake-out/test/size_test) arr=($output) size=${arr[4]} @@ -403,6 +404,7 @@ jobs: # build module for executorch.extension.pybindings.portable_lib bash test/build_size_test.sh strip cmake-out/test/size_test + strip --strip-debug cmake-out/test/size_test output=$(ls -la cmake-out/test/size_test) arr=($output) size=${arr[4]} From bf512fea3240526377e9e1107bb408a468bc5fc5 Mon Sep 17 00:00:00 2001 From: Scott Wolchok Date: Thu, 26 Jun 2025 17:28:17 -0700 Subject: [PATCH 5/6] Update [ghstack-poisoned] --- CMakeLists.txt | 2 +- backends/qualcomm/CMakeLists.txt | 4 ++-- examples/models/llama/CMakeLists.txt | 2 +- examples/models/llava/CMakeLists.txt | 2 +- examples/selective_build/CMakeLists.txt | 2 +- test/CMakeLists.txt | 6 +++--- tools/cmake/preset/default.cmake | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3a3b1f7bfe0..5128a013076 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -694,7 +694,7 @@ if(EXECUTORCH_BUILD_EXECUTOR_RUNNER) endif() add_executable(executor_runner ${_executor_runner__srcs}) - if(CMAKE_BUILD_TYPE STREQUAL "Release") + if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug") if(APPLE) target_link_options(executor_runner PRIVATE "LINKER:-dead_strip") else() diff --git a/backends/qualcomm/CMakeLists.txt b/backends/qualcomm/CMakeLists.txt index 203cdf2c314..9f1be61de2b 100644 --- a/backends/qualcomm/CMakeLists.txt +++ b/backends/qualcomm/CMakeLists.txt @@ -60,7 +60,7 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") add_link_options("-flto=auto") endif() -if(CMAKE_BUILD_TYPE STREQUAL "Release") +if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug") # strip symbols add_link_options("-s") @@ -259,7 +259,7 @@ if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64") pybind11_strip(PyQnnWrapperAdaptor) endif() - if(CMAKE_BUILD_TYPE STREQUAL "Release") + if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug") # need to allow exceptions in pybind set(_pybind_compile_options -Wno-deprecated-declarations -fPIC -frtti -fexceptions diff --git a/examples/models/llama/CMakeLists.txt b/examples/models/llama/CMakeLists.txt index 8c27de20845..3216469c13a 100644 --- a/examples/models/llama/CMakeLists.txt +++ b/examples/models/llama/CMakeLists.txt @@ -209,7 +209,7 @@ if(ANDROID) endif() add_executable(llama_main ${_srcs}) -if(CMAKE_BUILD_TYPE STREQUAL "Release") +if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug") if(APPLE) target_link_options(llama_main PRIVATE "LINKER:-dead_strip") else() diff --git a/examples/models/llava/CMakeLists.txt b/examples/models/llava/CMakeLists.txt index 64be6111674..41270d0133f 100644 --- a/examples/models/llava/CMakeLists.txt +++ b/examples/models/llava/CMakeLists.txt @@ -197,7 +197,7 @@ list(APPEND _common_include_directories ${stb_SOURCE_DIR} ) add_executable(llava_main ${_srcs}) -if(CMAKE_BUILD_TYPE STREQUAL "Release") +if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug") if(APPLE) target_link_options(llava_main PRIVATE "LINKER:-dead_strip,-s") else() diff --git a/examples/selective_build/CMakeLists.txt b/examples/selective_build/CMakeLists.txt index 39b212b16fb..24fd102fee9 100644 --- a/examples/selective_build/CMakeLists.txt +++ b/examples/selective_build/CMakeLists.txt @@ -151,7 +151,7 @@ list(TRANSFORM _executor_runner__srcs PREPEND "${EXECUTORCH_ROOT}/") # link to # add_executable(selective_build_test ${_executor_runner__srcs}) -if(CMAKE_BUILD_TYPE EQUAL "Release") +if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug") target_link_options(selective_build_test PRIVATE "LINKER:--gc-sections") endif() target_link_libraries( diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 0e3a6703c54..967610f48f8 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -52,7 +52,7 @@ list(TRANSFORM _size_test__srcs PREPEND "${EXECUTORCH_ROOT}/") # when we cross compile to ios add_executable(size_test ${_size_test__srcs}) target_link_libraries(size_test executorch) -if(CMAKE_BUILD_TYPE EQUAL "Release") +if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug") target_link_options(size_test PRIVATE "LINKER:--gc-sections") endif() @@ -64,7 +64,7 @@ target_link_options_shared_lib(portable_ops_lib) target_link_libraries( size_test_all_ops executorch portable_ops_lib portable_kernels ) -if(CMAKE_BUILD_TYPE EQUAL "Release") +if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug") target_link_options(size_test_all_ops PRIVATE "LINKER:--gc-sections") endif() @@ -76,7 +76,7 @@ add_executable(size_test_all_optimized_ops ${_size_test__srcs}) target_link_options_shared_lib(optimized_native_cpu_ops_lib) target_link_libraries( size_test_all_optimized_ops executorch optimized_native_cpu_ops_lib) -if(CMAKE_BUILD_TYPE EQUAL "Release") +if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug") target_link_options(size_test_all_optimized_ops PRIVATE "LINKER:--gc-sections") endif() endif() diff --git a/tools/cmake/preset/default.cmake b/tools/cmake/preset/default.cmake index 21f3cf53ae8..f2733f591eb 100644 --- a/tools/cmake/preset/default.cmake +++ b/tools/cmake/preset/default.cmake @@ -4,7 +4,7 @@ # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. -if(CMAKE_BUILD_TYPE STREQUAL "Release") +if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug") set(_is_build_type_release ON) set(_is_build_type_debug OFF) else() From 8782fb2f44415d1ba7a7553168344f1da3b72c0a Mon Sep 17 00:00:00 2001 From: Scott Wolchok Date: Thu, 26 Jun 2025 23:28:30 -0700 Subject: [PATCH 6/6] suppress -Wmaybe-uninitialized in #12019 [ghstack-poisoned] --- test/build_size_test.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/build_size_test.sh b/test/build_size_test.sh index 8b7c37fb020..9dde5f676bf 100644 --- a/test/build_size_test.sh +++ b/test/build_size_test.sh @@ -15,7 +15,10 @@ EXTRA_BUILD_ARGS="${@:-}" # TODO(#8357): Remove -Wno-int-in-bool-context # TODO: Replace -ET_HAVE_PREAD=0 with a CMake option. # FileDataLoader used in the size_test breaks baremetal builds with pread when missing. -COMMON_CXXFLAGS="-fno-exceptions -fno-rtti -Wall -Werror -Wno-int-in-bool-context -DET_HAVE_PREAD=0" +# -Werror=maybe-uninitialized causes failures with GCC 9.5, which we +# -currently use in CI. There were known issues with this warning and +# -std::optional: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80635 +COMMON_CXXFLAGS="-fno-exceptions -fno-rtti -Wall -Werror -Wno-int-in-bool-context -Wno-maybe-uninitialized -DET_HAVE_PREAD=0" cmake_install_executorch_lib() { echo "Installing libexecutorch.a"