본문 바로가기

컴퓨터/머신러닝 (Machine Learning)

AMD GPU MIGraphX docker 사용 정리

Ubuntu 20.04

ROCm 5.4

Radeon VII


Nvidia의 TensorRT와 같은 포지션에 있는
AMD의 MIGraphX 정리

 

apt install, build from source, docker 를 통한 설치를 모두 해본 결과

docker가 가장 문제없이 잘 돌아간다.

 

참고 글

GitHub - ROCmSoftwarePlatform/AMDMIGraphX: AMD's graph optimization engine.

 

GitHub - ROCmSoftwarePlatform/AMDMIGraphX: AMD's graph optimization engine.

AMD's graph optimization engine. Contribute to ROCmSoftwarePlatform/AMDMIGraphX development by creating an account on GitHub.

github.com

 

1. git clone

 

https://github.com/ROCmSoftwarePlatform/AMDMIGraphX.git

 

2. AMDMIGraphX 폴더에서 docker build

시간이 조금 걸린다.

 

docker build -t migraphx .

 

3. 도커 실행

 

# 공식 깃에서 제공하는 docker 코드
docker run --device='/dev/kfd' --device='/dev/dri' -v=`pwd`:/code/AMDMIGraphX -w /code/AMDMIGraphX --group-add video -it migraphx

# 필자가 사용한 코드
sudo docker run --device='/dev/kfd' --device='/dev/dri' -v=`pwd`:/code/AMDMIGraphX -w /code/AMDMIGraphX --group-add video -it --shm-size 8G --network=host --ipc=host migraphx

 

4. 도커로 실행한 container 안 /code/AMDMIGraphX 폴더에서 source build

 

4-1. half 설치 후 build

 

apt install half

 

build (오래걸림)

 

rbuild build -d depend --cxx=/opt/rocm/llvm/bin/clang++

 

4-2. AMDMIGraphX/build 폴더에서 deb package 만들기

(migraphx package import 연결)

 

make package

 

이후 만들어진 .deb 파일을 입력

 

# 버전확인!
dpkg -i migraphx_2.5.0-_amd64.deb

 

설치 끝

 

5. AMDMIGraphX 폴더 내, examples/vision/resnet50 테스트 해보기

 

5-1 pytorch jupyterlab opencv matplotlib 설치

 

# pip 버전 업그레이드
pip install --upgrade pip

# ROCm 용 pytorch 설치
!pip3 install --pre torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/nightly/rocm5.3

# 나머지 패키지 설치
!pip install jupyterlab opencv-python matplotlib

 

5-2. libSM.so.6: cannot open shared object file~ 에러 발생 시

 

!apt install && apt install -y libsm6 libxext6
!apt-get install -y libxrender-dev

 

5-3. 이후 ipynb 에 따라 실행

중간에 모델 구조를 프린트를 살펴보면

 

 

resnet의 input layer 이름은 data 인 것을 확인할 수 있다.

이후 inference 부분을 보면

'data' 부분 맞춰준 것을 확인할 수 있다.

즉, 다른 모델을 사용할 때는 'data' 부분을 해당 모델의 input layer 이름과 맞춰줘야 한다.

 

 

Docker image build 와 MIGraphX source build 를 해야하므로 상당히 시간이 오래 걸린다.

따라서 image를 꼭 commit 하는게 좋을듯 하다.