A CUDA-based large integer calculation method, device and storage medium
Patent Information
- Application Number
- CN202311592957.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-11-27
- Publication Date
- 2026-09-15
- Estimated Expiration
- 2043-11-27
AI Technical Summary
[0005]本申请的目的是解决传统的大整数计算方法难以移植在GPU上执行的问题,提供一种基于CUDA的大整数计算方法、设备及存储介质,实现CPU加载大整数、GPU计算大整数,通过GPU的强大并发能力,可以在较短时间内完成海量数据的大整数计算
[0018] This method implements a large integer computing library that can be used in Nvidia series GPUs. It loads the large integer to be processed by the CPU and performs large integer operations on the GPU, making full use of the large number of GPU computing cores, and can complete a large number of large integer operations in a short time.
Smart Images

Figure CN117573072B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of scientific computing, and more specifically, to a method, apparatus, and storage medium for large integer computing based on CUDA. Background Technology
[0002] Large integer calculations typically include addition, subtraction, multiplication, division, modulo, higher power modulo, and bit shifting of large integers. Currently, many mature computational packages can perform large integer calculations, such as Java's built-in BigInteger module, C++'s gmp extension package, and Python's built-in multi-precision calculation tools.
[0003] However, these large integer computing frameworks often focus on reducing the latency of a single computation. The algorithms within these frameworks prioritize optimizing execution efficiency and are designed to run solely on the CPU. Therefore, with the gradual deterioration of Moore's Law for CPUs, it is difficult to further increase CPU clock frequencies. Under the current technological framework, it is already very difficult to further reduce computation latency for large integer computing.
[0004] Currently, heterogeneous computing devices such as GPUs are developing rapidly, and their concurrent computing capabilities are becoming increasingly powerful. However, traditional large integer calculation methods are difficult to port to GPUs. Therefore, this invention provides a CUDA-based large integer calculation method, device, and storage medium to solve the above problems. Summary of the Invention
[0005] The purpose of this application is to solve the problem that traditional large integer calculation methods are difficult to port to GPUs, and to provide a CUDA-based large integer calculation method, device and storage medium that enables the CPU to load large integers and the GPU to calculate large integers. Through the powerful concurrency capabilities of the GPU, large integer calculations of massive data can be completed in a short time.
[0006] Firstly, this application provides a CUDA-based large integer calculation method applied to a host CPU, comprising: S1, loading data to be processed, representing the data to be processed as a row-based storage structure, converting the row-based storage structure into a column-based storage structure according to the computing core of the device GPU, wherein the column-based storage structure is used to indicate the access method of the data to be processed; S2, writing the column-based storage structure into local memory using unified memory technology, and simultaneously synchronizing the metadata information of this memory block to the device GPU; S3, sending calculation instructions to the device GPU, wherein the device GPU is used to receive the calculation instructions sent by the host CPU, load the column-based storage structure in memory into video memory according to the metadata information, read the column-based storage structure in video memory, convert the column-based storage structure into a row-based structure, execute specific calculation logic, obtain the row-based calculation result, convert the row-based calculation result into a column-based structure and write it into video memory, and simultaneously notify the host CPU that the calculation is complete; S4, after receiving the notification from the device GPU, using unified memory technology to load the column-based calculation result from video memory into memory, and retrieving the calculation result from memory.
[0007] Using the above technical solutions, a large integer computing library capable of being used in Nvidia GPUs was created. This library improves the efficiency of large integer computation by loading large integers to be processed onto the CPU and performing large integer operations on the GPU; it also enables the migration of large integers between the CPU and GPU by setting a special large integer representation method in conjunction with the same memory technology; and it achieves high-concurrency computing by setting a special storage structure in conjunction with the GPU's read-write merging capabilities.
[0008] In one possible implementation of the first aspect, in step S1, the row-oriented storage structure is: a bool variable for recording the sign of the large integer; an int variable for recording the actual array length real_length occupied by the large integer; and an int static array for recording the maximum computable array length block_length.
[0009] In one possible implementation of the first aspect, in step S1, the columnar storage structure is: a bool array for recording the signs of batch_size large integers, where batch_size represents the maximum number of data that the device-side GPU can process simultaneously at any given time, and is an integer multiple of the number of computing cores; an int array for recording the array length actually occupied by batch_size large integers; and an int array for recording a two-dimensional array with rows of block_length and columns of batch_size.
[0010] In one possible implementation of the first aspect, in step S3, the specific calculation logic is any one of large integer addition, large integer subtraction, large integer multiplication, large integer division, large integer remainder, and large integer power remainder.
[0011] Secondly, this application also provides a CUDA-based large integer calculation method applied to a device-side GPU, comprising: S1, receiving a calculation instruction sent by a host-side CPU, wherein the host-side CPU loads data to be processed, represents the data to be processed as a row-based storage structure, converts the row-based storage structure into a column-based storage structure according to the computing core of the device-side GPU, the column-based storage structure is used to indicate the access method of the data to be processed, writes the column-based storage structure into local memory using unified memory technology, and simultaneously synchronizes the metadata information of this memory block to the device-side GPU; S2, loading the column-based storage structure in memory into video memory according to the metadata information; S3, reading the column-based storage structure in video memory, converting the column-based storage structure into a row-based structure, executing specific calculation logic, and obtaining a row-based calculation result; S4, converting the row-based calculation result into a column-based structure and writing it into video memory, and simultaneously notifying the host-side CPU that the calculation is complete, wherein the host-side CPU, upon receiving the notification from the device-side GPU, uses unified memory technology to load the column-based calculation result from video memory into memory and retrieves the calculation result from memory.
[0012] In one possible implementation of the second aspect, in step S1, the row-oriented storage structure is: a bool variable for recording the sign of the large integer; an int variable for recording the actual array length real_length occupied by the large integer; and an int static array for recording the maximum computable array length block_length.
[0013] In one possible implementation of the second aspect, in step S1, the columnar storage structure is: a bool array for recording the signs of batch_size large integers, where batch_size represents the maximum number of data that the device-side GPU can process simultaneously at any given time, and is an integer multiple of the number of computing cores; an int array for recording the actual array length occupied by batch_size large integers; and an int array for recording a two-dimensional array with rows of block_length and columns of batch_size.
[0014] In one possible implementation of the second aspect, in step S3, the specific calculation logic is any one of large integer addition, large integer subtraction, large integer multiplication, large integer division, large integer remainder, and large integer power remainder.
[0015] Thirdly, this application provides an electronic device, including: at least one processor, the at least one processor being coupled to a memory, reading and executing instructions in the memory to implement the method provided in any one of the embodiments of the first aspect and the second aspect above.
[0016] Fourthly, this application provides a computer-readable storage medium, characterized in that the computer-readable storage medium stores computer instructions that, when executed on a computer, cause the computer to perform the method provided by any one of the embodiments of the first and second aspects described above.
[0017] Compared with the prior art, this application has the following beneficial effects:
[0018] This method implements a large integer computing library that can be used in Nvidia series GPUs. It loads the large integer to be processed by the CPU and performs large integer operations on the GPU, making full use of the large number of GPU computing cores, and can complete a large number of large integer operations in a short time.
[0019] By setting a special large integer representation method and using unified memory technology, data migration between the CPU and GPU is achieved; by setting a special large integer storage structure and using the GPU's read and write merging capabilities, high-concurrency computing is achieved.
[0020] In addition, since modern encryption systems frequently use large integer calculations, this method can also generate significant performance gains for encryption algorithms such as RSA and Paillier. Attached Figure Description
[0021] The accompanying drawings, which are included to provide a further understanding of embodiments of the invention and form part of this application, do not constitute a limitation thereof. In the drawings:
[0022] Figure 1 The flowchart is shown below for the large integer calculation method provided in Embodiments 1-2 of the present invention;
[0023] Figure 2 This is a schematic diagram of a conventional array representation of large integers provided in Embodiments 1-2 of the present invention;
[0024] Figure 3 This is a schematic diagram of the arrangement of data represented by a specific structure in the storage space, as provided in Embodiments 1-2 of the present invention.
[0025] Figure 4 This is a schematic diagram of the arrangement of the columnar storage structure provided in Embodiments 1-2 of the present invention in the storage space;
[0026] Figure 5This is a schematic diagram illustrating the principle of GPU read-write merging provided in Embodiments 1-2 of the present invention;
[0027] Figure 6 This is a structural comparison of the CPU and GPU provided in Embodiments 1-2 of the present invention;
[0028] Figure 7 This is a schematic diagram of the structure of the electronic device provided in Embodiment 3 of the present invention;
[0029] Figure 8 This is a performance comparison chart of large integer addition provided in Embodiment 5 of the present invention;
[0030] Figure 9 This is a performance comparison chart of large integer subtraction provided in Embodiment 5 of the present invention;
[0031] Figure 10 This is a comparison chart of the performance of large integer multiplication provided in Embodiment 5 of the present invention;
[0032] Figure 11 This is a performance comparison chart of large integer division provided in Embodiment 5 of the present invention;
[0033] Figure 12 This is a comparison chart of the performance of large integer modulo operations provided in Embodiment 5 of the present invention;
[0034] Figure 13 This is a comparison chart of the large integer RSA encryption performance provided in Embodiment 5 of the present invention;
[0035] Figure 14 This is a comparison chart of the decryption performance of large integer RSA provided in Embodiment 5 of the present invention. Detailed Implementation
[0036] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the embodiments and accompanying drawings. The illustrative embodiments and descriptions of this application are only for explaining this application and are not intended to limit this application.
[0037] Example 1 provides a CUDA-based method for large integer computation, applied to a host-side CPU. Please refer to... Figure 1 As shown, Figure 1This is a flowchart of a large integer calculation method. The method includes: S1, loading the data to be processed, representing the data as a row-oriented storage structure, and converting the row-oriented storage structure into a column-oriented storage structure according to the computing core of the device's GPU. The column-oriented storage structure is used to indicate the access method of the data to be processed; S2, writing the column-oriented storage structure into local memory using unified memory technology, and simultaneously synchronizing the metadata information of this memory block to the device's GPU; S3, sending calculation instructions to the device's GPU, which receives the calculation instructions sent by the host CPU, loads the column-oriented storage structure in memory into video memory according to the metadata information, reads the column-oriented storage structure in video memory, converts the column-oriented storage structure into a row-oriented structure, executes the specific calculation logic, obtains the row-oriented calculation result, converts the row-oriented calculation result into a column-oriented structure and writes it into video memory, and simultaneously notifies the host CPU that the calculation is complete; S4, after receiving the notification from the device GPU, using unified memory technology to load the column-oriented calculation result from video memory into memory, and retrieves the calculation result from memory.
[0038] This method loads large integers to be processed by the CPU, performs large integer operations by the GPU, and returns the calculation results. By leveraging the large number of computing cores in the GPU, it can complete a large number of large integer operations in a short time. By setting a special large integer representation method and using unified memory technology, it realizes data migration between the CPU and the GPU. By setting a special large integer storage structure and using the read and write merging capabilities of the GPU, it achieves high-concurrency computing.
[0039] It should be noted that this method is based on CUDA provided by NVIDIA series graphics cards, and can only run on NVIDIA graphics cards, and the CUDA version should be higher than 6.
[0040] To explain this method in detail, the following sections will cover four aspects: representation of large integers, storage and retrieval of large integers, calculation framework for large integers, and various mathematical operations on large integers.
[0041] First, regarding the representation of large integers:
[0042] In one possible implementation, in step S1, the data to be processed is loaded and represented as a row-oriented storage structure. The row-oriented storage structure consists of: a bool variable to record the sign of the large integer; an int variable to record the actual array length real_length occupied by the large integer; and an int static array to record the maximum computable array length block_length.
[0043] It should be noted that, according to the data types of various computer languages, the basic types capable of storing the highest precision include C++'s `unsigned long long` and Java's `unsigned long`, etc. These basic types generally occupy 8 bytes, or 64 bits. Using 64 bits, a total of 2^64 unsigned integers can be represented.
[0044] Therefore, large integers are generally considered to be unsigned integers not less than 2^64, or signed integers with an absolute value greater than 2^63. For these large integers, existing algorithms use arrays for representation.
[0045] For example, an array of integers of length 128, where each integer element can store 32 bits of information, can represent a total of 4096 bits of information, or 2^4096 unsigned integers. See also... Figure 2 As shown, Figure 2 This is a diagram illustrating how to represent large integers using an existing array. Therefore, mathematically speaking, this representation is a 2^32 array. 64 Number system representation.
[0046] In traditional CPU-based algorithms, there are already very reasonable solutions for representing large integers. Taking the widely used Java built-in class BigInteger as an example, existing solutions generally represent a large integer object using two parts: a boolean variable to record the sign of the current large integer; and an int dynamic array to record the large integer itself.
[0047] The main problem with porting the above solution to the GPU is that the underlying implementation of the int dynamic array requires the use of pointers. However, in order to ensure the transfer of data between the CPU and the GPU, this method needs to use a unified memory technology. This technology cannot automatically synchronize the dynamic memory allocated by pointers. At the same time, the allocation and reclamation of dynamic memory are very time-consuming in the GPU.
[0048] Therefore, this method makes some minor adjustments to the representation of large integers: First, this method still uses a boolean variable to record the current large integer sign, but this solution makes two improvements to the dynamic array of type int: First, the dynamic array is changed to a static array of fixed length, and the length of the static array is a fixed constant block_length, for example, in this case block_length = 160. Using a static array can avoid the GPU's overhead in memory allocation and reclamation, which can greatly reduce memory fragmentation. Second, an int variable is used to record the actual array length used for the current large integer.
[0049] It should be noted that the integer variable used to record the actual array length used for the current large integer is unnecessary in this method. If this integer variable does not exist, all subsequent calculations of large integers can be performed by traversing the maximum length `block_length`. Using a separate variable to record the actual array length used for the current large integer is to improve the calculation speed. Below is the large integer representation method designed in this method:
[0050]
[0051] The layout of the above structure in the storage space can be found in [reference needed]. Figure 3 As shown in the diagram, each box represents one byte. This structure is also called a "row-based storage structure" in this method. It is a memory organization structure that facilitates algorithm development. In contrast, there is another structure called a "column-based storage structure." The column-based storage structure has high performance in reading and writing, which will be introduced in detail later in the section on the storage and retrieval of large integers. Figure 3 In this example, `sign` is a boolean variable. When `sign` is true, it represents a positive integer; otherwise, it represents a negative integer. (Specially, when the current large integer is 0, `sign` is also set to true). `real_length` is an integer variable used to record the actual length of the integer array occupied by the large integer. `Blocks` is an integer array used to replace the dynamic array in the original scheme. Here, it has been modified into a fixed-length array. In this example, `block_length = 160`, which means that the large integer scheme in this example can calculate a large integer of up to 160 * 32 = 5120 bits, which is sufficient for everyday cryptographic needs.
[0052] Second, regarding the storage and retrieval of large integers:
[0053] In one possible implementation, in step S1, the row-based storage structure is converted into a column-based storage structure according to the computing cores of the device-side GPU. The column-based storage structure is used to indicate the access method of the data to be processed. The column-based storage structure consists of: a bool array for recording the signs of batch_size large integers, where batch_size represents the maximum number of data that the device-side GPU can process simultaneously at any given time, and is an integer multiple of the computing cores; an int array for recording the actual array length occupied by batch_size large integers; and an int array for recording a two-dimensional array with rows of block_length and columns of batch_size.
[0054] It's important to note that the large integer representation method described above is not suitable for direct use in GPUs. The main reason for this is that GPU memory access is characterized by high latency and high bandwidth. Each read operation involves the GPU accessing a large block of memory that is a multiple of 32 bytes.
[0055] Based on the above characteristics, it can be seen that if the data to be read is converted into columnar storage, then each thread of the GPU will have a large number of read requests hitting contiguous space when reading the data to be processed. In this case, the GPU's built-in merge read algorithm will greatly reduce the number of reads.
[0056] Furthermore, GPUs typically contain thousands of computing units. For example, even the worst-performing RTX 4060 laptop version of NVIDIA's latest 40-series graphics cards (as of September 2023) has 3072 computing units, far exceeding the number of CPU cores. However, the computational power of a single GPU computing unit is much lower than that of a single CPU core. Therefore, in this method, the GPU only gains an advantage through its powerful concurrency capabilities when performing a large number of large integer operations.
[0057] Therefore, based on the above characteristics, a columnar storage scheme is designed as follows: First, a constant `batch_size` needs to be defined to represent the maximum number of data items that the GPU can process simultaneously. It is recommended that this constant be set to an integer multiple of the number of computing cores. For example, in this case, `batch_size` = 196608. For more powerful graphics cards, this constant can be increased appropriately. Second, the data structure definition is similar to the large integer representation method designed above, but each element will be expanded by one dimension. Following the above principles, this method designs the following data structure:
[0058]
[0059] The layout of the above structure in the storage space can be found in [reference needed]. Figure 4 As shown. Each column in this structure can be converted into the row-oriented storage structure described above. The meaning of each variable in this structure is the same as... Figure 3 The same applies to the previous ones, so I won't repeat it here.
[0060] Understandably, using a columnar storage structure for accessing large integers is 30% to 50% faster than the row-oriented storage structure described above (measured on an RTX 4060 laptop graphics card). The faster read and write speeds are due to the GPU's built-in read-write merging capabilities. For example... Figure 5 As shown, Figure 5This is a schematic diagram illustrating the principle of GPU read / write merging. Because each thread executes the same code during runtime, they will initiate queries or writes to video memory almost simultaneously. These threads only differ in the video memory addresses they query or write to. Therefore, using the columnar storage structure of this method, it can be guaranteed that when all threads are reading the sign in the representation of large integers, these signs are distributed in a contiguous video memory space. Thus, the GPU will merge the queries, which will greatly improve read / write speed.
[0061] Third, regarding the calculation framework for large integers:
[0062] like Figure 1 As shown, this method proposes a general computing architecture in which all algorithms are executed. This framework delegates the more complex tasks such as data loading, resource allocation, and task allocation to the CPU, while the computationally intensive tasks are performed by the GPU.
[0063] It's worth noting that Unified Memory technology first emerged in 2013 and is now very mature for modern CUDA versions. This technology allows the system to automatically migrate data between the CPU and GPU as needed, enabling programmers to focus on algorithms and program logic rather than memory management.
[0064] Figure 1 In this context, the data flow is as follows:
[0065] Step 1: The host computer loads the data to be processed and converts it into a columnar storage structure;
[0066] Step 2: The host writes the columnar storage structure into local memory using unified memory technology, and at the same time synchronizes the metadata information of this memory block to the device.
[0067] Step 3: The host sends calculation instructions to the device.
[0068] Step 4: The device receives the calculation instructions from the host and begins to read the columnar storage structure in the video memory. With the help of unified memory technology, the device will automatically load the columnar storage structure to be calculated into the video memory according to the metadata information in Step 2.
[0069] Step 5: The device converts the columnar storage structure in the video memory into row-based storage for subsequent calculations.
[0070] Step 6: The device executes the specific calculation logic and calculates the row-wise calculation result;
[0071] Step 7: The device converts the row-based calculation result into column-based result and writes it to the display memory, while notifying the host that the calculation is complete.
[0072] Step 8: After receiving the notification from the device, the host uses a method similar to Step 4 to retrieve the calculation results from the unified memory.
[0073] Fourth, various mathematical operations involving large integers:
[0074] In one possible implementation, the specific calculation logic in step S3 is any one of large integer addition, large integer subtraction, large integer multiplication, large integer division, large integer remainder, and large integer power remainder.
[0075] It should be noted that various algorithms for calculating large integers have been thoroughly studied. However, these algorithms are all designed for CPU operation. In this approach, it is necessary to port these algorithms to CUDA implementations, rather than directly referencing existing large number libraries.
[0076] Furthermore, regarding large integer multiplication algorithms: In previous studies, there have been various implementation algorithms for large integer multiplication, such as the most basic long multiplication, the Karatsuba algorithm which uses the divide-and-conquer approach, and the NTT algorithm which is modified using the Fast Fourier Transform. In this study, the long multiplication algorithm, which has the highest computational complexity, has the highest computational efficiency when running on a GPU.
[0077] There are two main reasons for this: 1. The large integer algorithm described in this method uses a static array instead of a dynamic array. The length of the static array is fixed at 5120 bits. Within this range, higher-level algorithms do not offer a significant advantage over the most basic long multiplication. 2. In the GPU chip structure, the largest area is the computation unit. As mentioned earlier, GPUs typically have more than a thousand computation units. However, their control units are very few. This results in GPUs being far less capable of executing branching statements than CPUs. Furthermore, the Karatsuba algorithm and the NTT algorithm require recursion or complex conditional statements, which are very inefficient for GPUs. Therefore, when considering computational algorithms, both hardware capabilities and algorithm complexity must be considered. A comparison of CPU and GPU structures is provided. Figure 6 As shown in the diagram, the green part represents the computing unit, and the yellow part is the control unit.
[0078] Based on the above two reasons, it was verified that on an RTX 4060 laptop graphics card, the karatsuba algorithm is often an order of magnitude slower than long multiplication.
[0079] Next, the pseudocode for the main algorithms for several large integer calculations included in this method is shown:
[0080]
[0081]
[0082]
[0083]
[0084]
[0085]
[0086]
[0087]
[0088] It should be noted that the above pseudocode can be implemented in C++ to create a CUDA-based large integer computing library.
[0089] As can be seen, this method implements a large integer computation library that can be used in Nvidia GPUs. Because GPUs have a vast number of computing cores, the computation library generated by this method can complete a large number of large integer operations in a short time. Furthermore, since modern encryption systems frequently use large integer calculations, the computation library generated by this method can also provide significant performance gains for encryption algorithms such as RSA and Paillier.
[0090] Example 2 also provides a CUDA-based method for large integer computation, applied to a device-side GPU. See [link to example]. Figure 1-6 As shown, corresponding to Embodiment 1, the method includes: S1, receiving a calculation instruction sent by a host CPU, wherein the host CPU loads the data to be processed, represents the data to be processed as a row-based storage structure, and converts the row-based storage structure into a column-based storage structure according to the computing core of the device GPU, wherein the column-based storage structure is used to indicate the access method of the data to be processed; writing the column-based storage structure into local memory using unified memory technology, and simultaneously synchronizing the metadata information of this memory block to the device GPU; S2, loading the column-based storage structure in memory into video memory according to the metadata information; S3, reading the column-based storage structure in video memory, converting the column-based storage structure into a row-based structure, executing specific calculation logic, and obtaining the row-based calculation result; S4, converting the row-based calculation result into a column-based structure and writing it into video memory, and simultaneously notifying the host CPU that the calculation is complete; the host CPU, after receiving the notification from the device GPU, uses unified memory technology to load the column-based calculation result from video memory into memory, and obtains the calculation result from memory.
[0091] In one possible implementation, in step S1, the data to be processed is represented as a row-oriented storage structure, which consists of: a bool variable to record the sign of the large integer; an int variable to record the actual array length real_length occupied by the large integer; and an int static array to record the maximum computable array length block_length.
[0092] In one possible implementation, in step S1, the row-based storage structure is converted into a column-based storage structure according to the computing cores of the device's GPU. The column-based storage structure is used to indicate the access method of the data to be processed. The column-based storage structure consists of: a bool array for recording the signs of batch_size large integers, where batch_size represents the maximum number of data that the device's GPU can process simultaneously at any given time, and is an integer multiple of the computing cores; an int array for recording the actual array length occupied by batch_size large integers; and an int array for recording a two-dimensional array with rows of block_length and columns of batch_size.
[0093] In one possible implementation, the specific calculation logic in step S3 is any one of large integer addition, large integer subtraction, large integer multiplication, large integer division, large integer remainder, and large integer power remainder.
[0094] Example 3 provides an electronic device; please refer to [link / reference]. Figure 7 As shown, Figure 7 This is a schematic diagram of the electronic device. The electronic device includes: at least one processor, which is coupled to a memory to read and execute instructions in the memory to implement a CUDA-based large integer calculation method provided in the above-described method embodiments. Of course, the electronic device may also have wired or wireless network interfaces, a keyboard, and input / output interfaces for input and output. The electronic device may also include other components for implementing device functions, which will not be elaborated here.
[0095] Example 4 provides a computer-readable storage medium storing computer instructions. When these instructions are executed on a computer, the computer performs a CUDA-based large integer calculation method as described in the above method embodiments. Optionally, the computer-readable storage medium can be any medium capable of storing program code, such as a USB flash drive, external hard drive, read-only memory (ROM), random access memory (RAM), magnetic disk, or optical disk.
[0096] Example 5 provides performance test results for a CUDA-based large integer computation method.
[0097] Through detailed testing of the CUDA-based large integer calculation method, it can be concluded that when performing large-scale large integer calculations, the performance of this method is far superior to that of CPU-based methods.
[0098] First, let me introduce the test results:
[0099] GPU used in the test: NVIDIA GeForce RTX 4060 Laptop GPU
[0100] CPU used in the test: Intel(R) Xeon(R) Gold 6136 CPU @ 3.00GHz
[0101] In addition, the GPU used in the test was a laptop-specific graphics card released in February 2023, and its key parameters are shown in the table below:
[0102] CUDA compute core count 3072 Acceleration frequency 1470~2370MHz Standard video memory configuration 8GB GDDR6 Memory bus width 128bit computing power 8.9
[0103] This graphics card is a gaming graphics card, and its performance in all aspects is lower than that of Tesla's professional computing cards, but through... Figure 8-14 The test results show that the large integer calculation capability of this method is still far superior to that of the CPU.
[0104] Below are the various calculations performed in the test, along with the corresponding test results:
[0105] A. Calculation Item: Adding two 2048-bit large integers; Number of Calculations: 100 million; Test Results: Please refer to [link / reference] Figure 8 As shown.
[0106] B. Calculation Item: Subtraction of two 2048-bit large numbers; Number of calculations: 100 million; Test results: Please refer to [link / reference]. Figure 9 As shown.
[0107] C. Calculation Item: Multiplication of two 2048-bit large numbers; Number of calculations: 100 million; Test results: Please refer to [link / reference]. Figure 10 As shown.
[0108] D. Calculation Item: Dividing a 2048-bit large number by a 512-bit large number; Number of Calculations: 100 million; Test Results: Please refer to [link / document / resources]. Figure 11 As shown.
[0109] E. Calculation Item: Modulo operation of a 2048-bit large number with a 512-bit large number; Number of calculations: 100 million; Test results: Please refer to [link / reference]. Figure 12 As shown.
[0110] F. Calculation Item: RSA encryption, where the public key e = 65537, and n is a 1024-bit large number; Number of calculations: 1 million; Test results: Please refer to [link / reference]. Figure 13 As shown.
[0111] G. Calculation Item: RSA decryption, where the private keys d and n are both 1024-bit large numbers; Number of calculations: 1 million; Test results: Please refer to [link / reference]. Figure 14 As shown.
[0112] As can be seen, this method can significantly increase the throughput of integer computations. Leveraging the powerful concurrency capabilities of GPUs, large integer computations on massive datasets can be completed in a relatively short time. Furthermore, since large integer computation is fundamental to modern cryptography, this method can significantly reduce encryption / decryption time overhead. With proper design, it's even possible to develop enterprise-level encryption systems where each system uploads its plaintext and public key to the system, which then encrypts a massive number of encryption requests. Moreover, the test results above demonstrate that even a moderately configured GPU can provide powerful computing capabilities, offering a certain economic benefit.
[0113] The specific embodiments described above further illustrate the purpose, technical solution, and beneficial effects of the present invention. It should be understood that the above description is only a specific embodiment of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.
Claims
1. A method for large integer computation based on CUDA, characterized in that, Applied to host-side CPUs, including: S1. Load the data to be processed, represent the data to be processed as a row-based storage structure, and convert the row-based storage structure into a column-based storage structure according to the computing cores of the GPU on the device. The column-based storage structure is used to indicate the access method of the data to be processed. In step S1, the row-based storage structure consists of: a bool variable to record the sign of the large integer; an int variable to record the actual array length occupied by the large integer (real_length); and an int static array to record the maximum computable array length (block_length). The column-based storage structure consists of: a bool array to record the signs of batch_size large integers, where batch_size represents the maximum number of data that the GPU on the device can process simultaneously at any given time, and is an integer multiple of the computing cores; an int array to record the actual array length occupied by batch_size large integers; and an int array to record a two-dimensional array with rows of block_length and columns of batch_size. S2. Write the columnar storage structure into local memory using unified memory technology, and simultaneously synchronize the metadata information of this memory block to the device GPU. S3. Sending computation instructions to the device-side GPU, the device-side GPU receives computation instructions sent by the host-side CPU, loads the columnar storage structure in memory into video memory according to the metadata information, reads the columnar storage structure in video memory, converts the columnar storage structure into a row structure, executes specific computation logic, obtains the row structure computation result, converts the row structure computation result into a column structure and writes it into video memory, and simultaneously notifies the host-side CPU that the computation is complete; wherein, S3 includes: receiving computation instructions sent by the host-side CPU, the host-side CPU loads the data to be processed, represents the data to be processed as a row structure, and converts the row structure into a column structure according to the computation core of the device-side GPU. The columnar storage structure is used to indicate the access method of the data to be processed. The columnar storage structure is written to local memory using unified memory technology, and the metadata information of this memory block is synchronized to the device-side GPU. Based on the metadata information, the columnar storage structure in memory is loaded into video memory. The columnar storage structure in video memory is read, converted into a row-based structure, and the specific calculation logic is executed to obtain the row-based calculation result. The row-based calculation result is converted into a columnar structure and written to video memory, while simultaneously notifying the host-side CPU that the calculation is complete. Upon receiving the notification from the device-side GPU, the host-side CPU uses unified memory technology to load the columnar calculation result from video memory into memory and retrieves the calculation result from memory. S4. After receiving the notification from the GPU on the device, use unified memory technology to load the columnar calculation results from the video memory to the memory, and then retrieve the calculation results from the memory.
2. The CUDA-based large integer calculation method according to claim 1, characterized in that, In step S3, the specific calculation logic is any one of the following: large integer addition, large integer subtraction, large integer multiplication, large integer division, large integer remainder, and large integer power remainder.
3. The method for calculating large integers based on CUDA according to claim 1, characterized in that, In step S1, the row-oriented storage structure is as follows: A boolean variable to store the sign of a large integer; An integer variable is used to record the actual array length occupied by the large integer, real_length; A static array of type int, used to record the maximum computable array length, block_length.
4. The CUDA-based large integer calculation method according to claim 3, characterized in that, In step S1, the columnar storage structure is as follows: A boolean array is used to record the signs of batch_size large integers, where batch_size represents the maximum number of data that the GPU on the device can process at the same time, and is taken as an integer multiple of the number of computing cores; An integer array is used to record the actual array length occupied by batch_size large integers; An integer array to record a two-dimensional array with rows of length block_length and columns of length batch_size.
5. An electronic device, characterized in that, include: At least one processor, the at least one processor being coupled to a memory, reading and executing instructions in the memory to implement the method as described in any one of claims 1-4.
6. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions that, when executed on a computer, cause the computer to perform the method as described in any one of claims 1-4.
Citation Information
Patent Citations
On-chip CPU / GPU streamlined computing method based on Linux and computer system
CN111190735A
Method for improving parallel NumPy computing performance by using characteristics of non-uniform memory access architecture
CN112860530A