-
Notifications
You must be signed in to change notification settings - Fork 689
Arm Zephyr cmake Preset #11923
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Arm Zephyr cmake Preset #11923
Changes from all commits
be258b1
cabbe9c
73e721b
4e09438
7e94e9f
268cf6f
9c5a727
50436ad
e508ff6
aa28a29
7772a68
a18ded6
d6efd1e
1cc7ca8
7264cd8
6e9b3e1
8edf792
e5c3572
752b386
a1ccdaa
1aacaee
ed10715
39c8812
34af1ac
3cb6a8e
d9ee622
dae1c27
34caf6e
cca82a5
8fa8ea7
e177c1d
0fd39bf
7af3884
e547c85
8dc97d5
0063bf1
3d5c07d
a25d611
eaca9bb
007851d
7d62f5a
fb84820
63db67a
001b543
314657f
669e525
169ecc1
7cab8b6
730788f
aebf60b
c017170
a92621e
e70c604
1545c7e
bd78d21
082799c
997ec26
49cf07e
f52ed35
07d985c
fa2f0ae
92c7151
f54e048
f404ad8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,4 @@ | |
# Setup arm example environment (including TOSA tools) | ||
git config --global user.email "[email protected]" | ||
git config --global user.name "Github Executorch" | ||
bash examples/arm/setup.sh --i-agree-to-the-contained-eula | ||
bash examples/arm/setup.sh --i-agree-to-the-contained-eula ${@:-} | ||
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -34,6 +34,45 @@ jobs: | |||||||||||||||||||||||||
${CONDA_RUN} cmake --preset ${{ matrix.preset }} | ||||||||||||||||||||||||||
${CONDA_RUN} cmake --build cmake-out -j$(( $(sysctl -n hw.ncpu) - 1 )) | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
zephyr: | ||||||||||||||||||||||||||
uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main | ||||||||||||||||||||||||||
strategy: | ||||||||||||||||||||||||||
fail-fast: false | ||||||||||||||||||||||||||
matrix: | ||||||||||||||||||||||||||
preset: [zephyr] | ||||||||||||||||||||||||||
Comment on lines
+37
to
+42
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Am I misunderstanding this, or should this technically have two different presets for ARM builds?
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think preset baremetal is a thing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can revisit this in the future. I like what @jathu proposed but we need to think a bit more about baremetal builds I guess. |
||||||||||||||||||||||||||
with: | ||||||||||||||||||||||||||
job-name: build | ||||||||||||||||||||||||||
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} | ||||||||||||||||||||||||||
runner: linux.2xlarge | ||||||||||||||||||||||||||
docker-image: executorch-ubuntu-22.04-arm-sdk | ||||||||||||||||||||||||||
submodules: recursive | ||||||||||||||||||||||||||
timeout: 90 | ||||||||||||||||||||||||||
script: | | ||||||||||||||||||||||||||
set -eux | ||||||||||||||||||||||||||
# The generic Linux job chooses to use base env, not the one setup by the image | ||||||||||||||||||||||||||
CONDA_ENV=$(conda env list --json | jq -r ".envs | .[-1]") | ||||||||||||||||||||||||||
conda activate "${CONDA_ENV}" | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
./install_requirements.sh > /dev/null | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
# Download toolchain | ||||||||||||||||||||||||||
toolchain_url="https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.17.2/toolchain_linux-x86_64_arm-zephyr-eabi.tar.xz" | ||||||||||||||||||||||||||
toolchain_dir="arm-zephyr-eabi" | ||||||||||||||||||||||||||
curl --output "${toolchain_dir}.tar.xz" -L "${toolchain_url}" | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
# Verify download | ||||||||||||||||||||||||||
echo "93128be0235cf5cf5f1ee561aa6eac5f ${toolchain_dir}.tar.xz" > arm-zephyr-eabi.md5 | ||||||||||||||||||||||||||
md5sum -c --strict arm-zephyr-eabi.md5 | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
# Extract and install to PATH | ||||||||||||||||||||||||||
tar xf "${toolchain_dir}.tar.xz" | ||||||||||||||||||||||||||
rm -f "${toolchain_dir}.tar.xz" | ||||||||||||||||||||||||||
toolchain_bin_path="$(cd ${toolchain_dir}/bin && pwd)" | ||||||||||||||||||||||||||
export PATH=$PATH:${toolchain_bin_path} | ||||||||||||||||||||||||||
Comment on lines
+58
to
+71
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One of the goals with presets, is that it should work "out of the box" without having to manually do extra steps. If you look at the other examples in the workflow, they are all 3-4 commands. What can we do to achieve that here? Right now, if I fetch ET and run There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well in CI we will have to download the toolchain separately right? This is similar to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think to support working out of the box, downloading the Arm toolchains would need to included as part of the preset configuration process (maybe the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't call setup_macos in this workflow because all the toolchains needed to build for macOS/iOS are already present in macOS. You need to have the toolchain ready before calling cmake so I don't think we can make it a part of the cmake build process. Perhaps we can abstract this out to a script that can be used be users? Not a blocker for this PR, we can follow up There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah it should be setup_zephyr.sh that handles the toolchain installation. |
||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
# Build Arm Zephyr Preset | ||||||||||||||||||||||||||
cmake --preset ${{ matrix.preset }} | ||||||||||||||||||||||||||
cmake --build cmake-out -j$(( $(nproc) - 1 )) | ||||||||||||||||||||||||||
linux: | ||||||||||||||||||||||||||
uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main | ||||||||||||||||||||||||||
strategy: | ||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -223,6 +223,10 @@ jobs: | |
permissions: | ||
id-token: write | ||
contents: read | ||
strategy: | ||
matrix: | ||
os: [bare_metal, zephyr-preset] | ||
fail-fast: false | ||
with: | ||
runner: linux.2xlarge | ||
docker-image: executorch-ubuntu-22.04-arm-sdk | ||
|
@@ -234,35 +238,62 @@ jobs: | |
CONDA_ENV=$(conda env list --json | jq -r ".envs | .[-1]") | ||
conda activate "${CONDA_ENV}" | ||
|
||
cxx_flags="-fno-exceptions -fno-rtti -Wall -Werror -Wno-int-in-bool-context -DET_HAVE_PREAD=0" | ||
setup_script_args="" | ||
if [[ ${{ matrix.os}} == "bare_metal" ]]; then | ||
toolchain_prefix=arm-none-eabi- | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't have to specify There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the arm scripts, the default toolchain is set to |
||
threshold="103268" # ~100KiB | ||
toolchain_cmake=examples/arm/ethos-u-setup/arm-none-eabi-gcc.cmake | ||
elif [[ ${{ matrix.os}} == "zephyr-preset" ]]; then | ||
setup_script_args="--target-toolchain zephyr" | ||
toolchain_prefix=arm-zephyr-eabi- | ||
threshold="133120" # should be ~125KB, set threshold to 130KB | ||
toolchain_cmake=examples/zephyr/x86_64-linux-arm-zephyr-eabi-gcc.cmake | ||
else | ||
echo "Fail unsupport OS selection ${{ matrix.os }}" | ||
exit 1 | ||
fi | ||
|
||
source .ci/scripts/utils.sh | ||
install_executorch "--use-pt-pinned-commit" | ||
.ci/scripts/setup-arm-baremetal-tools.sh | ||
.ci/scripts/setup-arm-baremetal-tools.sh ${setup_script_args} | ||
source examples/arm/ethos-u-scratch/setup_path.sh | ||
|
||
# User baremetal toolchain | ||
arm-none-eabi-c++ --version | ||
toolchain_cmake=examples/arm/ethos-u-setup/arm-none-eabi-gcc.cmake | ||
# User toolchain | ||
${toolchain_prefix}c++ --version | ||
|
||
# Setup cmake target to desired toolchain | ||
toolchain_cmake=$(realpath ${toolchain_cmake}) | ||
|
||
# Build and test size test | ||
bash test/build_size_test.sh "-DCMAKE_TOOLCHAIN_FILE=${toolchain_cmake} -DEXECUTORCH_BUILD_ARM_BAREMETAL=ON" | ||
# Build and run size test | ||
if [[ ${{ matrix.os}} == "bare_metal" ]]; then | ||
bash test/build_size_test.sh "-DCMAKE_TOOLCHAIN_FILE=${toolchain_cmake} -DEXECUTORCH_BUILD_ARM_BAREMETAL=ON" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not in this PR but some day we should have a arm baremetal preset instead of running this script. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That makes sense, should I make an issue for it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah let's create an issue There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Created the issue here: #12186, can discuss more about what this feature should look like on that thread. |
||
elif [[ ${{ matrix.os}} == "zephyr-preset" ]]; then | ||
CXXFLAGS=${cxx_flags} cmake --preset zephyr -DCMAKE_BUILD_TYPE=Release -DEXECUTORCH_OPTIMIZE_SIZE=ON -DCMAKE_INSTALL_PREFIX=cmake-out -Bcmake-out . | ||
cmake --build cmake-out -j9 --target install --config Release | ||
CXXFLAGS=${cxx_flags} cmake -DCMAKE_TOOLCHAIN_FILE=${toolchain_cmake} -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=cmake-out -Bcmake-out/test test | ||
cmake --build cmake-out/test -j9 --config Release | ||
else | ||
echo "Fail unsupport OS selection ${{ matrix.os }}" | ||
exit 1 | ||
fi | ||
|
||
elf="cmake-out/test/size_test" | ||
|
||
# Dump basic info | ||
ls -al ${elf} | ||
arm-none-eabi-size ${elf} | ||
${toolchain_prefix}size ${elf} | ||
|
||
# Dump symbols | ||
# Dump symbol | ||
python .github/scripts/run_nm.py -e ${elf} | ||
python .github/scripts/run_nm.py -e ${elf} -f "executorch" -p "arm-none-eabi-" | ||
python .github/scripts/run_nm.py -e ${elf} -f "executorch_text" -p "arm-none-eabi-" | ||
python .github/scripts/run_nm.py -e ${elf} -f "executorch" -p "${toolchain_prefix}" | ||
python .github/scripts/run_nm.py -e ${elf} -f "executorch_text" -p "${toolchain_prefix}" | ||
|
||
# Add basic guard - TODO: refine this! | ||
arm-none-eabi-strip ${elf} | ||
${toolchain_prefix}strip ${elf} | ||
output=$(ls -la ${elf}) | ||
arr=($output) | ||
size=${arr[4]} | ||
threshold="103268" # ~100KiB | ||
echo "size: $size, threshold: $threshold" | ||
if [[ "$size" -le "$threshold" ]]; then | ||
echo "Success $size <= $threshold" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
# | ||
# Copyright (c) 2020-2022 Arm Limited. All rights reserved. | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the License); you may | ||
# not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an AS IS BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
# Copied this file from core_platform/cmake/toolchain/arm-non-eabi-gcc.cmake And | ||
# modified to align better with cs300 platform | ||
|
||
set(TARGET_CPU | ||
"cortex-m55" | ||
CACHE STRING "Target CPU" | ||
) | ||
string(TOLOWER ${TARGET_CPU} CMAKE_SYSTEM_PROCESSOR) | ||
|
||
set(CMAKE_SYSTEM_NAME Generic) | ||
set(CMAKE_C_COMPILER "arm-zephyr-eabi-gcc") | ||
set(CMAKE_CXX_COMPILER "arm-zephyr-eabi-g++") | ||
set(CMAKE_ASM_COMPILER "arm-zephyr-eabi-gcc") | ||
set(CMAKE_LINKER "arm-zephyr-eabi-ld") | ||
|
||
set(CMAKE_EXECUTABLE_SUFFIX ".elf") | ||
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) | ||
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) | ||
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) | ||
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) | ||
|
||
# Select C/C++ version | ||
set(CMAKE_C_STANDARD 11) | ||
set(CMAKE_CXX_STANDARD 17) | ||
|
||
set(GCC_CPU ${CMAKE_SYSTEM_PROCESSOR}) | ||
string(REPLACE "cortex-m85" "cortex-m55" GCC_CPU ${GCC_CPU}) | ||
|
||
# Compile options | ||
add_compile_options( | ||
-mcpu=${GCC_CPU} -mthumb "$<$<CONFIG:DEBUG>:-gdwarf-3>" | ||
"$<$<COMPILE_LANGUAGE:CXX>:-fno-unwind-tables;-fno-rtti;-fno-exceptions>" | ||
-fdata-sections -ffunction-sections | ||
) | ||
|
||
# Compile defines | ||
add_compile_definitions("$<$<NOT:$<CONFIG:DEBUG>>:NDEBUG>") | ||
|
||
# Link options | ||
add_link_options(-mcpu=${GCC_CPU} -mthumb) | ||
|
||
if(SEMIHOSTING) | ||
add_link_options(--specs=rdimon.specs) | ||
else() | ||
add_link_options(--specs=nosys.specs) | ||
endif() | ||
|
||
# Set floating point unit | ||
if(CMAKE_SYSTEM_PROCESSOR MATCHES "\\+fp") | ||
set(FLOAT hard) | ||
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "\\+nofp") | ||
set(FLOAT soft) | ||
elseif( | ||
CMAKE_SYSTEM_PROCESSOR MATCHES "cortex-m33(\\+|$)" | ||
OR CMAKE_SYSTEM_PROCESSOR MATCHES "cortex-m55(\\+|$)" | ||
OR CMAKE_SYSTEM_PROCESSOR MATCHES "cortex-m85(\\+|$)" | ||
) | ||
set(FLOAT hard) | ||
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "cortex-m4(\\+|$)" | ||
OR CMAKE_SYSTEM_PROCESSOR MATCHES "cortex-m7(\\+|$)" | ||
) | ||
set(FLOAT hard) | ||
set(FPU_CONFIG "fpv4-sp-d16") | ||
add_compile_options(-mfpu=${FPU_CONFIG}) | ||
add_link_options(-mfpu=${FPU_CONFIG}) | ||
else() | ||
set(FLOAT soft) | ||
endif() | ||
|
||
if(FLOAT) | ||
add_compile_options(-mfloat-abi=${FLOAT}) | ||
add_link_options(-mfloat-abi=${FLOAT}) | ||
endif() | ||
|
||
add_link_options(LINKER:--nmagic,--gc-sections) | ||
|
||
# Compilation warnings | ||
add_compile_options( | ||
# -Wall -Wextra -Wcast-align -Wdouble-promotion -Wformat | ||
# -Wmissing-field-initializers -Wnull-dereference -Wredundant-decls -Wshadow | ||
# -Wswitch -Wswitch-default -Wunused -Wno-redundant-decls | ||
-Wno-stringop-overread | ||
-Wno-error=format= | ||
-Wno-error=maybe-uninitialized | ||
-Wno-error=deprecated-declarations | ||
-Wno-error=shift-count-overflow | ||
-Wno-psabi | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
|
||
digantdesai marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# All rights reserved. | ||
# | ||
# This source code is licensed under the BSD-style license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
set_overridable_option(EXECUTORCH_BUILD_COREML OFF) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: most, if not all, of these are off by default anyways — so I guess we don't need to manually do it here again |
||
set_overridable_option(EXECUTORCH_ENABLE_EVENT_TRACER OFF) | ||
set_overridable_option(EXECUTORCH_BUILD_KERNELS_CUSTOM OFF) | ||
set_overridable_option(EXECUTORCH_BUILD_KERNELS_CUSTOM_AOT OFF) | ||
set_overridable_option(EXECUTORCH_BUILD_EXTENSION_DATA_LOADER OFF) | ||
set_overridable_option(EXECUTORCH_BUILD_EXTENSION_FLAT_TENSOR OFF) | ||
set_overridable_option(EXECUTORCH_BUILD_EXTENSION_LLM OFF) | ||
set_overridable_option(EXECUTORCH_BUILD_EXTENSION_MODULE OFF) | ||
set_overridable_option(EXECUTORCH_BUILD_EXTENSION_TRAINING OFF) | ||
set_overridable_option(EXECUTORCH_BUILD_EXTENSION_APPLE OFF) | ||
set_overridable_option(EXECUTORCH_BUILD_MPS OFF) | ||
set_overridable_option(EXECUTORCH_BUILD_NEURON OFF) | ||
set_overridable_option(EXECUTORCH_BUILD_OPENVINO OFF) | ||
set_overridable_option(EXECUTORCH_BUILD_PYBIND OFF) | ||
set_overridable_option(EXECUTORCH_BUILD_QNN OFF) | ||
set_overridable_option(EXECUTORCH_BUILD_KERNELS_OPTIMIZED OFF) | ||
set_overridable_option(EXECUTORCH_BUILD_KERNELS_QUANTIZED OFF) | ||
set_overridable_option(EXECUTORCH_BUILD_DEVTOOLS OFF) | ||
set_overridable_option(EXECUTORCH_BUILD_TESTS OFF) | ||
set_overridable_option(EXECUTORCH_BUILD_XNNPACK OFF) | ||
set_overridable_option(EXECUTORCH_BUILD_VULKAN OFF) | ||
set_overridable_option(EXECUTORCH_BUILD_PORTABLE_OPS ON) | ||
set_overridable_option(EXECUTORCH_BUILD_CADENCE OFF) | ||
set_overridable_option(EXECUTORCH_BUILD_PTHREADPOOL OFF) | ||
set_overridable_option(EXECUTORCH_BUILD_CPUINFO OFF) | ||
set_overridable_option(EXECUTORCH_USE_CPP_CODE_COVERAGE OFF) |
Uh oh!
There was an error while loading. Please reload this page.