3.9. sample_gpu_3d Instructions

X53D GPU supports the following standard APIs:

  • EGL

  • OpenGLES

  • Vulkan

  • OpenCL

Among these, EGL acts as an intermediate layer API that provides interaction support with underlying hardware. Therefore, sample code is provided for the following three APIs:

  1. OpenGLES example

  2. Vulkan example

  3. OpenCL example

Please select the appropriate API example based on your specific needs for reference and use.

3.9.1. OpenGL ES

3.9.1.1. sample_bezier

Function Overview

Function Description: sample_bezier uses the 3D GPU to draw a Bezier curve and saves the image to a file.

Software Architecture Description

sample_bezier supports two rendering modes:

  • Onscreen mode (default): Presents the EGL surface on an HDMI monitor via DRM + GBM.

  • Offscreen mode: Renders offscreen via fbdev virtual framebuffer, no physical monitor required.

 framwork_bezier

Code Location and Directory Structure
  • Code Location: app/samples/platform_samples/sample_gpu_3d/gles/sample_bezier

  • Directory Structure

sample_bezier/
├── common
│   ├── bmp.c
│   ├── bmp.h
│   ├── vdk_common.c
│   └── vdk_common.h
└── sample_bezier
    ├── bezier.c
    └── Makefile
API Flow Description
Overall Flow

 sample_bezier_data_flow

vdk_init

vdk_init is a function in libVDK.so that encapsulates the EGL interface and completes the initialization of the EGL context based on DRM+GBM or fbdev when no desktop system is available. Which path is used is determined by the VDK_PLATFORM environment variable set when the program starts:

  • Onscreen mode: VDK_PLATFORM=gbm

  • Offscreen mode: VDK_PLATFORM=fbdev, with VIV_EGL_PLATFORM=fbdev and VFB_ENABLE=1 set

 sample_bezier_vdk_init_data_flow

Compilation and Deployment

Compilation
  • Enter the sample_bezier directory and run make to compile.

  • The output artifact is bezier located in the sample_bezier source directory.

  • For detailed compilation methods, please refer to the Compilation Method section.

Program Deployment
  1. Upload the sample_bezier directory to the /userdata directory of the development board.

  2. Enter the sample_bezier directory and run the command chmod +x bezier to grant execution permission to the program.

Running

sample_bezier runs in Onscreen mode (DRM + GBM) by default and requires a display panel connected via HDMI. For development boards without a display panel, you can switch to Offscreen mode fbdev for offscreen rendering via the -o/--offscreen option. The resulting bezier.bmp is identical to that of Onscreen mode.

Program Parameter Options
Option Description
-o, --offscreen Offscreen rendering mode, renders via fbdev (no physical display panel required). If not specified, renders via GBM (requires a display panel connected)
-h, --help Print help information and exit
How to Run the Program

Onscreen mode (default, requires an HDMI display panel)

Load the drivers:

modprobe panel-jc-050hd134
modprobe galcore
modprobe vio_n2d
modprobe lontium_lt8618
modprobe vs-x5-syscon-bridge
modprobe vs_drm

Connect a monitor via the HDMI interface, and run the program:

Execution command:
./bezier

Runtime log:

Render mode: onscreen (gbm)

Offscreen mode (-o, for boards without a display panel)

Execution command:
./bezier -o

Runtime log:

Render mode: offscreen (fbdev)
Running Results

Result description:
In the current directory, a BMP image file named bezier.bmp will be generated. The red line in the file represents a Bezier curve. The bezier.bmp generated in Onscreen and Offscreen modes is identical.

 Result

3.9.2. OpenCL

3.9.2.1. sample_matrix_multiply

Function Overview

Function Description: sample_matrix_multiply performs identical matrix operations using both the 3D GPU and CPU, and prints the execution time for both.

Software Architecture Description

 framwork_matrix_mulpi

Code Location and Directory Structure
  • Code Location: app/samples/platform_samples/sample_gpu_3d/cl/sample_matrix_multiply

  • Directory Structure

└── sample_matrix_multiply
    ├── Makefile
    └── matrix_multiply.c
API Flow Description
Overall Flow

 sample_matrix_mulpti_data_flow

matirc_mult_opencl

The function matirc_mult_opencl uses the GPU to perform matrix multiplication, as shown in the following process (corresponding to the yellow background section in the overall flow):

 sample_matrix_mulpti_opencl_data_flow

Compilation and Deployment

Compilation
  • Enter the sample_matrix_multiply directory and execute make to compile.

  • The output artifact is matrix_multiply located in the sample_matrix_multiply source directory.

  • For detailed compilation methods, please refer to the Compilation Method section.

Program Deployment
  1. Upload the sample_matrix_multiply directory to the /userdata directory of the development board.

  2. Enter the sample_matrix_multiply directory and run the command chmod +x matrix_multiply to grant execution permission to the program.

Running

How to Run the Program

Run the executable: ./matrix_multiply

Program Parameter Options

None

Running Results

Execution command: ./matrix_multiply

Runtime log:

./matrix_multiply
CPU execution time: 19.133549 seconds
OpenCL execution time: 0.792543 seconds
Matrices are identical!

Result description: For the same matrix multiplication operation:

  1. CPU execution time: 19.133549 seconds

  2. GPU execution time: 0.792543 seconds

From the total execution time, it can be seen that the GPU has significantly better performance than the CPU in matrix multiplication operations.