Array element processing method and device, storage medium and electronic equipment
By executing multiple threads in parallel to find non-zero elements in large-scale sparse data, the problem of low efficiency in the prior art is solved, and the effect of improving computing speed and resource utilization is achieved.
Patent Information
- Application Number
- CN202411899466.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-20
- Publication Date
- 2025-04-04
- Estimated Expiration
- 2044-12-20
AI Technical Summary
In large-scale sparse data processing, the method of finding non-zero elements through sequential traversal in the prior art is less efficient, resulting in low efficiency in the processing of array elements.
By executing multiple threads in parallel, dividing the target input array into multiple data subblocks, and finding non-zero elements in the data subblocks in each thread, recording the position index of the non-zero elements into the target output array.
The search efficiency and atomic operation management of non-zero elements in large-scale arrays are improved, the needs of deep learning models on large-scale data are met, and the technical effect of improving the computing speed and resource utilization in model training is achieved.
Smart Images

Figure CN119760180A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of computers, and more specifically, to a method and device for processing array elements, a storage medium, and an electronic device. Background Art
[0002] In the process of deep learning and big data processing, sparse data structures are increasingly used, especially in natural language processing, graph neural networks, recommendation systems, and scientific computing. Sparse data structures have become one of the key technologies for processing high-dimensional data and storage optimization. Among them, sparse data structures usually exist in the form of arrays and contain a large number of zero-valued elements, while their non-zero elements carry the main information required by the model. Therefore, how to efficiently extract and store these non-zero elements has become a problem that needs to be solved.
[0003] In order to solve the above problems, in the related art, a sequential traversal method is usually used to find non-zero elements in sparse data structures, that is, each element in the data structure is checked one by one to determine whether it is non-zero. This method is efficient when processing small-scale data sets, but in large-scale sparse data processing, such as large-scale matrix or tensor processing in deep learning, it takes a lot of time to find and determine the non-zero element index, resulting in a low efficiency technical problem in the processing of array elements.
[0004] With respect to the problem of low efficiency in the process of processing array elements in the related art, no effective solution has been proposed so far. Summary of the invention
[0005] The embodiments of the present application provide a method and device for processing array elements, a storage medium, and an electronic device, so as to at least solve the problem of low efficiency occurring during the processing of array elements.
[0006] According to an embodiment of the present application, a method for processing array elements is provided, including: obtaining a target input array, wherein the target input array includes at least one non-zero element; dividing each element in the target input array into multiple data sub-blocks, wherein one data sub-block includes at least one element; searching for non-zero elements in multiple data sub-blocks by executing multiple threads in parallel to obtain position indexes of the non-zero elements, wherein the position index represents the row coordinates and column coordinates of each non-zero element in a set of non-zero elements shown in the target input array; recording the position indexes of the non-zero elements in a target output array, wherein the column dimension of the target output array is the same as the dimension of the target input array; and training a machine learning model using the target input array and the target output array.
[0007] In an exemplary embodiment, the above-mentioned dividing each element in the target input array into multiple data sub-blocks, wherein a data sub-block includes at least one element, includes: obtaining each row element from the target input array in turn as a current row of elements; dividing the current row of elements according to a preset data segment length to obtain a current group of data sub-blocks, wherein the multiple data sub-blocks include the current group of data sub-blocks.
[0008] In an exemplary embodiment, the above-mentioned method of executing multiple threads in parallel to search for non-zero elements in multiple data sub-blocks and obtain position indexes of non-zero elements includes: obtaining one thread from multiple threads in turn as a current thread; determining a current data sub-block assigned to the current thread from multiple data sub-blocks; and within the current thread, looping through each element in the current data sub-block based on the position index of the element to obtain a set of position indexes of a set of non-zero elements.
[0009] In an exemplary embodiment, the above-mentioned process loops through each element in a current data sub-block based on the position index of the element within a current thread to obtain a set of position indexes of a set of non-zero elements, including: performing the following processing on the i-th element in the current data sub-block that has been traversed, where i is a positive integer greater than or equal to 1: obtaining the i-th position index of the i-th element; finding the i-th element based on the i-th position index; and determining the i-th element as a non-zero element when the i-th element meets a preset judgment condition.
[0010] In an exemplary embodiment, the above-mentioned determining the i-th element as a non-zero element when the i-th element satisfies a preset judgment condition includes: when the value of the i-th element is not 0, determining the i-th element as a non-zero element; or obtaining a preset number of bits used to represent the i-th element; performing a bit operation on the preset number of bits to obtain a target operation result, wherein the bit operation includes performing an AND operation or an OR operation on each bit in the preset number of bits; when the numerical value represented by the target operation result is non-0, determining the i-th element as a non-zero element.
[0011] In an exemplary embodiment, the above-mentioned recording of the position index of the non-zero element into the target output array includes: in the process of executing the first thread and the second thread in parallel, finding the first non-zero element in the first data sub-block through the first thread and calling the global counter; performing an add 1 operation on the global variable through the global counter to obtain a first counting result, and returning a first historical counting result, wherein the first historical counting result indicates the first element position in the target output array where the position index was last written; writing the first position index of the first non-zero element to the second element position after the first element position; finding the second non-zero element in the second data sub-block through the second thread, and calling the first counting result of the global variable, wherein the first counting result indicates the second element position that has been written to the first position index; writing the second position index of the second non-zero element to the third element position adjacent to the second position and after the second element position.
[0012] In an exemplary embodiment, the method further includes: when the target input array is a one-dimensional array, searching for elements at each position in the one-dimensional array by executing multiple threads in parallel; when at least one non-zero element is found by at least one thread, obtaining a third historical count result of a global variable of a global counter, wherein the third historical count result indicates the fourth element position of the position index that was last written in the target output array; for at least one non-zero element, sequentially performing an add 1 operation on the global variable, and writing the first non-zero element found first among the at least one non-zero element to the fifth element position after the fourth element position; sequentially writing the remaining non-zero elements except the first non-zero element to other element positions after the fifth element position; or when the target input array is a two-dimensional array, searching for elements in each data sub-block in the two-dimensional array by executing multiple threads in parallel; and performing a count operation on the global variable of the global counter by executing multiple threads in parallel. When at least one non-zero element is found in the program, a fourth history count result of the global variable is obtained, wherein the fourth history count result represents the sixth element position and the seventh element position of the position index last written in the target output array, the value at the sixth element position represents the row index of the position index last written, and the value at the seventh element position represents the column index of the position index last written; for at least one non-zero element, the global variable is sequentially added by 1, and the row index of the first non-zero element found first among the at least one non-zero element is written to the eighth element position after the sixth element position, and the column index of the first non-zero element is written to the ninth element position after the seventh element position; the row indexes of the remaining non-zero elements except the first non-zero element are sequentially written to other element positions after the eighth element position, and the column indexes of the remaining non-zero elements are sequentially written to other element positions after the ninth element position.
[0013] According to another embodiment of the embodiment of the present application, a processing device for array elements is also provided, including: a first acquisition unit, used to acquire a target input array, wherein the target input array includes at least one non-zero element; a division unit, used to divide each element in the target input array into multiple data sub-blocks, wherein one data sub-block includes at least one element; a first search unit, used to search for non-zero elements in multiple data sub-blocks by executing multiple threads in parallel, and obtain position indexes of the non-zero elements, wherein the position index represents the row coordinates and column coordinates of each non-zero element in the set of non-zero elements shown in the target input array; a recording unit, used to record the position indexes of the non-zero elements in the target output array, wherein the column dimension of the target output array is the same as the dimension of the target input array; a training unit, used to train the machine learning model using the target input array and the target output array.
[0014] According to another embodiment of the present application, a computer-readable storage medium is provided, in which a computer program is stored, wherein the computer program is configured to execute the steps of any of the above method embodiments when running.
[0015] According to another embodiment of the present application, an electronic device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.
[0016] According to another embodiment of the present application, a computer program product is provided. The computer program product includes a computer program. When the computer program is executed by a processor, the steps in any one of the above method embodiments are implemented.
[0017] Through the above-mentioned embodiment provided by the present application, multiple threads executed in parallel are used to synchronously search for non-zero elements in multiple data sub-blocks in the divided target input array, and the position index of the non-zero element is recorded in the target output array. In other words, the technical solution of the present application makes full use of the parallel computing capability of the GPU, improves the search efficiency and atomic operation management of non-zero elements in large-scale arrays by optimizing thread allocation, meets the needs of deep learning models on large-scale data, and achieves the technical effect of improving the computing speed and resource utilization in the model training process. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0019] Figure 1It is a hardware structure block diagram of a server device of a method for processing array elements according to an embodiment of the present application;
[0020] Figure 2 is a flowchart of an optional array element processing method according to an embodiment of the present application;
[0021] Figure 3 is an overall schematic diagram of an optional array element processing method according to an embodiment of the present application;
[0022] Figure 4 is a schematic diagram of an optional data sub-block according to an embodiment of the present application;
[0023] Figure 5 is a schematic diagram of an optional method of writing non-zero element indexes of a two-dimensional array into an output array according to an embodiment of the present application;
[0024] Figure 6 is a specific example of determining non-zero elements by bit operation according to an optional embodiment of the present application;
[0025] Figure 7 is a structural block diagram of a verification device for a soft decoding function according to an embodiment of the present application;
[0026] Figure 8 It is a schematic diagram of the structure of an optional electronic device according to an embodiment of the present application. DETAILED DESCRIPTION
[0027] The embodiments of the present application will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.
[0028] It should be noted that the terms "first", "second", etc. in the specification and claims of this application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence.
[0029] The array element processing method embodiment provided in the embodiment of the present application can be executed in a server device or a similar computing device. Taking running on a server device as an example, Figure 1 1 is a hardware structure block diagram of a server device of an array element processing method according to an embodiment of the present application. Figure 1 As shown, the server device may include one or more ( Figure 1 Only one is shown in the figure) a processor 102 (the processor 102 may include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA) and a memory 104 for storing data, wherein the server device may also include a transmission device 106 and an input / output device 108 for communication functions. It can be understood by those skilled in the art that Figure 1The structure shown is only for illustration and does not limit the structure of the above server device. Figure 1 More or fewer components as shown, or with Figure 1 Different configurations are shown.
[0030] The memory 104 can be used to store computer programs, for example, software programs and modules of application software, such as the computer program corresponding to the method for processing array elements in the embodiment of the present application. The processor 102 executes various functional applications and data processing by running the computer program stored in the memory 104, that is, to implement the above method. The memory 104 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 104 may further include a memory remotely arranged relative to the processor 102, and these remote memories may be connected to the server device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0031] The transmission device 106 is used to receive or send data via a network. The specific example of the above network may include a wireless network provided by a communication provider of the server device. In one example, the transmission device 106 includes a network adapter (Network Interface Controller, referred to as NIC), which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the transmission device 106 can be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.
[0032] In order to solve the above problems existing in the related art, a method for processing array elements is provided in this embodiment, and its execution body includes but is not limited to a non-zero index calculation module in a parallel computing mode based on CUDA, such as Figure 2 As shown, the process includes the following steps S202-S210:
[0033] Step S202: obtaining a target input array, wherein the target input array includes at least one non-zero element;
[0034] Step S204: Divide each element in the target input array into a plurality of data sub-blocks, wherein a data sub-block includes at least one element;
[0035] Step S206: searching for non-zero elements in multiple data sub-blocks by executing multiple threads in parallel to obtain position indexes of the non-zero elements, wherein the position index represents the row coordinates and column coordinates of each non-zero element in the set of non-zero elements in the target input array;
[0036] Step S208: recording the position index of the non-zero element into the target output array, wherein the column dimension of the target output array is the same as the dimension of the target input array;
[0037] Step S210: Train the machine learning model using the target input array and the target output array.
[0038] Specifically, the embodiment of the present application introduces a non-zero index computing module in a parallel computing mode based on CUDA (Compute Unified Device Architecture), wherein the parallel computing in CUDA is implemented through threads, and each thread can be regarded as a lightweight execution unit.
[0039] Among them, the kernel function is the main function executed on the GPU (Graphics Processing Unit) in the CUDA program. The kernel function can be regarded as a function executed in parallel. When called, multiple threads will be started to execute the kernel function code in parallel.
[0040] In addition to the above kernel functions, CUDA also supports atomic operations, which are very useful when updating shared data in a multi-threaded environment. It can ensure the atomicity and consistency of the operation. The use process of atomic operations will be described in detail below in conjunction with specific embodiments.
[0041] For ease of understanding, in the embodiments of the present application, a one-dimensional array is first taken as an example to briefly introduce the process of searching for the position index of non-zero elements in a target input array using multiple threads executed in parallel.
[0042] Table 1 below provides a process of using GPU to execute multiple threads in parallel to search for non-zero elements in a one-dimensional array:
[0043] Table 1
[0044]
[0045]
[0046] The element index in Table 1 can be understood as the position index of the non-zero element in the target input array. The so-called position index includes but is not limited to the position identifier of the non-zero element in the one-dimensional array, for example, the first bit is 0, the second bit is 1, and so on.
[0047] In a two-dimensional array, the position index of the above-mentioned non-zero element includes but is not limited to the row identifier and column identifier of the non-zero element in the two-dimensional array. For example, in a two-dimensional array with a dimension of 3×3, the row identifier a(0) and the column identifier b(0) represent the position index of the element located in the first row and the first column.
[0048] The atomic operations in Table 1 are mainly used when multiple threads executed in parallel find non-zero elements in the target input array. If multiple non-zero elements are found at the same time, only the position index of one non-zero element among the multiple non-zero elements can be written into the target output array at the same time, and the purpose is to ensure the uniqueness and non-overwriting of the non-zero element index written into the output array. The writing process of the position index will be explained in conjunction with a specific embodiment.
[0049] In GPU programming, atomic operations refer to the situation where multiple threads may access the same memory location at the same time during the parallel execution of multiple threads. If there is no proper synchronization mechanism, race conditions may occur, leading to data inconsistency.
[0050] During an atomic operation, when multiple threads need to update the value of the same counter or accumulator, atomic operations can be used to ensure the atomicity of the update.
[0051] Combine the following Figure 3 The processing flow of array elements is described as shown in Table 1 above.
[0052] S302, obtaining an input array;
[0053] In this embodiment, in order to facilitate understanding of the solution, a one-dimensional array is taken as an example to explain the above array element processing method. At the same time, the processing method and steps can be extended to multi-dimensional arrays or multi-dimensional tensors to supplement the implementation of non-zero index calculation of various data structures.
[0054] S304, assigning a GPU thread to each element in the input array;
[0055] The method in which a thread searches for whether an element is non-zero here is only an example and is not limited thereto. In actual application scenarios, thread 1 can also be used to search for each element (2, 0, 4) in data sub-block 1, and thread 2 can be used to search for each element (56, 0) in data sub-block 2 as a non-zero element.
[0056] S306, using each GPU thread, determining whether the element processed by the thread is a non-zero element;
[0057] If yes, execute step S308; otherwise, return to the previous level.
[0058] S308, in the process of executing multiple computing threads in parallel, writing the position index of the non-zero element found into the output array;
[0059] like Figure 3 As shown, in the process of writing the position index of non-zero elements, the global variable out_indices is introduced, and the initial value of out_indices is equal to 0, which means that the first write position is the 0th position in the output array (which can be understood as the first position, for example, Figure 3 3). In other words, the value of the global variable indicates the element position at which the position index in the target output array is written.
[0060] In the above example, the element 3 written at the first position in the output array may represent, but is not limited to, the position index Idx=3 of the element 56 in the input array found by thread 4. The case where multiple non-zero element indexes are found at the same time will be explained below with reference to specific examples.
[0061] In the above manner, multiple threads executed in parallel are used to synchronously search for non-zero elements in multiple data sub-blocks in the divided target input array, and the position index of the non-zero elements is recorded in the target output array. In other words, the technical solution of the present application makes full use of the parallel computing capability of the GPU, improves the search efficiency and atomic operation management of non-zero elements in large-scale arrays by optimizing thread allocation, meets the needs of deep learning models on large-scale data, and achieves the technical effect of improving the computing speed and resource utilization in the model training process.
[0062] In an exemplary embodiment, each element in the target input array is divided into a plurality of data sub-blocks, wherein a data sub-block includes at least one element, including:
[0063] Get each row of elements from the target input array in turn as the current row of elements;
[0064] According to a preset data segment length, a current row of elements is divided to obtain a current group of data sub-blocks, wherein the multiple data sub-blocks include the current group of data sub-blocks.
[0065] The process of dividing each element in the target input array into a plurality of data sub-blocks includes but is not limited to the following steps: Figure 4 As shown, there are a total of 10 elements in the target input array. These 10 elements are divided into 2 groups, and 5 elements in each group are determined as a data sub-block. Then, two threads are used to synchronously traverse multiple data segments (that is, multiple elements) in the two data sub-blocks.
[0066] By reading the elements of each row in the target input array in turn, treating them as the elements of the current row, and dividing the elements of the current row according to the preset data segment length, a current group of data sub-blocks is obtained, wherein the data segment length of each data sub-block in the current group of data sub-blocks may be the same or different, and the embodiment of the present application is not limited to this.
[0067] By dividing the target input array into smaller data sub-blocks, the number of data segments that can be processed in parallel can be reduced, thereby improving the parallel computing efficiency of the GPU; at the same time, out-of-order reading of memory access is shortened, and the locality of data access is improved, thereby reducing GPU memory access latency and improving computing performance.
[0068] In addition, through the optimization of the above threads, not only the search speed of non-zero elements in large-scale sparse data structures (for example, large-scale sparse matrices) is improved, but also the storage overhead is optimized, providing strong support for efficient computing in fields such as deep learning, recommendation systems, and graph neural networks.
[0069] In an exemplary embodiment, the above-mentioned searching for non-zero elements in multiple data sub-blocks by executing multiple threads in parallel to obtain position indexes of the non-zero elements includes:
[0070] Obtain one thread from multiple threads in turn as the current thread;
[0071] Determine a current data sub-block allocated to a current thread from the plurality of data sub-blocks;
[0072] In a current thread, based on the position index of the element, each element in the current data sub-block is looped through to obtain a set of position indexes of a set of non-zero elements.
[0073] This embodiment is a deepening of the specific implementation of the above non-zero element search method, focusing on thread scheduling, data sub-block allocation and non-zero element search logic of thread content.
[0074] Specifically, in the parallel computing mode, taking one thread among multiple threads as an example, within the one thread, based on the position index Idx of the element in the target input array, each element in its allocated data sub-block is looped through to find and locate the non-zero element.
[0075] For example, suppose the target input array is Figure 5 The two-dimensional array shown, assuming that each row is a data sub-block, includes a total of 3 data sub-blocks, and then thread 1 is used to search for non-zero elements in the 3 elements of the first row, thread 2 is used to interpolate the non-zero elements of the 3 elements of the second row, and thread 3 is used to search for non-zero elements in the 3 elements of the third row.
[0076] When using thread 1 to search for the three elements in the first row, the position of the non-zero element found by thread 1 in the target input array is determined mainly based on the position index of the three elements in the target input array.
[0077] The position index of the element provides its precise position in the target input array, which is crucial for the subsequent recording of index information. The specific process of traversal is as follows:
[0078] The following processing is performed on the i-th element in the current data sub-block that is traversed, where i is a positive integer greater than or equal to 1:
[0079] Get the i-th position index of the i-th element;
[0080] Based on the i-th position index, find the i-th element;
[0081] When the i-th element satisfies a preset determination condition, the i-th element is determined as a non-zero element.
[0082] Based on the obtained position index, the current thread accurately searches for and accesses the i-th element in the target input array. Subsequently, the thread determines whether the element is a non-zero element according to the preset judgment condition.
[0083] For example, Figure 3 As shown, the currently accessed i-th element is compared with the value 0 to determine whether the i-th element is a non-zero element. Once it is determined to be a non-zero element, the thread will use atomic operations to record the position index of the non-zero element into the target output array, avoiding data conflicts that may occur in parallel computing. In addition, by controlling the synchronization between threads, it is ensured that the index information of all non-zero elements is recorded correctly.
[0084] In this way, each thread can accurately locate the element it needs to process, avoiding unnecessary access to the target input array and improving data processing efficiency. In addition, through simple conditional judgment, non-zero elements can be quickly and accurately identified, reducing the waste of computing resources.
[0085] By adopting the embodiments of the present application, the computing efficiency of parallel threads is improved and the accuracy of data processing is ensured, invalid computing operations and data processing delays are significantly reduced, and at the same time, the correctness and consistency of position index lookup of non-zero elements are guaranteed.
[0086] In an exemplary embodiment, when the i-th element satisfies a preset determination condition, determining the i-th element as a non-zero element includes:
[0087] When the value of the i-th element is not 0, the i-th element is determined to be a non-zero element; or
[0088] Get a preset number of bits used to represent the i-th element;
[0089] Performing a bit operation on a preset number of bits to obtain a target operation result, wherein the bit operation includes performing an AND operation or an OR operation on each bit in the preset number of bits;
[0090] When the value represented by the target operation result is non-zero, the i-th element is determined to be a non-zero element.
[0091] As can be seen from the description in the above embodiments, when searching for non-zero elements in a data sub-block using one thread, it is usually possible to determine whether an element in the data sub-block is 0, thereby determining whether the element is a non-zero element.
[0092] In addition, for some sparse matrix or arrays, bit masking, conditional filtering and other methods can be used to quickly determine whether an element is 0, thereby reducing the overhead of conditional judgment.
[0093] The above determination method of directly comparing the element value with 0 is simple and direct, and is applicable to scenarios where the element value is an integer or a floating-point number, but may be less efficient when processing certain specific data types because additional type conversion or checking operations may be involved.
[0094] For example, if Figure 6 As shown, assuming that 4 bits in the register are used to represent the elements in the target input array, it is possible but not limited to perform bit operations on the binary number itself, and determine whether the element represented by the binary number is a non-zero element based on the result of the micro-operation.
[0095] Specifically, two binary numbers at the same position on two identical binary numbers are ANDed in sequence according to the bit position, and the result of the ANDed operation is 0100, which represents the number 2, indicating that the element currently being judged is a non-zero element.
[0096] Similarly, referring to the above-mentioned AND operation method, two bytes of 8 bits (or 16 bits, etc.) can be ORed bit by bit, and whether the element is a non-zero element can be determined based on the result of the OR operation.
[0097] The above bit operations can be used to directly determine non-zero elements on the binary representation of the element value. Especially when processing integer type data, by checking whether there is a 1 in the bit, it is possible to quickly determine whether the element is non-zero, thereby reducing the calculation time.
[0098] In addition, bit manipulation methods are particularly suitable for parallel computing environments because they can process multiple bits at the same time, making full use of the parallel computing capabilities of the GPU to improve overall computing efficiency. In other words, by applying bit manipulation methods to different levels of data processing, the efficiency and performance of parallel computing can be further improved.
[0099] The bit operation optimization method can not only be used to determine non-zero elements, but can also be applied to a wider range of parallel computing tasks, such as data compression, feature selection, etc., which improves the scope of application of the technical solution of the present application.
[0100] In an exemplary embodiment, the above-mentioned recording the position index of the non-zero element into the target output array includes:
[0101] In the process of executing the first thread and the second thread in parallel, the first thread searches for a first non-zero element in the first data sub-block and calls a global counter;
[0102] By using a global counter, performing an increment operation on the global variable to obtain a first counting result, and returning a first historical counting result, wherein the first historical counting result indicates the first element position of the last written position index in the target output array;
[0103] Write the first position index of the first non-zero element to the second element position after the first element position;
[0104] Finding a second non-zero element in a second data sub-block through a second thread, calling a first counting result of a global variable, wherein the first counting result indicates a second element position that has been written to the first position index;
[0105] The second position index of the second non-zero element is written to a third element position adjacent to the second position and after the second element position.
[0106] Suppose there is a sparse matrix, in which, by executing thread 1 and thread 2 in parallel, the non-zero elements in the data sub-blocks that the two threads are responsible for are found. On the GPU, when the threads are executed in parallel, each thread may find one or more non-zero elements and record the position index of the non-zero elements they found in the global output array output.
[0107] However, since GPU threads execute concurrently, multiple threads may attempt to write to the same location in the output array at the same time. For example, thread 1 is responsible for finding Figure 5 The first row of elements shown, thread 2 is used to find Figure 5If there is no synchronization mechanism to manage the writing order of the threads, a write conflict will occur, resulting in incorrect results or data loss.
[0108] For example, write the two non-zero elements found by thread 1 and thread 2 to the same position in the output array, such as Figure 3 The output[0] shown is Figure 3 If the first bit is shown, the write operation of one thread will overwrite the result of another thread, resulting in the position index of some non-zero elements not being recorded.
[0109] In order to solve the above problem, the atomicAdd atomic operation is used to ensure the atomicity of each addition operation. Usually a global counter output_indices is used to track the current write position.
[0110] For example, when thread 1 in the above embodiment finds Figure 5 When there is a non-zero element 6 in the first row of elements of the input array shown, and thread 2 finds a non-zero element 7 in the third row, it calls atomicAdd(output_indices,1) to increase the global variable output_indices by 1 and return the old value before the increase.
[0111] The thread will use this old value as the only write location to store the position index of the non-zero element. The atomic operation can ensure that each thread can exclusively obtain a unique write location, thereby avoiding write conflicts.
[0112] Among them, when thread 1 and thread 2 find non-zero elements at the same time, if the first non-zero element found by thread 1 is responded to first, then in the process of calling the global counter to perform the first addition operation on the global variable, the processing flow of the second non-zero element found by thread 2 will be blocked.
[0113] When writing the first non-zero element found by thread 1 to the output array, the old value of the global variable before the first addition operation is performed is returned. For example, returning 0 means that the first non-zero element 6 will be written to the first position in the output array.
[0114] When the second non-zero element found by thread 2 is written to the output array, the global variable performs a second increment operation and returns the old value 1 of the global variable after the first increment operation. Then the second non-zero element is written to the second position (output[1]) in the output array.
[0115] That is to say, through atomic operability, the position index of the non-zero element to be written in the current process can be determined by using the value of the global variable after the addition operation is performed in the previous writing process.
[0116] Atomic operations ensure that modifications to global variables are not interfered with by other threads, avoiding race conditions and improving the efficiency of parallel computing. The global counter is used to record the position of the element indexed by the last write position in the target output array. By performing atomic operations on it, the write position can be accurately assigned to each non-zero element to avoid data conflicts and overwriting. Synchronization of index records: Through global counters and atomic operations, efficient synchronization of non-zero element index records can be achieved, ensuring the accuracy and completeness of index information in a parallel computing environment.
[0117] In an exemplary embodiment, the method further includes:
[0118] When the target input array is a one-dimensional array, multiple threads are executed in parallel to find the element at each position in the one-dimensional array;
[0119] In the case where at least one non-zero element is found through at least one thread, a third historical counting result of the global variable of the global counter is obtained, wherein the third historical counting result represents the fourth element position of the position index that was last written in the target output array;
[0120] For at least one non-zero element, perform an increment operation on the global variable in sequence, and write the first non-zero element found among the at least one non-zero element to the fifth element position after the fourth element position;
[0121] Write the remaining non-zero elements except the first non-zero element to the other element positions after the fifth element position in sequence; or
[0122] When the target input array is a two-dimensional array, multiple threads are executed in parallel to search for elements in each data sub-block in the two-dimensional array;
[0123] In the case where at least one non-zero element is found through at least one thread, a fourth history count result of the global variable is obtained, wherein the fourth history count result represents the sixth element position and the seventh element position of the last written position index in the target output array, the value at the sixth element position represents the row index of the last written position index, and the value at the seventh element position represents the column index of the last written position index;
[0124] For at least one non-zero element, perform the addition operation on the global variable in sequence, and write the row index of the first non-zero element found first among the at least one non-zero element to the eighth element position after the sixth element position, and write the column index of the first non-zero element to the ninth element position after the seventh element position;
[0125] The row indices of the remaining non-zero elements except the first non-zero element are sequentially written to the other element positions after the eighth element position, and the column indices of the remaining non-zero elements are sequentially written to the other element positions after the ninth element position.
[0126] In a specific embodiment, assuming that the target input array is as follows Figure 3 The one-dimensional array shown, and each thread is used to find whether an element in the input array is a non-zero element.
[0127] That is, thread 1 is used to determine whether the first element is non-zero, thread 2 is used to determine whether the second non-zero element is non-zero, and so on, thread 4 is used to determine whether the fourth element 56 is non-zero. In the process of executing multiple threads in parallel, the initial value of the global variable in the global counter output_indices defaults to 0, that is, the first non-zero index written will be recorded in the first position of the output array.
[0128] If thread 4 first executes the step of adding 1 to the global counter, triggering the atomic operation, output_indices will increase by 1, and thread 1 will be blocked by the atomic operation of thread 4. After waiting for the atomic operation of thread 4 to complete, thread 4 will find the position index Idx=3 and it will be written to the first bit of the output array.
[0129] After removing the influence of thread 4's atomic operation on thread 1, thread 1 will call the false 1 operation step of the global counter, output_indices will be increased by 1 again, and the old value 1 after thread 4's increase by 1 operation will be returned, and the position index Idx=0 of the non-zero element found by thread 1 will be written to output[1] in the output array indicated by the old value 1, that is, the position index Idx=0 will be written to the second position of the output array. Similarly, the position indexes of the non-zero elements found by each thread will be written to the corresponding element positions of the output array one by one.
[0130] In another specific example, suppose the target input array is Figure 5 The two-dimensional array shown uses thread 1 to search for the first row of elements in the input two-dimensional array, thread 2 to search for the second row of elements in the two-dimensional array, and thread 3 to search for the third row of elements in the two-dimensional array.
[0131] Since the position index of an element of a two-dimensional array includes two parts, the row index and the column index, the addition operation in the global counter is also performed in both the row and column dimensions.
[0132] For example, when thread 1 finds the non-zero element 6 in the first row, since the position index of 6 is the 1st row and the 3rd column, the row index 1 is written to the element position of the first row and the first column of the output array; then when thread 3 executes the step of adding 1 to the global counter, the position index (3rd row, 2nd column) of the non-zero element 7 in the third row is written to the two element positions of the second row in the output array.
[0133] When processing the index records of non-zero elements in a two-dimensional array, attention will be paid to the synchronous records of the row index and column index of the non-zero elements. During the last write process, the count changes in the row and column dimensions were also included when the plus 1 operation was performed. When one of the threads finds a non-zero element, the row index of the non-zero element is written to the corresponding position of the first column in the output array, and the column index is written to the corresponding element position of the second column in the output array through the row count and column count in the old value of the returned global counter.
[0134] It should be noted that the number of columns of the output array corresponding to the two-dimensional array is 2, and the number of columns of the output array corresponding to the one-dimensional array is 1. That is, the column dimension of the target output array is the same as the dimension of the target input array.
[0135] Through the above atomic operation method, it can be ensured that each thread will not be interrupted by other threads when executing the count plus 1 operation. Therefore, each non-zero element will be accurately written to a different position of the output array output, avoiding data loss or overwriting problems.
[0136] The embodiment of the present application realizes efficient non-zero index search for large-scale sparse matrices (a type of target input array) on the GPU, significantly improves the search speed of sparse data, and optimizes storage overhead, so that the technical solution of the present application can be used for large-scale sparse data processing in scenarios such as deep learning models, recommendation systems, and graph neural networks.
[0137] In the process of searching for the position index of non-zero elements, the embodiment of the present application designs a parallelized non-zero element search module, which utilizes intra-thread loop traversal and conditional filtering to enable each GPU thread to independently process elements in a specific data segment. At the same time, atomic operations are used to avoid write conflicts in parallel computing mode, thereby improving the efficiency of searching for non-zero values.
[0138] The above-mentioned technical solution of the method for searching non-zero data in a large-scale one-dimensional or two-dimensional sparse array can be applied to, but not limited to, the training process of a deep learning model. In addition, in the natural language processing scenario, the efficiency and performance of natural language processing can also be improved by searching for non-zero elements in text data.
[0139] Through the description of the above implementation methods, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes a number of instructions for a terminal device (which can be a mobile phone, computer, server, or network device, etc.) to execute the methods of each embodiment of the present application.
[0140] In the present embodiment, a processing device for array elements is also provided to implement the above-mentioned embodiments and preferred implementation modes, which have been described and will not be repeated here. As used below, the term "module" can implement a combination of software and / or hardware of a predetermined function. Although the modules described in the following embodiments are preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and conceivable.
[0141] Figure 7 is a structural block diagram of a device for processing array elements according to an embodiment of the present application, the device comprising:
[0142] A first acquisition unit 702 is used to acquire a target input array, wherein the target input array includes at least one non-zero element;
[0143] A division unit 704 is used to divide each element in the target input array into a plurality of data sub-blocks, wherein a data sub-block includes at least one element;
[0144] A first search unit 706 is configured to search for non-zero elements in a plurality of data sub-blocks by executing a plurality of threads in parallel, and obtain position indexes of the non-zero elements, wherein the position indexes represent row coordinates and column coordinates of each non-zero element in the set of non-zero elements in the target input array;
[0145] A recording unit 708, configured to record the position index of the non-zero element into a target output array, wherein the column dimension of the target output array is the same as the dimension of the target input array;
[0146] The training unit 710 is used to train the machine learning model using the target input array and the target output array.
[0147] In an exemplary embodiment, the division unit 704 includes:
[0148] A first acquisition module is used to acquire a target input array, wherein the target input array includes at least one non-zero element;
[0149] A first partitioning module, used to partition each element in the target input array into a plurality of data sub-blocks, wherein a data sub-block includes at least one element;
[0150] A first search module is used to search for non-zero elements in multiple data sub-blocks by executing multiple threads in parallel to obtain position indexes of the non-zero elements, wherein the position index represents the row coordinates and column coordinates of each non-zero element in the set of non-zero elements in the target input array;
[0151] A first recording module, used for recording the position index of the non-zero element into a target output array, wherein the column dimension of the target output array is the same as the dimension of the target input array;
[0152] The first training module is used to train the machine learning model using the target input array and the target output array.
[0153] In an exemplary embodiment, the first search unit 706 includes:
[0154] A second acquisition module is used to sequentially acquire one thread from the multiple threads as a current thread;
[0155] A first processing module, configured to determine a current data sub-block allocated to a current thread from a plurality of data sub-blocks;
[0156] The second processing module is used to loop through each element in a current data sub-block based on the position index of the element in a current thread to obtain a set of position indexes of a set of non-zero elements.
[0157] In an exemplary embodiment, the second processing module includes:
[0158] The first processing submodule is used to perform the following processing on the i-th element in the current data subblock that has been traversed, where i is a positive integer greater than or equal to 1:
[0159] Get the i-th position index of the i-th element;
[0160] Based on the i-th position index, find the i-th element;
[0161] When the i-th element satisfies a preset determination condition, the i-th element is determined as a non-zero element.
[0162] In an exemplary embodiment, the second processing module includes:
[0163] a second processing submodule, configured to determine the ith element as a non-zero element when the value of the ith element is not 0; or
[0164] Get a preset number of bits used to represent the i-th element;
[0165] Performing a bit operation on a preset number of bits to obtain a target operation result, wherein the bit operation includes performing an AND operation or an OR operation on each bit in the preset number of bits;
[0166] When the value represented by the target operation result is non-zero, the i-th element is determined to be a non-zero element.
[0167] In an exemplary embodiment, the recording unit 708 includes:
[0168] A second search module is used to search for a first non-zero element in a first data sub-block through the first thread and call a global counter during the parallel execution of the first thread and the second thread;
[0169] A third processing module is used to perform an addition operation on the global variable through a global counter to obtain a first counting result, and return a first historical counting result, wherein the first historical counting result indicates the first element position of the last written position index in the target output array;
[0170] A first writing module, used for writing a first position index of a first non-zero element to a second element position located after the first element position;
[0171] A fourth processing module is used to find a second non-zero element in the second data sub-block through a second thread, and call a first counting result of the global variable, wherein the first counting result indicates a second element position that has been written into the first position index;
[0172] The second writing module is used to write the second position index of the second non-zero element to a third element position adjacent to the second position and located after the second element position.
[0173] In an exemplary embodiment, the first search unit 706 includes:
[0174] A fifth processing module, for searching for an element at each position in the one-dimensional array by executing multiple threads in parallel when the target input array is a one-dimensional array;
[0175] In the case where at least one non-zero element is found through at least one thread, a third historical counting result of the global variable of the global counter is obtained, wherein the third historical counting result represents the fourth element position of the position index that was last written in the target output array;
[0176] For at least one non-zero element, perform an increment operation on the global variable in sequence, and write the first non-zero element found among the at least one non-zero element to the fifth element position after the fourth element position;
[0177] Write the remaining non-zero elements except the first non-zero element to the other element positions after the fifth element position in sequence; or
[0178] When the target input array is a two-dimensional array, multiple threads are executed in parallel to search for elements in each data sub-block in the two-dimensional array;
[0179] In the case where at least one non-zero element is found through at least one thread, a fourth history count result of the global variable is obtained, wherein the fourth history count result represents the sixth element position and the seventh element position of the last written position index in the target output array, the value at the sixth element position represents the row index of the last written position index, and the value at the seventh element position represents the column index of the last written position index;
[0180] For at least one non-zero element, perform the addition operation on the global variable in sequence, and write the row index of the first non-zero element found first among the at least one non-zero element to the eighth element position after the sixth element position, and write the column index of the first non-zero element to the ninth element position after the seventh element position;
[0181] The row indices of the remaining non-zero elements except the first non-zero element are sequentially written to the other element positions after the eighth element position, and the column indices of the remaining non-zero elements are sequentially written to the other element positions after the ninth element position.
[0182] It should be noted that the above modules can be implemented by software or hardware. For the latter, it can be implemented in the following ways, but not limited to: the above modules are all located in the same processor; or the above modules are located in different processors in any combination.
[0183] An embodiment of the present application further provides a computer-readable storage medium, in which a computer program is stored, wherein the computer program is configured to execute the steps of any of the above method embodiments when running.
[0184] Optionally, in this embodiment, the computer program may be configured to perform the following steps by means of the computer program:
[0185] S1, obtaining a target input array, wherein the target input array includes at least one non-zero element;
[0186] S2, dividing each element in the target input array into a plurality of data sub-blocks, wherein a data sub-block includes at least one element;
[0187] S3, searching for non-zero elements in multiple data sub-blocks by executing multiple threads in parallel, and obtaining position indexes of the non-zero elements, wherein the position indexes represent row coordinates and column coordinates of each non-zero element in the set of non-zero elements in the target input array;
[0188] S4, recording the position index of the non-zero element into the target output array, wherein the column dimension of the target output array is the same as the dimension of the target input array;
[0189] S5, trains the machine learning model using the target input array and the target output array.
[0190] In an exemplary embodiment, the computer-readable storage medium may include, but is not limited to, various media that can store computer programs, such as a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk.
[0191] The embodiment of the present application also provides an electronic device, such as Figure 8 As shown, the electronic device includes a memory 802 and a processor 804. The memory 802 stores a computer program, and the processor 804 is configured to execute the steps in any of the above method embodiments through the computer program.
[0192] Optionally, in this embodiment, the processor 804 may be configured to perform the following steps through a computer program:
[0193] S1, obtaining a target input array, wherein the target input array includes at least one non-zero element;
[0194] S2, dividing each element in the target input array into a plurality of data sub-blocks, wherein a data sub-block includes at least one element;
[0195] S3, searching for non-zero elements in multiple data sub-blocks by executing multiple threads in parallel, and obtaining position indexes of the non-zero elements, wherein the position indexes represent row coordinates and column coordinates of each non-zero element in the set of non-zero elements in the target input array;
[0196] S4, recording the position index of the non-zero element into the target output array, wherein the column dimension of the target output array is the same as the dimension of the target input array;
[0197] S5, trains the machine learning model using the target input array and the target output array.
[0198] For specific examples in this embodiment, reference may be made to the examples described in the above embodiments and exemplary implementation modes, and this embodiment will not be described in detail herein.
[0199] Alternatively, a person skilled in the art may understand that: Figure 8 The structure shown is for illustration only. Figure 8 The structure of the electronic device is not limited. For example, the electronic device may also include Figure 8 More or fewer components (such as network interfaces, etc.) as shown in, or with Figure 8 Different configurations are shown.
[0200] Among them, the memory 802 can be used to store software programs and modules, such as the program instructions / modules corresponding to the array element processing method and the array element processing device in the embodiment of the present application. The processor 804 executes various functional applications and data processing by running the software programs and modules stored in the memory 802, that is, realizing the above-mentioned array element processing method. The memory 802 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 802 may further include a memory remotely arranged relative to the processor 804, and these remote memories may be connected to the terminal via a network. Examples of the above-mentioned networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof. Among them, the memory 802 can be specifically, but not limited to, used to store information such as a target input array, multiple data sub-blocks, etc. As an example, such as Figure 8 As shown, the memory 802 may include, but is not limited to, the first acquisition unit 702, the division unit 704, the first search unit 706, the recording unit 708, and the training unit 710 in the array element processing device. In addition, other module units in the array element processing device may also be included but are not limited to the above, which will not be repeated in this example.
[0201] Optionally, the transmission device 806 is used to receive or send data via a network. Specific examples of the network may include wired networks and wireless networks. In one example, the transmission device 806 includes a network adapter (Network Interface Controller, NIC), which can be connected to other network devices and routers via a network cable so as to communicate with the Internet or a local area network. In one example, the transmission device 806 is a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.
[0202] In addition, the electronic device mentioned above further includes: a display 808; and a connection bus 810, which is used to connect various module components in the electronic device mentioned above.
[0203] In other embodiments, the electronic device may be a node in a distributed system, wherein the distributed system may be a blockchain system, and the blockchain system may be a distributed system formed by connecting the multiple nodes in the form of network communication. Among them, the nodes may form a peer-to-peer (P2P) network, and any form of computing device, such as a server, terminal, or other electronic device, may become a node in the blockchain system by joining the peer-to-peer network.
[0204] An embodiment of the present application further provides a computer program product, which includes a computer program. When the computer program is executed by a processor, the steps in any of the above method embodiments are implemented.
[0205] An embodiment of the present application further provides another computer program product, including a non-volatile computer-readable storage medium, wherein the non-volatile computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps in any of the above method embodiments are implemented.
[0206] The embodiments of the present application also provide a computer program, which includes computer instructions, which are stored in a computer-readable storage medium; a processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device performs the steps of any one of the above method embodiments.
[0207] Obviously, those skilled in the art should understand that the above modules or steps of the present application can be implemented by a general computing device, they can be concentrated on a single computing device, or distributed on a network composed of multiple computing devices, they can be implemented by a program code executable by a computing device, so that they can be stored in a storage device and executed by the computing device, and in some cases, the steps shown or described can be executed in a different order from that herein, or they can be made into individual integrated circuit modules, or multiple modules or steps therein can be made into a single integrated circuit module for implementation. Thus, the present application is not limited to any specific combination of hardware and software.
[0208] The above are only preferred embodiments of the present application and are not intended to limit the present application. For those skilled in the art, the present application may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the principles of the present application shall be included in the protection scope of the present application.
Claims
1. A method for processing array elements, characterized in that: include: Obtaining a target input array, wherein the target input array includes at least one non-zero element; Dividing each element in the target input array into a plurality of data sub-blocks, wherein a data sub-block includes at least one element; By executing multiple threads in parallel, searching for non-zero elements in the multiple data sub-blocks, obtaining position indexes of the non-zero elements, wherein the position indexes represent row coordinates and column coordinates of each non-zero element in the set of non-zero elements in the target input array; Recording the position index of the non-zero element into a target output array, wherein the column dimension of the target output array is the same as the dimension of the target input array; The machine learning model is trained using the target input array and the target output array.
2. The method according to claim 1, characterized in that The step of dividing each element in the target input array into a plurality of data sub-blocks, wherein a data sub-block includes at least one element, comprises: Obtaining each row of elements from the target input array in sequence as the current row of elements; The elements of the current row are divided according to a preset data segment length to obtain a current group of data sub-blocks, wherein the multiple data sub-blocks include the current group of data sub-blocks.
3. The method according to claim 1, characterized in that The step of searching for non-zero elements in the plurality of data sub-blocks by executing the plurality of threads in parallel to obtain position indexes of the non-zero elements includes: Obtain one thread from the multiple threads in sequence as a current thread; Determine a current data sub-block allocated to the current thread from the multiple data sub-blocks; In the current thread, based on the position index of the element, each element in the current data sub-block is traversed in a loop to obtain a set of position indexes of a set of non-zero elements.
4. The method according to claim 3, characterized in that In the current thread, based on the position index of the element, looping through each element in the current data sub-block to obtain a set of position indexes of a set of non-zero elements, including: The following processing is performed on the i-th element in the current data sub-block that has been traversed, where i is a positive integer greater than or equal to 1: Get the i-th position index of the i-th element; Based on the i-th position index, find the i-th element; When the i-th element satisfies a preset determination condition, the i-th element is determined as a non-zero element.
5. The method according to claim 4, characterized in that The step of determining the i-th element as a non-zero element when the i-th element satisfies a preset determination condition includes: When the value of the i-th element is not 0, determining the i-th element as a non-zero element; or Obtaining a preset number of bits for representing the i-th element; Performing a bit operation on the preset number of bits to obtain a target operation result, wherein the bit operation includes performing an AND operation or an OR operation on each bit in the preset number of bits; When the value represented by the target operation result is non-zero, the i-th element is determined to be a non-zero element.
6. The method according to claim 1, characterized in that The step of recording the position index of the non-zero element into the target output array includes: In the process of executing the first thread and the second thread in parallel, the first thread searches for a first non-zero element in the first data sub-block and calls a global counter; By using the global counter, performing an addition operation on the global variable to obtain a first counting result, and returning a first historical counting result, wherein the first historical counting result indicates the first element position of the last written position index in the target output array; Writing the first position index of the first non-zero element to the second element position after the first element position; Finding a second non-zero element in a second data sub-block through the second thread, calling the first counting result of the global variable, wherein the first counting result indicates the second element position that has been written to the first position index; The second position index of the second non-zero element is written to a third element position adjacent to the second position and after the second element position.
7. The method according to any one of claims 1 to 6, characterized in that The method further comprises: In the case where the target input array is a one-dimensional array, searching for an element at each position in the one-dimensional array by executing the multiple threads in parallel; In the case where at least one non-zero element is found through at least one thread, a third historical counting result of the global variable of the global counter is obtained, wherein the third historical counting result represents the fourth element position of the last written position index in the target output array; For the at least one non-zero element, sequentially perform an addition operation on the global variable, and write the first non-zero element found first among the at least one non-zero element to the fifth element position after the fourth element position; writing the remaining non-zero elements except the first non-zero element into other element positions after the fifth element position in sequence; or In the case where the target input array is a two-dimensional array, searching for elements in each data sub-block in the two-dimensional array by executing the multiple threads in parallel; In the case where the at least one non-zero element is found by the at least one thread, a fourth history count result of the global variable is obtained, wherein the fourth history count result represents the sixth element position and the seventh element position of the last written position index in the target output array, the value at the sixth element position represents the row index of the last written position index, and the value at the seventh element position represents the column index of the last written position index; For the at least one non-zero element, sequentially perform an addition operation on the global variable, and write the row index of the first non-zero element found first among the at least one non-zero element to the eighth element position after the sixth element position, and write the column index of the first non-zero element to the ninth element position after the seventh element position; The row indices of the remaining non-zero elements except the first non-zero element are sequentially written into other element positions after the eighth element position, and the column indices of the remaining non-zero elements are sequentially written into other element positions after the ninth element position.
8. A device for processing array elements, characterized in that: include: A first acquisition unit is used to acquire a target input array, wherein the target input array includes at least one non-zero element; A partitioning unit, configured to partition each element in the target input array into a plurality of data sub-blocks, wherein a data sub-block includes at least one element; A first search unit is configured to search for non-zero elements in the plurality of data sub-blocks by executing a plurality of threads in parallel, and obtain position indexes of the non-zero elements, wherein the position indexes represent row coordinates and column coordinates of each non-zero element in the set of non-zero elements in the target input array; A recording unit, used for recording the position index of the non-zero element into a target output array, wherein the column dimension of the target output array is the same as the dimension of the target input array; A training unit is used to train a machine learning model using the target input array and the target output array.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, wherein the computer program implements the steps of the method described in any one of claims 1 to 7 when executed by a processor.
10. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the method described in any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
Method for storing diagonal data of sparse matrix and SpMV (Sparse Matrix Vector) realization method based on method
CN102141976A
Data compression method and device, electronic equipment and readable storage medium
CN117873394A
Sparse matrix storage method and vector multiplication method
CN118484135A
Computer-readable recording medium storing information processing program and information processing method
US20230068150A1
Matrix storage method and device
WO2024222762A1