Abstract
GPUs are increasingly playing vital roles in the modern technology industry. Improving the GPU performance involves optimizing its architectural design and fine-tuning its software code. However, to achieve this, engineers must investigate codes from as many GPU-related applications as possible to identify code portions that need fine-tuning. Moreover, this effort requires engineers to have good domain knowledge, and their work is made more arduous because the source codes of applications are normally confidential. To this end, we introduce ShaderAnalyzer, a solution leveraging graph mining and machine learning to analyze GPU-executed low-level machine codes and identify their fine-tuning opportunities. Our approach includes representing machine code with graph structure and subsequently identifying frequently occurring substructures within the codes. Optimizing the execution of these substructures can enhance the overall performance of the GPU. In addition, our model leverages these frequent patterns to further facilitate engineers' tasks by selecting representative patterns to predict and investigate low-efficiency ones. We conduct comprehensive experiments to evaluate the performance of our solution, and the results have been validated by our industry partners. ShaderAnalyzer is an end-to-end framework that helps engineers identify code segments with the highest potential for performance gains after fine-tuning and offers valuable insights for hardware architects in future products design.
Introduction
Modern GPU performance tuning is a "needle in a haystack" problem. Engineers need to optimize shaders—the low-level programs that handle everything from pixel rendering to AI—but they face three massive hurdles: confidentiality of high-level source code, the sheer scale of instructions per frame, and the diversity of optimization strategies across different games.
ShaderAnalyzer is a new end-to-end framework designed to overcome these challenges. By representing low-level machine code as graphs, the tool uncovers frequently occurring patterns across millions of shaders, allowing engineers to optimize hardware and software without needing access to a developer's confidential source code.
The ShaderAnalyzer Framework
ShaderAnalyzer treats shader code analysis as a graph mining problem. The framework extracts shader code from video games, converts it into a graph dataset, and applies frequent subgraph mining to identify critical patterns. These patterns then inform downstream tasks like clustering and efficiency prediction, ultimately guiding software tuning and hardware design.
Methodology
Graph Formulation
The system converts disassembled shader instructions into nodes and their execution flow into edges. Two versions are utilized: a "full-instruction" graph for detail and a "critical-instruction" graph that focuses on time-intensive operations (like memory loads) to speed up analysis.
MAX-gSpan and Semantic Completion
Standard frequent subgraph mining (FSM) often returns thousands of tiny, redundant fragments. The authors developed MAX-gSpan to retain only the "maximal" subgraphs—the largest possible frequent patterns—reducing noise. Because mined subgraphs are often just fragments, a semantic completion step maps these fragments back to their "parent" code to reconstruct complete, meaningful blocks like loops or conditional branches.
Downstream Machine Learning Tasks
The framework leverages the Weisfeiler-Lehman (WL) Graph Kernel to measure similarity between shaders, powering several key tasks:
- Clustering: Grouping similar game scenes to avoid redundant tuning.
- Community Detection: Identifying "families" of sub-patterns across different applications.
- Efficiency Prediction: Utilizing a Random Forest classifier to predict which code patterns are likely to be "low-efficiency" bottlenecks based on structural features.
Experimental Evaluation
The study utilized a massive dataset of over 4 million disassembled shaders extracted from 68 scenes across 31 different games, including AAA titles like Grand Theft Auto 5, Battlefield 5, and Horizon Zero Dawn.
Key Results: * Efficiency Gains: Industry partners reported that ShaderAnalyzer reduced analysis time by over 2/3. * High Predictive Accuracy: The Random Forest model achieved a 94% validation accuracy in identifying low-efficiency shader segments. * Pattern Discovery: The system identified 48 distinct "communities" of sub-patterns, with the top two groups accounting for nearly 45% of all frequent subgraphs found.
Key Insights
- Structure as Logic: The research demonstrates that the structure of machine code (via WL Kernel) is a reliable proxy for the logic of the original high-level program.
- Hardware Optimization: By identifying frequent sub-patterns, hardware architects can design specialized circuits (ASICs) to handle specific patterns with extreme efficiency.
- Cross-Game Redundancy: Many games share engines (e.g., Unreal Engine). ShaderAnalyzer exploits this by clustering similar scenes, allowing engineers to apply reference configurations across different titles.
Conclusion and Future Work
While ShaderAnalyzer significantly automates bottleneck identification, it currently relies on expert labeling for ground-truth data and may lose some information regarding specific resource binding details. Future work will focus on integrating deep learning models, such as Graph Neural Networks (GNNs), to further automate feature extraction and reduce reliance on manual labeling.
Summary updated