> For the complete documentation index, see [llms.txt](https://robertchoi.gitbook.io/jetson-tx2/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://robertchoi.gitbook.io/jetson-tx2/3.md).

# 3장 동작모드

### 동작 모드에대한 고찰 <a href="#undefined" id="undefined"></a>

#### nvpmodel 명령어 <a href="#nvpmodel" id="nvpmodel"></a>

Jetpack을 설치해서 동작하면 기본 Default mode는 `Mode ID=2`로 15W로 동작하게 된다.\
아래는 주요 명령어들이다.

* `sudo nvpmodel -q (for current mode)` 자세히 보고 싶으면 `--verbose` option 추가
* `sudo nvpmodel -m 0 (for changing mode, persists after reboot)`
* `sudo ~/tegrastats (for monitoring clocks & core utilization)`

각각의 모드들에 대한 소비전력과 성능은 아래의 표와 같다.<br>

![](https://i.imgur.com/QHLToo9.png)

모드를 적용 시키기 위해선 재부팅을 해야한다.

#### jetson\_clocks.sh <a href="#jetson_clocks-sh" id="jetson_clocks-sh"></a>

`jetson_clocks.sh` 스크립트를 통해서 현재의 `nvpmodel mode`에서의 최고의 성능을 달성 할 수 있다. DVFS로 동작하는것을 방지하기 때문이다.

아래와 같이 세가지 동작 옵션을 내장하고 있다.

```
Maximize jetson performance by setting static max frequency to CPU, GPU and EMC clocks.
Usage:
jetson_clocks.sh [options]
  options,
  --show             display current settings
  --store [file]     store current settings to a file (default: ${HOME}/l4t_dfs.conf)
  --restore [file]   restore saved settings from a file (default: ${HOME}/l4t_dfs.conf)
  run jetson_clocks.sh without any option to set static max frequency to CPU, GPU and EMC clocks.
```

`--show`를 통해서 현재 상태를 알 수 있다.

```
nvidia@jetson-0423718017159:~$ sudo ./jetson_clocks.sh --show
SOC family:tegra194  Machine:jetson-xavier
Online CPUs: 0-7
CPU Cluster Switching: Disabled
cpu0: Gonvernor=schedutil MinFreq=1190400 MaxFreq=2265600 CurrentFreq=1190400
cpu1: Gonvernor=schedutil MinFreq=1190400 MaxFreq=2265600 CurrentFreq=2112000
cpu2: Gonvernor=schedutil MinFreq=1190400 MaxFreq=2265600 CurrentFreq=1344000
cpu3: Gonvernor=schedutil MinFreq=1190400 MaxFreq=2265600 CurrentFreq=1651200
cpu4: Gonvernor=schedutil MinFreq=1190400 MaxFreq=2265600 CurrentFreq=1728000
cpu5: Gonvernor=schedutil MinFreq=1190400 MaxFreq=2265600 CurrentFreq=2035200
cpu6: Gonvernor=schedutil MinFreq=1190400 MaxFreq=2265600 CurrentFreq=2035200
cpu7: Gonvernor=schedutil MinFreq=1190400 MaxFreq=2265600 CurrentFreq=1420800
GPU MinFreq=318750000 MaxFreq=1377000000 CurrentFreq=318750000
EMC MinFreq=204000000 MaxFreq=2133000000 CurrentFreq=2133000000 FreqOverride=0
Fan: speed=0
```

`nvpmodel`과 다르게 이건 `reboot`하면 유지되지 않는다.

#### 최고 성능으로 동작 시키기 <a href="#undefined" id="undefined"></a>

```
$ sudo nvpmodel -m 0
$ sudo ${HOME}/jetson_clocks.sh
```

### Installing TensorFlow on Xavier <a href="#installing-tensorflow-on-xavier" id="installing-tensorflow-on-xavier"></a>

설치가능한 framework들은 아래와 같다.\
<https://developer.qa.nvidia.com/deep-learning-frameworks>

**공식적인 설치 절차**\
<https://docs.nvidia.com/deeplearning/dgx/install-tf-xavier/index.html>

python 3.6으로 설치했다.

#### 사전 설치 단계 <a href="#undefined" id="undefined"></a>

* Install JetPack 4.1.1 Developer Preview
* Install HDF5
  * `apt-get install libhdf5-serial-dev hdf5-tools`
* Install pip3 (python3.6)
* Install the following packages:

  ```
  pip3 install --upgrade pip
  sudo apt-get install zlib1g-dev zip libjpeg8-dev libhdf5-dev
  sudo pip3 install -U numpy grpcio absl-py py-cpuinfo psutil portpicker grpcio six mock requests gast h5py astor termcolor
  ```

  pip3로 패키지 설치시 생각보다 엄청 오래걸리므로 절대로 `Ctrl+C`하지말고 기다리면 언젠간 설치된다.

```
Collecting numpy
  Downloading https://files.pythonhosted.org/packages/2d/80/1809de155bad674b494248bcfca0e49eb4c5d8bee58f26fe7a0dd45029e2/numpy-1.15.4.zip (4.5MB)
    100% |████████████████████████████████| 4.5MB 119kB/s
..
..
Collecting idna<2.9,>=2.5 (from requests)
  Downloading https://files.pythonhosted.org/packages/14/2c/cd551d81dbe15200be1cf41cd03869a46fe7226e7450af7a6545bfc474c9/idna-2.8-py2.py3-none-any.whl (58kB)
    100% |████████████████████████████████| 61kB 3.4MB/s
Installing collected packages: numpy, six, grpcio, absl-py, py-cpuinfo, psutil, portpicker, pbr, mock, urllib3, certifi, idna, requests, gast, h5py, astor, termcolor
  Running setup.py install for numpy ... |
```

최종결과

```
Successfully installed absl-py-0.6.1 astor-0.7.1 certifi-2018.11.29 gast-0.2.0 grpcio-1.17.1 h5py-2.9.0 idna-2.8 mock-2.0.0 numpy-1.15.4 pbr-5.1.1 portpicker-1.2.0 psutil-5.4.8 py-cpuinfo-4.0.0 requests-2.21.0 six-1.12.0 termcolor-1.1.0 urllib3-1.24.1
```

#### Tensorflow-gpu 설치 및 확인 <a href="#tensorflow-gpu" id="tensorflow-gpu"></a>

* Installing TensorFlow
  * `pip3 install --extra-index-url https://developer.download.nvidia.com/compute/redist/jp/v411 tensorflow-gpu`\
    미리 nvidia에서 사전에 빌드해둔 것이 `https://developer.download.nvidia.com/compute/redist/jp/v411/tensorflow-gpu/`에 있다. 이것을 다운받아서 설치하는 명령어이다. 현재 가장 최신 stable 버전을 포함한다.

**tensorflow-gpu 설치완료**

```
Successfully built grpcio numpy absl-py termcolor gast h5py
Installing collected packages: wheel, six, grpcio, setuptools, protobuf, werkzeug, markdown, numpy, tensorboard, astor, h5py, keras-applications, absl-py, termcolor, gast, keras-preprocessing, tensorflow-gpu
Successfully installed absl-py-0.6.1 astor-0.7.1 gast-0.2.0 grpcio-1.17.1 h5py-2.9.0 keras-applications-1.0.6 keras-preprocessing-1.0.5 markdown-3.0.1 numpy-1.15.4 protobuf-3.6.1 setuptools-40.6.3 six-1.12.0 tensorboard-1.12.1 tensorflow-gpu-1.12.0+nv18.12 termcolor-1.1.0 werkzeug-0.14.1 wheel-0.32.3
```

**설치 확인**\
아래와 같이 나오면 설치가 완료

```
Python 3.6.7 (default, Oct 22 2018, 11:32:17)
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
>>> import tensorflow as tf
>>> tf.__version__
'1.12.0'
```

### MNIST데이터를 이용한 CNN 모델 학습 시간 분석 <a href="#mnist-cnn" id="mnist-cnn"></a>

[이전 포스트](http://goodtogreate.tistory.com/entry/GPU-TensorFlow-on-Window-10-TensorFlow-GPU%EB%B2%84%EC%A0%84-%EC%9C%88%EB%8F%84%EC%9A%B010-%EC%84%A4%EC%B9%98)에서 여러 GPU들과 비교 했었다. 같은 코드로 `Jetson Xaiver`보드도 대략적으로 테스트 해본다.

사용한 코드는 이전처럼 아래 git에 있다.\
<https://github.com/leejaymin/TensorFlowLecture/tree/master/5.CNN>

`deafult mode = 2`로 실험한 결과 아래와 같다.

```
speed
97 0.9921875
98 0.98828125
99 1.0
time elapsed: 1007.16s
```

최고성능 모드: `mode = 0`, `jetson_clock.sh`

```
97 1.0
98 1.0
99 1.0
time elapsed: 525.10s
```

결론적으로 생각보다 느리다.\
아래와 같은 수준이다. 이론상 performance는 32-TOPS이다. 기존 다른 NVIDIA tegra 계열이나 1080 또는 2080 계열은 이론상 FLOPS로 표기한다.

결국 아래 성능 차이는 아래와 같다.

* `GTX 970` < `Jetson-Xaiver` < `1060` < `1080` < `P100`

#### TOPS와 TFLOPS와의 차이점 <a href="#tops-tflops" id="tops-tflops"></a>

TOPS are Tera operations per second, i.e. 1 trillion operations (integer, float, etc.) each second.

TFLOPS are Tera floating point operations per second, i.e. 1 trillion (usually single precision) floating point operations per second.<br>
