Data preprocessing method and device
By creating index columns in the CPU and sending them to the DSA to construct the matrix, the problem of high data transmission bandwidth and low efficiency in heterogeneous computing is solved, and matrix acceleration and query efficiency are improved.
Patent Information
- Application Number
- CN202310344765.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-03-31
- Publication Date
- 2024-10-15
AI Technical Summary
In heterogeneous computing, how to efficiently convert raw data into corresponding coefficient matrices to accelerate SQL query calculations? In the existing technology, all raw data need to be sent to DSA to construct the coefficient matrix, resulting in high data transmission bandwidth and low efficiency.
By creating index columns in the CPU of the computing device, a matrix corresponding to the original data is constructed, and only the index columns are sent to the DSA, thereby reducing data transmission and improving matrix construction efficiency.
It saves the data transmission bandwidth between the computing device and the DSA, improves the efficiency of coefficient matrix construction and query algorithm acceleration, and reduces the cost of data processing.
Smart Images

Figure CN118779343A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a data preprocessing method and device. Background Art
[0002] The development of computing technology has gone through three stages: single-core computing, multi-core computing, and heterogeneous computing. Among them, the most commonly used solution for heterogeneous computing is to use a domain-specific accelerator (DSA) built with a matrix-multiplication accelerator (MMA) to perform calculations. As the name suggests, MMA can directly complete the multiplication calculation of two matrices.
[0003] In order to improve the efficiency of structured query language (SQL) queries, SQL query calculations can be performed through DSA. In this process, the original data to be queried needs to be converted into the corresponding coefficient matrix, and the query algorithm needs to be equivalently converted into matrix multiplication. In this way, DSA can obtain the query result by performing the corresponding matrix multiplication based on the original data converted to the corresponding coefficient matrix. Therefore, how to convert the original data to be queried into the corresponding coefficient matrix has become a technical problem that needs to be solved urgently. Summary of the invention
[0004] The present application provides a data preprocessing method and device, which can construct a matrix corresponding to the original data required for performing matrix multiplication corresponding to a query algorithm on the original data, so as to achieve algorithm acceleration.
[0005] To achieve the above objectives, this application provides the following technical solutions:
[0006] In a first aspect, the present application provides a data preprocessing method, which is applied to a central processing unit (CPU) of a computing device, and the method includes: obtaining first original data including an element column and an element value column; creating a first index column of the first original data, and the first index column of the first original data is used to construct a first matrix corresponding to the first original data. The element column of the first original data includes a plurality of elements, and the element value column includes an element value corresponding to each of the plurality of elements. The first index column of the first original data has the same column length as the element column of the first original data, and includes the index value of each element in the element column of the first original data.
[0007] In this way, in a scenario where a computing device needs to accelerate the processor through DSA, the method of the present application can construct a matrix corresponding to the original data required to perform matrix multiplication corresponding to the query algorithm on the original data, thereby achieving algorithm acceleration.
[0008] In a possible design, the computing device is further configured with a DSA, and the first matrix is used by the DSA to perform aggregation calculations on the first original data, or is used by the DSA to count the number of each element in an element column of the first original data.
[0009] Through this possible design, the matrix constructed by the method of the present application can be used in a variety of scenarios that require matrix operations to achieve algorithm acceleration.
[0010] In another possible design, the method further includes: sending a first index column to the DSA, where the first index column is specifically used by the DSA to construct a first matrix.
[0011] Through this possible design, compared with the solution of sending the original data to the DSA of the computing device so that the DSA constructs the corresponding coefficient matrix based on the original data, the method provided by the present application only needs to send the index column of the original data to the DSA. Therefore, the solution provided by the present application can save the data transmission bandwidth between the computing device processor and the DSA.
[0012] In another possible design, the method further includes: constructing a first matrix according to the first index column.
[0013] Through this possible design, after constructing the first matrix, the processor of the computing device can send the constructed first matrix to the DSA, so that the DSA does not need to bear the algorithm of constructing the first matrix, but only needs to perform the corresponding matrix multiplication operation according to the first matrix received from the processor to achieve algorithm acceleration of the corresponding algorithm.
[0014] In another possible design, the above-mentioned creation of the first index column of the first original data includes: setting an index value for each element in the element column of the first original data through a hash table constructed based on the element column of the first original data. The first index column is created according to the index value of each element in the element column of the first original data. Through this possible design, the index column of the original data can be quickly constructed.
[0015] In another possible design, when multiple rows of data are added to the first original data, the method further includes: creating a newly added index column according to the elements in the multiple rows of data, each element in the first original data element column and the corresponding index value. The column length of the newly added index column is the same as the number of rows of the aforementioned multiple rows of data, and includes the index value corresponding to each element in the multiple rows of data, and the newly added index column is used to update the first matrix.
[0016] In another possible design, the method further includes: sending the newly added index column to a DSA configured on the computing device, where the newly added index column is specifically used by the DSA to update the first matrix.
[0017] Through this possible design, when the coefficient matrix (i.e., the first matrix) corresponding to the first original data is updated by the DSA based on the index column of the newly added data, compared to sending all the first original data including the newly added data to the DSA of the computing device so that the DSA can reconstruct the corresponding coefficient matrix based on the first original data including the newly added data, the method provided by the present application only needs to send the index column of the newly added data to the DSA, and the DSA can update the coefficient matrix corresponding to the first original data not including the newly added data based on the index column of the newly added data, without the need to reconstruct the coefficient matrix of the first original data including the newly added data. Moreover, when the first original data is newly added, when it is necessary to perform aggregate calculation on the first original data after the newly added data, it is only necessary to send the element value column of the newly added data to the DSA. Therefore, the method provided by the present application can not only save the data transmission bandwidth between the computing device processor and the DSA, but also improve the efficiency of constructing the coefficient matrix.
[0018] In another possible design, the number of row vectors in the first matrix is the number of index values included in the first index column, and the number of column vectors in the first matrix is the number of different index values in the first index column. For the first row vector in the first matrix, when the row in the first index column that is the same as the number of rows of the first row vector in the first matrix is the first target row, and the bit number of the index value in the first target row is j, then the value of the jth data in the first row vector is 1, and the values of the remaining data are 0. Among them, j is a positive integer less than or equal to the number of column vectors, and the bit number of the index value is the sorting number after the different index values in the first index column are sorted by size.
[0019] In another possible design, when the first matrix includes n column vectors, the method further includes: obtaining second original data. The element column of the second original data and the element column of the first original data include the same elements, and the second matrix corresponding to the second original data and the first matrix described above are used to perform a connection calculation on the first original data and the second original data. The number of row vectors in the second matrix is the number of rows of the second original data, and the number of column vectors in the second matrix is the same as the number of column vectors in the first matrix.
[0020] In another possible design, the method further includes: constructing the second matrix according to the elements in the second original data, the elements in the first original data and the corresponding index values. Alternatively, sending the element columns of the second original data and the elements in the first original data and the corresponding index values to the DSA configured on the computing device, so that the DSA constructs the second matrix.
[0021] In another possible design, for the second row vector in the second matrix, when the row in the index column of the second original data that has the same number of rows as the second row vector in the second matrix is the second target row, and the bit number of the index value in the second target row is k, the value of the kth data in the second row vector is 1, and the values of the remaining data are 0. Wherein k is a positive integer, and the bit number of the index value is the sorting number after different index values in the first index column are sorted by size.
[0022] Through the above-mentioned several possible designs, a coefficient matrix required for accelerating the concatenation operation on the first original data and the second original data can be constructed to achieve acceleration of the concatenation algorithm.
[0023] In another possible design, the above-mentioned original data is data in a column database. As an example, the original data described in this application can be column data in an SQL database.
[0024] In the second aspect, the present application provides a data preprocessing device, which is used to execute any of the methods provided by the above-mentioned first aspect and any possible design thereof. The present application may divide the preprocessing device into functional modules according to any of the methods provided by the above-mentioned first aspect. For example, each functional module may be divided according to each function, or two or more functions may be integrated into one processing module. Exemplarily, the present application may divide the preprocessing device into an acquisition unit and a processing unit, etc. according to the function. The description of the possible technical solutions and beneficial effects executed by each of the above-mentioned divided functional modules can refer to the technical solutions provided by the above-mentioned first aspect or its corresponding possible design, which will not be repeated here.
[0025] In a third aspect, the present application provides a processor configured to read program instructions stored in a memory to execute any method provided in the first aspect and any possible design thereof.
[0026] In a fourth aspect, the present application provides a computer-readable storage medium, which includes program instructions. When the program instructions are executed on a processor, the processor executes any method provided by any possible implementation of the first aspect.
[0027] In a fifth aspect, the present application provides a computer program product, which, when executed on a data preprocessing device, enables any method provided by any possible implementation in the first aspect to be executed.
[0028] It can be understood that any of the above-mentioned devices, computer storage media or computer program products can be applied to the corresponding methods provided above. Therefore, the beneficial effects that can be achieved can refer to the beneficial effects in the corresponding methods and will not be repeated here.
[0029] In this application, the name of the data preprocessing device does not limit the device or functional module itself. In actual implementation, these devices or functional modules may appear with other names. As long as the functions of each device or functional module are similar to those of this application, they fall within the scope of the claims of this application and their equivalent technologies. BRIEF DESCRIPTION OF THE DRAWINGS
[0030] Figure 1 A schematic diagram of the hardware structure of a computing device provided in an embodiment of the present application;
[0031] Figure 2 A schematic diagram of a data preprocessing method provided in an embodiment of the present application;
[0032] Figure 3 A schematic diagram of a process for constructing a first matrix based on preprocessed data provided in an embodiment of the present application;
[0033] Figure 4 A schematic diagram of another process of constructing a first matrix based on preprocessed data provided in an embodiment of the present application;
[0034] Figure 5 A schematic diagram of a flow chart of another data preprocessing method provided in an embodiment of the present application;
[0035] Figure 6 A schematic diagram of a flow chart of another data preprocessing method provided in an embodiment of the present application;
[0036] Figure 7 A schematic diagram of the structure of a data preprocessing device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0037] In order to more clearly understand the embodiments of the present application, some terms or technologies involved in the embodiments of the present application are explained below:
[0038] 1) Aggregate Calculation
[0039] Aggregate calculation is to add up the element values of each element in the data table to obtain the sum of the element values of each element in the data table. The same elements in the data table are called one element.
[0040] For example, it is assumed that the data table a is as shown in the following Table 1:
[0041] Table 1
[0042] element Element value 1 ship 5.1 bus 4.0 ship 3.2 airplane 9.3
[0043] When performing aggregation calculation on data table a, the element values of the element "ship" in data table a are actually summed (that is, 5.1 and 3.2 are summed), the element values of the element "bus" in data table a are summed, and the element values of the element "airplane" in data table a are summed.
[0044] 2) Join calculation
[0045] For two data tables including the same elements, the join calculation refers to summarizing the element values of the same elements in the two tables based on the common elements in the two tables, thereby joining the two data tables into one data table.
[0046] For example, assume that data table b is as shown in Table 2 below:
[0047] Table 2
[0048] element Element value 2 ship A airplane B
[0049] When data table b is connected to the data table a described above, based on the same elements "ship" and "airplane" in Table 1 and Table 2, the element values of these two elements in Table 2 are summarized in Table 1, so that Table 1 and Table 2 are connected into one table, as shown in Table 3:
[0050] Table 3
[0051] element Element value 1 Element value 2 ship 5.1 A bus 4.0 - ship 3.2 A airplane 9.3 B
[0052] 3) Other terms
[0053] In the embodiments of the present application, words such as "exemplary" or "for example" are used to indicate examples, illustrations or descriptions. Any embodiment or design described as "exemplary" or "for example" in the embodiments of the present application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplary" or "for example" is intended to present related concepts in a specific way.
[0054] In the embodiments of the present application, the terms "first" and "second" are used for descriptive purposes only and are not to be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of the features.
[0055] The term "at least one" in this application means one or more. Unless otherwise specified, the term "plurality" in this application means two or more.
[0056] It should also be understood that the term "and / or" used in this article refers to and covers any and all possible combinations of one or more of the associated listed items. The term "and / or" is a description of the association relationship of associated objects, indicating that three relationships can exist. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the characters "three" in this application generally indicate that the objects associated before and after are in an "or" relationship.
[0057] The embodiment of the present application provides a data preprocessing method, which is applied to a central processing unit (CPU) of a computing device. The method creates an index column including the index value of each element in the original data in the original data, so that the computing device can construct a coefficient matrix corresponding to the original data based on the index column. Furthermore, the DSA configured by the computing device performs the matrix multiplication corresponding to the query algorithm according to the coefficient matrix corresponding to the original data, so as to realize the query operation on the original data, thereby obtaining the query result.
[0058] In the embodiment of the present application, the above-mentioned original data is data stored in a column structure. For example, the original data is column data in a column database (such as a SQL database).
[0059] Specifically, the raw data described in the embodiment of the present application includes an element column and an element value column with the same column length, where the column length can be understood as the number of rows included in the data column. Among them, the element column of the raw data includes multiple elements, and the element value column of the raw data includes the element value corresponding to each element in the aforementioned multiple elements. In the raw data, each row of data of the raw data includes an element and one or more element values of the element. In addition, the elements in the element column of the raw data can be different elements from each other. Of course, the same elements can also be included in the element column, which is not limited to this. As an example, the raw data can be the data table a shown in Table 1 above, or the data table b shown in Table 2, and so on.
[0060] The present application also provides a data preprocessing device, which is used to execute the method provided in the present application. The preprocessing device can be any computing device with computing processing capabilities, or a functional module in the computing device, without limitation.
[0061] Optionally, the computing device may be a terminal device such as a general-purpose computer, a laptop computer or a tablet, or the computing device may be a server, without limitation.
[0062] Taking the above computing device as an example, reference Figure 1 , Figure 1 FIG. 1 is a schematic diagram showing a hardware structure of a computing device provided in an embodiment of the present application. Figure 1 As shown, the computing device 10 includes a processor 101, a memory 102, a communication interface 103, a DSA 104, and a bus 105. The processor 101, the memory 102, the communication interface 103, and the DSA 104 are connected and communicated through the bus 105.
[0063] Processor 101 is the control center of computing device 10 and may be a general-purpose CPU. Processor 101 may also be other general-purpose processors, digital signal processors (digital signal processing, DSP), application-specific integrated circuits (application-specific integrated circuits, ASIC), field-programmable gate arrays (field-programmable gate arrays, FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, graphics processing units (graphics processing units, GPU), neural processing units (neural processing units, NPU), tensor processing units (tensor processing units, TPU) or artificial intelligence (artificial intelligent) chips, data processors (data processing units, DPU), etc.
[0064] As an example, the processor 101 includes one or more CPUs, such as Figure 1 In addition, the present application does not limit the number of processor cores in each processor.
[0065] The memory 102 is used to store program instructions or data to be accessed by the application process. The processor 101 can implement the data preprocessing method provided in the embodiment of the present application by executing the program instructions in the memory 102.
[0066] The memory 102 includes a volatile memory or a nonvolatile memory, or may include both volatile and nonvolatile memories. Among them, the volatile memory may be a read-only memory (ROM), a programmable ROM (PROM), an erasable programmable ROM (EPROM), an electrically erasable programmable ROM (EEPROM), or a flash memory. The volatile memory may be a random access memory (RAM), which is used as an external cache. By way of example but not limitation, many forms of RAM are available, such as static RAM (SRAM), dynamic random access memory (DRAM), synchronous DRAM (SDRAM), double data rate synchronous dynamic random access memory (DDRSDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous link DRAM (SLDRAM) and direct rambus RAM (DR RAM). Non-volatile memory can be storage class memory (SCM), solid state drive (SSD), hard disk drive (HDD), etc. Among them, storage class memory can be, for example, non-volatile memory (NVM), phase-change memory (PCM), persistent memory, etc.
[0067] In one possible implementation, the memory 102 exists independently of the processor 101. The memory 102 is connected to the processor 101 via a bus 105 and is used to store data, instructions, or program codes. When the processor 101 calls and executes the instructions or program codes stored in the memory 102, the data preprocessing method provided in the embodiment of the present application can be implemented.
[0068] In another possible implementation, the memory 102 and the processor 101 are integrated together.
[0069] The communication interface 103 is used to connect the computing device 10 to other devices (such as devices for storing raw data) through a communication network, and the communication network can be Ethernet, a radio access network (RAN), a wireless local area network (WLAN), etc. The communication interface 103 includes a receiving unit for receiving data / messages and a sending unit for sending data / messages.
[0070] The DSA 104 may be any chip or device including an MMA, and is not limited thereto. For example, the DSA may be a GPU including an MMA.
[0071] Generally, DSA can be used to accelerate the processor 101. For example, DSA accelerates the processor 101 by taking on a portion of the data operations originally performed by the processor 101.
[0072] The bus 105 may be an industry standard architecture (ISA) bus, a peripheral component interconnect (PCI) bus, a high-speed serial computer expansion bus (PCIe), a compute express link (CXL) or an extended industry standard architecture (EISA) bus. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 1 Only one thick line is used in the diagram, but this does not mean that there is only one bus or only one type of bus.
[0073] It should be pointed out that Figure 1 The structure shown in the figure does not constitute a limitation on the computing device 10, except Figure 1 In addition to the components shown, the computing device 10 includes Figure 1 More or fewer components may be shown, or certain components may be combined, or the components may be arranged differently.
[0074] The data preprocessing method provided in the embodiment of the present application is described below in conjunction with the accompanying drawings.
[0075] refer to Figure 2 , Figure 2 A schematic diagram of a data preprocessing method provided in an embodiment of the present application is shown, which can be applied to Figure 1The computing device of the hardware structure shown in the figure. The method comprises the following steps.
[0076] S101: A processor of a computing device obtains first original data.
[0077] The first original data includes an element column and an element value column with the same column length. The detailed description of the first original data can refer to the description of the original data above, which will not be repeated here.
[0078] As an example, assume that the element column of the first original data includes m (m is a positive integer) elements, and correspondingly, the element value column of the first original data includes m element values. In this case, the m elements correspond to the m element values one by one. Moreover, the m elements in the first original data may be different elements, or the m elements may include the same elements, which is not limited.
[0079] Optionally, the first original data is pre-stored in the memory of the computing device. In this case, the processor of the computing device can read the first original data from the memory.
[0080] Optionally, the computing device may send a data acquisition request to the server (or other device) to request to acquire the first original data stored in the server (or other device).
[0081] S102: A processor of the computing device creates a first index column of first original data, where the first index column includes an index value of each element in an element column of the first original data, and the first index column is used to construct a first matrix corresponding to the first original data.
[0082] The column length of the first index column is the same as the column length of the first original data element column (or element value column). The index value in the first index column is the index value set by the computing device for each element in the first original data element column. In addition, different elements in the first original data element column correspond to different index values, and the same elements correspond to the same index value.
[0083] Taking the first original data element column including m elements as an example, the first index column includes m index values. When the aforementioned m elements are different elements, the m index values in the first index column are different. When the aforementioned m elements include the same element, and assuming that the number of different elements in the m elements is n, and n is a positive integer less than or equal to m, then correspondingly, the m index values in the first index column include n different index values.
[0084] Optionally, the process of the processor of the computing device creating the first index column in the first original data may be implemented by the following steps S1021 to S1022:
[0085] S1021. The processor of the computing device sets an index value for each element in the first original data element column by constructing a hash table based on the element column of the first original data.
[0086] Specifically, the processor of the computing device sets the same index value for the same elements in the first original data element column, and sets different index values for different elements.
[0087] The processor of the computing device may first preset a hash table, the number of hash addresses included in the hash table being greater than or equal to the number of elements in the element column in the first original data. For example, assuming that the element column of the first original data includes m elements, the hash table preset by the processor of the computing device may include at least m hash addresses.
[0088] Next, the processor of the computing device performs a hash calculation on the first element in the first original data element column to obtain a first result, and writes the index value set for the first element into the hash address corresponding to the first result in the preset hash table, and records the keyword (key) of the hash address as the first element. The first element may be an element in the first row of the first original data element column, an element in the last row of the first original data element column, or an element in any row of the first original data element column, without limitation. In addition, the index value set for the first element may be any preset number, such as 0, 1, 2, etc., without limitation.
[0089] Then, the computing device performs a hash calculation on the second element in the first original data element column to obtain a second result, and queries the hash table to see whether the hash address corresponding to the second result has been written into the index value. The second element can be any element in the first original data except the first element, and this is not limited.
[0090] When it is determined that the hash address corresponding to the second result in the above hash table has the index value written into it, in this case, it means that the second element is the same as the element indicated by the key of the hash address (ie, the first element), so the two have the same index value.
[0091] When it is determined that the hash address corresponding to the second result in the hash table has no index value written in it, the processor of the computing device writes the index value set for the second element in the hash address corresponding to the second result, and records the key of the hash address as the second element. The index value set for the second element is any preset value different from the index value written in the hash table.
[0092] Furthermore, similar to the processing process of the second element, the processor of the computing device performs hash calculations on each element in the first original data element column except the first element and the second element and performs corresponding operations, and writes the index value set for each element in the hash table. Thus, the purpose of setting an index value for each element in the element column of the first original data is achieved. Among them, the same element is called an element.
[0093] It should be understood that when the processor of the computing device performs hash calculation on each element in the first original data element column, the hash algorithm used is the same, and the embodiment of the present application does not specifically limit the hash algorithm.
[0094] In practice, for ease of operation, the processor of the computing device generally performs hash calculations and corresponding operations on each element in the element column in sequence from top to bottom (or from bottom to top) of the first original data element column, so as to achieve the purpose of setting index values for each element in the first original data element column in sequence from top to bottom (or from bottom to top) of the element column.
[0095] It should also be understood that when constructing the coefficient matrix corresponding to the first original data (i.e., the first matrix described below) based on the index value of each element in the first original data element column, it is necessary to sort the index values of different elements in the first original data element column, and construct the coefficient matrix based on the sorting sequence number of each element (i.e., the bit sequence number described in the embodiment of the present application), please refer to the following description for details, which will not be repeated here. For simple operation, when setting the index value for each element of the first original data element column in the order of the element column from top to bottom (or from bottom to top), the index value can be set to increase or decrease in sequence with any value as the starting value. For example, starting from 0, and the index value is set to increase in sequence at an interval of 1. For another example, assuming that the element column includes 100 elements in total, the index value can be set to decrease in sequence at an interval of 1 with 100 as the starting value, without limitation.
[0096] As an example, in combination with Table 1 described above, assuming that the element column of the first original data is an element column including 4 elements in data table a shown in Table 1, the computing device first presets a hash table 10 including at least 4 hash addresses. Then, the processor of the computing device performs a hash calculation on the first element "ship" in the element column shown in Table 1 to obtain result 1. Assuming that the hash address corresponding to result 1 in hash table 10 is hash address 1, the processor writes the index value "0" set for writing element "ship" at hash address 1 of hash table 10, and records the key of hash address 1 as element "ship".
[0097] Next, the processor performs hash calculation on the second element "bus" in the order of the element column of data table a from top to bottom, and obtains result 2. Assuming that the hash address corresponding to result 2 in hash table 10 is hash address 2, the processor writes the index value "1" set for element "bus" to hash address 2 in hash table 10, and records the key of hash address 2 as element "bus".
[0098] Then, the processor performs hash calculation on the third element "ship" in the order of the element column of data table a from top to bottom, and obtains result 1. Since the hash address 1 corresponding to result 1 in hash table 10 has been written with index value "0", it means that the third element is the same as the first element. In this case, the processor processes the fourth element in the element column of data table a in the order of the element column of data table a from top to bottom.
[0099] Similarly, the processor performs hash calculation on the fourth element "airplane" and obtains result 3. Assuming that the hash address corresponding to result 3 in hash table 10 is hash address 3, the processor writes the index value "2" set for element "airplane" at hash address 3 in hash table 10, and records the key of hash address 3 as element "airplane".
[0100] In this way, the purpose of setting an index value for each element in the element column of data table a is achieved, and when the index value is set for each element in sequence from top to bottom in the element column of data table a, the index value starts at 0 and increases in intervals of 1. Referring to Table 4, the index value set for each element in the element column of data table a shown in Table 1 according to the process described in S1021 is shown in Table 4:
[0101] Table 4
[0102] element Index value ship 0 bus 1 airplane 2
[0103] S1022: The processor of the computing device creates a first index column according to the index value of each element in the element column of the first original data.
[0104] Specifically, the processor of the computing device may first create a blank column whose column length is the same as the column length of the first original data element column (or element value column).
[0105] Then, the processor of the computing device writes the index value set for each element in the first original data element column in S1021 into the newly created blank column, thereby obtaining the first index column. Among them, for any index value written in the first index column, the position of the index value in the first index column is the same as the position of the element corresponding to the index value in the first original data element column. Or it can be understood that the number of rows of the index value in the first index column is the same as the number of rows of the element corresponding to the index value in the first original data element column.
[0106] In a possible implementation, when the processor of the computing device writes the index value set for each element in the first original data element column in S1021 to the blank column, for any row of the blank column to which the index value is to be written (referred to as the row to be written), the processor can determine the element at the corresponding position in the first original data element column according to the position (or number of rows) of the row to be written in the blank column. Here, the element is the element corresponding to the row to be written (hereinafter referred to as the corresponding element), and the corresponding position is the same position in the first original data element column as the position (or number of rows) of the row to be written in the blank column. Then, the processor searches the hash table in S1021 to which the index value has been written according to the aforementioned corresponding element, and determines the index value at the hash address in the hash table with the corresponding element as the key as the index value of the corresponding element. Then, the processor writes the index value to the row to be written in the blank column. In this way, writing the index value in the blank column can be completed.
[0107] As an example, if the first original data is data table a shown in Table 1, the column length of the blank column created by the processor of the computing device is 4. When the index value set for each element in the data table a element column is as shown in Table 3, for the first row of the aforementioned blank column, the processor determines that the first row of the data table a element column is the position corresponding to the first row of the blank column based on the number of rows of the first row of the blank column in the blank column, and then the processor determines that the element "ship" in the first row of the data table a element column is the element corresponding to the first row of the blank column. Furthermore, the processor searches the hash table to which the index value has been written based on the element "ship", and writes the index value "0" at the hash address in the hash table with the element "ship" as the key to the first row of the blank column. Similarly, the processor of the computing device writes the index value "1" on the hash address with the element "bus" as the key into the second row of the blank column, writes the index value "0" on the hash address with the element "ship" as the key into the third row of the blank column, and writes the index value "2" on the hash address with the element "airplane" as the key into the fourth row of the blank column, thereby obtaining the first index column of data table a, as shown in Table 5:
[0108] Table 5
[0109] Index value 0 1 0 2
[0110] Furthermore, the first index column obtained above can be used to construct a coefficient matrix corresponding to the first original data (hereinafter referred to as the first matrix).
[0111] In this way, in a scenario where the computing device needs to accelerate the processor through DSA, the first matrix can be used for the DSA of the computing device to perform aggregation calculation on the first original data, or for DSA to count the number of each element in the first original data element column, or to perform join calculation on the first original data and the second original data, etc., but it is not limited thereto. The detailed process can be referred to the description below and will not be repeated here.
[0112] In some embodiments, after the computing device determines the first index column of the first original data based on S101 to S102, it refers to Figure 3 The process in which the computing device constructs a first matrix corresponding to the first original data based on the first index column can be implemented through the following S103 to S104.
[0113] S103. The processor of the computing device sends a first index column to the DSA of the computing device.
[0114] The first index column is specifically used for the DSA of the computing device to construct a first matrix corresponding to the first original data.
[0115] Optionally, the processor of the computing device may communicate with the processor via a bus (such as Figure 1 Bus 105 as shown), sends the first index column to the DSA.
[0116] S104. The DSA of the computing device receives the first index column and constructs a first matrix according to the first index column.
[0117] Optionally, DSA may perform a scatter calculation on the first index column to construct a first matrix.
[0118] Specifically, after receiving the first index column, the DSA of the computing device can first determine the number of row vectors and column vectors in the first matrix according to the column length of the first index column and the number of different index values in the first index column. Among them, the row vector of the matrix refers to a row of data in the matrix, and the column vector of the matrix refers to a column of data in the matrix. Therefore, it can also be understood that: DSA determines the number of rows and columns of the first matrix, that is, the size of the first matrix, according to the column length of the first index column and the number of different index values in the first index column.
[0119] Specifically, DSA determines the column length of the first index column as the number of row vectors in the first matrix, and determines the number of different index values in the first index column as the number of column vectors in the first matrix.
[0120] Assuming that the column length of the element column of the first original data is m, correspondingly, the column length of the first index column which is the same as the column length of the element column is m. Assuming that the number of different elements in the element column of the first original data is n, it means that the number of different index values in the first index column is n. In this case, the first matrix includes m row vectors and n column vectors, that is, the size of the first matrix is m×n.
[0121] As an example, assume that the first original data is data table a shown in Table 1, and the first index column of data table a is the index column shown in Table 5. It can be seen from the first index column shown in Table 5 that the first index column includes 4 index values, and the number of different index values is 3, so the first matrix includes 4 row vectors and 3 column vectors. That is, the first matrix corresponding to data table a is a 4×3 matrix.
[0122] Further, for any row vector in the first matrix, such as the first row vector, when the row in the first index column that is the same as the number of rows of the first row vector in the first matrix is the first target row, and the bit sequence number of the index value in the first target row is j (j is a positive integer less than or equal to n), the value of the jth data in the first row vector is 1, and the values of the remaining data are 0. Among them, the bit sequence number of the index value is the sorting number after the different index values in the first index column are sorted by size. Here, the sorting of the different index values in the first index column can be from large to small or from small to large, and there is no limitation on this. In this way, the first matrix corresponding to the first original data can be constructed.
[0123] As an example, assume that the first original data is data table a shown in Table 1, and the first index column of data table a is the index column shown in Table 5. It can be seen from Table 5 that the first matrix corresponding to data table a is a 4×3 matrix. In addition, after sorting the different index values in the first index column shown in Table 5 from small to large, the sorting number (i.e., the bit number) of the index value "0" located in the first row of the first index column shown in Table 5 is 1, the sorting number (i.e., the bit number) of the index value "1" located in the second row of the first index column shown in Table 5 is 2, and the sorting number (i.e., the bit number) of the index value "2" located in the fourth row of the first index column shown in Table 5 is 3.
[0124] Therefore, for the first row vector in the first matrix, the first target row in the first index column shown in Table 5 with the same row number as the first row vector in the first matrix is the first row of the first index column. Since the bit number of the index value "0" of the first row in the first index column is 1, the value of the first data in the first row vector is 1, and the rest of the values are 0, as shown in the following formula (1) of matrix A.
[0125] Similarly, for the second row vector in the first matrix, the first target row in the first index column shown in Table 5 with the same row number as the second row vector in the first matrix is the second row of the first index column. Since the bit number of the index value "1" of the second row in the first index column is 2, the value of the second data in the second row vector is 1, and the rest of the values are 0, as shown in the following formula (1) matrix A.
[0126] For the third row vector in the first matrix, the first target row in the first index column shown in Table 5 that has the same number of rows as the third row vector in the first matrix is the third row of the first index column. Since the bit number of the index value "0" of the third row in the first index column is 1, the value of the first data in the third row vector is 1, and the rest of the values are 0, as shown in the following formula (1) for matrix A.
[0127] For the 4th row vector in the first matrix, the first target row in the first index column shown in Table 5 with the same row number as the 4th row vector in the first matrix is the 4th row of the first index column. Since the bit number of the index value "2" of the 4th row in the first index column is 3, the value of the 3rd data in the 4th row vector is 1, and the rest of the values are 0, as shown in the following formula (1) for matrix A.
[0128] Formula (1)
[0129] Through the above method, after determining the first index column of the first original data, the DSA of the computing device can construct a coefficient matrix corresponding to the first original data based on the first index column, that is, a first matrix.
[0130] Compared with the scheme of sending the first original data to the DSA of the computing device so that the DSA constructs a corresponding coefficient matrix based on the first original data, the method provided in the embodiment of the present application only needs to send the index column of the first original data to the DSA. Therefore, the scheme provided in the embodiment of the present application can save the data transmission bandwidth between the computing device processor and the DSA.
[0131] Furthermore, in an example (such as Example 1), after constructing the first matrix corresponding to the first original data, when it is necessary to count the number of each element in the first original data element column, the computing device can perform the corresponding matrix multiplication operation on the first matrix through DSA, thereby accelerating the data calculation. The same elements in the element column are called one element.
[0132] Still taking the case where the first original data is the data table a shown in Table 1 as an example, based on the method described above, the DSA of the computing device constructs the first matrix corresponding to the data table a as the above-mentioned matrix A. When it is necessary to count the number of each element in the element column of the data table a, the computing device sends a calculation instruction to the DSA through the processor to instruct the DSA to perform a multiplication operation on the preset coefficient matrix and the matrix A.
[0133] The preset coefficient matrix is a matrix whose row vector number is 1 and whose column vector number is the same as the column length (i.e., the number of rows) of the first original data element column. In addition, all values in the preset coefficient matrix are 1. Therefore, for data table a, the preset coefficient matrix is [1 1 1 1].
[0134] Optionally, the preset coefficient matrix may be preset in the DSA, or may be carried in a calculation instruction sent by a processor of the computing device to the DSA, and this is not limited. The calculation instruction may be, for example, sent to the DSA at the same time when the processor of the computing device sends the first index column to the DSA in the above S103, and this is not limited.
[0135] After receiving the calculation instruction from the processor, the DSA of the computing device performs a multiplication operation on the preset coefficient matrix and the matrix A, as shown in the following formula (2):
[0136] Formula (2)
[0137] Wherein, each data in the result matrix of formula (2) is used to indicate the number of each element in the element column a of the data table.
[0138] Specifically, the result matrix of formula (2) includes only one row vector, and the column length (or number of data) of the row vector is used to indicate the number of different elements in the element column of data table a, so the value of each data in the row vector represents the number of one element. Moreover, the arrangement order of the data in the row vector is the arrangement order of different index values in the first index column described above. Therefore, in the row vector, the first data "2" is used to represent the number of elements "ship" corresponding to the index value "0" with a position order of 1 in the first index column of data table a, that is, the number of elements "ship" is 1. Similarly, the second data "1" is used to represent the number of elements "bus" corresponding to the index value "1" with a position order of 2 in the first index column of data table a, that is, the number of elements "bus" is 1. The third data "1" is used to represent the number of elements "airplane" corresponding to the index value "2" with a position order of 3 in the first index column of data table a, that is, the number of elements "airplane" is 1.
[0139] In another example (such as Example 2), after constructing a first matrix corresponding to the first original data, when aggregation calculation is required for the first original data, the computing device can perform a matrix multiplication operation corresponding to the aggregation calculation on the first matrix through DSA, thereby achieving the purpose of accelerating data aggregation calculation.
[0140] Still taking the example that the first original data is data table a shown in Table 1, based on the above, the first matrix corresponding to data table a is the above-mentioned matrix A. When it is necessary to perform aggregation calculation on data table a, the computing device sends a calculation instruction to DSA through the processor to instruct DSA to perform multiplication operation on the transposed matrix corresponding to the element value column of data table a and matrix A.
[0141] The transposed matrix corresponding to the element value column of data table a is a matrix including row vectors obtained by transposing the element value column of data table a. For data table a shown in Table 1, the transposed matrix is [5.1 4.0 3.2 9.3].
[0142] Optionally, the processor of the computing device may send the element value column of the first original data (such as data table a) to the DSA while executing S103 above to send the first index column to the DSA, so that the DSA generates a corresponding transposed matrix based on the element value column. Alternatively, after the processor of the computing device generates the transposed matrix corresponding to the element value column of the first original data (such as data table a), and sends the first index column to the DSA while executing S103 above, the processor sends the transposed matrix to the DSA, without limitation. It should also be understood that the element value column or transposed matrix sent by the processor of the computing device to the DSA may be carried in the above-mentioned calculation indication, or may be sent separately, without limitation.
[0143] Then, after receiving the calculation instruction, DSA performs a multiplication operation on the transposed matrix corresponding to the element value column of data table a and matrix A, as shown in formula (3):
[0144] Formula (3)
[0145] Wherein, each data in the result matrix of formula (3) is used to indicate the sum of the element values of each element in the element column a of the data table.
[0146] Specifically, the result matrix of formula (3) includes only one row vector, and the column length (or number of data) of the row vector is used to indicate the number of different elements in the element column of data table a, so the value of each data in the row vector represents the sum of the element values of an element. Moreover, the arrangement order of the data in the row vector is the arrangement order of the different index values in the first index column described above. Therefore, in the row vector, the first data "8.3" is used to represent the sum of the element values of the element "ship" corresponding to the index value "0" with a position of 1 in the first index column of data table a, that is, the sum of the element values of the element "ship" is 8.3. Similarly, the second data "3.2" is used to represent the sum of the element values of the element "bus" corresponding to the index value "1" with a position of 2 in the first index column of data table a, that is, the sum of the element values of the element "bus" is 3.2. The third data "9.3" is used to represent the sum of the element values of the element "airplane" corresponding to the index value "2" with a position order of 3 in the first index column of the data table a, that is, the sum of the element values of the element "airplane" is 9.3.
[0147] Thus, based on the above two examples, it can be known that by performing corresponding matrix multiplication on the first original data corresponding to the first matrix, the corresponding result can be quickly obtained.
[0148] In some other embodiments, after the computing device determines the first index column of the first original data based on S101 to S102, it refers to Figure 4 The process in which the computing device constructs a first matrix corresponding to the first original data based on the first index column can also be implemented through the following S105.
[0149] S105: The processor of the computing device constructs a first matrix according to the first index column.
[0150] Specifically, for detailed description of the processor constructing the first matrix according to the first index column, reference may be made to the description of DSA constructing the first matrix according to the first index column in S104, which will not be repeated here.
[0151] Furthermore, the processor of the computing device can send the constructed first matrix to the DSA, so that the DSA performs the corresponding matrix multiplication operation based on the first matrix (such as the matrix multiplication operation described in the above-mentioned Examples 1 and 2) to achieve aggregation calculation of the first original data or count the number of each element in the first original data, which will not be repeated here.
[0152] In some other embodiments, when multiple rows of data are added to the first original data, refer to Figure 5 , Figure 5 FIG. 2 is a flow chart showing another method for preprocessing data provided by an embodiment of the present application. Figure 5As shown, after constructing the first matrix corresponding to the first original data by the method described above, the method further performs the following steps:
[0153] S106: The processor of the computing device creates a new index column according to the elements in the newly added multiple rows of data, each element in the first original data element column and the corresponding index value. The new index column is used to update the first matrix described above.
[0154] The length of the newly added index column is the same as the number of rows of the newly added multiple rows of data, and includes the index value corresponding to each element in the newly added multiple rows of data.
[0155] Specifically, the processor can set an index value for each element in the newly added multiple rows of data in the hash table used to set index values for elements in the first original data in S1021 based on the process described in S1021 above. For detailed description, please refer to the description in S1021 and will not be repeated here.
[0156] It should be understood that, in step S1021, the index value and the corresponding element (i.e., key) corresponding to each element in the first original data element column have been written into the hash table used to set the index value for the element in the first original data. Therefore, by performing a hash calculation on each element in the newly added multiple rows of data, and querying the hash table based on the calculation result, and when the index value is not found at the hash address corresponding to the calculation result, the index value set for the current element is written to the hash address. When the index value is found at the hash address corresponding to the calculation result, it means that the index value is the index value set for the current element.
[0157] It should also be understood that if the index value is set in increments when setting the index value for the element in the first original data in S1021, then when the index value is set for the element in the newly added multiple lines of data, the index value is continuously set in increments along the largest index value in the first index column. Of course, if the index value is set in decrement when setting the index value for the element in the first original data in S1021, then when the index value is set for the element in the newly added multiple lines of data, the index value is continuously set in decrement along the smallest index value in the first index column.
[0158] Furthermore, according to the index value set for each element in the newly added multiple rows of data, an index column of the multiple rows of data, ie, a newly added index column, is created. The specific process can be referred to the description of S1022 above and will not be repeated here.
[0159] Furthermore, the newly added index columns created for the newly added multiple rows of data can be used to update the first matrix mentioned above, so as to obtain a coefficient matrix corresponding to the first original data after the newly added multiple rows of data.
[0160] Optionally, when the first matrix described above is constructed by a processor of a computing device, the process of updating the first matrix based on the newly added index column can be performed by the processor. Of course, the processor of the computing device can also send the newly added index column to the DSA, so that the DSA updates the first matrix described above based on the newly added index column, which is not limited to this.
[0161] Optionally, when the first matrix mentioned above is constructed by the DSA of the computing device, the processor of the computing device may send the created newly added index column to the DSA, and the DSA may update the first matrix mentioned above based on the newly added index column.
[0162] The following takes DSA updating the above-mentioned first matrix based on the newly added index column as an example to describe the process of updating the first matrix based on the newly added index column.
[0163] Specifically, DSA determines the number of column vectors that need to be added to the first matrix based on the number of index values in the newly added index column that are different from the index values in the first index column, and the first m values of the newly added column vectors are filled with 0. Where m is the number of rows of the first matrix that has not been updated.
[0164] DSA also determines the number of row vectors that need to be added to the first matrix based on the column length (or number of rows) of the newly added index column. For each newly added row vector, the setting method of the value of the data in each row vector (such as 0 or 1) can refer to the description of setting specific values (such as 0 or 1) for the data in each row vector in the first matrix above, and will not be repeated here. It should be noted that when setting the value of the data in the newly added row vector, the bit number of the index value corresponding to the data set to 1 is the sorting number of all different index values in the first index column and the newly added index column.
[0165] As an example, the first original data is still taken as the data table a shown in Table 1. Based on the above, the first matrix corresponding to the data table a is the above-mentioned matrix A. Assume that two rows of data are added to the data table a, and the data table a after adding two rows of data is shown in Table 6:
[0166] Table 6
[0167] element Element value 1 ship 5.1 bus 4.0 ship 3.2 airplane 9.3 bus 5.8 train 6.4
[0168] Based on the elements in the two newly added rows of data in Table 6, each element in the element column a of the original data table and the corresponding index value (for example, as shown in Table 4), the newly added index column created by the computing device is shown in Table 7:
[0169] Table 7
[0170] element Index value bus 1 train 3
[0171] Furthermore, based on the newly added index column shown in Table 7, DSA determines that the number of index values in the newly added index column that are different from the index values in the first index column (such as shown in Table 5) is 1, and thus determines that matrix A needs to add 1 column vector, and the values of the first 4 (the number of rows of matrix A that have not been updated) data of the column vector are filled with 0. In addition, DSA also determines that matrix A needs to add 2 row vectors based on the column length of the newly added index column.
[0172] For the newly added 1st row vector, the first target row with the same row number as the 1st newly added row vector in all newly added row vectors is the 1st row of the newly added index column shown in Table 7. Since the index value "1" in the 1st row of the newly added index column shown in Table 7 has a bit number of 2 in all the different index values of the index columns shown in Tables 5 and 7, the value of the second data in the newly added 1st row vector is 1, and the rest of the values are 0, as shown in the following formula (4) for the matrix Anew.
[0173] Similarly, for the newly added second row vector, the first target row with the same row number as the newly added second row vector in all newly added row vectors is the second row of the newly added index column shown in Table 7. Since the index value "3" in the second row of the newly added index column shown in Table 7 is ranked as 4 in the order of all the different index values of the index columns shown in Tables 5 and 7, the value of the fourth data in the newly added second row vector is 1, and the rest of the values are 0, as shown in the following formula (4) for the matrix Anew.
[0174] Formula (4)
[0175] In this way, through the above method, when new data is added to the first original data, it is only necessary to determine the index column of the new data, and then the coefficient matrix corresponding to the first original data can be updated based on the index column.
[0176] It can be seen that when the coefficient matrix (such as the above-mentioned first matrix) corresponding to the first original data is updated by DSA based on the index column of the newly added data, compared with sending all the first original data including the newly added data to the DSA of the computing device so that the DSA can reconstruct the corresponding coefficient matrix based on the first original data including the newly added data, the method provided by the present application only needs to send the index column of the newly added data to the DSA, and the DSA can update the coefficient matrix corresponding to the first original data not including the newly added data based on the index column of the newly added data, without the need to reconstruct the coefficient matrix of the first original data including the newly added data. Moreover, when the first original data is newly added, when it is necessary to perform aggregation calculation on the first original data after the newly added data, it is only necessary to send the element value column of the newly added data to the DSA. Therefore, the method provided by the present application can not only save the data transmission bandwidth between the computing device processor and the DSA, but also improve the efficiency of constructing the coefficient matrix.
[0177] In some other examples, after constructing or updating the first matrix corresponding to the first original data, when it is necessary to connect the first original data with the second original data, the computing device may construct a second matrix based on the elements in the first original data element column and the elements in the second original data element column, wherein the second matrix and the first matrix described above are used to perform connection calculation on the first original data and the second original data.
[0178] refer to Figure 6 , Figure 6 FIG. 2 is a flow chart showing another method for preprocessing data provided by an embodiment of the present application. Figure 6 As shown, the method may include the following steps:
[0179] S201: A processor of a computing device obtains second original data.
[0180] The second original data and the first original data include the same elements. Based on the same elements in the second original data and the first original data, the second original data can be connected to the first original data.
[0181] Specifically, for the detailed description of the processor of the computing device acquiring the second original data, reference may be made to the description of S101 acquiring the first original data, which will not be described in detail.
[0182] Optionally, the processor of the computing device may obtain the second original data and the first original data simultaneously, or may obtain the second original data and the first original data successively, which is not limited to the above.
[0183] S202: The processor of the computing device determines a second index column of the second original data according to an element in the second original data and an index value of each element in an element column of the first original data.
[0184] Specifically, the processor of the computing device may first determine the index value of each element in the second original data element column.
[0185] Optionally, for any element in the second original data, such as the first element, the processor of the computing device may query in the element column of the first original data to determine whether the element column of the first original data includes the first element.
[0186] When the first element is included in the element column of the first original data, the processor of the computing device may determine the index value set for the first element in the first original data element column in S1021 above as the index value of the first element in the second original data element column. When the first element is not included in the element column of the first original data, the processor of the computing device may set the index value of the first element in the second original data element column to a preset value. The preset value may be any value different from the index value of the element in the first original data, or the preset value may be empty. Here, for the data row in the second original data where the index value is the preset value, the row vector data in the second matrix with the same number of rows as the data row is all filled with 0.
[0187] Next, the processor of the computing device creates a second index column based on the determined index value of each element in the second original data element column. Here, the detailed description of the processor of the computing device creating the second index column according to the index value of each element in the second original data element column can refer to the description of creating the first index column according to the index value of each element in the element column of the first original data in S1022 above, and will not be repeated here.
[0188] Still taking the example that the first original data is data table a shown in Table 1, the index values set for the elements in the element column of data table a are shown in Table 4. Assuming that the second original data is data table b shown in Table 2, since the processor determines that the element "ship" in the element column of data table b exists in the element column of data table a, the processor determines the index value of the element "ship" in data table b to be the index value "0" of the element "ship" in data table a. Similarly, since the processor determines that the element "airplane" in the element column of data table b exists in the element column of data table a, the processor determines the index value of the element "airplane" in data table b to be the index value "2" of the element "airplane" in data table a. Furthermore, the processor creates a second index column of data table b based on the index values determined for the two elements in data table b, as shown in Table 8:
[0189] Table 8
[0190] element Index value ship 0 airplane 2
[0191] S203: The processor of the computing device sends a second index column to the DSA.
[0192] The second index column is specifically used for the DSA of the computing device to construct a coefficient matrix corresponding to the second original data, that is, a second matrix, and the number of column vectors of the second matrix is the same as the number of column vectors of the first matrix.
[0193] Optionally, the processor of the computing device may communicate with the processor via a bus (such as Figure 1Bus 105 as shown) sends the second index column to the DSA.
[0194] S204. The DSA of the computing device constructs a second matrix according to the received second index column.
[0195] Specifically, DSA can determine the number of column vectors in the first matrix as the number of column vectors in the second matrix. DSA also determines the number of rows of the second index column (ie, the number of rows of the second original data) as the number of row vectors in the second matrix.
[0196] Assuming that the first matrix includes n column vectors, the second matrix includes n column vectors. Assuming that the number of rows of the second index column is q (q is a positive integer), the second matrix includes q row vectors. Therefore, the size of the second matrix is q×n.
[0197] Still taking the data table a shown in Table 1 as the first original data and the data table b shown in Table 2 as the second original data as an example, assuming that the coefficient matrix corresponding to the data table a is the matrix A described above, since the matrix A includes 3 column vectors, the second matrix includes 3 column vectors. In addition, since the index column of the data table b, that is, the number of rows of the second index column is 2, the second matrix includes 2 row vectors. Therefore, the size of the second matrix is 2×3.
[0198] Furthermore, for any row vector in the second matrix, such as the second row vector, when the row in the second index column that has the same number of rows as the second row vector in the second matrix is the second target row, and the bit number of the index value in the second target row is k, the value of the kth data in the second row vector is 1, and the values of the remaining data are 0, and k is a positive integer. Here, the bit number of the index value is the permutation number of the index value after sorting different index values in the first index column.
[0199] As an example, assuming that the first original data is data table a shown in Table 1, and the second original data is data table b shown in Table 2, the second matrix corresponding to the second original data includes 2 row vectors and 3 column vectors. And assuming that in the first index column of data table a shown in Table 5, the ranking (i.e., the bit sequence number) of the index value "0" located in the first row of the index column shown in Table 5 is 1, the ranking (i.e., the bit sequence number) of the index value "1" located in the second row of the index column shown in Table 5 is 2, and the ranking (i.e., the bit sequence number) of the index value "2" located in the fourth row of the index column shown in Table 5 is 3.
[0200] Therefore, for the first row vector in the second matrix, the second target row in the second index column shown in Table 8 with the same row number as the first row vector in the second matrix is the first row of the second index column. Since the bit number of the index value "0" of the first row in the second index column is 1, the value of the first data in the first row vector is 1, and the remaining values are 0, as shown in the following formula (5) of matrix B.
[0201] Similarly, for the second row vector in the second matrix, the second target row in the second index column shown in Table 8 with the same row number as the second row vector in the second matrix is the second row of the second index column. Since the bit number of the index value "2" of the second row in the second index column is 3, the value of the third data in the second row vector is 1, and the remaining values are 0, as shown in the following formula (5) of matrix B.
[0202] Formula (5)
[0203] In this way, the DSA of the computing device constructs a second matrix corresponding to the second original data. Compared with sending the second original data to the DSA of the computing device so that the DSA constructs the corresponding coefficient matrix based on the second original data, the method provided by the present application only needs to send the index column of the second original data to the DSA, thereby saving the data transmission bandwidth between the computing device processor and the DSA.
[0204] It should be understood that the above-mentioned second matrix can also be constructed by the processor of the computing device. The detailed process can refer to the description of DSA constructing the second matrix in S204, which will not be repeated. When the second matrix is constructed by the processor of the computing device, the processor sends the second matrix to the DSA after constructing the second matrix, so that the DSA performs the following connection calculation based on the second matrix and the first matrix described above.
[0205] It should also be understood that when the second matrix needs to be constructed, the computing device can start to construct the second matrix after step S1021 described above. Of course, the second matrix can also be constructed after the first matrix is constructed, which is not limited.
[0206] Furthermore, when DSA receives an indication that a join calculation needs to be performed on the first original data and the second original data, DSA can quickly obtain the join result of the first original data and the second original data by performing a matrix multiplication operation corresponding to the join calculation on the first matrix and the second matrix.
[0207] For example, the DSA of the computing device performs a multiplication operation on the first matrix and the second matrix as shown in the following formula (6) to obtain a connection result:
[0208] Formula (6)
[0209] The result matrix of formula (6) is used to indicate the connection result of data table a and data table b.
[0210] Specifically, in the result matrix shown in formula (6), the row vector corresponds to the data row of the first original data (such as data table a), and the column vector corresponds to the data row in the second original data (such as data table) b. Moreover, the data with a value of 1 in the result matrix indicates that the data rows corresponding to the position of the data with the value 1 in the two data tables to be connected are connected. In other words, based on the data position of the value 1 in the result matrix shown in formula (6), a row of data table a corresponding to the position and a row of data table b can be connected.
[0211] Specifically, the data with a value of 1 in the first row of the result matrix shown in formula (6) indicates that the first row of data table a and the first row of data table b are connected. Similarly, the data with a value of 1 in the third row of the result matrix indicates that the third row of data table a and the first row of data table b are connected, and the data with a value of 1 in the fourth row of the result matrix indicates that the fourth row of data table a and the second row of data table b are connected. Among them, since there is no data with a value of 1 in the second row of the result matrix, it means that there is no data row in data table b that can be connected with the second row of data table a. Therefore, the data table after the connection of data table a and data table b obtained according to the matrix result shown in formula (6) is shown in Table 3 described above.
[0212] In summary, the column-structured original data is preprocessed by the method provided in the embodiment of the present application, so that when the DSA of the computing device needs to accelerate the calculation of the original data through matrix multiplication, the coefficient matrix corresponding to the original data can be constructed while saving the data bandwidth between the processor and the DSA.
[0213] The above mainly introduces the solution provided in the embodiment of the present application from the perspective of method.
[0214] In order to achieve the above functions, Figure 7 As shown, Figure 7 FIG. 7 is a schematic diagram showing the structure of a data preprocessing device 70 provided in an embodiment of the present application. The preprocessing device 70 is applied to a CPU of a computing device and is used to execute the above-mentioned data preprocessing method, for example, to execute Figure 3 , Figure 3 , Figure 4 , Figure 5 or Figure 6 The method shown in the figure. The pre-processing device 70 may include an acquisition unit 701 and a processing unit 702.
[0215] The acquisition unit 701 is used to acquire the first original data including an element column and an element value column. The processing unit 702 is used to create a first index column of the first original data, and the first index column of the first original data is used to construct a first matrix corresponding to the first original data. The element column of the first original data includes a plurality of elements, and the element value column includes an element value corresponding to each of the plurality of elements. The first index column of the first original data has the same column length as the element column of the first original data, and includes the index value of each element in the element column of the first original data.
[0216] As an example, combining Figure 2 , Figure 3 as well as Figure 4 , the acquisition unit 701 may be used to execute S101. The processing unit 702 may be used to execute S102.
[0217] Optionally, the computing device is further configured with a DSA, and the first matrix is used by the DSA to perform aggregation calculations on the first original data, or is used by the DSA to count the number of each element in the element column of the first original data.
[0218] Optionally, the preprocessing device 70 further includes: a sending unit 703, configured to send a first index column to the DSA, where the first index column is specifically used by the DSA to construct a first matrix.
[0219] As an example, combining Figure 3 , the sending unit 703 can be used to execute S103.
[0220] Optionally, the processing unit 702 is further configured to construct a first matrix according to the first index column.
[0221] As an example, combining Figure 4 , the processing unit 702 can be used to execute S105.
[0222] Optionally, the processing unit 702 is specifically used to: set an index value for each element in the element column of the first original data by constructing a hash table based on the element column of the first original data; and create a first index column according to the index value of each element in the element column of the first original data.
[0223] As an example, combining Figure 2 , the processing unit 702 can be used to execute S1021~S1022.
[0224] Optionally, the processing unit 702 is further configured to create a newly added index column according to the elements in the multiple rows of data, each element in the first original data element column and the corresponding index value when multiple rows of data are added to the first original data. The column length of the newly added index column is the same as the number of rows of the aforementioned multiple rows of data, and includes the index value corresponding to each element in the multiple rows of data, and the newly added index column is used to update the first matrix.
[0225] As an example, combining Figure 5 , the processing unit 702 can be used to execute S106.
[0226] Optionally, the sending unit 703 is further used to send the newly added index column to the DSA, where the newly added index column is specifically used for the DSA to update the first matrix.
[0227] Optionally, the number of row vectors in the first matrix is the number of index values included in the first index column, and the number of column vectors in the first matrix is the number of different index values in the first index column. For the first row vector in the first matrix, when the row in the first index column that is the same as the number of rows of the first row vector in the first matrix is the first target row, and the bit number of the index value in the first target row is j, then the value of the jth data in the first row vector is 1, and the values of the remaining data are 0. Among them, j is a positive integer less than or equal to the number of column vectors, and the bit number of the index value is the sorting number after the different index values in the first index column are sorted by size.
[0228] Optionally, when the first matrix includes n column vectors, the acquisition unit 701 is further used to acquire the second original data. The element column of the second original data and the element column of the first original data include the same elements, and the second matrix corresponding to the second original data and the first matrix described above are used to perform a connection calculation on the first original data and the second original data. The number of row vectors in the second matrix is the number of rows of the second original data, and the number of column vectors in the second matrix is the same as the number of column vectors in the first matrix.
[0229] As an example, combining Figure 6 , the acquisition unit 701 can be used to execute S201.
[0230] Optionally, the processing unit 702 is further configured to construct a second matrix according to the elements in the second original data, the elements in the first original data and the corresponding index values. Alternatively, the sending unit 703 is configured to send the element columns of the second original data and the elements in the first original data and the corresponding index values to the DSA configured on the computing device, so that the DSA constructs the second matrix.
[0231] As an example, combining Figure 6 , the sending unit 703 can be used to execute S203.
[0232] Optionally, for the second row vector in the second matrix, when the row in the index column of the second original data that has the same number of rows as the second row vector in the second matrix is the second target row, and the bit number of the index value in the second target row is k, the value of the kth data in the second row vector is 1, and the values of the remaining data are 0. Wherein, k is a positive integer, and the bit number of the index value is the sorting number after different index values in the first index column are sorted by size.
[0233] Optionally, the original data mentioned above is data in a column-based database.
[0234] For the detailed description of the above optional methods, please refer to the above method embodiments, which will not be repeated here. In addition, the explanation of any pre-processing device 70 provided above and the description of the beneficial effects can refer to the above corresponding method embodiments, which will not be repeated here.
[0235] As an example, combining Figure 1 The functions implemented by the acquisition unit 701, the processing unit 702 and the sending unit 703 in the preprocessing device 70 can be realized by Figure 1 The processor 101 in the illustrated computing device 10 executes program code implemented in the memory 102 .
[0236] Those skilled in the art should easily realize that, in combination with the units and algorithm steps of each example described in the embodiments disclosed herein, the present application can be implemented in the form of hardware or a combination of hardware and computer software. Whether a function is executed in the form of hardware or computer software driving hardware depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0237] It should be noted that Figure 7 The division of modules in the example is schematic and is only a logical function division. There may be other division methods in actual implementation. For example, two or more functions may be integrated into one processing module. The above integrated modules may be implemented in the form of hardware or software function modules.
[0238] The present application also provides a computer program product and a computer-readable storage medium for storing the computer program product. The computer program product may include one or more program instructions, which, when executed by one or more processors, can provide the above Figure 2 , Figure 3 , Figure 4 , Figure 5 or Figure 6 Thus, for example, reference to Figure 2 One or more features of S101 to S102 may be undertaken by one or more instructions in the computer program product.
[0239] In some examples, such as for executing Figure 2 , Figure 3 , Figure 4 , Figure 5 or Figure 6 The data preprocessing apparatus describing the method may be configured to provide various operations, functions, or actions in response to one or more program instructions stored in a computer-readable storage medium.
[0240] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using a software program, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When executing instructions on a computer and executing a computer, a process or function according to an embodiment of the present application is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. Computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium, for example, computer instructions can be transmitted from a website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (digital subscriber line, DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) mode to another website site, computer, server or data center. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server, data center, etc. that contains one or more servers that can be integrated with a medium. The available medium may be a magnetic medium (eg, a floppy disk, a hard disk, a magnetic tape), an optical medium (eg, a DVD), or a semiconductor medium (eg, a solid state disk (SSD)).
[0241] The above is only a specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any person skilled in the art can easily think of changes or substitutions within the technical scope disclosed by the present invention, which should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention should be based on the protection scope of the claims.
Claims
1. A data preprocessing method, characterized in that: A central processing unit (CPU) for a computing device; the method comprising: Acquire first original data, the original data including an element column and an element value column, the element column including a plurality of elements, and the element value column including an element value corresponding to each of the plurality of elements; Create a first index column of the first original data, where the first index column has the same column length as the element column of the first original data and includes an index value of each element in the element column of the first original data. The first index column is used to construct a first matrix corresponding to the first original data.
2. The method according to claim 1, characterized in that The computing device is further configured with a domain-specific acceleration processor DSA, and the first matrix is used by the DSA to perform aggregation calculations on the first original data, or is used by the DSA to count the number of each element in the element column of the first original data.
3. The method according to claim 2, characterized in that The method further comprises: The first index column is sent to the DSA, where the first index column is specifically used by the DSA to construct the first matrix.
4. The method according to claim 2, characterized in that The method further comprises: The first matrix is constructed according to the first index column.
5. The method according to any one of claims 1 to 4, characterized in that The creating a first index column of the first original data includes: Setting an index value for each element in the element column of the first original data by using a hash table constructed based on the element column of the first original data; The first index column is created according to the index value of each element in the element column of the first original data.
6. The method according to any one of claims 1 to 5, characterized in that When multiple lines of data are added to the first original data, the method further includes: Create a new index column based on the elements in the multiple rows of data, each element in the first original data element column and the corresponding index value, where the column length of the new index column is the same as the number of rows of the multiple rows of data and includes the index value corresponding to each element in the multiple rows of data. The new index column is used to update the first matrix.
7. The method according to claim 6, characterized in that The computing device is further configured with a domain-specific acceleration processor DSA, and the method further comprises: The newly added index column is sent to the DSA, where the newly added index column is specifically used by the DSA to update the first matrix.
8. The method according to any one of claims 1 to 7, characterized in that The number of row vectors in the first matrix is the number of index values included in the first index column, and the number of column vectors in the first matrix is the number of different index values in the first index column; For the first row vector in the first matrix, when the row in the first index column with the same number of rows as the first row vector in the first matrix is the first target row, and the bit sequence number of the index value in the first target row is j, then the value of the j-th data in the first row vector is 1, and the values of the remaining data are 0; where j is a positive integer less than or equal to the number of column vectors, and the bit sequence number of the index value is the sorting sequence number after different index values in the first index column are sorted by size.
9. The method according to any one of claims 1 to 8, characterized in that When the first matrix includes n column vectors, the method further includes: Obtain second original data, where an element column of the second original data and an element column of the first original data include the same elements, a second matrix corresponding to the second original data and the first matrix are used to perform a join calculation on the first original data and the second original data, the number of row vectors in the second matrix is the number of rows of the second original data, and the number of column vectors in the second matrix is the same as the number of column vectors in the first matrix.
10. The method according to claim 9, characterized in that The method further comprises: constructing the second matrix according to the elements in the second original data, the elements in the first original data and the corresponding index values; or, Send the element columns of the second original data to the DSA configured on the computing device, and send the elements in the first original data and the corresponding index values, so that the DSA constructs the second matrix.
11. The method according to claim 9 or 10, characterized in that For the second row vector in the second matrix, when the row in the index column of the second original data that has the same number of rows as the second row vector in the second matrix is the second target row, and the bit sequence number of the index value in the second target row is k, then the value of the kth data in the second row vector is 1, and the values of the remaining data are 0; where k is a positive integer, and the bit sequence number of the index value is the sorting sequence number after different index values in the first index column are sorted by size.
12. The method according to any one of claims 1 to 11, characterized in that The original data is data in a column-based database.
13. A data preprocessing device, characterized in that: A central processing unit (CPU) for a computing device; the device comprises: an acquiring unit, configured to acquire first original data, the original data including an element column and an element value column, the element column including a plurality of elements, and the element value column including an element value corresponding to each of the plurality of elements; A processing unit is configured to create a first index column of the first original data, wherein the first index column has the same column length as the element column of the first original data and includes an index value of each element in the element column of the first original data, and the first index column is used to construct a first matrix corresponding to the first original data.
14. The device according to claim 13, characterized in that The computing device is further configured with a domain-specific acceleration processor DSA, and the first matrix is used by the DSA to perform aggregation calculations on the first original data, or is used by the DSA to count the number of each element in the element column of the first original data.
15. The device according to claim 14, characterized in that The device further comprises: A sending unit is configured to send the first index column to the DSA, where the first index column is specifically used by the DSA to construct the first matrix.
16. The device according to claim 14, characterized in that The processing unit is further configured to construct the first matrix according to the first index column.
17. The device according to any one of claims 13 to 16, characterized in that The processing unit is specifically configured to: Setting an index value for each element in the element column of the first original data by using a hash table constructed based on the element column of the first original data; The first index column is created according to the index value of each element in the element column of the first original data.
18. The device according to any one of claims 13 to 17, characterized in that The processing unit is further used to create a new index column when multiple rows of data are added to the first original data based on the elements in the multiple rows of data, each element in the first original data element column and the corresponding index value. The column length of the new index column is the same as the number of rows of the multiple rows of data, and includes the index value corresponding to each element in the multiple rows of data. The new index column is used to update the first matrix.
19. The device according to claim 18, characterized in that The computing device is further configured with a domain-specific acceleration processor DSA, and the apparatus further comprises: A sending unit is configured to send the newly added index column to the DSA, where the newly added index column is specifically used by the DSA to update the first matrix.
20. The device according to any one of claims 13 to 19, characterized in that The number of row vectors in the first matrix is the number of index values included in the first index column, and the number of column vectors in the first matrix is the number of different index values in the first index column; For the first row vector in the first matrix, when the row in the first index column with the same number of rows as the first row vector in the first matrix is the first target row, and the bit sequence number of the index value in the first target row is j, then the value of the j-th data in the first row vector is 1, and the values of the remaining data are 0; where j is a positive integer less than or equal to the number of column vectors, and the bit sequence number of the index value is the sorting sequence number after different index values in the first index column are sorted by size.
21. The device according to any one of claims 13 to 20, characterized in that When the first matrix includes n column vectors, The acquisition unit is further used to acquire second original data, where the element column of the second original data and the element column of the first original data include the same elements, and the second matrix corresponding to the second original data and the first matrix are used to perform connection calculations on the first original data and the second original data, the number of row vectors in the second matrix is the number of rows of the second original data, and the number of column vectors in the second matrix is the same as the number of column vectors in the first matrix.
22. The device according to claim 21, characterized in that The device further includes a sending unit, The processing unit is further configured to construct the second matrix according to the elements in the second original data, the elements in the first original data, and the corresponding index values; or, The sending unit is used to send the element column of the second original data and the elements and corresponding index values in the first original data to the DSA configured by the computing device, so that the DSA can construct the second matrix.
23. The device according to claim 21 or 22, characterized in that For the second row vector in the second matrix, when the row in the index column of the second original data that has the same number of rows as the second row vector in the second matrix is the second target row, and the bit sequence number of the index value in the second target row is k, then the value of the kth data in the second row vector is 1, and the values of the remaining data are 0; where k is a positive integer, and the bit sequence number of the index value is the sorting sequence number after different index values in the first index column are sorted by size.
24. The device according to any one of claims 13 to 23, characterized in that The original data is data in a column-based database.
25. A processor, characterized in that: The processor is configured to read program instructions stored in the memory to execute the method according to any one of claims 1 to 12.
26. A computer-readable storage medium, characterized in that The computer-readable storage medium includes program instructions, and when the program instructions are executed on a processor, the processor is caused to perform the method according to any one of claims 1 to 12.
Citation Information
Patent Citations
Method and device for matrix data index
CN105095208A
Data processing method and device and hardware accelerator
CN110929854A
Communication method and device
CN111988112A
Method and circuit for executing matrix multiplication and SOC (system on chip)
CN114138231A
