Loading page

Identify Mali GPU resources used by the sample

ML Drift unified shaders let you reuse computation across supported GPU backends. However, performance still depends on the GPU architecture, driver, and workload. You’ll use Arm Streamline to see how the OpenCL sample uses Mali GPU resources.

Build with debug symbols

Open two terminals.

In the first terminal, build the Android arm64 sample with release optimizations and debug symbols:

    

        
        
bazel build -c opt --config=android_arm64 \
  --copt=-g \
  --strip=never \
  --linkopt=-Wl,-z,max-page-size=16384 \
  --linkopt=-Wl,-z,common-page-size=16384 \
  //ml_drift/samples/stable_diffusion:sd_gpu_opencl

    

This preserves runtime performance while providing function names and source mappings for Streamline analysis.

Copy the debug executable to your Android device, then make it runnable:

    

        
        
adb push bazel-bin/ml_drift/samples/stable_diffusion/sd_gpu_opencl \
  /data/local/tmp/sd_gpu_opencl

adb shell chmod +x /data/local/tmp/sd_gpu_opencl

    

Deploy the profiling agent

Set STREAMLINE to your Streamline installation directory. The following example uses Arm Performance Studio 2026.6 on macOS. If you have a different version installed, adjust the version number in the path accordingly:

    

        
        
export STREAMLINE="/Applications/Arm Performance Studio 2026.6/streamline"

    

On x86 Linux, use your corresponding installation directory.

Copy the Android arm64 profiling agent, gatord, to your device. Make it runnable:

    

        
        
adb push "$STREAMLINE/bin/android/arm64/gatord" /data/local/tmp/
adb shell chmod +x /data/local/tmp/gatord

    

Launch Streamline on your host computer and perform the following steps:

  1. Select the connected Android device.
  2. Under Configure Capture, enable Use advanced mode if Select Counters isn’t visible.
  3. Open Select Counters and select the pre-made template matching your target Mali GPU, as shown in the following image.

Image Alt Text:Streamline counter selection showing the Mali G1-Ultra template selected and GPU events populated, identifying the counter configuration to export for capture.

  1. Use the export button to save configuration.xml in the ML Drift repository root.

Copy the exported counter configuration to your Android device. Replace the first configuration.xml with the path to your exported file:

    

        
        
adb push configuration.xml /data/local/tmp/configuration.xml

    

Finally, enable the Android GPU driver Perfetto tracing:

    

        
        
adb shell setprop debug.graphics.gpu.profiler.perfetto 1

    

Capture idle and generation activity

Start the sample on the Android device. Leave it running at the Enter phrase: prompt:

    

        
        
adb shell -t 'cd /data/local/tmp && ./sd_gpu_opencl'

    

In the second terminal, start gatord on the Android device:

    

        
        
adb shell 'cd /data/local/tmp && ./gatord \
  -c configuration.xml \
  -o sd_gpu_debug.apc \
  -i "$(pidof sd_gpu_opencl)"'

    

You’ll use gatord to profile the running sample with your exported counter configuration.

Keep both processes running concurrently during image generation. Wait for a few seconds to capture idle activity.

Then, in the first terminal, enter the image description and diffusion step count:

    

        
        
image of a cat in space
10

    

When generation completes and Enter phrase: returns, press Ctrl+C only in the first terminal to exit the sample. Wait for the second terminal to finish the capture and return to the command prompt. Then, copy the capture to the Streamline data directory on your host computer:

    

        
        
mkdir -p "$HOME/Documents/Streamline"
adb pull /data/local/tmp/sd_gpu_debug.apc "$HOME/Documents/Streamline/"

    

Inspect GPU activity

To inspect GPU activity on Arm Streamline, complete the following steps:

  1. Open sd_gpu_debug in the Streamline Data view. If the capture isn’t listed, add ~/Documents/Streamline to the data locations.
  2. In the Analyze dialog, add the exact executable used for the capture.
  3. For the optimized build with debug symbols created earlier, select <path-to-ml-drift>/bazel-out/arm64-v8a-opt/bin/ml_drift/samples/stable_diffusion/sd_gpu_opencl.
  4. Select its Use checkbox to enable symbol loading, then select Analyze to start the analysis.

Image Alt Text:Streamline Analyze dialog showing an executable with code, symbols, debug information, and call frame information available.Select the matching executable and enable Use for symbol loading

Timeline view

Use the Timeline view to explore how Mali GPU activity changes during image generation. Its charts provide a closer look at GPU components, including the programmable shader cores, arithmetic units, and memory system. These measurements help you understand how the workload uses the GPU.

Image Alt Text:Streamline Timeline showing GPU activity charts during ML Drift image generation.Mali GPU activity during image generation

Select Mali Timeline in the details panel to inspect GPU workload scheduling. Events are grouped by device, process, context, and stream.

Image Alt Text:Streamline showing GPU activity and compute queue utilization charts above Mali Timeline events in the application&rsquo;s Compute stream.Mali Timeline aligns GPU compute workloads with activity and utilization charts

For this OpenCL sample, expand the Compute stream of the application to see recorded GPU workloads.

Functions view

Use the Functions view to see where sampled CPU execution occurs in ML Drift. Function names, sample counts, and source locations help you identify frequently sampled code and choose where to investigate further. This source attribution applies to CPU code, not the shaders that run on the GPU.

Image Alt Text:Streamline Functions tab showing resolved ML Drift function names, sample counts, and source filenames with line numbers, demonstrating CPU source attribution with debug information loaded.CPU function samples with source locations

What you’ve accomplished

You used Streamline to confirm sustained Mali GPU activity during image generation and inspect how the workload uses GPU resources.

You can extend the Learning Path by authoring your own portable GPU kernels with Unified Compute Language (UCL). You can integrate the kernels as custom operations in ML Drift, and profile their performance on Mali GPUs.