A method for accelerating sparse multi-scalar multiplication using image processor

By optimizing the parallel computing of sparse multi-scalar multiplication on the image processor, the problem of insufficient sparsity utilization is solved, and efficient multi-scalar multiplication computing is achieved to meet the needs of large-scale zero-knowledge proof systems.

CN119540025BActive Publication Date: 2025-09-23HUAZHONG UNIV OF SCI & TECH
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411653089.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-11-19
Publication Date
2025-09-23
Estimated Expiration
2044-11-19

AI Technical Summary

Technical Problem

Existing technologies fail to fully utilize the scalar sparsity characteristics of sparse multi-scalar multiplication, resulting in low efficiency of multi-scalar multiplication and difficulty in meeting the computing requirements of large-scale zero-knowledge proof systems.

Method used

The calculation of sparse multi-scalar multiplication is migrated to the video memory of the graphics processor. Through bucket distribution, concurrent thread calculation and result merging, the parallel processing of scalar multiplication is optimized. The hardware resources and parallel computing capabilities of the graphics processor are utilized to achieve load balancing and efficient computing.

Benefits of technology

The computational performance of sparse multi-scalar multiplication has been significantly improved, especially when processing large-scale data. It adapts to the efficient computing needs of multi-node and multi-GPU environments and reduces system resource overhead.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119540025B_ABST
    Figure CN119540025B_ABST
Patent Text Reader

Abstract

The present invention discloses a method for accelerating sparse multi-scalar multiplication using an image processor, belonging to the field of parallel computing technology. The method involves a CPU managing the scalar vectors involved in the calculation and the point vectors in the group, and applying for sufficient memory on the GPU to store these contents. The CPU and GPU operate asynchronously, with the GPU performing bucket distribution, bucket summation, and bucket merging calculations, ultimately obtaining the calculation results within a window. First, the present invention fully utilizes the sparsity of scalars, particularly when processing large-scale data, resulting in significant performance improvements. Second, the design of a multi-GPU parallel computing architecture fully utilizes the advantages of GPU hardware resources, and load balancing is finely controlled by the present invention, reducing system resource overhead. Finally, the adopted parallel processing technology solution enables the efficient expansion of MSM operations to multi-node and multi-GPU environments, adapting to the efficient computing requirements of large-scale zero-knowledge proof systems.
Need to check novelty before this filing date? Find Prior Art

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 using an image processor. Background Art

[0002] Multiscalar multiplication (MSM) is a crucial operation widely used in cryptography and blockchain systems, playing a particularly crucial role in elliptic curve-based zero-knowledge proofs (ZKPs). MSM requires large-scale parallel computing to improve efficiency when processing multiple scalar products. In recent years, research has focused on optimizing single-GPU and multi-GPU systems for efficient computation. Existing multiscalar multiplication schemes employ elliptic curve point addition and point multiplication based on projective coordinates, using a windowed Pippenger algorithm to optimize computational complexity. Several methods have demonstrated promising results in single-GPU environments or GPU clusters. Their fundamental principle is to leverage parallel computing structures to distribute tasks and optimize computational processes using CUDA kernels, effectively reducing computational latency and resource consumption. They achieve fast processing for multiscalar multiplications 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 of 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, the 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 response to the above-mentioned defects or improvement needs of the prior art, the present invention provides a method for accelerating sparse multi-scalar multiplication using an image processor, the purpose of which is to solve the technical problem of low efficiency of multi-scalar multiplication caused by insufficient utilization of scalar sparsity in sparse multi-scalar multiplication applicable to 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 allocated scalar, uses the mask of each scalar to correct the accessed bucket number and increment, 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 in 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 the scalar products 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 summation results corresponding to all windows before the current window left by w bits and adds 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 and returns to S2.

[0012] In one embodiment, the calculation of the mask of each scalar allocated in each thread block in S2 includes: for each scalar allocated to each thread block, bitwise ORing the w-bit complement of the scalar with the scalar, right shifting the bitwise OR result by w-1 bits, and taking the w-bit complement of the shifted result as the mask corresponding to the scalar.

[0013] In one embodiment, the point subscripts of each thread block in each of the linked list merge tables in S2 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 thread block allocation decision problem is modeled as an optimization problem, where the goal is to minimize the maximum number of different bucket categories processed within 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 the summation result in a 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 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, which represents 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 represents 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 the 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-making scheme currently under consideration; 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 second smallest 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 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 log2 N T For each bucket, the threads that process the sum of the bucket are selected and asked to write the results to a specific area on the video memory.

[0023] In one embodiment, the S4 includes:

[0024] The image processor takes the sum of the points in each bucket For input,

[0025] Image processor creates w×2 w threads, where 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 configured 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 configured to read all scalars in the current window upon receiving the bucket distribution instruction, and distribute all scalars in the current window to multiple parallel thread blocks; calculate the mask of each allocated scalar in each thread block, use the mask of each scalar to correct the bucket number and increment to be accessed, add the increment to the corresponding bucket tail pointer, store the point subscript at the pointer and put the point subscript into 2w pre-established linked lists; then merge the point subscripts put in by each thread block in each linked list; wherein w is the number of bits in the current window; create a concurrent thread to sum the points in each bucket to obtain a first summation result of each bucket in the current window, and save it in the video memory; create a concurrent thread to respectively calculate the scalar product of the first summation result of each bucket in the current window, sum each scalar product to obtain a second summation result in the current window, and then send the second summation result in the current window back to the central processing unit;

[0029] The central processing unit is further configured to shift the cumulative summation results corresponding to all windows before the current window left by w bits and then add the result to the second summation result in the current window sent back by the image processor to obtain a 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 enable 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. 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 fully utilizing the sparsity of scalars, the method performs superiorly, especially when processing large-scale data, with significant performance improvements. Secondly, the design of the multi-GPU parallel computing architecture fully utilizes the advantages of GPU hardware resources, and the load balancing is finely controlled by the present invention, reducing the system's resource overhead. 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 This is a flow chart of a method for accelerating sparse multi-scalar multiplication using an image processor provided in Example 1 of the present invention;

[0033] Figure 2 This is a schematic diagram of data flow in a method for accelerating sparse multi-scalar multiplication using an image processor provided in Example 1 of the present invention;

[0034] Figure 3 1 is a schematic diagram illustrating an execution method for accelerating sparse multi-scalar multiplication using an image processor provided in Example 1 of the present invention;

[0035] Figure 4 1 is a schematic diagram of a process for calculating each scalar mask provided by Example 1 of the present invention;

[0036] Figure 5 This 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 objectives, technical solutions and advantages of the present invention more clearly understood, the present invention is further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely for the purpose of explaining 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 may 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, it includes steps S1-S4.

[0040] S1: The CPU migrates the obtained sparse multi-scalar multiplication calculation 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 divides all scalars in the current window into 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 table; 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 them to 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. 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 requested 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: The GPU creates concurrent threads to calculate the scalar product of the sum of each bucket and then sums them, sending the results back to the CPU;

[0050] S5: After reading the result of this round of multi-scalar multiplication, the CPU 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 aforementioned S2 bucket distribution parallel computing method, S3 thread allocation scheme, and S4 concurrent computing method all have degrees of freedom. The main technical solution proposed is to select excellent parallel strategies in these aspects and perform targeted optimization:

[0052] (1) Using a memory load-sharing method to reduce memory access conflicts during bucket scatter: During bucket scatter, a large number of GPU threads may concurrently access buckets corresponding to 0 and 1. The delay caused by concurrent access to 0 is unnecessary. However, in the SIMD architecture, if a thread reading scalar 0 wishes to avoid maintaining bucket 0, it must use conditional branches, which are more expensive on GPUs. We propose an innovative method to distribute concurrent access to bucket 0 while maintaining the SIMD mode.

[0053] Specifically, in the bucket distribution phase of sparseMSM, the key to optimization lies in reducing 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 latency. To this end, an algorithm called sparseScatter is proposed, which distributes threads with scalar 0 to other buckets in SIMD mode, thereby evenly distributing the concurrent access pressure on bucket 0. Specifically, conditional branches are used to avoid maintenance on bucket 0. Instead, threads with scalar 0 are assigned to other randomly selected buckets through bitwise operations, reducing unnecessary access to bucket 0 and thus optimizing memory access performance.

[0054] Furthermore, during bucket distribution, GPU thread block shared memory is used to store the distribution results within the block, avoiding concurrent atomic read and write requests to the tail pointer between a large number of threads. Bucket distribution is performed within the thread block, and then the results of multiple thread blocks are merged. This approach fully utilizes the parallel computing capabilities of the GPU and effectively reduces the memory access bottleneck caused by sparse scalar data, thereby improving the efficiency of the entire multi-scalar multiplication process.

[0055] (2) Based on the data distribution information of the vast majority of scalars being 0 / 1, the load balancing of the bucket sum and bucket reduce stages is adjusted: The bucket sum stage requires carefully assigning computational tasks to each thread based on the size of each bucket. On the one hand, the uneven distribution of bucket sizes requires a different number of threads to be assigned to each bucket sum. On the other hand, the thread block size is fixed and only threads within the block have fast-accessible shared memory and synchronization mechanisms. The specific dispatching method is carefully designed based on the input distribution.

[0056] Specifically, during the bucket summation phase, an optimization algorithm is employed to achieve load balancing, modeling the thread block allocation decision as an optimization problem. First, the elements in each bucket are divided into multiple thread blocks based on their relative sizes, ensuring that threads within the same thread block process the summation task for the same bucket. This allocation method leverages the high-speed nature of shared memory within the block and improves data exchange efficiency. For the remaining elements in each bucket, a search method with pruning is used to optimize the thread block allocation, ensuring that the number of different bucket categories processed within each thread block is minimized, further optimizing computational efficiency.

[0057] To further improve parallel efficiency, a load balancing strategy based on the size and number of elements in each bucket is implemented. Specifically, each bucket is assigned to an appropriate number of thread blocks, each responsible for summing a portion of the elements in that bucket, ensuring an even distribution of the load across the thread blocks. This approach not only effectively reduces computational bottlenecks caused by unbalanced loads but also minimizes conflicts when processing multiple buckets within each thread block, thereby improving 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 under window partitioning, except for the lowest window, 90% of the coefficients in each window are 0. In this scenario, the remaining 10% of 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 to existing technologies, the GPU-optimized sparseMSM algorithm provided by this invention offers a number of significant advantages. First, it fully exploits sparsity, particularly when processing large amounts of data, resulting in significant performance improvements. Second, the multi-GPU parallel computing architecture design fully leverages the advantages of GPU hardware resources, allowing load balancing to be finely regulated by the algorithm, reducing system resource overhead. Finally, the parallel processing technology employed by this invention enables MSM operations to be efficiently scaled to multi-node, multi-GPU environments, meeting 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 to each thread block is calculated, including: for each scalar allocated to each thread block, bitwise ORing the w-bit complement of the scalar with the scalar, right-shifting the bitwise OR result by w-1 bits, and taking the w-bit complement of the shifted result 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 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 it brings. 90% of them are 0 / 1, especially when the current window being processed is not the lowest (almost 90% of the scalars are 0). Even if the shared memory in the block is first distributed within the block, 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, it is necessary to let each thread calculate the mask mask based on the current scalar to not change the original operation mode under the SIMD architecture, while randomly selecting a bucket's tail pointer to apply for atomic read and write and perform a null operation when the input scalar is 0, 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 under 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 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 and right shifting 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 of 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 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 embodiment, the point subscripts of each thread block in each linked list merge table in S2 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 embodiment, S3 includes: S31: modeling the decision problem of thread block allocation 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 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 algorithm load depends on the maximum number of bucket categories that each thread needs to process. The thread block allocation decision problem 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 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 decision to be retrieved and the candidate decision that has 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 it is a two-tuple ((r1,…,r l ),s),(r1,…,r l ) is a permutation of 1, ..., l, which represents 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 represents 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 the 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-making scheme currently under consideration; 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 pruning search method 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 through 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 ) at any position, these tuples of length l+1 constitute the set L;

[0080] (312.4) Set s 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 second smallest element (r, s) in queue q2 and return r.

[0086] The main framework of the optimization problem is the breadth-first search algorithm, and optimality pruning is performed. For each node expansion permutation, the number of bucket categories handled by 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 and suboptimal solutions need to be retained for node expansion. During actual runtime, to balance the overhead of calculating the optimal allocation strategy with the computational overhead of the algorithm, only a subset of points with the same maximum number of categories can be retained in (2.2.6).

[0087] Furthermore, the GPU uses the obtained allocation strategy r to create concurrent threads. In each thread, the points in each bucket are summed. That is, after the algorithm is completed, the thread allocation plan is determined, and the following steps are then executed:

[0088] B1: GPU with 2 w -1 linked list (bucket distribution gets 2 w Linked list, skip 0) As input, it is necessary to complete the sum of the corresponding points in each linked list, that is, to calculate for the jth linked list

[0089] B2: Assign n points to N T threads, the algorithm will prepare at most 2 for each thread in advance w -1 pointer and its 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 of 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 have it write the result to a specific area on the video memory.

[0092] In one embodiment, S32 includes: GPU skips the first linked list, with 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 for each thread w -1 pointer and the corresponding length; N TThreads pass log2N T For each bucket, the threads that process the sum of the bucket are selected and asked to write the results to a specific area on the video memory.

[0093] In one embodiment, S4 includes: GPU takes the sum of the points in each bucket For input, GPU creates w×2 w threads, where 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, parallel calculation To do this, the GPU creates a w×2 w threads, where the jw+kth thread is responsible for calculating j k (2 k B j ), and then calculate the sum of these contents using the previous binary tree merging method. To optimize the computational overhead of repeated point multiplication, a conventional method is used to optimize the point multiplication calculation path on the elliptic curve group represented by Jacobian coordinates. This involves pre-multiplying the Y coordinate and performing an additional 1-bit right shift when returning the result. The GPU repeatedly iterates through different windows, running bucket distribution, bucket summation, and bucket merging. The results are then sent back to the CPU, which performs window merging as described previously. After W / W rounds of iterations, the final result is obtained on the CPU.

[0095] Example 2

[0096] This embodiment provides a device for accelerating sparse multi-scalar multiplication using a GPU, comprising: a CPU and a GPU in communication connection;

[0097] The CPU is used to migrate the obtained sparse multi-scalar multiplication calculation 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 allocated scalar 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 wEach linked list is then merged with 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 summation 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 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 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 them to 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 enable the GPU to 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 merely 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 scope of protection 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 allocated scalar, uses the mask of each scalar to correct the accessed bucket number and increment, 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 in 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 the scalar products 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 summation results corresponding to all windows before the current window left by w bits and adds 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 and returns to S2.

2. The method for accelerating sparse multi-scalar multiplication using an image processor according to claim 1, wherein: The step 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 subscripts of the points where each thread block in each linked list merge table in S2 is placed include: Thread 0 of each thread block in the jth current window is responsible for applying for atomic read and write 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 the linked list 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.

4. The method for accelerating sparse multi-scalar multiplication using an image processor according to claim 1, wherein: The S3 includes: S31: The thread block allocation decision problem is modeled as an optimization problem, where the goal is to minimize the maximum number of different bucket categories processed within 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 the summation result in a video memory.

5. The method for accelerating sparse multi-scalar multiplication using an image processor according to claim 4, wherein: 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 queue q1; 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, which represents 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 represents 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 the 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-making scheme currently under consideration; 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 second smallest 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 according to claim 4, wherein: 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 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 For each bucket, the threads that process the sum of the bucket are selected and asked to write the results 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 takes the sum of the points in each bucket For input, Image processor creates w×2 w threads, where 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 processor connected in communication; The central processing unit is configured 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 configured to read all scalars in the current window upon receiving the bucket distribution instruction, and distribute all scalars in the current window to multiple parallel thread blocks; calculate the mask of each allocated scalar in each thread block, use the mask of each scalar to correct the bucket number and increment to be accessed, add the increment to the corresponding bucket tail pointer, store the point subscript at the pointer and put the point subscript into 2w pre-established linked lists; then merge the point subscripts put in by each thread block in each linked list; wherein w is the number of bits in the current window; create a concurrent thread to sum the points in each bucket to obtain a first summation result of each bucket in the current window, and save it in the video memory; create a concurrent thread to respectively calculate the scalar product of the first summation result of each bucket in the current window, sum each scalar product to obtain a second summation result in the current window, and then send the second summation result in the current window back to the central processing unit; The central processing unit is further configured to shift the cumulative summation results corresponding to all windows before the current window left by w bits and then add the result to the second summation result in the current window sent back by the image processor to obtain a 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 enable the image processor to execute the calculation task of the next window.

Citation Information

Patent Citations

  • Data processing apparatus and data processing method

    CN116170159A

  • Zero-knowledge proof acceleration method and system based on GPU cluster

    CN118157872A