본문 바로가기
서버/리눅스 서버

우분투 Tensorflow 환경 구축 (+GPU +Jupyter +GTX1050TI)

by ㅋㅋ잠자 2018. 11. 20.
반응형

안녕하세요. 아래의 글에 이어서 우분투 환경에 구축해 보도록 하겠습니다.


우분투 설치 과정이 많이 바뀌었네요.


https://blog.djjproject.com/486 - 윈도우 환경에서 설치과정기


노래를 트시고 노래가 끝나기 전까지 읽어보시면 될것 같습니다.


감사합니다.






1. 우분투 설치과정


실제로 데비안 같은 설치 UI 였습니다.



본래 상기와 같은 UI 였으나 아래처럼 간단하게 바뀌었네요. 설치도 매우 빠릅니다.



설치 과정중에 언어를 묻는 창에서는 꼭 English 로 해주시길 바랍니다. 간단히 잡혀있는 화면 터미널에서 한글 폰트가 지원되지 않음으로 꼭 English 로 설치하시길 바랍니다.


다음으로 인스톨 우분투 옵션을 선택합니다.



다음으로 네트워크 설정을 하는 부분입니다. 랜포트가 2개 있다면 둘 중에 하나 뜰 것입니다. 아래에 DONE 을 체크하고 넘어갑니다.



프록시 설정 부분입니다. 그냥 넘어갑니다.



다음은 패키지 레포 주소를 넣는 부분입니다. 기본적으로 설정값이 들어가 있으니 그냥 넘어가시면 됩니다.



다음은 파일 시스템 설정 부분입니다. 별 다른 설정없이 전체 디스크로 잡으시면 됩니다.


LVM 을 사용하시려면 LVM 을 선택하시길 바랍니다. 수동으로 하셔도 됩니다. 수동으로 하시려면 EFI 부팅일 경우 EFI 파티션도 만들어 주셔야합니다.



하드디스크에 설치를 진행합니다. 결과물을 체크합니다. 그리고 넘어갑니다.



계정정보를 생성합니다. 초기 계정은 하나 꼭 있어야 되네요. 나중에 지우겠습니다.



스냅 우분투를 기반으로 하는 것들을 설치하는 기능이 있습니다. 그냥 아무것도 누르지 않고 밑의 DONE 을 누릅니다.



그리고 설치가 진행됩니다. 아래 스크린샷은 중간에 랜선이 분리되어 나타난 에러입니다만, 사진이 이것 밖에 없어서 그냥 올려둡니다.






2. 기본설정 진행하기


서버 자체에서 명령을 내릴것이 아니기 때문에 SSH 설정을 먼저 진행합니다.


먼저 아래의 과정을 진행해야 합니다.


# 루트 계정 비밀번호 면경 및 SSH 서버 설치

sudo passwd root

su

apt update

apt install openssh-server


# 설정 파일 수정

nano /etc/ssh/sshd_config


#       $OpenBSD: sshd_config,v 1.101 2017/03/14 07:19:07 djm Exp $


# This is the sshd server system-wide configuration file.  See

# sshd_config(5) for more information.


# This sshd was compiled with PATH=/usr/bin:/bin:/usr/sbin:/sbin


# The strategy used for options in the default sshd_config shipped with

# OpenSSH is to specify options with their default value where

# possible, but leave them commented.  Uncommented options override the

# default value.


Port 22

#AddressFamily any

#ListenAddress 0.0.0.0

#ListenAddress ::


PermitRootLogin yes
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

#PubkeyAuthentication yes

# Expect .ssh/authorized_keys2 to be disregarded by default in future.
#AuthorizedKeysFile     .ssh/authorized_keys .ssh/authorized_keys2

# openssh-server 재시작
service ssh restart


Putty 혹은 Xshell 에서 연결을 시도합니다.



아이피는 ifconfig 으로 확인하시길 바랍니다.


root@djjproject:~# ifconfig

enp4s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

        inet 192.168.0.2  netmask 255.255.255.0  broadcast 192.168.0.255

        inet6 fe80::ca5b:76ff:fee8:3bb9  prefixlen 64  scopeid 0x20<link>

        ether c8:5b:76:e8:3b:b9  txqueuelen 1000  (Ethernet)

        RX packets 3418  bytes 2210754 (2.2 MB)

        RX errors 0  dropped 894  overruns 0  frame 0

        TX packets 1268  bytes 122748 (122.7 KB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0


lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536

        inet 127.0.0.1  netmask 255.0.0.0

        inet6 ::1  prefixlen 128  scopeid 0x10<host>

        loop  txqueuelen 1000  (Local Loopback)

        RX packets 212  bytes 17076 (17.0 KB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 212  bytes 17076 (17.0 KB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0


root@djjproject:~# 


Xshell 로 연결한 모습입니다.



시스템 정보 대략적으로 확인하기


root@djjproject:~# apt install htop

Reading package lists... Done

Building dependency tree       

Reading state information... Done

htop is already the newest version (2.1.0-3).

The following package was automatically installed and is no longer required:

  grub-pc-bin

Use 'apt autoremove' to remove it.

0 upgraded, 0 newly installed, 0 to remove and 99 not upgraded.

root@djjproject:~# htop






3. 파이썬 3 설치하기


아래의 명령어로 시도합니다.


# 파이썬 설치를 시도해 봅니다. 안됩니다.

root@djjproject:~# apt install python3 python3-pip

Reading package lists... Done

Building dependency tree       

Reading state information... Done

E: Unable to locate package python3-pip


# 소스 리스트를 수정합니다. universe 에 속해 있음으로 universe 를 추가합니다.

root@djjproject:~# nano /etc/apt/sources.list


deb http://archive.ubuntu.com/ubuntu bionic main universe

deb http://archive.ubuntu.com/ubuntu bionic-security main universe

deb http://archive.ubuntu.com/ubuntu bionic-updates main universe


# 패키지 리스트를 갱신합니다.

root@djjproject:~# apt update

Hit:1 http://archive.ubuntu.com/ubuntu bionic InRelease

Get:2 http://archive.ubuntu.com/ubuntu bionic-security InRelease [83.2 kB]

Get:3 http://archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]

Get:4 http://archive.ubuntu.com/ubuntu bionic/universe amd64 Packages [8,570 kB]

Get:5 http://archive.ubuntu.com/ubuntu bionic/universe Translation-en [4,941 kB]

Get:6 http://archive.ubuntu.com/ubuntu bionic-security/universe amd64 Packages [96.6 kB]

Get:7 http://archive.ubuntu.com/ubuntu bionic-security/universe Translation-en [54.6 kB]

Get:8 http://archive.ubuntu.com/ubuntu bionic-updates/universe amd64 Packages [575 kB]                                

Get:9 http://archive.ubuntu.com/ubuntu bionic-updates/universe Translation-en [155 kB]                                

Fetched 14.6 MB in 8s (1,756 kB/s)                                                                                    

Reading package lists... Done

Building dependency tree       

Reading state information... Done

110 packages can be upgraded. Run 'apt list --upgradable' to see them.



# 파이선3 과 pip 를 설치합니다.

root@djjproject:~# apt install python3 python3-pip

Reading package lists... Done

Building dependency tree       

Reading state information... Done

The following package was automatically installed and is no longer required:

  grub-pc-bin

Use 'apt autoremove' to remove it.

The following additional packages will be installed:

  binutils binutils-common binutils-x86-64-linux-gnu build-essential cpp cpp-7 dh-python dpkg-dev fakeroot g++ g++-7

  gcc gcc-7 gcc-7-base gcc-8-base libalgorithm-diff-perl libalgorithm-diff-xs-perl libalgorithm-merge-perl libasan4

  libatomic1 libbinutils libc-dev-bin libc6-dev libcc1-0 libcilkrts5 libdpkg-perl libexpat1-dev libfakeroot

  libfile-fcntllock-perl libgcc-7-dev libgcc1 libgomp1 libisl19 libitm1 liblsan0 libmpc3 libmpx2 libpython3-dev

  libpython3-stdlib libpython3.6 libpython3.6-dev libpython3.6-minimal libpython3.6-stdlib libquadmath0

  libstdc++-7-dev libstdc++6 libtsan0 libubsan0 linux-libc-dev make manpages-dev python-pip-whl python3-crypto

  python3-dev python3-distutils python3-keyring python3-keyrings.alt python3-lib2to3 python3-minimal

  python3-secretstorage python3-setuptools python3-wheel python3-xdg python3.6 python3.6-dev python3.6-minimal

Suggested packages:

  binutils-doc cpp-doc gcc-7-locales debian-keyring g++-multilib g++-7-multilib gcc-7-doc libstdc++6-7-dbg

  gcc-multilib autoconf automake libtool flex bison gdb gcc-doc gcc-7-multilib libgcc1-dbg libgomp1-dbg libitm1-dbg

  libatomic1-dbg libasan4-dbg liblsan0-dbg libtsan0-dbg libubsan0-dbg libcilkrts5-dbg libmpx2-dbg libquadmath0-dbg

  glibc-doc bzr libstdc++-7-doc make-doc python3-doc python3-tk python3-venv python-crypto-doc gnome-keyring

  libkf5wallet-bin gir1.2-gnomekeyring-1.0 python-secretstorage-doc python-setuptools-doc python3.6-venv

  python3.6-doc binfmt-support

The following NEW packages will be installed:

  binutils binutils-common binutils-x86-64-linux-gnu build-essential cpp cpp-7 dh-python dpkg-dev fakeroot g++ g++-7

  gcc gcc-7 gcc-7-base libalgorithm-diff-perl libalgorithm-diff-xs-perl libalgorithm-merge-perl libasan4 libatomic1

  libbinutils libc-dev-bin libc6-dev libcc1-0 libcilkrts5 libdpkg-perl libexpat1-dev libfakeroot

  libfile-fcntllock-perl libgcc-7-dev libgomp1 libisl19 libitm1 liblsan0 libmpc3 libmpx2 libpython3-dev

  libpython3.6-dev libquadmath0 libstdc++-7-dev libtsan0 libubsan0 linux-libc-dev make manpages-dev python-pip-whl

  python3-crypto python3-dev python3-distutils python3-keyring python3-keyrings.alt python3-lib2to3 python3-pip

  python3-secretstorage python3-setuptools python3-wheel python3-xdg python3.6-dev

The following packages will be upgraded:

  gcc-8-base libgcc1 libpython3-stdlib libpython3.6 libpython3.6-minimal libpython3.6-stdlib libstdc++6 python3

  python3-minimal python3.6 python3.6-minimal

11 upgraded, 57 newly installed, 0 to remove and 99 not upgraded.

Need to get 91.2 MB of archives.

After this operation, 247 MB of additional disk space will be used.

Do you want to continue? [Y/n] 


설치 완료 후 일단 virtualenv 를 설치해 봅니다.


root@djjproject:~# python3 -V

Python 3.6.7


root@djjproject:~# pip3 -V

pip 9.0.1 from /usr/lib/python3/dist-packages (python 3.6)


root@djjproject:~# pip3 install virtualenv

Collecting virtualenv

  Downloading https://files.pythonhosted.org/packages/7c/17/9b7b6cddfd255388b58c61e25b091047f6814183e1d63741c8df8dcd65a2/virtualenv-16.1.0-py2.py3-none-any.whl (1.9MB)

    100% |████████████████████████████████| 1.9MB 880kB/s 

Installing collected packages: virtualenv

Successfully installed virtualenv-16.1.0

root@djjproject:~# 





3. GPU 환경 구동에 필요한 CUDA 설치


1. 그래픽 드라이버 설치하기


리눅스용 드라이버를 받습니다.



다음으로 파일의 링크를 긇어서 다운받고 설치합니다. 410버전 입니다.


# 파일 다운로드 

root@djjproject:~# wget http://us.download.nvidia.com/XFree86/Linux-x86_64/410.78/NVIDIA-Linux-x86_64-410.78.run

--2018-11-19 22:20:04--  http://us.download.nvidia.com/XFree86/Linux-x86_64/410.78/NVIDIA-Linux-x86_64-410.78.run

Resolving us.download.nvidia.com (us.download.nvidia.com)... 192.229.232.112, 2606:2800:247:2063:46e:21d:825:102e

Connecting to us.download.nvidia.com (us.download.nvidia.com)|192.229.232.112|:80... connected.

HTTP request sent, awaiting response... 200 OK

Length: 107944209 (103M) [application/octet-stream]

Saving to: ‘NVIDIA-Linux-x86_64-410.78.run’


NVIDIA-Linux-x86_64-410.78.ru 100%[================================================>] 102.94M  11.2MB/s    in 9.4s    


2018-11-19 22:20:13 (10.9 MB/s) - ‘NVIDIA-Linux-x86_64-410.78.run’ saved [107944209/107944209]


# 실행 권한 주기

root@djjproject:~# chmod a+x NVIDIA-Linux-x86_64-410.78.run 


# 실행하기

root@djjproject:~# ./NVIDIA-Linux-x86_64-410.78.run 


실행을 해보니 아래와 같은 에러가 발생하고 있습니다.



모듈을 언로드 해야될것 같네요.


NVIDIA 의 문서를 참고하면 아래와 같이 실행하면 됩니다.


https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#ixzz4rQODN0jy


일단은 인스톨러에 비활성화 기능이 있어서 비활성화 후 재부팅 한 후에 다시 시도해 봅니다. 안되면 가이드를 따라 해야겠습니다.




상기처럼 하고 인스톨러가 에러 로그를 남기고 끝납니다. 이러한 상태에서 재부팅하고 나서 재설치를 시도해 보겠습니다. 동일한 현상입니다. 



가이드를 참고하여 아래의 방법을 진행합니다.


# 새 파일 생성 및 내용 추가

root@djjproject:~# nano /etc/modprobe.d/blacklist-nouveau.conf


blacklist nouveau

options nouveau modeset=0


# 커널에 수정값 반영

root@djjproject:~# update-initramfs -u

update-initramfs: Generating /boot/initrd.img-4.15.0-39-generic


# 재부팅

root@djjproject:~# reboot


다시 설치를 진행해 봅니다.


root@djjproject:~# ./NVIDIA-Linux-x86_64-410.78.run 

Verifying archive integrity... OK

Uncompressing NVIDIA Accelerated Graphics Driver for Linux-x86_64 410.78............................................................................................................................................................................................................................................................................................................................................................................................................................................................


진행이 잘 되네요.



설치 중간에 라이브러리 경로가 다르다는 문제가 뜹니다. 문제가 발생하면 pkg-config 패키지를 설치하고 다시 드라이버를 설치하라고 뜨네요. 일단 문제가 생기면 그렇게 해보겠습니다.



한편 32비트 시스템이 아니라서 32비트용은 설치안해줄께 라고도 합니다.


그리고 설치가 완료 되었습니다.



드라이버를 설치한 후 쿠다 버전은 10으로 나오고 있습니다.


root@djjproject:~# nvidia-smi

Mon Nov 19 22:41:09 2018       

+-----------------------------------------------------------------------------+

| NVIDIA-SMI 410.78       Driver Version: 410.78       CUDA Version: 10.0     |

|-------------------------------+----------------------+----------------------+

| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |

| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |

|===============================+======================+======================|

|   0  GeForce GTX 105...  Off  | 00000000:01:00.0 Off |                  N/A |

| N/A   38C    P0    N/A /  N/A |      0MiB /  4042MiB |      1%      Default |

+-------------------------------+----------------------+----------------------+

                                                                               

+-----------------------------------------------------------------------------+

| Processes:                                                       GPU Memory |

|  GPU       PID   Type   Process name                             Usage      |

|=============================================================================|

|  No running processes found                                                 |

+-----------------------------------------------------------------------------+


root@djjproject:~# nvidia-smi -L

GPU 0: GeForce GTX 1050 Ti (UUID: GPU-b52ee1ea-c91f-0903-08f3-120e08fe64f8)


2. CUDA 9.0 설치하기


텐서플로 홈페이지를 참고하면 레포지토리 주소 등록을 통해 쉽게 설치가 가능하다고 되어 있습니다. 그럼 그렇게 설치를 진행해 보겠습니다.


https://www.tensorflow.org/install/gpu


참고로 이렇게 apt 를 통해 설치할 경우 디버깅이 어려울 수 있습니다. 패키지를 말끔히 지우시려면 설치했던 명령어를 그대로 하여 apt-get autoremove --purge 를 해주시면 될것 같습니다.


한편으로 패키지별 deb 파일이 rm 스크립트가 제대로 되어 있지 않은 경우가 많음으로 완벽 삭제가 어려울 수 있습니다.


# 키 추가 하기

root@djjproject:~# apt-key adv --fetch-keys http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/7fa2af80.pub

Executing: /tmp/apt-key-gpghome.tQjisexlA9/gpg.1.sh --fetch-keys http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/7fa2af80.pub

gpg: requesting key from 'http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/7fa2af80.pub'

gpg: key F60F4B3D7FA2AF80: public key "cudatools <cudatools@nvidia.com>" imported

gpg: Total number processed: 1

gpg:               imported: 1


# 레포 주소 추가해주는 deb 파일 받고 설치하기

root@djjproject:~# wget http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/cuda-repo-ubuntu1604_9.1.85-1_amd64.deb

--2018-11-19 22:32:40--  http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/cuda-repo-ubuntu1604_9.1.85-1_amd64.deb

Resolving developer.download.nvidia.com (developer.download.nvidia.com)... 192.229.232.112, 2606:2800:247:2063:46e:21d:825:102e

Connecting to developer.download.nvidia.com (developer.download.nvidia.com)|192.229.232.112|:80... connected.

HTTP request sent, awaiting response... 200 OK

Length: 2820 (2.8K) [application/x-deb]

Saving to: ‘cuda-repo-ubuntu1604_9.1.85-1_amd64.deb’


cuda-repo-ubuntu1604_9.1.85-1 100%[================================================>]   2.75K  --.-KB/s    in 0s      


2018-11-19 22:32:40 (84.7 MB/s) - ‘cuda-repo-ubuntu1604_9.1.85-1_amd64.deb’ saved [2820/2820]


# dpkg 로 해도 될것 같으나 가이드에 이렇게 나와 있습니다.

root@djjproject:~# apt install ./cuda-repo-ubuntu1604_9.1.85-1_amd64.deb

Reading package lists... Done

Building dependency tree       

Reading state information... Done

Note, selecting 'cuda-repo-ubuntu1604' instead of './cuda-repo-ubuntu1604_9.1.85-1_amd64.deb'

The following package was automatically installed and is no longer required:

  grub-pc-bin

Use 'apt autoremove' to remove it.

The following NEW packages will be installed:

  cuda-repo-ubuntu1604

0 upgraded, 1 newly installed, 0 to remove and 99 not upgraded.

Need to get 0 B/2,820 B of archives.

After this operation, 37.9 kB of additional disk space will be used.

Get:1 /root/cuda-repo-ubuntu1604_9.1.85-1_amd64.deb cuda-repo-ubuntu1604 amd64 9.1.85-1 [2,820 B]

Selecting previously unselected package cuda-repo-ubuntu1604.

(Reading database ... 109027 files and directories currently installed.)

Preparing to unpack .../cuda-repo-ubuntu1604_9.1.85-1_amd64.deb ...

Unpacking cuda-repo-ubuntu1604 (9.1.85-1) ...

Setting up cuda-repo-ubuntu1604 (9.1.85-1) ...

N: Download is performed unsandboxed as root as file '/root/cuda-repo-ubuntu1604_9.1.85-1_amd64.deb' couldn't be accessed by user '_apt'. - pkgAcquire::Run (13: Permission denied)

# ?????



# 다른 repo 를 추가하는 패키지를 받고 설치합니다.

root@djjproject:~# wget http://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1604/x86_64/nvidia-machine-learning-repo-ubuntu1604_1.0.0-1_amd64.deb

--2018-11-19 22:32:59--  http://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1604/x86_64/nvidia-machine-learning-repo-ubuntu1604_1.0.0-1_amd64.deb

Resolving developer.download.nvidia.com (developer.download.nvidia.com)... 192.229.232.112, 2606:2800:247:2063:46e:21d:825:102e

Connecting to developer.download.nvidia.com (developer.download.nvidia.com)|192.229.232.112|:80... connected.

HTTP request sent, awaiting response... 200 OK

Length: 2816 (2.8K) [application/x-deb]

Saving to: ‘nvidia-machine-learning-repo-ubuntu1604_1.0.0-1_amd64.deb’


nvidia-machine-learning-repo- 100%[================================================>]   2.75K  --.-KB/s    in 0s      


2018-11-19 22:32:59 (168 MB/s) - ‘nvidia-machine-learning-repo-ubuntu1604_1.0.0-1_amd64.deb’ saved [2816/2816]



# 설치해 줍니다.

root@djjproject:~# apt install ./nvidia-machine-learning-repo-ubuntu1604_1.0.0-1_amd64.deb

Reading package lists... Done

Building dependency tree       

Reading state information... Done

Note, selecting 'nvidia-machine-learning-repo-ubuntu1604' instead of './nvidia-machine-learning-repo-ubuntu1604_1.0.0-1_amd64.deb'

The following package was automatically installed and is no longer required:

  grub-pc-bin

Use 'sudo apt autoremove' to remove it.

The following NEW packages will be installed:

  nvidia-machine-learning-repo-ubuntu1604

0 upgraded, 1 newly installed, 0 to remove and 99 not upgraded.

Need to get 0 B/2,816 B of archives.

After this operation, 37.9 kB of additional disk space will be used.

Get:1 /root/nvidia-machine-learning-repo-ubuntu1604_1.0.0-1_amd64.deb nvidia-machine-learning-repo-ubuntu1604 amd64 1.0.0-1 [2,816 B]

Selecting previously unselected package nvidia-machine-learning-repo-ubuntu1604.

(Reading database ... 109030 files and directories currently installed.)

Preparing to unpack .../nvidia-machine-learning-repo-ubuntu1604_1.0.0-1_amd64.deb ...

Unpacking nvidia-machine-learning-repo-ubuntu1604 (1.0.0-1) ...

Setting up nvidia-machine-learning-repo-ubuntu1604 (1.0.0-1) ...

Warning: The postinst maintainerscript of the package nvidia-machine-learning-repo-ubuntu1604

Warning: seems to use apt-key (provided by apt) without depending on gnupg or gnupg2.

Warning: This will BREAK in the future and should be fixed by the package maintainer(s).

Note: Check first if apt-key functionality is needed at all - it probably isn't!

Warning: apt-key should not be used in scripts (called from postinst maintainerscript of the package nvidia-machine-learning-repo-ubuntu1604)

OK

N: Download is performed unsandboxed as root as file '/root/nvidia-machine-learning-repo-ubuntu1604_1.0.0-1_amd64.deb' couldn't be accessed by user '_apt'. - pkgAcquire::Run (13: Permission denied)


# 리스트 갱신해 줍니다.

root@djjproject:~# apt update

Ign:1 http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64  InRelease

Ign:2 http://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1604/x86_64  InRelease

Get:3 http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64  Release [564 B]

Get:4 http://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1604/x86_64  Release [564 B]

Get:5 http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64  Release.gpg [801 B]

Get:6 http://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1604/x86_64  Release.gpg [801 B]

Hit:7 http://archive.ubuntu.com/ubuntu bionic InRelease                             

Get:8 http://archive.ubuntu.com/ubuntu bionic-security InRelease [83.2 kB]

Get:9 http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64  Packages [158 kB]

Get:10 http://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1604/x86_64  Packages [34.6 kB]

Get:11 http://archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]                                            

Fetched 367 kB in 3s (145 kB/s)     

Reading package lists... Done

Building dependency tree       

Reading state information... Done

100 packages can be upgraded. Run 'apt list --upgradable' to see them.

root@djjproject:~#


혹시나 나는 18.04 인데 16.04 용으로 받는 것이 문제가 될 수 있습니다만, 제가 REPO 주소를 참고해본 결과 범용으로 쓰는 것이라 크게 문제가 없을 것으로 추정하고 있습니다.


CUDA : deb http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64 /

MACHINE LEARNING : deb http://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1604/x86_64 /

상기의 주소를 보시면 크게 버전에 따라 나뉘어 있지 않습니다.

아래의 패키지들을 설치합니다.

root@djjproject:~# apt install cuda9.0 cuda-cublas-9-0 cuda-cufft-9-0 cuda-curand-9-0 cuda-cusolver-9-0 cuda-cusparse-9-0 libcudnn7=7.2.1.38-1+cuda9.0 libnccl2=2.2.13-1+cuda9.0 cuda-command-line-tools-9-0
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Note, selecting 'nvinfer-runtime-trt-repo-ubuntu1604-5.0.2-ga-cuda9.0' for regex 'cuda9.0'
Note, selecting 'nvinfer-runtime-trt-repo-ubuntu1604-4.0.1-ga-cuda9.0' for regex 'cuda9.0'
Note, selecting 'nvinfer-runtime-trt-repo-ubuntu1604-3.0.4-ga-cuda9.0' for regex 'cuda9.0'
Note, selecting 'nvinfer-runtime-trt-repo-ubuntu1604-5.0.0-rc-cuda9.0' for regex 'cuda9.0'
The following package was automatically installed and is no longer required:
  grub-pc-bin
Use 'apt autoremove' to remove it.
The following additional packages will be installed:
  cuda-core-9-0 cuda-cudart-9-0 cuda-cudart-dev-9-0 cuda-driver-dev-9-0 cuda-license-9-0 cuda-misc-headers-9-0
The following NEW packages will be installed:
  cuda-command-line-tools-9-0 cuda-core-9-0 cuda-cublas-9-0 cuda-cudart-9-0 cuda-cudart-dev-9-0 cuda-cufft-9-0
  cuda-curand-9-0 cuda-cusolver-9-0 cuda-cusparse-9-0 cuda-driver-dev-9-0 cuda-license-9-0 cuda-misc-headers-9-0
  libcudnn7 libnccl2 nvinfer-runtime-trt-repo-ubuntu1604-3.0.4-ga-cuda9.0
  nvinfer-runtime-trt-repo-ubuntu1604-4.0.1-ga-cuda9.0 nvinfer-runtime-trt-repo-ubuntu1604-5.0.0-rc-cuda9.0
  nvinfer-runtime-trt-repo-ubuntu1604-5.0.2-ga-cuda9.0
0 upgraded, 18 newly installed, 0 to remove and 100 not upgraded.
Need to get 701 MB of archives.
After this operation, 1,219 MB of additional disk space will be used.
Do you want to continue? [Y/n] 


텐서플로 설치 가이드에서 설치하는 옵션 패키지도 설치해 줍니다.


root@djjproject:~# apt update

Get:1 file:/var/nvinfer-runtime-trt-repo-3.0.4-ga-cuda9.0  InRelease

Ign:1 file:/var/nvinfer-runtime-trt-repo-3.0.4-ga-cuda9.0  InRelease

Get:2 file:/var/nvinfer-runtime-trt-repo-4.0.1-ga-cuda9.0  InRelease

Ign:2 file:/var/nvinfer-runtime-trt-repo-4.0.1-ga-cuda9.0  InRelease

Get:3 file:/var/nvinfer-runtime-trt-repo-5.0.0-rc-cuda9.0  InRelease

Ign:3 file:/var/nvinfer-runtime-trt-repo-5.0.0-rc-cuda9.0  InRelease

Get:4 file:/var/nvinfer-runtime-trt-repo-5.0.2-ga-cuda9.0  InRelease

Ign:4 file:/var/nvinfer-runtime-trt-repo-5.0.2-ga-cuda9.0  InRelease

Get:5 file:/var/nvinfer-runtime-trt-repo-3.0.4-ga-cuda9.0  Release [574 B]

Get:6 file:/var/nvinfer-runtime-trt-repo-4.0.1-ga-cuda9.0  Release [574 B]                                  

Get:7 file:/var/nvinfer-runtime-trt-repo-5.0.0-rc-cuda9.0  Release [574 B]                          

Get:8 file:/var/nvinfer-runtime-trt-repo-5.0.2-ga-cuda9.0  Release [574 B]                          

Get:5 file:/var/nvinfer-runtime-trt-repo-3.0.4-ga-cuda9.0  Release [574 B]                          

Get:6 file:/var/nvinfer-runtime-trt-repo-4.0.1-ga-cuda9.0  Release [574 B]                          

Get:9 file:/var/nvinfer-runtime-trt-repo-3.0.4-ga-cuda9.0  Release.gpg [801 B]                      

Get:7 file:/var/nvinfer-runtime-trt-repo-5.0.0-rc-cuda9.0  Release [574 B]                                                           

Get:10 file:/var/nvinfer-runtime-trt-repo-4.0.1-ga-cuda9.0  Release.gpg [801 B]                     

Get:8 file:/var/nvinfer-runtime-trt-repo-5.0.2-ga-cuda9.0  Release [574 B]                                                            

Get:11 file:/var/nvinfer-runtime-trt-repo-5.0.0-rc-cuda9.0  Release.gpg [801 B]                     

Get:9 file:/var/nvinfer-runtime-trt-repo-3.0.4-ga-cuda9.0  Release.gpg [801 B]                                                        

Get:12 file:/var/nvinfer-runtime-trt-repo-5.0.2-ga-cuda9.0  Release.gpg [801 B]                         

Get:10 file:/var/nvinfer-runtime-trt-repo-4.0.1-ga-cuda9.0  Release.gpg [801 B]                                                           

Get:11 file:/var/nvinfer-runtime-trt-repo-5.0.0-rc-cuda9.0  Release.gpg [801 B]                          

Get:12 file:/var/nvinfer-runtime-trt-repo-5.0.2-ga-cuda9.0  Release.gpg [801 B]                          

Ign:13 http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64  InRelease                                             

Get:14 file:/var/nvinfer-runtime-trt-repo-3.0.4-ga-cuda9.0  Packages [744 B]                           

Ign:15 http://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1604/x86_64  InRelease                           

Hit:16 http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64  Release              

Get:17 file:/var/nvinfer-runtime-trt-repo-4.0.1-ga-cuda9.0  Packages [741 B]                           

Hit:18 http://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1604/x86_64  Release                             

Get:19 file:/var/nvinfer-runtime-trt-repo-5.0.0-rc-cuda9.0  Packages [761 B]                           

Get:20 file:/var/nvinfer-runtime-trt-repo-5.0.2-ga-cuda9.0  Packages [763 B]   

Hit:21 http://archive.ubuntu.com/ubuntu bionic InRelease                    

Get:24 http://archive.ubuntu.com/ubuntu bionic-security InRelease [83.2 kB]

Get:25 http://archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]

Fetched 172 kB in 2s (78.2 kB/s)    

Reading package lists... Done

Building dependency tree       

Reading state information... Done

102 packages can be upgraded. Run 'apt list --upgradable' to see them.


root@djjproject:~# apt install libnvinfer4=4.1.2-1+cuda9.0

Reading package lists... Done

Building dependency tree       

Reading state information... Done

The following package was automatically installed and is no longer required:

  grub-pc-bin

Use 'apt autoremove' to remove it.

The following NEW packages will be installed:

  libnvinfer4

0 upgraded, 1 newly installed, 0 to remove and 102 not upgraded.

Need to get 0 B/36.1 MB of archives.

After this operation, 104 MB of additional disk space will be used.

Get:1 file:/var/nvinfer-runtime-trt-repo-4.0.1-ga-cuda9.0  libnvinfer4 4.1.2-1+cuda9.0 [36.1 MB]

Selecting previously unselected package libnvinfer4.

(Reading database ... 110349 files and directories currently installed.)

Preparing to unpack .../libnvinfer4_4.1.2-1+cuda9.0_amd64.deb ...

Unpacking libnvinfer4 (4.1.2-1+cuda9.0) ...

Setting up libnvinfer4 (4.1.2-1+cuda9.0) ...

Processing triggers for libc-bin (2.27-3ubuntu1) ...

root@djjproject:~# 


3. cudaDNN 7.4.1 for CUDA9.0 설치하기


이까지 설치 하였는데 얼만큼 설치가 된 것인지 모르겠습니다.


cuDNN 64.7 라이브러리가 설치되어 있어야 하나 찾아보니 없어서 설치를 해줘야하는 것 같습니다.


root@djjproject:~# find / -name cuDNN

root@djjproject:~#


일단은 deb 파일 말고 Linux 용을 받아보겠습니다.


회원 전용이라 아래와 같이 URL 을 직접 찍으면 다운로드가 되지 않습니다 ㅎㅎ..


root@djjproject:~# wget https://developer.nvidia.com/compute/machine-learning/cudnn/secure/v7.4.1.5/prod/9.0_20181108/cudnn-9.0-linux-x64-v7.4.1.5.tgz

--2018-11-19 22:49:11--  https://developer.nvidia.com/compute/machine-learning/cudnn/secure/v7.4.1.5/prod/9.0_20181108/cudnn-9.0-linux-x64-v7.4.1.5.tgz

Resolving developer.nvidia.com (developer.nvidia.com)... 192.229.189.146

Connecting to developer.nvidia.com (developer.nvidia.com)|192.229.189.146|:443... connected.

HTTP request sent, awaiting response... 403 Forbidden

2018-11-19 22:49:12 ERROR 403: Forbidden.


root@djjproject:~# 


받아서 옮겨주겠습니다.


root@djjproject:~# apt-get install lrzsz

Reading package lists... Done

Building dependency tree       

Reading state information... Done

The following package was automatically installed and is no longer required:

  grub-pc-bin

Use 'apt autoremove' to remove it.

Suggested packages:

  minicom

The following NEW packages will be installed:

  lrzsz

0 upgraded, 1 newly installed, 0 to remove and 102 not upgraded.

Need to get 74.8 kB of archives.

After this operation, 531 kB of additional disk space will be used.

Get:1 http://archive.ubuntu.com/ubuntu bionic/universe amd64 lrzsz amd64 0.12.21-8build1 [74.8 kB]

Fetched 74.8 kB in 1s (58.6 kB/s)

Selecting previously unselected package lrzsz.

(Reading database ... 110363 files and directories currently installed.)

Preparing to unpack .../lrzsz_0.12.21-8build1_amd64.deb ...

Unpacking lrzsz (0.12.21-8build1) ...

Setting up lrzsz (0.12.21-8build1) ...

Processing triggers for man-db (2.8.3-2) ...

root@djjproject:~#


lrzsz 패키지를 통해 ssh 상으로 파일 전송이 가능합니다.



압축을 풀고 확인해 봅니다.


# 윈도우에서 받으니 확장자가 이상하게 되네요.

root@djjproject:~# ls

]                                        cudnn-9.0-linux-x64-v7.4.1.5.solitairetheme8  nvidia-machine-learning-repo-ubuntu1604_1.0.0-1_amd64.deb

cuda-repo-ubuntu1604_9.1.85-1_amd64.deb  NVIDIA-Linux-x86_64-410.78.run


# 이름을 살짝 바꿔주고 압축 풀어줍니다.

root@djjproject:~# mv cudnn-9.0-linux-x64-v7.4.1.5.solitairetheme8 cudnn-9.0-linux-x64-v7.4.1.5.tar.gz

root@djjproject:~# tar xf cudnn-9.0-linux-x64-v7.4.1.5.tar.gz 


root@djjproject:~/cuda# ls

include  lib64  NVIDIA_SLA_cuDNN_Support.txt

root@djjproject:~/cuda# cd lib64/

root@djjproject:~/cuda/lib64# ls

libcudnn.so  libcudnn.so.7  libcudnn.so.7.4.1  libcudnn_static.a

root@djjproject:~/cuda/lib64#


상기 라이브러리들을 라이브러리로 등록되어 있는 폴더에 넣거나 혹은 LD_LIBRARY_PATH 에 추가해 주면 될것 같습니다.


일단 정확한 파일명을 알았으니 검색을 통해 이미 설치가 되어 있는지 알아보겠습니다.


root@djjproject:~/cuda/lib64# find / -name libcudnn.so.7

/root/cuda/lib64/libcudnn.so.7

/usr/lib/x86_64-linux-gnu/libcudnn.so.7


root@djjproject:~/cuda/lib64# 


이미 2번 순서에서 설치가 일부 된것 같으나 모든 파일이 들어 있지는 않습니다. 적절하게 넣어주겠습니다.


# 헤더파일 위치 배치

root@djjproject:~/cuda# cd include/

root@djjproject:~/cuda/include# ls

cudnn.h

root@djjproject:~/cuda/include# cp cudnn.h /usr/include/


# 모듈 파일 위치 배치

root@djjproject:~/cuda/include# cd ..

root@djjproject:~/cuda# cd lib64/

root@djjproject:~/cuda/lib64# ls

libcudnn.so  libcudnn.so.7  libcudnn.so.7.4.1  libcudnn_static.a

root@djjproject:~/cuda/lib64# cp * /usr/lib/x86_64-linux-gnu/


라이브러리 갱신을 위해서 ldconfig 을 실행해 줍니다.


다음으로 재부팅을 한번 해 줍니다.





3. Tensorflow GPU 및 jupyter-notebook 설치


홈폴더로 이동하여 가상환경을 하나 만들어 주고 필요한 패키지를 설치합니다.


# 적절한 경로로 이동

root@djjproject:~# cd /home/


# 가상환경 생성

root@djjproject:/home# virtualenv --system-site-packages -p python3 tensorflow-gpu

Already using interpreter /usr/bin/python3

Using base prefix '/usr'

New python executable in /home/tensorflow-gpu/bin/python3

Also creating executable in /home/tensorflow-gpu/bin/python

Installing setuptools, pip, wheel...

done.


# 가상환경으로 진입

root@djjproject:/home# source tensorflow-gpu/bin/activate


# 앞에 ( .... ) 가 생겼는지 확인 후 pip 로 원하는 패키지 설치

(tensorflow-gpu) root@djjproject:/home# pip install tensorflow-gpu jupyter matplotlib pandas

Collecting tensorflow-gpu

  Downloading https://files.pythonhosted.org/packages/55/7e/bec4d62e9dc95e828922c6cec38acd9461af8abe749f7c9def25ec4b2fdb/tensorflow_gpu-1.12.0-cp36-cp36m-manylinux1_x86_64.whl (281.7MB)

    4% |█▍                              | 12.1MB 12.2MB/s eta 0:00:23


현재 우분투를 구동하고 있는 게이밍 노트북이 X 윈도우를 활성화 하지 않고 사용함으로 주피터 노트북 실행옵션은 --no-browser 옵션으로 가야합니다. 그리고 아이피를 찍어주셔야합니다.


# 기본 설정파일을 생성합니다.

(tensorflow-gpu) root@djjproject:/home# jupyter notebook --generate-config

Writing default config to: /root/.jupyter/jupyter_notebook_config.py


# 기본 기능을 통해 비밀번호를 생성합니다.

(tensorflow-gpu) root@djjproject:/home# jupyter notebook password

Enter password: 

Verify password: 

[NotebookPasswordApp] Wrote hashed password to /root/.jupyter/jupyter_notebook_config.json


# 일단 서버 모드로 시작합니다.

(tensorflow-gpu) root@djjproject:/home# jupyter notebook --no-browser --ip=0.0.0.0

[I 08:07:00.133 NotebookApp] Writing notebook server cookie secret to /run/user/0/jupyter/notebook_cookie_secret

[C 08:07:01.838 NotebookApp] Running as root is not recommended. Use --allow-root to bypass.


# 루트 계정에서 실행할 수 있게 옵션을 줍니다.

(tensorflow-gpu) root@djjproject:/home# jupyter notebook --no-browser --ip=0.0.0.0 --allow-root

[I 08:07:06.983 NotebookApp] Serving notebooks from local directory: /home

[I 08:07:06.983 NotebookApp] The Jupyter Notebook is running at:

[I 08:07:06.983 NotebookApp] http://(djjproject or 127.0.0.1):8888/

[I 08:07:06.983 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).


기본 샘플 파일을 받기 위해서 git clone 을 수행합니다.


# 적절한 폴더 생성합니다.

(tensorflow-gpu) root@djjproject:/home# mkdir board

(tensorflow-gpu) root@djjproject:/home# cd board/


# 해당 폴더에서 git clone 합니다.

(tensorflow-gpu) root@djjproject:/home/board# git clone https://github.com/Jpub/TensorflowDeeplearning.git

Cloning into 'TensorflowDeeplearning'...

remote: Enumerating objects: 1, done.

remote: Counting objects: 100% (1/1), done.

remote: Total 68 (delta 0), reused 0 (delta 0), pack-reused 67

Unpacking objects: 100% (68/68), done.

(tensorflow-gpu) root@djjproject:/home/board#


(tensorflow-gpu) root@djjproject:/home/board# jupyter notebook --no-browser --ip=0.0.0.0 --allow-root --port=8080

[I 08:10:15.724 NotebookApp] Serving notebooks from local directory: /home/board

[I 08:10:15.724 NotebookApp] The Jupyter Notebook is running at:

[I 08:10:15.724 NotebookApp] http://(djjproject or 127.0.0.1):8080/

[I 08:10:15.724 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).

[I 08:10:19.527 NotebookApp] 302 GET / (192.168.0.149) 1.35ms

[I 08:10:19.533 NotebookApp] 302 GET /tree? (192.168.0.149) 0.46ms

[I 08:10:21.938 NotebookApp] 302 POST /login?next=%2Ftree%3F (192.168.0.149) 2.20ms


들어가 보면 아래와 같이 뜹니다.






4. 샘플 코드 돌려보기


몇가지 샘플 코드를 돌려 보겠습니다.


잘 작동합니다.








5. 주피터 노트북 터미널 기능


제가 몰랐는데 주피터 노트북에 터미널 기능이 있습니다.


보안을 제대로 갖추고 사용하면 정말 좋을것 같습니다.






아.. 이걸 군대가기 전에 알았더라면.. 


그리고 주피터 랩? 이라는 패키지도 있는데 웹 기반으로 개발환경을 구축할 수 있는 느낌이 나고 있습니다.


https://github.com/jupyterlab/jupyterlab








반응형

댓글