Multi-scalar multiplication calculation method and device, computer equipment and program product

Through parallel processing and bucketing technology on the target GPU, the problem of long-term multiplication in zero-knowledge proof is solved, and a more efficient calculation process is achieved.

CN120104317AActive Publication Date: 2025-06-06ZHEJIANG ANT MISUAN TECHNOLOGY CO LTD
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202510162431.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-02-12
Publication Date
2025-06-06
Estimated Expiration
2045-02-12

Smart Images

  • Figure CN120104317A_ABST
    Figure CN120104317A_ABST
Patent Text Reader

Abstract

The invention provides a multi-scalar multiplication calculation method. Point sequences and scalar sequences involved in multi-scalar multiplication are subjected to one-to-one para-position multiplication. The method is applied to a target GPU, a plurality of thread blocks are deployed in the target GPU, and each thread block is responsible for one sub-sequence in a plurality of sub-sequences divided by a point sequence. In the execution process of the method, any first thread block determines a sub-bucket corresponding to each point in the allocated first sub-sequence, and for each sub-bucket, the sum of the number of points falling into the sub-bucket in the first sub-sequence is determined. All the thread blocks are based on a distributed shared memory mechanism, different counters are aggregated for the sub-buckets corresponding to the same scalar value and from different thread blocks, and the global offset of all the sub-buckets of all the thread blocks in the target global memory is obtained. And according to the global offset, the points are stored in a global memory, and calculation operation is executed based on the bucket dividing result, so that a calculation result of multi-scalar multiplication is obtained. Global atomic operation is not needed, and acceleration is achieved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] One or more embodiments of the present specification relate to the field of computer technology application technology, and in particular, to a multi-scalar multiplication calculation method, apparatus, computer equipment, and program product. Background Art

[0002] Zero Knowledge Proof (ZKP) is a multi-party interactive cryptographic method. The prover declares that he has secret information, and the verifier needs to determine whether the prover's statement is true. Through zero-knowledge proof, the prover can convince the verifier of the authenticity of his statement without revealing any confidential information.

[0003] Zero-knowledge proof in the prior art is generally time-consuming, and the most time-consuming operation in zero-knowledge proof is multi-scalar multiplication (MSM). Therefore, in order to speed up zero-knowledge proof, it is necessary to accelerate the MSM operator. Summary of the invention

[0004] In view of this, one or more embodiments of the present specification provide a multi-scalar multiplication calculation method, apparatus, computer device, and program product.

[0005] According to a first aspect of one or more embodiments of the present specification, a multi-scalar multiplication calculation method is proposed, which is applied to a target GPU, wherein the target GPU includes a target global memory and is deployed with multiple thread blocks, wherein the multi-scalar multiplication involves a one-to-one bitwise multiplication of elements in a point sequence and a scalar sequence, wherein the point sequence is divided into multiple subsequences and assigned to the multiple thread blocks; the method comprises:

[0006] Any first thread block determines the buckets into which each point in the allocated first subsequence falls, and for each bucket, determines the sum of the number of points falling into the bucket, and stores the sum in the first counter of the bucket; wherein the bucket into which any target point falls corresponds to the scalar value of the target scalar to be bitwise multiplied with the target point;

[0007] Each thread block aggregates counters of buckets corresponding to the same scalar value based on a distributed shared memory mechanism to obtain a global offset of each bucket in each thread block in the target global memory;

[0008] Each thread block stores the point sequence in the target global memory according to the global offset of each bucket, so as to perform bucket-based computing operations.

[0009] According to a second aspect of one or more embodiments of the present specification, a multi-scalar multiplication computing device is provided, which is applied to a target GPU, wherein the target GPU includes a target global memory and is deployed with a plurality of thread blocks, wherein the multi-scalar multiplication involves a one-to-one bitwise multiplication of elements in a point sequence and a scalar sequence, wherein the point sequence is divided into a plurality of subsequences and assigned to the plurality of thread blocks; the device comprises:

[0010] A bucketing module is used for any first thread block to determine the buckets into which each point falls for the allocated first subsequence, and for each bucket, to determine the sum of the number of points falling into the bucket, and store the sum in a first counter of the bucket; wherein the bucket into which any target point falls corresponds to the scalar value of the target scalar to be bitwise multiplied with the target point;

[0011] An offset calculation module is used for each thread block to aggregate the counters of buckets corresponding to the same scalar value based on a distributed shared memory mechanism to obtain a global offset of each bucket in each thread block in the target global memory;

[0012] A storage module is used for each thread block to store the point sequence in the target global memory according to the global offset of each bucket, so as to perform bucket-based computing operations.

[0013] According to a third aspect of the embodiments of this specification, a computer-readable storage medium is provided, on which computer instructions are stored. When the instructions are executed by a processor, the multi-scalar multiplication calculation method as described in the first aspect of the embodiments of this specification is implemented.

[0014] According to a fourth aspect of an embodiment of this specification, a computer device is provided, the computer device comprising:

[0015] processor;

[0016] a memory for storing processor-executable instructions;

[0017] The processor implements the multi-scalar multiplication calculation method as described in the first aspect of the embodiment of this specification by running the executable instructions.

[0018] According to a fifth aspect of the embodiments of this specification, a computer program product is provided, which, when executed by a processor, implements the multi-scalar multiplication calculation method as described in the first aspect of the embodiments of this specification.

[0019] This specification provides a multi-scalar multiplication calculation method. The point sequence and the scalar sequence involved in the multi-scalar multiplication are multiplied one by one. The method is applied to a target GPU, and the target GPU is deployed with multiple thread blocks, each of which is responsible for one of the multiple subsequences into which the point sequence is divided. During the execution of the method, any first thread block determines the buckets corresponding to each point in the allocated first subsequence, and for each bucket, determines the sum of the number of points in the first subsequence that fall into the bucket. Based on the distributed shared memory mechanism, each thread block aggregates different counters for buckets from different thread blocks corresponding to the same scalar value, and obtains the global offset of each bucket of each thread block in the target global memory. And according to the global offset, the point is stored in the global memory, and the calculation operation is performed based on the above bucket result to obtain the calculation result of the multi-scalar multiplication.

[0020] Through the distributed shared memory mechanism, a thread block can access the counters of other thread blocks, so that the counters between different thread blocks can be aggregated and the global offset can be calculated. There is no need to calculate the storage location through global atomic operations, which speeds up the execution of bucket operations and thus accelerates the execution of multi-scalar multiplication.

[0021] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present specification. BRIEF DESCRIPTION OF THE DRAWINGS

[0022] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the specification and, together with the description, serve to explain the principles of the specification.

[0023] Figure 1 It is a schematic diagram of a GPU cluster performing multi-scalar multiplication according to an exemplary embodiment of the present specification.

[0024] Figure 2 It is a flowchart of a multi-scalar multiplication calculation method shown in this specification according to an exemplary embodiment.

[0025] Figure 3 It is a schematic diagram of a subsequence that a thread block is responsible for according to an exemplary embodiment of the present specification.

[0026] Figure 4 is a schematic diagram of a global shared segment according to an exemplary embodiment of the present specification.

[0027] Figure 5 It is a block diagram of a multi-scalar multiplication computing device shown in this specification according to an exemplary embodiment.

[0028] Figure 6It is a hardware structure diagram of a computer device shown in this specification according to an exemplary embodiment. DETAILED DESCRIPTION

[0029] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with one or more embodiments of this specification. Instead, they are merely examples of devices and methods consistent with some aspects of one or more embodiments of this specification as detailed in the appended claims.

[0030] It should be noted that: in other embodiments, the steps of the corresponding method are not necessarily performed in the order shown and described in this specification. In some other embodiments, the steps included in the method may be more or less than those described in this specification. In addition, a single step described in this specification may be decomposed into multiple steps for description in other embodiments; and multiple steps described in this specification may be combined into a single step for description in other embodiments.

[0031] Zero-knowledge proof is a cryptographic primitive that allows the prover to convince the verifier of the authenticity of his statement without revealing any confidential information. By using zero-knowledge proof, users who do not trust each other on the network can exchange information without revealing any privacy and without supervision. Zero-knowledge proof has been widely used in many fields, such as verifiable outsourced computing, electronic voting, verifiable machine learning, and online auctions.

[0032] Zero-knowledge proofs generally require multiple interactions, and the amount of data involved is also large, which results in a large communication overhead and, in turn, low versatility. Therefore, a succint non-interactive zero-knowledge proof (zkSNARK) is proposed in the related art, which reduces the amount of communication during the proof process and makes the proof more concise.

[0033] Although the proofs generated by zkSNARK can be quickly verified, the computationally intensive proof generation process is the main obstacle to its large-scale implementation in real-world scenarios. The core operations in the zkSNARK calculation process include multi-scalar multiplication MSM and number theoretic transformation (NTT), of which the calculation of MSM takes up nearly 80% of the time. Therefore, in order to speed up the calculation of zero-knowledge proofs, it is necessary to calculate the MSM operator.

[0034] Multi-scalar multiplication is an algorithm for summing scalar multiplications of points on an elliptic curve. Formally, MSM is represented by ∑k i P i , where each P i represents a point on the elliptic curve, k i is a λ-bit scalar. Each product k i P i Point multiplication (PMUL) is required, which is also referred to as elliptic curve multiplication in the following text. Similar to the fast exponentiation technique, PMUL can be efficiently implemented using point addition (PADD) and point doubling (PDBL) operations. PADD is also referred to as elliptic curve addition in the following text.

[0035] In order to speed up the calculation process of multi-scalar multiplication, in one implementation, for each group of k i P i , according to which the scalar k i The scalar value of the point P that is multiplied by the scalar i For example, k i The possible values ​​of k include 0-7, so we can get 8 buckets corresponding to the scalar values ​​0-7. i When it is 0, the point P i Divide into buckets 0, k i When it is 1, the point P i Assign it to bucket 1, and so on.

[0036] After obtaining each bucket, for each bucket, first perform elliptic curve addition operation on the points in the bucket to obtain the sum of all points in the bucket. Then perform elliptic curve multiplication operation on the sum of all points and the scalar value corresponding to the bucket to obtain the multiplication result. Finally, perform elliptic curve addition operation on the multiplication results corresponding to each bucket to obtain the result of multi-scalar multiplication.

[0037] Since the calculation speed of elliptic curve multiplication is slow, the above bucketing operation can reduce the number of elliptic curve multiplications and speed up the implementation of multi-scalar multiplication.

[0038] In the above process, the bucketing process of multi-scalar multiplication still consumes a lot of computing time. Next, the computing process of multi-scalar multiplication in one implementation will be specifically described.

[0039] This method is applied to the Graphics Processing Unit (GPU), and the characteristics of the GPU can better perform parallel calculations on multi-scalar multiplications. In GPUs, bucketing operations are generally completed through multiple thread blocks. Among them, thread blocks are a form of organization for threads, and each thread block is a collection of multiple threads. Threads within a thread block share the same execution context, such as instruction pointers, program counters, etc. In addition, each thread block has its own shared memory, which can be accessed by threads within the thread block, while threads in other thread blocks generally cannot access the shared memory. Each thread block also has a set of registers for the thread block.

[0040] For each point P in the point sequence i In general, each thread block is responsible for bucketing some of the points.

[0041] Each thread block first determines the corresponding bucket according to the scalar value corresponding to each point (that is, the scalar value of the scalar multiplied by the point). And in the shared memory corresponding to the thread block, each point is stored according to the bucket, that is, the points corresponding to each bucket are stored together. For example, the points corresponding to each bucket can be stored continuously in the shared memory, first continuously storing the points corresponding to the first bucket, and then continuously storing the points corresponding to the second bucket after the last point of the first bucket, and so on.

[0042] In the above process, the bucketing operation is only performed within one thread block. Further, the buckets of each thread block need to be aggregated. Specifically, all points corresponding to each bucket need to be stored together in the global memory accessible to each thread block. For example, if there are three thread blocks, for the first bucket, the points corresponding to the first bucket of the three thread blocks need to be stored together. This makes it convenient to perform elliptic curve addition operations on the points in each bucket in the subsequent process.

[0043] Then, each thread block takes out the points corresponding to each bucket from the shared memory. For each bucket, the points of the bucket of the thread block are stored in the global memory through a global atomic operation, so that multiple thread blocks can store the points of buckets with the same scalar value together.

[0044] Among them, atomic operations are inseparable operations in computer execution. They are either completed in full or not completed in full during the execution process. There will be no situation where only part of the operations are completed. Atomic operations are the basis for ensuring data consistency and implementing synchronization mechanisms. For this reason, atomic operations will not be interrupted by other operations during execution. For example, two threads need to operate on the same shared resource, such as two threads need to accumulate the same counter. If it is not executed through atomic operations, the accumulation operation of one thread may be interrupted by the accumulation operation of another thread, which ultimately makes the accumulation result inaccurate. Through atomic operations, the competition between the two threads for the same shared resource is avoided, making the accumulation operation accurate.

[0045] In the scenario where multiple thread blocks perform storage operations on buckets, the global atomic operation refers to the process in which a thread block stores points in a bucket into global memory, and this process cannot be interrupted by other threads. Since multiple thread blocks may compete for the same memory address, the global atomic operation prevents threads in other thread blocks from storing points in buckets corresponding to the same scalar value in global memory at the same time, thus ensuring the accuracy of the stored content.

[0046] The uninterruptibility of global atomic operations reduces the parallelism of the GPU and increases the time required for bucketing operations.

[0047] Based on this, this specification provides a multi-scalar multiplication calculation method. The point sequence and the scalar sequence involved in the multi-scalar multiplication are multiplied one by one. The method is applied to the target GPU, and the target GPU is deployed with multiple thread blocks, each thread block is responsible for one of the multiple subsequences into which the point sequence is divided. During the execution of the method, any first thread block determines the bucket corresponding to each point in the allocated first subsequence, and for each bucket, determines the sum of the number of points in the first subsequence that fall into the bucket. Based on the distributed shared memory mechanism, each thread block aggregates different counters for the buckets from different thread blocks corresponding to the same scalar value, and obtains the global offset of each bucket of each thread block in the target global memory. And according to the global offset, the point is stored in the global memory, and the calculation operation is performed based on the above bucket result to obtain the calculation result of the multi-scalar multiplication.

[0048] Through the distributed shared memory mechanism, a thread block can access the counters of other thread blocks, so that the counters between different thread blocks can be aggregated and the global offset can be calculated. There is no need to use global atomic operations to store the points in the buckets, which speeds up the execution of bucket storage and thus the execution of multi-scalar multiplication.

[0049] Next, a multi-scalar multiplication calculation method provided in this specification will be described.

[0050] In this specification, it is necessary to calculate multi-scalar multiplication, which involves point sequences and scalar sequences. Multi-scalar multiplication involves one-by-one multiplication of elements in point sequences and scalar sequences. As mentioned above, multi-scalar multiplication can be expressed as ∑k i P i , k i The sequence composed of is a scalar sequence, P i The composed sequence is a point sequence, and the points in the point sequence are the points in the elliptic curve.

[0051] The multi-scalar multiplication may be a multi-scalar multiplication calculation operation in zero-knowledge proof, or may be a calculation operation in any other application that requires a multi-scalar multiplication calculation result.

[0052] As for the application device of the method, the method can be applied to a target GPU, wherein the target GPU can execute the result of the bitwise multiplication of the elements in the point sequence and the scalar sequence through a single GPU.

[0053] In addition, due to the limited computing power of a single GPU in the related art, in some cases, a GPU cluster consisting of multiple GPUs is used to complete the zero-knowledge proof method. Correspondingly, the method of this specification can also be applied to the target GPU of a GPU cluster. In other words, the target GPU is deployed in a GPU cluster. When the method is applied to a GPU cluster, the schematic diagram of each GPU cooperating to perform multi-scalar multiplication is as follows Figure 1 shown.

[0054] Figure 1 In, P 0 To P n-1 The n points represent a point sequence, any point P i The corresponding 01 bit string is the binary representation of the scalar to be multiplied with the point. The total scalar sequence is composed of all the scalars corresponding to the bit strings in each row. Multi-scalar multiplication ultimately requires the calculation of ∑Q i When the target GPU executes this method, the scalar sequence it is responsible for is: a sequence consisting of substrings of a preset range intercepted from the binary string of each scalar in the total scalar sequence, and different GPUs in the GPU cluster are responsible for scalar sequences corresponding to different interception ranges. That is, each GPU intercepts a continuous substring from the binary string of each total scalar to form a new scalar for calculation.

[0055] like Figure 1 As shown, the total scalar sequence is divided into multiple parts (three parts are shown in the figure), where the elliptic curve multiplication operation of the scalar sequence and the point sequence corresponding to the green part is calculated by GPU0, and the elliptic curve multiplication operation of the scalar sequence and the point sequence corresponding to the blue part is calculated by GPU1, and so on. The arrows in the figure point to the GPU responsible for the scalar sequence.

[0056] The method of this specification can achieve better results when applied to a GPU cluster. For example, different GPUs in a GPU cluster intercept different positions of the total scalar sequence, which reduces the number of buckets that each GPU is responsible for. It is more likely to happen that multiple threads operate on the same shared resource in parallel, which makes the impact of global atomic operations on speed greater. Therefore, avoiding global atomic operations through a distributed shared memory mechanism can improve performance more significantly.

[0057] Specifically, there is a one-to-one correspondence between the number of buckets and all possible scalar values ​​of the scalar. For example, if the scalar is 4-bit binary data, then the scalar value range is 0-15 (decimal), so all points can be divided into 16 buckets; if the scalar has 3 bits and the scalar value range is 0-7, then all points can be divided into 8 buckets. Since different GPUs intercept different positions of the total scalar sequence, the possible range of the scalar that each GPU is responsible for becomes smaller, thereby reducing the number of buckets that the GPU is responsible for.

[0058] Here, for the sake of convenience, the characteristics of global atomic operations will be further explained. Global atomic operations are independent for different shared resources. Specifically, when a global atomic operation is executed on shared resource 1 (such as counter 1), global atomic operations on other shared resources (such as counter 2) can be executed in parallel.

[0059] Therefore, when the number of buckets decreases, resource contention is more likely to occur in the process of storing the points of a bucket in the global memory, and the deceleration effect of the global atomic operation is more obvious.

[0060] For example, the thread of thread block 1 needs to store the points of bucket 1 with a scalar value of 1 in the global memory. In the above process, the thread of thread block 2 may also need to store its own points of bucket 1 with a scalar value of 1 in the global memory. This process will cause competition, and the global atomic operation used by thread block 1 in the above calculation will cause the storage operation of thread block 2 to wait.

[0061] If the number of buckets is large, the probability of contention is not high. Even if global atomic operations are used, the operations of thread blocks rarely wait for a long time.

[0062] However, in a GPU cluster, since each GPU is responsible for a scalar formed by a substring, the scalar value range is smaller, and the number of buckets is reduced, the above-mentioned concurrent competition will be more obvious, and the impact of global atomic operations on execution speed will be more obvious. And the more GPUs there are, the more obvious this problem is. The method of this specification can avoid global atomic operations, so that better acceleration effects can be achieved in a GPU cluster.

[0063] Next, we will combine Figure 2 The flowchart shown in the figure is used to illustrate the multi-scalar multiplication calculation method shown in this specification. The method is applied to a target GPU, and the target GPU includes a target global memory, and the target global memory is used to store points in a point sequence. The target GPU is deployed with multiple thread blocks, and the point sequence mentioned above is divided into multiple subsequences and assigned to the multiple thread blocks. The method includes the following steps:

[0064] Step 201, any first thread block determines the buckets into which each point in the allocated first subsequence falls, and for each bucket, determines the sum of the number of points falling into the bucket, and stores it in the first counter of the bucket. The bucket into which any target point falls corresponds to the scalar value of the target scalar to be bitwise multiplied with the target point.

[0065] This step is described by taking the first thread block as an example. It is understandable that each thread block in the plurality of thread blocks can be used as the first thread block in this specification to execute the method. The first subsequence refers to a subsequence in the plurality of subsequences that is assigned to the first thread block.

[0066] For ease of understanding, Figure 1 Take the scalar sequence and point sequence processed by GPU0 in the example to illustrate the relationship between the first subsequence and the point sequence. Assume that the point sequence has 9 points in total, there are 3 thread blocks in total, and each thread block is responsible for a subsequence with 3 points. It should be noted that the example here is only for the convenience of explanation. In actual application, there may be more points in the point sequence. So, Figure 3 The first subsequence that the first thread block is responsible for may include point P 0 To P 2 , the second subsequence that the second thread block is responsible for may include point P 3 To P 5 , the third subsequence that the third thread block is responsible for may include point P 6 To P 8 .

[0067] Taking the first thread block as an example, in this step, the first thread block needs to determine which bucket each point in the first subsequence falls into, and determine the sum of the number of points falling into each bucket for the first subsequence it is assigned to. It can be understood that determining the sum of the number of points falling into the bucket refers to the sum of the number of points falling into the bucket in the first subsequence. The first counter is a counter inside the thread block. In the above steps, different thread blocks bucket and count their own subsequences, and obtain their own counters for each bucket. For example, for bucket 1 with a scalar value of 1, the first thread block has a first counter for bucket 1, and the second thread block has a second counter for bucket 1. The first counter stores the number of points in the first subsequence that fall into bucket 1, and the second counter stores the number of points in the second subsequence (i.e., the subsequence assigned to the second thread block) that fall into bucket 1.

[0068] It should be noted that each thread block corresponds to a set of counters. For example, if there are 8 buckets, each thread block corresponds to 8 counters. For the same bucket, the counters corresponding to different thread blocks are independent of each other. The counter corresponding to each thread block is only used to record the bucket status of the points that the thread block is responsible for.

[0069] The bucket that any target point falls into corresponds to the scalar value of the target scalar to be multiplied with the target point, that is, the scalar values ​​corresponding to different points in the same bucket are the same. In other words, bucketing is performed according to the size of the scalar values ​​corresponding to the points. Points with the same scalar value are placed in the same bucket, and points with different scalar values ​​are placed in different buckets.

[0070] Next, the specific implementation method of the above steps will be described through a specific embodiment, and this embodiment does not limit this specification.

[0071] The above step 201 may include: any first thread block executes, for each point in the first subsequence:

[0072] According to the scalar value of the scalar corresponding to the point, determine the bucket into which the point falls, and store the identifier of the bucket into which the point falls in a register;

[0073] Through a local atomic operation in the first thread block, a first counter of the bucket into which the point falls is incremented.

[0074] The scalar corresponding to the point is also the scalar multiplied by the point. Local atomic operations refer to atomic operations within a thread block. The specific meaning of atomic operations is detailed in the previous article and will not be repeated here. Compared with global atomic operations, local atomic operations are atomic operations within thread blocks, which maintain the parallelism between thread blocks and have less impact on execution speed. The above local atomic increment operation can specifically be "atomic_inc".

[0075] In addition, the reason why local atomic operations are required in the above method is that: multiple threads of the first thread block may process different points in parallel, calculate the buckets of the points, and increment the first counter of the bucket that the point falls into. In this case, different threads may compete for incrementing the counter of the same bucket. In order to ensure the accuracy of the counter number, local atomic operations can be used to complete it.

[0076] The above method can be completed through multiple loops, and the number of loops can be related to the number of points in the first subsequence. Multiple threads in the thread block can execute different loops in parallel. In each loop, a point can be processed. Specifically, the bucket into which the point falls is calculated, and the bucket identifier of the bucket corresponding to the point is stored in a register. In addition, an increment operation is performed on the counter corresponding to the bucket.

[0077] In addition, after executing step 201 and before storing the points in the global memory (i.e., step 203), the points can also be stored in the shared memory inside the thread block according to buckets, so as to facilitate storing the points of each bucket of each thread block in the global memory together in the subsequent process.

[0078] Specifically, any first thread block may also execute:

[0079] Aggregating first counters of different buckets in the first thread block according to a parallel prefix sum function to obtain a first offset of each bucket in a first shared memory corresponding to the first thread block;

[0080] Points in the first subsequence are stored in the first shared memory according to the first offset.

[0081] The parallel prefix sum function may be specifically: parallel_prefix_sum(), which is specifically used to calculate the prefix sum of an array. Specifically, the function can add the elements in the array one by one, so that each element saves the cumulative result of all the previous elements. For example, executing the parallel prefix sum function for the array [1,2,3,4,5] can get [1,3,6,10,15]. Among them, the second element 3 in the result array is the sum of the first element 1 and the second element 2 of the original array, and the third element 6 in the result array is the sum of the first element 1, the second element 2 and the third element 3 of the original array, and so on.

[0082] The original array in this method is the counter of each bucket corresponding to the first thread block. Since the storage space size of each point is fixed and is 1 storage unit, the continuous storage position of each bucket in the shared memory of the first thread block can be obtained through the parallel prefix sum function. For example, the counter of each bucket can be [1,2,3,4,5]. Then the result [1,3,6,10,15] calculated by the parallel prefix sum function can be used as the end position of each bucket in the shared memory, and the storage start position of each bucket is determined according to the end position for storage.

[0083] The first counter is a counter of the first thread block, and the first is used to distinguish which thread block the counter belongs to. The first of the first offset is the same as the first of the first counter, and is not used to distinguish different buckets, but to distinguish different thread blocks.

[0084] After the first offset is calculated by the parallel prefix sum function, each point can be stored in sequence in the storage space of the shared memory corresponding to the first offset. Furthermore, through the above method, the points allocated to each thread block can be continuously stored in the shared memory of the thread block in the bucket order, and the points in the same bucket are stored continuously.

[0085] Step 203 : Each thread block aggregates counters of buckets corresponding to the same scalar value based on the distributed shared memory mechanism to obtain a global offset of each bucket in each thread block in the target global memory.

[0086] Specifically, in order to avoid using global atomic operations, this specification uses a distributed shared memory (DSM) mechanism to allow different thread blocks to access their shared memory, so that the counters of buckets corresponding to the same scalar value of different thread blocks can be more conveniently aggregated, thereby determining the global offset of each bucket of each thread block in the global memory.

[0087] Among them, the distributed shared memory mechanism is a mechanism of GPU, which can map the shared memory and perform other processing, so that the shared memory of a thread block can be accessed by other thread blocks.

[0088] Next, the specific implementation method of step 203 is described: the first thread block sets a global shared segment in the first shared memory that other thread blocks have the right to access, and stores the first counter corresponding to each bucket therein; by running a parallel prefix sum function in the global shared segment of each thread block as a whole, the counter accumulated value of each bucket is obtained, thereby obtaining the global offset of each bucket in each thread block in the target global memory.

[0089] That is, each thread block maps part of its shared memory to a global shared segment accessible to other thread blocks through the distributed shared memory mechanism, and stores the counters corresponding to each bucket in the segment. Then, for each bucket corresponding to a scalar value, a parallel prefix sum function can be executed in the global shared segment corresponding to each thread block to obtain the global offsets of multiple buckets corresponding to the scalar value in the target global memory.

[0090] Specifically, suppose there are 3 thread blocks in total, and the number of buckets corresponding to each thread block is 2. In other words, the scalar sequence includes scalar values ​​0 and 1. The counters of bucket 0 of the three thread blocks with scalar values ​​0 are 2, 3, and 5 respectively, and the counters of bucket 1 of the three thread blocks with scalar values ​​1 are 1, 4, and 6 respectively. Then the global shared segment can be as follows Figure 4 As shown, Figure 4 The entire square in the figure represents the shared memory of the thread block. The shared memory of different thread blocks is independent of each other. The global shared segment with a green background in the figure can be obtained through the distributed shared memory mechanism. The global shared segment stores the counters of each bucket. Furthermore, the parallel prefix sum function can be executed between the global shared segments represented by the green range.

[0091] Due to the distributed shared memory mechanism, the parallel prefix and function can be executed between the shared memories of different thread blocks, thereby completing the method of realizing offset calculation without the need for global atomic operations.

[0092] The global offset here is distinguished from the first offset and is used to indicate that it is an offset in the target global memory.

[0093] The global shared segment can be set by cluster.map_shared_rank() function, whose parameters can include shared memory pointer. The function can return the shared memory address, through which other thread blocks can access the shared memory of a thread block pointed to by the pointer. That is, through this function, the address pointed to by the shared memory pointer can be changed into the global shared segment.

[0094] When setting the global shared segment, cluster.map_shared_rank() may be executed for each bucket to obtain a global shared segment that can store the counter of the bucket, and store the counter of the bucket therein.

[0095] The parallel prefix sum function is described in the previous article. Here, the parallel prefix sum function can be executed separately for each bucket corresponding to the scalar value. For example, for the bucket with a scalar value of 0, Figure 4As shown, the counters of the buckets with scalar values ​​of 0 in each thread block are 2, 3, and 5 respectively. The prefix sum calculation can get 2, 5, and 10, which are the global offsets corresponding to the buckets with scalar values ​​of 1 in the three thread blocks. In this way, the points of the buckets with scalar values ​​of 0 in different thread blocks can be stored together.

[0096] For the convenience of calculation, you can also use a parallel prefix sum function to calculate the global offset of each bucket of scalar values. Figure 4 In the example, we can obtain the counter array [2,3,5,1,4,6] that stores the buckets with scalar values ​​of 0 and scalar values ​​of 1 of the three thread blocks in order according to the bucket order, and input the array into the parallel prefix sum function to obtain [2,5,1,11,15,21]. [2,5,1,11,15,21] is used as the global offset of bucket 0 of the first thread block, the global offset of bucket 0 of the second thread block, the global offset of bucket 0 of the third thread block, the global offset of bucket 1 of the first thread block, the global offset of bucket 1 of the second thread block, and the global offset of bucket 1 of the third thread block.

[0097] Step 205: Each thread block stores the point sequence in the target global memory according to the global offset of each bucket, so as to perform bucket-based computing operations.

[0098] Specifically, after the global offset corresponding to each bucket of each thread block is obtained through step 203, the points of each bucket can be stored in the target global memory to obtain the bucket results, so as to complete the calculation of multi-scalar multiplication according to the bucket results.

[0099] As mentioned above, for the convenience of processing, each point of the first subsequence may be stored in a shared memory. In this case, the above step 205 may include:

[0100] Any first thread block executes for each bucket:

[0101] Taking out the first point set falling into the bucket from the first shared memory;

[0102] According to the global offset of the bucket in the global memory, the first point set is stored in the target global memory.

[0103] The first point set is the points in the first subsequence that fall into the bucket.

[0104] The bucket-based calculation operation may specifically be, for a first bucket corresponding to a first scalar value, calculating the elliptic curve addition result of all points falling into the first bucket, and calculating the elliptic curve multiplication result of the first scalar value and the addition result; performing elliptic curve addition operation on the multiplication results corresponding to each bucket to obtain multi-scalar multiplication results in the target GPU.

[0105] In other words, for each bucket of a scalar value, the sum of all points inside the bucket is calculated, and the sum result is multiplied by the scalar value to obtain multiple multiplication results, and finally the multiplication results are added to obtain a multi-scalar multiplication result.

[0106] It should be noted that when executing bucket-based computing operations, multiple thread blocks can be executed in parallel, and the original allocation relationship between subsequences and thread blocks is no longer considered during execution. That is, the thread block that executes elliptic curve addition is no longer determined by the original allocation relationship.

[0107] In addition, as mentioned above, the target GPU used by the method of this specification may belong to a GPU cluster. In this case, the process of calculating multi-scalar multiplication is as follows: Figure 1 As shown, the multi-scalar multiplication results of the total scalar sequence and the point sequence can be determined according to the bucket-based calculation operation results of each GPU. In an optional embodiment, this step is as follows Figure 1 As shown, it can be executed by the CPU.

[0108] Specifically, if Figure 1 As shown, the target GPU first calculates the sum of all points in each bucket for each scalar value, and sends the sum result to the CPU, which obtains the multi-scalar multiplication calculation result through PADD and PAML based on each sum result.

[0109] Next, the method of this specification will be described through a specific embodiment. The pseudo code in this example can be:

[0110]

[0111]

[0112] The above method is executed through 4 loops, and the 4 loops will be described below respectively.

[0113] Lines 1-5 are the first loop, which is executed by each thread block (for the convenience of explanation, the execution method of the first thread block is taken as an example, which will be described later). Its function is to determine the bucket of each point in the first subsequence allocated by the first thread block, and to count the number of points in each bucket of the first thread block, that is, to determine the size of the first counter of each bucket. K is the number of points in the first subsequence, that is, each round of loop processes one point. It should be noted that the loop here can be a loop of different rounds executed in parallel by multiple threads in the first thread block, and the loop in the following text is similar to it, which will not be described again.

[0114] Lines 2-3 are used to calculate the bucket identifier of the point processed in this round of loop. Line 4 is used to store the calculated bucket identifier in the corresponding position of the register. Line 5 is used to increment the first counter of the bucket that the point falls into. This increment operation is a local atomic operation inside the thread block. shm_count[bucket_id] is the size of the first counter corresponding to each bucket.

[0115] After the first round of loop execution is completed, the parallel prefix sum function in line 6 can be used to determine the offset of each bucket in the shared memory of the first thread block, that is, the storage position therein.

[0116] Lines 7-10 are the second loop, which is executed by each thread block and has the function of storing each point of the first subsequence in the shared memory of the first thread block in bucket order.

[0117] Specifically, each loop processes one point. In each loop, line 8 is used to retrieve the bucket identifier of the point from the register, line 9 calculates the storage location of the point in the shared memory through an increment operation, and line 10 stores the point in the calculated location. Among them, the increment operation is a local atomic operation, which can avoid conflicts in the increment calculation of the same shm_off[bucket_id] by multiple threads in the first thread block. shm_off[bucket_id] is the storage location of each bucket in the shared memory after the previous loop ends. Through the above operations, points in the same bucket can be stored together to facilitate subsequent operations.

[0118] Lines 11-14 are the third loop, which is executed by each thread block and is used to set the global shared segment through the distributed shared memory mechanism. s is the number of buckets, and s is the length of the scalar sequence, that is, each round of the cycle processes one bucket.

[0119] Specifically, lines 12 and 13 are used to set the global shared segment through the distributed shared memory mechanism. smem is the pointer to the shared memory, and dist_shm_count is the address of the global shared segment. tb_rank is another parameter of cluster.map_shared_rank in addition to the shared memory pointer, which represents the rank of the thread block, which is the index of the thread block that needs to access the shared memory in the CUDA cluster structure.

[0120] Line 14 is used to store the counter in the global shared section through a local atomic operation inside the first thread block.

[0121] Line 15 is used to execute the parallel prefix sum function in the global shared segment of multiple thread blocks to determine the global offset (offset) of each bucket of each thread block in the target global memory. At the same time, according to the size of the counter of each bucket, the size (size) of the storage space required for each bucket in the target global memory can also be obtained. That is, through this step, the storage location of each bucket in the target global memory can be determined, that is, the point corresponding to each bucket can be stored in the address of offset to offset+size in the target global memory. .

[0122] 16-19 is the fourth loop, which is executed by each thread block. Its function is to store the points of each bucket according to the global offset. The number of loops is still the number of buckets. Each loop is used to take out the points of a bucket from the shared memory and store them in the location corresponding to the global offset of the target global memory.

[0123] Specifically, line 17 is used to retrieve the corresponding bucket point of the current round loop from the shared memory of the first thread block. Lines 18 and 19 are used to obtain the global offset of the bucket and store the point in the shared memory to the corresponding position of the target global memory. Since the global offset is determined by the parallel prefix sum function between multiple global shared segments in line 15, when obtaining the storage location in the target global memory, there will be no computational competition for the storage location with other thread blocks, and no global atomic operation is required, thereby speeding up the bucket operation.

[0124] Corresponding to the embodiments of the aforementioned method, this specification also provides embodiments of a device and a terminal to which it is applied.

[0125] like Figure 5 As shown, Figure 5This is a block diagram of a multi-scalar multiplication computing device according to an exemplary embodiment of the present specification, the device is applied to a target GPU, the target GPU includes a target global memory, and is deployed with multiple thread blocks, the multi-scalar multiplication involves a one-to-one bitwise multiplication of elements in a point sequence and a scalar sequence, the point sequence is divided into multiple subsequences and assigned to the multiple thread blocks; the device includes:

[0126] The bucketing module 310 is used for any first thread block to determine the buckets into which each point falls for the allocated first subsequence, and for each bucket, to determine the sum of the number of points falling into the bucket, and store the sum in a first counter of the bucket; wherein the bucket into which any target point falls corresponds to the scalar value of the target scalar to be bitwise multiplied with the target point;

[0127] An offset calculation module 320 is used for each thread block to aggregate counters of buckets corresponding to the same scalar value based on a distributed shared memory mechanism to obtain a global offset of each bucket in each thread block in the target global memory;

[0128] The storage module 330 is used for each thread block to store the point sequence in the target global memory according to the global offset of each bucket, so as to perform bucket-based computing operations.

[0129] In an optional embodiment, the offset calculation module 320 is used for the first thread block to set a global shared segment in the first shared memory that other thread blocks have the right to access, and store the first counter corresponding to each bucket therein; by running a parallel prefix sum function in the global shared segment of each thread block as a whole, the counter cumulative value of each bucket is obtained, thereby obtaining the global offset of each bucket in each thread block in the target global memory.

[0130] In an optional embodiment, the bucketing module 310 is used for any first thread block to perform, for each point in the first subsequence: determining the bucket into which the point falls according to the scalar value of the scalar corresponding to the point, and storing the identifier of the bucket into which the point falls in a register; and incrementing the first counter of the bucket into which the point falls through local atomic operations within the first thread block.

[0131] In an optional embodiment, the device also includes a storage module 330 which is also used to execute, for any first thread block: aggregating first counters of different buckets in the first thread block according to a parallel prefix sum function to obtain a first offset of each bucket in a first shared memory corresponding to the first thread block; and storing points in the first subsequence in the first shared memory according to the first offset.

[0132] In an optional implementation, the storage module 330 is used for any first thread block to execute, for each bucket: taking out the first point set that falls into the bucket from the first shared memory; and storing the first point set in the target global memory according to the global offset of the bucket.

[0133] In an optional embodiment, the points in the point sequence are points in an elliptic curve; the storage module 330 is used to calculate the elliptic curve addition result of all points falling into the first bucket corresponding to the first scalar value, and calculate the elliptic curve multiplication result of the first scalar value and the addition result; perform elliptic curve addition operation on the multiplication results corresponding to each bucket to obtain multiple scalar multiplication results in the target GPU.

[0134] In an optional embodiment, the target GPU is deployed in a GPU cluster, and the scalar sequence is a sequence composed of substrings of a preset range intercepted from the binary string of each scalar in the total scalar sequence, and different GPUs in the GPU cluster are responsible for scalar sequences corresponding to different interception ranges; the device also includes a summation module for determining multi-scalar multiplication results of the total scalar sequence and the point sequence according to the bucket-based calculation operation results of each GPU.

[0135] The implementation process of the functions and effects of each module in the above-mentioned device is specifically described in the implementation process of the corresponding steps in the above-mentioned method, which will not be repeated here.

[0136] For the device embodiment, since it basically corresponds to the method embodiment, the relevant parts can refer to the partial description of the method embodiment. The device embodiment described above is only schematic, wherein the modules described as separate components may or may not be physically separated, and the components displayed as modules may or may not be physical modules, that is, they may be located in one place, or they may be distributed on multiple network modules. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this specification. A person of ordinary skill in the art can understand and implement it without paying creative labor.

[0137] like Figure 6 As shown, Figure 6 A hardware structure diagram of a computer device is shown, and the device may include: a processor 1010, a memory 1020, an input / output interface 1030, a communication interface 1040, and a bus 1050. The processor 1010, the memory 1020, the input / output interface 1030, and the communication interface 1040 are connected to each other through the bus 1050 in the device.

[0138] The processor 1010 can be implemented by a general-purpose CPU (Central Processing Unit), a microprocessor, an application-specific integrated circuit (ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of this specification. The processor implements the above method by running executable instructions.

[0139] The memory 1020 for storing processor executable instructions can be implemented in the form of ROM (Read Only Memory), RAM (Random Access Memory), static storage device, dynamic storage device, etc. The memory 1020 can store an operating system and other application programs. When the technical solutions provided in the embodiments of this specification are implemented by software or firmware, the relevant program codes are stored in the memory 1020.

[0140] The input / output interface 1030 is used to connect the input / output module to realize information input and output. The input / output module can be configured in the device as a component (not shown in the figure), or it can be externally connected to the device to provide corresponding functions. The input device may include a keyboard, a mouse, a touch screen, a microphone, various sensors, etc., and the output device may include a display, a speaker, a vibrator, an indicator light, etc.

[0141] The communication interface 1040 is used to connect a communication module (not shown) to realize communication interaction between the device and other devices. The communication module can realize communication through a wired mode (such as USB, network cable, etc.) or a wireless mode (such as mobile network, WIFI, Bluetooth, etc.).

[0142] The bus 1050 includes a path that transmits information between the various components of the device (eg, the processor 1010, the memory 1020, the input / output interface 1030, and the communication interface 1040).

[0143] It should be noted that, although the above device only shows the processor 1010, the memory 1020, the input / output interface 1030, the communication interface 1040 and the bus 1050, in the specific implementation process, the device may also include other components necessary for normal operation. In addition, it can be understood by those skilled in the art that the above device may also only include the components necessary for implementing the embodiments of the present specification, and does not necessarily include all the components shown in the figure.

[0144] The embodiments of the present specification also provide a computer program product, which implements the above-mentioned multi-scalar multiplication calculation method when executed by a processor.

[0145] The embodiments of the present specification also provide a computer-readable storage medium on which a computer program is stored. When the program is executed by a processor, the above-mentioned multi-scalar multiplication calculation method is implemented.

[0146] Computer readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include temporary computer readable media (transitory media), such as modulated data signals and carrier waves.

[0147] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.

[0148] The above is a description of a specific embodiment of the specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.

[0149] The user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of relevant countries and regions, and provide corresponding operation entrances for users to choose to authorize or refuse.

Claims

1. A multi-scalar multiplication calculation method, applied to a target GPU, the target GPU includes a target global memory and is deployed with a plurality of thread blocks, the multi-scalar multiplication involves a one-to-one bitwise multiplication of elements in a point sequence and a scalar sequence, the point sequence is divided into a plurality of subsequences and assigned to the plurality of thread blocks; the method comprises: Any first thread block determines the buckets into which each point in the allocated first subsequence falls, and for each bucket, determines the sum of the number of points falling into the bucket, and stores the sum in the first counter of the bucket; wherein the bucket into which any target point falls corresponds to the scalar value of the target scalar to be bitwise multiplied with the target point; Each thread block aggregates counters of buckets corresponding to the same scalar value based on a distributed shared memory mechanism to obtain a global offset of each bucket in each thread block in the target global memory; Each thread block stores the point sequence in the target global memory according to the global offset of each bucket, so as to perform bucket-based computing operations.

2. The method according to claim 1, wherein: The thread blocks aggregate counters of buckets corresponding to the same scalar value based on the distributed shared memory mechanism to obtain the global offset of each bucket in each thread block in the target global memory, including: The first thread block sets a global shared section in the first shared memory that other thread blocks have the right to access, and stores a first counter corresponding to each bucket therein; By running the parallel prefix sum function in the global shared section of each thread block as a whole, the counter accumulation value of each bucket is obtained, thereby obtaining the global offset of each bucket in each thread block in the target global memory.

3. The method according to claim 1, wherein: The arbitrary first thread block determines, for the allocated first subsequence, the buckets into which each point falls respectively; and for each bucket, determines the sum of the number of points falling into the bucket as the size of the first counter of the bucket, including: Any first thread block executes, for each point in the first subsequence: According to the scalar value of the scalar corresponding to the point, determine the bucket into which the point falls, and store the identifier of the bucket into which the point falls in a register; Through a local atomic operation in the first thread block, a first counter of the bucket into which the point falls is incremented.

4. The method according to claim 1, wherein: Before each thread block stores the point sequence in the target global memory according to the global offset of each bucket, the method further includes: Any first thread block executes: Aggregating first counters of different buckets in the first thread block according to a parallel prefix sum function to obtain a first offset of each bucket in a first shared memory corresponding to the first thread block; Points in the first subsequence are stored in the first shared memory according to the first offset.

5. The method according to claim 4, wherein: Each thread block stores the point sequence in the target global memory according to the global offset of each bucket, including: Any first thread block executes for each bucket: Taking out the first point set falling into the bucket from the first shared memory; According to the global offset of the bucket, the first point set is stored in the target global memory.

6. The method according to claim 1, wherein: The points in the point sequence are points in an elliptic curve; and the bucket-based calculation operation includes: For a first bucket corresponding to a first scalar value, calculate an elliptic curve addition operation result for all points falling into the first bucket, and calculate an elliptic curve multiplication operation result of the first scalar value and the addition operation result; Perform elliptic curve addition on the multiplication results corresponding to each bucket to obtain the multi-scalar multiplication results in the target GPU.

7. The method according to claim 1, wherein: The target GPU is deployed in a GPU cluster, the scalar sequence is a sequence consisting of substrings of a preset range intercepted from a binary string of each scalar in the total scalar sequence, and different GPUs in the GPU cluster are responsible for scalar sequences corresponding to different interception ranges; The method further comprises: According to the bucket-based calculation operation results of each GPU, the multi-scalar multiplication results of the total scalar sequence and the point sequence are determined.

8. A multi-scalar multiplication computing device, applied to a target GPU, the target GPU comprising a target global memory and deployed with a plurality of thread blocks, the multi-scalar multiplication involving a one-to-one bitwise multiplication of elements in a point sequence and a scalar sequence, the point sequence being divided into a plurality of subsequences assigned to the plurality of thread blocks; the device comprising: A bucketing module is used for any first thread block to determine the buckets into which each point falls for the allocated first subsequence, and for each bucket, to determine the sum of the number of points falling into the bucket, and store the sum in a first counter of the bucket; wherein the bucket into which any target point falls corresponds to the scalar value of the target scalar to be bitwise multiplied with the target point; An offset calculation module is used for each thread block to aggregate the counters of buckets corresponding to the same scalar value based on a distributed shared memory mechanism to obtain a global offset of each bucket in each thread block in the target global memory; A storage module is used for each thread block to store the point sequence in the target global memory according to the global offset of each bucket, so as to perform bucket-based computing operations.

9. A computer program product, wherein when the computer program product is executed by a processor, the method according to any one of claims 1 to 8 is implemented.

10. A computer device comprising: processor; a memory for storing processor-executable instructions; The processor implements the method according to any one of claims 1 to 8 by running the executable instructions.

Citation Information

Patent Citations

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

    CN118157872A

  • CUDA (Compute Unified Device Architecture)-based elliptic curve multi-scalar multiplication acceleration method and system and storage medium

    CN118312135A

  • Universal zk-SNARK zero-knowledge proof optimization system and method

    CN119070995A

  • Multi-scalar multiplication implementation method and apparatus, terminal, and storage medium

    WO2024243897A1