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

想本地编译一个Apple Sillicon M1版本的大概要怎么做? #8

Open
wzh4464 opened this issue Jan 22, 2022 · 12 comments
Open

Comments

@wzh4464
Copy link

wzh4464 commented Jan 22, 2022

git clone 下来跑 python setup.py bdist_wheel 的话直接是 x86

@tonquer
Copy link
Owner

tonquer commented Jan 22, 2022

首先你需要编译openmp, 参考ncnn提供的方法

        wget https://github.com/llvm/llvm-project/releases/download/llvmorg-11.0.0/openmp-11.0.0.src.tar.xz
        tar -xf openmp-11.0.0.src.tar.xz
        cd openmp-11.0.0.src
        sed -i'' -e '/.size __kmp_unnamed_critical_addr/d' runtime/src/z_Linux_asm.S
        sed -i'' -e 's/__kmp_unnamed_critical_addr/___kmp_unnamed_critical_addr/g' runtime/src/z_Linux_asm.S
        mkdir -p build && cd build
        cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=install -DCMAKE_OSX_ARCHITECTURES="x86_64;arm64" \
            -DLIBOMP_ENABLE_SHARED=OFF -DLIBOMP_OMPT_SUPPORT=OFF -DLIBOMP_USE_HWLOC=OFF ..
        cmake --build . -j 2

将编译好的libomp.a替换下本项目目录下的
VulkanSDK/macos/libomp.a

修改一下setup.py
加一行
image

"-DCMAKE_OSX_ARCHITECTURES=\"x86_64;arm64\"",

编译好可以用lipo -info看看支持的架构
image

因为我没得m1,你可以参考一下

@tonquer
Copy link
Owner

tonquer commented Jan 24, 2022

tonquer added a commit that referenced this issue Jan 24, 2022
@wzh4464
Copy link
Author

wzh4464 commented Jan 25, 2022

之前的我试了一下 两个静态库都arm编译了,但是输出的库还是libxxxxxx86_64....
新的我试一下

@wzh4464
Copy link
Author

wzh4464 commented Jan 25, 2022

$ pip install ~/Downloads/waifu2x_vulkan-1.1.1-cp39-cp39-macosx_10_9_universal2.whl
ERROR: waifu2x_vulkan-1.1.1-cp39-cp39-macosx_10_9_universal2.whl is not a supported wheel on this platform.

@wzh4464
Copy link
Author

wzh4464 commented Jan 25, 2022

$ python setup.py bdist_wheel
的前几行是

darwin
running bdist_wheel 
running build
running build_py
creating build
creating build/lib.macosx-10.9-x86_64-3.8
creating build/lib.macosx-10.9-x86_64-3.8/waifu2x_vulkan

@tonquer
Copy link
Owner

tonquer commented Jan 25, 2022

你安装universal2版本的python试试
看起来你的python版本是x86转义的不是原生arm的
image

@wzh4464
Copy link
Author

wzh4464 commented Jan 25, 2022 via email

@tonquer
Copy link
Owner

tonquer commented Jan 25, 2022

你能找到你系统libpython38.dylib吗
用lipo看看架构是不是arm的

@wzh4464
Copy link
Author

wzh4464 commented Jan 25, 2022

$ lipo -info libpython3.8.dylib                 
Non-fat file: libpython3.8.dylib is architecture: arm64

这个python就是我运行python setup.py bdist_wheel 的python

@tonquer
Copy link
Owner

tonquer commented Jan 25, 2022

那你试试第二种编译,直接运行sh build_mac.sh

@wzh4464
Copy link
Author

wzh4464 commented Jan 25, 2022

编译成功.so了多谢

@tonquer
Copy link
Owner

tonquer commented Jan 25, 2022

可以把so 放入到waifu_vulkan目录,然后用

python setup2.py  bdist_wheel --plat-name=macosx_10_15_universal2 --python-tag=cp38

打包

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants