You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 2.1 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. # Extern-C-Opr with MACE
  2. ### Build MegEngine `load_and_run` for arm64-v8a
  3. ```bash
  4. cd $MEGENGINE_HOME
  5. ./scripts/cmake-build/cross_build_android_arm_inference.sh -a arm64-v8a -r
  6. ```
  7. After successfully built, load_and_run should be in `$MEGENGINE_HOME/build_dir/android/arm64-v8a/Release/install/bin`
  8. ### Build MACE libraries for arm64-v8a with GPU runtime
  9. ```bash
  10. cd $MACE_HOME
  11. RUNTIME=GPU bash tools/cmake/cmake-build-arm64-v8a.sh
  12. cp -r $MACE_HOME/build/cmake-build/arm64-v8a/install $MEGENGINE_HOME/sdk/c-opr-loaders/mace/arm64-v8a
  13. ```
  14. ### Build MACE loader for MegEngine
  15. ```
  16. SDK_PATH=/path/to/mace-sdk make
  17. ```
  18. If `SDK_PATH` is not set, by default it's `./arm64-v8a`
  19. You can run with debug mode(by adding `DEBUG=1` to make command), which will show more running information
  20. ### Prepare a MACE model(for example: resnet_50), wrap it with MegEngine extern c opr
  21. ```
  22. python3 dump_model.py path/to/resnet_50.pb path/to/resnet_50.data path/to/resnet_50.mdl path/to/resnet_50.yml
  23. ```
  24. `*.pb` file denotes the model structure, `*.data` denotes the model parameters
  25. Check [here](https://github.com/XiaoMi/mace-models) to learn how to write yml files for MACE
  26. ### Run with load-and-run
  27. First of all, send all files to the executed device:
  28. - load_and_run
  29. - resnet_50.mdl
  30. - libmace_loader.so
  31. - opencl library(something like libOpenCL.so, libmali.so or libEGL.so ...) if you want to run it on GPU
  32. ```
  33. MGB_MACE_RUNTIME=GPU MGB_MACE_OPENCL_PATH=/path/to/opencl MGB_MACE_LOADER_FORMAT=NCHW /path/to/load_and_run /path/to/resnet_50.mdl --c-opr-lib /path/to/libmace_loader.so
  34. ```
  35. RUNTIME candidates:
  36. - CPU
  37. - GPU
  38. Running with GPU runtime on android needs opencl library, one can set `MGB_MACE_OPENCL_PATH` by using environment variable
  39. We mainly use NCHW data format, if you have NHWC model, use environment `MGB_MACE_LOADER_FORMAT=NHWC`
  40. For CPU runtime, default running thread is 1, could be specified with `MGB_MACE_NR_THREADS=n`
  41. if you want to run with HEXAGON runtime, more efforts should be made, please check [here](https://mace.readthedocs.io/en/latest/faq.html#why-is-mace-not-working-on-dsp).

MegEngine 安装包中集成了使用 GPU 运行代码所需的 CUDA 环境,不用区分 CPU 和 GPU 版。 如果想要运行 GPU 程序,请确保机器本身配有 GPU 硬件设备并安装好驱动。 如果你想体验在云端 GPU 算力平台进行深度学习开发的感觉,欢迎访问 MegStudio 平台