Qualcomm Robotics RB5/RB6 - GPU Profiling
In this section we will see how to work with the Qualcomm Robotics RB5's GPU. The RB5/RB6 has a Qualcomm Adreno 650 GPU as one of its hardware processing units. We will see how to measure it usage percentage and how to run some examples in the GPU. For the latter, we will use OpenGL with GStreamer and two compiled examples. OpenGL is a cross-language, cross-platform application programming interface for rendering 2D and 3D vector graphics. The API is typically used to interact with a graphics processing unit (GPU), to achieve hardware-accelerated rendering [1].
Profile GPU
Profiling the GPU means we will see how much of the GPU is being used by our applications. This allows for a better analysis of how our applications is working. The method we are using works for RB5/RB6 boards flashed with Ubuntu Linux.
To measure the GPU usage percentage, we are going to check a node from the system. The node is in the following direction: /sys/class/kgsl/kgsl-3d0/gpu_busy_percentage
. To check the value of the GPU, you can use the following command:
cat /sys/class/kgsl/kgsl-3d0/gpu_busy_percentage
If you want to measure constantly the GPU, you can use the watch
command, like the following:
watch -n 1 cat /sys/class/kgsl/kgsl-3d0/gpu_busy_percentage
Where the value is getting updated every second. Now, lets try some examples and measure the GPU!
GStreamer pipeline
The first example we are using is a GStreamer pipeline. To run it in the GPU, we are using OpenGL plugins. The OpenGL plugins are from the Plugins base of GStreamer, so you only need to install GStreamer. The RB5/RB6 board flashed with a LU image from Thundercomm, already comes with GStreamer and the OpenGL plugins preinstalled. The pipeline we are using is the next one:
gst-launch-1.0 videotestsrc is-live=true ! "video/x-raw,width=1920,height=1080,framerate=30/1" ! videoconvert ! glupload ! gleffects_fisheye ! glvideoflip video-direction=1 ! gleffects_sepia ! gldownload ! queue ! videoconvert ! waylandsink sync=false
In the pipeline above, we are using as our source element videotestsrc
, that will generate a video. Then, we define the caps of the video and use videoconvert to transform the format of the data to one that the OpenGL environment supports. To enter the OpenGL environment, we need to use the glupload
element. Inside this environment, we can later use all of the available OpenGL Plugins, that you can check with the following command:
gst-inspect-1.0 | grep opengl
In our case, we are testing three elements: gleffects_fisheye, glvideoflip, and gleffects_sepia. The first one, applies a fisheye effect to the video, then the glvideoflip element is rotates the video 90 degrees clockwise. Finally, the gleffects_sepia element applies a Sepia Toning effect. We then use the gldownload
element to come back to the GStreamer environment, and finally display the output to a monitor with waylandsink
. In Figure 1, you can see the expected output.
If we measure the GPU while running the pipeline the usage percentage is of 8%. This shows that out pipeline is in fact running on th GPU.
Draw a square
In this next example, we are creating and displaying a colored window in our monitor. This example uses EGL and wayland protocol. The example we are using was created by Miouyouyou, and you can get the source files from the following link. The firsts steps are done in your host computer.
1. Enter the link above, where you will find three files: init_window.c
, init_window.h
, and log.h
.
2. Now, you need to download the files. You can click the Download ZIP button, it will download a zip file with the the source code. In your host computer, you can open a terminal and check the downloaded file.
user@desktop:~/Downloads/OpenGL_draw_square$ ls ca15af1c7f2696f66b0e013058f110b4-af380e5baabecc70d890d41b81ce87b5951dc48f.zip
The downloaded file should have name similar to the above.
3. Move the zip file to the board using ADB or SSH. If you are using ADB, use the following command:
adb push ca15af1c7f2696f66b0e013058f110b4-af380e5baabecc70d890d41b81ce87b5951dc48f.zip /work/directory/path/
If you are using SSH, you can use the following command:
scp ca15af1c7f2696f66b0e013058f110b4-af380e5baabecc70d890d41b81ce87b5951dc48f.zip root@192.168.1.1:/work/directory/path/
4. Now, the next steps will be using your Qualcomm Robotics RB5/RB6 board. You can access it with ADB or SSH. Unzip the file and change the directory name. Use the following commands:
unzip ca15af1c7f2696f66b0e013058f110b4-af380e5baabecc70d890d41b81ce87b5951dc48f.zip mv ca15af1c7f2696f66b0e013058f110b4-af380e5baabecc70d890d41b81ce87b5951dc48f window_example cd window_example
Inside the directory, you should have the following files:
user@desktop:~/work/OpenGL/window_example$ ls init_window.c init_window.h log.h
5. Compile the program using the following command:
gcc -o test_window init_window.c -I. -lwayland-client -lwayland-server -lwayland-client -lwayland-egl -lEGL -lGLESv2
In the above command, we are generating a an output executable file named test_window
and giving all the needed libraries for compilation.
6. Now, we need to define some environment variables needed to display in our monitor. Use the following commands:
export LD_LIBRARY_PATH=/usr/lib:/usr/lib/aarch64-linux-gnu/ export XDG_RUNTIME_DIR=/usr/bin/weston_socket
7. Finally, we can execute the program! Use the next command:
./test_window
You should see a brown window in your monitor, like the one in Figure 2.
When running the example, the GPU usage percentage is of 6%.
Draw a rotating triangle
In this next and final example, we will create a multi-color triangle rotating on its own axis. For this example, we are using the code created by KRH called simple-egl.c
. You can access the code in the following link. The firsts steps are done in your host computer.
1. Enter the next link to see the source code. Please copy it and paste it in a a new file in your computer. Name this file with the same name: simple-egl.c
.
2. Move the file to the board using ADB or SSH. If you are using ADB, use the following command:
adb push simple-egl.c /work/directory/path/
If you are using SSH, you can use the following command:
scp simple-egl.c root@192.168.1.1:/work/directory/path/
3. Now, we need to continue working in the RB5/RB6 board. We will now compile the file using the following command:
gcc -o test_triangle simple-egl.c -I. -lwayland-client -lwayland-server -lwayland-client -lwayland-egl -lEGL -lGLESv2 -lm -lwayland-cursor
In the above command, we are generating a an output executable file named test_triangle
and giving all the needed libraries for compilation.
4. Finally, we can execute the program! Use the next command:
./test_triangle
You should see a multi-color triangle rotating in your monitor, like the one in Figure 3.
When running the example, the GPU usage percentage is of 5%.
Results
We already saw how to measure the GPU utilisation percentage and three examples running on it. In table 1, we have a summary of each example and the percentage of GPU it is using.
Test case | GPU (%) |
---|---|
GStreamer pipeline | 8 |
Color window | 6 |
Multi-color rotating triangle | 5 |
References