레이블이 SSD인 게시물을 표시합니다. 모든 게시물 표시
레이블이 SSD인 게시물을 표시합니다. 모든 게시물 표시

2022년 2월 27일 일요일

Effective Jetson Xavier NX Setup - SSD Booting

 Let's see how to install JetPack 4.6 on Jetson xavier nx and use it effectively.

Jetson Nano uses SD card. Therefore, multiple SD card images can be prepared and used. For example, an SD card for Tensorflow and an SD card for PyTorch are prepared separately and used while replacing the SD card as needed.

Xavier NX allows additional SSD installation. SSDs are much faster and more stable than SD cards. Therefore, it is better to install various software using an SSD rather than using multiple SD cards.  

Jetson Xavier NX -Run from SSD

To use SSDs with Xavier NX, you need a standalone x86 Ubuntu server.

The documentation says that Ubuntu 18.04 and 16.04 are available, but as a result of my testing, it failed in 18.04. Please prepare one x86 PC with Ubuntu 16.04 installed. If you have used Jetxon TX2 or AGX Xavier, you probably have experience installing and using NVidia SDK Manager on an x86 PC.

However, SDK manager is not used in this work. We will directly transfer the JetPack 4.6 image to Xavier NX using a bash script.

I know that NVidia is working on integrating this SSD bootable method into SDK Manager. Maybe JetPack 4.7 will use the SDK Manager.

And since booting from the SSD drive proceeds, there is no need to use the SD card anymore.

The following content is taken from the JetsonHacks homepage. Thanks to JetsonHacks for the nice introduction.

<JetsonHack's Youube>


SSD Installation

Be sure to prepare an M.2 NVMe type SSD. I prepared a 128GB Samsung SSD, but it would be better if I prepared a larger size SSD. How to install the SSD is detailed in the video above.


Install SW on the Host

Install the software required for the host first. Since JetsonHacks has made the necessary scripts for the job well, I will clone the git he made and use it.


$ git clone https://github.com/jetsonhacks/bootFromExternalStorage.git

$ cd bootFromExternalStorage

$ ./install_dependencies.sh

$ ./get_jetson_files.sh

It may takes several minutes.


Xavier NX Recovery Mode

After installing the SSD, set Xavier NX to Force Recovery mode. To set the Force Recovery Mode, connect pins 9 and 10 among the pins below the SD card slot. In the picture below, a jumper is used, but you can use a breadboard female cable. It is well explained in the video above.

<recovery mode jumper connection from https://www.stereolabs.com/blog/getting-started-with-jetson-xavier-nx/>


USB Connection

Now connect Xavier NX to the x86 host computer.

<USB Connection> 


Bootup the Xavier NX

Connect the power of Xavier NX in force recovery mode. Xavier NX will show a green light. And check the connection status on the host computer as follows. You can check the Xavier NX connected to the USB port with the lsusb command. If it is not confirmed, there is a high possibility that the Force Recovery Mode jumper connection is wrong or the USB cable is bad.


Flashing the Xavier NX

Now run the last script to install the Jetpack 4.6 image to the Xavier NX's SSD.

 ./flash_jetson_external_storage.sh

Running the script will search for connected Xavier NX. And it asks to cancel the Force Recovery mode. You can then remove the jumper cable and continue. 

This work takes about ten minutes. Once this has been done successfully, the host computer is no longer needed.

Then, connect the mouse, keyboard, monitor, and LAN cable to Xavier NX and boot it. Now the last task remains.  This must be done in Xavier NX.

$ git clone https://github.com/jetsonhacks/bootFromExternalStorage.git

$ cd bootFromExternalStorage

./install_jetson_default_packages.sh

     

Wrapping UP

Now reboot Xavier NX and proceed with initial setup. Note that the current Xavier NX does not have an SD card, only an SSD. If the capacity seems to be low due to the unallocated partition on the ssd, install the gparted program to extend the partition.

Now you can use Xavier NX much faster and more reliably than when using an SD card.

I highly recommend reading JetsonHack's blog post as well.

Today we learned how to install an SSD in Xavier NX to get the best hardware performance. In the next article, we will learn how to efficiently use Python, OpenCV, TensorFlow, and PyTorch.






2020년 7월 22일 수요일

Jetson Xavier NX - Python virtual environment and ML platforms(tensorflow, Pytorch) installation

This article is in line with the Jetson Xavier NX-JetPack 4.4 (production release) headless setup described in the previous blog.
So far, I haven't used the Python virtual environment while using the Jetson Nano. The reason is that Jetson Nano only supports SD cards, so it is convenient to prepare several SD cards and install and use the necessary packages. And because JetPack is updated frequently, it was also a big reason to prepare a new image on an SD card from time to time. However, the Xavier NX does offer an M.2 slot for SSD installation. SSDs offer significantly better performance than SD cards or eMMC memory.  Therefore, I will install and use a SSD on the Xavier NX.  When using the Jetson Nano, replacing the SD card was like using a completely new system. However, if you installed the package or saved data using an SSD, it is convenient to continue using the SSD regardless of the SD card replacement.
I will be mainly working on AI edge computing on Xavier NX. And I will use Python 3 as the development language. In the future, most of the data or packages will be installed on SSDs to improve performance and to enable the system to be used without replacing SD cards.

Creating a Python virtual environment

You can install TensorFlow, PyTorch, Yolo, etc. frameworks for use in one virtual environment, or you can create multiple Python virtual environments to install each framework in a separate virtual environment. Just choose the method that suits your Hankyung. Sometimes I feel the need to use TensorFlow and PyTorch together, so I will install multiple machine learning frameworks on a single virtual machine.

spypiggy@XavierNX:~$ sudo apt-get install python3-dev python3-pip
spypiggy@XavierNX:~$ pip3 install  -U virtualenv

The advantage of the Python virtual environment is that all packages installed in the virtual environment are installed in the virtual environment, so if you delete the virtual environment, everything installed in the virtual environment is cleared and does not affect other Python virtual environments.
Make sure to create the Python virtual environment on the SSD installed earlier. Previously, the SSD was mounted at /home/spypiggy. Therefore, create a virtual environment under /home/spypiggy.

Create a Python virtual environment with the following command. When you run this command, the core elements of your current Python 3 are copied to the /home/spypiggy/python directory.

spypiggy@XavierNX:~$ python3 -m virtualenv --system-site-packages /home/spypiggy/python

To enter the virtual environment, use the source command. Notice that the prompt name has been changed.

spypiggy@XavierNX:~$ source /home/spypiggy/python/bin/activate
(python) spypiggy@XavierNX:~$

From now on, all packages installed using the pip3 command are installed under the /home/spypiggy/python directory, and these packages are effective only when working in a virtual environment.


Install machine learning related platforms

Tensorflow

Do not follow the installation method of Tensorflow homepage. NVidia provides TensorFlow optimized for Jetpack version.
You can download the appropriate version for JetPack4.4 from the https://developer.download.nvidia.com/compute/redist/jp/v44/tensorflow/ page.
If the 4.6 version will be released after a while, you can probably search https://developer.download.nvidia.com/compute/redist/jp/v46/tensorflow/.


The naming convention is as follows.

TensorFlow version + NVIDIA container version of TensorFlow + Python version + CPU.

It is safe to select the latest version with a higher NVIDIA container version of TensorFlow value from the same TensorFlow version.
Select the desired version from TensorFlow 2.X version and 1.X version, and then install it. If you want to use both, you can create a new virtual environment and install it in another virtual environment. I will install tensorflow-1.15.2+nv20.6-cp36-cp36m-linux_aarch64.whl.

(python) spypiggy@XavierNX:~$ sudo apt-get install -y libhdf5-serial-dev hdf5-tools libhdf5-dev zlib1g-dev zip libjpeg8-dev
(python) spypiggy@XavierNX:~$ pip3 install numpy grpcio absl-py py-cpuinfo psutil portpicker six mock requests gast h5py astor termcolor protobuf keras-applications keras-preprocessing wrapt google-pasta(python) spypiggy@XavierNX:~$ wget https://developer.download.nvidia.com/compute/redist/jp/v44/tensorflow/tensorflow-1.15.2+nv20.6-cp36-cp36m-linux_aarch64.whl
(python) spypiggy@XavierNX:~$ wget https://developer.download.nvidia.com/compute/redist/jp/v44/tensorflow/tensorflow-1.15.2+nv20.6-cp36-cp36m-linux_aarch64.whl
(python) spypiggy@XavierNX:~$ pip3 install tensorflow-1.15.2+nv20.6-cp36-cp36m-linux_aarch64.whl

After installation, you can check as follows.

(python) spypiggy@XavierNX:~$ python
Python 3.6.9 (default, Apr 18 2020, 01:56:04) 
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
2020-07-22 09:45:49.770178: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcudart.so.10.2
WARNING:tensorflow:Deprecation warnings have been disabled. Set TF_ENABLE_DEPRECATION_WARNINGS=1 to re-enable them.
>>> tf.__version__
'1.15.2'


PyTorch

How to install PyTorch 1.6 on Jetson Nano using JetPack 4.4 (DP Version) is explained in this blog. How to install PyTorch on Xavier NX is not much different from the content of this blog.
Like TensorFlow, NVidia provides an installation package optimized for Jetson. Install this package.

We always use Python 3.X. Therefore, download the whl file that can be used in Python 3.6. And install the necessary packages as follows. JetPack 4.3 and later comes with OpenCV 4.1.1 and numpy. So you don't have to install numpy anymore.

(python) spypiggy@XavierNX:~$ sudo apt-get update
(python) spypiggy@XavierNX:~$ wget https://nvidia.box.com/shared/static/yr6sjswn25z7oankw8zy1roow9cy5ur1.whl -O torch-1.6.0-cp36-cp36m-linux_aarch64.whl (python) spypiggy@XavierNX:~$ sudo apt-get install python3-pip libopenblas-base libopenmpi-dev (python) spypiggy@XavierNX:~$ pip3 install Cython (python) spypiggy@XavierNX:~$ pip3 install torch-1.6.0-cp36-cp36m-linux_aarch64.whl

Download Torchvision for Jetson Xavier NX

If you have successfully installed PyTorch 1.6.0, install Torchvision 0.7.0. The latest version of torchvision can be found at https://github.com/pytorch/vision/releases.

(python) spypiggy@XavierNX:~$ sudo apt-get install libjpeg-dev zlib1g-dev
(python) spypiggy@XavierNX:~$ wget https://github.com/pytorch/vision/archive/v0.6.1.tar.gz   
(python) spypiggy@XavierNX:~$ cd v0.7.0
(python) spypiggy@XavierNX:~/v0.7.0$ python3 setup.py install
(python) spypiggy@XavierNX:~/v0.7.0$ sudo apt-get install libfreetype6-dev
(python) spypiggy@XavierNX:~/v0.7.0$ pip3 uninstall pillow
(python) spypiggy@XavierNX:~/v0.7.0$ pip3 install --no-cache-dir pillow

Let's check whether the installation is correct.
If you see the screen like this, the installation is successful.

root@jetpack-4:/usr/local/src/torchvision# python3
Python 3.6.9 (default, Apr 18 2020, 01:56:04)
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> import torchvision
>>> torch.__version__
'1.6.0'
>>> torchvision.__version__
'0.7.0
>>>


Wrapping up

So far, in Xavier NX, I have created a Python virtual environment in SSD storage and installed the machine learning platform Tensorflow and PyTorch. Unlike Jetson Nano, Xavier NX can be equipped with SSD. It is recommended to use SSD actively to improve performance. To install as many Python packages as possible in the SSD repository, I created a Python virtual environment and installed TensorFlow, PyTorch, etc.
I'll run a lot of tests that I've done on Jetson Nano so far on Xavier and post articles comparing performance.
























Jetson Xavier NX - JetPack 4.4(production release) headless setup

First, download SD card image for Xavier NX from https://developer.nvidia.com/embedded/jetpack .
As of July 2020, the latest version is JetPack 4.4. JetPack upgrades to the new version frequently, so always check the latest version on the homepage. Then, use the Etcher tool to create an SD card image. Since this process has a lot of help materials, the explanation is omitted. Etcher supports zip compressed files, so you don't have to decompress it on purpose.

Tips:Xavier NX can be installed with an additional SSD. If you plan to use an SSD together, it is recommended to prepare an SD card with a capacity of 128 GB or more. If you are not using an SSD, you can use an SD card with 32 or 64GB capacity. The reason is that if you use SSD together, you can use a large amount of storage space, so you can install multiple platforms at once. Therefore, it is recommended not to change the SD card with OS as often as possible in order to use the installed system for a long time.
How to use the SD card without replacing it will be explained again later.

Headless Setup

Now insert the SD card into Xavier NX. And before connecting the power, connect the USB cable as shown in the picture. Connect the other end of the USB cable to your PC.
Then connect the Xavier NX's 19V power supply. When Xavier NX boots, the device connected to COM3 is shown in the device manager of the PC as shown in the following figure. The COM port number will change depending on your PC.




You can now connect serially using putty. Connect using the COM port number checked in the PC device manager. System Configurationon putty screen as follows. Now follow the instructions on the screen to set up.
I have explained in a previous blog how to do a headless setup on the Jetson Nano. For more information, please refer to this blog.




Serial connection using putty can be used at any time. Therefore, when a monitor, keyboard, etc. are not ready, serial connection using a USB cable is a useful connection method. Once connected, it provides the same console environment as using ssh.

Boot from SSD

Xavier NX can be only booted using eMMC or SD card. There are articles introducing the SSD booting on the Xavier NX and then booting the SSD using a service script that changes the rootfs.
The typical article is https://www.jetsonhacks.com/2020/05/29/jetson-xavier-nx-run-from-ssd/ introduced by JetsonHacks. However, even in this case, the boot does not start from the SSD. After booting the kernel using the SD card, the rootfs are changed to SSD. Therefore, SD card must be used together. It is not a complete SSD boot.

JetsonHacks' Youtube video explains how to use SSDs with Xavier NX



Personally, I think it's a good idea to wait for NVidia to provide SSD bootable firmware. If they don't offer this, I can't help it.

How to set up an SSD

SD cards are not only less stable and less faster than SSDs, but also have less capacity, so let's find a way to properly utilize SSDs.

I plan to use Xavier NX primarily for edge AI computing. And the programming language will mainly use Python. Probably many people are similar to me.

Since the Jetson Nano can only use SD cards, I have created several SD card images and then installed and used the packages needed for a specific purpose on the SD card. For example, the A SD card is used for PyTorch and the B SD card is used for Tensorflow. However, if you want the SSD to take advantage of the large storage capacity, you may prefer to use the Python virtual environment rather than this method.
After creating a Python virtual environment on an SSD, install most of the necessary Python packages in the virtual environment to utilize the SSD efficiently.

1. Power off the Xavier NX and install NVME SSD at the bottom of Xavier NX M.2 slot.


<image from jetsonhacks>


2.Power on the system and format the SSD drive. In my case there's already 3 partitions. I'll delete all existing partitions.

root@XavierNX:~# mkfs.ext4 /dev/nvme0n1
mke2fs 1.44.1 (24-Mar-2018)
Discarding device blocks: done
Creating filesystem with 31258710 4k blocks and 7815168 inodes
Filesystem UUID: c1726e94-12c1-43bf-bcee-9811970202b8
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000, 7962624, 11239424, 20480000, 23887872

Allocating group tables: done
Writing inode tables: done
Creating journal (131072 blocks): done
Writing superblocks and filesystem accounting information: done


3. Create a mount point for the drive

So far I've been working mostly in the /usr/local/src directory.
However, in Xavier NX, I plan to mainly work in /home/spypiggy. spypiggy is my username in Xavier NX. I will mount /home/spypiggy directory to ssd and use it. So in the future, most of the work on Xavier NX will be done in /home/spypiggy.


#First, copy the existing files on the /home/spypiggy to /dev/nvme0n1
mount /dev/nvme0n1 /mnt
rsync -avhr /home/spypiggy/.* /mnt
rsync -avhr /home/spypiggy/* /mnt
umount /mnt

#Now mount /dev/nvme0n1 to /home/spypiggy/
mount /dev/nvme0n1 /home/spypiggy/
vim /etc/fstab 
/dev/nvme0n1 /home/spypiggy ext4 defaults 0 1
reboot

#reboot and check the /home/spypiggy directory
Filesystem      Size  Used Avail Use% Mounted on
/dev/mmcblk0p1  116G   13G   98G  12% /
none            3.5G     0  3.5G   0% /dev
tmpfs           3.8G  4.0K  3.8G   1% /dev/shm
tmpfs           3.8G   20M  3.8G   1% /run
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
tmpfs           3.8G     0  3.8G   0% /sys/fs/cgroup
/dev/nvme0n1    117G   61M  111G   1% /home/spypiggy
tmpfs           778M  8.0K  778M   1% /run/user/120
tmpfs           778M     0  778M   0% /run/user/0

After rebooting, you can see that the /home/spypiggy directory is mounted on /dev/nvme0n1.

Power mode

After installing JetPack 4.4, install htop.
And if you check the system with htop command, it is as follows.



There are only two CPU Cores visible. Xavier NX clearly states that it has 6 cores...
This table shows the power mode that the Xavier NX supports. Mode ID value is from 0 to 4. Mode IDs 3 and 4 operate in a low power mode of 10W. Mode ID 2 is the most powerful with 15W of power and six cores.



The same console command as this is nvpmodel. You can check the current power model using the nvpmodel command.

spypiggy@XavierNX:~$ sudo nvpmodel -q
NV Fan Mode:quiet
NV Power Mode: MODE_10W_2CORE
3

You can see that it is currently mode3. As you can see from the above table, you can change to mode 3 to get the most out of 6 cores.

spypiggy@XavierNX:~$ sudo nvpmodel -m 2
NVPM WARN: patching tpc_pg_mask: (0x1:0x4)
NVPM WARN: patched tpc_pg_mask: 0x4
spypiggy@XavierNX:~$ sudo nvpmodel -q
NV Fan Mode:quiet
NV Power Mode: MODE_15W_6CORE
2

Now run htop and you should see 6 cores.
If you normally use 2 cores and up to 10W of power in Mode ID 3, which is the default mode, and you need to perform machine learning, etc., you can change the mode to 2 for maximum performance.
For reference, since the GPU is used regardless of the Mode ID, the machine learning execution performance, which is highly dependent on the GPU usage, does not depend heavily on the Mode ID.

Wrapping up

So far, we have seen how to install JetPack in Headless mode on Jetson Xavier NX and how to use SSD. Next time, I will look at using the Python virtual environment to utilize SSD effectively.





2019년 11월 5일 화요일

Jetson TX2 - Install SSD

The 32Gb eMMC capacity of the Jetson TX2 is not sufficient to install and test various machine learning frameworks and data. The Jetson Nano can do a variety of tests by replacing the sd card, but the eMMC on the Jetson TX2 is not easy to replace. Therefore, increasing the capacity of the storage device is a great help. In this article, we'll add an SSD to the Jetson TX2 and use it as a workspace in the future.
The next video from JetsonHacks will help you install an SSD.


SSD connection 

Prepare SSD


We will use a SATA SSD. Prepare SATA SSD and SATA cable as follows.




Connect SSD to TX2

TX2 board has a SATA slot. Power off the TX2 and connect the SATA cable to the slot.


Then power on the TX2.

Configuration

Follow these steps.


Run Disk utility.



You can see the SSD that you connected. In this picture, I connected ADATA's 120GB SSD that I was using on the Windows. My SSD  already has many partitions. So press "-" button and delete all partitions. If you use a new SSD, there may be no "-" button appears.



 Now all partitions are cleared.



Then format the 120GB SSD. Press the gear button and select format menu.



 Enter the volume name you like and file system (EXT4).




Now the new SSD is ready to use.



The final step is to permanently mount the new SSD.


cd /
sudo mkdir work
vim /etc/fstab

The fstab file looks like this.


# <file system> <mount point>             <type>          <options>                               <dump> <pass>
/dev/root            /                     ext4           defaults                                     0 1
/dev/sda1            /work                 ext4           defaults                                     0 1

Now reboot the TX2 system and check the file system.


spytx@spytx-desktop:~/Pictures$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/mmcblk0p1   28G   13G   14G  49% /
none            3.8G     0  3.8G   0% /dev
tmpfs           3.9G  4.0K  3.9G   1% /dev/shm
tmpfs           3.9G   21M  3.9G   1% /run
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
tmpfs           3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/sda1       110G   61M  104G   1% /work
tmpfs           786M   12K  786M   1% /run/user/120
tmpfs           786M  104K  786M   1% /run/user/1000


Yes, you can now mount a 110GB SSD in the /work directory.

Wrapping up

The Jetson TX2 is not easy to replace, so adding storage, such as an SSD, is quite useful.
In the future, many machine learning packages will need to be installed on a single storage device. We will use the Python virtual environment to make it easier to avoid failures due to interference between packages. However, in case of OpenCV which is used commonly in most packages, it can be used in common. For installing OpenCV 4.1.1 on Jetson TX2, see the following article(https://spyjetson.blogspot.com/2019/11/jetson-tx2-opencv-411-upgrade.html).