§2024-12-04

Building PyTorch from source

¶Prerequisites

¶ 1. Verify if your device is Jetson Orin Nano

$ cat /etc/nv_tegra_release
# R36 (release), REVISION: 4.0, GCID: 37537400, BOARD: generic, EABI: aarch64, DATE: Fri Sep 13 04:36:44 UTC 2024
# KERNEL_VARIANT: oot
TARGET_USERSPACE_LIB_DIR=nvidia
TARGET_USERSPACE_LIB_DIR_PATH=usr/lib/aarch64-linux-gnu/nvidia

$ sudo lshw -C system
[sudo] password for alexlai: 
jetsonorinnano              
    description: Computer
    product: NVIDIA Jetson Orin Nano Developer Kit
    vendor: NVIDIA
    version: Not Specified
    serial: 1424124331068
    width: 64 bits
    capabilities: smbios-3.6.0 dmi-3.6.0 smp tagged_addr_disabled
    configuration: boot=normal family=Unknown sku=Unknown

¶ 2. Check if CUDA is enabled on your device

CUDA is typically enabled if you're using a supported version of the JetPack SDK for the Jetson platform.

Option 1: Check CUDA version

$ nvcc --version  <-- ???
bash: nvcc: command not found
sudo apt install nvidia-driver-52  <-- even installed
$ nvcc
bash: nvcc: command not found


if not found

wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/arm64/cuda-ubuntu2204.pin
sudo mv cuda-ubuntu2204.pin /etc/apt/preferences.d/cuda-repository-pin-600
wget https://developer.download.nvidia.com/compute/cuda/12.6.3/local_installers/cuda-tegra-repo-ubuntu2204-12-6-local_12.6.3-1_arm64.deb
sudo dpkg -i cuda-tegra-repo-ubuntu2204-12-6-local_12.6.3-1_arm64.deb
sudo cp /var/cuda-tegra-repo-ubuntu2204-12-6-local/cuda-*-keyring.gpg /usr/share/keyrings/
sudo apt-get update
sudo apt-get -y install cuda-toolkit-12-6 cuda-compat-12-6
(PYTHON-3.10.15) alexlai@JetsonOrinNano:~/build/src$ tegrastats
12-04-2024 14:21:53 RAM 3686/7620MB (lfb 1x4MB) SWAP 582/3810MB (cached 0MB) CPU [2%@729,1%@729,1%@729,1%@729,0%@729,0%@729] GR3D_FREQ 0% cpu@51.593C soc2@51.156C soc0@50.343C gpu@50.625C tj@51.593C soc1@51.156C VDD_IN 5172mW/5172mW VDD_CPU_GPU_CV 512mW/512mW VDD_SOC 1537mW/1537mW
12-04-2024 14:21:54 RAM 3686/7620MB (lfb 1x4MB) SWAP 582/3810MB (cached 0MB) CPU [1%@729,1%@729,0%@729,0%@729,0%@729,0%@729] GR3D_FREQ 0% cpu@51.343C soc2@51C soc0@50.343C gpu@50.718C tj@51.343C soc1@51.218C VDD_IN 5172mW/5172mW VDD_CPU_GPU_CV 512mW/512mW VDD_SOC 1537mW/1537mW

¶ Get the PyTorch Source

git clone --recursive https://github.com/pytorch/pytorch
cd pytorch
# if you are updating an existing checkout
git submodule sync
git submodule update --init --recursive
pip install -r requirements.txt
Successfully installed astunparse-1.6.3 cmake-3.31.1 expecttest-0.2.1 hypothesis-6.122.1 lintrunner-0.12.5 ninja-1.11.1.2 optree-0.13.1 types-dataclasses-0.6.6 typing-extensions-4.12.2 wheel-0.45.1