Skip to content
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

[Build] reduce the size of the shared library #21544

Open
saad-koukous opened this issue Jul 29, 2024 · 4 comments
Open

[Build] reduce the size of the shared library #21544

saad-koukous opened this issue Jul 29, 2024 · 4 comments
Labels
build build issues; typically submitted using template stale issues that have not been addressed in a while; categorized by a bot

Comments

@saad-koukous
Copy link

Describe the issue

I successfully built a shared library, but the size of the .so file is 14 MB, which is too big for me. How can I reduce it?
onnx v1.18.0

Urgency

No response

Target platform

beagleBone Black rev3 armv7 gcc 8.3

Build script

ARMCC_FLAGS="-march=armv7-a -mfpu=neon-vfpv3 -funsafe-math-optimizations -mfp16-format=ieee"
ARMCC_PREFIX=/home/saad/toolchains/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf/bin/arm-linux-gnueabihf-
cmake -DCMAKE_C_COMPILER=${ARMCC_PREFIX}gcc
-DCMAKE_CXX_COMPILER=${ARMCC_PREFIX}g++
-DCMAKE_C_FLAGS="${ARMCC_FLAGS}"
-DCMAKE_CXX_FLAGS="${ARMCC_FLAGS}"
-DCMAKE_SYSTEM_NAME=Linux
-DCMAKE_SYSTEM_PROCESSOR=armv7
-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON
-Donnxruntime_BUILD_SHARED_LIB=ON
-Donnxruntime_BUILD_UNIT_TESTS=OFF
-Donnxruntime_MINIMAL_BUILD_CUSTOM_OPS=ON
-DCMAKE_BUILD_TYPE=MinSizeRel
-Donnxruntime_ENABLE_CPUINFO=OFF
../cmake
make -j6

Error / output

no error

Visual Studio Version

No response

GCC / Compiler Version

No response

@saad-koukous saad-koukous added the build build issues; typically submitted using template label Jul 29, 2024
@skottmckay
Copy link
Contributor

Create a config based on your model to limit the operators and types to the required ones.

https://github.com/microsoft/onnxruntime/blob/main/docs/Reduced_Operator_Kernel_build.md

@saad-koukous
Copy link
Author

saad-koukous commented Jul 31, 2024

Thank you for your response. After generating the required operators, how can I use them in the build script I previously provided?
Generated from ONNX model/s:

  • C:\Users\SKoukous\Documents\model\tinyCNN_KD.onnx
    ai.onnx;17;Add,Concat,Constant,Conv,Relu,Resize,Shape,Sigmoid,Slice

@edgchen1
Copy link
Contributor

To do a reduced ops build, it's easiest to use build.py.

Otherwise, if you want to directly use CMake, you'll need to also run reduce_op_kernels.py (see the doc linked above) and define onnxruntime_REDUCED_OPS_BUILD=ON.

Here's how build.py calls reduce_op_kernels.py:

reduce_ops(

Copy link
Contributor

This issue has been automatically marked as stale due to inactivity and will be closed in 30 days if no further activity occurs. If further support is needed, please provide an update and/or more details.

@github-actions github-actions bot added the stale issues that have not been addressed in a while; categorized by a bot label Sep 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build build issues; typically submitted using template stale issues that have not been addressed in a while; categorized by a bot
Projects
None yet
Development

No branches or pull requests

3 participants