Method for accelerating sparse multi-scalar multiplication by using image processor
By performing bucket distribution, bucket sum and bucket merging calculations on the image processor, and using sparseness to accelerate sparse multi-scalar multiplication, the problem of inefficiency in the existing technology is solved, and significant performance improvement and efficient expansion capabilities are achieved.
Patent Information
- Application Number
- CN202411653089.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-19
- Publication Date
- 2025-02-28
- Estimated Expiration
- 2044-11-19
AI Technical Summary
When the prior art uses GPU for sparse multiscalar multiplication acceleration, it fails to fully utilize the sparseness of the scalar value distribution, resulting in low efficiency.
By migrating the calculation example of sparse multiscalar multiplication to the image processor's video memory, and using the image processor to perform bucket distribution, bucket sum and bucket merging calculations, the sparseness of the scalar is fully utilized to speed up the calculation process.
It significantly improves the computing efficiency of sparse multi-scalar multiplication, especially when processing large-scale data, has excellent performance, and can efficiently expand to multi-node multi-GPU environments to meet the efficient computing needs of large-scale zero-knowledge proof systems.
Smart Images

Figure CN119540025A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of parallel computing, and more specifically, relates to a method for accelerating sparse multi-scalar multiplication by using an image processor. Background Art
[0002] Multiscalar multiplication (MSM) is an important operation widely used in cryptography and blockchain systems, especially in zero-knowledge proof (ZKP) based on elliptic curves. When processing multiple scalar products, MSM requires large-scale parallel computing to improve efficiency. In recent years, related research has focused on optimizing single GPU and multi-GPU systems to achieve efficient computing. The existing multiscalar multiplication scheme uses elliptic curve point addition and point doubling calculations based on the projective coordinate system at the bottom layer, and uses the windowed Pippenger algorithm to optimize the computational complexity. Several methods have achieved certain results in a single GPU environment or GPU cluster. The basic principle is to use parallel computing structures to allocate tasks, optimize the calculation process through CUDA kernels, effectively reduce calculation delays and resource consumption, and achieve fast processing for multiscalar multiplication with densely distributed scalar values.
[0003] Some existing GPU optimization solutions do take into account the sparse values of scalars. Some work uses sparse matrices to perform GPU parallel acceleration on MSM. Other work uses sparsity to adjust the computational load. For example, in the Pippenger algorithm, if the "scalar-point" pairs accessed by multiple GPU threads belong to the same bucket, concurrent reading and writing of a large number of threads will result in higher latency.
[0004] That is, the existing methods do not fully utilize the sparsity of the scalar value distribution in sparse scalar multiplication operations, and their efficiency still has great potential for improvement to meet the needs of practical applications. Summary of the invention
[0005] In view of the above defects or improvement needs of the prior art, the present invention provides a method for accelerating sparse multi-scalar multiplication using an image processor, wherein the method aims to solve the technical problem of low efficiency of multi-scalar multiplication caused by insufficient utilization of scalar sparsity in sparse multi-scalar multiplication in zero-knowledge proof systems.
[0006] To achieve the above object, according to one aspect of the present invention, a method for accelerating sparse multi-scalar multiplication using an image processor is provided, comprising:
[0007] S1: The central processing unit migrates the obtained sparse multi-scalar multiplication calculation instance to the video memory of the image processor, and sends a bucket distribution command to the image processor;
[0008] S2: When the image processor receives the bucket distribution instruction, it reads all scalars in the current window and distributes all scalars in the current window to multiple parallel thread blocks; in each thread block, it calculates the mask of each scalar allocated, uses the mask of each scalar to correct the bucket number and increment to be accessed, adds the increment to the corresponding bucket tail pointer, stores the point subscript at the pointer and puts the point subscript into 2w pre-established linked lists; then each linked list merges the point subscripts put in by each thread block in the table; wherein w is the number of bits of the current window;
[0009] S3: the image processor creates a concurrent thread to sum the points in each bucket to obtain a first summation result of each bucket in the current window, and saves the summation result in the video memory;
[0010] S4: the image processor creates a concurrent thread to respectively calculate the scalar product of the first summation result of each bucket in the current window, sums each scalar product to obtain a second summation result in the current window, and then sends the second summation result in the current window back to the central processor;
[0011] S5: The central processing unit shifts the cumulative sum results corresponding to all windows before the current window left by w positions and adds the second sum result in the current window sent back by the image processor to obtain the current cumulative sum result; if the current window is the last window, the current cumulative sum result is used as the calculation result of the calculation instance and output; otherwise, a bucket distribution command is sent to the image processor and returns to S2.
[0012] In one embodiment, the mask of each scalar allocated in each thread block is calculated in S2, including: for each scalar allocated to each thread block, the w-bit complement of the scalar is bitwise ORed with the scalar, the bitwise OR result is right shifted by w-1 bits, and the w-bit complement of the shifted result is taken as the mask corresponding to the scalar.
[0013] In one of the embodiments, the point subscripts into which each thread block in each of the linked list merge tables in S2 is placed include: thread No. 0 of each thread block in the jth current window is responsible for applying for atomic reading and writing of the tail pointer of the jth linked list in the global memory, thereby obtaining the write address of the linked list and adding the number of elements in bucket j in its own thread block as an increment to the linked list tail pointer of bucket j, so as to correctly prepare the write address for other thread blocks, and then the threads in the thread block concurrently fill the contents of bucket j in the block into the global linked list.
[0014] In one embodiment, the S3 includes:
[0015] S31: The decision problem of thread block allocation is modeled as an optimization problem, the goal of which is to minimize the maximum number of different bucket categories processed in the same thread block to determine the target thread allocation strategy;
[0016] S32: the image processor creates and allocates concurrent threads according to the target thread allocation strategy, so that each thread sums the points in its own bucket to obtain a first summation result of each bucket in the current window, and stores it in the video memory.
[0017] In one embodiment, the S31 includes:
[0018] S311: Create queues q1 and q2 for storing the decisions to be retrieved and the candidate decisions that have been evaluated in the search space, and add (1, 1) to the queue q1;
[0019] S312: When the queue q1 is not empty, loop the following steps: take out the first element of the queue q1, assuming it is a tuple ((r1,…,r l ),s),(r1,…,r l ) is a permutation of 1, ..., l, indicating the decision plan obtained by assigning the remaining points in the buckets to the thread blocks in the order of buckets r1, ..., bucket rl. s indicates the maximum number of concurrently processed buckets of this decision plan, which is used to measure the cost of this decision plan. If l = 2 w -1, l represents the length of the first component of the above two-tuple; add it to queue q2; otherwise, insert l+1 into (r1,…,r l ) at any position to obtain a tuple of length l+1 to form a set L; then initialize s m =∞,s m Represents the cost of the decision solution currently being considered; for each r′∈L: calculate the maximum number of different bucket categories s′, r′ processed in the same thread block under the corresponding thread block allocation strategy; then update s m =min{s m ,s′}, for each r′∈L, if the corresponding s′∈[s m ,s m +1], then add (r′,s′) to queue q2;
[0020] S313: Take out the element (r, s) with the smallest second component in the queue q2, and then return r as the target thread allocation strategy.
[0021] In one embodiment, the step S32 includes: the image processor skips the first linked list and uses 2 w-1 linked list As input, the process of summing the corresponding points in each linked list is as follows:
[0022] Assume that the n points in each linked list are assigned to N T threads, prepare at most 2 for each thread w -1 pointer and the corresponding length; N T Threads go through log2 N T The sum of different parts of the same bucket is obtained in rounds of interaction; for each bucket, each thread that processes the sum in the bucket is selected to write the result to a specific area on the video memory.
[0023] In one embodiment, the S4 includes:
[0024] The image processor uses the sum of the points in each bucket For input,
[0025] Image processor creates w×2 w threads, of which the jw+kth thread is responsible for calculating j k (2 k B j );use Calculates the sum of all contents within this thread.
[0026] According to another aspect of the present invention, there is provided an apparatus for accelerating sparse multi-scalar multiplication using an image processor, comprising: a central processing unit and an image processor in communication connection;
[0027] The central processing unit is used to migrate the obtained sparse multi-scalar multiplication calculation instance to the video memory of the image processor and send a bucket distribution command to the image processor;
[0028] The image processor is used to read all scalars in the current window when receiving the bucket distribution instruction, and divide all scalars in the current window into multiple parallel thread blocks; calculate the mask of each scalar allocated in each thread block, use the mask of each scalar to correct the bucket number and increment to be accessed, add the increment at the corresponding bucket tail pointer, store the point subscript at the pointer and put the point subscript into 2w pre-established linked lists; then each linked list merges the point subscripts put in by each thread block in the table; wherein w is the number of bits of the current window; create a concurrent thread to sum the points in each bucket to obtain the first summation result of each bucket in the current window, and save it in the video memory; create a concurrent thread to calculate the scalar product of the first summation result of each bucket in the current window, sum each scalar product to obtain the second summation result in the current window, and then send the second summation result in the current window back to the central processor;
[0029] The central processing unit is further used to shift the cumulative summation results corresponding to all windows before the current window left by w positions and add the second summation result in the current window sent back by the image processor to obtain the current cumulative summation result; if the current window is the last window, the current cumulative summation result is used as the calculation result of the calculation instance and output; otherwise, a bucket distribution command is sent to the image processor to execute the calculation task of the next window.
[0030] In general, the above technical solutions conceived by the present invention can achieve the following beneficial effects compared with the prior art:
[0031] (1) The present invention provides a method for accelerating sparse multi-scalar multiplication using an image processor, wherein the CPU manages the scalar vectors involved in the operation and the point vectors in the group, and applies for sufficient memory on the GPU to store these contents; the CPU and GPU work asynchronously, and the GPU performs bucket distribution, bucket summation, and bucket merging calculations to obtain the calculation results within a window. By making full use of the sparsity of scalars, it performs well, especially when processing large-scale data, and the performance is significantly improved; secondly, the design of the multi-GPU parallel computing architecture fully utilizes the advantages of GPU hardware resources, and the load balancing is finely regulated by the present invention, reducing the resource overhead of the system; finally, the parallel processing technology solution adopted enables the MSM operation to be efficiently expanded to a multi-node multi-GPU environment, adapting to the efficient computing requirements of large-scale zero-knowledge proof systems. BRIEF DESCRIPTION OF THE DRAWINGS
[0032] Figure 1 is a flow chart of a method for accelerating sparse multi-scalar multiplication using an image processor provided in Embodiment 1 of the present invention;
[0033] Figure 2 It is a schematic diagram of data trends of a method for accelerating sparse multi-scalar multiplication using an image processor provided in Embodiment 1 of the present invention;
[0034] Figure 3 is a schematic diagram of executing a method for accelerating sparse multi-scalar multiplication using an image processor provided in Embodiment 1 of the present invention;
[0035] Figure 4 is a schematic diagram of a flow chart of calculating each scalar mask provided by Embodiment 1 of the present invention;
[0036] Figure 5 It is a schematic diagram of link list merging using a binary tree provided in Example 1 of the present invention. DETAILED DESCRIPTION
[0037] In order to make the purpose, technical solutions and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention. In addition, the technical features involved in the various embodiments of the present invention described below can be combined with each other as long as they do not conflict with each other.
[0038] Example 1
[0039] This embodiment provides a method for accelerating sparse multi-scalar multiplication using a GPU, such as Figure 1 As shown, steps S1-S4 are included.
[0040] S1: The CPU migrates the obtained sparse multi-scalar multiplication computing instance to the GPU memory and sends a bucket distribution command to the GPU.
[0041] S2: When the GPU receives the bucket distribution instruction, it reads all scalars in the current window and distributes them to multiple parallel thread blocks. In each thread block, it calculates the mask of each scalar allocated, uses the mask of each scalar to correct the bucket number and increment to be accessed, adds the increment to the corresponding bucket tail pointer, stores the point subscript at the pointer and puts the point subscript into the pre-established 2 w linked lists; then each linked list merges the point subscripts of each thread block in the list; where w is the number of bits in the current window.
[0042] S3: The GPU creates a concurrent thread to sum the points in each bucket to obtain the first summation result of each bucket in the current window and save it in the video memory.
[0043] S4: The GPU creates a concurrent thread to calculate the scalar product of the first summation result of each bucket in the current window, sums each scalar product to obtain the second summation result in the current window, and then sends the second summation result in the current window back to the CPU.
[0044] S5: The CPU shifts the cumulative sum results corresponding to all windows before the current window left by w positions and adds the second sum result in the current window sent back by the GPU to obtain the current cumulative sum result; if the current window is the last window, the current cumulative sum result is used as the calculation result of the calculation instance and output; otherwise, a bucket distribution command is sent to the GPU and returns to S2.
[0045] For example, for a given instance of MSM assumed The elements in are represented by W-bit binary numbers, and the window size of the Pippenger algorithm is w. Then the number of iterations of the Pippenger algorithm is set to W / w, and each iteration processes the calculation task within a window, such as Figure 2 As shown, the details are as follows:
[0046] S1: The CPU obtains the instance of the MSM and migrates it to the GPU memory, and the CPU sends a command to the GPU;
[0047] S2: When receiving the command to process the bucket distribution service, the GPU reads the scalar in the current window and distributes the point index to different bucket spaces previously applied on the GPU according to the different scalars;
[0048] S3: After the bucket distribution is completed, the GPU creates a concurrent thread to sum the points in each bucket to complete the bucket sum calculation, and the result is saved in the GPU memory;
[0049] S4: GPU creates concurrent threads to calculate the scalar product of the sum of each bucket and then sum them up, and sends the results back to the CPU;
[0050] S5: After the CPU reads the result of this round of multi-scalar multiplication, it shifts the current accumulated result left by w bits and adds it to the data sent back by the GPU, then returns to step S2 until the maximum number of iterations is reached.
[0051] The above-mentioned S2 bucket distribution parallel computing method, S3 thread allocation solution and S4 concurrent computing method are all links with freedom. The main technical solution proposed is to select excellent parallel strategies in these aspects and perform targeted optimization:
[0052] (1) Use the memory load balancing method to reduce memory access conflicts during bucket scatter: During bucket scatter, a large number of GPU threads may concurrently access the buckets corresponding to 0 / 1. The delay caused by concurrent access to 0 is unnecessary. However, under the SIMD architecture, if the thread that reads scalar 0 does not want to maintain bucket 0, it must use conditional branches, and the overhead of conditional branches on GPUs is higher. An innovative method is proposed to amortize the concurrent access to bucket 0 while maintaining the SIMD mode.
[0053] Specifically, in the bucket distribution phase of sparseMSM, the key to optimization is to reduce memory access conflicts caused by sparse scalars. In the traditional bucket distribution process, GPU threads may concurrently access bucket 0, which will cause significant memory access delays. To this end, an algorithm called sparseScatter is proposed, which distributes threads with scalar 0 to other buckets in SIMD mode, thereby amortizing the concurrent access pressure of bucket 0. Specifically, conditional branches are used to avoid maintenance of bucket 0. Instead, threads with scalar 0 are assigned to other randomly selected buckets through bitwise operations, reducing unnecessary access to bucket 0 and optimizing memory access performance.
[0054] In addition, when performing bucket distribution, GPU thread block shared memory is used to store the distribution results within the block, avoiding concurrent atomic read and write requests for tail pointers between a large number of threads. Bucket distribution is first performed within the thread block, and then the results of multiple thread blocks are merged. In this way, the parallel computing capabilities of the GPU can be fully utilized, and the memory access bottleneck caused by the sparse scalar characteristics can be effectively reduced, thereby improving the efficiency of the entire multi-scalar multiplication calculation process.
[0055] (2) Adjust the load balance of bucket sum and bucket reduce stages based on the data distribution information where the majority of scalars are 0 / 1: In the bucket sum stage, it is necessary to carefully assign computing tasks to each thread according to the size of each bucket. On the one hand, the uneven distribution of bucket sizes requires that different numbers of threads be assigned to the summation within each bucket. On the other hand, the size of the thread block is fixed and only the threads within the block have quickly accessible shared memory and synchronization mechanisms. The specific assignment method is carefully designed based on the input distribution.
[0056] Specifically, in the bucket summation phase, in order to achieve load balancing, an optimization algorithm is used to model the thread block allocation decision as an optimization problem. First, the elements in each bucket are divided into multiple thread blocks according to their relative sizes, and the threads in the same thread block are guaranteed to process the summation tasks of the same bucket. This allocation method fully utilizes the high-speed characteristics of the shared memory within the block and improves the efficiency of data exchange. For the remaining elements in each bucket, the thread block allocation is optimized through a search method with pruning to ensure that the number of different bucket categories processed in each thread block is minimized, thereby further optimizing the computational efficiency.
[0057] In order to further improve the parallel efficiency, a load balancing strategy based on the size of each bucket and the number of elements is adopted. Specifically, for each bucket, it is assigned to an appropriate number of thread blocks, each thread block is responsible for processing the sum of a part of the elements in the bucket, ensuring that the load is evenly distributed among the thread blocks. This method not only effectively reduces the computing bottleneck caused by unbalanced load, but also minimizes the conflict when processing multiple buckets in each thread block, thereby improving the overall performance.
[0058] (3) We further utilize the distribution of input data under window partitioning and adjust the thread block organization scheme in window merging (window reduce): 90% of the scalars in sparseMSM are 0 / 1, while in fact, except for the lowest window, 90% of the coefficients in each window are 0 under window partitioning. In this scenario, the remaining 10% of the multi-scalar multiplication is closer to the multi-scalar multiplication under uniform coefficient distribution. Combined with the optimization scheme of denseMSM, the proposed sparseMSM can also adapt well to the distribution changes brought about by window partitioning.
[0059] Compared with the prior art, the GPU optimized sparseMSM algorithm provided by the present invention has a series of significant advantages. First, the present invention fully utilizes sparsity, especially when processing large-scale data, and significantly improves performance; second, the design of the multi-GPU parallel computing architecture fully utilizes the advantages of GPU hardware resources, and the load balancing is finely regulated by the algorithm, which reduces the resource overhead of the system; finally, the parallel processing technology solution adopted by the present invention enables the MSM operation to be efficiently expanded to a multi-node multi-GPU environment, adapting to the efficient computing requirements of large-scale zero-knowledge proof systems.
[0060] In summary, the overall operation mode of the acceleration method provided by this solution is: Figure 3 Given. The scalar vectors s1,…,s involved in the operation are managed by the CPU. n and the point vectors P1,…P in the group n And apply for sufficient memory on the GPU to store these contents. The CPU and GPU can work asynchronously. The GPU performs bucket distribution, bucket summation, and bucket merging calculations to obtain the calculation results within a window and then migrate them back to the CPU. After receiving the calculation results, the CPU first stores the currently stored calculation results P as shown in Example 3. acc Perform w cumulative point multiplication operations, and then add the results of the operations. While the operations are being performed, the GPU can start calculating the next window.
[0061] In one embodiment, in S2, the mask of each scalar allocated in each thread block is calculated, including: for each scalar allocated to each thread block, the w-bit complement of the scalar is bitwise ORed with the scalar, the bitwise OR result is right-shifted by w-1 bits, and the w-bit complement of the shifted result is taken as the mask corresponding to the scalar. The details of the bucket distribution stage are as follows:
[0062] The basic idea of distribution is that the GPU distributes n scalars to N T threads, maintaining 2 w The tail pointer and contents of the linked list. For example, let n = 2 20 , GPU creates 2 16 There are concurrent threads, each thread traverses 16 scalars. When encountering scalar s, it applies for atomic read and write operations on the tail pointer of bucket s. After the application is successful, the tail pointer can be increased by one unit, and then the number of the current scalar is filled in the original position.
[0063] Next, an important load balancing design is introduced to fully utilize the sparsity of the input scalar and handle the concurrent memory access conflicts caused by it. 90% of them are 0 / 1, especially when the current processing is not the lowest window (almost 90% of the scalars are 0). Even if the shared memory in the block is first distributed in the bucket, there will still be a large number of threads concurrently accessing the tail pointer corresponding to bucket 0. Since the maximum number of threads in a thread block of a single GPU cannot exceed 1024, in this case, an average of more than 900 threads will concurrently access the corresponding tail pointer of bucket 0, which will still bring a large memory access delay. To this end, each thread needs to calculate the mask mask based on the current scalar to not change the original operation mode under the SIMD architecture, but when the input scalar is 0, it will randomly select a bucket's tail pointer to apply for atomic read and write and perform a null operation, thereby balancing the large number of concurrent accesses to bucket 0. The specific steps are as follows:
[0064] The GPU uses the value of each scalar in the current window As input, the point subscripts are classified according to the corresponding scalars during the bucket distribution process, and the classification results are maintained using appropriate data structures. w The linked lists maintain the bucket distribution results, and the elements in the jth linked list constitute the set
[0065] A1: Set the GPU to use the value of each scalar in the current window As input, create 2 w A linked list is used to maintain the bucket distribution results; the elements in the jth linked list constitute the set
[0066] A2: The GPU first divides the scalar into each thread block and calculates the mask used to balance the load in each thread block. The specific calculation method is as follows: Figure 4 , first calculate the scalar The w-bit complement of After bitwise OR, shift right by w-1 bits, take the w-bit complement of the result to get the mask mask, and then use this mask to correct the bucket number accessed (s&mask)|(thread number&~mask) and increment (1&mask). Each thread block is based on the scalar in the current window. Calculate the bucket number, then add an increment to the corresponding bucket tail pointer and store the subscript at the pointer;
[0067] A3: Each thread block stores the point index it manages in parallel into the bucket memory within the block. The specific method is to apply for exclusive read and write of the bucket tail pointer and then write the point index at this location. In this way, each thread block will get 2 w A linked list that maintains the bucket distribution information of the scalars involved in this thread block
[0068] A4: Each thread block then needs to merge this information in parallel and store it in 2 w in a linked list.
[0069] This process takes 2 w -1 round of synchronization operation (bucket 0 is skipped). In the jth round of operation, thread 0 of each thread block is responsible for applying for atomic read and write for the tail pointer of bucket j in the global linked list, thereby obtaining the write address of the linked list and adding the number of elements in bucket j in its own thread block to the tail pointer of bucket j, so as to correctly prepare the write address for other thread blocks. Then the threads in the thread block concurrently fill the contents of bucket j in the block into the global linked list.
[0070] In one of the embodiments, the point subscripts into which each thread block in each linked list merge table in S2 is placed include: thread No. 0 of each thread block in the jth current window is responsible for applying for atomic reading and writing of the tail pointer of the jth linked list in the global memory, thereby obtaining the write address of the linked list and adding the number of elements in bucket j in its own thread block as an increment to the linked list tail pointer of bucket j, so as to correctly prepare the write address for other thread blocks, and then the threads in the thread block concurrently fill the contents of bucket j in the block into the global linked list.
[0071] In one of the embodiments, S3 includes: S31: modeling the decision problem of thread block allocation as an optimization problem, with the goal of minimizing the maximum number of different bucket categories processed in the same thread block to determine the target thread allocation strategy; S32: the GPU creates and allocates concurrent threads according to the target thread allocation strategy so that each thread sums the points in its own bucket to obtain the first summation result of each bucket in the current window, and saves it in the video memory.
[0072] Regarding the bucket summation phase, the details are as follows: The load of the algorithm depends on the maximum number of bucket categories that each thread needs to process. The decision problem of thread block allocation is modeled as an optimization problem, the goal is to minimize the maximum number of different bucket categories processed in the same thread block. Assume that the linked list The lengths are A thread block of size B can process N P =Bn / N T The sum of the points, so first we can j Middle j -(l j mod N P ) points are assigned to several thread blocks for processing. These thread blocks all calculate the sum of points in the same bucket, so the high-speed characteristics of shared memory can be fully utilized.
[0073] In one embodiment, S31 includes: S311: creating queues q1 and q2 for storing the candidate decisions to be retrieved and the candidate decisions that have been evaluated in the search space, and adding (1, 1) to the queue q1; S312: looping the following steps when the queue q1 is not empty: taking out the first element of the queue q1, assuming that it is a two-tuple ((r1,…,r l ),s),(r1,…,r l ) is a permutation of 1, ..., l, indicating the decision plan obtained by assigning the remaining points in the buckets to the thread blocks in the order of buckets r1, ..., bucket rl. s indicates the maximum number of concurrently processed buckets of this decision plan, which is used to measure the cost of this decision plan. If l = 2 w -1, l represents the length of the first component of the above two-tuple; add it to queue q2; otherwise, insert l+1 into (r1,…,r l ) at any position to obtain a tuple of length l+1 to form a set L; then initialize s m =∞,s m represents the cost of the decision solution currently being considered; for each r′∈L: calculate the maximum number of different bucket categories s′, r′ processed in the same thread block under the corresponding thread block allocation strategy; then update s m =min{s m ,s′}, for each r′∈L, if the corresponding s′∈[sm ,s m +1], then add (r′, s′) to queue q2; S313: take out the element (r, s) with the second smallest component in queue q2, then return r and use it as the target thread allocation strategy.
[0074] For the remaining points in each linked list, a search method with pruning is used to find the optimal thread block allocation scheme: let the number of points remaining in each bucket be By arranging The algorithm will output {1,…,2 w -1}, indicating an allocation strategy that allocates points to thread blocks in sequence according to the order of the arrangement.
[0075] (311) Create queues q1 and q2, and add (1, 1) to queue q1;
[0076] (312) When the queue q1 is not empty, loop the following steps:
[0077] (312.1) Take out the first element of q1, assuming it is a tuple ((r1,…,r l ),s);
[0078] (312.2) If l = 2 w -1, add it to queue q2;
[0079] (312.3) Otherwise, l+1 can be inserted into (r1,…,r l ), these tuples of length l+1 constitute the set L;
[0080] (312.4) Set m =∞;
[0081] (312.5) For each r′∈L:
[0082] (312.5.1) Calculate the maximum number s′ of different bucket categories processed in the same thread block under the corresponding thread block allocation strategy;
[0083] (312.5.2) Set m =min{s m ,s′};
[0084] (312.6) For each r′∈L, if the corresponding s′∈[s m ,s m +1], (r′,s′) is added to queue q2;
[0085] (313) Take out the element (r, s) with the second smallest component in queue q2, and then return r.
[0086] The main framework of the optimization problem is the breadth-first search algorithm, and optimality pruning is performed. In the permutation obtained by each node expansion, the number of different bucket categories processed in each thread block in the corresponding thread block allocation strategy changes by at most 1, and the maximum number of categories also changes by at most 1. Therefore, only the optimal solution and the suboptimal solution need to be retained for node expansion. In actual operation, in order to balance the additional overhead brought by calculating the optimal allocation strategy and the computational overhead of the main algorithm, only a part of the points with the same maximum number of categories can be retained in (2.2.6).
[0087] Furthermore, the GPU is used to create concurrent threads using the obtained allocation strategy r. In each thread, the points in each bucket are summed. That is, after the algorithm is run, the thread allocation scheme is determined, and then the following steps are run:
[0088] B1: GPU with 2 w -1 linked list (bucket distribution gets 2 w Linked list, skip 0) As input, we need to complete the sum of the corresponding points in each linked list, that is, calculate for the jth linked list
[0089] B2: Assign n points to N T threads, the algorithm will prepare at most 2 w -1 pointer and the corresponding length, used to represent the points in each bucket that it needs to process. Each thread calculates the sum of these points in each bucket in parallel;
[0090] B3:N T Threads pass log2N T The sum of different parts in the same bucket is obtained by round interaction. Specifically, in the jth round of interaction, the thread numbered t needs to interact with the thread numbered t XOR (1<<j). This process is actually a binary tree merge of the data on the threads, such as Figure 5 shown.
[0091] B4: Next, for each bucket, select any thread that processes the sum in the bucket and let it write the result to a specific area on the video memory.
[0092] In one embodiment, S32 includes: the GPU skips the first linked list and uses 2 w -1 linked list As input, the process of summing the corresponding points in each linked list is as follows: Assume that n points in each linked list are assigned to N T threads, prepare at most 2 w -1 pointer and the corresponding length; N TThreads pass log2N T The sum of different parts of the same bucket is obtained in rounds of interaction; for each bucket, each thread that processes the sum in the bucket is selected to write the result to a specific area on the video memory.
[0093] In one embodiment, S4 includes: GPU takes the sum of the points in each bucket As input, the GPU creates w×2 w threads, of which the jw+kth thread is responsible for calculating j k (2 k B j );use Calculates the sum of all contents within this thread.
[0094] Specifically, in the bucket merging stage, the GPU uses the sum of the points in each bucket As input, it will be calculated in parallel To do this, the GPU creates a w×2 w threads, of which the jw+kth thread is responsible for calculating j k (2 k B j ), and then use the previous binary tree merging method to calculate the sum of these contents. In order to optimize the computational overhead of repeated point doubling, the point doubling calculation path on the elliptic curve group represented by Jacobian coordinates is optimized using a common method, that is, the Y coordinate is multiplied in advance, and an additional right shift of 1 bit is performed when returning the result. Iterate different windows on the GPU repeatedly to run bucket distribution-bucket summation-bucket merging, and then send the results back to the CPU, which implements window merging in the manner described previously. After W / W rounds of iterations, the final result can be obtained on the CPU.
[0095] Example 2
[0096] This embodiment provides a device for accelerating sparse multi-scalar multiplication using a GPU, including: a CPU and a GPU that are communicatively connected;
[0097] The CPU is used to migrate the obtained sparse multi-scalar multiplication computing instance to the GPU memory and send a bucket distribution command to the GPU;
[0098] The GPU is used to read all scalars in the current window when receiving the bucket distribution instruction, and divide all scalars in the current window into multiple parallel thread blocks; calculate the mask of each scalar allocated in each thread block, use the mask of each scalar to correct the accessed bucket number and increment, add the increment to the corresponding bucket tail pointer, store the point subscript at the pointer and put the point subscript into the pre-established 2 wlinked lists; each linked list then merges the point subscripts of each thread block in the list; where w is the number of bits in the current window; a concurrent thread is created to sum the points in each bucket to obtain the first sum result of each bucket in the current window, and save it in the video memory; a concurrent thread is created to calculate the scalar product of the first sum result of each bucket in the current window, sum each scalar product to obtain the second sum result in the current window, and then send the second sum result in the current window back to the CPU;
[0099] The CPU is also used to shift the cumulative sum results corresponding to all windows before the current window left by w positions and add the second sum result in the current window sent back by the GPU to obtain the current cumulative sum result; if the current window is the last window, the current cumulative sum result is used as the calculation result of the calculation instance and output; otherwise, a bucket distribution command is sent to the GPU to let the GPU execute the calculation task of the next window.
[0100] It will be easily understood by those skilled in the art that the above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present invention should be included in the protection scope of the present invention.
Claims
1. A method for accelerating sparse multi-scalar multiplication using an image processor, characterized in that: include: S1: The central processing unit migrates the obtained sparse multi-scalar multiplication calculation instance to the video memory of the image processor, and sends a bucket distribution command to the image processor; S2: When the image processor receives the bucket distribution instruction, it reads all scalars in the current window and distributes all scalars in the current window to multiple parallel thread blocks; in each thread block, it calculates the mask of each scalar allocated, uses the mask of each scalar to correct the bucket number and increment to be accessed, adds the increment to the corresponding bucket tail pointer, stores the point subscript at the pointer and puts the point subscript into 2w pre-established linked lists; then each linked list merges the point subscripts put in by each thread block in the table; wherein w is the number of bits of the current window; S3: the image processor creates a concurrent thread to sum the points in each bucket to obtain a first summation result of each bucket in the current window, and saves the summation result in the video memory; S4: the image processor creates a concurrent thread to respectively calculate the scalar product of the first summation result of each bucket in the current window, sums each scalar product to obtain a second summation result in the current window, and then sends the second summation result in the current window back to the central processor; S5: The central processing unit shifts the cumulative sum results corresponding to all windows before the current window left by w positions and adds the second sum result in the current window sent back by the image processor to obtain the current cumulative sum result; if the current window is the last window, the current cumulative sum result is used as the calculation result of the calculation instance and output; otherwise, a bucket distribution command is sent to the image processor and returns to S2.
2. The method for accelerating sparse multi-scalar multiplication using an image processor according to claim 1, wherein: The S2 calculates the mask of each scalar allocated in each thread block, including: For each scalar allocated to each thread block, the w-bit complement of the scalar is bitwise ORed with the scalar, the bitwise OR result is right shifted by w-1 bits, and the w-bit complement of the shifted result is taken as the mask corresponding to the scalar.
3. The method for accelerating sparse multi-scalar multiplication using an image processor according to claim 1, wherein: The point subscripts at which each thread block in each of the linked list merge tables in S2 is placed include: Thread No. 0 of each thread block in the jth current window is responsible for applying for atomic reading and writing of the tail pointer of the jth linked list in the global memory, thereby obtaining the write address of the linked list and adding the number of elements in bucket j in its own thread block as an increment to the tail pointer of bucket j of the linked list, so as to correctly prepare the write address for other thread blocks, and then the threads in the thread block concurrently fill the contents of bucket j in the block into the global linked list.
4. The method for accelerating sparse multi-scalar multiplication using an image processor according to claim 1, wherein: The S3 includes: S31: The decision problem of thread block allocation is modeled as an optimization problem, the goal of which is to minimize the maximum number of different bucket categories processed in the same thread block to determine the target thread allocation strategy; S32: the image processor creates and allocates concurrent threads according to the target thread allocation strategy, so that each thread sums the points in its own bucket to obtain a first summation result of each bucket in the current window, and stores it in the video memory.
5. The method for accelerating sparse multi-scalar multiplication using an image processor as claimed in claim 4, characterized in that: The S31 includes: S311: Create queues q1 and q2 for storing the decisions to be retrieved and the candidate decisions that have been evaluated in the search space, and add (1, 1) to the queue q1; S312: When queue q1 is not empty, loop the following steps: take out the first element of queue q1, assuming it is a tuple ((r1,…,r l ),s),(r1,…,r l ) is a permutation of 1, ..., l, indicating the decision plan obtained by assigning the remaining points in the buckets to the thread blocks in the order of buckets r1, ..., bucket rl. s indicates the maximum number of concurrently processed buckets of the decision plan, which is used to measure the cost of this decision plan. If l = 2 w -1, l represents the length of the first component of the above two-tuple; add it to queue q2; otherwise, insert l+1 into (r1,…,r l ) at any position to obtain a tuple of length l+1 to form a set L; then initialize s m =∞,s m represents the cost of the decision solution currently being considered; for each r′∈L: calculate the maximum number of different bucket categories s′, r′ processed in the same thread block under the corresponding thread block allocation strategy; then update s m =min{s m ,s′}, for each r′∈L, if the corresponding s′∈[s m ,s m +1], then add (r′,s′) to queue q2; S313: Take out the element (r, s) with the smallest second component in the queue q2, and then return r as the target thread allocation strategy.
6. The method for accelerating sparse multi-scalar multiplication using an image processor as claimed in claim 4, characterized in that: The S32 includes: The image processor skips the first linked list and takes 2 w -1 linked list As input, the process of summing the corresponding points in each linked list is as follows: Assume that the n points in each linked list are assigned to N T threads, prepare at most 2 for each thread w -1 pointer and the corresponding length; N T Threads pass log2N T The sum of different parts of the same bucket is obtained in rounds of interaction; for each bucket, each thread that processes the sum in the bucket is selected to write the result to a specific area on the video memory.
7. The method for accelerating sparse multi-scalar multiplication using an image processor according to claim 1, wherein: The S4 includes: The image processor uses the sum of the points in each bucket For input, Image processor creates w×2 w threads, of which the jw+kth thread is responsible for calculating j k (2 k B j );use Calculates the sum of all contents within this thread.
8. A device for accelerating sparse multi-scalar multiplication using an image processor, characterized in that: include: A central processing unit and an image processing unit that are communicatively connected; The central processing unit is used to migrate the obtained sparse multi-scalar multiplication calculation instance to the video memory of the image processor and send a bucket distribution command to the image processor; The image processor is used to read all scalars in the current window when receiving the bucket distribution instruction, and divide all scalars in the current window into multiple parallel thread blocks; calculate the mask of each scalar allocated in each thread block, use the mask of each scalar to correct the bucket number and increment to be accessed, add the increment at the corresponding bucket tail pointer, store the point subscript at the pointer and put the point subscript into 2w pre-established linked lists; then each linked list merges the point subscripts put in by each thread block in the table; wherein w is the number of bits of the current window; create a concurrent thread to sum the points in each bucket to obtain the first summation result of each bucket in the current window, and save it in the video memory; create a concurrent thread to calculate the scalar product of the first summation result of each bucket in the current window, sum each scalar product to obtain the second summation result in the current window, and then send the second summation result in the current window back to the central processor; The central processing unit is further used to shift the cumulative summation results corresponding to all windows before the current window left by w positions and add the second summation result in the current window sent back by the image processor to obtain the current cumulative summation result; if the current window is the last window, the current cumulative summation result is used as the calculation result of the calculation instance and output; otherwise, a bucket distribution command is sent to the image processor to execute the calculation task of the next window.
Citation Information
Patent Citations
System and method for real-time performance and load statistics of a communications system
CN102415130A
multi-core parallel signal processing system and method based on an SRIO bus
CN109656861A
Data processing apparatus and data processing method
CN116170159A
Zero-knowledge proof acceleration method and system based on GPU cluster
CN118157872A
Method for generic-point parallel elliptic curve scalar multiplication
US20140105381A1
Cited By
Vertical direction pixel parallel depth operation implementation method and device, medium, equipment and product
CN120318057A
Method, device, medium, equipment and product for implementing vertical pixel parallel depth calculation
CN120318057B