IP Library › Granted Patent US 12,731,026
Granted Patent B2
US 12,731,026 · App. 17/976,193 · Granted Sep 8, 2026

Method and system for program sampling using neural network

Inventors: Yuanwei Fang (Sunnyvale, CA); Jian Chen (Sunnyvale, CA); Yen-Kuang Chen (Palo Alto, CA); Yuan Xie (Sunnyvale, CA)
Assignee: Alibaba (China) Co., Ltd.
G06N3/08G06F8/41
View Patent ↗
Loading inventors, assignments & file history…
Monitor This Case
Get email alerts when status or documents change.
Order Certified Copies
Most orders are placed with the USPTO same day — all within 24 business hours.
Order via The Patent Place →
Pre-filled with this patent's details
Quick Facts
Patent No.
US 12,731,026
App. No.
17/976,193
Filed
Oct 28, 2022
Granted
Sep 8, 2026
Kind
B2
Art Unit
2143
USPC
706/25
Abstract

This application describes methods, systems, and apparatus, for neural network-based program sampling (NPS). An example device may obtain an assembly code of a program and an execution trace of the program, and divide the assembly code into a plurality of execution intervals. The device may construct a plurality of code graphs respectively corresponding to the plurality of execution intervals, and for each of the plurality of code graphs: generate a plurality of graph snapshots based on the code graph and the execution trace of the program; embed, by using a Graph Neural Network, the plurality of graph snapshots into a plurality of vectors; and aggregate the plurality of vectors into an execution embedding. The device may cluster the plurality of execution embeddings into a plurality of clusters and select representative execution intervals of the program based on the plurality of clusters for execution.

Claims (81)

1 . A computer-implemented method for program sampling, comprising:

obtaining an assembly code of a program and an execution trace of the program;

dividing the assembly code into a plurality of execution intervals, each execution interval corresponding to a portion of the assembly code;

constructing a plurality of code graphs respectively corresponding to the plurality of execution intervals;

for each code graph of the plurality of code graphs:

generating a plurality of graph snapshots based on the code graph and the execution trace of the program that correspond to different time points during an execution of the program, wherein generating each graph snapshot of the plurality of graph snapshots comprises fusing a subgraph of the code graph with dynamic states of the program from the execution trace of the program, and the fusing comprises adding or removing one or more nodes or edges of the code graph based on the dynamic states of the program at a given time point during the execution of the program;

embedding, by using a Graph Neural Network (GNN), the plurality of graph snapshots into a plurality of vectors; and

aggregating the plurality of vectors corresponding to the plurality of graph snapshots into an execution embedding to represent the execution interval corresponding to the code graph;

clustering the plurality of execution embeddings representing the plurality of execution intervals into a plurality of clusters; and

selecting representative execution intervals of the program based on the plurality of clusters for execution.

2 . The computer-implemented method of claim 1 , wherein the obtaining the assembly code of the program comprises:

compiling the program written in a high-level programming language into the assembly code of the program.

3 . The computer-implemented method of claim 1 , wherein the constructing the plurality of code graphs respectively corresponding to the plurality of execution intervals comprises, for each execution interval of the plurality of execution intervals:

identifying instructions and variables in assembly code in the execution interval;

constructing a backbone of a code graph by:

creating instruction nodes and variable nodes based on the instructions and variables;

connecting the instruction nodes and the variable nodes to represent a control flow and a data flow of the assembly code;

adding function nodes to the backbone of the code graph to represent functions that are implied in the assembly code; and

connecting the instruction nodes, variable nodes, and function nodes to form the code graph.

4 . The computer-implemented method of claim 3 , wherein the function nodes correspond to functions including memory reference functions.

5 . The computer-implemented method of claim 1 , wherein the generating the plurality of graph snapshots based on the code graph and the execution trace of the program comprises:

for a given graph node in the code graph, determining a memory depth based on a number of memory references visited along all code paths in the code graph that start from the given graph node;

performing a breadth-first search in the code graph starting from the given graph node constrained by the memory depth to obtain a subgraph of the code graph; and

adding intermediate nodes representing the dynamic states extracted from the execution trace to the subgraph to obtain the graph snapshot.

6 . The computer-implemented method of claim 1 , wherein the GNN is a graph attention network (GAT) comprising parameters jointly trained with a code path selection module and a memory address prediction module.

7 . The computer-implemented method of claim 6 , wherein the GAT is trained by:

feeding a training graph snapshot into the GAT for embedding, wherein the training graph snapshot corresponds to a ground truth execution trace;

obtaining, from the GAT, embeddings of function nodes in the training graph snapshot, wherein the function nodes correspond to memory reference functions in the training graph snapshot;

feeding the embeddings of the function nodes into the code path selection module to predict a code path in the training graph snapshots;

obtaining embeddings of memory addresses to be visited along the code path;

feeding the embeddings of the memory addresses into the memory address prediction module to predict next memory addresses to be visited along the code path;

obtaining prediction errors by comparing the predicted next memory addresses and the ground truth execution trace; and

adjusting parameters of the GAT, the code path selection module, and the memory address prediction module to minimize the prediction errors.

8 . The computer-implemented method of claim 6 , wherein the code path selection module comprises an attention layer and a weighted unsort segment sum layer for generating weights for code path candidates, wherein a code path candidate with a highest weight is selected as a predicted code path.

9 . The computer-implemented method of claim 6 , wherein after training, the GAT is deployed for embedding graph snapshots.

10 . The computer-implemented method of claim 1 , wherein clustering the plurality of execution embeddings of the plurality of execution intervals into the plurality of clusters comprises:

clustering the plurality of execution embeddings using K-means.

11 . The computer-implemented method of claim 1 , wherein the selecting representative execution intervals of the program based on the plurality of clusters comprises:

from one or more of the plurality of clusters, selecting one execution embedding from each of the plurality of clusters; and

selecting, from the program, one or more execution intervals that correspond to the one or more selected execution embeddings as the representative execution intervals.

12 . The computer-implemented method of claim 1 , further comprising:

executing the representative execution intervals of the program rather than executing an entirety of the program.

13 . A system comprising one or more processors and one or more non-transitory computer-readable memories coupled to the one or more processors, the one or more non-transitory computer-readable memories storing instructions that, when executed by the one or more processors, cause the system to perform operations comprising:

obtaining an assembly code of a program and an execution trace of the program;

dividing the assembly code into a plurality of execution intervals, each execution interval corresponding to a portion of the assembly code;

constructing a plurality of code graphs respectively corresponding to the plurality of execution intervals;

for each code graph of the plurality of code graphs:

generating a plurality of graph snapshots based on the code graph and the execution trace of the program that correspond to different time points during an execution of the program, wherein generating each graph snapshot of the plurality of graph snapshots comprises fusing a subgraph of the code graph with dynamic states of the program from the execution trace of the program, and the fusing comprises adding or removing one or more nodes or edges of the code graph based on the dynamic states of the program at a given time point during the execution of the program;

embedding, by using a Graph Neural Network (GNN), the plurality of graph snapshots into a plurality of vectors; and

aggregating the plurality of vectors corresponding to the plurality of graph snapshots into an execution embedding to represent the execution interval corresponding to the code graph;

clustering the plurality of execution embeddings representing the plurality of execution intervals into a plurality of clusters; and

selecting representative execution intervals of the program based on the plurality of clusters for execution.

14 . The system of claim 13 , wherein the generating the plurality of graph snapshots based on the code graph and the execution trace of the program comprises:

for a given graph node in the code graph, determining a memory depth based on a number of memory references visited along all code paths in the code graph that start from the given graph node;

performing a breadth-first search in the code graph starting from the given graph node constrained by the memory depth to obtain a subgraph of the code graph; and

adding intermediate nodes representing the dynamic states extracted from the execution trace to the subgraph to obtain the graph snapshot.

15 . The system of claim 13 , wherein the GNN is a graph attention network (GAT) comprising parameters jointly trained with a code path selection module and a memory address prediction module.

16 . The system of claim 15 , wherein the GAT is trained by:

feeding a training graph snapshot into the GAT for embedding, wherein the training graph snapshot corresponds to a ground truth execution trace;

obtaining, from the GAT, embeddings of function nodes in the training graph snapshot, wherein the function nodes correspond to memory reference functions in the training graph snapshot;

feeding the embeddings of the function nodes into the code path selection module to predict a code path in the training graph snapshots;

obtaining embeddings of memory addresses to be visited along the code path;

feeding the embeddings of the memory addresses into the memory address prediction module to predict next memory addresses to be visited along the code path;

obtaining prediction errors by comparing the predicted next memory addresses and the ground truth execution trace; and

adjusting parameters of the GAT, the code path selection module, and the memory address prediction module to minimize the prediction errors.

17 . The system of claim 15 , wherein the code path selection module comprises an attention layer and a weighted unsort segment sum layer for generating weights for code path candidates, wherein a code path candidate with a highest weight is selected as a predicted code path.

18 . The system of claim 13 , wherein the selecting representative execution intervals of the program based on the plurality of clusters comprises:

from one or more of the plurality of clusters, selecting one execution embedding from each of the plurality of clusters; and

selecting, from the program, one or more execution intervals that correspond to the one or more selected execution embeddings as the representative execution intervals.

19 . The system of claim 13 , wherein the operations further comprise:

executing the representative execution intervals of the program rather than executing an entirety of the program.

20 . A non-transitory computer-readable storage medium configured with instructions executable by one or more processors to cause the one or more processors to perform operations comprising:

obtaining an assembly code of a program and an execution trace of the program;

dividing the assembly code into a plurality of execution intervals, each execution interval corresponding to a portion of the assembly code;

constructing a plurality of code graphs respectively corresponding to the plurality of execution intervals;

for each code graph of the plurality of code graphs:

generating a plurality of graph snapshots based on the code graph and the execution trace of the program that correspond to different time points during an execution of the program, wherein generating each graph snapshot of the plurality of graph snapshots comprises fusing a subgraph of the code graph with dynamic states of the program from the execution trace of the program, and the fusing comprises adding or removing one or more nodes or edges of the code graph based on the dynamic states of the program at a given time point during the execution of the program;

embedding, by using a Graph Neural Network (GNN), the plurality of graph snapshots into a plurality of vectors; and

aggregating the plurality of vectors corresponding to the plurality of graph snapshots into an execution embedding to represent the execution interval corresponding to the code graph;

clustering the plurality of execution embeddings representing the plurality of execution intervals into a plurality of clusters; and

selecting representative execution intervals of the program based on the plurality of clusters for execution.

Assignments (1)
ASSIGNMENT OF ASSIGNOR'S INTEREST Recorded Oct 28, 2022
From: FANG, YUANWEI; CHEN, JIAN; CHEN, YEN-KUANG; XIE, YUAN
To: ALIBABA (CHINA) CO., LTD.
Reel/Frame 061583/0443 →
Continuity (2)
Provisional Application 63349578 · Jun 6, 2022
Related Publication 20230394300A1 · Dec 7, 2023
References Cited (75)
US 7813822B1 · Hoffberg · 2010 [cited by applicant]
US 9720403B2 · Power et al. · 2017 [cited by applicant]
US 9734169B2 · Redlich et al. · 2017 [cited by applicant]
US 9934364B1 · Kumar et al. · 2018 [cited by applicant]
US 10606949B2 · Zhu et al. · 2020 [cited by applicant]
US 11108809B2 · Johns et al. · 2021 [cited by applicant]
US 11348110B2 · Adjaoute · 2022 [cited by applicant]
US 11393250B2 · Mishra et al. · 2022 [cited by applicant]
US 11409587B2 · Bridges et al. · 2022 [cited by applicant]
US 11429934B2 · Demick et al. · 2022 [cited by applicant]
US 20090210447A1 · Moshe · 2009 [cited by applicant]
US 20150363294A1 · Carback, III et al. · 2015 [cited by applicant]
US 20160379309A1 · Shikhare · 2016 [cited by applicant]
US 20170212829A1 · Bales et al. · 2017 [cited by applicant]
US 20180247195A1 · Kumar et al. · 2018 [cited by applicant]
US 20180373986A1 · Rainwater · 2018 [cited by applicant]
US 20190265955A1 · Wolf · 2019 [cited by applicant]
US 20190378616A1 · Abrami et al. · 2019 [cited by applicant]
US 20200326934A1 · Tepper · 2020 [cited by examiner]
US 20210142233A1 · Masood et al. · 2021 [cited by applicant]
US 20210186329A1 · Tran · 2021 [cited by applicant]
Wunderlich et al., “SMARTS: Accelerating Microarchitecture Simulation via Rigorous Statistical Sampling”, Jun. 2003, Proceedings of the 30th Annual International Symposium on Computer Architecture (ISCA'03), 12 pages (Y… [cited by examiner]
Hamerly et al., “SimPoint 3.0: Faster and More Flexible Program Phase Analysis”, Sep. 2005, Journal of Instruction-Level Parallelism, vol. 7, 28 pages (Year: 2005). [cited by examiner]
Xu et al., “A Brief Survey of Program Slicing”, Mar. 2005, ACM SIGSOFt Software Engineering Notes, vol. 30 No. 2, 36 pages (Year: 2005). [cited by examiner]
Lu et al., “Program Classification Using Gated Graph Attention Neural Network for Online Programming Services”, Mar. 9, 2019, arXiv:1903.03804v1, 12 pages (Year: 2019). [cited by examiner]
Draelos, “Multi-label vs. Multi-class Classification: Sigmoid vs Softmax”, May 26, 2019, https://glassboxmedicine.com/2019/05/26/classification-sigmoid-vs-softmax/, 11 pages (Year: 2019). [cited by examiner]
Velickovic et al., “Neural Execution of Graph Algorithms”, Jan. 15, 2020, arXiv: 1910. 10593v2, 14 pages (Year: 2020). [cited by examiner]
Guo et al., “GRAPHSPY: Fused Program Semantic-Level Embedding via Graph Neural Networks for Dead Store Detection”, Nov. 18, 2020, arXiv:2011.09501v1, 9 pages (Year: 2020). [cited by examiner]
Flolid et al., “SimTrace: Capturing Over Time Program Phase Behavior”, Aug. 2020, 2020 IEEE International Symposium on Performance Analysis of Systems and Software (ISPASS), 3 pages (Year: 2020). [cited by examiner]
Farina, “A Crash Course in Assembly Language—The Basics of x86 Assembly for Reverse Engineering”, Mar. 26, 2021, https://medium.com/reverse-engineering-for-dummies/a-crash-course-in-assembly-language-695b07995b4d, 12 pa… [cited by examiner]
“Apache kafka,” https://kafka.apache.org/, retrieved on Nov. 4, 2022. [cited by applicant]
SPEC CPU® 2006, Standard Performance Evaluation Corporation, https://www.spec.org/cpu2006/, retrieved on Nov. 4, 2022. [cited by applicant]
“Synopsys DSO.ai,” Synopsys, https://www.synopsys.com/implementation-and-signoff/ml-ai-design/dso-ai.html, retrieved on Nov. 4, 2022. [cited by applicant]
“Valgrind User Manual,” Valgrind™ Developers, https://valgrind.org/docs/manual/bbv-manual.html, retrieved on Nov. 4, 2022. [cited by applicant]
Akram et al., “Validation of the gem5 Simulator for x86 Architectures,” 2019 IEEE/ACM Performance Modeling, Benchmarking and Simulation of High Performance Computer Systems (PMBS), Nov. 2019. [cited by applicant]
Allamanis et al., “Learning to Represent Programs with Graphs,” ICLR 2018, May 4, 2018. [cited by applicant]
Alon et al., “code2vec: Learning Distributed Representations of Code,” Oct. 30, 2018. [cited by applicant]
Ando, “SWQUE: A Mode Switching Issue Queue with Priority-Correcting Circular Queue,” Oct. 2019. [cited by applicant]
Awad et al., “STM: Cloning the spatial and temporal memory access behavior,” 2014 IEEE 20th International Symposium on High Performance Computer Architecture (HPCA), Feb. 2014. [cited by applicant]
Badr et al., “Mocktails: Capturing the memory behaviour of proprietary mobile architectures,” 2020 ACM/IEEE 47th Annual International Symposium on Computer Architecture (ISCA), 2020, downloaded on Jul. 28, 2020. [cited by applicant]
Bai et al., “Boom-explorer: Risc-v boom microarchitecture design space exploration framework,” 2021 IEEE/ACM International Conference On Computer Aided Design (ICCAD), Nov. 2021. [cited by applicant]
Bera et al., “Dspatch: Dual spatial pattern prefetcher,” Proceedings of the 52nd Annual IEEE/ACM International Symposium on Microarchitecture, Oct. 2019. [cited by applicant]
Bieber et al., “Learning to execute programs with instruction pointer attention graph neural networks,” 34th Conference on Neural Information Processing Systems (NeurIPS 2020), Oct. 23, 2020. [cited by applicant]
Binkert et al., “The gem5 simulator,” ACM SIGARCH Computer Architecture News, vol. 39, No. 2, May 2011. [cited by applicant]
Chen et al., “DWT: Decoupled Workload Tracing for Data Centers,” 2020 IEEE International Symposium on High Performance Computer Architecture (HPCA), Feb. 2020. [cited by applicant]
Choi et al., “Encoding musical style with transformer autoencoders,” International Conference on Machine Learning. PMLR, Jun. 30, 2020. [cited by applicant]
Dai et al., “Transformer-xl: Attentive language models beyond a fixed-length context,” Proceedings of the 57th Annual Meeting of the Association for Computational Linguistics, Jun. 2019. [cited by applicant]
Dinella et al., “Hoppity: Learning graph transformations to detect and fix bugs in programs,” ICLR 2020, Sep. 2019. [cited by applicant]
Haj-Ali et al., “Neurovectorizer: End-to-end vectorization with deep reinforcement learning,” Proceedings of the 18th ACM/IEEE International Symposium on Code Generation and Optimization, Jan. 2020. [cited by applicant]
Hamerly et al., “Using machine learning to guide architecture simulation,” Journal of Machine Learning Research 7, Feb. 2006. [cited by applicant]
Hamilton et al., “Inductive representation learning on large graphs,” 31st Conference on Neural Information Processing Systems (NIPS 2017), Sep. 10, 2018. [cited by applicant]
Hashemi et al., “Filtered runahead execution with a runahead buffer,” Proceedings of the 48th International Symposium on Microarchitecture, Dec. 2015. [cited by applicant]
Hashemi et al., “Learning memory access patterns,” International Conference on Machine Learning, Mar. 2018. [cited by applicant]
Jain et al., “Back to the future: Leveraging belady's algorithm for improved cache replacement,” 2016 ACM/IEEE 43rd Annual International Symposium on Computer Architecture (ISCA), IEEE, Jun. 2016. [cited by applicant]
Kipf et al., “Semi-supervised classification with graph convolutional networks,” International Conference on Learning Representations (ICLR), Feb. 2017. [cited by applicant]
Li et al., “Gated graph sequence neural networks,” International Conference on Learning Representations (ICLR'16), Sep. 22, 2017. [cited by applicant]
Lin et al., “A Deep Reinforcement Learning Framework for Architectural Exploration: A Routerless NoC Case Study,” 2020 IEEE International Symposium on High Performance Computer Architecture (HPCA), IEEE, Feb. 2020. [cited by applicant]
Luk et al., “Pin: Building Customized Program Analysis Tools with Dynamic Instrumentation,” Acm sigplan notices, vol. 40, No. 6, Jun. 2005. [cited by applicant]
Zangeneh et al., “BranchNet: Using Offline Deep Learning To Predict Hard-To-Predict Branches,” Aug. 2019. [cited by applicant]
Mirhoseini et al., “A graph placement methodology for fast chip design,” Nature, vol. 594, No. 7862, Jun. 9, 2021. [cited by applicant]
Panda et al., “Proxy benchmarks for emerging big-data workloads,” 2017 26th International Conference on Parallel Architectures and Compilation Techniques (PACT), IEEE, Apr. 2017. [cited by applicant]
Patil et al., “ELFies: executable region checkpoints for performance analysis and simulation,” 2021 IEEE/ACM International Symposium on Code Generation and Optimization (CGO), IEEE, 2021, downloaded on May 23, 2021. [cited by applicant]
Patil et al., “Pinplay: a framework for deterministic replay and reproducible analysis of parallel programs,” Proceedings of the 8th annual IEEE/ACM international symposium on Code generation and optimization, Apr. 2010. [cited by applicant]
Perelman et al., “Using simpoint for accurate and efficient simulation,” SIGMETRICS'03, Jun. 2003. [cited by applicant]
Renda et al., “DiffTune: Optimizing CPU Simulator Parameters with Learned Differentiable Surrogates,” Dec. 5, 2020. [cited by applicant]
Shi et al., “A hierarchical neural model of data prefetching,” Proceedings of the 26th ACM International Conference on Architectural Support for Programming Languages and Operating Systems, Apr. 2021. [cited by applicant]
Shi et al., “Learning Execution through Neural Code Fusion,” ICLR 2020, Mar. 11, 2020. [cited by applicant]
Trask et al., “Neural Arithmetic Logic Units,” Aug. 1, 2018. [cited by applicant]
Veličković et al., “Graph Attention Networks,” Feb. 2018. [cited by applicant]
Wei et al., “LambdaNet: Probabilistic Type Inference using Graph Neural Networks,” Apr. 2020. [cited by applicant]
Ying et al., “Hierarchical Graph Representation Learning with Differentiable Pooling,” Feb. 2019. [cited by applicant]
Zhang et al., “An End-to-End Deep Learning Architecture for Graph Classification,” Apr. 2018. [cited by applicant]
Zhou et al., “GDP: Generalized Device Placement for Dataflow Graphs,” Sep. 28, 2019. [cited by applicant]
First Office Action for Chinese Application No. 202310413817.0 mailed on Jul. 28, 2026. [cited by applicant]
Hamerly et al., “SimPoint 3.0: Faster and More Flexible Program Analysis”, Dec. 31, 2005. [cited by applicant]