Glow 설치법 및 활용
Glow는 하드웨어 가속기를 위한 머신러닝 컴파일러이자 실행 엔진이다.
ubuntu 18.04 기준 설치
소스 다운
git clone git@github.com:pytorch/glow.git # or: git clone https://github.com/pytorch/glow.git
cd glow
#submodules 다운
git submodule update --init --recursive
# 필요 package들 설치
sudo apt-get install clang clang-8 cmake graphviz libpng-dev \
libprotobuf-dev llvm-8 llvm-8-dev ninja-build protobuf-compiler wget \
opencl-headers libgoogle-glog-dev
# update-alternatives to manage the version of clang/clang++:
sudo update-alternatives --install /usr/bin/clang clang \
/usr/lib/llvm-8/bin/clang 50
sudo update-alternatives --install /usr/bin/clang++ clang++ \
/usr/lib/llvm-8/bin/clang++ 50
# Glow uses the system default C/C++ compiler (/usr/bin/C++), and so you may also want to switch your default C/C++ compiler to clang:
sudo update-alternatives --config cc
# Select the option corresponding to /usr/bin/clang ...
sudo update-alternatives --config c++
# Select the option corresponding to /usr/bin/clang++ ...
아래와 같이 clang
compiler를 선택 한다.
ProtoBuf 설치법
최신 버전은 git clone으로 다운 받고 정해진 버전은 아래와 같이 release tag를 이용해서 다운 받는다.
https://github.com/protocolbuffers/protobuf/releases/tag/v3.6.1
Git 경우
$ sudo apt-get install autoconf automake libtool curl make g++ unzip
$ git clone https://github.com/protocolbuffers/protobuf.git
$ cd protobuf
$ git submodule update --init --recursive
$ ./autogen.sh
$ ./configure
$ make
$ make check
$ sudo make install
$ sudo ldconfig # refresh shared library cache.
./configure --prefix=/usr
Glow 최종 컴파일 및 실행 파일
Debug mode 컴파일
mkdir build_Debug
cd build_Debug
cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug ..
ninja all
Release mode 컴파일
-DCMAKE_BUILD_TYPE=Release ..
실행
아래와 같이 최종적으로 tests
에 테스팅 가능한 실행 파일들이 존재한다. 각각 실행해 보면 정상적으로 설치가 되었는지 확인 가능하다.
bin
디렉터리 안에는 아래와 같이 다양한 실행파일들이 존재한다. --help
옵션을 넣어서 어떠한 인자들을 넣어야 실행 가능한지 알 수 있다.
실행 가능 파일
InstrGen fr2en mnist resnet-runtime tracing-compare
NodeGen image-classifier model-runner resnet-training
char-rnn include-bin png2bin resnet-verify
cifar10 lenet-loader ptb text-translator
테스팅과 실행: Unit tests
ninja test
를 통해서 모든 테스트들을 실행 할 수 있다.Debug
또는 Release
로 빌드를 수행한 디렉토리에서 수행한다.
결과는 아래와 같다.
jemin@jemin:~/development/glow/build_Debug$ ninja test
[0/1] Running tests...
Test project /home/jemin/development/glow/build_Debug
Start 1: BackendCorrectnessTest
1/35 Test #1: BackendCorrectnessTest .............. Passed 11.51 sec
Start 2: BackendTest
2/35 Test #2: BackendTest ......................... Passed 1.35 sec
Start 3: BasicIRTest
3/35 Test #3: BasicIRTest ......................... Passed 0.14 sec
Start 4: Caffe2ImporterTest
4/35 Test #4: Caffe2ImporterTest .................. Passed 1.93 sec
Start 5: DeviceManagerTest
5/35 Test #5: DeviceManagerTest ................... Passed 0.39 sec
Start 6: ThreadPoolExecutorTest
6/35 Test #6: ThreadPoolExecutorTest .............. Passed 1.43 sec
Start 7: Float16Test
7/35 Test #7: Float16Test ......................... Passed 0.00 sec
Start 8: GemmTest
8/35 Test #8: GemmTest ............................ Passed 0.09 sec
Start 9: GlowOnnxifiManagerTest
9/35 Test #9: GlowOnnxifiManagerTest .............. Passed 0.09 sec
Start 10: GradCheckTest
10/35 Test #10: GradCheckTest ....................... Passed 3.63 sec
Start 11: GraphGradTest
11/35 Test #11: GraphGradTest ....................... Passed 0.07 sec
Start 12: GraphOptzTest
12/35 Test #12: GraphOptzTest ....................... Passed 0.11 sec
Start 13: GraphSchedulerTest
13/35 Test #13: GraphSchedulerTest .................. Passed 0.01 sec
Start 14: GraphTest
14/35 Test #14: GraphTest ........................... Passed 0.45 sec
Start 15: HostManagerTest
15/35 Test #15: HostManagerTest ..................... Passed 3.94 sec
Start 16: HyphenTest
16/35 Test #16: HyphenTest .......................... Passed 0.83 sec
Start 17: IROptTest
17/35 Test #17: IROptTest ........................... Passed 0.01 sec
Start 18: ImageTest
18/35 Test #18: ImageTest ........................... Passed 0.24 sec
Start 19: LLVMIRGenTest
19/35 Test #19: LLVMIRGenTest ....................... Passed 0.04 sec
Start 20: MLTest
20/35 Test #20: MLTest .............................. Passed 17.52 sec
Start 21: MemoryAllocatorTest
21/35 Test #21: MemoryAllocatorTest ................. Passed 0.14 sec
Start 22: OnnxImporterTest
22/35 Test #22: OnnxImporterTest .................... Passed 0.30 sec
Start 23: OnnxExporterTest
23/35 Test #23: OnnxExporterTest .................... Passed 0.06 sec
Start 24: OperatorGradTest
24/35 Test #24: OperatorGradTest .................... Passed 0.04 sec
Start 25: OperatorTest
25/35 Test #25: OperatorTest ........................ Passed 6.80 sec
Start 26: PartitionerTest
26/35 Test #26: PartitionerTest ..................... Passed 0.11 sec
Start 27: RecommendationSystemTest
27/35 Test #27: RecommendationSystemTest ............ Passed 226.65 sec
Start 28: ProvisionerTest
28/35 Test #28: ProvisionerTest ..................... Passed 0.54 sec
Start 29: QuantizationTest
29/35 Test #29: QuantizationTest .................... Passed 3.96 sec
Start 30: TensorsTest
30/35 Test #30: TensorsTest ......................... Passed 0.17 sec
Start 31: TensorPoolTest
31/35 Test #31: TensorPoolTest ...................... Passed 0.01 sec
Start 32: ThreadPoolTest
32/35 Test #32: ThreadPoolTest ...................... Passed 0.01 sec
Start 33: TraceEventsTest
33/35 Test #33: TraceEventsTest ..................... Passed 6.74 sec
Start 34: TypeAToTypeBFunctionConverterTest
34/35 Test #34: TypeAToTypeBFunctionConverterTest ... Passed 0.05 sec
Start 35: UtilsTest
35/35 Test #35: UtilsTest ........................... Passed 0.01 sec
100% tests passed, 0 tests failed out of 35
Label Time Summary:
EXPENSIVE = 226.65 sec*proc (1 test)
Total Test time (real) = 289.40 sec
C++ API examples
example 디렉터리에 각종 예제가 존재 한다.
MAC-OS (10.14.6 Mojave)
다운
git clone git@github.com:pytorch/glow.git # or: git clone https://github.com/pytorch/glow.git
cd glow
git submodule update --init --recursive
필수 페키지 설치
brew install cmake graphviz libpng ninja protobuf wget glog autopep8
brew install llvm@7
링크
ln -s "/usr/local/opt/llvm@7/bin/clang-format" "/usr/local/bin/clang-format"
ln -s "/usr/local/opt/llvm@7/bin/clang-tidy" "/usr/local/bin/clang-tidy"
Mac OS 10.14 (Mojava)의 경우 ninja all시 header 파일 몇개가 없어서 빌드가 실패 한다.
아래와 같이 CLT을 실행해서 추가적으로 설치 한다.
open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg
설치 명령어
mkdir build_Debug
cd ./build_Debug
cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug -DLLVM_DIR=/usr/local/opt/llvm@7/lib/cmake/llvm ..
#결과
-- Found glog with new-style glog target.
-- Found LLVM 7.1.0
-- Using LLVMConfig.cmake in: /usr/local/opt/llvm@7/lib/cmake/llvm
Adding CPU backend.
Adding Interpreter backend.
--
-- ******** Summary ********
-- CMake version : 3.13.4
-- CMake command : /usr/local/Cellar/cmake/3.13.4/bin/cmake
-- System : Darwin
-- C++ compiler : /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
-- C++ compiler version : 10.0.1.10010046
-- CXX flags : -Wall -Wnon-virtual-dtor -fno-exceptions -fno-rtti -Wnon-virtual-dtor
-- Build type : Debug
-- Compile definitions : GIT_SHA1="cd686e48";GIT_DATE="2019-07-26";WITH_PNG;GLOW_WITH_LLVMIRCODEGEN=1;GLOW_WITH_CPU=1;GOOGLE_PROTOBUF_NO_RTTI;ONNX_NAMESPACE=glow_onnx
-- CMAKE_PREFIX_PATH :
-- CMAKE_INSTALL_PREFIX : /usr/local
-- CMAKE_MODULE_PATH : /Users/jeminlee/development/glow/cmake/modules
--
-- ONNX version : 1.5.0
-- ONNX NAMESPACE : glow_onnx
-- ONNX_BUILD_TESTS : OFF
-- ONNX_BUILD_BENCHMARKS : OFF
-- ONNX_USE_LITE_PROTO : OFF
-- ONNXIFI_DUMMY_BACKEND : OFF
-- ONNXIFI_ENABLE_EXT : OFF
--
-- Protobuf compiler : /usr/local/bin/protoc
-- Protobuf includes : /usr/local/include
-- Protobuf libraries : /usr/local/lib/libprotobuf.dylib
-- BUILD_ONNX_PYTHON : OFF
-- Failed to find LLVM FileCheck
-- git Version: v1.5.0
-- Version: 1.5.0
-- Performing Test HAVE_THREAD_SAFETY_ATTRIBUTES -- failed to compile
-- Performing Test HAVE_STD_REGEX -- success
-- Performing Test HAVE_GNU_POSIX_REGEX -- failed to compile
-- Performing Test HAVE_POSIX_REGEX -- success
-- Performing Test HAVE_STEADY_CLOCK -- success
Skipping adding test en2gr_cpu_test because it requires a models directory. Configure with -DGLOW_MODELS_DIR.
Skipping adding test en2gr_quantization_test because it requires a models directory. Configure with -DGLOW_MODELS_DIR.
Skipping adding test en2gr_cpu_partition_test because it requires a models directory. Configure with -DGLOW_MODELS_DIR.
Skipping adding test en2gr_cpu_config_test because it requires a models directory. Configure with -DGLOW_MODELS_DIR.
Skipping adding test resnet_runtime_test because it requires a models directory. Configure with -DGLOW_MODELS_DIR.
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/jeminlee/development/glow/build_Debug
$ ninja all
[1/300] Running gen_proto.py on onnx/onnx.in.proto
Processing /Users/jeminlee/development/glow/thirdparty/onnx/onnx/onnx.in.proto
Writing /Users/jeminlee/development/glow/build_test/lib/Importer/build_onnx/onnx/onnx_glow_onnx-ml.proto
Writing /Users/jeminlee/development/glow/build_test/lib/Importer/build_onnx/onnx/onnx_glow_onnx-ml.proto3
Writing /Users/jeminlee/development/glow/build_test/lib/Importer/build_onnx/onnx/onnx-ml.pb.h
generating /Users/jeminlee/development/glow/build_test/lib/Importer/build_onnx/onnx/onnx_pb.py
[5/300] Running gen_proto.py on onnx/onnx-operators.in.proto
Processing /Users/jeminlee/development/glow/thirdparty/onnx/onnx/onnx-operators.in.proto
Writing /Users/jeminlee/development/glow/build_test/lib/Importer/build_onnx/onnx/onnx-operators_glow_onnx-ml.proto
Writing /Users/jeminlee/development/glow/build_test/lib/Importer/build_onnx/onnx/onnx-operators_glow_onnx-ml.proto3
Writing /Users/jeminlee/development/glow/build_test/lib/Importer/build_onnx/onnx/onnx-operators-ml.pb.h
generating /Users/jeminlee/development/glow/build_test/lib/Importer/build_onnx/onnx/onnx_operators_pb.py
[42/300] InstrGen: Generating instructions.
Writing instr descriptors to:
/Users/jeminlee/development/glow/build_test/glow/AutoGenInstr.h
/Users/jeminlee/development/glow/build_test/glow/AutoGenInstr.cpp
/Users/jeminlee/development/glow/build_test/glow/AutoGenInstr.def
/Users/jeminlee/development/glow/build_test/glow/AutoGenIRBuilder.h
/Users/jeminlee/development/glow/build_test/glow/AutoGenIRBuilder.cpp
/Users/jeminlee/development/glow/build_test/glow/AutoGenIRGen.h
[45/300] NodeGen: Generating nodes.
Writing node descriptors to:
/Users/jeminlee/development/glow/build_test/glow/AutoGenNodes.h
/Users/jeminlee/development/glow/build_test/glow/AutoGenNodes.cpp
/Users/jeminlee/development/glow/build_test/glow/AutoGenNodes.def
[300/300] Linking CXX executable tests/RuntimeBench
문제해결 (Troubleshooting)
git pull 후 tests/googletest/googletest/CMakeLists.txt:133 (cxx_library) 관련 에러
Glow는 Thirdparty library들이 많이 엮여 있다. 따라서 관련 라이브러리들도 모두 업데이트 해야한다.
해결 방법
git submodule sync
Synchronizing submodule url for 'tests/OutputCheck'
Synchronizing submodule url for 'tests/googlebenchmark'
Synchronizing submodule url for 'tests/googletest'
Synchronizing submodule url for 'thirdparty/foxi'
Synchronizing submodule url for 'thirdparty/fp16'
Synchronizing submodule url for 'thirdparty/onnx'
Synchronizing submodule url for 'thirdparty/pybind11'
git submodule update --init --recursive
Submodule path 'tests/googletest': checked out '703bd9caab50b139428cea1aaff9974ebee5742e'
Submodule path 'thirdparty/foxi': checked out '97fe555430a857581b9b826ecd955e4f0a3653f0'
llvm 경로 문제
보통 자동 설치하면 llvm 경로는 알아서 잡힌다.
경로가 잡히지 않으면 아래와 같이 DLLVM_DIR 옵션을 준다.
cmake -G Ninja ../glow \
-DCMAKE_BUILD_TYPE=Debug \
-DLLVM_DIR=/usr/local/opt/llvm@7/lib/cmake/llvm
'AI > Embedded Deep learning' 카테고리의 다른 글
MLPerf (0) | 2020.07.01 |
---|---|
ONNX (4) | 2020.05.04 |
Coral Dev Board (Google Edge TPU) 설정 및 사용후기 (2) | 2019.08.13 |
Glow: graph lowering compiler for hardware accelerators (0) | 2019.02.07 |
TensorFlow Lite 예제 실행 (2) | 2017.12.05 |