A data processing method based on the CUDA computing platform

By combining CPU and GPU dataflow parallel computing on the CUDA computing platform, the problem of lack of library functions on GPU is solved, and efficient parallel processing of randomly shuffled data is achieved, reducing the time spent by CPU to generate and transmit indexes and improving overall performance.

CN115756851BActive Publication Date: 2025-12-02JIUZHIXING (BEIJING) TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211457787.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-11-21
Publication Date
2025-12-02
Estimated Expiration
2042-11-21

AI Technical Summary

Technical Problem

Existing technologies for randomly shuffling data on GPUs lack library function support, resulting in a long processing time for the CPU to generate and transmit random indices, thus losing parallelism and increasing overall processing time.

Method used

By employing the CUDA computing platform and combining the data flow of the CPU and GPU, the parallel computation of random indexing and data processing is achieved by generating and shuffling the index array on the CPU and performing parallel computation on the GPU, thus hiding the CPU's computation time.

Benefits of technology

By reading random indices within the GPU, the time spent by the CPU in generating and transmitting indices is reduced, achieving a balance between random reads and computational performance, with no significant increase in overall time consumption.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115756851B_ABST
    Figure CN115756851B_ABST
Patent Text Reader

Abstract

This invention relates to a data processing method based on a CUDA computing platform, comprising: setting the data block size on the CPU side; generating an index array for the data blocks using the CPU; shuffling the index array; detecting the GPU device and starting CUDA to begin parallel CPU and GPU computing; inputting the array to be processed, the data block size, and the index array into the GPU; calculating a random index for the array to be processed under the current GPU thread; acquiring data, whereby the GPU uses the random index to acquire data from the array to be processed under the current thread; during the parallel GPU and CPU computing phase, the GPU performs data computation, and the CPU shuffles the index array to prepare for the next data computation. This invention achieves random access to input data on the GPU by reading random indices in the GPU; performs initial processing and block setting on the CPU side, reducing the time spent on CPU shuffle operations and copying to the GPU; and achieves a balance between random access functionality and computational performance through the "random index + block" method.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of computer application technology, and more specifically to a data processing method based on the CUDA computing platform. Background Technology

[0002] In software development, there are many scenarios that require randomly shuffling input data before subsequent operations. However, since GPUs lack pre-implemented library functions like those available for CPUs, it's necessary to implement a custom random shuffling algorithm and optimize performance to reduce processing time. Current technologies either shuffle the data on the CPU and then process it, or the CPU generates a random index and passes it to the GPU for random data retrieval. However, shuffling and processing the data on the CPU sacrifices parallelism and is time-consuming. Generating the random index on the CPU and passing it to the GPU are both time-consuming. Summary of the Invention

[0003] To address the shortcomings of the prior art, this invention proposes a data processing method based on the CUDA computing platform. This method utilizes the combination of CPU and GPU data streams to achieve random reading of input data within the GPU. Furthermore, the CUDA stream enables the randomization of CPU indexing and the parallel processing of GPU data, thereby hiding the computation time consumed by the CPU and ensuring that the overall processing time is not significantly improved.

[0004] To solve the above-mentioned technical problems, the technical solution of the present invention is: to propose a data processing method based on the CUDA computing platform, comprising:

[0005] Set the data block size on the CPU side;

[0006] Use the CPU to generate an index array of data blocks;

[0007] Shuffle the indices, shuffle the index array;

[0008] Detect the GPU device and launch CUDA to begin parallel computing between the CPU and GPU;

[0009] Input the array to be processed, the data block size, and the index array into the GPU;

[0010] Calculate the random index of the array to be processed under the current GPU thread;

[0011] To retrieve data, the GPU uses random indexes to retrieve data from the array to be processed within the current thread.

[0012] In the parallel computing phase between the GPU and CPU, the GPU performs data calculations, while the CPU shuffles the index array to prepare for the next data calculation.

[0013] As a preferred technical solution, when setting the data block size on the CPU side, the specific steps include:

[0014] Let the total length of the input array A be N;

[0015] Set the data block size to M;

[0016] Divide array A into K smaller array blocks, where K = N / M. When the value of K is a floating-point type, round up to the nearest integer.

[0017] As a preferred technical solution, the size M of the data block is determined based on the host resources.

[0018] As a preferred technical solution, when using the CPU to generate the index array of data blocks, specifically, the CPU generates an index array B with a length of K and a content of 0 to K-1.

[0019] As a preferred technical solution, when shuffling the index, the contents of the index array B are shuffled using the CPU's shuffle function.

[0020] In the above steps, the data to be computed is initially processed and divided into blocks on the CPU side. Without this data block processing, if the CPU generates a random index array of size N, the large amount of data will cause the index to be shuffled during the shuffle operation and increase the time spent on the next step of copying to the GPU. However, by dividing the data into blocks, the time can be reduced to 1 / K.

[0021] As a preferred technical solution, the random index of the array to be processed under the current GPU thread is calculated, specifically including:

[0022] Calculate the block index of the GPU in the current thread. Let the ID of the current thread of the GPU be thread_i, then the block index is B[thread_i].

[0023] The block index B[thread_i] is calculated using a for loop within the GPU to obtain the random index of the array A to be processed under the current GPU thread.

[0024] As a preferred technical solution, when using a for loop within the GPU, the block index B[thread_i] has a value of 0 to K-1.

[0025] As a preferred technical solution, the random index of the array A to be processed under the current GPU thread is calculated to be B[thread_i * K] + i.

[0026] As a preferred technical solution, during the data acquisition stage, under the current thread ID of thread_i, the GPU uses the random index B[thread_i * K] + i to obtain random data A[B[thread_i * K] + i from the array A to be processed.

[0027] On the GPU side, a random index is calculated using "block ID + intra-block index" and the calculated data is obtained, thus achieving a balance between random access functionality and computational performance.

[0028] As a preferred technical solution, the method further includes determining the execution order of the current threads so that data processing operations are performed in the order of execution.

[0029] Compared with the prior art, the present invention has achieved the following technical effects: (1) random reading of input data on the GPU is achieved by reading random indexes in the GPU; (2) the data is processed in the initial stage on the CPU and set in blocks, which greatly reduces the time spent on shuffle operation and copying to the GPU using the CPU; (3) the present method achieves a balance between the function of random reading and the computing performance through the method of "random index + block". Attached Figure Description

[0030] Figure 1 A schematic diagram of the data block segmentation process during the initialization phase on the CPU side, as proposed in this embodiment of the invention;

[0031] Figure 2 A schematic diagram of the data computation process performed on the GPU according to an embodiment of the present invention;

[0032] Figure 3 A schematic diagram of a data processing method based on the CUDA computing platform proposed in this embodiment of the invention. Detailed Implementation

[0033] To make the objectives, technical solutions, and advantages of this invention clearer, the technical solutions of this invention will be clearly and completely described below in conjunction with specific embodiments and corresponding drawings. Obviously, the described embodiments are only a part of the embodiments of this invention, and not all of them. Based on the embodiments of this invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this invention.

[0034] The steps illustrated in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. Furthermore, although a logical order is shown in the flowchart, in some cases the steps shown or described may be performed in a different order than that presented here.

[0035] This invention proposes a data processing method based on a CUDA computing platform. This method combines CPU and GPU data streams to enable random access of input data within the GPU, followed by GPU data computation. Furthermore, the CUDA streams allow for stream parallelism between CPU indexing and GPU data processing, thus hiding the CPU's computational time and resulting in no significant increase in overall processing time. The specific method is described in detail in the following embodiments.

[0036] Here, we'll briefly introduce streaming parallelism. The CPU and GPU are two independent computing hardware components, allowing them to perform computations simultaneously. A stream can be understood as a CUDA work queue. After the CPU places computational tasks into the queue, CUDA automatically executes these tasks on the GPU, allowing the CPU to continue executing subsequent programs. Therefore, CUDA streaming enables parallel processing of GPU computations and CPU operations involving shuffling indexed arrays. Example

[0037] according to Figure 1 As can be seen, during the initialization phase, preparations are made on the CPU side for data computation by performing preliminary processing on the data to be computed. Specifically, the methods for data processing during the initialization phase include:

[0038] Step 101: Set the data block size on the CPU side and divide the array to be processed into several smaller array blocks. Preferably, let the array to be processed be A, with a total length of N, and divide the array A into K smaller array blocks. Let the size of the data block be M, where K = N / M. When the value of K is a floating-point type, round up to the nearest integer. Furthermore, the size M of the data block is determined based on the host's resources to ensure smooth computation on the host.

[0039] Step 102: Use the CPU to generate an index array for the data blocks. Preferably, the CPU generates an index array B of length K, with contents ranging from 0 to K-1.

[0040] Step 103: Shuffle the indexes. The contents of the index array are shuffled using the CPU's shuffle function.

[0041] Step 104: Input the array to be processed A, the data block size M, and the index array B into the GPU.

[0042] The above steps have performed preliminary processing of the data A to be calculated, including data block segmentation. Without this data segmentation, generating a random index array of size N using the CPU would increase the time required for the shuffle operation to shuffle the indexes due to the large data volume, as well as the time required for the next step of copying to the GPU. However, by segmenting the array A into K smaller array blocks, the processing time can be reduced to 1 / K.

[0043] The above steps completed the data block setup and data processing during the CPU initialization phase, preparing the system for computation. Next, utilizing the CUDA streaming computing platform, the system enters the CPU-GPU parallel computing phase. At this point, the GPU device is detected and CUDA is launched, initiating CPU-GPU parallel computation. During parallel computation, CUDA streaming allows for parallel execution of CPU indexing and GPU data processing, thus hiding the CPU's computational time and resulting in no significant increase in overall time consumption.

[0044] according to Figure 2 It can be seen that data computation on the GPU is based on the initial data processing on the CPU. Specifically, the computation process includes:

[0045] Step 201: On the GPU side, receive the array to be processed A, the data block size M, and the index array B.

[0046] Step 202: Calculate the block index of the GPU in the current thread. After receiving the data, the GPU calculates the block index in the current thread. Let the ID of the current GPU thread be thread_i, then the block index is B[thread_i].

[0047] Step 203: Based on the block index B[thread_i], calculate the random index of the array A to be processed under the current GPU thread. The block index B[thread_i] is calculated using a for loop within the GPU, where i ranges from 0 to K-1. The calculated random index of the array A to be processed under the current GPU thread is B[thread_i * K] + i.

[0048] Step 204: The GPU acquires data, performs data calculations, and uses the GPU random index to retrieve data from the array A to be processed. More preferably, the random data acquired by the GPU thread_i is A[B[thread_i*K] +i].

[0049] Step 205: The GPU performs the computation.

[0050] Preferably, the data processing method further includes determining the execution order of the current thread so that the data processing operations are performed in the order of execution.

[0051] The above utilizes CUDA asynchronous streams to enable parallel computing between the GPU and CPU. During this phase, the GPU performs data computation, while the CPU shuffles the index array to prepare for the next data computation.

[0052] Figure 3 This is a schematic flowchart illustrating a data processing method based on the CUDA computing platform proposed in an embodiment of the present invention. This embodiment provides a clearer explanation of the technical solution of the present invention. Figure 3 As shown, this embodiment includes:

[0053] Step 1: Set the block size;

[0054] Step 2: Generate an index array;

[0055] Step 3: Shuffle the index array;

[0056] Step 4: Enter stream parallelism;

[0057] Step 5: Transfer data to the GPU;

[0058] Step 6: Calculate the random index;

[0059] Step 7: Obtain data;

[0060] Step 8: GPU computation;

[0061] In the streaming parallel phase, step 3 is executed in parallel while steps 5-8 are being executed.

[0062] Step 9: Determine if there is a need for another calculation. If yes, continue to Step 4; otherwise, proceed to the end.

[0063] Step 10: End.

[0064] This completes a data stream processing method based on the CUDA computing platform. The key aspects of this invention lie in the calculation of the random index array generated by the CPU after partitioning the data into blocks, and the calculation of random indices using "block ID + intra-block index" on the GPU side, and the acquisition of computational data. Performing initial data processing and block partitioning on the CPU significantly reduces the time spent on CPU shuffle operations and copying data to the GPU.

Claims

1. A data processing method based on the CUDA computing platform, characterized in that, include: Set the data block size on the CPU side; The CPU is used to generate an index array for the data blocks; Shuffle the indexes, shuffle the index array; Detect the GPU device and launch CUDA to begin parallel computing between the CPU and GPU; Input the array to be processed, the data block size, and the index array into the GPU; Calculate the random index of the array to be processed under the current GPU thread; To retrieve data, the GPU uses random indexes to retrieve data from the array to be processed within the current thread. In the parallel computing phase between the GPU and CPU, the GPU performs data calculations, while the CPU shuffles the index array to prepare for the next data calculation.

2. The data processing method based on the CUDA computing platform according to claim 1, characterized in that, Setting the data block size on the CPU side specifically includes: Let the total length of the input array A be N; Set the data block size to M; Divide array A into K smaller array blocks, where K = N / M. When the value of K is a floating-point type, round up to the nearest integer.

3. The data processing method based on the CUDA computing platform according to claim 2, characterized in that, The size M of the data block is determined based on the host resources.

4. The data processing method based on the CUDA computing platform according to claim 2, characterized in that, When using the CPU to generate the index array of the data block, specifically, the CPU generates an index array B of length K and content from 0 to K-1.

5. The data processing method based on the CUDA computing platform according to claim 4, characterized in that, When the index is shuffled, the contents of the index array B are shuffled using the CPU's shuffle function.

6. The data processing method based on the CUDA computing platform according to claim 4, characterized in that, Calculate the random index of the array to be processed under the current GPU thread, specifically including: Calculate the block index of the GPU in the current thread. Let the ID of the current thread of the GPU be thread_i, then the block index is B[thread_i]. The block index B[thread_i] is calculated using a for loop within the GPU to obtain the random index of the array A to be processed under the current GPU thread.

7. The data processing method based on the CUDA computing platform according to claim 6, characterized in that, When the block index B[thread_i] is used in a for loop within the GPU, the value of i is 0 to K-1.

8. The data processing method based on the CUDA computing platform according to claim 7, characterized in that, The random index of the array A to be processed under the current GPU thread is calculated to be B[thread_i * K] + i.

9. A data processing method based on a CUDA computing platform according to claim 8, characterized in that, During the data acquisition phase, under the current thread ID thread_i, the GPU uses the random index B[thread_i * K] + i to obtain random data A[B[thread_i * K] + i from the array A to be processed.

10. A data processing method based on a CUDA computing platform according to claim 1, characterized in that, The method further includes determining the execution order of the current thread so that data processing operations are performed in the order of execution.

Citation Information

Patent Citations

  • Parallel generation method of random two-phase medium model based on GPU and electric equipment

    CN107563080A

  • Evaluation method of evaluation result of recommendation system model and electronic equipment

    CN113112148A