text stringlengths 128 2.05k |
|---|
XFGs (e.g., Fig. 2(d) ) are directed multigraphs, where two nodes can be connected by more than one edge. XFG nodes can either be variables or label identifiers (e.g., basic block, function name), appearing in the figure as ovals or rectangles respectively. Correspondingly, an edge either represents data-dependence (in... |
XFG Construction We generate XFGs incrementally from LLVM IR, as follows: 1. Read LLVM IR statements once, storing function names and return statements. |
2. Second pass over the statements, adding nodes and edges according to the following rule-set: (a) Data dependencies within a basic block are connected. |
(b) Inter-block dependencies (e.g., [MATH] -expressions) are both connected directly and through the label identifier (statement-less edges). |
(c) Identifiers without a dataflow parent are connected to their root (label or program root). It follows that XFGs create paths through dataflow as well as branches, loops, and functions (including recursion). Owing to the two passes, as well as the linear-time construction of LLVM IR |
, XFGs are constructed in [MATH] for a program with [MATH] SSA statements. This is especially valuable when learning over large code corpora, such as Tensorflow. |
External Code Calls to external code (e.g., libraries, frameworks) can be divided into two categories: statically- and dynamically-linked. If the code is accessible during compilation (header-only frameworks and static libraries), LLVM IR is available and the statements are traversed as part of the XFG. In the dynamic ... |
inst2vec : Embedding Statements in Continuous Space With XFGs providing a notion of context, we can now train an embedding space for individual statements. To support learnability, desiderata for such a space include: (a) statements that are in close proximity should have similar artifacts on a system (i.e., use the sa... |
, following preprocessing to limit the vocabulary size. 5.1 Statement Preprocessing and Training Preprocessing First, we filter out comments and metadata from statements. Then, identifiers and immediate values (numeric constants, strings) are replaced with %ID and <INT/FLOAT/STRING> respectively, where immediate values... |
Dataset Table summarizes the code corpora and vocabulary statistics of the inst2vec dataset. We choose corpora from different disciplines, including high-performance computing, benchmarks, operating systems, climate sciences, computer vision, machine learning (using Tensorflow’s own source code), and synthetically-gene... |
and Flang , using compilation flags from the original code (if available) and randomly chosen compiler optimization (e.g., -ffast-math ) and target architecture flags. |
For the synthetic corpus, we use both C code and the Eigen C++ library. In particular, random linear algebra operations are procedurally |
Setup and Training Given a set of XFGs created from the LLVM IR files, we generate neighboring statement pairs up to a certain context size, following the skip-gram model |
. A context of size [MATH] includes all statement pairs that are connected by a path shorter or equal to [MATH] To obtain the pairs, we construct a dual graph in which statements are nodes, omitting duplicate edges. Following this process, we discard statements that occur less than 300 times in the dataset, pairs of id... |
We train inst2vec with an embedding dimension of 200 for 5 epochs using Tensorflow . The Adam optimizer is used with the default published hyperparameters and softmax cross-entropy loss. |
5.2 Evaluation Clustering Fig. depicts the t-SNE plots for trained inst2vec spaces with different XFG context sizes, colored by statement and data type (legend in Appendix ). In the plots, we see that both a context size of 1 statement in each direction (Fig. 6(a) ) or 3 statements (Fig. 6(c) ) generate large, multi-ty... |
An example of a semantically -similar statement cluster can be found in data structures. In particular, the top-5 nearest neighbors of operations on the complex data type “ std::complex<float> ” include “ 2 x float ” (i.e., a vector type). In fact, LLVM IR represents the complex data type as {float, float} , so this pr... |
Analogies and Tests We also evaluate inst2vec by automatically generating a list of statement analogies (“a” is to “b” as “c” is to “?”, or “ a:b; c:? ”) that appear in our vocabulary using the LLVM IR syntax. We then use the embeddings to find the result by computing a-b+c and asking whether the result is in the top-5... |
of the form [MATH] to test whether statements that use different resources are further away than those who use the same. Table shows the analogy and test results for inst2vec trained on XFG as well as on CFG (control flow-only) and DFG (data flow-only) for different context sizes. The analogies are divided into differe... |
%ID = add i64 %ID, %ID : %ID = fadd float %ID, %ID; %ID = sub i64 %ID, %ID :? %ID = fsub float %ID, %ID and a data structure analogy: |
%ID = extractvalue { double, double } %ID, 0 : %ID = extractelement <2 x double> %ID, <TYP> 0; %ID = extractvalue { double, double } %ID, 1 :? %ID = extractelement <2 x double> %ID, <TYP> 1 |
The results confirm that over all scores, a context size of 2 is the best-performing configuration, and show that the XFG representation is more complete and leads to better embeddings than taking into account control or data flow alone. |
Code Comprehension Experiments In this section, we evaluate inst2vec on three different tasks, comparing with manually-extracted features and state-of-the-art specialized deep learning approaches. Throughout all tasks, we use the same neural network architecture and our pre-trained embedding matrix from Section , which... |
Training Our recurrent network (see schematic description in the Appendix ) consists of an inst2vec input with an XFG context size of 2, followed by two stacked LSTM |
layers with 200 units in each layer, batch normalization , a dense 32-neuron layer with ReLU activations, and output units matching the number of classes. The loss function is a categorical cross-entropy trained using Adam |
with the default hyperparameters. Additionally, for the compute device mapping and optimal thread coarsening factor prediction tasks, we train the LLVM IR statements with the immediate values that were stripped from them during preprocessing (see Section ). Further details are given in Appendix |
Datasets The algorithm classification task uses the POJ-104 dataset , collected from a Pedagogical Open Judge system. The dataset contains 104 program classes written by 500 different people (randomly selected subset per class). For the compute device mapping and optimal thread coarsening factor prediction tasks, we us... |
6.1 Algorithm Classification Using inst2vec , we construct an RNN that reads embedded source code and outputs a predicted program class. We compare our approach with Tree-Based CNNs (TBCNN) |
, the best-performing algorithm classifier in the POJ-104 dataset. TBCNN constructs embeddings from Astract Syntax Tree nodes of source code, and employs two specialized layers: tree convolutions and dynamic pooling. Their network comprises 5 layers, where convolution and fully connected layers are 600-dimensional. Our... |
, splitting the dataset 3:1:1 for training, validation, and testing. To compile the programs successfully, we prepend #include statements to each file. Data augmentation is then applied on the training set by compiling each file 8 times with different flags ( -O{0-3} -ffast-math ). |
Table compares inst2vec (trained for 100 epochs) with the reported results of Mou et al. , which contain TBCNN as well as a 600-cell RNN and a manual feature extraction approach (Surface Features). The results show that inst2vec sets a new state-of-the-art with a 13.8 % decrease in error, even though the dataset used t... |
6.2 Heterogeneous Compute Device Mapping Next, we use Neural Code Comprehension to predict whether a given OpenCL program will run faster on a CPU (Intel Core i7-3820) or a GPU (AMD Tahiti 7970 and NVIDIA GTX 970) given its code, input data size, and work-group size (i.e., number of threads that work in a group with sh... |
, removing their specialized OpenCL source rewriter and replacing their code token embeddings with our XFGs and inst2vec . We concatenate the data and work-group sizes to the network inputs, and train with stratified 10-fold cross-validation. We repeat the training [MATH] times with random initialization of the network... |
In Table inst2vec and inst2vec-imm (i.e., with immediate value handling) are compared with a manual code feature extraction approach by Grewe et al. |
and DeepTune , in terms of runtime prediction accuracies and resulting speedup. The baseline for the speedup is a static mapping, which selects the device that yields the best average case performance over all programs in the data set: in the case of AMD Tahiti versus Intel i7-3820, that is the CPU and in the case of N... |
6.3 Optimal Thread Coarsening Factor Prediction Our third example predicts the best-performing thread coarsening factor , a measure of the amount of work done per GPU thread, for a given OpenCL code. We again compare the achieved speedups of inst2vec with manual features |
, DeepTune, and DeepTune with transfer learning applied from the task in Section 6.2 (denoted by DeepTune-TL). Possible values for the coarsening factor are [MATH] (baseline for speedups), [MATH] [MATH] [MATH] [MATH] , and [MATH] . The results in Table show that while inst2vec yields better speedups than DeepTune-TL in... |
Conclusion In this paper, we have empirically shown that semantics of statements can be successfully recovered from their context alone. This recovery relies both on proper granularity, where we propose to use filtered LLVM IR instructions; and on the grouping of statements, for which we use a mixture of data- and cont... |
With this work, we attempt to pave the way towards mechanized code comprehension via machine learning, whether the code was authored by a human or automatically-generated. Further research could be conducted in various directions. Rather than directly using statements, the representation may be refined using part-based... |
inst2vec can also be used as a basis for neural code interpretation, using a modified Differentiable Neural Computer to enable execution of arbitrary code over DNNs. |
Acknowledgments We wish to thank Theodoros Theodoridis, Kfir Levy, Tobias Grosser, and Yunyan Guo for fruitful discussions. The authors also acknowledge MeteoSwiss, and thank Hussein Harake, Colin McMurtrie, and the whole CSCS team for granting access to the Greina machines, and for their excellent technical support. T... |
Appendix A Statement Categories for inst2vec Clustering Results Table presents the mapping from colors to statement categories that appear in Fig. . The following rules apply to the categories in the table: |
1. type operation generally refers to an operation, a function call, or the definition of a function, that returns an instance of type |
2. type* refers to a pointer of type . Asterisks could be chained for pointers-to-pointers. 3. <d x type> is a vector of elements of type |
4. [d x type] is an array of elements of type 5. struct/class denotes an aggregate structure (e.g., C struct ) of multiple types, e.g., {type_1, type_2, ..., type_n} in LLVM IR. |
6. floating point can refer to either single- or double-precision floating point values. 7. int can refer to an integer of any bit-width. |
8. void categories ( call void invoke void ) refer to calls/invocations of functions that have no return value. 9. conversion operations denote type conversions within LLVM, which do not necessarily translate into code. |
10. load function pointer store function pointer refer to instructions that read or write function pointers into memory, respectively. |
Appendix B Neural Code Comprehension: Network Architecture Fig. depicts the neural network architecture used for the high-level tasks in this paper. Below we describe each of the underlying layers in the network. |
Input and Embedding Lookup As an input, the Neural Code Comprehension architecture accepts programs as sequences of LLVM IR statements. Each statement is represented through its corresponding embedding vector, and for statements that are not in the inst2vec vocabulary, they are assigned the embedding vector correspondi... |
Program Characterization The sequence of statement embedding vectors is passed to two layers of Long Short-Term Memory (LSTM) cells. This program characterization layer transforms an input sequence of arbitrary length into a fixed-length vector that captures the properties of the processed program. |
Auxiliary Input Concatenation (optional) Additional data may optionally be concatenated with the output of the two-layer LSTM at this point. This allows information that is only available at runtime (e.g., hardware parameters or data size) to be taken into account in the predictive modeling. |
Batch normalization is performed, and then the vector output of program characterization goes through a [MATH] -unit fully connected dense layer with rectifier (ReLU) activations |
. Finally, the output layer is another fully-connected layer, which features a number of units equal to the number of possible output categories. The output is given by a sigmoid activation function (output between [MATH] and [MATH] ), where the largest activation corresponds to the model’s prediction. |
Appendix C Training NCC with Immediate Values: Method Description In the transformations applied to raw LLVM IR code before inst2vec training, the statements are stripped of their immediate values and are replaced by tokens indicating the value type: <INT> <FLOAT> <STRING> (see Section for further detail). The purpose ... |
“naïve concatenation” ( concat_naïve Instead of feeding the model with the embedding vector of a statement alone (see layer [MATH] , above), embedding vectors are first concatenated with their corresponding immediate values. The first set of LSTM cells accept an input of size embedding dimension + length of list of imm... |
“concatenate then embed” ( concat_embed This method introduces an additional embedding step: statement embedding vectors are first concatenated with their corresponding immediate values. They then pass through a fully-connected layer, which reduces the layer dimension from input dimension = embedding dimension + length... |
“extract then concatenate” ( extract_concat In this method, immediate values are never coupled back directly to the statement from which they were extracted. Rather, the sequence of immediate values of the entire program undergoes a separate processing pipeline, before being concatenated with the output of the program ... |
Appendix D Training NCC with Immediate Values: Exhaustive Results Tables and present the results for the heterogeneous device mapping and optimal thread coarsening factor tasks, obtained with the different modes of immediate value handling described in Appendix . The column ’ignore’ presents the results for the simples... |
# Source: arxiv 1806.07529 # Title: Prevalence of Delay Embeddings with a Fixed Observation Function # Sections: all # Downloaded: 2026-03-02T08:51:09.155104+00:00 |
Prevalence of Delay Embeddings with a Fixed Observation Function ( ) Abstract Let [MATH] [MATH] , be a dynamical system with [MATH] being a diffeomorphism. Although the state vector |
[MATH] is often unobservable, the dynamics can be recovered from the delay vector [MATH] , where [MATH] is the scalar-valued observation function and [MATH] is the embedding dimension. The delay map is an embedding for generic [MATH] , and more strongly, the embedding property is prevalent. We consider the situation wh... |
being the projection to the first coordinate. However, we allow polynomial perturbations to be applied directly to the diffeomorphism [MATH] thus mimicking the way dynamical systems are parametrized. We prove that the delay map is an embedding with probability one with respect to the perturbations. Our proof introduces... |
Department of Mathematics, University of Michigan (raymundo/divakar@umich.edu). Introduction Let [MATH] be a dynamical system. If [MATH] is a scalar valued observation function, the delay map is given by |
[EQUATION] The question of when [MATH] is an embedding was considered by Aeyels and Takens . Suppose that [MATH] but with the dynamics confined to an invariant submanifold of dimension |
[MATH] . Alternatively, we may assume [MATH] where [MATH] is a manifold of dimension [MATH] . Based on an analogy to Whitney embedding |
, we may expect [MATH] to be an embedding for generic [MATH] for embedding dimension [MATH] Here genericity is with respect to the space of functions [MATH] under [MATH] topology with [MATH] |
Sauer et al introduced a new point of view, supported by deep ideas, into the theory of delay embeddings. If [MATH] and [MATH] is a multi-index, denote the monomial [MATH] by [MATH] . Instead of assuming the observation function [MATH] to be any [MATH] function, Sauer et al take the observation function to be the sum o... |
[MATH] . Proofs of genericity rely on “bump” functions or [MATH] functions with compact support. Although the device of bump functions is of much utility in differential topology |
bump functions hardly ever arise in applications. In contrast, physical models often use polynomials. Thus, limiting the perturbations to a finite linear combination of polynomials is a welcome shift in point of view. |
A property is generic in a Baire space if it holds for a countable intersection of open and dense sets. A generic set is always dense but it may be of probability zero (in a reasonable sense). For example, generic subsets of [MATH] of probability zero may be constructed easily. Thus, it may be questioned whether the co... |
Sauer et al answered that question by introducing the notion of prevalence. To say that delay embeddings are prevalent is equivalent to saying that the delay map is an embedding for almost every linear combination of polynomials. If probabilities are defined by normalizing the Lebesgue measure, we may say that the dela... |
Suppose [MATH] and [MATH] . For [MATH] to be an injection, we must have [MATH] whenever [MATH] . A major difficulty in the proof of injectivity arises in handling points [MATH] but with overlapping orbits. For example, we may have [MATH] or [MATH] Related difficulties arise in handling periodic points and in the proof ... |
introduced several key ideas for handling these difficulties. However, there is a minor gap in their proof. In section 4, we fix that gap and show that earlier mathematical treatments have serious deficiencies. Therefore, proofs prior to Sauer et al cannot be accepted. |
The proof of Sauer et al is quite informal. We give a more formally precise development of their ideas in sections 2 and 3. Later, we consider the case where the observation map is fixed at [MATH] , with [MATH] being the projection to the first coordinate and with polynomial perturbations applied directly to [MATH] . I... |
From section 5 onwards, we treat the case where [MATH] and [MATH] itself is perturbed by polynomials. There are two main motivations for considering this case. First, from a purely aesthetic point of view, it is desirable to make the theory of delay embeddings depend upon the dynamics and not the observation function. ... |
The main technical novelty in our approach is related to the concept of Lebesgue points. Our delay embedding theorem for the [MATH] |
case requires [MATH] , although our earlier work suggests [MATH] . In the concluding section, we express the hope that the technique of Lebesgue points may prove useful in obtaining prevalence versions of some classical results in dynamical systems theory. In that regard, we mention the extensions of delay embedding th... |
. A more complete account of other mathematical investigations in embedding theory may be found in the introduction to our earlier work |
Transfer of volume A key idea in the work of Sauer et al is to transfer volumes from embedding space to parameter space. For an example of what we mean by transfer of volume, suppose [MATH] is a square matrix. Then a volume equal to [MATH] in the range is transferred to [MATH] in the domain. |
Suppose [MATH] is a [MATH] function with [MATH] . Here [MATH] is the space of parameters and we will denote a point in parameter space by [MATH] or [MATH] , with the understanding that [MATH] (or [MATH] )is a column vector. The transfer of volume is carried out with fixed [MATH] Thus, the dependence of [MATH] on |
[MATH] , which will be nonlinear, does not come up in the transfer of volume argument. When the map [MATH] is fixed and only the observation function is parametrized, [MATH] is linear in the parameters |
[MATH] . The embedding space is [MATH] and the dimension [MATH] of this space is of much importance. The rank of [MATH] is mainly constrained by [MATH] because [MATH] , and the rank determines how much volume (or how little, with lesser the better) is transferred from embedding space to parameter space. |
In the following lemma and later we refer to [MATH] where [MATH] is the Lebesgue measure, as the probability of [MATH] relative to [MATH] (both sets are assumed to be measurable). Measure will always refer to Lebesgue measure. The following lemma transfers the volume of a ball of radius [MATH] in [MATH] |
to parameter space. All norms in this paper are spectral or [MATH] norms. Lemma 1 Let [MATH] be a linear (affine) map from [MATH] to [MATH] with [MATH] being a [MATH] matrix. Suppose the first |
[MATH] singular values of [MATH] are at least as great as [MATH] Then the measure of the set [EQUATION] is less than or equal to |
[EQUATION] and the probability of [MATH] relative to [MATH] is less than or equal to [EQUATION] Proof. Suppose [MATH] are the right singular vectors, [MATH] |
are the left singular vectors, and [MATH] the singular values of [MATH] . (see ). Let [MATH] and [MATH] For [MATH] [MATH] implies that [MATH] |
and therefore [MATH] Thus, the coefficient [MATH] must lie in an interval of measure less than [MATH] for [MATH] For [MATH] [MATH] |
implies that [MATH] must vary inside the interval [MATH] whose length is [MATH] Therefore, the volume of the set ( 2.1 ) is bounded above by [MATH] which simplifies to ( 2.2 ). |
For the statement about the probability of [MATH] relative to [MATH] , we divide ( 2.2 by [MATH] , where [MATH] is the volume of the unit sphere in [MATH] , to obtain |
[EQUATION] The proof is completed using [MATH] Lemma shows how a volume [MATH] in embedding space is transferred to a probability relative to [MATH] |
in parameter space. The transferred probability is proportional to [MATH] , and therefore, as the rank [MATH] increases, the probability becomes smaller. |
To obtain prevalence with the observation function fixed and the map parametrized, we will rely on the following nonlinear transfer of volume lemma. When the previous Lemma |
is applied, [MATH] will be a Lipshitz constant. When the following lemma is applied, [MATH] will be a Lipshitz constant as well as a bound on the quadratic remainder term in a Taylor series. |
Lemma 2 Suppose [MATH] is a [MATH] function, with the Taylor series [MATH] We assume that both [MATH] and [MATH] are defined for [MATH] and that [MATH] We also assume that the first [MATH] singular values of [MATH] |
are at least as great as [MATH] . Then the probability of [MATH] relative to [MATH] is less than or equal to [EQUATION] for [MATH] |
Proof. If [MATH] and [MATH] then [MATH] Therefore, [MATH] The proof is completed by applying the previous lemma with [MATH] and [MATH] |
Applications of Lemmas and will require us to get a handle on singular values. We will turn to that in the next section. Before doing so, we recapitulate an elegant argument of Sauer et al |
. This argument, although elementary, gives a good idea of the general approach when the observation function is parametrized. Suppose [MATH] is a smooth sub-manifold or even a fractal set of box counting dimension [MATH] and with compact closure that is a subset of [MATH] . Let the embedding dimension be [MATH] . If [... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.