|
| 1 | +# Home |
| 2 | +## Cheat Sheet |
| 3 | +This Cheat Sheet contains all commands to run a tflite demo in gem5 fs mode. |
| 4 | + |
| 5 | +## Get Started |
| 6 | +Follow these instructions to download all the required materials, build a gem5 binary and run simple examples in both System Call Emulation (SE) and Full System (FS) modes. |
| 7 | + |
| 8 | +## Get GEM5 |
| 9 | +- Follow this [tutorial](https://www.gem5.org/getting_started/) to build a excutable gem5 binary. |
| 10 | +- We use the v22.0.0.1 version. |
| 11 | + |
| 12 | +## Simulate Arm in gem5 |
| 13 | + |
| 14 | +### SE Simulation |
| 15 | + |
| 16 | +#### Run simple SE: |
| 17 | +``` |
| 18 | +$ ./build/ARM/gem5.opt configs/example/arm/starter_se.py --cpu="minor" "tests/test-progs/hello/bin/arm/linux/hello" _# Hello world!_ |
| 19 | +``` |
| 20 | +#### Run multicore SE: |
| 21 | + |
| 22 | +Note: each core runs its own program |
| 23 | +``` |
| 24 | +$ ./build/ARM/gem5.opt configs/example/arm/starter_se.py --cpu="minor" --num-cores=2 "tests/test-progs/hello/bin/arm/linux/hello" "tests/test-progs/hello/bin/arm/linux/hello" |
| 25 | +``` |
| 26 | +### FS Simulation |
| 27 | + |
| 28 | +Get an Arm full system disk image from the gem5 downloads page, and set $M5_PATH: |
| 29 | + |
| 30 | +> Note: the download URLs and filenames below are examples, and may change as new binaries are released by the gem5 project. Please also use a suitable $M5_PATH of your choice. |
| 31 | +``` |
| 32 | +$ export M5_PATH="${PWD}/../m5_binaries" |
| 33 | +
|
| 34 | +$ mkdir -p "${M5_PATH}" |
| 35 | +
|
| 36 | +$ wget -P "${M5_PATH}" http://dist.gem5.org/dist/v22-0/arm/aarch-system-20220707.tar.bz2 |
| 37 | +
|
| 38 | +$ tar -xjf "${M5_PATH}/aarch-system-20210904.tar.bz2" -C "${M5_PATH}" |
| 39 | +
|
| 40 | +$ wget -P "${M5_PATH}/disks" http://dist.gem5.org/dist/v22-0/arm/disks/ubuntu-18.04-arm64-docker.img.bz2 |
| 41 | +
|
| 42 | +$ bunzip2 "${M5_PATH}/disks/ubuntu-18.04-arm64-docker.img.bz2" |
| 43 | +
|
| 44 | +$ echo "export M5_PATH=${M5_PATH}" >> ~/.bashrc |
| 45 | +``` |
| 46 | +#### Run simple FS with disk image: |
| 47 | +``` |
| 48 | +$ ./build/ARM/gem5.opt configs/example/arm/starter_fs.py --cpu="minor" --num-cores=1 \ |
| 49 | + --disk-image=$M5_PATH/disks/ubuntu-18.04-arm64-docker.img --root-device=/dev/vda1 |
| 50 | +``` |
| 51 | +#### Create a checkpoint after boot: |
| 52 | +``` |
| 53 | +$ telnet localhost 3456 |
| 54 | +
|
| 55 | +$ m5 checkpoint |
| 56 | +``` |
| 57 | +> Note: 3456 is the default port number used by the gem5 simulator. If this does not work, the correct port number can be found in the gem5 output: |
| 58 | +
|
| 59 | +system.terminal: Listening for connections on port 3456 |
| 60 | + |
| 61 | +A more modern alternative is to use the m5term utility provided with gem5. |
| 62 | + |
| 63 | +#### Restore from a checkpoint: |
| 64 | + |
| 65 | +> Note: Arm starter_fs.py allows you to specify checkpoints with --restore=m5out/cpt.TICKNUMBER/. Make sure the --num-cores and --disk-image arguments are the same as the original simulation; the --cpu type may be changed. |
| 66 | +``` |
| 67 | +$ ./build/ARM/gem5.opt configs/example/arm/starter_fs.py --restore=m5out/cpt.TICKNUMBER/ --cpu="minor" --num-cores=1 --disk-image=$M5_PATH/disks/ubuntu-18.04-arm64-docker.img --root-device=/dev/vda1 |
| 68 | +``` |
| 69 | +## FS Benchmarks |
| 70 | + |
| 71 | +### Get and Compile OpenCV |
| 72 | + |
| 73 | +Install ccmake |
| 74 | +``` |
| 75 | +$ sudo apt-get install cmake-curses-gui |
| 76 | +``` |
| 77 | +Install the Arm cross compiler toolchain |
| 78 | +``` |
| 79 | +$ sudo apt install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu binutils-aarch64-linux-gnu |
| 80 | +``` |
| 81 | + |
| 82 | +Download OpenCV 4.6.0: |
| 83 | +``` |
| 84 | +$ wget https://github.com/opencv/opencv/archive/refs/tags/4.6.0.tar.gz |
| 85 | +$ tar -xvzf opencv-4.6.0.tar.gz && cd opencv-4.6.0 |
| 86 | +$ mkdir build && cd build && ccmake -DCMAKE_TOOLCHAIN_FILE=../platforms/linux/aarch64-gnu.toolchain.cmake .. |
| 87 | +``` |
| 88 | +We build the opencv world static library |
| 89 | + |
| 90 | + |
| 91 | +``` |
| 92 | +$ make -j install |
| 93 | +``` |
| 94 | + |
| 95 | +### Get and Compile TFLITE |
| 96 | + |
| 97 | +- Follow this [tutorial](https://www.tensorflow.org/lite/guide/build_cmake) to build a static tensorflow-lite library. |
| 98 | +- We use the v2.9.1 version. |
| 99 | + |
| 100 | +### Cross-Compile Demo on x86 |
| 101 | + |
| 102 | +[link](../README) |
| 103 | + |
| 104 | +### Run TFLITE demo |
| 105 | +To run TFLITE demo on Arm, we need to enlarge the disk image and copy the directory of compiled demo to it. Then, we need to pass the demo runscripts via the --script option to the simulation script starter_fs.py. |
| 106 | + |
| 107 | +### Copy classification to Disk Image |
| 108 | + |
| 109 | +#### Expand and resize the disk image: |
| 110 | +``` |
| 111 | +$ cp ubuntu-18.04-arm64-docker.img expanded-ubuntu-18.04-arm64-docker.img |
| 112 | +
|
| 113 | +$ dd if=/dev/zero bs=1G count=20 >> ./expanded-ubuntu-18.04-arm64-docker.img # add 20G zeros |
| 114 | +
|
| 115 | +$ sudo parted expanded-ubuntu-18.04-arm64-docker.img resizepart 1 100% # grow partition 1 |
| 116 | +``` |
| 117 | +#### Mount the expanded disk image, resize the filesystem, and copy PARSEC to it: |
| 118 | + |
| 119 | +#### In order to mount the disk image, we must calculate the offset of the first partition. |
| 120 | + |
| 121 | +#### Run fdisk to find the start offset (in sectors) and the sector size (in bytes) of the partition. |
| 122 | +``` |
| 123 | +$ fdisk -l expanded-ubuntu-18.04-arm64-docker.img |
| 124 | +``` |
| 125 | +Disk expanded-ubuntu-18.04-arm64-docker.img: 21.9 GiB, 23474836480 bytes, 45849290 sectors |
| 126 | + |
| 127 | +Units: sectors of 1 * 512 = 512 bytes |
| 128 | + |
| 129 | +Sector size (logical/physical): 512 bytes / 512 bytes |
| 130 | + |
| 131 | +I/O size (minimum/optimal): 512 bytes / 512 bytes |
| 132 | + |
| 133 | +Disklabel type: dos |
| 134 | + |
| 135 | +Disk identifier: 0x93d4895b |
| 136 | + |
| 137 | +Device Boot Start End Sectors Size Id Type |
| 138 | + |
| 139 | +expanded-ubuntu-18.04-arm64-docker.img1 128 45849289 45849162 21.9G 83 Linux |
| 140 | + |
| 141 | +#### In this example the start offset (in sectors) is 128 and the sector size (in bytes) is 512, giving a start offset of 128x512=65536 bytes. |
| 142 | + |
| 143 | +#### Now mount the disk image, resize the filesystem, and copy PARSEC. |
| 144 | + |
| 145 | +> Note: set /path_to_compiled_parsec-3.0_dir/, and change 32256 to the offset in bytes calculted above |
| 146 | +``` |
| 147 | +$ mkdir disk_mnt |
| 148 | +
|
| 149 | +$ sudo mount -o loop,offset=65536 expanded-ubuntu-18.04-arm64-docker.img disk_mnt |
| 150 | +
|
| 151 | +$ df # find /dev/loopX for disk_mnt |
| 152 | +
|
| 153 | +$ sudo resize2fs /dev/loopX # resize filesystem |
| 154 | +
|
| 155 | +$ df # check that the Available space for disk_mnt is increased |
| 156 | +
|
| 157 | +$ mkdir -p disk_mnt/root/tflite |
| 158 | +
|
| 159 | +$ sudo cp -r classification/ disk_mnt/root/tflite # copy the compiled tflite_classification demo and the other files to the image |
| 160 | +
|
| 161 | +$ sudo ls disk_mnt/root/tflite/classification # check the demo contents |
| 162 | +
|
| 163 | +$ sudo umount disk_mnt |
| 164 | +``` |
| 165 | +### Run classification on HPI |
| 166 | + |
| 167 | +We only show how to run classification on the HPI model. Reading results from stats.txt files can be done by using the read_results.sh script, as shown for the SE mode. |
| 168 | + |
| 169 | +#### benchmark runscripts |
| 170 | + |
| 171 | +[link](../scripts/run_classification.sh) |
| 172 | + |
| 173 | +#### Run starter_fs using the expanded image and benchmark runscript |
| 174 | + |
| 175 | +$ ./build/ARM/gem5.opt -d fs_results/<benchmark> configs/example/arm/starter_fs.py --cpu="hpi" --num-cores=1 --disk-image=$M5_PATH/disks/expanded-ubuntu-18.04-arm64-docker.img --root-device=/dev/vda1 --script=../scripts/run_classification.sh |
0 commit comments