A processing method and device for a point multiplication task
By having the image processor process the dot product task in parallel and transmit the results asynchronously under the control of the central processing unit, the problem of low efficiency in dot product operation of elliptic curve algorithm is solved, the computing performance and parallelism are improved, and the processing time is reduced.
Patent Information
- Application Number
- CN202111537606.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-15
- Publication Date
- 2026-02-17
- Estimated Expiration
- 2041-12-15
AI Technical Summary
Existing elliptic curve algorithms suffer from poor parallelism, high complexity, and long execution time in dot product operations, leading to wasted computational performance and low efficiency in image processors.
When the number of dot product tasks to be processed reaches a threshold, the central processing unit (CPU) distributes them to the image processor for parallel processing. By combining multi-threading and asynchronous transmission mechanisms, memory usage is optimized, and the computational efficiency and parallelism of the image processor are improved.
This approach improves the computational performance of the image processor, reduces processing time, increases the efficiency and parallelism of dot product tasks, and reduces memory management overhead.
Smart Images

Figure CN114253719B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the field of Fintech, and in particular to a processing method and device for point multiplication tasks. BACKGROUND
[0002] With the development of computer technology, more and more technologies (for example: blockchain, cloud computing or big data) are applied in the financial field, and the traditional financial industry is gradually changing to Fintech, and big data technology is no exception. However, due to the security and real-time requirements of the financial and payment industries, higher requirements are also put forward for cryptography in big data technology.
[0003] As the cornerstone of the blockchain system, the elliptic curve algorithm plays an important role; such as the private key, public key and digital signature in the blockchain system are realized through elliptic curve cryptography. The elliptic curve algorithm refers to an asymmetric encryption algorithm designed based on elliptic curve mathematics. In the elliptic curve algorithm, the elliptic curve point multiplication operation is an important component of elliptic curve cryptography.
[0004] However, the point multiplication operation of the elliptic curve algorithm in the prior art has poor parallelism, high complexity and long execution time. SUMMARY
[0005] The embodiments of the present application provide a processing method and device for point multiplication tasks, which are used for implementation.
[0006] In a first aspect, the embodiments of the present application provide a processing method for point multiplication tasks, comprising:
[0007] When the central processing unit (CPU) determines that the number of point multiplication tasks to be processed is not less than a first threshold value, the CPU determines the task processing strategy of each graphics processing unit (GPU); the task processing strategy includes the point multiplication tasks processed in parallel by each GPU and the number of threads in each GPU processing the same point multiplication task; the point multiplication task is an elliptic curve point multiplication operation;
[0008] The CPU distributes the point multiplication tasks to be processed to each GPU according to the task processing strategy of each GPU;
[0009] For any GPU, the GPU processes each point multiplication task according to the corresponding task processing strategy and asynchronously transmits the processing result to the CPU.
[0010] In the technical solution, the central processor is distributed to the image processor when the number of point multiplication tasks to be processed is determined to be no less than a first threshold, so that the image processor GPU is prevented from being frequently called when there is only one or a small number of point multiplication tasks, the computing performance of the image processor is prevented from being wasted, and the computing efficiency of the image processor is improved; the parallel degree of determining a processing result is improved by executing the point multiplication tasks in parallel through a plurality of GPUs; further, in any GPU, any point multiplication task is executed through multi-threading, so that the efficiency of determining the processing result is improved, and the time consumption of determining the processing result is reduced; in addition, the processing results of the GPUs are transmitted to the CPU asynchronously, so that the time of the CPU waiting for the processing results can be reduced.
[0011] Optionally, the CPU distributes the point multiplication tasks to be processed to the GPUs according to the task processing strategies of the GPUs, and the distributing includes:
[0012] The CPU stores the point multiplication tasks to be processed in a task array.
[0013] The point multiplication tasks in the task array are transmitted to the memory space of each GPU asynchronously according to the task processing strategies of the GPUs; and the memory space of each GPU is a part of a GPU memory pool.
[0014] In the technical solution, the CPU stores the point multiplication tasks to be processed in a task array, so that the plurality of point multiplication tasks to be processed are distributed to the image processor, and the image processor GPU is prevented from being frequently called, and the computing efficiency of the GPU is improved.
[0015] Optionally, after the processing result is transmitted to the CPU asynchronously, the method further includes:
[0016] The CPU sets an overwrite mark for the point multiplication task corresponding to the processing result in the memory space of the corresponding GPU; and the overwrite mark is used to indicate that the data recorded in the memory space is allowed to be overwritten.
[0017] In the technical solution, the memory space is set with an overwrite mark, so that the memory space can be reused without being released, the reusability of the memory space is improved, the requirement for releasing data is reduced, and the computing performance of the CPU is improved.
[0018] Optionally, the task processing strategies of the GPUs are determined, and the determining includes:
[0019] The CPU determines that the number of threads processing the same point multiplication task in each GPU is b.
[0020] The CPU determines the point multiplication task processed by each GPU according to the number g of the GPUs and the number m of the point multiplication tasks to be processed.
[0021] The CPU determines the number of thread groups required by each GPU when processing the corresponding point multiplication task according to m, b, g, and the number w of threads in the thread group.
[0022] In the technical solution, the thread group required by the point multiplication task to be processed is determined, and the point multiplication task to be processed is processed by multiple threads, thereby improving the efficiency of determining the processing result and reducing the time consumption of determining the processing result.
[0023] Optionally, the GPU processes each point multiplication task according to a corresponding task processing strategy, including: when the GPU determines that the point multiplication task is an unknown point multiplication, the GPU converts a first parameter in the input parameter of the point multiplication task into a second parameter; the first parameter is in binary form; the second parameter is in NAF form; and the second parameter is stored in a memory space that can be shared and read and written by threads in the same thread group.
[0024] The GPU processes the second parameter of the same point multiplication task by multiple threads in each thread group according to a corresponding task processing strategy.
[0025] In the technical solution, the second parameter in NAF form is stored in a memory space that can be shared and read and written by threads in the same thread group, the point multiplication task to be processed is processed by multiple threads, thereby improving the efficiency of determining the processing result and reducing the time consumption of determining the processing result.
[0026] Optionally, the GPU processes each point multiplication task according to a corresponding task processing strategy, including:
[0027] When the GPU determines that the point multiplication task is a fixed point multiplication, if it is determined that the value of the jth bit of the first parameter in the input parameter of the point multiplication task is 1, the GPU obtains the intermediate result of the jth bit in a precomputed table, adds the intermediate result of the jth bit and the (j+1)th bit result to obtain the jth bit result; the precomputed table is stored in the memory space of the GPU; and the precomputed table records the intermediate results corresponding to the first parameter when the 0th bit to the 255th bit of the first parameter is 1.
[0028] When the GPU determines that the value of the jth bit of the first parameter is 0, the (j+1)th bit result is taken as the jth bit result, and the values of the bits of the first parameter are iterated until the iteration is completed.
[0029] Optionally, the precomputed table is stored in the constant memory of the GPU, and the constant memory is initialized by the CPU and can be read by each thread in the GPU.
[0030] In the technical solution, the precomputed table is stored in the constant memory of the GPU, which improves the speed of accessing the precomputed table by the GPU threads and improves the calculation speed of the fixed point multiplication task.
[0031] In a second aspect, an embodiment of the present application provides a processing device for a point multiplication task, comprising:
[0032] a distribution module configured to determine a task processing strategy of each GPU when the number of the point multiplication tasks to be processed is not less than a first threshold value, wherein the task processing strategy comprises a number of the point multiplication tasks processed in parallel by each GPU and a number of threads in each GPU processing the same point multiplication task, and the point multiplication task is an elliptic curve point multiplication operation;
[0033] distribute the point multiplication tasks to be processed to each GPU according to the task processing strategy of each GPU;
[0034] a processing module configured to process each point multiplication task according to the corresponding task processing strategy and transmit the processing result to the CPU asynchronously.
[0035] Optionally, the distribution module is specifically configured to:
[0036] store the point multiplication tasks to be processed in a task array;
[0037] transmit the point multiplication tasks in the task array to the memory space of each GPU asynchronously according to the task processing strategy of each GPU, wherein the memory space of each GPU is a part of a GPU memory pool.
[0038] Optionally, the processing module is further configured to:
[0039] after transmitting the processing result to the CPU asynchronously, set an overlay mark in the memory space of the corresponding GPU for the point multiplication task corresponding to the processing result, wherein the overlay mark is used to indicate that the data recorded in the memory space is allowed to be overwritten.
[0040] Optionally, the distribution module is specifically configured to:
[0041] determine the number of threads in each GPU processing the same point multiplication task as b;
[0042] determine the point multiplication task processed by each GPU according to the number g of GPUs and the number m of the point multiplication tasks to be processed;
[0043] determine the number of thread groups required by each GPU when processing the corresponding point multiplication task according to m, b, g and the number w of threads in a thread group.
[0044] Optionally, the processing module is specifically configured to:
[0045] In a case where the point multiplication task is determined to be an unknown point multiplication, a first parameter in input parameters of the point multiplication task is converted into a second parameter; the first parameter is in a binary form; the second parameter is in a NAF form; and the second parameter is stored in a memory space that can be shared for reading and writing by threads in a same thread group.
[0046] According to a corresponding task processing strategy, the multiple threads in each thread group process the second parameters of the same point multiplication task.
[0047] Optionally, the processing module is specifically configured to:
[0048] In a case where the point multiplication task is determined to be a fixed point multiplication, in a case where a value of a jth bit of the first parameter in the input parameters of the point multiplication task is determined to be 1, a jth bit intermediate result is obtained from a pre-computed table, the jth bit intermediate result is added to a (j+1)th bit result to obtain a jth bit result; the pre-computed table is stored in a memory space of the GPU; and the pre-computed table records the intermediate results corresponding to the first parameter with the 0th bit to the 255th bit being 1.
[0049] In a case where the value of the jth bit of the first parameter is determined to be 0, the (j+1)th bit result is taken as the jth bit result, until the values of the bits of the first parameter are traversed.
[0050] Optionally, the pre-computed table is stored in a constant memory of the GPU, the constant memory is initialized by the CPU and can be read by the threads in the GPU.
[0051] In a third aspect, an embodiment of the present application further provides a computer device, comprising:
[0052] a memory configured to store program instructions;
[0053] a processor configured to invoke the program instructions stored in the memory, and perform the processing method for the point multiplication task according to the obtained program.
[0054] In a fourth aspect, an embodiment of the present application further provides a computer readable storage medium, the computer readable storage medium stores computer executable instructions, and the computer executable instructions are used to make a computer execute the processing method for the point multiplication task. BRIEF DESCRIPTION OF DRAWINGS
[0055] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following will briefly introduce the drawings needed to be used in the embodiment description. Obviously, the drawings in the following description are only some embodiments of the present application, and other drawings can also be obtained by those skilled in the art without any creative effort based on these drawings.
[0056] Figure 1 A system architecture schematic diagram is provided for an embodiment of the present application.
[0057] Figure 2 A flowchart of a processing method for a dot multiplication task is provided for an embodiment of the present application.
[0058] Figure 3 A structure schematic diagram of a processing device for a dot multiplication task is provided for an embodiment of the present application. DETAILED DESCRIPTION
[0059] In order to make the objects, technical solutions and advantages of the present application clearer, the present application will be further described in detail below with reference to the drawings. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative work fall within the scope of protection of the present application.
[0060] In order to better illustrate the technical solutions of the present application, the following explains the possible terms.
[0061] CPU (central processing unit, central processor): as the operation and control core of the computer system, it is the final execution unit of information processing and program running.
[0062] GPU (Graphics Processing Unit, graphics processing unit): a kind of processor for executing drawing operation. GPU has the characteristics of very high parallelism, such as thousands of cores in Nvidia GPU. This feature makes GPU be widely used in general computing tasks, and can achieve several orders of magnitude faster computing speed than CPU.
[0063] At the hardware level of the parallel level of GPU, GPU contains dozens of SM (streaming multiprocessor), each SM has hundreds of cores, and one core corresponds to one thread. GPU adopts the parallel model of SIMT (Single Instruction Multiple Thread), that is, multiple threads are organized into a warp for scheduling, and threads in the same warp can only execute the same instruction. At the software level, the program executed on GPU is called kernel, each kernel corresponds to a group of thread grid, each grid contains multiple thread block groups, and each block group contains multiple threads.
[0064] In the memory hierarchy of a GPU, a GPU has a global memory (very large memory) with a capacity of tens of GB, which can be read and written by all threads, but the access speed is slow and the delay is high; all threads can also access a constant memory (constant memory) with a capacity of only tens of KB, which cannot be modified after initialization, but the reading speed is fast and the access delay is low. In addition, threads in the same block group share a shared memory with fast read and write speed, but the capacity is only tens of KB. A block cannot access the shared memory of other blocks.
[0065] Elliptic curve cryptography: refers to a class of asymmetric encryption algorithms designed based on elliptic curve mathematics. In elliptic curve cryptography, an elliptic curve is usually defined by four parameters p, E, G, n; wherein the parameter p is a prime number, and according to p, a prime field F p , that is, a set of natural numbers from 0 to p-1 can be defined. All operations in the prime field need to be taken modulo p; the parameter E represents the elliptic curve equation y 2 =x 3 +ax+b, wherein a and b are fixed parameters, and x and y are variables, x and y satisfying the equation represent points (x, y) on the elliptic curve, and the elliptic curve is defined on the prime field F p , that is, a, b, x, and y are all elements in the prime field F p ; the parameter G is the base point (x G , y G ) of the elliptic curve, and the points on the elliptic curve in the prime field F p form a cyclic group, and the base point G is the generating element of the cyclic group; the parameter n represents the order, that is, the number of elements in the cyclic group, and n is a prime number.
[0066] In elliptic curve cryptography, common operations on points on an elliptic curve include negation operation, point addition operation, point multiplication operation, etc.; the specific description is as follows.
[0067] Negation operation: given a point P(x P , y P ), taking the negative of point P is equivalent to taking the negative of the value of y coordinate, that is, -P=(x P , -y P ).
[0068] Point addition operation: given a point P(x P , y P ) and a point Q(x Q , y Q ), let R(x R , y R) represents the result of P and Q added together, that is, R=P+Q; the specific calculation method is to first calculate the slope of PQ, that is, λ=(y P -y Q ) / (x P -x Q ), and then x R =λ 2 -x P -x Q , y R =λ(x P -x R )-y P .
[0069] Doubling operation: given a point P(x P , y P ), let S(x S , y S ) represent the doubling point of P, that is, S=2P.
[0070] Point multiplication operation: in elliptic curve cryptography, the point multiplication operation generally refers to scalar multiplication, that is, given a point P(x P , y P ) and a natural number k, the point multiplication kP is the operation of adding k P, wherein, according to whether the point to be multiplied P is known, the point multiplication operation can be classified into unknown point multiplication and fixed point multiplication; the unknown point multiplication refers to that the point to be multiplied P is an arbitrary point on the elliptic curve, and a general algorithm needs to be used for calculation; and the fixed point multiplication refers to that the point P is a determined parameter (such as the base point G of the elliptic curve), and when the fixed point multiplication is calculated, the calculation overhead can be reduced by storing part of the calculation intermediate results to a lookup table in advance.
[0071] Currently, the commonly used elliptic curve (such as secp256r1 curve, SM2 curve, etc.) uses a key length of 256-bit binary string, so the present application takes the elliptic curve key length of 256 bits as an example, but this is not limited.
[0072] In the prior art, the processing result of the point multiplication task is generally determined by continuously doubling the point to be multiplied P to determine a plurality of intermediate results (such as P, 2P, 4P, …, 2 255 P), and then selecting part of the intermediate results to obtain the processing result k*P. The specific process is as follows.
[0073] S11, given a point to be multiplied P(xP, yP) and a natural number k, and an initial point R(xR, yR) is set as the processing result of the point multiplication task, wherein the initial point R takes the value of 0 in the initial state;
[0074] S12, taking the last bit of k as the 256th bit and the first bit of k as the 1st bit, traversing from the 256th bit of k, determining a processing result R; first judging the value of the i-th bit, if the value of the i-th bit is 1, executing step S13; if the value of the i-th bit is 0, executing step S14;
[0075] S13, adding the to-be-multiplied point P i+1 and the point R i+1 , obtaining P i , and i = 256, P i+1 is the initial state, then executing step S14;
[0076] S14, doubling the point R i+1 , that is, performing a point doubling operation, obtaining R i , and i = 256, R i+1 is the initial state, then returning to step S12; until the values of the 256 bits of k are all traversed.
[0077] In the above method, the point multiplication task is sent to the GPU by the CPU, at present, the point multiplication task is processed in parallel by a GPU through multi-threading, wherein one thread corresponds to processing one point multiplication task, which leads to occupying a large number of registers and memory spaces of the GPU, leading to resource competition among the threads of the GPU, low processing efficiency, and long time consumption for determining the processing result; and frequently, multiple batches of point multiplication tasks arrive in succession, the CPU needs to call the GPU function multiple times for processing, leading to frequent calling of the GPU function, repeatedly allocating and releasing the memory of the GPU end, causing high memory management overhead, at the same time, when the number of point multiplication tasks transmitted each time the GPU function is called is too small, the computing performance of the GPU cannot be fully exerted, and the GPU computing efficiency is not high; in addition, the intermediate result memory required by the fixed point multiplication point multiplication task is too large and is stored in the non-constant memory, so that the access speed of the GPU thread is slow and the time consumption for determining the processing result is long.
[0078] Therefore, there is an urgent need for a processing method for point multiplication tasks to avoid waste of the computing performance of the image processor, improve the computing efficiency of the image processor, improve the parallelism of determining the processing result, improve the efficiency of determining the processing result, and reduce the time consumption of determining the processing result.
[0079] Figure 1 An exemplary system architecture to which the embodiment of the application is applicable is shown, which includes a central processing unit CPU 110 and an image processor GPU 120.
[0080] The CPU 110 is configured to store the point multiplication tasks to be processed into a task array, and determine the number of point multiplication tasks to be processed; when determining that the number of point multiplication tasks to be processed is not less than a first threshold, determine the task processing strategy of each GPU 120 according to the number of GPUs 120, and distribute the task processing strategy of the GPU 120 to each GPU 120.
[0081] Any GPU 120 is configured to determine the processing result of the point multiplication task using multi-threading according to the type of the point multiplication task, and return the processing result to the CPU 110 asynchronously; wherein the number of GPUs 120 can be multiple, and 'N' is the number of GPUs 120, which is not specifically limited herein.
[0082] It should be noted that the structure shown in the above Figure 1 is only an example, and the embodiments of the present application are not limited thereto.
[0083] Based on the above description, Figure 2 an exemplary flowchart of a processing method for point multiplication tasks provided by the embodiments of the present application is shown, which can be executed by a processing device for point multiplication tasks.
[0084] As Figure 2 shown, the flow specifically includes:
[0085] In step 210, when the central processing unit CPU determines that the number of point multiplication tasks to be processed is not less than a first threshold, the task processing strategy of each image processing unit GPU is determined.
[0086] In the embodiments of the present application, the task processing strategy includes the point multiplication tasks processed in parallel by each image processing unit GPU and the number of threads processing the same point multiplication task in each GPU; the point multiplication task is an elliptic curve point multiplication operation.
[0087] In step 220, the CPU distributes the point multiplication tasks to be processed to each GPU according to the task processing strategy of each GPU.
[0088] In the embodiments of the present application, the point multiplication tasks to be processed are distributed to each GPU according to the number of GPUs, the preset order and the task processing strategy of each GPU.
[0089] In step 230, for any GPU, the GPU processes each point multiplication task according to the corresponding task processing strategy, and transmits the processing result to the CPU asynchronously.
[0090] In the embodiments of the present application, the point multiplication task includes unknown point multiplication and fixed point multiplication, and the GPU adopts a corresponding processing method for different types of point multiplication tasks to obtain the processing result.
[0091] In step 210, in order to avoid the number of point multiplication tasks output to the GPU being small, the CPU calculates the number of point multiplication tasks when obtaining the point multiplication tasks, and determines the task processing strategy of each image processor GPU until the number of point multiplication tasks is greater than a first threshold.
[0092] For example, the first threshold is 10, and the CPU judges that the number of received point multiplication tasks is 5, and then does not process the 5 point multiplication tasks. If the CPU obtains 7 point multiplication tasks again, at this time the number of point multiplication tasks stored in the CPU is 12, which is greater than 10, and then the task processing strategy of each image processor GPU is determined according to the 12 point multiplication tasks.
[0093] Further, the CPU determines the number of threads in each GPU processing the same point multiplication task as b; the CPU determines the number of point multiplication tasks processed by each GPU according to the number of GPUs g and the number of point multiplication tasks to be processed m; the CPU determines the number of thread groups required by each GPU when processing the corresponding point multiplication task according to m, b, g and the number of threads in a thread group w; wherein w is the number of threads in a thread block group.
[0094] Based on the above example, the number of point multiplication tasks to be processed m is 12, and assuming that the number of GPUs g is 4, then the number of point multiplication tasks processed by each GPU is determined to be 3.
[0095] In an implementable manner, the CPU determines the point multiplication tasks processed by each GPU in turn; for example, the point multiplication tasks to be processed are m1, m2, …, m12, and the GPUs are g1, g2, g3 and g4 respectively, then the point multiplication task m1 is determined as the point multiplication task processed by the GPU g1, the point multiplication task m2 is determined as the point multiplication task processed by the GPU g2, and so on, and the point multiplication tasks processed by the GPU g1 are determined to be m1, m5 and m9; the point multiplication tasks processed by the GPU g2 are determined to be m2, m6 and m10; the point multiplication tasks processed by the GPU g3 are determined to be m3, m7 and m11; and the point multiplication tasks processed by the GPU g4 are determined to be m4, m8 and m12.
[0096] In another implementable manner, the CPU directly determines the point multiplication tasks processed by each GPU; for example, the point multiplication tasks to be processed are m1, m2, …, m12, and the GPUs are g1, g2, g3 and g4 respectively, and the number of point multiplication tasks processed by each GPU is determined to be 3, then the point multiplication tasks m1, m2 and m3 are determined as the point multiplication tasks processed by the GPU g1; then the point multiplication tasks m4, m5 and m6 are determined as the point multiplication tasks processed by the GPU g2; then the point multiplication tasks m7, m8 and m9 are determined as the point multiplication tasks processed by the GPU g3; and then the point multiplication tasks m10, m11 and m12 are determined as the point multiplication tasks processed by the GPU g4.
[0097] After the CPU determines the point multiplication tasks processed by each GPU, the CPU determines the number of thread groups required by each GPU when processing the corresponding point multiplication task according to the following formula (1).
[0098] L = (b*m) / (w*g) (1);
[0099] In the formula, L is the number of thread groups required by the GPU when processing the corresponding point multiplication task; b is the number of threads in the GPU processing the same point multiplication task (for example, 5 threads are required for the GPU g1 to process the point multiplication task m1) ; m is the number of point multiplication tasks to be processed; w is the number of threads in a thread group; and g is the number of GPUs.
[0100] In step 220, after the CPU determines the task processing strategy of each GPU, the CPU distributes the task processing strategy to each GPU; specifically, the CPU stores the point multiplication tasks to be processed in a task array; and the point multiplication tasks in the task array are transmitted to the memory space of each GPU asynchronously according to the task processing strategy of each GPU; wherein the memory space of each GPU is a part of the GPU memory pool.
[0101] Based on the above example, when the CPU determines that the point multiplication tasks processed by the GPU g1 are m1, m5 and m9, the CPU sends the point multiplication tasks m1, m5 and m9 to the memory space of the GPU g1.
[0102] In an implementable manner, the memory space of the GPU is pre-provided with an overwrite mark to indicate that the data recorded in the memory space is allowed to be overwritten.
[0103] In the embodiment of the application, after the GPU determines the processing result of the point multiplication task and transmits the processing result to the CPU, the corresponding point multiplication task is provided with an overwrite mark in the memory space of the corresponding GPU; the overwrite mark is used to indicate that the data recorded in the memory space is allowed to be overwritten.
[0104] Based on the above example, the GPU g1 processes the point multiplication tasks m1, m5 and m9, and after obtaining the processing result corresponding to the point multiplication tasks m1, m5 and m9 and transmitting the processing result to the CPU, the memory space is provided with an overwrite mark, so that when the GPU g1 processes the next batch of point multiplication tasks, the data generated by processing the next batch of point multiplication tasks is used to overwrite the data generated by processing the point multiplication tasks m1, m5 and m9, so as to realize that the data generated by processing the point multiplication tasks m1, m5 and m9 does not need to be released, the reusability of the memory space is improved, the requirement for releasing the data is reduced, and the computing performance of the CPU is improved.
[0105] In step 230, the types of point multiplication tasks include fixed point multiplication and unknown point multiplication, and different processing methods are used for different types of point multiplication tasks.
[0106] Exemplarily, when the point multiplication task is an unknown point multiplication, a first parameter in input parameters of the point multiplication task is converted into a second parameter; the first parameter is in binary form; the second parameter is in NAF form; the second parameter is stored in a memory space which can be shared for reading and writing by threads in a same thread group; and the GPU processes the second parameter of the same point multiplication task by a corresponding task processing strategy.
[0107] Further, when the point multiplication task is an unknown point multiplication, the point multiplication task includes a first parameter in binary form and a point to be multiplied; the GPU converts the first parameter in binary form into a second parameter in NAF form; the first bit of the second parameter is the first bit, and the last bit value of the second parameter is traversed; the processing result of the i+1th bit of the second parameter is doubled, and if it is determined that the value of the ith bit of the second parameter is 1, the processing result of the i+1th bit after doubling is added to the point to be multiplied to obtain the processing result of the ith bit; when i is the last bit of the second parameter, the processing result of the i+1th bit is the initial value, i.e., 0;
[0108] If it is determined that the value of the ith bit of the second parameter is -1, the processing result of the i+1th bit after doubling is subtracted from the point to be multiplied to obtain the processing result of the ith bit;
[0109] If it is determined that the value of the ith bit of the second parameter is 0, the processing result of the i+1th bit after doubling is taken as the processing result of the ith bit; the processing result of the i-1th bit of the second parameter is determined until the traversal of each bit of the second parameter is completed, and the processing result of the first bit is determined as the processing result of the point multiplication task of the unknown point multiplication.
[0110] For example, when i=3, R4 is first subjected to a doubling point operation, if the value of the third bit of the second parameter is 1, then R4 is added to the point to be multiplied P to obtain R3; wherein R4 is the processing result of the fourth bit, and R3 is the processing result of the third bit;
[0111] R4 is first subjected to a doubling point operation, if the value of the third bit of the second parameter is -1, then R4 is subtracted from the point to be multiplied P, i.e., the point to be multiplied P is taken as a negative value and then added to R4 to obtain R3;
[0112] R4 is first subjected to a doubling point operation, if the value of the third bit of the second parameter is 0, then the doubled R4 is taken as R3; i.e., R3=2R4.
[0113] In the embodiment of the present application, the second parameter is stored in the memory space shared by reading and writing, and can be read and written by multiple threads, so that the point multiplication task can be processed by multiple threads; for example, the first 100 bits of the second parameter are processed by thread 1, and the parameters after the 100th bit of the second parameter are processed by thread 2; for another example, the value of any bit of the second parameter is processed by thread 1 for multiplication operation, by thread 2 for addition operation, and by thread 3 for subtraction operation, and the present application does not make specific limitation on the multiple threads processing a point multiplication task.
[0114] wherein the second parameter is determined by traversing each bit of the first parameter; specifically, if the GPU determines that the value of the last bit of the first parameter is 1, the last bit of the first parameter is removed to obtain the third parameter;
[0115] if the GPU determines that the value of the last bit of the third parameter is 1, the last bit of the second parameter is set to -1, and the third parameter is incremented by 1 to obtain the fourth parameter, and the fourth parameter is taken as the first parameter;
[0116] if the GPU determines that the value of the last bit of the third parameter is 0, the last bit of the second parameter is set to 1, and the third parameter is taken as the first parameter;
[0117] if the GPU determines that the value of the last bit of the first parameter is 0, the last bit of the second parameter is set to 0, and the last bit of the first parameter is removed to determine the next bit of the first parameter; until the values of all bits of the first parameter are traversed, the second parameter is determined.
[0118] For example, the process is as follows.
[0119] S21, the first parameter is “***101”, and when it is determined that the last bit (“1”) of the first parameter is 1, the last bit of the first parameter is removed to obtain the third parameter (“***10”);
[0120] S22, it is determined whether the value of the last bit of the third parameter is 1, if yes, step S23 is executed, otherwise step S24 is executed;
[0121] S23, assuming that the value of the last bit of the third parameter is 1 (for example, the third parameter is “***01”), the last bit of the second parameter is set to -1, and the third parameter is incremented by 1 to obtain the fourth parameter (the fourth parameter is “***10”), and the fourth parameter is taken as the first parameter; step S25 is executed;
[0122] S24, the value of the last bit of the third parameter is 1 (for example, the third parameter is “***10”), the last bit of the second parameter is set to 1, and the third parameter is taken as the first parameter; step S25 is executed;
[0123] S25, determining the second-to-last bit value of the second parameter according to the updated first parameter (i.e., the third parameter or the fourth parameter).
[0124] For example, when the point multiplication task is fixed point multiplication, if it is determined that the value of the jth bit of the first parameter in the input parameter of the point multiplication task is 1, the jth intermediate result is obtained from the pre-computation table, the jth intermediate result is added to the (j+1)th result to obtain the jth result; the pre-computation table is stored in the memory space of the GPU; the pre-computation table records the intermediate results corresponding to the first parameter being 1 at the 0th bit to the 255th bit; when it is determined that the value of the jth bit of the first parameter is 0, the (j+1)th result is taken as the jth result, until the values of the bits of the first parameter are traversed.
[0125] Further, when the point multiplication task is fixed point multiplication, the point multiplication task includes a first parameter in binary form; the GPU is preset with a fixed point to be multiplied (such as a base point of an elliptic curve), and the first bit of the first parameter is taken as the 1st bit, and the value of the last bit (i.e., the 256th bit) of the first parameter is traversed.
[0126] If the GPU determines that the value of the jth bit of the first parameter is 1, the jth intermediate result is obtained from the pre-computation table, and the jth intermediate result is added to the processing result of the (j+1)th bit to obtain the processing result of the jth bit; when j is the last bit of the first parameter, the processing result of the (j+1)th bit is the initial value, i.e., 0;
[0127] If the GPU determines that the value of the jth bit of the first parameter is 0, the processing result of the (j+1)th bit is taken as the processing result of the jth bit, until the values of the bits of the first parameter are traversed, and the processing result of the 1st bit is determined as the processing result of the point multiplication task of the fixed point multiplication.
[0128] The pre-computation table records the intermediate results of the 0th bit to the 255th bit of the first parameter; each intermediate result is determined according to the fixed point to be multiplied; for example, the fixed point to be multiplied is the base point Q of the elliptic curve, and each intermediate result includes 2 0 Q, 2 1 Q, …, 2 255 Q, i.e., the pre-computation table records 2 0 Q, 2 1 Q, …, 2 255 Q.
[0129] It should be noted that the pre-computation table is stored in the constant memory of the GPU (i.e., the constant memory of the GPU), which is initialized by the CPU and can be read by each thread in the GPU.
[0130] In the embodiment of the present application, the parallel architecture is realized by multiple GPUs, any GPU processes the point multiplication task through multi-threading, the computing capability of the GPU is improved, the parallel degree of the GPU for determining the processing result is improved, the efficiency of the GPU for determining the processing result is improved, and the time consumption of the GPU for determining the processing result is reduced; and the computing efficiency of the GPU is improved by determining the processing results of the point multiplication tasks of the unknown point multiplication and the fixed point multiplication by the multiple GPUs.
[0131] Based on the same technical concept, Figure 3 An exemplary structural schematic diagram of a processing device for a point multiplication task provided by the embodiment of the present application is shown, which can execute the flow of the processing method for the point multiplication task.
[0132] As Figure 3 shown, the device specifically includes:
[0133] The distribution module 310 is configured to determine the task processing strategy of each image processor GPU when the number of the point multiplication tasks to be processed is not less than the first threshold value; the task processing strategy includes the point multiplication tasks processed by each image processor GPU in parallel and the number of threads in each GPU processing the same point multiplication task; the point multiplication task is an elliptic curve point multiplication operation;
[0134] According to the task processing strategy of each GPU, the point multiplication tasks to be processed are distributed to each GPU;
[0135] The processing module 320 is configured to process each point multiplication task according to the corresponding task processing strategy, and transmit the processing result to the CPU asynchronously.
[0136] Optionally, the distribution module 310 is specifically configured to:
[0137] store the point multiplication tasks to be processed in a task array;
[0138] According to the task processing strategy of each GPU, the point multiplication tasks in the task array are transmitted to the memory space of each GPU asynchronously; wherein the memory space of each GPU is a part of the GPU memory pool.
[0139] Optionally, the processing module 320 is further configured to:
[0140] After the processing result is transmitted to the CPU asynchronously, the point multiplication task corresponding to the processing result is set with an overlay mark in the memory space of the corresponding GPU; the overlay mark is used to indicate that the data recorded in the memory space is allowed to be covered.
[0141] Optionally, the distribution module 310 is specifically configured to:
[0142] determine the number of threads in each GPU processing the same point multiplication task as b;
[0143] determine the point multiplication task to be processed by each GPU according to the number g of GPUs and the number m of point multiplication tasks to be processed;
[0144] determine the number of thread groups required by each GPU when processing the corresponding point multiplication task according to m, b, g and the number w of threads in a thread group.
[0145] Optionally, the processing module 320 is specifically configured to:
[0146] convert the first parameter in the input parameter of the point multiplication task into a second parameter when determining that the point multiplication task is an unknown point multiplication; the first parameter is in binary form; the second parameter is in NAF form; and the second parameter is stored in a memory space that can be shared for reading and writing by each thread in the same thread group;
[0147] According to the corresponding task processing strategy, the plurality of threads in each thread group process the second parameter of the same point multiplication task.
[0148] Optionally, the processing module 320 is specifically configured to:
[0149] if it is determined that the value of the jth bit of the first parameter in the input parameter of the point multiplication task is 1, obtain the intermediate result of the jth bit in the pre-computed table, add the intermediate result of the jth bit and the (j+1)th bit result to obtain the jth bit result when determining that the point multiplication task is a fixed point multiplication; the pre-computed table is stored in the memory space of the GPU; and the pre-computed table records the intermediate results corresponding to the first parameter when the 0th bit to the 255th bit of the first parameter is 1;
[0150] if it is determined that the value of the jth bit of the first parameter is 0, then the (j+1)th bit result is taken as the jth bit result, until the values of the bits of the first parameter are traversed.
[0151] Optionally, the pre-computed table is stored in the constant memory of the GPU, and the constant memory is initialized by the CPU and can be read by each thread in the GPU.
[0152] Based on the same technical concept, the embodiments of the present application also provide a computer device, comprising:
[0153] a memory for storing program instructions;
[0154] a processor for calling the program instructions stored in the memory and executing the above-mentioned processing method for point multiplication tasks according to the obtained program.
[0155] Based on the same technical concept, the embodiment of the present application also provides a computer readable storage medium, which stores computer executable instructions for causing a computer to execute the processing method for the dot product task.
[0156] Those skilled in the art should understand that the embodiments of the present application can be provided as a method, a system, or a computer program product. Therefore, the present application can take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware aspects. Moreover, the present application can take the form of a computer program product implemented on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROMs, optical storage devices, etc.) containing computer-usable program code.
[0157] The present application is described with reference to the flowcharts and / or block diagrams of the method, device (system), and computer program product according to the present application. It should be understood that each flow and / or block in the flowcharts and / or block diagrams, and the combination of flows and / or blocks in the flowcharts and / or block diagrams can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device produce the functions specified in the flowcharts and / or block diagrams. Figure 1 one or more flows and / or blocks Figure 1 means for carrying out the functions specified in the flow(s) or block(s).
[0158] These computer program instructions can also be stored in a computer readable memory that can direct the computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer readable memory produce a product including an instruction device that implements the functions specified in the flowcharts and / or block diagrams. Figure 1 one or more flows and / or blocks Figure 1 means for carrying out the functions specified in the flow(s) or block(s).
[0159] These computer program instructions can also be loaded into a computer or other programmable data processing device, so that a series of operation steps are executed on the computer or other programmable device to produce a computer-implemented process, so that the instructions executed on the computer or other programmable device provide a process for implementing the functions specified in the flowcharts and / or block diagrams. Figure 1 one or more flows and / or blocks Figure 1 means for carrying out the functions specified in the flow(s) or block(s).
[0160] Obviously, many modifications and variations of the present application are possible in light of the above teachings. It is, therefore, to be understood that within the scope of the appended claims and their equivalents, the application can be practiced otherwise than as specifically described.
Claims
1. A processing method for a point multiplication task, characterized by, The method comprises the following steps: A central processing unit (CPU) determines a number of point multiplication tasks to be processed is not less than a first threshold value, and determines a task processing strategy of each graphics processing unit (GPU); The task processing strategy comprises point multiplication tasks processed by each GPU in parallel and a number of threads in each GPU processing the same point multiplication task; the point multiplication task is an elliptic curve point multiplication operation; The CPU distributes the point multiplication tasks to be processed to each GPU according to the task processing strategy of each GPU; For any GPU, the GPU processes each point multiplication task according to the corresponding task processing strategy and asynchronously transmits the processing result to the CPU; The type of the point multiplication task comprises a fixed point multiplication and an unknown point multiplication; If the GPU determines that the point multiplication task is an unknown point multiplication, the unknown point multiplication comprises a first parameter and a point to be multiplied, the first parameter in the input parameter of the point multiplication task is converted into a second parameter, the first parameter is in binary form; and the second parameter is in NAF form; The second parameter is stored in a memory space that can be read and written by each thread in the same thread group; and according to the corresponding task processing strategy, a plurality of threads in each thread group process the second parameter of the same point multiplication task; If the GPU determines that the point multiplication task is a fixed point multiplication, if the value of the jth bit of the first parameter in the input parameter of the point multiplication task is 1, the jth bit intermediate result is obtained from a precomputed table, the jth bit intermediate result is added to the (j+1)th bit result to obtain the jth bit result; when j is the last bit of the first parameter, the (j+1)th bit result is an initial value, i.e., 0; the precomputed table is stored in the memory space of the GPU; and the precomputed table records the intermediate results corresponding to the first parameter with the 0th bit to the 255th bit being 1; If the value of the jth bit of the first parameter is 0, the (j+1)th bit result is taken as the jth bit result until the values of the bits of the first parameter are traversed, and the 1st bit result is determined as the processing result of the fixed point multiplication task; the precomputed table is stored in the constant memory of the GPU, the constant memory is initialized by the CPU and can be read by each thread in the GPU.
2. The method of claim 1, wherein, The CPU distributes the point multiplication tasks to be processed to each GPU according to the task processing strategy of each GPU, which comprises the following steps: The CPU stores the point multiplication tasks to be processed in a task array; The point multiplication tasks in the task array are asynchronously transmitted to the memory space of each GPU according to the task processing strategy of each GPU; and the memory space of each GPU is a part of a GPU memory pool.
3. The method of claim 2, wherein, After the processing result is asynchronously transmitted to the CPU, the following steps are further included: The CPU sets an overlay mark for the point multiplication task corresponding to the processing result in the memory space of the corresponding GPU; and the overlay mark is used to indicate that the data recorded in the memory space is allowed to be overwritten.
4. The method of claim 1, wherein, The CPU determines the number of threads in each GPU processing the same point multiplication task as b; The CPU determines the point multiplication task processed by each GPU according to the number g of GPUs and the number m of the point multiplication tasks to be processed; The CPU determines the number of thread groups required by each GPU when processing the corresponding point multiplication task according to m, b, g and the number w of threads in a thread group.
5. A processing device for a point multiplication task, characterized by Comprise: The distribution module is configured to determine a task processing strategy of each GPU when the CPU determines that the number of point multiplication tasks to be processed is not less than a first threshold value; The task processing strategy comprises a point multiplication task processed by each GPU in parallel and a number of threads in each GPU processing the same point multiplication task; the point multiplication task is an elliptic curve point multiplication operation; According to the task processing strategy of each GPU, the point multiplication tasks to be processed are distributed to each GPU; The processing module is configured to process each point multiplication task according to the corresponding task processing strategy and transmit the processing result to the CPU asynchronously; The type of the point multiplication task comprises a fixed point multiplication and an unknown point multiplication; If the GPU determines that the point multiplication task is an unknown point multiplication, the unknown point multiplication comprises a first parameter and a point to be multiplied, the first parameter in the input parameter of the point multiplication task is converted into a second parameter, the first parameter is in binary form; the second parameter is in NAF form; The second parameter is stored in a memory space that can be shared and read and written by each thread in the same thread group; according to the corresponding task processing strategy, a plurality of threads in each thread group process the second parameter of the same point multiplication task; If the GPU determines that the point multiplication task is a fixed point multiplication, if the value of the jth bit of the first parameter in the input parameter of the point multiplication task is 1, the intermediate result of the jth bit is obtained in a precomputed table, the intermediate result of the jth bit is added to the result of the j+1th bit to obtain the result of the jth bit; when j is the last bit of the first parameter, the result of the j+1th bit is the initial value, i.e., 0; the precomputed table is stored in the memory space of the GPU; the precomputed table records the intermediate results corresponding to the first parameter being 1 at the 0th bit to the 255th bit, respectively; If the value of the jth bit of the first parameter is 0, the result of the j+1th bit is taken as the result of the jth bit until the values of the bits of the first parameter are traversed, and the result of the 1st bit is determined as the processing result of the fixed point multiplication task; the precomputed table is stored in the constant memory of the GPU, which is initialized by the CPU and can be read by each thread in the GPU.
6. A computer device, comprising: Comprise: The memory is configured to store program instructions; The processor is configured to invoke the program instructions stored in the memory and execute the method according to any one of claims 1 to 4.
7. A computer-readable storage medium, characterized in that, The computer readable storage medium stores computer executable instructions for causing a computer to execute the method according to any one of claims 1 to 4.
Citation Information
Patent Citations
Heterogeneous calculation method and device, electronic equipment and storage medium
CN113377439A
GPU-based high-throughput SM2 digital signature computing system and method
CN113628094A