A GPU template calculation method supporting the combination of memory access and circular queue

Through the GPU template calculation method of merged memory fetch and loop queues, the problem of inefficient GPU template calculation is solved, efficient composite differential operator calculation is realized, and GPU performance is improved.

CN116126540BActive Publication Date: 2025-08-01UNIV OF SCI & TECH BEIJING
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310181904.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-02-21
Publication Date
2025-08-01
Estimated Expiration
2043-02-21

AI Technical Summary

Technical Problem

In the prior art, GPU template calculation is inefficient in merging memory fetching and composite differential operators, and cannot fully utilize GPU performance. Especially when calculating cube shape template calculation in physics, data transmission overhead is high, and the traditional 2.5D blocking method cannot be applied.

Method used

The GPU template calculation method of merged memory fetch and loop queues is adopted, and two-dimensional plane data is read through merged memory fetch and loop queues are used to optimize the access of data in shared memory, which is suitable for complex differential operator calculations.

Benefits of technology

It improves the efficiency of GPU template computing, reduces data exchange, and reduces memory access pressure. It is suitable for various mainstream GPUs and improves the computing performance of composite differential operators.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116126540B_ABST
    Figure CN116126540B_ABST
Patent Text Reader

Abstract

The present invention discloses a GPU template calculation method supporting combined memory access and circular queue. The method includes: performing combined memory access to read a block of data on a two-dimensional plane; and performing template calculation based on the circular queue. The conventional 2.5D block template calculation method used on GPUs can well reuse the data on a certain axis (usually the axis), but cannot achieve full combined memory access and is also difficult to apply to complex composite differential operators in computational physics. The memory access efficiency of modern GPUs is much lower than the computing efficiency, and it is difficult for computational applications that cannot utilize combined memory access to fully utilize the performance of GPUs. The present invention establishes a block template calculation method combining a circular queue and combined memory access, which can fully utilize the memory access performance of GPUs and is applicable to complex differential operators.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of high-performance computing, and particularly relates to a GPU template calculation method supporting combined memory access and circular queue. Background Art

[0002] Template calculation is a basic operation in the implementation of the finite difference method. It is a nearest neighbor calculation that usually needs to traverse a two-dimensional or three-dimensional spatial grid and calculate a value using the data of adjacent grid points. Until the entire grid is calculated once, the output result of the current time step can be obtained. In the specific design of the finite difference solver, there are many different types of differential operators, and these operators correspond to different template calculation formats. For example, a 3-point or 5-point template in the same direction is used to calculate partial derivatives, and a 5-point, 7-point or even 13-point template in three directions is used to calculate the Laplace operator. The typical 5-point template calculation format is as follows.

[0003]

[0004] Among them, u represents the data involved in the calculation, such as temperature. The subscripts m and n respectively represent the input data indices in the X and Y directions, and the subscript t represents the output data of the current time step; G is a function of the input data, that is, the calculation formula. This format calculates the new data at the central position from 5 points around a point (,n).

[0005] The general GPU architecture is updated very quickly, but basically adopts the same programming model, called SIMT. The current de facto standard interfaces for this model are CUDA and HIP. By using CUDA / HIP, the template calculation of the entire three-dimensional region can be decomposed into multiple thread blocks, and each thread is responsible for the actual calculation. However, the data required for each thread to complete the calculation is not just one point, resulting in each thread within a thread block having to repeatedly access the same data. For example, in the 5-point template calculation, each point is used by 5 adjacent threads and is thus read 5 times repeatedly. This greatly increases the burden on the bandwidth. The current common practice is to adopt combined memory access (coalescing) and on-chip shared memory, and read all the data required by a thread block into the shared memory closer to the computing unit at one time. This practice saves memory access time in two aspects: First, the computing unit reads data from the GPU global memory in blocks, and combined memory access can minimize the number of memory accesses; Second, when multiple threads access the same data, they only need to read from the shared memory, which is faster than reading from the global memory.

[0006] A common approach for stencil calculations on GPUs is called 2.5D blocking. Traditional SinglePass and TwoPass methods fall into this category. These methods treat calculations on a 3D grid as multiple 2D grids, proceeding sequentially from the first 2D grid. This process reuses previous data, saving data read overhead.

[0007] When calculating data on a two-dimensional grid, in order to obtain D x ×D y The output data of larger size requires larger input data, for example (D x +2r x )(D y +2r y ), where the increment depends on the size of the template. The data reused by the 2.5D type method is usually the data along the third axis (z axis), which makes the current two-dimensional plane and the two-dimensional planes before and after it clearly different: the current plane is always saved on the GPU computing unit (D x +2r x )(D y +2r y ) size, other planes only need D x D y Although this approach reduces the amount of data stored locally, it fails to take advantage of coalesced memory access. In actual computational problems, the radius of the template calculation is much smaller than the width of the problem grid, and the amount of data introduced by the boundary data is not large.

[0008] On the other hand, computational physics often uses various differential operators and their composite operators, while the traditional 2.5D block method is only applicable to cross-shaped templates (such as ), which is not applicable to cube-shaped templates (there are values outside the cross). This also causes some complex operators to be split into multiple simple operators for calculation, increasing the overhead of data transmission. Summary of the Invention

[0009] The present invention is provided to solve the above problems existing in the prior art. Therefore, a GPU template calculation method supporting merged memory access and circular queue is needed to fully utilize the high efficiency of merged memory access to implement GPU calculation of complex differential operators.

[0010] According to a first embodiment of the present invention, a GPU template calculation method supporting combined memory access and circular queue is provided, the method comprising:

[0011] Merge memory access to read a block of data on a two-dimensional plane;

[0012] Template Calculation Based on Circular Queue:

[0013] Given a 3D template calculation problem: template calculation formula F, template radius r x , r y and r z ; 3D grid D x ×D y ×D z , the size H of the surrounding halo region x , H y and H z ; input data pointer data, output data pointer out; initialize pointers s pointing to different data blocks in shared memory mm , s m , s c , s p , s pp ; thread block size B x , B y , the index b of the current thread block x , b y , the index t of the current thread x , t y ;

[0014] Read the initial data block into shared memory. Except for the first data block, s m , s m , s c , s p , s pp ;

[0015] Adjust the output data pointer to point to the correct position: Calculate the number of data points separated in the 2D plane, l = (D x + 2H x )(D y + 2H y ); Calculate the index of the current thread in the 2D plane, i x = t x + b x B x , i y = t y + b y B y ; Calculate the position where the first output data of the current thread is located, out = out + (i x + H x )(i y + H y )(D x + 2H x ) + r z l;

[0016] Calculate the number of data points separated in the 2D plane, l = (Dx +2H x )(D y +2H y );

[0017] Let k = 2r z , representing the index of the data block to be read currently along the z - direction;

[0018] If k < D z +2H z , perform the following operations:

[0019] a) Perform necessary thread synchronization;

[0020] b) Read new data into s mm ;

[0021] c) Rotate the pointer so that s mm points to the data of the original s m , s m points to the data of the original s c , ……, s pp points to the data of the original s mm ;

[0022] d) Execute the template calculation formula F;

[0023] e) Output the data to the position pointed to by out;

[0024] f) Adjust out to point to the next output position, out = out + l;

[0025] g) Re - compare k with D z +2H z for size comparison;

[0026] If k > D Z +2H Z , it means that all the output data calculations are completed.

[0027] Furthermore, the merged memory access reads a block of data on the two - dimensional plane, specifically including:

[0028] Obtain the thread block size B x 、B y and the redundant data width H x 、H y ;

[0029] Given other initial data: the pointer data of the input data, the two - dimensional grid plane size is (D x +2H x )×(D y +2H y) Assuming that the three-dimensional grid is stored as a one-dimensional array at the same time; the pointer s to the storage location of the read data in the GPU shared memory; the index t of the current active thread within the thread block x and t y ; the index b of the current active thread block within the entire GPU computing grid x and b y ;

[0030] Call the synchronization method of the GPU thread block to prevent the read data from overwriting the data being used;

[0031] Calculate the one-dimensional number of the current active thread within the thread block, Ind = t x + t y B x ;

[0032] Calculate the deformed shape of the thread block, R x = (B x + 2H x ) and

[0033] Calculate the index of the current thread after deformation, and where % and / are the remainder and integer division respectively;

[0034] Calculate the index of the data to be read by the current thread in the three-dimensional grid, and

[0035] Calculate the number of times each thread reads data,

[0036] Let k = 0;

[0037] If k < w, read data from the input data into the shared memory:

[0038] a) The brackets indicate referring to the corresponding element of the array;

[0039] b)

[0040] c) i y = i y + R y ;

[0041] The brackets indicate referring to the corresponding element of the array; d) k = k + 1; <00005(END]]

[0042] Once the reading is completed, compare the sizes of k and w again.

[0043] According to the second solution of the present invention, a GPU template computing device supporting coalesced memory access and circular queue is provided. The device includes:

[0044] The memory access merging unit is configured to merge the data read from the memory access for a block of data on a two-dimensional plane;

[0045] The template calculation unit is configured to perform template calculations based on a circular queue:

[0046] Given a three-dimensional template calculation problem: the template calculation formula F, the template radius r x 、r y and r z ; the three-dimensional grid D x ×D y ×D z ,the size of the surrounding halo region H x 、H y and H z ; the input data pointer data, the output data pointer out; initialize the pointers s mm , s m , s c , s p , s pp ; the thread block size B x 、B y ,the index b of the current thread block x 、b y ,the index t of the current thread x 、t y ;

[0047] Read the initial data block into the shared memory. Except for the first data block, s m , s m , s c , s p , s pp ;

[0048] Adjust the output data pointer to make it point to the correct position: calculate the number of data points separated on the two-dimensional plane, l = (D x +2H x )(D y +2H y ); calculate the index of the current thread on the two-dimensional plane, i x = t x +b x B x ,i y = t y +b y B y ; calculate the position where the first output data of the current thread is located, out = out+(i x +H x )+(i y +H y )(Dx +2H x )+r z l;

[0049] Calculate the number of data points at a distance in a two-dimensional plane, l = (D x +2H x )(D y +2H y );

[0050] Let k = 2r z , representing the index of the data block to be read currently along the z direction;

[0051] If k < D z +2H z , perform the following operations:

[0052] a) Perform necessary thread synchronization;

[0053] b) Read new data into s mm ;

[0054] c) Rotate the pointer so that s mm points to the data of the original s m , s m points to the data of the original s c , ……, s pp points to the data of the original s mm ;

[0055] d) Execute the template calculation formula F;

[0056] e) Output the data to the position pointed to by out;

[0057] f) Adjust put to point to the next output position, put = put + l;

[0058] g) Compare k with D z +2H z again;

[0059] If k > D z +2H z , it means that all output data calculations are completed.

[0060] Furthermore, the merged memory access unit is further configured to:

[0061] Obtain the thread block size B x , B x and the redundant data width H x , H y ;

[0062] Given other initial data: the pointer data of the input data, the size of the two-dimensional grid plane is (Dx +2H x ) × (D y +2H y ), assuming that the three-dimensional grid is stored as a one-dimensional array; the pointer s to the storage location of the read data in the GPU shared memory; the index t of the current active thread within the thread block x and t y ; the index b of the current active thread block within the entire GPU computing grid x and b y ;

[0063] Call the synchronization method of the GPU thread block to avoid overwriting the data being used by the read data;

[0064] Calculate the one-dimensional number of the current active thread within the thread block, Ind = t x + t y B x ;

[0065] Calculate the deformed shape of the thread block, R x = (B x + 2H x ) and

[0066] Calculate the index of the current thread after deformation, and where % and / are the remainder and integer division respectively;

[0067] Calculate the index of the data to be read by the current thread in the three-dimensional grid, and

[0068] Calculate the number of times each thread reads the data,

[0069] Let k = 0;

[0070] If k < w, read data from the input data to the shared memory:

[0071] a) where the parentheses indicate referring to the corresponding element of the array;

[0072] b)

[0073] c) i y = i y + R y ;

[0074] d) k = k + 1;

[0075] Once the reading is completed, compare the sizes of k and w again.

[0076] According to a third aspect of the present invention, there is provided a non-transitory computer-readable storage medium storing instructions, which, when executed by a processor, perform the methods according to the various embodiments of the present invention.

[0077] The GPU template calculation method supporting combined memory access and circular queue according to the various aspects of the present invention has at least the following technical effects:

[0078] 1) By making full use of the characteristics of GPU shared memory and combined memory access, a 2.5D block template calculation method based on a circular queue is invented, which can be applied to general templates and can improve the calculation efficiency of composite differential operators on the GPU.

[0079] 2) The circular queue on the shared memory ensures less data exchange during the calculation process and does not bring additional memory access pressure to the shared memory. At the same time, the operation of the circular queue is simple and can be applied to various mainstream GPUs. BRIEF DESCRIPTION OF THE DRAWINGS

[0080] In the drawings, which are not necessarily drawn to scale, the same reference numerals may describe similar components in different views. The same reference numerals with letter suffixes or different letter suffixes may represent different instances of similar components. The drawings generally illustrate various embodiments by way of example and not limitation, and are used together with the description and the claims to explain the embodiments of the invention. Where appropriate, the same reference numerals are used throughout the drawings to refer to the same or similar parts. Such embodiments are illustrative and not intended to be an exhaustive or exclusive embodiment of the device or method.

[0081] Figure 1 A schematic diagram of the deformation of a thread block for combined memory access is shown. In the figure, the upper white dotted area is the shape B of the thread block during the calculation process x ×B y , and the lower white striped area is the shape R of the thread block during the memory access process x ×R y . The two parts represent the same number of threads, but with different assumed shapes. The surrounding gray area is the halo area with a width of H x and H y . In this figure, the total data area is (B x +2H x )(B y +2H y ). In the case of combined memory access, it is required that is an integer (the case of w = 2 is demonstrated in the figure), and the meaning of w is that each thread block performs w memory access operations. To ensure that w is an integer, the transformed thread block should be able to span the entire data area to achieve coalesced memory access. Therefore, R x = B x + 2H x .

[0082] Figure 2 shows a schematic diagram of the circular queue method. This figure is divided into 4 sub - figures, which respectively represent the shared memory states at 4 different times. In the schematic diagram, the radius of the template calculation along the z - direction is r z = 2. The large square box in each sub - figure represents the shared memory, and the small parallelograms inside represent the data blocks located on the shared memory. s mm 、s m 、s c 、s p and s pp represent pointers to the data in the shared memory. In the initial state, 4 data blocks are first read into the shared memory, which come from z0, z1, z2, z3 respectively, and the pointer s mm does not point to any data temporarily; in the first iteration, a new data of z4 is read, and the pointer is rotated. Finally, s c points to the data of z2; in the second iteration, a new data of z5 is read to overwrite the data of z0, and the pointer is rotated. Finally, s c points to the data of z3; in the third iteration, a new data of z6 is read to overwrite the data of z1, and the pointer is rotated. Finally, s c points to the data of z4. The subsequent iterations follow the same pattern. Detailed implementation mode

[0083] To enable those skilled in the art to better understand the technical solution of the present invention, the present invention will be described in detail below in conjunction with the accompanying drawings and specific implementation modes. The embodiments of the present invention will be further described in detail below in conjunction with the accompanying drawings and specific examples, but it is not a limitation to the present invention. For the steps described herein, if there is no necessity for a sequential relationship between them, the order in which they are described as examples herein should not be regarded as a limitation. Those skilled in the art should know that they can adjust the order as long as the logic between them is not destroyed and the entire process cannot be realized.

[0084] The traditional 2.5D block template calculation method used on GPUs can well reuse the data on a certain axis (usually the z-axis), but it cannot achieve full coalesced memory access and is also difficult to apply to complex composite differential operators in computational physics. The memory access efficiency of modern GPUs is much lower than the computational efficiency, and computational applications that cannot utilize coalesced memory access are difficult to fully utilize the performance of GPUs. The purpose of the present invention is to establish a block template calculation method that combines a circular queue and coalesced memory access based on the traditional 2.5D block template calculation method, which can fully utilize the memory access performance of GPUs and is applicable to complex differential operators.

[0085] The principle of the present invention is as follows:

[0086] Given a three-dimensional template calculation problem, the entire grid can be divided into an interior and an exterior. The size of the interior is D x ×D y ×D z , and the size of the entire grid is (D x +2r x )×(D y +2r y )×(D z +2r z ), where r x , r y and r z are called the radii of the template along the three directions. For example, the first-order difference template of the differential operator only has a radius along the x direction, r x = 1, and the radii in the other two directions are both 0.

[0087] In 2.5D block template calculation, each GPU thread calculates one output at a time. Therefore, the D x ×D y data points inside the grid need to be divided into several blocks of B x ×B y , where B x ×B y is the size of the GPU two-dimensional thread block. If the interior of the grid is not sufficient to be exactly divided into an integer number of B x ×B y blocks, there are many ways to handle it, such as adding redundant data, adding logical judgments to skip calculations, and so on.

[0088] The template calculation method of the present invention regards the template calculation of a three-dimensional grid as multiple two-dimensional calculations, and calculates the values on one z-plane (i.e., the xy-plane) each time. For example, if the radius r zIf =2, then when calculating the z2 plane, data from 5 planes are needed: z0, z1, z2, z3, z4. At this time, z2 is called the current plane. When the calculation reaches the z3 plane, data from 5 planes z1, z2, z3, z4, z5 are needed. The data of the first 4 planes can be reused, and only the data of the 5th plane needs to be read. For any current plane z c , the 5 planes it uses can be denoted as z mm , z m , z c , z p , z pp . The data used by each thread block on the GPU comes from these 5 planes.

[0089] To be applicable to a general 3D template, first, each thread block needs to retain the complete data (data inside and outside the thread block) with a size of (B x + 2r x ) × (B y + 2r y ). For the shared memory in a GPU computing unit, denote its pointer (or reference) as s. At the start of the calculation, allocate a space of size 5(B x + 2r x ) × (B y + 2r y ) to store the data required for the current calculation, and use 5 pointers to point to the starting points of 5 blocks of data respectively: s mm , s m , s c , s p , s pp . At the start of the first calculation, the initial 5 blocks of data need to be read into the shared memory. After that, only one block of data needs to be read for each subsequent calculation. The following separately describes the circular queue operation and merged memory access when reading data.

[0090] 1) Circular queue operation. The currently used data is the data pointed to by 5 pointers s mm , s m , s c , s p , s pp , that is, the data on z n , z n+1 , z n+2 , z n+3 , z n+4 . After the calculation is completed, the data z mm pointed to by s n will no longer be used in the future, and the newly read data z n+5 should be stored in s mmThe pointed shared memory location, thus avoiding repeated data swapping in the shared memory. To save data movement operations, it is also necessary to ensure that the next plane calculation still uses these 5 pointers. Therefore, a rotation operation needs to be performed on these 5 pointers so that s pp , s mm , s m , s c , s p point to z n+5 , z n+1 , z n+2 , z n+3 , z n+4 respectively. Through this rotation method of the circular queue, each time the data on a plane is read, only the pointer pointing needs to be adjusted, instead of adjusting the actual data position on the shared memory.

[0091] 2) Merge memory access. The size B x ×B y of each GPU thread block corresponds to the size of the output data block, while the size of the input data block is (B x +2r x )×(B y +2r y ). The template calculation without merged memory access will first read in data of size B x [[ID=�7]]×B y , and then dispatch some threads to read the surrounding data. To merge memory access, the thread block should adopt different shapes when reading data and during calculation, but the total number of threads remains unchanged. For this purpose, some redundant data is added to the entire input grid along the x and y directions, and the data with widths of r x and r y at the boundary is widened to H x and H y respectively. At the same time, the data read by each thread block is changed to (B x +2H x )×(B y +2H y ). The present invention adopts the simplest method for selecting the thread block shape, that is, the thread block size satisfies is an integer. When w is an integer, the data size read by each thread block is exactly an integer multiple of the number of threads. Therefore, the shape of the thread block reading data can be changed to Each thread block reads data in this shape w times, and each time memory access can be merged, greatly reducing the overhead of reading data. In actual calculation, w is usually 2.

[0092] When the basic working principle of the present invention is clear, the specific implementation method of the GPU template calculation method that supports merged memory access and circular queue is described in two parts, and the behavior of the thread block is described from the perspective of the GPU. The first part is to read a block of data on the two-dimensional plane using merged memory access, and this method is denoted as ReadSlice; the second part is the entire template calculation method based on the circular queue, denoted as StencilCQ.

[0093] The process of reading a block of data on the two-dimensional plane using merged memory access, and the implementation process of ReadSlice is as follows:

[0094] 1. By the method of selecting the thread block size for merged memory access (using an existing method, not within the scope of the present invention), obtain the thread block size B that can achieve merged memory access x 、B y and the redundant data width H x 、H y ;

[0095] 2. Given other initial data:

[0096] a) The pointer data of the input data, and the size of the two-dimensional grid plane is (D x + 2H x ) × (D y + 2H y ), and it is assumed that the three-dimensional grid is stored as a one-dimensional array;

[0097] b) The pointer s to the storage location of the read data on the GPU shared memory;

[0098] c) The index t of the current active thread within the thread block x and t y ;

[0099] d) The index b of the current active thread block within the entire GPU computing grid x and b y ;

[0100] 3. Call the synchronization method of the GPU thread block to avoid the read data overwriting the data being used;

[0101] 4. Calculate the one-dimensional number of the current active thread within the thread block, Ind = t x + t y B x ;

[0102] 5. Calculate the deformed shape of the thread block, R x = (B x + 2H x ) and As Figure 1 shown;

[0103] 6. Calculate the index of the current thread after transformation, and where % and / are modulo and integer division respectively;

[0104] 7. Calculate the index of the data to be read by the current thread in the three-dimensional grid, and

[0105] 8. Calculate the number of times each thread reads data,

[0106] 9. Let k = 0;

[0107] 10. If k < w, read data from the input data to the shared memory:

[0108] a) where the parentheses indicate referring to the corresponding element of the array;

[0109] b)

[0110] c) i y = i y + R y ;

[0111] d) k = k + 1;

[0112] After one read, go to 10;

[0113] 11. End.

[0114] The implementation process of the entire template calculation method based on the circular queue, StencilCQ (taking the template with a radius of 2 in three directions as an example) is as follows:

[0115] 1. Given a three-dimensional template calculation problem:

[0116] a) Template calculation formula F, template radius r x 、r y and r z ;

[0117] b) Three-dimensional grid D x ×D y ×D z ,surrounding halo region size H x 、H y and H z ;

[0118] c) Input data pointer data, output data pointer out;

[0119] d) Initialize the pointer s pointing to different data blocks in the shared memory mm,s m ,s c ,s p ,s pp (If the z - direction radius increases, the number of pointers is increased accordingly. To adapt to the radius change, an array of pointers can be used);

[0120] e) Thread block size B x 、B y , the index b of the current thread block x 、b y , the index t of the current thread x 、t y ;

[0121] 2. Use ReadSlice to read the initial data block into shared memory, except for the first data block, s m ,s m ,s c ,s p ,s pp ;

[0122] 3. Adjust the output data pointer to point to the correct position:

[0123] a) Calculate the number of data points separated in the two - dimensional plane, l=(D x + 2H x )(D y + 2H y );

[0124] b) Calculate the index of the current thread in the two - dimensional plane, i x = t x + b x B x , i y = t y + b y B y ;

[0125] c) Calculate the position where the first output data of the current thread is located, out = out+(i x + H x )+(i y + H y )(D x + 2H x )+r z l;

[0126] 4. Calculate the number of data points separated in the two - dimensional plane, l=(D x + 2H x )(D y + 2H y );

[0127] 5. Let k = 2r z , representing the index of the data block to be read currently along the z - direction;

[0128] 6. If k < D z +2H z , perform the following operations such as memory access, rotation, and calculation:

[0129] a) Perform necessary thread synchronization;

[0130] b) Read new data into s mm ;

[0131] c) Rotate the pointer so that s mm points to the data of the original s m , s m points to the data of the original s c , ……, s pp points to the data of the original s mm , as shown in [[ID=?]] Figure 2 ;

[0132] d) Execute the template calculation F;

[0133] e) Output the data to the position pointed to by out;

[0134] f) Adjust out to point to the next output position, out = out + l;

[0135] g) Jump to 6

[0136] Otherwise, jump to 7.

[0137] 7. After all output data calculations are completed, end.

[0138] The embodiment of the present invention also provides a GPU template calculation device supporting combined memory access and circular queue. The device includes:

[0139] A combined memory access unit configured to combine memory access to read a block of data on a two - dimensional plane;

[0140] A template calculation unit configured to perform template calculation based on a circular queue:

[0141] Given a three - dimensional template calculation problem: template calculation formula F, template radius r x , r y and r z ; three - dimensional grid D x ×D y ×D z , the size of the surrounding halo region H x , H y and H z Note: There seems to be a missing number in the reference for "as shown in Figure 2 ". It should be something like "as shown in Figure X". Also, some of the tags might be specific to a particular system or context that is not fully clear without additional background information.; Input data pointer data, output data pointer out; Initialize the pointers s that point to different data blocks in the shared memory mm , s m , s c , s p , s pp ; Thread block size B x 、B y , the index b of the current thread block x 、b y , the index t of the current thread x 、t y ;

[0142] Read the initial data block into the shared memory, except for the first data block, s m , s m , s c , s p , s pp ;

[0143] Adjust the output data pointer to point to the correct position: Calculate the number of data points separated in the two-dimensional plane, l = (D x + 2H x )(D y + 2H y ); Calculate the index of the current thread in the two-dimensional plane, i x = t x + b x B x , i y = t y + b y B y ; Calculate the position where the first output data of the current thread is located, out = out + (i x + H x )(i y + H y )(D x + 2H x ) + r z l;

[0144] Calculate the number of data points separated in the two-dimensional plane, l = (D x + 2H x )(D y + 2H y );

[0145] Let k = 2r z , indicating the index along the z direction of the data block that should be read in currently;

[0146] If k < D z + 2H z , perform the following operations:

[0147] a) Perform necessary thread synchronization;

[0148] b) Read new data into s mm ;

[0149] c) Rotate the pointer so that s mm points to the data of the original s m data, s m points to the data of the original s c data, ……, s pp points to the data of the original s mm data;

[0150] d) Execute the template calculation formula F;

[0151] e) Output data to the position pointed to by out;

[0152] f) Adjust out to point to the next output position, out = out + l;

[0153] g) Re - compare the magnitudes of k and D z + 2H z ;

[0154] If k > D z + 2H z , it means that all output data calculations are completed.

[0155] In some embodiments, the merged memory access unit is further configured to:

[0156] Obtain the thread block size B x of the merged memory access, B y and the redundant data width H x of the merged memory access, H y ;

[0157] Given other initial data: the pointer data of the input data, the two - dimensional grid plane size is (D x + 2H x ) × (D y + 2H y ), and assuming that the three - dimensional grid is stored as a one - dimensional array; the pointer s to the storage location of the read data on the GPU shared memory; the index t x of the current active thread within the thread block and t y ; the index b x of the current active thread block within the entire GPU computing grid and b y ;

[0158] Call the synchronization method of the GPU thread block to avoid the read data from overwriting the data being used;

[0159] Calculate the one-dimensional number of the current active thread within the thread block, Ind = t x + t y B x ;

[0160] Calculate the deformed shape of the thread block, R x = (B x + 2H x ) and

[0161] Calculate the index of the current thread after deformation, and where % and / are the remainder and integer division respectively;

[0162] Calculate the index of the data to be read by the current thread in the three-dimensional grid, and

[0163] Calculate the number of times each thread reads data,

[0164] Let k = 0;

[0165] If k < w, read data from the input data to the shared memory:

[0166] a) where the parentheses indicate referring to the corresponding element of the array;

[0167] b)

[0168] c)i y = y + y ;

[0169] d)k = k + 1;

[0170] Once the reading is complete, compare the sizes of k and w again.

[0171] It should be noted that the device provided in the embodiments of the present invention belongs to the same technical concept as the previously provided method, has the same technical principle and can achieve the same technical effect, which will not be elaborated here.

[0172] The embodiments of the present invention also provide a non-transitory computer-readable storage medium storing instructions, which when executed by a processor, execute the methods according to the various embodiments of the present invention.

[0173] In addition, although exemplary embodiments have been described herein, the scope includes any and all embodiments based on the present invention that have equivalent elements, modifications, omissions, combinations (e.g., schemes that cross various embodiments), adaptations, or alterations. The elements in the claims will be broadly interpreted based on the language employed in the claims and are not limited to the examples described in this specification or during the implementation of this application, and the examples will be construed as non-exclusive. Thus, this specification and the examples are intended to be considered only as examples, and the true scope and spirit are indicated by the following claims and the full scope of their equivalents.

[0174] The above description is intended to be illustrative and not restrictive. For example, the above examples (or one or more aspects thereof) can be used in combination with each other. For example, those of ordinary skill in the art can use other embodiments when reading the above description. Additionally, in the above detailed description, various features can be grouped together to simplify the present invention. This should not be construed as an intention that the features of an unclaimed invention are necessary for any claim. On the contrary, the subject matter of the present invention can be less than all the features of a particular embodiment of the invention. Thus, the following claims are hereby incorporated into the detailed description as examples or embodiments, where each claim independently serves as a separate embodiment, and it is contemplated that these embodiments can be combined with each other in various combinations or permutations. The scope of the present invention should be determined with reference to the appended claims and the full scope of the equivalents to which those claims are entitled.

Claims

1. A GPU template calculation method supporting combined memory access and circular queue, characterized in that The method includes: Combining to access and read a block of data on a two-dimensional plane; Template calculation based on a circular queue: Given 3D template calculation problem: template calculation formula F, template radius r x 、r y and r z ,where r x 、r y and r z are the radii of the template along three directions; 3D grid D x ×D y ×D z , the size H of the surrounding halo region x 、H y and H z ; input data pointer data, output data pointer out; initialize pointers s mm ,s m ,s c ,s p ,s pp ; thread block size B x 、B y , the index b of the current thread block x 、b y , the index t of the current thread x 、t y ; Read the initial data blocks except the first block of data into the shared memory, s m ,s c ,s p ,s pp ; Adjust the output data pointer to point it to the correct position: Calculate the number of data points separated in the two-dimensional plane, l = (D x +2H x )(D y +2H y );Calculate the index of the current thread in the two-dimensional plane, i x =t x +b x B x ,i y =t y +b y B y ;Calculate the position where the first output data of the current thread is located, out = out + (i x +H x )+(i y +H y )(D x +2H x )+r z l; Calculate the number of data points separated in a two-dimensional plane, l = (D x + 2H x )(D y + 2H y ); Let k = 2r z , representing the index of the data block to be read currently along the z - direction; If k < D z +2H z , perform the following operations: a) Performing thread synchronization; b) Read new data into s mm ; c) Rotate the pointer so that s mm points to the original s m 's data, s m points to the original s c 's data,..., s pp points to the original s mm 's data; d) Executing the template calculation formula F; e) Outputting data to the position pointed to by out; f) Adjusting out to point to the next output position, out = out + l; g) Compare k and D again z +2H z for their magnitudes; If k > D z +2H z , it means that all the output data calculations are completed.

2. The method according to claim 1, wherein The combining to access and read a block of data on a two-dimensional plane specifically includes: Obtain the thread block size B for combined memory access x 、B y and the redundant data width H x 、H y ; Given other initial data: a pointer data to the input data, a two-dimensional grid plane with a size of (D x +2H x )×(D y +2H y ), and the three-dimensional grid is stored as a one-dimensional array; a pointer s to the storage location of the read data in the GPU shared memory; the index t x and t y of the current active thread within the thread block; the index b x and b y of the current active thread block within the entire GPU computing grid; Invoking the synchronization method of the GPU thread block; Calculate the one-dimensional number of the current active thread within the thread block, Ind = t x + t y B x ; Calculate the shape of the warped thread block, R x = (B x + 2H x ) and Calculate the index of the current thread after transformation, and where % and / are the remainder and integer division respectively; Calculate the index of the data to be read by the current thread in the three-dimensional grid, and Calculate the number of times each thread reads data, Let k = 0; If k < w, reading data from the input data into the shared memory: a) wherein the parentheses indicate corresponding elements of an array; b) c)i y = i y + R y ; d) k = k + 1; After one read is completed, comparing the sizes of k and w again.

3. A GPU template computing device that supports merged memory access and circular queue, characterized in that, The device includes: A combined memory access unit configured to combine memory access to read a block of data on a two-dimensional plane; A template calculation unit configured to perform template calculation based on a circular queue: Given a 3D template calculation problem: template calculation formula F, template radius r x 、r y and r z where r x 、r y and r z are the radii of the template along three directions; 3D grid D x ×D y ×D z , surrounding halo region size H x 、H y and H z ; input data pointer data, output data pointer out; initialize pointers s mm ,s m ,s c ,s p ,s pp ; thread block size B x 、B y , index b x 、b y of the current thread block, index t x 、t y ; Read the initial data blocks except the first block of data into the shared memory, s m ,s c ,s p ,s pp ; Adjust the output data pointer to point it to the correct position: Calculate the number of data points in the two-dimensional plane, l = (D x +2H x )(D y +2H y );Calculate the index of the current thread in the two-dimensional plane, i x =t x +b x B x ,i y =t y +b y B y ;Calculate the position where the first output data of the current thread is located, out = out + (i x +H x )+(i y +Hy ) (D x +2H x )+r z l; Calculate the number of data points separated in a two-dimensional plane, l = (D x + 2H x )(D y + 2H y ); Let k = 2r z , representing the index of the data block to be read currently along the z direction; If k < D z +2H z , perform the following operations: a) Performing thread synchronization; b) Read new data into s mm ; c) Rotate the pointer so that s mm points to the original s m 's data, s m points to the original s c 's data,..., s pp points to the original s mm 's data; d) Executing the template calculation formula F; e) Outputting data to the position pointed to by out; f) Adjusting out to point to the next output position, out = out + l; g) Re-compare the magnitudes of k and D z +2H z ; If k > D z +2H z , it means that all the output data calculations are completed.

4. The device according to claim 3, characterized in that, The combined memory access unit is further configured to: Obtain the thread block size B for combined memory access x 、B y and the redundant data width H x 、H y ; Given other initial data: a pointer data to the input data, a two-dimensional grid plane of size (D x +2H x ) × (D y +2H y ), and a three-dimensional grid is stored as a one-dimensional array; a pointer s to the storage location of the read data on the GPU shared memory; the index t x and t y of the current active thread within the thread block; the index b x and b y of the current active thread block within the entire GPU computing grid; Invoke the synchronization method of the GPU thread block; Calculate the one-dimensional number of the current active thread within the thread block, Ind = t x + t y B x ; Calculate the shape of the transformed thread block, R x =(B x + 2H x ) and Calculate the index of the current thread after transformation, and where % and / are the remainder and integer division respectively; Calculate the index of the data to be read by the current thread in the three-dimensional grid, and Calculate the number of times each thread reads data, Let k = 0; If k < w, reading data from the input data into the shared memory: a) wherein the parentheses indicate corresponding elements of the reference array; b) c)i y = i y + R y ; d) k = k + 1; After one read is completed, comparing the sizes of k and w again.

5. A non-transitory computer-readable storage medium storing instructions, which when executed by a processor, execute the method according to any one of claims 1 to 2.

Citation Information

Patent Citations

  • Rhombus partition parallel optimization method for template calculation

    CN111381886A

  • Systems and methods for mapping a neighborhood of data to general registers of a processing element

    US8423745B1