mace compile

mace 是小米开源的一个深度学习推断引擎,相比ncnn最大的优势是opencl和高通的dsp优化的很好,cpu方面ncnn还是benchmark。

从代码安装mace还是有点麻烦,主要是依赖第三方库比较多。下面简单描述一下安装的步骤的注意点。

1. 首先安装bazel。这篇文章时mace的最新发布版本是0.9. mace的master版本还不太稳定,因此使用0.9来安装。mace官方的doc中推荐的是0.13.1的bael版本,不过使用这个版本没有安装成功,提示opencl的问题。因此选择了0.15.2版本bazel. bazel直接使用 sudo Ingles安装在/usr/local/bin目录,这样就不用写在PATH中。

2. sudo apt-get install android-tools-adb.

3. 安装第三方依赖python包。主要是numpy six sh filelock jinja2 pyyaml scipy pycodestyle。

最好使用sudo pip这样直接安装后非root用户也可以使用,否则需要加 --user

pip install -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com setuptools
pip install -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com \
    "numpy>=1.14.0" \
    scipy \
    jinja2 \
    pyyaml \
    sh==1.12.14 \
    pycodestyle==2.4.0 \
    filelock

可以通过

pip install -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com setuptools

设置pip的安装包源,这样安装tensorflow/torch/torchvision时就非常快。

sudo pip install -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com tensorflow==1.6.0

4. NDK设置在/etc/profile或者~/.bashrc中。需要export ANDROID_NDK_VERSION/ANDROID_NDK/ANDROID_NDK_HOME.估计mace的安装脚本中有引用这些宏,具体没有考证。

5. 下载mace-0.9.0 release代码。解压后执行 

bash tools/build-standalone-lib.sh

因为会编译arm7/arm7-no-neon/arm8静态和动态版本,因此需要花费几分钟时间。一切顺利的话,就可以看到libmace.a.

------------------------------------- 分割线 -------------------------

如果出现opencl的问题,或者其它的问题,可以完全删除/home/candy/.cache文件夹下的所有文件,这样可以完全删除由bazel编译缓存导致的opencl问题。

 

CMake Error at /usr/share/cmake-3.28/Modules/CMakeTestCXXCompiler.cmake:60 (message): The C++ compiler "/usr/bin/c++" is not able to compile a simple test program. It fails with the following output: Change Dir: '/home/zms/lammps/build/CMakeFiles/CMakeScratch/TryCompile-WfO3XC' Run Build Command(s): /usr/bin/cmake -E env VERBOSE=1 /usr/bin/gmake -f Makefile cmTC_a0654/fast /usr/bin/gmake -f CMakeFiles/cmTC_a0654.dir/build.make CMakeFiles/cmTC_a0654.dir/build gmake[1]: Entering directory '/home/zms/lammps/build/CMakeFiles/CMakeScratch/TryCompile-WfO3XC' Building CXX object CMakeFiles/cmTC_a0654.dir/testCXXCompiler.cxx.o /usr/bin/c++ -std=gnu++17 -o CMakeFiles/cmTC_a0654.dir/testCXXCompiler.cxx.o -c /home/zms/lammps/build/CMakeFiles/CMakeScratch/TryCompile-WfO3XC/testCXXCompiler.cxx Linking CXX executable cmTC_a0654 /usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_a0654.dir/link.txt --verbose=1 /usr/bin/c++ CMakeFiles/cmTC_a0654.dir/testCXXCompiler.cxx.o -o cmTC_a0654 /home/zms/.conda/envs/mace_env/bin/ld: /lib/x86_64-linux-gnu/libc.so.6: undefined reference to `_dl_audit_symbind_alt@GLIBC_PRIVATE' /home/zms/.conda/envs/mace_env/bin/ld: /lib/x86_64-linux-gnu/libc.so.6: undefined reference to `_dl_catch_exception@GLIBC_PRIVATE' /home/zms/.conda/envs/mace_env/bin/ld: /lib/x86_64-linux-gnu/libc.so.6: undefined reference to `__nptl_change_stack_perm@GLIBC_PRIVATE' /home/zms/.conda/envs/mace_env/bin/ld: /lib/x86_64-linux-gnu/libc.so.6: undefined reference to `_dl_find_dso_for_object@GLIBC_PRIVATE' /home/zms/.conda/envs/mace_env/bin/ld: /lib/x86_64-linux-gnu/libc.so.6: undefined reference to `__tunable_is_initialized@GLIBC_PRIVATE' /home/zms/.conda/envs/mace_env/bin/ld: /lib/x86_64-linux-gnu/libc.so.6: undefined reference to `__tunable_get_val@GLIBC_PRIVATE' /home/zms/.conda/envs/mace_env/bin/ld: /lib/x86_64-linux-gnu/libc.so.6: undefined reference to `_dl_signal_exception@GLIBC_PRIVATE' /home/zms/.conda/envs/mace_env/bin/ld: /lib/x86_64-linux-gnu/libc.so.6: undefined reference to `_dl_signal_error@GLIBC_PRIVATE' /home/zms/.conda/envs/mace_env/bin/ld: /lib/x86_64-linux-gnu/libc.so.6: undefined reference to `_dl_audit_preinit@GLIBC_PRIVATE' collect2: error: ld returned 1 exit status gmake[1]: *** [CMakeFiles/cmTC_a0654.dir/build.make:99: cmTC_a0654] Error 1 gmake[1]: Leaving directory '/home/zms/lammps/build/CMakeFiles/CMakeScratch/TryCompile-WfO3XC' gmake: *** [Makefile:127: cmTC_a0654/fast] Error 2 CMake will not be able to correctly generate this project. Call Stack (most recent call first): CMakeLists.txt:31 (project)
09-18
Traceback of TorchScript, serialized code (most recent call last): File "code/__torch__/mace/calculators/lammps_mace.py", line 24, in forward torch._set_item(data, "head", head) model = self.model out = (model).forward(data, False, False, False, False, compute_displacement, False, False, False, False, ) ~~~~~~~~~~~~~~ <--- HERE node_energy = out["node_energy"] if torch.__is__(node_energy, None): File "code/__torch__/mace/modules/models.py", line 35, in forward _2 = __torch__.mace.modules.utils.get_outputs _3 = __torch__.mace.modules.utils.get_atomic_virials_stresses ctx = _0(data, compute_virials, compute_stress, compute_displacement, lammps_mliap, ) ~~ <--- HERE is_lammps = (ctx)[0] num_atoms_arange = torch.to((ctx)[2], 4) File "code/__torch__/mace/modules/utils.py", line 38, in prepare_graph else: displacement0 = displacement _10 = _1(data["positions"], data["edge_index"], data["shifts"], False, 1.0000000000000001e-09, ) ~~ <--- HERE vectors, lengths, = _10 ikw = __torch__.mace.modules.utils.InteractionKwargs(None, (0, 0)) File "code/__torch__/mace/modules/utils.py", line 198, in get_edge_vectors_and_lengths receiver = torch.select(edge_index, 0, 1) _47 = annotate(List[Optional[Tensor]], [receiver]) _48 = torch.index(positions, _47) ~~~~~~~~~~~ <--- HERE _49 = annotate(List[Optional[Tensor]], [sender]) _50 = torch.sub(_48, torch.index(positions, _49)) Traceback of TorchScript, original code (most recent call last): File "/home/zms/.conda/envs/mkl_env/lib/python3.13/site-packages/mace/calculators/lammps_mace.py", line 41, in forward compute_displacement = True data["head"] = self.head out = self.model( ~~~~~~~~~~ <--- HERE data, training=False, File "/home/zms/.conda/envs/mkl_env/lib/python3.13/site-packages/mace/modules/models.py", line 459, in forward ) -> Dict[str, Optional[torch.Tensor]]: # Setup ctx = prepare_graph( ~~~~~~~~~~~~~ <--- HERE data, compute_virials=compute_virials, File "/home/zms/.conda/envs/mkl_env/lib/python3.13/site-packages/mace/modules/utils.py", line 622, in prepare_graph ) data["positions"], data["shifts"] = p, s vectors, lengths = get_edge_vectors_and_lengths( ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ <--- HERE positions=data["positions"], edge_index=data["edge_index"], File "/home/zms/.conda/envs/mkl_env/lib/python3.13/site-packages/mace/modules/utils.py", line 268, in get_edge_vectors_and_lengths sender = edge_index[0] receiver = edge_index[1] vectors = positions[receiver] - positions[sender] + shifts # [n_edges, 3] ~~~~~~~~~~~~~~~~~~~ <--- HERE lengths = torch.linalg.norm(vectors, dim=-1, keepdim=True) # [n_edges, 1] if normalize:
最新发布
09-26
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值