Matrix data transposition method, matrix data transposition device and chip

By adopting matrix data transposition method in artificial intelligence chips, the number of cache units is reduced by cyclic shift, write and combination modules, and efficient transposition is achieved, which solves the problems of large chip area and low performance, and improves the transposition performance and efficiency .

CN118916596APending Publication Date: 2024-11-08TENCENT TECHNOLOGY (SHENZHEN) CO LTD
View PDF 0 Cites 3 Cited by

Patent Information

Application Number
CN202310516046.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-05-08
Publication Date
2024-11-08

AI Technical Summary

Technical Problem

In existing high bandwidth artificial intelligence chips, the area complexity of the transpose unit is high, resulting in a large chip area and affecting performance efficiency.

Method used

The matrix data transposition method is adopted to reduce the number of instantiation of cache units through the first cyclic shift, write module, combination module and reorganization module, improve transposition performance, read matrix elements in parallel, and simplify matrix elements reorganization.

Benefits of technology

Effectively reduce the area of ​​artificial intelligence chips, while improving transposition performance, improving the surface-effect ratio and matrix elements reading efficiency, and reducing response time.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118916596A_ABST
    Figure CN118916596A_ABST
Patent Text Reader

Abstract

The embodiment of the invention discloses a matrix data transposing method, a matrix data transposing device and a chip, the matrix data transposing method comprises the following steps: performing first cyclic shift on initial matrix data to obtain shift matrix data, taking every at least two adjacent matrix elements as an element set, and further writing the element set into a cache unit; according to the method, the instantiation number of cache units in an artificial intelligence chip can be effectively reduced, so that the area of the artificial intelligence chip is reduced, a target element set is read from each cache unit and combined to obtain target row data, and then the transposed initial matrix data is obtained through simple matrix element recombination, so that the transposed initial matrix data is obtained. Therefore, the time complexity can be effectively reduced, the transposition performance is improved, the area-effect ratio is effectively improved, the transposition performance is effectively improved while the area of an artificial intelligence chip is reduced, and the method can be widely applied to the technical fields of artificial intelligence, cloud technology and the like.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of artificial intelligence technology, and in particular to a matrix data transposition method, a matrix data transposition device and a chip. Background Art

[0002] Matrix operations are a commonly used type of operation, and transposition operations are the basic operations of matrix operations. For example, in neural network training, it is usually necessary to transpose the input matrix and then perform convolution or deconvolution operations in neural network training, or directly output the transposed matrix data.

[0003] Currently, in high-bandwidth artificial intelligence chips, in order to ensure the transposition performance of the transposition unit, the area complexity of the transposition unit is usually high, resulting in a larger area of ​​the artificial intelligence chip. Summary of the invention

[0004] The following is a summary of the subject matter described in detail in this application. This summary is not intended to limit the scope of the claims.

[0005] The embodiments of the present application provide a matrix data transposition method, a matrix data transposition device, and a chip, which can effectively improve the transposition performance while reducing the area of ​​the artificial intelligence chip.

[0006] On the one hand, an embodiment of the present application provides a matrix data transposition method, comprising:

[0007] Acquire initial matrix data, and perform a first cyclic shift on the initial matrix data to obtain shifted matrix data;

[0008] In each row of the shift matrix data, at least two adjacent matrix elements are used as an element set, and each element set is written into a corresponding cache unit according to a column range to which the element set belongs in the shift matrix data;

[0009] Reading a target element set from each of the cache units, combining the target element sets belonging to the same column range in the initial matrix data to obtain at least two target row data;

[0010] Matrix elements are reorganized between at least two of the target row data, and the transposed initial matrix data is obtained according to the target row data after the matrix elements are reorganized.

[0011] On the other hand, an embodiment of the present application further provides a matrix data transposition device, comprising:

[0012] A first cyclic shift module, used for acquiring initial matrix data, performing a first cyclic shift on the initial matrix data, and obtaining shifted matrix data;

[0013] A writing module, used to take at least two adjacent matrix elements in each row of the shift matrix data as an element set, and write each element set into a corresponding cache unit according to a column range to which the element set belongs in the shift matrix data;

[0014] A combining module, configured to read a target element set from each of the cache units, and combine the target element sets belonging to the same column range in the initial matrix data to obtain at least two target row data;

[0015] The reorganization module is used to reorganize matrix elements between at least two of the target row data, and obtain the transposed initial matrix data according to the target row data after the matrix element reorganization.

[0016] Further, the above-mentioned combination module includes a second cyclic shift module and a reading module having the same number as the cache units;

[0017] The reading module is used to read the target element set from the corresponding cache unit, and combine the target element sets belonging to the same column range in the initial matrix data to obtain at least two initial row data;

[0018] The second cyclic shift module is used to perform a second cyclic shift on the initial row data to obtain target row data, wherein the second cyclic shift is in the opposite direction to the first cyclic shift.

[0019] Further, the combination module further includes a first multiplexer, the first multiplexer being used for stopping writing the initial row data corresponding to the second buffer area into the second cyclic shift module when writing the initial row data corresponding to the first buffer area into the second cyclic shift module, and stopping writing the initial row data corresponding to the first buffer area into the second cyclic shift module when writing the initial row data corresponding to the second buffer area into the second cyclic shift module;

[0020] Wherein, the first cache area and the second cache area each include a plurality of cache units.

[0021] Furthermore, the matrix data transposition device also includes a second multiplexer having the same number as the cache units, and the second multiplexer is used to stop the writing module from writing the element set to the corresponding cache unit when the combination module reads the target element set from the corresponding cache unit.

[0022] Furthermore, the above-mentioned reorganization module includes a reorganization register and a register control module, the reorganization register is used to write at least two of the target rows of data, and the register control module is used to reorganize matrix elements of at least two of the target rows of data in the reorganization register.

[0023] Further, the above-mentioned reorganization module includes a multiplexer, a third multiplexer and a plurality of the above-mentioned reorganization registers;

[0024] The demultiplexer is used to write at least two of the target row data into a target reorganization register, wherein the target reorganization register refers to the reorganization register in an idle state;

[0025] The third multiplexer is used to output the target row data after matrix element reorganization by the target reorganization register to obtain the transposed initial matrix data.

[0026] On the other hand, an embodiment of the present application further provides a chip, including: the above-mentioned matrix data transposition device.

[0027] The embodiments of the present application include at least the following beneficial effects: by performing a first circular shift on the initial matrix data to obtain shifted matrix data, taking at least two adjacent matrix elements as an element set, and since the element set is composed of at least two adjacent matrix elements, by writing the element set into the cache unit, the number of instantiations of the cache unit in the artificial intelligence chip can be effectively reduced, thereby reducing the area of ​​the artificial intelligence chip; on this basis, further reading the target element set from each of the cache units, combining the target element sets belonging to the same column range in the initial matrix data to obtain at least two target row data, performing matrix element reorganization between the at least two target row data, and obtaining the transposed initial matrix according to the target row data after the matrix element reorganization. Data, therefore, only a simple reorganization of matrix elements is needed to obtain multiple target row data and then complete the transposition of the initial matrix data, thereby effectively reducing the time complexity, improving the transposition performance, and effectively improving the surface efficiency ratio. In addition, by writing each element set into the corresponding cache unit according to the column range to which the element set belongs in the shifted matrix data, it is equivalent to staggering the matrix elements of each column range of the initial matrix data and writing them into different cache units, which is convenient for the subsequent parallel reading of the matrix elements of the same column range of the initial matrix data from each cache unit, which can improve the reading efficiency of the matrix elements and further improve the transposition performance. It can be seen that the matrix data transposition method provided in the embodiment of the present application can effectively improve the transposition performance while reducing the area of ​​the artificial intelligence chip.

[0028] Other features and advantages of the present application will be set forth in the following description, and in part will become apparent from the description, or may be understood by practicing the present application. BRIEF DESCRIPTION OF THE DRAWINGS

[0029] The accompanying drawings are used to provide further understanding of the technical solution of the present application and constitute a part of the specification. Together with the embodiments of the present application, they are used to explain the technical solution of the present application and do not constitute a limitation on the technical solution of the present application.

[0030] Figure 1 A schematic diagram of an optional implementation environment provided for an embodiment of the present application;

[0031] Figure 2 An optional flowchart of a matrix data transposition method provided in an embodiment of the present application;

[0032] Figure 3 An optional flowchart of a transposition operation provided in an embodiment of the present application;

[0033] Figure 4 An optional structural diagram of the shift matrix data provided in the embodiment of the present application;

[0034] Figure 5 A schematic diagram of an optional relationship between shift matrix data and a cache unit provided in an embodiment of the present application;

[0035] Figure 6 An optional flowchart of a matrix element reorganization process provided in an embodiment of the present application;

[0036] Figure 7 Another optional flowchart of the matrix element reorganization process provided in the embodiment of the present application;

[0037] Figure 8 A schematic diagram of an optional process for determining shift matrix data provided in an embodiment of the present application;

[0038] Fig. 9 A schematic diagram of another optional relationship between the shift matrix data and the cache unit provided in an embodiment of the present application;

[0039] Fig.10 A schematic diagram of an optional process for determining target row data provided in an embodiment of the present application;

[0040] Fig.11 A schematic diagram of another optional process for determining target row data provided in an embodiment of the present application;

[0041] Fig.12 Another optional flowchart of the matrix element reorganization process provided in the embodiment of the present application;

[0042] Fig.13 A schematic diagram of another optional relationship between the shift matrix data and the cache unit provided in an embodiment of the present application;

[0043] Fig.14 A schematic diagram of an optional process for determining target row data provided in an embodiment of the present application;

[0044] Fig.15 A schematic diagram of another optional process for determining target row data provided in an embodiment of the present application;

[0045] Fig.16 Another optional flowchart of the matrix element reorganization process provided in the embodiment of the present application;

[0046] Fig.17 Another optional flowchart of the matrix data transposition method provided in the embodiment of the present application;

[0047] Fig.18 A schematic diagram of an optional structure of a matrix data transposition device provided in an embodiment of the present application;

[0048] Fig.19 A schematic diagram of another optional structure of the matrix data transposition device provided in an embodiment of the present application;

[0049] Fig. 20 A schematic diagram of an optional architecture of a direct memory access engine provided in an embodiment of the present application;

[0050] Fig.21 Another optional structural diagram of the chip provided in the embodiment of the present application;

[0051] Fig. 22 A partial structural block diagram of a terminal provided in an embodiment of the present application;

[0052] Fig.23 A partial structural block diagram of the server provided in an embodiment of the present application. DETAILED DESCRIPTION

[0053] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0054] It should be noted that in each specific embodiment of the present application, when it comes to the need to perform relevant processing based on data related to the characteristics of the target object such as target object attribute information or attribute information set, the permission or consent of the target object will be obtained first, and the collection, use and processing of these data will comply with relevant laws, regulations and standards. Among them, the target object can be a user. In addition, when the embodiment of the present application needs to obtain the target object attribute information, the target object's separate permission or separate consent will be obtained by means of a pop-up window or jumping to a confirmation page, etc., and after the separate permission or separate consent of the target object is clearly obtained, the necessary target object-related data for enabling the normal operation of the embodiment of the present application will be obtained.

[0055] To facilitate understanding of the technical solutions provided in the embodiments of the present application, some key terms used in the embodiments of the present application are explained here:

[0056] Artificial Intelligence (AI) is the theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results. In other words, artificial intelligence is a comprehensive technology in computer science that attempts to understand the essence of intelligence and produce a new intelligent machine that can respond in a similar way to human intelligence. Artificial intelligence is to study the design principles and implementation methods of various intelligent machines so that machines have the functions of perception, reasoning and decision-making.

[0057] Artificial intelligence technology is a comprehensive discipline that covers a wide range of fields, including both hardware-level and software-level technologies. Basic artificial intelligence technologies generally include sensors, dedicated artificial intelligence chips, cloud computing, distributed storage, big data processing technology, operating / interactive systems, mechatronics and other technologies. Artificial intelligence software technologies mainly include computer vision technology, speech processing technology, natural language processing technology, as well as machine learning / deep learning, autonomous driving, smart transportation and other major directions.

[0058] Machine Learning (ML) is a multi-disciplinary subject that involves probability theory, statistics, approximation theory, convex analysis, algorithm complexity theory and other disciplines. It specializes in studying how computers simulate or implement human learning behavior to acquire new knowledge or skills and reorganize existing knowledge structures to continuously improve their performance. Machine learning is the core of artificial intelligence and the fundamental way to make computers intelligent. Its applications are spread across all areas of artificial intelligence. Machine learning and deep learning usually include artificial neural networks, belief networks, reinforcement learning, transfer learning, inductive learning, and teaching learning.

[0059] Currently, in high-bandwidth artificial intelligence chips, in order to ensure the transposition performance of the transposition unit, the area complexity of the transposition unit is usually high, resulting in a larger area of ​​the artificial intelligence chip.

[0060] Based on this, the embodiments of the present application provide a matrix data transposition method, a matrix data transposition device and a chip, which can effectively improve the transposition performance while reducing the area of ​​the artificial intelligence chip.

[0061] Reference Figure 1 , Figure 1 A schematic diagram of an optional implementation environment provided for an embodiment of the present application, the implementation environment includes a terminal 101 and a server 102, wherein the terminal 101 and the server 102 are connected via a communication network.

[0062] Exemplarily, the server 102 may receive a neural network processing request (e.g., an image processing request, a text processing request, or a voice processing request, etc.) sent by the terminal 101, and the neural network processing request carries data to be processed (a target image, a target text, or a target voice, etc.). The server 102 extracts initial matrix data corresponding to the target image, target text, or target voice (e.g., an image feature vector, a text feature vector, or a voice feature vector, etc.), performs a first cyclic shift on the initial matrix data, and obtains shifted matrix data; in each row of the shifted matrix data, at least two adjacent matrix elements are used as an element set. , write each element set into a corresponding cache unit according to the column range to which the element set belongs in the shift matrix data; read the target element set from each cache unit, combine the target element sets belonging to the same column range in the initial matrix data, and obtain at least two target row data; reorganize the matrix elements between the at least two target row data, and obtain the transposed initial matrix data according to the target row data after the matrix element reorganization, and obtain the processing result of the neural network processing request (for example, it can be an image recognition result, a text recognition result, or a speech recognition result, etc.) according to the transposed initial matrix data, and send the processing result to the terminal 101.

[0063] The server 102 obtains shifted matrix data by performing a first circular shift on the initial matrix data, and takes at least two adjacent matrix elements as an element set. Since the element set is composed of at least two adjacent matrix elements, the number of instantiations of the cache units in the artificial intelligence chip can be effectively reduced by writing the element set into the cache unit, thereby reducing the area of ​​the artificial intelligence chip; on this basis, the target element set is further read from each cache unit, and the target element sets belonging to the same column range in the initial matrix data are combined to obtain at least two target row data, and matrix elements are reorganized between the at least two target row data. According to the target row data after the matrix elements are reorganized, the transposed initial matrix data is obtained. Therefore, multiple target row data can be obtained by simply reorganizing the matrix elements to complete the process. The transposition of the initial matrix data can be achieved, thereby effectively reducing the time complexity, improving the transposition performance, and effectively improving the area efficiency ratio. Moreover, by writing each element set into the corresponding cache unit according to the column range to which the element set belongs in the shifted matrix data, it is equivalent to staggering the matrix elements of each column range of the initial matrix data and writing them into different cache units, so as to facilitate the subsequent parallel reading of the matrix elements of the same column range of the initial matrix data from each cache unit, which can improve the reading efficiency of the matrix elements and further improve the transposition performance. It can be seen that the matrix data transposition method provided in the embodiment of the present application can effectively improve the transposition performance while reducing the area of ​​the artificial intelligence chip, thereby improving the efficiency of the server 102 in processing the data to be processed, thereby reducing the response time of the server 102 to the neural network processing request.

[0064] Server 102 can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms. In addition, server 102 can also be a node server in a blockchain network.

[0065] The terminal 101 may be a smart phone, a tablet computer, a laptop computer, a desktop computer, a smart speaker, a smart watch, a vehicle-mounted terminal, etc., but is not limited thereto. The terminal 101 and the server 102 may be directly or indirectly connected via wired or wireless communication, which is not limited in the present embodiment.

[0066] The method provided in the embodiments of the present application can be applied to various technical fields, including but not limited to cloud technology, artificial intelligence, natural language processing and other technical fields.

[0067] Reference Figure 2, Figure 2 An optional flow chart of a matrix data transposition method provided in an embodiment of the present application, the matrix data transposition method can be executed by a server, or can also be executed by a terminal, or can also be executed by a server in cooperation with a terminal, the matrix data transposition method includes but is not limited to the following steps 201 to 204.

[0068] Step 201: Acquire initial matrix data, perform a first cyclic shift on the initial matrix data, and obtain shifted matrix data;

[0069] Among them, the initial matrix data refers to the input matrix to be transposed by the artificial intelligence chip. When the artificial intelligence chip responds to the neural network processing request, it can process the data to be processed carried by the neural network processing request. During the processing, the initial matrix data can be extracted from the data to be processed and the initial matrix data can be transposed.

[0070] During the transposition operation, the initial matrix data is first subjected to a first circular shift, which may be a left circular shift or a right circular shift. The first circular shift is used to change the positions of the matrix elements in the initial matrix data. The first circular shift does not change the structure of the initial matrix data. Therefore, the structure of the shifted matrix data obtained by the shift is the same as that of the initial matrix data. Specifically, each matrix element occupies one bit. The first circular shift means that the matrix elements that are out of the range of the initial matrix data are not lost during the shift, and the matrix elements that are out of the range of the initial matrix data are used as the fill-in elements at the other end. It is necessary to perform the first circular shift on one row of matrix elements of the initial matrix data, specifically, to circularly shift 2 places to the right. Before the shift, it is assumed that the matrix elements are arranged in the following order: [1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7]. After the shift, the matrix elements are arranged in the following order: [1.6, 1.7, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5]. It can be seen that the matrix elements [1.6] and [1.7] are shifted out of the range of the initial matrix data, but are not lost. Instead, they are added as supplementary elements to the first and second places.

[0071] Specifically, the purpose of the first circular shift is to stagger the matrix elements in the initial matrix data. The corresponding circular shift amount can be set for each row of matrix elements in the initial matrix data to facilitate the subsequent transposition operation. After the first circular shift is performed on the initial matrix data, shifted matrix data can be obtained, that is, the shifted matrix data is the initial matrix data after the first circular shift.

[0072] In one possible implementation, referring to Figure 3 , Figure 3An optional flow chart of the transposition operation provided for the embodiment of the present application, wherein the transposition operation on the initial matrix data refers to replacing the rows and columns of the initial matrix data. For example, a transposition operation is performed on an initial matrix data of 8x8 specification to obtain a transposed matrix data of 8x8 specification. In actual operation, the transposition operation is usually performed on the initial matrix data of 64x64 specification, and the transposition operation can also be performed on initial matrix data of other specifications. The specific specifications can be adjusted according to the needs of the artificial intelligence chip.

[0073] Step 202: In each row of the shift matrix data, take at least two adjacent matrix elements as an element set, and write each element set into a corresponding cache unit according to the column range to which the element set belongs in the shift matrix data;

[0074] Among them, the cache unit can be a storage area of ​​a static random access memory (SRAM) in the artificial intelligence chip. A cache unit is equivalent to a bank on the static random access memory, and each bank on the static random access memory has a unique addressing address; the shift matrix data contains multiple rows of matrix elements. In any row of matrix elements, adjacent matrix elements are used as element sets. In any two adjacent rows of matrix elements, the element set located in the upper row is aligned with the element set located in the lower row, and the number of matrix elements contained in each element set is also the same.

[0075] The column range is the interval of the columns where the matrix elements in the element set are located. The element sets in the same column range are aligned in the matrix data. Each column range corresponds to a cache unit, that is, multiple column ranges correspond to multiple different cache units. When writing an element set, the element set is written to the cache unit corresponding to the column range where the element set is located.

[0076] For example, for a 2x8 shift matrix data, the matrix elements of the first row are arranged in order: 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, and the matrix elements of the second row are arranged in order: 1.6, 1.7, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5. Assuming that every two adjacent matrix elements are taken as element sets, the element sets corresponding to the matrix elements of the first row are: [0.0, 0.1], [0.2, 0.3], [0.4, 0.5], [0.6, 0.7], and the element sets corresponding to the matrix elements of the second row are: [1.6, 1.7], [1.0, 1.1], [1.2, 1.3], [1.4, 1.5]. Among them, the element sets [0.0, 0.1] and The element set [1.6, 1.7] is aligned, and the element set [0.0, 0.1] and the element set [1.6, 1.7] belong to the same column range in the shift matrix data. The element set [0.0, 0.1] and the element set [1.6, 1.7] are written to the same cache unit. Specifically, the element set [0.0, 0.1] and the element set [1.6, 1.7] are written to the cache unit in sequence, while the element set [0.0, 0.1] and the element set [0.2, 0.3] belong to different column ranges in the shift matrix data. The element set [0.0, 0.1] and the element set [0.2, 0.3] are written to different cache units. Specifically, the element set [0.0, 0.1] and the element set [0.2, 0.3] can be written to the corresponding cache units in parallel.

[0077] In a possible implementation, a first circular shift is performed on the initial matrix data to obtain shifted matrix data, which may specifically be to traverse the matrix elements of each row of the initial matrix data; a first circular shift is performed on the matrix elements of the i-th row in the initial matrix data, so that the matrix elements of the i-th row are circularly shifted by (n*i)-n positions, wherein i and n are both positive integers, and n is the number of matrix elements in the element set. Based on this, the shift amount of the matrix elements of each row is first determined, and then the matrix elements of each row in the initial matrix data are staggered by the first circular shift. After completing the first circular shift, the shifted matrix data is obtained, so that the matrix elements of each column range of the initial matrix data can be staggered and written to different cache units, so that the matrix elements of the same column range of the initial matrix data can be read in parallel from each cache unit later, which can improve the reading efficiency of the matrix elements and further improve the transposition performance.

[0078] In one possible implementation, referring to Figure 4 , Figure 4 An optional structural diagram of the shift matrix data provided in the embodiment of the present application, Figure 3The initial matrix data of 8x8 size is subjected to the first circular shift to obtain the corresponding shifted matrix data of 8x8 size. Every two adjacent matrix elements are taken as element sets, that is, n=2. By the calculation formula of (n*i)-n, the shift amounts of the matrix elements from the first row to the fourth row are calculated to be 0, 2, 4, and 6 respectively, and the shift amounts of the matrix elements from the fifth row to the eighth row are 8, 10, 12, and 14 respectively. The shift amount corresponding to the matrix elements of the first row is zero, which is equivalent to that the matrix elements of the first row do not need to be circularly shifted. Since the initial matrix number There are a total of eight columns. If the shift amount corresponding to the matrix elements of a row is greater than or equal to eight, the shift amount can be divided by eight, and the remainder of the division result can be regarded as the shift amount corresponding to the matrix elements of the row. Therefore, the shift amounts of the matrix elements from the fifth to the eighth rows can be regarded as 0, 2, 4, and 6, respectively, which can effectively reduce the number of shifts. It can be seen that the shift amount of the matrix elements in each row is a multiple of 2. This is because two adjacent matrix elements are regarded as an element set, and the element set is regarded as the basic shift unit of the first cyclic shift, and zero, one or more element sets are moved each time.

[0079] On this basis, refer to Figure 5 , Figure 5 A schematic diagram of an optional relationship between shift matrix data and cache units provided in an embodiment of the present application, for an 8x8 shift matrix data, the number of matrix elements in the element set is two, the shift matrix data has a total of four column ranges, each column range contains two columns of matrix elements, each column range corresponds to a cache unit, therefore, there are a total of four cache units, namely the first cache unit bank_0a, the second cache unit bank_1a, the third cache unit bank_2a and the fourth cache unit bank_3a, for the element sets [0.0, 0.1], [1.6, 1.7], [2.4, 2.5], [3.2, 3.3], [4.0, 4.1], [5.6, 5.7], [6.4, 6.5], [7.2, 7.3], they are all located in the same column range, and thus are all written to the first cache unit bank_0a, and the same applies to the element sets of other column ranges.

[0080] In a possible implementation, each element set is written to a corresponding cache unit, specifically, each row of data of the shift matrix data can be traversed; the j-th element set of the i-th row of data in the shift matrix data is written to the storage space pointed to by the i-th storage address in the j-th cache unit, where j is a positive integer. Based on this, before each element set is written to the corresponding cache unit, it is necessary to determine the order in which each element set is located in the row of the shift matrix data. For example, the element sets corresponding to the matrix elements of the second row are: [1.6, 1.7], [1.0, 1.1], [1.2, 1.3], [1.4, 1.5], and the order in which the element set [1.2, 1.3] is located in the row of the shift matrix data is 3. Therefore, the element set [1.2, 1.3] is the third element set of the second row of data. The element set [1.2, 1.3] is written to the storage space pointed to by the second storage address in the third cache unit. It can be seen that each column range corresponds to a cache unit. Compared with the storage space pointed to by a storage address in the cache unit, only one matrix element can be stored. The number of instantiations of cache units in the artificial intelligence chip is large, resulting in a larger area of ​​the artificial intelligence chip. However, in the present application, the storage space pointed to by a storage address in the cache unit can store one element set. It can be seen that the embodiments of the present application can reduce the number of instantiations of cache units in the artificial intelligence chip by merging storage spaces, thereby reducing the area of ​​the artificial intelligence chip.

[0081] For example, the size of each matrix element is 16 bits, and the element set includes two matrix elements. When the storage space is merged, the size of each element set is 32 bits. A first cache unit with a specification of 64x32 is used to store 128 matrix elements. The first cache unit can store 64 element sets, and the area of ​​the first cache unit is 271um^2. When the storage space is not merged, two second cache units with a specification of 64x16 are used to store 128 matrix elements. The overall area of ​​the two second cache units is 364um^2. It can be seen that by merging the storage space, the area can be reduced by 26%.

[0082] Step 203: Read target element sets from each cache unit, and combine target element sets that belong to the same column range in the initial matrix data to obtain at least two target row data;

[0083] Among them, each cache unit is used to store an element set of shift matrix data, and the element sets in different cache units can be read in parallel. Within one clock cycle, a target element set can be read from any cache unit, and the target element sets obtained by reading each cache unit are combined to obtain a target row data; some matrix elements corresponding to a column range can be one of the target row data, and the matrix elements corresponding to a column range can be the sum of multiple target row data.

[0084] For example, the matrix elements of the first column in the initial matrix data include: 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, the matrix elements of the second column in the initial matrix data include: 0.1, 1.1, 2.1, 3.1, 4.1, 5.1, 6.1, 7.1, the matrix elements of the first column and the second column of the initial matrix data belong to the same column range, assuming that the number of matrix elements in the element set is two, the shift matrix is ​​obtained by the first cyclic shift Data is written into the corresponding cache unit, and the first cache unit stores the element set [0.0, 0.1] and [4.0, 4.1], the second cache unit stores the element set [1.0, 1.1] and [5.0, 5.1], the third cache unit stores the element set [2.0, 2.1] and [6.0, 6.1], and the fourth cache unit stores the element set [3.0, 3.1] and [7.0, 7.1]. In the clock cycle, the target element sets that can be read in parallel are: [0.0, 0.1], [1.0, 1.1], [2.0, 2.1] and [3.0, 3.1]. The first target row data obtained by combination is: [0.0, 0.1, 1.0, 1.1, 2.0, 2.1, 3.0, 3.1]. In the second clock cycle, the target element sets that can be read in parallel are: [4.0, 4.1], [5.0, 5.1], [6.0, 6.1] 1] and [7.0, 7.1], the second target row data obtained by combination is: [4.0, 4.1, 5.0, 5.1, 6.0, 6.1, 7.0, 7.1]. ​​Therefore, the matrix element corresponding to the column range is the sum of the first target row data and the second target row data. It can be seen that the matrix elements corresponding to the column range in the initial matrix data can be effectively read, and the transposed matrix of the initial matrix data can be determined through the matrix elements corresponding to the column range, and the transposition efficiency is high.

[0085] In one possible implementation, the target element set is read from each cache unit. Specifically, the storage address in each cache unit is evenly divided into at least two target address ranges according to the number of matrix elements in the element set; and the target element set is read from the same target address range of each cache unit.

[0086] Among them, the column ranges of multiple target element sets in the initial matrix data are the same, which is equivalent to reading the target element sets from each cache unit in a step-by-step reading manner. Based on this, each cache unit may include multiple storage spaces. In any cache unit, the storage address of the cache unit points to a unique storage space. Each cache unit may include the same storage address range, and the storage address in the cache unit is evenly divided into at least two target address ranges, which is equivalent to evenly dividing the storage space in the cache unit into at least two subspaces. The number of target address ranges is determined by the number of matrix elements in the element set. Each column range in the initial matrix data will correspond to multiple read cycles. In one read cycle, the target element set is read from one of the target address ranges of each cache unit, and one of the target row data is obtained by combining. A column range of the initial matrix data may correspond to multiple target row data. Multiple read cycles are required to read all target row data corresponding to the column range to ensure the effective subsequent matrix element reorganization.

[0087] For example, the storage address range of each cache unit is 0x00 to 0x3F, where 0x00 and 0x3F are hexadecimal numbers, and the decimal data of 0x3F is 63, which is equivalent to the number of storage addresses of the cache unit being 64. Assuming that the number of matrix elements in the element set is two, the storage addresses in each cache unit can be evenly divided into two target address ranges. The first target address range is: 0x00 to 0x1F, and the second target address range is: 0x20 to 0x3F. Each column range in the initial matrix data will correspond to two read cycles. For any column range in the initial matrix data, the target element set read by the first read cycle needs to meet two conditions. The first condition is that the target element set is located in the first target address range of each cache unit, and the second condition is that the target element set belongs to the column range. The target element set read by the second read cycle also needs to meet two conditions. The first condition is that the target element set is located in the second target address range of each cache unit, and the second condition is that the target element set belongs to the column range.

[0088] In a possible implementation, the number of matrix elements in the element set and the number of target address ranges are both two; the target element sets belonging to the same column range in the initial matrix data are combined to obtain at least two target row data, specifically, the target element sets read from one of the target address ranges of each cache unit are combined to obtain one of the target row data; the target element sets read from another target address range of each cache unit are combined to obtain another target row data.

[0089] Among them, assuming that the number of matrix elements in the element set is two, the storage address in the cache unit can be evenly divided into two target address ranges. For example, the storage address range of each cache unit is 0x0 to 0x7, where 0x0 and 0x7 are hexadecimal numbers, and the decimal data of 0x7 is 7, which is equivalent to the number of storage addresses in the cache unit being 8. After even division, the first target address range is: 0x0 to 0x3, and the second target address range is: 0x4 to 0x7. The initial matrix data of 8x8 specification corresponds to four cache units, and each column range in the initial matrix data corresponds to two read cycles;

[0090] For any column range in the initial matrix data, the target element set read in the first read cycle needs to meet two conditions. The first condition is that the target element set is located in the first target address range of each cache unit, and the second condition is that the target element set belongs to the column range. The first target address range is: 0x0 to 0x3. The element set stored at the storage address 0x0 in the first cache unit is [0.0, 0.1]. The matrix element stored at the storage address 0x1 in the second cache unit is [1.0, 1.1]. The matrix element stored at the storage address 0x3 in the third cache unit is [2. 0, 2.1], the matrix element stored at the storage address 0x4 in the fourth cache unit is [3.0, 3.1], the element sets [0.0, 0.1], [1.0, 1.1], [2.0, 2.1] and [3.0, 3.1] all belong to the first column range of the initial matrix data, therefore, the target element sets read in the first read cycle are [0.0, 0.1], [1.0, 1.1], [2.0, 2.1] and [3.0, 3.1] respectively, and the target element sets read in the first read cycle can be combined into the first target row data in one set of target row data;

[0091] The target element set read by the second read cycle also needs to meet two conditions. The first condition is that the target element set is located in the second target address range of each cache unit, and the second condition is that the target element set belongs to the column range; the second target address range is: 0x4 to 0x7, the element set stored at the storage address 0x4 in the first cache unit is [4.0, 4.1], the matrix element stored at the storage address 0x5 in the second cache unit is [5.0, 5.1], the matrix element stored at the storage address 0x6 in the third cache unit is [6.0, 6.1], and the matrix element stored at the storage address 0x7 in the fourth cache unit is [7.0, 7.1]. ​​The element sets are [4.0, 4.1], [5.0, 5.1], [6.0 , 6.1] and [7.0, 7.1] all belong to the first column range of the initial matrix data. Therefore, the target element sets read by the second read cycle are [4.0, 4.1], [5.0, 5.1], [6.0, 6.1] and [7.0, 7.1] respectively. The target element sets read by the second read cycle can be combined into the second target row data in the group of target row data. It can be seen that each target address range corresponds to one of the target row data in a group of target row data. Therefore, when the number of target address ranges is two, any column range of the initial matrix data corresponds to two target row data. It is required to go through two read cycles to read all the target row data corresponding to the column range to ensure the effective reorganization of subsequent matrix elements.

[0092] In a possible implementation, target element sets belonging to the same column range in the initial matrix data are combined to obtain at least two target row data. Specifically, target element sets belonging to the same column range in the initial matrix data are combined to obtain at least two initial row data. The initial row data is subjected to a second circular shift to obtain target row data, wherein the second circular shift is in the opposite direction to the first circular shift. Based on this, the position of the element set stored in the cache unit corresponds to the position of the element set in the shifted matrix data. The target element sets read from each cache unit are combined in a fixed order to obtain initial row data. The initial row data corresponds to the column range of the initial matrix data. Since the shifted matrix data is a shift of the initial matrix data, The first circular shift is performed, therefore, the matrix elements in the initial row data will be offset, and several matrix elements belonging to the tail are located at the head of the initial row data. The initial row data needs to be reversely circularly shifted to eliminate the offset of the matrix elements in the initial row data. The offset of the matrix elements in the initial row data is determined by the shift amount of the first circular shift. The target row data is obtained by performing a second circular shift on the initial row data. The second circular shift is opposite to the direction of the first circular shift. The shift amount of the second circular shift is the offset. The second circular shift is used to change the position of the matrix elements in the initial row data. The second circular shift will not change the structure of the initial row data. Therefore, the structure of the target row data obtained by the shift is the same as the structure of the initial row data.

[0093] Specifically, the second circular shift means that the matrix elements that are out of the range of the initial row data are not lost during the shift, and the matrix elements that are out of the range of the initial row data are used as the supplementary elements at the other end. For example, the initial matrix data obtained by combination is [3.2, 3.3, 0.2, 0.3, 1.2, 1.3, 2.2, 2.3], and the offset of the initial matrix data is 2 bits. Specifically, it is necessary to circularly shift 2 bits to the left. After the second circular shift, the target row data is [0.2, 0.3, 1.2, 1.3, 2.2, 2.3, 3.2, 3.3]. It can be seen that the matrix element [3.2] and the matrix element [3.3] are moved out of the range of the initial matrix data and are not lost, but are supplemented to the seventh and eighth bits as supplementary elements, so that the matrix elements of the target row data do not have an offset, thereby ensuring the effective reorganization of the subsequent matrix elements.

[0094] In a possible implementation, a second circular shift is performed on the initial row data, specifically, the arrangement order of each column range in the initial matrix data is determined; the initial row data is subjected to a second circular shift so that the initial row data is circularly shifted by (n*k)-n bits, wherein n and k are both positive integers, n is the number of matrix elements in the element set, and k is the arrangement order of the column range to which the initial row data belongs in the initial matrix data. Based on this, before performing the second circular shift, it is necessary to determine the arrangement order of each column range in the initial matrix data. Exemplarily, the initial matrix data includes four column ranges, and the arrangement orders of the four column ranges are: 1, 2, 3, and 4, respectively. Assuming that the number of matrix elements in the element set is two, the arrangement order of the column range corresponding to a certain initial row data is 3, and the shift amount is determined to be: (2*3)-2=4 bits. The initial row data is subjected to a second circular shift, specifically, it needs to be shifted by 4 bits, so that the matrix elements of the target row data are not offset, thereby ensuring the effective reorganization of the subsequent matrix elements.

[0095] In a possible implementation, a target element set is read from each cache unit, specifically, the target element set can be read from each cache unit in the first cache area, and each element set of the next shift matrix data is written to the corresponding cache unit in the second cache area; wherein the first cache area and the second cache area both include multiple cache units, specifically, a static random access memory in an artificial intelligence chip can be divided into multiple cache areas, each cache area corresponds to a group of cache units, and a group of cache units corresponds to an initial matrix data, for example, it can be divided into a first cache area and a second cache area, the first cache area and the second cache area both include multiple cache units, the first cache area is used to write one element set of the shift matrix data, and the second cache area can be used to write another element set of the shift matrix data, the first cache area is used as the "ping" cache area in the ping-pong cache mechanism, and the second cache area is used as the "pong" cache area in the ping-pong cache mechanism, during the writing and reading process of the element set. A ping-pong cache is implemented in the process. While reading the target element sets of each cache unit in the first cache area, each element set of the next shift matrix data is written to the corresponding cache unit in the second cache area. And while reading the target element sets of each cache unit in the second cache area, each element set of the next shift matrix data is written to the corresponding cache unit in the first cache area. For example, all cache units in the first cache area are: bank_0a to bank_32a, and all cache units in the second cache area are: bank_0b to bank_32b. Bank_0a to bank_32a store one of the element sets of the shift matrix data. While reading one of the target element sets of the shift matrix data from bank_0a to bank_32a, each element set of the next shift matrix data can be written to the corresponding cache unit in the second cache area, so that matrix transposition can be fully pipelined, and the transposition performance is high.

[0096] In a possible implementation, a target element set is read from each cache unit in a first cache area, and each element set of the next shift matrix data is written to a corresponding cache unit in a second cache area. Specifically, control signals of the first cache area and the second cache area may be determined, wherein the control signal includes a write signal and a read signal. When the control signal of the first cache area is a read signal, the control signal of the second cache area is a write signal. When the control signal of the second cache area is a read signal, the control signal of the first cache area is a write signal. When the control signal of the first cache area is a read signal, the control signal of the first cache area is a write signal. When the control signal of the first cache area is a read signal, the target element set is read from each cache unit in the first cache area in response to the control signal of the first cache area, and each element set of the next shift matrix data is written to a corresponding cache unit in the second cache area in response to the write signal of the second cache area. Based on this, a plurality of cache areas are set, and each cache area is controlled to alternately Read operations and write operations are performed, and ping-pong cache is implemented in the process of writing and reading element sets. Each cache unit will receive control signals of write signals and read signals. The actual operation of each cache area is determined by determining the control signals of the first cache area and the second cache area. The first cache area is used as the "ping" cache area in the ping-pong cache mechanism, and the second cache area is used as the "pong" cache area in the ping-pong cache mechanism. When reading the target element set of each cache unit in the first cache area, each element set of the next shift matrix data is written to the corresponding cache unit in the second cache area, and when reading the target element set of each cache unit in the second cache area, each element set of the next shift matrix data is written to the corresponding cache unit in the first cache area. It can be ensured that for any cache unit, only one control signal will be responded in a timing sequence, so that matrix transposition can be fully pipelined, and the transposition performance is high.

[0097] Step 204: reorganize matrix elements between at least two target row data, and obtain transposed initial matrix data according to the target row data after the matrix element reorganization.

[0098] Among them, the matrix element reorganization can be an interleaving process (interleave), that is, replacing one of the elements in the current target row data with one of the elements in another target row data. The target row data is obtained by combining the read results of each cache unit. Since the element set includes at least two adjacent matrix elements, the actual ordering of the matrix elements in the target row data is different from the target ordering of the matrix elements of the row data of the transposed matrix data. The transposed matrix data refers to the initial matrix data after transposition. For any matrix element in any target row data, the matrix element adjacent to the matrix element in the transposed matrix data is used as the target adjacent matrix element. The matrix element and the target adjacent matrix element are separated by (n-1) matrix elements in the target row data, where n is the number of matrix elements in the element set. For example, the number of matrix elements in the element set is two, one of the target row data is [0.0, 0.1, 1.0, 1.1, 2.0, 2.1, 3.0, 3.1], and the target adjacent matrix elements of matrix element 1.0 are matrix element 0.0 and matrix element 2.0. In the target row data, there is one matrix element between matrix element 1.0 and the target adjacent matrix element. Therefore, it is necessary to reorganize the matrix elements and adjust the positions of the matrix elements in the target row data so that the target row data is the same as the row data of the transposed matrix data. Since the matrix elements corresponding to any column range of the initial matrix data can be multiple Therefore, any column range of the initial matrix data can correspond to at least two target row data. In the process of matrix element reorganization, it is necessary to simultaneously reorganize the matrix elements of all target row data corresponding to the column range to obtain the complete row data of the transposed matrix data. For example, the first column range of the initial matrix data corresponds to two target row data. The first target row data is: [0.0, 0.1, 1.0, 1.1, 2.0, 2.1, 3.0, 3.1], and the second target row data is: [4.0, 4.1, 5.0, 5.1, 6.0, 6.1, 7.0, 7.1 ], and at the same time, the matrix elements of the two target row data are reorganized, and the first target row data after reorganization is obtained as: [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0], and the second target row data after reorganization is obtained as: [0.1, 1.1, 2.1, 3.1, 4.1, 5.1, 6.1, 7.1]. ​​The first target row data after reorganization corresponds to the first row data of the transposed matrix data, and the second target row data after reorganization corresponds to the second row data of the transposed matrix data. After multiple matrix element reorganizations, the transposed matrix of the initial matrix data can be determined, and the transposition efficiency is high.

[0099] Among them, by reorganizing the matrix elements of the target row data, the row data of the transposed matrix data can be obtained. The transposed matrix data refers to the initial matrix data after transposition. The number of target row data is the same as the number of rows of the transposed matrix data. For example, for the initial matrix row data of 8x8 specification, in the process of the first matrix reorganization, the matrix elements of the first row and the second row of target row data are reorganized to obtain the two reorganized target row data. The reorganized first row of target row data is the first row of transposed matrix data, and the reorganized second row of target row data is the second row of transposed matrix data. The third row data and the fourth row data of the transposed matrix data are determined by the second matrix reorganization, the fifth row data and the sixth row data of the transposed matrix data are determined by the third matrix reorganization, and the seventh row data and the eighth row data of the transposed matrix data are determined by the fourth matrix reorganization. The transposed matrix data needs to be determined by the results of four matrix element reorganizations.

[0100] In a possible implementation, the number of target row data is two; matrix element reorganization is performed between at least two target row data, specifically, the matrix elements located at odd positions in the two target row data are spliced ​​to obtain one of the target row data after the matrix element reorganization is performed; and the matrix elements located at even positions in the two target row data are spliced ​​to obtain the other target row data after the matrix element reorganization is performed. Based on this, when the number of matrix elements in the element set is two, a column range of the initial matrix data corresponds to two target row data, and the two target row data corresponding to the same column range need to be matrix element reorganized. The elements are reorganized to obtain two rows of transposed matrix data. In the matrix element reorganization process, since the number of matrix elements in the element set is two, in the target row data, any matrix element and the corresponding target adjacent matrix element are separated by 1 matrix element between the target row data. Therefore, the matrix elements located at odd positions in the two target row data are spliced ​​to obtain one row of transposed matrix data, and the matrix elements located at even positions in the two target row data are spliced ​​to obtain the other row of transposed matrix data. After the matrix element reorganization, the transposed matrix of the initial matrix data can be determined, and the transposition efficiency is high.

[0101] In one possible implementation, referring to Figure 6 , Figure 6An optional flow chart of the matrix element reorganization process provided in an embodiment of the present application, for 8x8 shift matrix data, the number of matrix elements in the element set is two, it can be determined that any group of target row data contains two target row data, for the first column range of the initial matrix data, after reading and processing, the corresponding two initial row data can be obtained, the two initial row data are: [0.0, 0.1, 1.0, 1.1, 2.0, 2.1, 3.0, 3.1] and [4.0, 4.1, 5.0, 5.1, 6.0, 6.1, 7.0, 7.1], the corresponding target row data is obtained after a second circular shift, the displacement of the second circular shift is 0, and the obtained The target row data are: [0.0, 0.1, 1.0, 1.1, 2.0, 2.1, 3.0, 3.1] and [4.0, 4.1, 5.0, 5.1, 6.0, 6.1, 7.0, 7.1]. ​​After element reorganization, the matrix elements at odd positions in the two target row data are concatenated to obtain the first row data of the transposed matrix data as [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0], and the matrix elements at even positions in the two target row data are concatenated to obtain the second row data of the transposed matrix data as [0.1, 1.1, 2.1, 3.1, 4.1, 5.1, 6.1, 7.1].

[0102] In one possible implementation, referring to Figure 7 , Figure 7Another optional flow chart of the matrix element reorganization process provided in the embodiment of the present application, for 8x8 shift matrix data, assuming that the number of matrix elements in the element set is two, it can be determined that any group of target row data contains two target row data, for the second column range of the initial matrix data, after reading and processing, the corresponding two initial row data can be obtained, and the two initial row data are: [3.2, 3.3, 0.2, 0.3, 1.2, 1.2, 2.2, 2.3] and [7.2, 7.3, 4.2, 4.3, 5.2, 5.3, 6.2, 6.3], and the corresponding target row data is obtained after the second circular shift, and the displacement of the second circular shift is 0, and the obtained The target row data are: [0.2, 0.3, 1.2, 1.2, 2.2, 2.3, 3.2, 3.3] and [4.2, 4.3, 5.2, 5.3, 6.2, 6.3, 6.1, 7.2, 7.3] respectively. After element reorganization, the matrix elements at odd positions in the two target row data are concatenated to obtain the third row data of the transposed matrix data as [0.2, 1.2, 2.2, 3.2, 4.2, 5.2, 6.2, 7.2], and the matrix elements at even positions in the two target row data are concatenated to obtain the fourth row data of the transposed matrix data as [0.3, 1.3, 2.3, 3.3, 4.3, 5.3, 6.3, 7.3].

[0103] In a possible implementation, matrix element reorganization is performed between at least two target row data, specifically, a target reorganization register in an idle state is determined among multiple reorganization registers; at least two target row data are written into the target reorganization register, and matrix element reorganization is performed on at least two target row data in the target reorganization register. Based on this, multiple reorganization registers are set, and the control signals of each reorganization register are adjusted to alternately write the target row data into each reorganization register, so that ping-pong cache is implemented in the process of matrix element reorganization. For example, for two reorganization registers, one of the reorganization registers is used as the "ping" in the ping-pong cache mechanism, and the other reorganization register is used as the "pong" in the ping-pong cache mechanism. Assuming that the time consumed for matrix element reorganization is one Reorganization cycles, in the first reorganization cycle, the target row data in the reorganization register as "ping" is undergoing matrix element reorganization, the reorganization register as "pong" is used as the target reorganization register, and one group of target row data is written to the reorganization register as "pong", in the second reorganization cycle, the target row data in the reorganization register as "pong" is undergoing matrix element reorganization, and the target row data in the reorganization register as "ping" has completed matrix element reorganization. At this time, the reorganization register as "ping" is in an idle state, the reorganization register as "ping" is used as the target reorganization register, and then the next group of target row data is written to the reorganization register as "ping", so that matrix elements can be reorganized in the full pipeline, the transposition efficiency is improved, and the transposition performance is high.

[0104] In one possible implementation, referring to Figures 8 to 12 , Figure 8 A schematic diagram of an optional process for determining shift matrix data provided in an embodiment of the present application, Fig. 9 A schematic diagram of another optional relationship between the shift matrix data and the cache unit provided in an embodiment of the present application, Fig.10 A schematic diagram of an optional process for determining target row data provided in an embodiment of the present application, Fig.11 Another optional flow chart of determining target row data provided in an embodiment of the present application is as follows: Fig.12 Another optional flowchart of the matrix element reorganization process provided in an embodiment of the present application.

[0105] like Figure 8As shown, a first circular shift is performed on an initial matrix data of 8x8 specification to obtain corresponding shifted matrix data of 8x8 specification, wherein the shift amount of each row of the initial matrix data is (4*i)-4, wherein i is the number of rows, and the shift amounts of the first row to the eighth row are calculated to be 0, 4, 8, 12, 16, 20, 24, and 28, respectively. Since the initial matrix data has a total of eight columns, if the shift amount corresponding to the matrix element of a row is greater than or equal to eight, the shift amount can be divided by eight, and the remainder of the division result is regarded as the shift amount corresponding to the matrix element of the row. Therefore, the shift amounts of the matrix elements of the third row to the eighth row can be regarded as 0, 4, 0, 4, 0, and 4, respectively, which can effectively reduce the number of shifts. It can be seen that the shift amount of the matrix elements in each row is a multiple of 4. This is because two adjacent matrix elements are regarded as an element set, and the element set is regarded as the basic shift unit of the first circular shift, and zero or one element set is moved each time.

[0106] like Fig. 9 As shown, for an 8x8 shift matrix data, the number of matrix elements in the element set is four, and the shift matrix data has two column ranges, each column range contains four columns of matrix elements, and each column range corresponds to a cache unit. Therefore, there are two cache units, namely the first cache unit bank_0a and the second cache unit bank_1a.

[0107] like Fig.10 and Fig.11As shown, since the number of matrix elements in the element set is four, the storage address of each cache unit can be evenly divided into four target address ranges, each target address range corresponds to one of the target row data in a group of target row data, therefore, any column range of the initial matrix data corresponds to four target row data, and four read cycles are required to read all the target row data corresponding to the column range; illustratively, for the initial matrix data of 8x8 specification, the first column range is the first column to the fourth column, and the second column range is the fifth column to the eighth column, and the process of reading all the target row data corresponding to the first column range is as follows: in the first read cycle, the target element set located in the first target address range and belonging to the first column range is read, and the first initial row data is obtained by combination: [0.0, 0.1, 0.2, 0.3, 1.0, 1.1, 1.2, 1.3]; in the second read cycle, the target element set located in the second target address range and belonging to the first column range is read, and the second initial row data is obtained by combination: [2.0, 2.1, 2.2, 2.3, 3.0, 3.1, 3.2, 3.3]; in the third read cycle, the target element set located in the third target address range and belonging to the first column range is read, and the third initial row data is obtained by combining: [4.0, 4.1, 4.2, 4.3, 5.0, 5.1, 5.2, 5.3]; in the fourth read cycle, the target element set located in the fourth target address range and belonging to the first column range is read, and the fourth initial row data is obtained by combining: [6.0, 6.1, 6.2, 6.3, 7.0, 7.1, 7.2, 7.3], since each initial row data belongs to the first column range, there is no offset in the matrix elements in the initial row data. Therefore, when the second circular shift is performed on the initial row data, the shift amount is 0, and the initial row data can obtain the corresponding target row data without the second circular shift; however, for the initial row data read from the second column range, the offset of the initial row data is 4. Therefore, when the second circular shift is performed on the initial row data, the shift amount is 4, and the initial row data obtains the corresponding target row data after the second circular shift.

[0108] like Fig.12As shown, since the number of matrix elements in the element set is four, in the target row data, any matrix element and the corresponding target adjacent matrix element are separated by 3 matrix elements in the target row data. For example, if the address bits of each target row data are: 0, 1, 2, 3, 4, 5, 6, 7, the matrix elements with address bits 0 and 4 in the four target row data are spliced ​​in turn to obtain the first row of the transposed matrix data: [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0], and the matrix elements with address bits 1 and 5 in the four target row data are spliced ​​in turn to obtain the second row of the transposed matrix data: [0.1, 1.1, 2. 1, 3.1, 4.1, 5.1, 6.1, 7.1], sequentially concatenate the matrix elements with address bits 2 and 6 in the four target row data to obtain the third row of the transposed matrix data: [0.2, 1.2, 2.2, 3.2, 4.2, 5.2, 6.2, 7.2], sequentially concatenate the matrix elements with address bits 3 and 7 in the four target row data to obtain the fourth row of the transposed matrix data: [0.3, 1.3, 2.3, 3.3, 4.3, 5.3, 6.3, 7.3], repeat the above steps to determine the remaining row data of the transposed matrix data, and after simple matrix element reorganization, the transposed matrix of the initial matrix data can be determined, and the transposition efficiency is high.

[0109] In one possible implementation, referring to Figure 8 , reference Figures 13 to 16 , Figure 8 A schematic diagram of an optional process for determining shift matrix data provided in an embodiment of the present application, Fig.13 A schematic diagram of another optional relationship between the shift matrix data and the cache unit provided in an embodiment of the present application, Fig.14 A schematic diagram of an optional process for determining target row data provided in an embodiment of the present application, Fig.15 Another optional flow chart of determining target row data provided in an embodiment of the present application is as follows: Fig.16 Another optional flowchart of the matrix element reorganization process provided in an embodiment of the present application.

[0110] Again Figure 8As shown, assuming that the number of matrix elements in the element set is two, the strategy of the first circular shift is adjusted. The shift amount of the first circular shift is not calculated by the calculation formula (n*i)-n, but the shift amount of the first circular shift is calculated by the calculation formula ((n+2)*i)-(n+2). The shift amounts of the first row to the eighth row are calculated as: 0, 4, 8, 12, 16, 20, 24, 28, respectively. Since the initial matrix data has a total of eight columns, if the shift amount corresponding to the matrix element of a row is greater than or equal to eight, the shift amount can be divided by eight, and the remainder of the division result is regarded as the shift amount corresponding to the matrix element of the row. Therefore, the shift amounts of the matrix elements from the third row to the eighth row can be regarded as 0, 4, 0, 4, 0, 4, respectively, which can effectively reduce the number of shifts. It can be seen that the shift amount of the matrix elements in each row is a multiple of 4. This is because two adjacent matrix elements are regarded as an element set, and the element set is regarded as the basic shift unit of the first circular shift, and zero or one element set is moved each time.

[0111] like Fig.13 As shown, Figure 8 Every two adjacent matrix elements in the shift matrix data are taken as an element set, therefore, the number of matrix elements in the element set is two, the shift matrix data has a total of four column ranges, each column range contains two columns of matrix elements, each column range corresponds to a cache unit, therefore, there are a total of four cache units, namely, a first cache unit bank_0a, a second cache unit bank_1a, a third cache unit bank_2a and a fourth cache unit bank_3a.

[0112] like Fig.14 and Fig.15As shown, it can be seen that for the calculation formula of the shift amount of the first cyclic shift of (n*i)-n, any cache unit is used to store 25% of the matrix elements of all the matrix elements corresponding to one of the column ranges, and for the calculation formula of the shift amount of the first cyclic shift of ((n+2)*i)-(n+2), any cache unit is used to store 50% of the matrix elements of all the matrix elements corresponding to one of the column ranges. Since the calculation formula of the shift amount of the first cyclic shift is adjusted, it is necessary to adaptively adjust the strategy of reading the target element set. In one reading cycle, 50% of the matrix elements in a target row of data are read. Based on this, due to the matrix elements in the element set The number is two, therefore, the storage address of each cache unit can be evenly divided into two target address ranges, each target address range corresponds to one of the target row data in a set of target row data, therefore, any column range of the initial matrix data corresponds to two target row data, and four read cycles are required to read all the target row data corresponding to the column range. Exemplarily, in the first read cycle, the target element set located in the first target address range and belonging to the first column range and having a relatively early storage address is read, and the row data is combined to obtain: [0.0, 0.1, 1.0, 1.1]; in the second read cycle, the target element set located in the first target address range is read, And the target element set that belongs to the first column range and the storage address is later, and the row data is obtained by combining: [2.0, 2.1, 3.0, 3.1]; in the third read cycle, the target element set that is located in the second target address range and belongs to the first column range and the storage address is earlier is read, and the row data is obtained by combining: [4.0, 4.1, 5.0, 5.1]; in the fourth read cycle, the target element set that is located in the second target address range and belongs to the first column range and the storage address is later is read, and the row data is obtained by combining: [6.0, 6.1, 7.0, 7.1]; the row data read in the first read cycle and the second read cycle The data is subjected to a second circular shift and combined to obtain the first target row data: [0.0, 0.1, 1.0, 1.1, 2.0, 2.1, 3.0, 3.1]; the row data read in the first read cycle and the second read cycle are subjected to a second circular shift and combined to obtain the second target row data: [4.0, 4.1, 5.0, 5.1, 6.0, 6.1, 7.0, 7.1]; assuming that one read cycle is equivalent to one clock cycle, it can be seen that, relative to the matrix data transposition method that only reads one matrix element in one clock cycle, the matrix data transposition method provided in this embodiment can read multiple matrix elements in one clock cycle, thereby effectively improving the transposition efficiency.

[0113] like Fig.16As shown, since the number of matrix elements in the element set is two, in the target row data, any matrix element and the corresponding target adjacent matrix element are separated by 1 matrix element between the target row data. Exemplarily, after element reorganization processing, the matrix elements located at odd positions in the first target row data and the second target row data are spliced ​​to obtain the first row data of the transposed matrix data as [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0], and the matrix elements located at even positions in the first target row data and the second target row data are spliced ​​to obtain the second row data of the transposed matrix data as [0.1, 1.1, 2.1, 3.1, 4.1, 5.1, 6.1, 7.1]. ​​By repeating the above steps, the remaining row data of the transposed matrix data can be determined. After simple matrix element reorganization, the transposed matrix of the initial matrix data can be determined, and the transposition efficiency is high.

[0114] Reference Fig.17 , Fig.17 Another optional flow chart of the matrix data transposition method provided in the embodiment of the present application, the matrix data transposition method can be applied to the direct memory access engine, and the matrix data transposition method includes but is not limited to the following steps:

[0115] Step 1701: the direct memory access engine obtains initial matrix data, performs a first circular shift on the initial matrix data, and obtains shifted matrix data;

[0116] Step 1702: the direct memory access engine uses at least two adjacent matrix elements in each row of the shift matrix data as an element set, and writes each element set into a corresponding cache unit according to the column range to which the element set belongs in the shift matrix data;

[0117] Step 1703: The direct memory access engine reads the target element sets from each cache unit, and combines the target element sets belonging to the same column range in the initial matrix data to obtain at least two target row data;

[0118] Step 1704: the direct memory access engine reorganizes matrix elements between at least two target row data, and obtains transposed initial matrix data according to the target row data after the matrix element reorganization;

[0119] Step 1705: The direct memory access engine sends the transposed initial matrix data to the first-level cache.

[0120] The detailed principles of steps 1701 to 1704 can be found in the previous explanations of steps 201 to 204 and will not be repeated here.

[0121] Among them, the direct memory access (DMA) engine can move matrix data stored outside the chip at other locations to the on-chip memory for storage, so that the processing unit obtains the matrix data from the on-chip memory for processing; the direct memory access engine mentioned in the embodiment of the present application is integrated on the artificial intelligence chip.

[0122] It is to be understood that, although the steps in the above-mentioned various flow charts are shown in sequence according to the indication of the arrows, these steps are not necessarily performed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in the present embodiment, the execution of these steps does not have a strict order restriction, and these steps can be performed in other orders. Moreover, at least a portion of the steps in the above-mentioned flow charts can include a plurality of steps or a plurality of stages, and these steps or stages are not necessarily performed at the same time, but can be performed at different times, and the execution order of these steps or stages is not necessarily performed in sequence, but can be performed in turn or alternately with at least a portion of the steps or stages in other steps or other steps.

[0123] Reference Fig.18 , Fig.18 This is an optional structural diagram of a matrix data transposition device provided in an embodiment of the present application. The matrix data transposition device 1800 includes:

[0124] A first cyclic shift module 1801 is used to obtain initial matrix data, perform a first cyclic shift on the initial matrix data, and obtain shifted matrix data;

[0125] A writing module 1802 is used to take at least two adjacent matrix elements in each row of the shift matrix data as an element set, and write each element set into a corresponding cache unit according to the column range to which the element set belongs in the shift matrix data;

[0126] A combining module 1803 is used to read target element sets from each cache unit, and combine target element sets belonging to the same column range in the initial matrix data to obtain at least two target row data;

[0127] The reorganization module 1804 is used to reorganize matrix elements between at least two target row data, and obtain transposed initial matrix data according to the target row data after the matrix element reorganization.

[0128] The above-mentioned matrix data transposition device 1800 and the matrix data transposition method are based on the same inventive concept, and the shifted matrix data is obtained by performing a first circular shift on the initial matrix data, and at least two adjacent matrix elements are used as an element set. Since the element set is composed of at least two adjacent matrix elements, the number of instantiations of the cache units in the artificial intelligence chip can be effectively reduced by writing the element set into the cache unit, thereby reducing the area of ​​the artificial intelligence chip; on this basis, the target element set is further read from each cache unit, and the target element sets belonging to the same column range in the initial matrix data are combined to obtain at least two target row data, and the matrix elements are reorganized between the at least two target row data. According to the target row data after the matrix element reorganization, the transposed initial matrix data is obtained. Matrix data, therefore, only a simple reorganization of matrix elements is needed to obtain multiple target row data and then complete the transposition of the initial matrix data, thereby effectively reducing the time complexity, improving the transposition performance, and effectively improving the surface efficiency ratio. In addition, by writing each element set into the corresponding cache unit according to the column range to which the element set belongs in the shifted matrix data, it is equivalent to staggering the matrix elements of each column range of the initial matrix data and writing them into different cache units, which is convenient for the subsequent parallel reading of the matrix elements of the same column range of the initial matrix data from each cache unit, which can improve the reading efficiency of the matrix elements and further improve the transposition performance. It can be seen that the matrix data transposition method provided in the embodiment of the present application can effectively improve the transposition performance while reducing the area of ​​the artificial intelligence chip.

[0129] The write module 1802 may generate a write signal, which carries an element set and a storage address of the element set. The write module 1802 sends the write signal to a corresponding cache unit, thereby writing the element set to the corresponding cache unit.

[0130] In one possible implementation, the combination module 1803 includes a second circular shift module and a reading module having the same number as the cache units; the reading module is used to read the target element set from the corresponding cache unit, and combine the target element sets belonging to the same column range in the initial matrix data to obtain at least two initial row data; the second circular shift module is used to perform a second circular shift on the initial row data to obtain the target row data, wherein the second circular shift is in the opposite direction to the first circular shift.

[0131] The reading module may generate a reading signal, the reading signal carries the storage address of the target element set, and the reading module sends the reading signal to the corresponding cache unit, thereby reading the corresponding target element set.

[0132] In one possible implementation, the combination module 1803 also includes a first multiplexer, which is used to stop writing the initial row data corresponding to the second cache area into the second cyclic shift module when the initial row data corresponding to the first cache area is written into the second cyclic shift module, and to stop writing the initial row data corresponding to the first cache area into the second cyclic shift module when the initial row data corresponding to the second cache area is written into the second cyclic shift module; wherein the first cache area and the second cache area both include multiple cache units.

[0133] Among them, a multiplexer (mux) refers to a combinational logic circuit that selects one path of data from multiple paths of data as an output signal under the control of an address selection signal.

[0134] Exemplarily, the first multiplexer is provided with an address input terminal, two input terminals and an output terminal, wherein one input terminal is connected to each cache unit of the first cache area, the other input terminal is connected to each cache unit of the second cache area, and the output terminal is connected to the second cyclic shift module. After reading the target element set of each cache unit in the first cache area, at least two initial row data are obtained through combination, and the initial row data corresponding to the first cache area is input to the first multiplexer. The address signal corresponding to the first cache area can be a low-level signal. Therefore, a low-level signal is sent to the address input terminal of the first multiplexer, and the first multiplexer shields the signals input from each cache unit of the second cache area. The first multiplexer switches the first cache area to the first cache area. The corresponding initial row data is output to the second circular shift module, and then the initial row data is subjected to a second circular shift to obtain the target row data; in addition, after reading the target element set of each cache unit in the second cache area, at least two initial row data are obtained through combination, and the initial row data corresponding to the second cache area is input to the first multiplexer. The address signal corresponding to the second cache area can be a high-level signal. Therefore, a high-level signal is sent to the address input end of the first multiplexer, and the first multiplexer shields the signals input by each cache unit of the first cache area. The first multiplexer outputs the initial row data corresponding to the second cache area to the second circular shift module, and then the initial row data is subjected to a second circular shift to obtain the target row data.

[0135] Among them, the processing unit of the artificial intelligence chip can send a control signal to the address input terminal of the first multiplexer.

[0136] In one possible implementation, the matrix data transposition device further includes a second multiplexer having the same number as the cache units, and the second multiplexer is used to stop the writing module 1802 from writing the element set to the corresponding cache unit when the combining module 1803 reads the target element set from the corresponding cache unit.

[0137] Exemplarily, the combination module 1803 includes multiple read modules, the number of the read modules is the same as that of the second multiplexer, the second multiplexer corresponds to the read modules, the second multiplexer is provided with an address input terminal, two input terminals and an output terminal, one of the input terminals is connected to the write module 1802, the other input terminal is connected to the corresponding read module, and the output terminal is connected to the corresponding cache unit. When the element set is written to the cache unit, the write module 1802 generates a write signal carrying the element set, and the write module 1802 inputs the write signal to the second multiplexer corresponding to the cache unit. The read module does not generate a read signal, and the address signal corresponding to the write module 1802 can be a low-level signal. Therefore, a low-level signal is sent to the address input terminal of the second multiplexer, and the second multiplexer shields the signal input by the read module. The second multiplexer outputs a write signal to the corresponding cache unit, and then writes the element set to the corresponding cache unit, and then reads the corresponding target element set; in addition, when reading the target element set from the cache unit, the read module generates a read signal for the target element set, and the read module inputs the read signal to the second multiplexer corresponding to the cache unit, and the write module 1802 generates a write signal for the element set carrying the next shift matrix data, and the write module 1802 inputs the write signal to the second multiplexer corresponding to the cache unit. The address signal corresponding to the read module can be a high-level signal, and therefore, a high-level signal is sent to the address input terminal of the second multiplexer, and the second multiplexer shields the signal input by the write module 1802, and the second multiplexer outputs the read signal to the corresponding cache unit, and then reads the corresponding target element set.

[0138] Among them, the processing unit of the artificial intelligence chip can send a control signal to the address input terminal of the second multiplexer.

[0139] In one possible implementation, the reorganization module 1804 includes a multiplexer, a third multiplexer and a plurality of reorganization registers; the multiplexer is used to write at least two target row data into a target reorganization register, wherein the target reorganization register refers to a reorganization register in an idle state; the third multiplexer is used to output the target row data after matrix elements are reorganized by the target reorganization register to obtain the transposed initial matrix data.

[0140] A demultiplexer is a combinational logic circuit that transmits an input data to any one of a plurality of output terminals as required under the control of an address selection signal.

[0141] Exemplarily, the number of reorganization registers is two, and the multiplexer is provided with an address input terminal, an input terminal and two output terminals, the first output terminal is connected to the first reorganization register, the second output terminal is connected to the second reorganization register, the input terminal of the multiplexer is connected to the second circular shift module, and the second circular shift module inputs the target row data to the multiplexer. When the first reorganization register is in an idle state, the first reorganization register is used as the target reorganization register, and the address signal corresponding to the first target reorganization register can be a low-level signal. Therefore, a low-level signal is sent to the address input terminal of the multiplexer, and the multiplexer only outputs the target row data to the first target reorganization register; in addition, when the second reorganization register is in an idle state, the second reorganization register is used as the target reorganization register, and the address signal corresponding to the second target reorganization register can be a high-level signal. Therefore, a high-level signal is sent to the address input terminal of the multiplexer, and the multiplexer only outputs the target row data to the second target reorganization register.

[0142] Among them, the processing unit of the artificial intelligence chip can send a control signal to the address input end of the multiplexer.

[0143] Further, the third multiplexer is provided with an address input terminal, two input terminals and an output terminal, the first input terminal is connected to the first reorganization register, the second input terminal is connected to the second reorganization register, and the output terminal is used to output the target row data after the matrix elements are reorganized. When the first reorganization register completes the matrix element reorganization of the target row data, the first reorganization register inputs the target row data after the matrix elements are reorganized into the third multiplexer, and the address signal corresponding to the first reorganization register can be a low-level signal. Therefore, a low-level signal is sent to the address input terminal of the third multiplexer, and the third multiplexer shields the signal input by the second reorganization register, and the third multiplexer can effectively output the target row data after the matrix elements are reorganized in the first reorganization register; in addition, when the second reorganization register completes the matrix element reorganization of the target row data, the second reorganization register inputs the target row data after the matrix elements are reorganized into the third multiplexer, and the address signal corresponding to the second reorganization register can be a high-level signal. Therefore, a high-level signal is sent to the address input terminal of the third multiplexer, and the third multiplexer shields the signal input by the first reorganization register, and the third multiplexer can effectively output the target row data after the matrix elements are reorganized in the second reorganization register.

[0144] Among them, the processing unit of the artificial intelligence chip can send a control signal to the address input terminal of the third multiplexer.

[0145] Reference Fig.19 , Fig.19Another optional structural diagram of the matrix data transposition device provided in the embodiment of the present application, the matrix data transposition device 1800 is a direct memory access engine, and the matrix data transposition device 1800 also includes:

[0146] The sending module 1805 is used to send the transposed initial matrix data to the first-level cache.

[0147] In one possible implementation, referring to Fig. 20 , Fig. 20 An optional architectural diagram of a direct memory access engine provided for an embodiment of the present application, the direct memory access engine may be the above-mentioned matrix data transposition device, the direct memory access engine includes but is not limited to: a first circular shift module, a write module, multiple read modules, a first multiplexer, multiple second multiplexers, a second circular shift module, two reorganization registers, a register control module, a multiplexer and a third multiplexer, the number of read modules is the same as the number of cache units, and the number of second multiplexers is the same as the number of cache units.

[0148] The first cyclic shift module is used to obtain initial matrix data, perform a first cyclic shift on the initial matrix data, and obtain shifted matrix data;

[0149] The writing module is used to take at least two adjacent matrix elements in each row of the shift matrix data as an element set, and write each element set into a corresponding cache unit according to the column range to which the element set belongs in the shift matrix data;

[0150] The reading module is used to read the target element set from the corresponding cache unit, and then combine the target element sets belonging to the same column range in the initial matrix data to obtain at least two initial row data;

[0151] The second cyclic shift module is used to perform a second cyclic shift on the initial row data to obtain target row data, wherein the second cyclic shift is in the opposite direction to the first cyclic shift;

[0152] The first multiplexer is used to stop writing the initial row data corresponding to the second buffer area into the second cyclic shift module when writing the initial row data corresponding to the first buffer area into the second cyclic shift module, and to stop writing the initial row data corresponding to the first buffer area into the second cyclic shift module when writing the initial row data corresponding to the second buffer area into the second cyclic shift module;

[0153] The second multiplexer is used for stopping the writing module from writing the element set into the cache unit when the combining module reads the target element set from the cache unit;

[0154] The reorganization register is used to write at least two target row data;

[0155] The register control module is used for performing matrix element reorganization on at least two target row data in the reorganization register;

[0156] The demultiplexer is used for writing at least two target row data into a target reorganization register, wherein the target reorganization register refers to a reorganization register in an idle state;

[0157] The third multiplexer is used to output the target row data after the matrix elements are reorganized by the target reorganization register to obtain the transposed initial matrix data.

[0158] Based on this, the first circular shift module performs a first circular shift on the initial matrix data to obtain the shifted matrix data, and then the writing module writes each element set of the shifted matrix data into the corresponding cache unit. Exemplarily, for a 64x64 direct memory access engine, assuming that the size of a matrix element is 16 bits, the total size of the element set that can be input in each clock cycle is the same as the size of a row of data in the initial matrix data. Therefore, the input bandwidth of the direct memory access engine is 64*16bit=1024bit, and the total size of the target element set that can be output in each clock cycle is the same as the size of a row of data in the initial matrix data. Therefore, the output bandwidth of the direct memory access engine is The direct memory access engine includes a first cache area and a second cache area, the first cache area includes a first group of cache units bank_0a to bank_32a, and the second cache area includes a second group of cache units bank_0b to bank_32b. Based on the ping-pong cache mechanism, when reading the target element set in the first group of cache units, the second multiplexer corresponding to the first group of cache units shields the signal input by the write module, and outputs the read signal of the read module to the first group of cache units, thereby realizing the parallel reading of each target element set in the first group of cache units, and the second multiplexer corresponding to the second group of cache units shields the signal input by the read module. The first multiplexer receives an input signal, and outputs a write signal of the write module carrying an element set of the next shift matrix data to the second group of cache units, thereby realizing writing each element set of the next shift matrix data to the second group of cache units. Similarly, when reading the target element set in the second group of cache units, each element set of the next shift matrix data is written to the first group of cache units. In addition, when writing the initial row data corresponding to the first group of cache units into the second cyclic shift module, the first multiplexer shields the initial row data corresponding to the second group of cache units, and outputs the initial row data corresponding to the first group of cache units to the second cyclic shift module. Similarly, when writing the initial row data corresponding to the second group of cache units into the first group of cache units, the first multiplexer shields the initial row data corresponding to the second group of cache units, and outputs the initial row data corresponding to the first group of cache units to the second cyclic shift module. When the second circular shift module is used, the first multiplexer shields the initial row data corresponding to the first group of cache units, and outputs the initial row data corresponding to the second group of cache units to the second circular shift module; then, the second circular shift module performs a second circular shift on the initial row data to obtain target row data, and based on the ping-pong cache mechanism again, the multiplexer outputs a group of target row data input by the second circular shift module to a target reorganization register in an idle state, and under the action of the register control module, matrix elements are reorganized for the target row data in the target reorganization register, and the third multiplexer outputs the target row data after matrix elements are reorganized by the target reorganization register to obtain the transposed initial matrix data.

[0159] Specifically, a static random access memory in an artificial intelligence chip can be divided into multiple cache areas, for example, divided into a first cache area and a second cache area, the first cache area includes a first group of cache units bank_0a to bank_32a, and the second cache area includes a second group of cache units bank_0b to bank_32b. The cache units in the first cache area are used to write one of the element sets of the shift matrix data, and the cache units in the second cache area are used to write another element set of the shift matrix data. By utilizing the ping-pong cache mechanism and controlling the input signal of the address input end of the second multiplexer, when reading the target element set of each cache unit in the first cache area, each element set of the next shift matrix data is written to the corresponding cache unit in the second cache area, and when reading the target element set of each cache unit in the second cache area, each element set of the next shift matrix data is written to the corresponding cache unit in the first cache area. Matrix transposition can be fully pipelined, and the transposition performance is high.

[0160] In one possible implementation, the processing unit of the artificial intelligence chip is capable of generating a first descriptor, a second descriptor, a first selection control signal, and a second selection control signal, the first descriptor is used to indicate the storage address of the element set to be written on the corresponding cache unit, the second descriptor is used to indicate the storage address of the target element set to be read on the corresponding cache unit, the first selection control signal and the second selection control signal are both used to control the second multiplexer, and the first selection control signal and the second selection control signal are different.

[0161] Exemplarily, based on the ping-pong cache mechanism, when reading the target element set from each cache unit in the first cache area, the processing unit sends the first descriptor to the write module so that the write module generates a write signal carrying the element set of the next shift matrix data, and the processing unit also sends the first selection control signal to the second multiplexer corresponding to each cache unit in the second cache area so that the second multiplexer shields the signal of the read module, and the second multiplexer outputs the write signal to each cache unit in the second cache area, thereby writing the element set of the next shift matrix data to the cache unit corresponding to each cache unit in the second cache area, and at the same time, the processing unit The processing unit sends the second descriptor to the read modules corresponding to the cache units in the first cache area so that the read modules generate a read signal. The processing unit also sends the second selection control signal to the second multiplexers corresponding to the cache units in the first cache area so that the second multiplexers shield the signal of the write module. The second multiplexers output the read signal to the corresponding cache units in the first cache area, and then read the corresponding target element sets from the cache units in the first cache area. Similarly, when the target element sets are read from the cache units in the second cache area, the element set of the next shift matrix data can also be written to the corresponding cache units in the first cache area.

[0162] In one possible implementation, the processing unit of the artificial intelligence chip is capable of generating a third selection control signal and a fourth selection control signal, both of which are used to control the first multiplexer, and the third selection control signal and the fourth selection control signal are different.

[0163] Exemplarily, based on the ping-pong cache mechanism, when reading the target element set from each cache unit in the first cache area, the processing unit sends a third selection control signal to the first multiplexer, the first multiplexer shields the signals input from each cache unit in the second cache area, and the first multiplexer outputs the initial row data corresponding to the first cache area to the second circular shift module, and then performs a second circular shift on the initial row data to obtain the target row data; similarly, when reading the target element set from each cache unit in the second cache area, the processing unit sends a fourth selection control signal to the first multiplexer, the first multiplexer shields the signals input from each cache unit in the first cache area, and the first multiplexer outputs the initial row data corresponding to the second cache area to the second circular shift module, and then performs a second circular shift on the initial row data to obtain the target row data.

[0164] On this basis, the reorganization module can be configured with a reorganization register 1 and a reorganization register 2. By using the ping-pong cache mechanism, the target row data is alternately written to the two reorganization registers by controlling the input signal of the address input terminal of the multiplexer. Ping-pong cache is realized in the process of matrix element reorganization. When the target row data in the reorganization register 1 is undergoing matrix element reorganization, the next set of target row data is written to the reorganization register 2, and when the target row data in the reorganization register 2 is undergoing matrix element reorganization, the next set of target row data is written to the reorganization register 1. The matrix elements can be reorganized in a full pipeline, thereby improving the transposition efficiency and having a high transposition performance. ; Wherein, when the number of matrix elements in the element set is two, a group of target row data includes two target row data, therefore, the reorganization register 1 includes jiont_0a and jiont_1a, and the reorganization register 2 includes jiont_0b and jiont_1b. When the reorganization register 1 processes a group of target row data, the first target row data is written to jiont_0a, and the second target row data is written to jiont_1a. In addition, when the reorganization register 2 processes a group of target row data, the first target row data is written to jiont_0b, and the second target row data is written to jiont_1b.

[0165] In one possible implementation, the processing unit of the artificial intelligence chip is capable of generating a first distribution control signal, a second distribution control signal, a fifth selection control signal, and a sixth selection control signal, the first distribution control signal and the second distribution control signal are both used to control the multiplexer, the first distribution control signal and the second distribution control signal are different, the fifth selection control signal and the sixth selection control signal are both used to control the third multiplexer, and the fifth selection control signal and the sixth selection control signal are different.

[0166] Exemplarily, based on the ping-pong cache mechanism, the processing unit adjusts the speed of alternately generating the first allocation control signal and the second allocation control signal according to the processing speed of the register control module for reorganizing the matrix elements of the target row data in each reorganization register, and adjusts the speed of alternately generating the fifth selection control signal and the sixth selection control signal. When the reorganization register 1 is in an idle state, the processing unit sends the first allocation control signal to the demultiplexer, and the demultiplexer outputs the target row data obtained by the cyclic shift module to the reorganization register 1. Similarly, when the reorganization register 2 is in an idle state, the processing unit sends the second allocation control signal to the demultiplexer, and the demultiplexer outputs the second cyclic shift module to the reorganization register 1. The target row data obtained by the circular shift module is output to the reorganization register 2; in addition, when the target row data in the reorganization register 1 completes the matrix element reorganization, the processing unit sends the fifth selection control signal to the third multiplexer, and the third multiplexer shields the signal input to the reorganization register 2, thereby causing the third multiplexer to output the target row data after the matrix element reorganization in the reorganization register 1; similarly, when the target row data in the reorganization register 2 completes the matrix element reorganization, the processing unit sends the sixth selection control signal to the third multiplexer, and the third multiplexer shields the signal input to the reorganization register 1, thereby causing the third multiplexer to output the target row data after the matrix element reorganization in the reorganization register 2.

[0167] Based on this, each cache unit will receive control signals from the read module and the write module. When it is necessary to write an element set of the shift matrix data to each cache unit, since the write address and timing of each cache unit are the same, only one write module is needed to generate a write signal. The write signal carries the element set and the storage address of the element set, and the write module broadcasts the write signal to each cache unit. When it is necessary to read the target element set in the cache unit, since the read address and timing of each cache unit are different, each cache unit needs to correspond to a read module, and the read module can send the read signal to the corresponding cache unit.

[0168] For example, when reading the target element set of each cache unit in the first cache area, each element set of the second shift matrix data is written to the corresponding cache unit in the second cache area. Since the write information of the write module will be broadcast to each cache unit, each cache unit in the first cache area will receive a read signal for reading the first cache area and a write signal for writing to the second cache area. The cache unit is a single-port RAM. The control signal required by each cache unit in the first cache area is the read signal for reading the first cache area. The write signal of the write module needs to be shielded. Therefore, the control signals of the write module and the read module are selected by setting a second multiplexer. The second multiplexer corresponds to the cache unit one by one. The second multiplexer corresponding to each cache unit in the first cache area can shield The write signal of the write module is shielded, and the read signal of the read module is output to each cache unit in the first cache area, and the second multiplexer corresponding to each cache unit in the second cache area can output the write signal of the write module to each cache unit in the second cache area; in addition, when reading the target element set of each cache unit in the second cache area, each element set of the next shift matrix data is written to the corresponding cache unit in the first cache area, the second multiplexer corresponding to each cache unit in the second cache area can shield the write signal of the write module, and output the read signal of the read module to each cache unit in the second cache area, and the second multiplexer corresponding to each cache unit in the first cache area can output the write signal of the write module to each cache unit in the first cache area.

[0169] At present, artificial intelligence chips use vector processors (VPUs) to complete the transposition operation of input matrix data. Specifically, the input matrix data is usually placed in a double data rate synchronous dynamic random access memory (DDR). DMA moves the input matrix data from the DDR to the first-level cache (L1 Cache). The VPU reads the input matrix data from the first-level cache by column, and then writes each column of the read data into the first-level cache by row, so that the data stored in the first-level cache is the transposed matrix data. The overall process of performing the transposition operation through the VPU is relatively long, and multiple read and write operations on the first-level cache are required, which has a high time complexity. Moreover, the VPU is a core technical resource. When the VPU performs the transposition operation, other core calculations, such as addition and multiplication operations, cannot be performed. The utilization rate of the core computing resources of the VPU is low. In addition, the VPU reads a column of input matrix data from the first-level cache by column, which requires the addressing of the first-level cache to support the addressing mode of the jump address, which has high requirements on the addressing mode of the first-level cache and the implementation complexity of the first-level cache is high.

[0170] Reference Fig.21 , Fig.21Another optional structural diagram of a chip provided in an embodiment of the present application, the chip includes:

[0171] The above-mentioned matrix data transposition device.

[0172] Wherein, the matrix data transposition device can be Fig.21 The direct memory access engine shown in the figure, the above chip can be an artificial intelligence chip, wherein the artificial intelligence chip can be deployed on a server or a terminal to provide high-performance, low-latency, and low-cost AI reasoning services for various scenarios. On the artificial intelligence chip, the transposition unit is integrated into the direct memory access engine by hardening the transposition unit. When the server or terminal responds to the neural network processing request, the initial matrix data extracted from the to-be-processed data carried by the neural network processing request can be stored in the off-chip memory, or the initial matrix data carried by the neural network processing request can be directly stored in the off-chip memory. The off-chip memory can be DDR, and the off-chip memory can also be or other types of memory, which are not limited here; then, when the initial matrix data needs to be transposed, the processing unit of the artificial intelligence chip sends a control instruction to the direct memory access engine. For example, the direct memory access engine includes but is not limited to: a first circular shift module, a write module, a plurality of read modules, a first multiplexer, a plurality of second multiplexers, a second circular shift module, two reorganization registers, a register control module, a multiplexer, and a third multiplexer. The processing unit sends a control instruction to the direct memory access engine to enable the direct memory access engine to execute the direct memory access operation. The engine moves the initial matrix data from the DDR. During the movement of the initial matrix data, the processing unit can send corresponding control instructions to the first multiplexer, the second multiplexer, the third multiplexer and the multiplexer of the direct memory access engine, so that the direct memory access engine can transpose the initial matrix data while moving the initial matrix data, and directly write the transposed matrix data to the first-level cache. The overall process of the transposition operation is short, which can effectively reduce the time complexity. During the transposition operation, at least two adjacent matrix elements are used as element sets. By writing the element sets into the cache unit, the number of instantiations of the cache unit in the artificial intelligence chip can be effectively reduced, thereby reducing the area of ​​the artificial intelligence chip. Therefore, the embodiment of the present application provides a high-surface-efficiency online transposition engine, which can effectively reduce the area of ​​the artificial intelligence chip while improving the transposition performance. In addition, the artificial intelligence chip does not need to use the VPU when transposing the matrix data, which is equivalent to releasing the VPU. The VPU can be used in computing-intensive scenarios to improve the utilization rate of core computing resources. Moreover, the addressing method of the first-level cache is relatively low, and the addressing of the first-level cache only needs to support linear addressing, which effectively reduces the implementation complexity of the first-level cache.

[0173] The electronic device for executing the above-mentioned matrix data transposition method provided in the embodiment of the present application may be a terminal. Fig. 22 , Fig. 22 This is a partial structural block diagram of a terminal provided in an embodiment of the present application. The terminal includes: a camera assembly 2210, a memory 2220, an input unit 2230, a display unit 2240, a sensor 2250, an audio circuit 2260, a wireless fidelity (WiFi) module 2270, a processor 2280, and a power supply 2290. Those skilled in the art can understand that Fig. 22 The terminal structure shown in the figure does not constitute a limitation on the terminal, and may include more or less components than shown in the figure, or combine certain components, or arrange the components differently.

[0174] The camera assembly 2210 can be used to capture images or videos. Optionally, the camera assembly 2210 includes a front camera and a rear camera. Typically, the front camera is disposed on the front panel of the terminal, and the rear camera is disposed on the back of the terminal. In some embodiments, there are at least two rear cameras, which are any one of a main camera, a depth of field camera, a wide-angle camera, and a telephoto camera, so as to realize the fusion of the main camera and the depth of field camera to realize the background blur function, the fusion of the main camera and the wide-angle camera to realize the panoramic shooting and VR (Virtual Reality) shooting function or other fusion shooting functions.

[0175] The memory 2220 may be used to store software programs and modules. The processor 2280 executes various functional applications and data processing of the terminal by running the software programs and modules stored in the memory 2220 .

[0176] The input unit 2230 may be used to receive input digital or character information and generate key signal input related to the terminal's settings and function control. Specifically, the input unit 2230 may include a touch panel 2231 and other input devices 2232 .

[0177] The display unit 2240 may be used to display input information or provided information and various menus of the terminal. The display unit 2240 may include a display panel 2241.

[0178] The audio circuit 2260, the speaker 2261, and the microphone 2262 may provide an audio interface.

[0179] The power source 2290 may be alternating current, direct current, a disposable battery, or a rechargeable battery.

[0180] The number of sensors 2250 may be one or more, and the one or more sensors 2250 include but are not limited to: acceleration sensors, gyroscope sensors, pressure sensors, optical sensors, etc. Among them:

[0181] The acceleration sensor can detect the magnitude of acceleration on the three coordinate axes of the coordinate system established by the terminal. For example, the acceleration sensor can be used to detect the components of gravity acceleration on the three coordinate axes. The processor 2280 can control the display unit 2240 to display the user interface in a horizontal view or a vertical view according to the gravity acceleration signal collected by the acceleration sensor. The acceleration sensor can also be used for collecting game or user motion data.

[0182] The gyroscope sensor can detect the body direction and rotation angle of the terminal, and the gyroscope sensor can cooperate with the acceleration sensor to collect the user's 3D actions on the terminal. The processor 2280 can implement the following functions based on the data collected by the gyroscope sensor: motion sensing (such as changing the UI according to the user's tilt operation), image stabilization during shooting, game control, and inertial navigation.

[0183] The pressure sensor can be set in the side frame of the terminal and / or the lower layer of the display unit 2240. When the pressure sensor is set in the side frame of the terminal, the user's holding signal of the terminal can be detected, and the processor 2280 performs left and right hand recognition or shortcut operation according to the holding signal collected by the pressure sensor. When the pressure sensor is set in the lower layer of the display unit 2240, the processor 2280 controls the operability controls on the UI interface according to the user's pressure operation on the display unit 2240. The operability control includes at least one of a button control, a scroll bar control, an icon control, and a menu control.

[0184] The optical sensor is used to collect the ambient light intensity. In one embodiment, the processor 2280 can control the display brightness of the display unit 2240 according to the ambient light intensity collected by the optical sensor. Specifically, when the ambient light intensity is high, the display brightness of the display unit 2240 is increased; when the ambient light intensity is low, the display brightness of the display unit 2240 is reduced. In another embodiment, the processor 2280 can also dynamically adjust the shooting parameters of the camera assembly 2210 according to the ambient light intensity collected by the optical sensor.

[0185] In this embodiment, the processor 2280 included in the terminal can execute the matrix data transposition method of the previous embodiment.

[0186] The electronic device for executing the above-mentioned matrix data transposition method provided in the embodiment of the present application may also be a server, referring to Fig.23 , Fig.23Partial structural block diagram of the server provided in the embodiment of the present application, the server 2300 may have relatively large differences due to different configurations or performances, and may include one or more central processing units (CPU) 2323 (for example, one or more processors) and memory 2332, one or more storage media 2330 (for example, one or more mass storage devices) storing application programs 2342 or data 2344. Among them, the memory 2332 and the storage medium 2330 can be short-term storage or permanent storage. The program stored in the storage medium 2330 may include one or more modules (not shown in the figure), and each module may include a series of instruction operations in the server 2300. Furthermore, the central processing unit 2323 can be configured to communicate with the storage medium 2330 and execute a series of instruction operations in the storage medium 2330 on the server 2300.

[0187] The server 2300 may also include one or more power supplies 2326, one or more wired or wireless network interfaces 2350, one or more input and output interfaces 2358, and / or one or more operating systems 2341, such as Windows ServerTM, Mac OS XTM, UnixTM, LinuxTM, FreeBSDTM, etc.

[0188] The processor in the server 2300 can be used to execute the matrix data transposition method.

[0189] An embodiment of the present application further provides a computer-readable storage medium, which is used to store program codes, and the program codes are used to execute the matrix data transposition methods of the aforementioned embodiments.

[0190] The embodiment of the present application also provides a computer program product, which includes a computer program stored in a computer-readable storage medium. A processor of a computer device reads the computer program from the computer-readable storage medium, and the processor executes the computer program, so that the computer device executes the above-mentioned matrix data transposition method.

[0191] The terms "first", "second", "third", "fourth", etc. (if any) in the specification of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein, for example. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0192] It should be understood that in the present application, "at least one (item)" means one or more, and "plurality" means two or more. "And / or" is used to describe the association relationship of associated objects, indicating that three relationships may exist. For example, "A and / or B" can mean: only A exists, only B exists, and A and B exist at the same time, where A and B can be singular or plural. The character " / " generally indicates that the objects associated before and after are in an "or" relationship. "At least one of the following" or similar expressions refers to any combination of these items, including any combination of single or plural items. For example, at least one of a, b or c can mean: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, c can be single or multiple.

[0193] It should be understood that in the description of the embodiments of the present application, the meaning of multiple (or multiple items) is more than two, greater than, less than, exceed, etc. are understood to not include the number, and above, below, within, etc. are understood to include the number.

[0194] In the several embodiments provided in the present application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.

[0195] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0196] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0197] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the various embodiments of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (Read-Only Memory, referred to as ROM), random access memory (Random Access Memory, referred to as RAM), disk or optical disk and other media that can store program codes.

[0198] It should also be understood that the various implementations provided in the embodiments of the present application can be combined arbitrarily to achieve different technical effects.

[0199] The above is a specific description of the preferred implementation of the present application, but the present application is not limited to the above implementation mode. Technical personnel familiar with the field can also make various equivalent modifications or substitutions under the shared conditions without violating the spirit of the present application. These equivalent modifications or substitutions are all included in the scope defined by the claims of the present application.

Claims

1. A matrix data transposition method, characterized in that: include: Acquire initial matrix data, and perform a first cyclic shift on the initial matrix data to obtain shifted matrix data; In each row of the shift matrix data, at least two adjacent matrix elements are used as an element set, and each element set is written into a corresponding cache unit according to a column range to which the element set belongs in the shift matrix data; Reading a target element set from each of the cache units, combining the target element sets belonging to the same column range in the initial matrix data to obtain at least two target row data; Matrix elements are reorganized between at least two of the target row data, and the transposed initial matrix data is obtained according to the target row data after the matrix elements are reorganized.

2. The matrix data transposition method according to claim 1, characterized in that: The matrix data transposition method is applied to a direct memory access engine, and the matrix data transposition method further comprises: The direct memory access engine sends the transposed initial matrix data to a first-level cache.

3. The matrix data transposition method according to claim 1, characterized in that: The reading of the target element set from each of the cache units includes: According to the number of the matrix elements in the element set, the storage addresses in each of the cache units are evenly divided into at least two target address ranges; A target element set is read from the same target address range of each cache unit, wherein a plurality of the target element sets have the same column range in the initial matrix data.

4. The matrix data transposition method according to claim 3, characterized in that: The number of the matrix elements in the element set and the number of the target address ranges are both two; the target element set is read from the same target address range of each cache unit to combine the target element sets belonging to the same column range in the initial matrix data to obtain at least two target row data, including: Combining the target element sets read from one of the target address ranges of each of the cache units to obtain one of the target row data; The target element sets read from another target address range of each cache unit are combined to obtain another target row of data.

5. The matrix data transposition method according to claim 4, characterized in that: The reorganizing of matrix elements between at least two target row data includes: splicing the matrix elements located at odd positions in the two target row data to obtain the target row data after reorganizing the matrix elements in one of the two target row data; and, The matrix elements located at even-numbered positions in two target row data are concatenated to obtain another target row data after matrix element reorganization.

6. The matrix data transposition method according to claim 1, characterized in that: The first cyclic shifting of the initial matrix data to obtain shifted matrix data includes: Traversing the matrix elements of each row of the initial matrix data; Perform a first cyclic shift on the matrix elements in the i-th row in the initial matrix data so that the matrix elements in the i-th row are cyclically shifted by (n*i)-n positions, wherein both i and n are positive integers, and n is the number of the matrix elements in the element set.

7. The matrix data transposition method according to claim 6, characterized in that: Writing each element set into a corresponding cache unit includes: Traversing each row of data of the shift matrix data; The j-th element set of the i-th row data in the shift matrix data is written into the storage space pointed to by the i-th storage address in the j-th cache unit, wherein j is a positive integer.

8. The matrix data transposition method according to claim 1, characterized in that: The step of combining the target element sets belonging to the same column range in the initial matrix data to obtain at least two target row data includes: Combining the target element sets belonging to the same column range in the initial matrix data to obtain at least two initial row data; Perform a second cyclic shift on the initial row data to obtain target row data, wherein the second cyclic shift is in a direction opposite to that of the first cyclic shift.

9. The matrix data transposition method according to claim 8, characterized in that: The performing a second cyclic shift on the initial row data comprises: Determining the arrangement order of each column range in the initial matrix data; A second circular shift is performed on the initial row data so that the initial row data is circularly shifted by (n*k)-n positions, wherein n and k are both positive integers, n is the number of the matrix elements in the element set, and k is the arrangement order of the column range to which the initial row data belongs in the initial matrix data.

10. The matrix data transposition method according to any one of claims 1 to 9, characterized in that: The reading of the target element set from each of the cache units includes: Reading a target element set from each of the cache units in the first cache area, and writing each of the element sets of the next shift matrix data into the corresponding cache unit in the second cache area; Wherein, the first cache area and the second cache area each include a plurality of cache units.

11. The matrix data transposition method according to claim 10, characterized in that: The step of reading a target element set from each of the cache units in the first cache area and writing each of the element sets of the next shift matrix data into the corresponding cache unit in the second cache area comprises: Determine control signals of the first buffer area and the second buffer area, wherein the control signals include a write signal and a read signal, when the control signal of the first buffer area is the read signal, the control signal of the second buffer area is the write signal, and when the control signal of the second buffer area is the read signal, the control signal of the first buffer area is the write signal; In a case where the control signal of the first cache area is the read signal, a target element set is read from each of the cache units in the first cache area in response to the control signal of the first cache area, and each of the element sets of the next shift matrix data is written to the corresponding cache unit in the second cache area in response to the write signal of the second cache area.

12. The matrix data transposition method according to any one of claims 1 to 9, characterized in that: The reorganizing of matrix elements between at least two target row data includes: determining a target reorganization register in an idle state among a plurality of reorganization registers; At least two of the target row data are written into the target reorganization register, and matrix elements of the at least two of the target row data in the target reorganization register are reorganized.

13. A matrix data transposition device, characterized in that: include: A first cyclic shift module is used to obtain initial matrix data, perform a first cyclic shift on the initial matrix data, and obtain shifted matrix data; A writing module, used to take at least two adjacent matrix elements in each row of the shift matrix data as an element set, and write each element set into a corresponding cache unit according to a column range to which the element set belongs in the shift matrix data; A combining module, configured to read a target element set from each of the cache units, and combine the target element sets belonging to the same column range in the initial matrix data to obtain at least two target row data; The reorganization module is used to reorganize matrix elements between at least two of the target row data, and obtain the transposed initial matrix data according to the target row data after the matrix element reorganization.

14. The matrix data transposition device according to claim 13, characterized in that: The combination module includes a second cyclic shift module and a reading module having the same number as the cache units; The reading module is used to read the target element set from the corresponding cache unit, and combine the target element sets belonging to the same column range in the initial matrix data to obtain at least two initial row data; The second cyclic shift module is used to perform a second cyclic shift on the initial row data to obtain target row data, wherein the second cyclic shift is in the opposite direction to the first cyclic shift.

15. The matrix data transposition device according to claim 14, characterized in that: The combining module further comprises a first multiplexer, the first multiplexer being used for stopping writing the initial row data corresponding to the first buffer area into the second cyclic shift module when writing the initial row data corresponding to the first buffer area into the second cyclic shift module, and stopping writing the initial row data corresponding to the first buffer area into the second cyclic shift module when writing the initial row data corresponding to the second buffer area into the second cyclic shift module; Wherein, the first cache area and the second cache area each include a plurality of cache units.

16. The matrix data transposition device according to claim 13, characterized in that: It also includes a second multiplexer with the same number as the cache units, and the second multiplexer is used to stop the writing module from writing the element set to the corresponding cache unit when the combination module reads the target element set from the corresponding cache unit.

17. The matrix data transposition device according to claim 13, characterized in that: The reorganization module comprises a reorganization register and a register control module, the reorganization register is used to write at least two target row data, and the register control module is used to reorganize matrix elements of at least two target row data in the reorganization register.

18. The matrix data transposition device according to claim 17, characterized in that: The reorganization module comprises a demultiplexer, a third multiplexer and a plurality of the reorganization registers; The demultiplexer is used to write at least two of the target row data into a target reorganization register, wherein the target reorganization register refers to the reorganization register in an idle state; The third multiplexer is used to output the target row data after matrix element reorganization by the target reorganization register to obtain the transposed initial matrix data.

19. A chip, characterized in that: include: A matrix data transposition device as claimed in any one of claims 13 to 18.

Citation Information

Cited By

  • Transposition circuit, transposition method and related device

    CN119864059A

  • Matrix parallel operation device and method

    CN120256064A

  • Method and computing device for transposing matrix

    KR102945674B1