Circuit netlist simulation acceleration optimization method based on visual Transform
Through the sparse matrix storage format classification model based on Vision Transformer, the problem of slow sparse matrix vector operation speed in circuit simulation is solved, efficient classification and storage format selection of large-dimensional circuit netlist matrices are achieved, and the simulation speed is significantly improved.
Patent Information
- Application Number
- CN202211390949.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-07
- Publication Date
- 2024-10-22
- Estimated Expiration
- 2042-11-07
AI Technical Summary
Existing technology is difficult to effectively accelerate sparse matrix vector operations in circuit simulation. Especially in large memory circuit simulation, traditional methods cannot select the optimal sparse matrix storage format, resulting in limited simulation speed.
A machine learning method based on the Vision Transformer model is used to convert the sparse matrix into a grayscale image. Through data enhancement and feature extraction, a sparse matrix storage format classification model is constructed, and the most suitable storage format is selected to accelerate sparse matrix multiplication operations.
It significantly improves the classification accuracy and simulation acceleration effect of large-dimensional circuit netlist matrices, which is better than traditional methods. It can select the best storage format under large-scale data sets and significantly improve the simulation speed.
Smart Images

Figure CN115879404B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of circuit simulation calculation acceleration, and in particular to a circuit netlist simulation acceleration optimization method based on visual Transform. Background Art
[0002] During the transient simulation of transistor-level circuits, the simulator needs to establish differential equations based on the circuit connection relationship and in combination with the KCL and KVL theorems, and then solve the discretized equations, outputting the simulation results of voltage and current at each step. Each step in the transient simulation involves a large number of matrix-vector operations. For example, the calculation of current output requires the calculation and summation of many branch currents. Matrix-vector operations take up a considerable proportion of the simulation time in the entire simulation, especially for the fast circuit simulator (FastSPICE) for memory circuits. Therefore, accelerating matrix-vector operations can directly improve the simulation speed of the circuit.
[0003] The size of the matrix of the circuit equation is proportional to the number of nodes in the circuit. For example, the dimension of a large memory circuit (DRAM, Flash, SRAM, etc.) can reach more than 10 million. Storing such a high-dimensional matrix in the form of an ordinary two-dimensional array will consume a huge amount of memory. Since each node of the circuit is usually connected to only a few nodes, the circuit equation matrix is usually a sparse matrix with high sparsity. The unique storage method of sparse matrices only contains non-zero elements in the matrix, which can greatly reduce the memory consumption and provide the possibility of storing high-dimensional matrices. The matrix-vector operations of sparse matrices are slightly different from ordinary matrix-vector operations, which has a significant impact on the overall operation speed.
[0004] Electronic circuit simulation generates a large number of sparse matrices. Traditional methods for accelerating sparse matrix calculations are mainly to accelerate the calculation process through parallelism and instruction optimization, ignoring the impact of sparse matrix storage formats. There are also methods that convert sparse matrices into images and then classify the storage formats. With the emergence of DNN and CNN, acceleration after image classification is possible.
[0005] Sparse Matrix-Vector Multiplication (SpMV) is a widely used computation kernel in many applications. There are many different implementations of SpMV using different processors and algorithms. The performance of different SpMV implementations varies greatly. Without performance analysis, it is basically difficult to select the best performance implementation for a given sparse matrix and a given platform. Sedaghati et al. (Naser Sedaghati, Te Mu, Louis-Noel Pouchet, Srinivasan Parthasarathy, and P. Sadayappan. 2015. Automatic Selection of Sparse Matrix Representation on GPUs. In Proceedings of the 29th ACM on International Conference on Supercomputing (ICS'15). Association for Computing Machinery, New York, NY, USA, 99–108.) selected the best sparse matrix storage format for SpMV based on the sparse matrix data structure characteristics obtained by analysis, using the machine learning method of decision tree classifier. However, their data set is limited and from a single source, and the selected matrices are all matrices of small dimensions, which do not meet the ultra-large dimensional requirements of circuit matrices; Cui (H. Cui, S. Hirasawa, H. Takizawa and H. Kobayashi," A Code Selection Mechanism Using Deep Learning," 2016IEEE 10th International Symposium on Embedded Multicore / Many-coreSystems-on-Chip (MCSOC), 2016, pp.385-392.) used CNN to filter and classify data on CPU and GPU respectively, but the accuracy of its screening results was low, only 54%, and the dimension of the selected matrix was also small, which did not meet the situation that the dimension of the circuit matrix was generally large.
[0006] In view of this, this paper proposes a machine learning intelligent optimization method based on the VIT (Vision transformer) model. Compared with CNN, it can better extract global features and has high classification accuracy in the case of large-scale data sets. It is used to select the SpMV code that best suits a given matrix, thereby achieving the purpose of circuit simulation calculation acceleration. The present invention aims to provide a circuit netlist simulation acceleration optimization method based on visual transformer. Summary of the invention
[0007] The problem to be solved by the present invention is to pass the sparse matrix netlist image into the model, optimize the classification of the netlist storage format, and accelerate the calculation of sparse matrix multiplication by selecting a suitable storage format, thereby realizing simulation acceleration of the circuit simulator.
[0008] The present invention is achieved by at least one of the following technical solutions.
[0009] A circuit netlist simulation acceleration optimization method based on visual Transform includes the following steps:
[0010] Acquire a data set, where the data in the data set includes a circuit netlist sparse matrix;
[0011] Matrix visualization: Convert the sparse circuit netlist matrix into a grayscale image and standardize the image size, while expanding the number of training sets through data augmentation;
[0012] Build a sparse matrix storage format classification model based on Vision Transformer;
[0013] Set the learning strategy and loss function in the training phase, use the training set to train the constructed sparse matrix storage format classification model, and use the test set to test the training effect.
[0014] Port the trained model to the Fastspice circuit simulator.
[0015] Furthermore, in step S2, the image size is normalized by mapping the matrix values to 0-255 and compressing the size to a uniform image_size.
[0016] Furthermore, the matrix-imaged data is preprocessed as follows:
[0017] d) Feature segmentation: The sparse matrix grayscale image is a single-channel two-dimensional image. After compressing the matrix to image_size*image_size, the input image is segmented into n single-channel images according to the size of patch_size;
[0018] e) Feature embedding: Expand the image blocks, flatten each image block by patch_size*patch_size*1, and add a learnable token to get embedded patches;
[0019] f) Position coding: superimpose a position code E on the image block pos .
[0020] Furthermore, the matrix compression of step a) includes:
[0021] All negative values are taken as their absolute values, and the remaining non-zero points are scaled according to the following formula:
[0022]
[0023] Among them, i and j represent matrix value indexes, and p i,j represents the value of the matrix i row and j column, p max Represents the maximum non-zero value of the current matrix. i,j,gray Represents the scaling value of row i and column j.
[0024] Furthermore, the sparse matrix storage format classification model based on Vision Transformer adds a CNN layer after the multi-head self-attention layer in the original Transformer Encoder to capture the local features of the sparse matrix, and finally inputs the obtained token with position encoding information into the MLP module for classification.
[0025] Furthermore, the grayscale image is bilinearly interpolated to set its size to image_size*image_size. After selecting labels for the circuit netlist matrix, the labels of the grayscale image samples corresponding to the netlist matrix are set to 0 to 4 categories, namely: COO, CSR, CSC, ELL, BSR. The labels are used for subsequent image classification.
[0026] Furthermore, the Vision Transformer-based sparse matrix storage format classification model includes a Transform Encoder module; the Transform Encoder module includes a multi-head self-attention layer, a CNN layer, and a multi-layer perception layer;
[0027] Furthermore, after the segmented circuit matrix grayscale image is concatenated with the position code, the global features are learned through the multi-head self-attention layer, and then passed to the CNN layer to learn the local features after normalization. Finally, it enters the MLP module for residual and outputs (image_size / patch_size)+1 token, and token 0 is taken out for subsequent module classification.
[0028] Furthermore, the spatial nodes between two nodes in the local spatial dimension are obtained through the multi-head self-attention layer, and weighted average is performed. The calculation formula is as follows:
[0029]
[0030]
[0031] Where Q, K, and V are the query matrix, X represents the feature tensor of the data, the keyword matrix, and the value matrix, respectively. is the scaling factor, d k represents the dimension of k, softmax represents the softmax function, W q , W k , W v They are query, key, and value weight matrices respectively;
[0032] Then use the following formula to calculate the multi-head self-attention mechanism composed of multiple self-attention mechanisms:
[0033] MultiHead(Q,K,V)=Concat(head1,...,head n )W 0
[0034] Among them head i =Attention(QW i Q ,KW i K ,VW i V ), W i Q is the query weight matrix of the ith head, W i K is the keyword weight matrix of the ith head, W i V is the value weight matrix of the i-th head, X represents the feature tensor of the data, Concat represents the concatenation of the feature tensors, and head i is the result of the i-th self-attention mechanism.
[0035] Furthermore, the trained Vision Transformer-based sparse matrix storage format classification model is used in the Fastspice simulator to generate the underlying circuit netlist matrix after the netlist generated during the simulation process. The storage format of the circuit netlist matrix is classified, and the best storage format of the netlist is selected. The matrix decomposition and solution process are performed when the format is input into the simulator.
[0036] Compared with the prior art, the present invention has the following beneficial effects:
[0037] The present invention adopts the VIT model for classification, which improves the classification accuracy and has obvious classification effect on large-dimensional circuit netlist matrices. When the existing traditional simulation solver only uses CSC and CSR formats for solving, format pre-classification is performed to accelerate the solving process. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] Figure 1 A flow chart of a circuit simulator acceleration calculation method proposed by the present invention;
[0039] Figure 2 A schematic diagram of a flow chart of a sparse matrix format selection model proposed by the present invention;
[0040] Figure 3 A schematic diagram of a Transformer network structure selected for a sparse matrix format proposed by the present invention;
[0041] Figure 4 This is a schematic diagram of a novel Transformer Encoder structure combined with a CNN module proposed in the present invention;
[0042] Figure 5 A schematic diagram of a process for screening sparse matrix data according to an embodiment of the present invention. DETAILED DESCRIPTION
[0043] In order to make the objectives, technical solutions and advantages of the present invention more clear, the present invention will be further described in detail below with reference to the accompanying drawings.
[0044] Example 1
[0045] A circuit netlist simulation acceleration optimization method based on visual Transform includes the following steps:
[0046] S1. Get a data set. The data set is a FastSPICE circuit netlist sparse matrix provided by the University of Florida and ProLiant. The University of Florida sparse matrix set selects matrices with Num Rows ≥ 1000. The matrices provided by the company are all circuit simulation matrices with matrix dimensions > 10000. The default storage format is COO. Multiply each matrix with a matrix filled with 1 in different formats and the same dimension, that is, matrix (format COO) * unit matrix (dimension 1×N), and calculate the time taken for the multiplication. Because the number of multiplication calculations in the Fastspice simulator is generally required to be less than 15, the multiplication is repeated for 15 rounds and its execution time COOtime is taken. The same is true for the other formats. Select the matrix format with the fastest multiplication speed among all the formats of the matrix as the label, such as Figure 5 shown.
[0047] S2. Matrix visualization: Convert the circuit netlist sparse matrix into an image. Set the maximum value of the matrix to 255, take the absolute value of all negative values, and scale the remaining non-zero points according to the following formula:
[0048]
[0049] Among them, i and j represent matrix value indexes, and p i,jrepresents the value of the matrix i row and j column, p max Represents the maximum non-zero value of the current matrix. i,j,gray Represents the scaling value of row i and column j.
[0050] In order to unify the subsequent sample input size, the grayscale image is bilinearly interpolated to set the size to image_size*image_size for subsequent processing. The sample label is the corresponding optimal storage format classification such as COO, CSR, CSC, ELL, BSR. The sparse matrix storage format type is not described here, and is marked as 0 to 4 categories respectively. At the same time, the number of training sets is expanded through data enhancement.
[0051] S3, build a sparse matrix storage format classification model based on Vision Transformer;
[0052] The sparse matrix storage format classification model based on Vision Transformer is improved from the original VIT model. A CNN layer is added after the multi-head self-attention layer in the original Transformer Encoder, such as Figure 4 As shown in the figure, it is used to capture the local features of the sparse matrix, and finally the obtained token with position encoding information is input into the MLP module for classification.
[0053] The sparse matrix storage format classification model based on Vision Transformer in this embodiment includes a Transformer Encoder module and a classifier, and its structure is as follows: Figure 3 As shown in the figure, the TransformerEncoder module adds a CNN layer after the multi-head self-attention layer in the original Transformer Encoder to extract local features, and finally passes it to the MLP module for classification.
[0054] S4, set the learning strategy and loss function in the training phase, use the training set to train the constructed VisionTransformer network, and use the test set to test the training effect, such as Figure 3 As shown;
[0055] The data input includes the following:
[0056] Feature segmentation: The sparse matrix grayscale image is a single-channel two-dimensional image. After compressing the matrix to image_size*image_size, the input image is segmented into n (n=image_size / patch_size) single-channel images according to the size of patch_size (image_size is the image size, and patch_size is the size of the image block after segmentation). In this embodiment, the input dimension 1024×1024×1 is taken as an example. The image is segmented into 32×32×1 blocks, and each image generates 1024 blocks, that is, the input dimension is 1024×1024.
[0057] Feature embedding: Perform a Linear Projection of Flattened patches operation on the image blocks, flatten each image block by patch_size*patch_size*1, that is, a total of 1025 tokens, and add a learnable token to get embedded patches, at this time the dimension is 1025×1024.
[0058] Position encoding: Position encoding is performed for the expanded image blocks to associate feature blocks with position information and pass them to the next layer. Here, a position encoding E needs to be superimposed. pos , participate in model training as a learnable parameter.
[0059] E pos ∈R (N+1)×D
[0060]
[0061]
[0062] The dimension of Z is 1025×1024. Z is the linearly expanded vector, which contains the content information of the segmented block and the position information. D is the dimension of each token after mapping. N is the number of segments. E pos is the vector value of the encoder input after position encoding, is the Nth flattened 2D image block, X class is the category of the flattened two-dimensional image block, C is the dimension of the flattened two-dimensional block, E is the vector value of the input code, and P is the previous patch_size, which is the size of the two-dimensional image after blocking.
[0063] The encoded embedded data needs to obtain the spatial nodes between two nodes in the local spatial dimension through the multi-head attention mechanism and perform weighted averaging. The calculation formula is as follows:
[0064]
[0065]
[0066] Where Q, K, and V are the query matrix, X represents the feature tensor of the data, the keyword matrix, and the value matrix, respectively. is the scaling factor, softmax represents the softmax function, and d k represents the dimension of k, W q , W k , W v They are the query, key, and value weight matrices respectively. The following formula is used to calculate the multi-head self-attention mechanism composed of multiple self-attention mechanisms:
[0067] MultiHead(Q,K,V)=Concat(head1,...,head n )W 0
[0068] Among them head i =Attention(QW i Q ,KW i K ,VW i V ), W i Q is the query weight matrix of the ith head, W i K is the keyword weight matrix of the ith head, W i V is the value weight matrix of the i-th head, X represents the feature tensor of the data, Concat represents the concatenation of the feature tensors, and head i is the result of the i-th self-attention mechanism.
[0069] After learning the global features through the Multi-Head attention layer of the Transform Encoder module, Figure 4 As shown in , the output data is compared with the Embedded Patches data to make a residual, and then sent to the CNN layer to learn the local features of the data after normalization, as shown in Figure 4As shown in the figure, after the convolution operation with a kernel of 3 and a stride of 1, the data size will be reduced by 2, so the data size input to the MLP module is projection-2, and then input to the MLP module after normalization. The size of the hidden layer of the MLP module is set to projection_dim*4, and the final output layer size is projectionio_dim. After the residual, the output is a total of (image_size / patch_size)+1 tokens, and token 0 is taken out for subsequent module classification.
[0070] The token output by the Transform Encoder module (mainly composed of the Multi-Head Attention layer, CNN layer and Multi-layer Perception layer (MLP module)) is input into the MLP module for classification. The size of the input layer is projection_dim, and the size of the output layer is the number of categories. There are 5 storage formats in total, so the output layer is 5, and there is no hidden layer. The cross entropy is calculated based on the predicted classification value and the true label, and the optimization method uses the Adam optimizer.
[0071] Example 2
[0072] In this embodiment, the dimension of the initial input circuit netlist matrix grayscale image is 1024×1024, and the patch_size of each image after segmentation is 32×32, so one image will generate (1024 / 32)×(1024 / 32)=32×32=1024 patches; that is, the input sequence length is 1024, and the dimension of each patch is 32×32×1 (that is, 1024 column vectors are input, and the dimension of each column vector is 1024); Linear Projection of Flattened Patches) dimension is 1024×N (N=1024, N is the number of divided blocks or sequence length), so the dimension of the input after passing through the linear projection layer is still 1024×1024, that is, there are 1024 tokens in total, and the dimension of each token is 1024; a special class_token needs to be added here and placed at the 0th position for subsequent classification, so the final dimension is 1025×1024; after position encoding information, the dimension is still 1025×1024.
[0073] Example 3
[0074] In the Transformer Encoder module of this embodiment, the position-encoded data is input into the LN layer, and the output dimension is still 1025×1024. Attention), first map the input to Q, K, V. Here, 16 heads are set (1024 / 16=64), then the dimensions of Q, K, V are 1025×64, and there are 16 groups of Q, K, V. Finally, concatenate the outputs of the 16 groups of Q, K, V, and the output dimension is 1025×1024. Then, after the residual, it passes through another layer of LN, and the dimension remains unchanged. Then, it is input into the CNN layer for local feature extraction. After the convolution operation with a convolution kernel of 3 and a step length of 1, the data size will be reduced by 2, that is, 1025×1022. After the LN layer, the dimension remains unchanged and is input into the MLP module. Here, the dimension will be enlarged and then reduced back. 1025×1022 is enlarged to 1025×4088, and then reduced to 1025×1022. Then, the output of the MLP module is compared with the data output by the Multi-Head Attention and the Embedded The residual of the data after adding the patches is added as the output, and token 0 is taken for feature learning and classification in subsequent modules.
[0075] The preferred embodiments of the present invention disclosed above are only used to help illustrate the present invention. The preferred embodiments do not describe all the details in detail, nor do they limit the invention to the specific implementation methods described. Obviously, many modifications and changes can be made according to the content of this specification. This specification selects and specifically describes these embodiments in order to better explain the principles and practical applications of the present invention, so that those skilled in the art can understand and use the present invention well. The present invention is limited only by the claims and their full scope and equivalents.
Claims
1. A circuit netlist simulation acceleration optimization method based on visual Transform, Features: The following steps are involved: Acquire a data set, where the data in the data set includes a circuit netlist sparse matrix; Matrix visualization: Convert the sparse circuit netlist matrix into a grayscale image and standardize the image size, while expanding the number of training sets through data augmentation; Build a sparse matrix storage format classification model based on Vision Transformer; Set the learning strategy and loss function in the training phase, use the training set to train the constructed sparse matrix storage format classification model, and use the test set to test the training effect; Port the trained model to the Fastspice circuit simulator; The sparse matrix storage format classification model based on Vision Transformer adds a CNN layer after the multi-head self-attention layer in the original Transformer Encoder to capture the local features of the sparse matrix, and finally inputs the obtained token with position encoding information into the MLP module for classification; The sparse matrix storage format classification model based on Vision Transformer includes a TransformEncoder module; the Transform Encoder module includes a multi-head self-attention layer, a CNN layer and a multi-layer perception layer.
2. The circuit netlist simulation acceleration optimization method based on visual Transform as claimed in claim 1, Features: In step S2, image size normalization is to map the matrix values to 0-255 and compress the size to a uniform image_size.
3. The circuit netlist simulation acceleration optimization method based on visual Transform as claimed in claim 1, Features: The data after matrix imaging is preprocessed as follows: a) Feature segmentation: The sparse matrix grayscale image is a single-channel two-dimensional image. After compressing the matrix to image_size*image_size, the input image is segmented into n single-channel images according to the size of patch_size; b) Feature embedding: Expand the image blocks, flatten each image block by patch_size*patch_size*1, and add a learnable token to get embedded patches; c) Position coding: superimpose a position code E on the image block pos .
4. The circuit netlist simulation acceleration optimization method based on visual Transform as claimed in claim 1, Features: The matrix compression of step a) includes: All negative values are taken as their absolute values, and the remaining non-zero points are scaled according to the following formula: Among them, i and j represent matrix value indexes, and p i,j represents the value of the matrix i row and j column, p max Represents the maximum non-zero value of the current matrix, p i,j,gray Represents the scaling value of row i and column j.
5. The circuit netlist simulation acceleration optimization method based on visual Transform as claimed in claim 1, Features: The grayscale image is bilinearly interpolated to set its size to image_size*image_size. After selecting labels for the circuit netlist matrix, the labels of the grayscale image samples corresponding to the netlist matrix are set to 0 to 4 categories, namely: COO, CSR, CSC, ELL, BSR. The labels are used for subsequent image classification.
6. The circuit netlist simulation acceleration optimization method based on visual Transform as claimed in claim 1, Features: After the segmented circuit matrix grayscale image is concatenated with the position code, the global features are learned through the multi-head self-attention layer, and then passed to the CNN layer to learn the local features after normalization. Finally, it enters the MLP module to make a residual and output (image_size / patch_size)+1 token. Token 0 is taken out for classification in subsequent modules.
7. The circuit netlist simulation acceleration optimization method based on visual Transform as claimed in claim 6, Features: The spatial nodes between two nodes in the local spatial dimension are obtained through the multi-head self-attention layer, and weighted average is performed. The calculation formula is as follows: Where Q, K, and V are the query matrix, X represents the feature tensor of the data, the keyword matrix, and the value matrix, respectively. is the scaling factor, d k represents the dimension of k, softmax represents the softmax function, W q , W k , W v They are query, key, and value weight matrices respectively; Then use the following formula to calculate the multi-head self-attention mechanism composed of multiple self-attention mechanisms: MultiHead(Q,K,V)=Concat(head 1 ,……,head n )W 0 in is the query weight matrix of the ith head, is the keyword weight matrix of the ith head, is the value weight matrix of the i-th head, X represents the feature tensor of the data, Concat represents the concatenation of the feature tensors, and head i is the result of the i-th self-attention mechanism.
8. The circuit netlist simulation acceleration optimization method based on visual Transform as claimed in claim 1, Features: The trained Vision Transformer-based sparse matrix storage format classification model is used in the Fastspice simulator. The netlist generated during the simulation process generates the underlying circuit netlist matrix, the storage format of the circuit netlist matrix is classified, and the best storage format of the netlist is selected. The format is input into the simulator for matrix decomposition and solution process.
Citation Information
Patent Citations
Transistor level piecewise linear modeling and model reduction method for nonlinear circuit
CN102194017A
Small sample insect image recognition method based on visual Transform
CN114676769A
Logic optimization method and device of integrated circuit, electronic equipment and readable medium
CN115204076A
Computationally efficient modeling and simulation of large scale systems
US20130124168A1
