Multi-entity cluster model parallel simulation method based on directed graph
By decomposing the entity simulation model and building directed graphs, the basic operator unit is encapsulated into a kernel function, and parallel computing is performed on the GPU, the problem of low computing efficiency of existing clusters is solved, and efficient parallel computing and real-time simulation are realized.
Patent Information
- Application Number
- CN202411801033.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-09
- Publication Date
- 2025-03-11
AI Technical Summary
The computing efficiency of existing cluster parallel simulation is low and cannot meet the computing requirements of entity cluster simulation.
By decomposing the entity simulation model, a directed graph of the entity simulation model is constructed, the basic operator unit is encapsulated into a kernel function, and the number of thread bundles is determined based on the maximum number of branches of the kernel function. At each moment, the kernel functions that can be computed in parallel are determined based on the directed graph, and their calculation instructions are sent to the GPU, and the corresponding number of threads are generated for parallel calculations, and the data of each thread is determined through reference remapping.
It improves the efficiency of parallel computing, meets the real-time requirements of entity cluster simulation, and avoids the reduction in computing efficiency caused by thread beam differentiation.
Smart Images

Figure CN119597486A_ABST
Abstract
Description
Technical Field
[0001] The invention relates to the technical field of cluster simulation, and in particular to a directed graph-based multi-entity cluster model parallel simulation method. Background Art
[0002] Modern cluster simulation has put forward many new requirements compared with traditional single-body simulation. Traditional single-body simulation is driven by time, uses the CPU as a processor, and executes the simulation program serially. That is, a physical model is placed in a thread, and the thread executes the calculation inside the model serially during simulation. For single-body simulation, the simulation step length gradually shortens, and the control algorithm and physical functions gradually become more complex; for physical cluster simulation, the most direct manifestation is that there are many simulation nodes, and the simulation platform requires powerful computing power. These requirements put forward very stringent requirements on the computing efficiency of the simulation platform.
[0003] In recent years, GPU parallel computing has been widely used in many fields such as neural networks, image processing, radar simulation, and complex control system simulation, and has achieved remarkable results. The existing cluster parallel simulation uses single-threaded solution, that is, a physical model is placed in one thread, and the thread performs the calculation inside the model serially during simulation. The existing cluster model parallel simulation calculation efficiency is low. Summary of the invention
[0004] In view of the above analysis, an embodiment of the present invention aims to provide a multi-entity cluster model parallel simulation method based on a directed graph, so as to solve the problem of low computational efficiency of existing cluster parallel simulation.
[0005] On the one hand, an embodiment of the present invention provides a directed graph-based multi-entity cluster model parallel simulation method, comprising the following steps:
[0006] Decomposing the entity simulation model into basic operator units, and constructing a directed graph of the entity simulation model according to the data flow dependency relationship between the basic operator units;
[0007] Encapsulate each basic operator unit into a kernel function; determine the number of thread bundles required for each kernel function based on the number of entities in the cluster and the maximum number of branches of each kernel function;
[0008] At each moment, the kernel function that can be calculated in parallel at the current moment is determined based on the directed graph of the entity simulation model; the calculation instructions of the kernel function that can be calculated in parallel at the current moment are simultaneously sent to the GPU;
[0009] The GPU generates threads corresponding to each kernel function according to the number of thread bundles required by each kernel function, which are used to process the data of the corresponding entity and complete the calculation; when executing the branch calculation instructions of the kernel function, the entity corresponding to each thread is re-determined through double reference remapping.
[0010] Based on the further improvement of the above method, the entity simulation model is decomposed into basic operator units, and a directed graph of the entity simulation model is constructed according to the data flow dependency relationship between the basic operator units, including:
[0011] Decompose the entity simulation model into sub-models that can be simulated in parallel;
[0012] For each sub-model, the sub-model is decomposed into basic operator units according to the functional points; a directed graph of the basic operator units of each sub-model is constructed with the basic operator units as nodes and the data flow dependencies between the basic operator units as edges to obtain a directed graph of the entity simulation model.
[0013] Based on the further improvement of the above method, the kernel function that can be calculated in parallel at the current moment is determined based on the directed graph of the entity simulation model, including:
[0014] If the current moment is the first moment of the frame period, the kernel function that can be calculated in parallel at the current moment is the kernel function corresponding to each node connected by the directed edge starting from the initial node in the directed graph of the entity simulation model;
[0015] Otherwise, the candidate node is determined based on the kernel function calculated in parallel at the last moment;
[0016] For each candidate node, if the kernel functions corresponding to all the starting points of the directed edges connected with the candidate node as the end point have been calculated, the kernel function corresponding to the candidate node is used as the kernel function that can be calculated in parallel at the current moment.
[0017] Based on the further improvement of the above method, the candidate nodes are determined according to the kernel function calculated in parallel at the last moment, including:
[0018] For each kernel function calculated in parallel at the last moment, each end point connected by all directed edges starting from the node corresponding to the kernel function in the directed graph is taken as a candidate node.
[0019] Based on the further improvement of the above method, the GPU side generates threads corresponding to each kernel function according to the number of thread bundles required by each kernel function, which are used to process the data of the corresponding entity and complete the calculation; when executing the branch calculation instruction of the kernel function, the entity corresponding to each thread is re-determined through double reference remapping, including:
[0020] For each kernel function, a parallel computing thread corresponding to the kernel function is generated and the original ID and index ID of the thread are determined. The index ID of the thread is used to determine the entity corresponding to the thread.
[0021] If the current instruction to be executed is a branch calculation instruction, each current valid thread determines the group, block and position in the block to which the entity corresponding to the current index ID of the valid thread belongs according to the branch judgment condition;
[0022] Redirect references to each thread bundle and determine the grouping corresponding to each thread bundle; redirect references to each thread according to the grouping corresponding to the thread bundle to which the thread belongs, determine the block corresponding to the thread and the position in the block, and obtain a new index ID for the thread;
[0023] If the current instruction to be executed is a branch calculation end instruction, the index ID value of each thread is modified to the original ID value;
[0024] Otherwise, each thread determines whether the thread is valid according to the index ID. If so, the entity corresponding to the thread is determined according to the index ID, and the calculation of the current instruction to be executed is performed.
[0025] Based on the further improvement of the above method, each current valid thread determines the group, block and position in the block to which the entity corresponding to the current index ID of the valid thread belongs according to the branch judgment condition, specifically including:
[0026] Determine the group to which the entity corresponding to the current index ID of the valid thread belongs according to the branch judgment condition;
[0027] Determine the block to which the entity belongs in the group according to the entity ID;
[0028] Atomically calculate the position of an entity within its chunk.
[0029] Based on the further improvement of the above method, reference redirection is performed on each thread warp to determine the group corresponding to each thread warp, including:
[0030] Determine the number of warps required for each group and the warp start index and warp end index of each group according to the number of entities in each block in each group;
[0031] The group corresponding to each warp is obtained according to the warp start index and the warp end index of each group.
[0032] Based on the further improvement of the above method, the number of thread warps required for each group is determined by the following formula according to the number of entities in each block in each group:
[0033]
[0034] Among them, b ij represents the number of entities in the jth block in the i-th group, m i represents the number of blocks in the i-th group, wi represents the number of thread warps required for the i-th group, w c Indicates the warp size.
[0035] Based on the further improvement of the above method, the following formula is used to calculate the thread warp start index and thread warp start index of each group:
[0036]
[0037] Among them, w j represents the number of thread warps required for the jth group, gS i represents the starting index of the thread warp of the i-th group, gE i Indicates the warp end index of the i-th group.
[0038] Based on the further improvement of the above method, each thread redirects the reference of the thread according to the group corresponding to the thread warp to which the thread belongs, determines the block corresponding to the thread and the position in the block, and obtains the new index ID of the thread, including:
[0039] Each thread calculates the thread start index and thread end index corresponding to each block in the group corresponding to the thread warp to which the thread belongs;
[0040] Calculate the neighborhood index of the thread according to the thread warp start index of the group corresponding to the thread warp to which the thread belongs;
[0041] Determine the block corresponding to the thread according to the thread start index and thread end index corresponding to each block in the group corresponding to the thread warp to which the thread belongs, and the neighborhood index of the thread;
[0042] The position of the block corresponding to the thread is determined according to the neighborhood index of the thread and the thread start index of the block corresponding to the thread, and a new index ID of the thread is obtained.
[0043] Compared with the prior art, the present invention decomposes the entity simulation model to construct a directed graph of the entity simulation model, encapsulates the basic operator units into kernel functions, and determines the number of thread bundles corresponding to them, thereby determining the current kernel function that can be calculated in parallel at each moment based on the directed graph, and simultaneously sending the calculation instructions of the kernel functions that can be calculated in parallel at the current moment to the GPU, generating a corresponding number of threads for each kernel function on the GPU side, and determining which entity corresponding to which data is executed by each thread by reference remapping, not only performing parallel calculations at the model level, but also realizing parallel calculations for the basic operator units inside the model, thereby improving the efficiency of parallel calculations and meeting the real-time requirements of entity cluster simulation.
[0044] In the present invention, the above-mentioned technical solutions can also be combined with each other to achieve more preferred combination solutions. Other features and advantages of the present invention will be described in the subsequent description, and some advantages can become obvious from the description, or can be understood by practicing the present invention. The purpose and other advantages of the present invention can be realized and obtained through the contents particularly pointed out in the description and the drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0045] The accompanying drawings are only used for the purpose of illustrating specific embodiments and are not to be considered as limiting the present invention. In the entire drawings, the same reference symbols represent the same components;
[0046] Figure 1 A flowchart of a parallel simulation method for a multi-entity cluster model based on a directed graph according to an embodiment of the present invention;
[0047] Figure 2 It is a decomposition schematic diagram of an entity cluster model according to an embodiment of the present invention;
[0048] Figure 3 It is a directed graph of an embodiment of the present invention. DETAILED DESCRIPTION
[0049] The preferred embodiments of the present invention are described in detail below in conjunction with the accompanying drawings, wherein the accompanying drawings constitute a part of this application and are used together with the embodiments of the present invention to illustrate the principles of the present invention, but are not used to limit the scope of the present invention.
[0050] A specific embodiment of the present invention discloses a parallel simulation method for a multi-entity cluster model based on a directed graph, such as Figure 1 As shown, the following steps are included:
[0051] S1. Decomposing the entity simulation model into basic operator units, and constructing a directed graph of the entity simulation model according to the data flow dependency relationship between the basic operator units;
[0052] S2. Encapsulate each basic operator unit into a kernel function; determine the number of thread bundles required for each kernel function according to the number of entities in the cluster and the maximum number of branches of each kernel function;
[0053] S3. At each moment, determine the kernel function that can be calculated in parallel at the current moment based on the directed graph of the entity simulation model; and send the calculation instructions of the kernel function that can be calculated in parallel at the current moment to the GPU at the same time;
[0054] S4. The GPU generates threads corresponding to each kernel function according to the number of thread bundles required by each kernel function, which are used to process the data of the corresponding entity and complete the calculation; when executing the branch calculation instruction of the kernel function, the entity corresponding to each thread is re-determined through double reference remapping.
[0055] It should be noted that the multi-entity cluster is, for example, a vehicle cluster, a robot cluster, etc., and the entity simulation model is, for example, a car simulation model, a robot simulation model. The simulation is driven by the CPU, and the calculation of all entity models needs to be completed in each frame period, that is, the calculation of all kernel functions in the directed graph needs to be completed. Each moment is each moment in the frame period.
[0056] Compared with the prior art, the directed graph-based parallel simulation method for multi-entity cluster models provided in this embodiment decomposes the entity simulation model to construct a directed graph of the entity simulation model, encapsulates the basic operator units into kernel functions, and determines the number of thread bundles corresponding to them, thereby determining the current kernel function that can be calculated in parallel based on the directed graph at each moment, and simultaneously sending the calculation instructions of the kernel functions that can be calculated in parallel at the current moment to the GPU, generating a corresponding number of threads for each kernel function on the GPU side for processing the data of the corresponding entity, and when executing the branch calculation instructions of the kernel function, re-determining which entity's corresponding data is executed by each thread by referencing remapping, not only performing parallel calculations at the model level, but also realizing parallel calculations for the basic operator units inside the model, thereby improving the efficiency of parallel calculations and meeting the real-time requirements of entity cluster simulation.
[0057] In entity cluster simulation, each entity-level model is instantiated to achieve parallel execution of multiple instantiated objects. A single entity model contains sub-models that run in parallel. For example, the corresponding sub-models of a car's engine, gearbox, brake, etc. are modeled with reference to the physical world. In the physical world, each sub-model works in parallel. After modeling, it can be executed in parallel. Each sub-model is mainly composed of operator units such as interpolation calculations and model equations. Each operator unit has input parameters and output parameters, which are called data-level operators. If there is no dependency between the input parameters of two operator units, parallel calculations can be performed.
[0058] Therefore, the entity simulation model is decomposed into basic operator units, and a directed graph of the entity simulation model is constructed according to the data flow dependency relationship between the basic operator units, including:
[0059] Decompose the entity simulation model into sub-models that can be simulated in parallel;
[0060] For each sub-model, the sub-model is decomposed into basic operator units according to the functional points; a directed graph of the basic operator units of each sub-model is constructed with the basic operator units as nodes and the data flow dependencies between the basic operator units as edges to obtain a directed graph of the entity simulation model.
[0061] It should be noted that the constructed directed graph is a directed acyclic graph.
[0062] During implementation, for example, if the entity is a vehicle, a simulation model of an entity includes a driver model sub-model, a transmission system sub-model, a brake sub-model, etc. that can be simulated in parallel, forming a parallelism at the sub-model level. Then, each sub-model is decomposed into basic operator units according to the functional points of the sub-model. For example, the functional points of the driver model sub-model include: vehicle loss torque calculation, vehicle correction torque calculation, request torque, etc. The parallel decomposition is as follows: Figure 2 shown.
[0063] For example, if the entity is a robot, a physical simulation model includes a body sub-model, a drive sub-model and a sensor system sub-model. The body sub-model includes basic operator units such as kinematics calculation and dynamics calculation, the drive system sub-model includes basic calculation units such as reducer calculation and DC motor calculation, and the sensor system sub-model includes rigid force sensor calculation and rigid torque sensor calculation.
[0064] Then, according to the data flow dependency, a directed acyclic graph (DAG) is constructed for each sub-model, G = (V, L), the node set V represents the basic operator unit, such as automobile loss torque calculation, automobile correction torque calculation, etc., and the edge set L represents the node dependency. The nodes with in-degree 0 of the sub-model are connected together through the initial node to obtain the directed graph of the physical simulation model, such as Figure 3 shown.
[0065] After obtaining the basic operator unit, each basic operator unit is encapsulated into a kernel function; the number of thread bundles required for each kernel function is determined according to the number of entities in the cluster and the maximum number of branches of each kernel function.
[0066] Before performing parallel computing, it is necessary to encapsulate the object of parallel computing, such as a basic computing unit, into a kernel function and determine the thread grid of the kernel function, that is, the number of threads. When performing parallel computing on the GPU side, sufficient threads are generated according to the thread grid to complete the parallel computing.
[0067] Branches, such as if-else statements, execute different instructions based on different judgment conditions. A set of branch calculation instructions is a branch calculation instruction that is divided into one or more execution paths based on the same judgment object.
[0068] Each thread bundle of the GPU performs calculations according to the SIMD (Single Instruction Multiple Date) parallel computing architecture, that is, the same instruction is executed in parallel within the thread bundle. This computing architecture will cause thread bundle differentiation in the branch selection stage of the model, converting full parallelism into grouped serial execution, reducing computing efficiency. The existing thread bundle optimization algorithm is determined according to the number of instances of parallel computing. For example, for a basic operator unit, the number of entities in the cluster will generate a corresponding number of threads when performing parallel computing on the basic operator unit. Therefore, even after optimization, differentiation problems are still inevitable, that is, threads within the same thread bundle are converted from full parallelism to grouped serial execution due to executing different branches, thereby reducing computing efficiency.
[0069] The present invention determines the number of thread bundles required by the kernel function according to the number of entities in the cluster and the maximum number of branches of the kernel function, thereby ensuring that there are enough thread bundles for parallel calculation each time a branch calculation of the kernel function is encountered, thereby shortening the calculation time and improving the calculation efficiency.
[0070] Specifically, the number of thread warps required for each kernel function is determined using the following formula based on the number of entities in the cluster and the maximum number of branches of each kernel function:
[0071]
[0072] Where g represents the number of thread warps, x represents the number of entities in the cluster, and w c Indicates the warp size, n indicates the maximum number of branches in the kernel function. The warp size is the number of threads in the warp.
[0073] The thread grid is mainly used to determine the number of threads started by the kernel function. To ensure that each thread bundle does not split, the required number of thread bundles is determined using formula (1) based on the number of entities in the cluster and the maximum number of branches of the kernel function.
[0074] For example, there is a set of branches inside the kernel function calculated as:
[0075] if(yy1>0){
[0076] }
[0077] else{
[0078] }
[0079] Another set of branches is calculated as:
[0080] if(yy2>16){
[0081] }
[0082] else if(yy2>0){
[0083] }
[0084] else{
[0085] }
[0086] Then the maximum number of branches is the number of branches calculated by the second set of branches, 3.
[0087] If the number of thread warps required for the kernel function is calculated as 3 according to formula (1), then 3 thread warps need to be started to ensure that no differentiation problem occurs when the thread warps are executed in parallel.
[0088] It should be noted that the GPU cannot perform independent computing, but can only be used as a coprocessor to form a heterogeneous computing platform with the CPU to complete computing tasks. The collaborative work of the two lays the foundation for asynchronous computing. The CPU plays a control role and is called the host, and the GPU completes the calculation and is called the device. During implementation, the decomposition of the physical model and the construction of the directed graph in step S1 are completed on the CPU side, and step S2 encapsulates each basic operator unit into a kernel function and determines the number of threads required for each kernel function, that is, the thread grid. The encapsulated kernel function and the input parameters corresponding to the kernel function can be stored in the GPU's memory in advance. The thread grid is included in the kernel function calculation instruction. When the calculation instruction is issued, the corresponding number of threads can be generated on the GPU side for parallel calculation.
[0089] When performing physical cluster simulation, the host side controls the time advancement and issues calculation instructions to the device side in each frame cycle. The device side generates a corresponding number of threads according to the instructions and completes the calculation of the kernel function. It should be noted that the input data required by the kernel function can be stored in the GPU memory in advance according to the application scenario, or it can be sent to the GPU during simulation.
[0090] Therefore, at each moment of the frame period, the host side needs to determine which kernel function calculation instructions to issue, that is, determine which kernel functions can be calculated in parallel at the current moment.
[0091] Specifically, the kernel function that can be calculated in parallel at the current moment is determined based on the directed graph of the entity simulation model, including:
[0092] If the current moment is the first moment of the frame period, the kernel function that can be calculated in parallel at the current moment is the kernel function corresponding to each node connected by the directed edge starting from the initial node in the directed graph of the entity simulation model;
[0093] Otherwise, the candidate node is determined based on the kernel function calculated in parallel at the last moment;
[0094] For each candidate node, if the kernel functions corresponding to all the starting points of the directed edges connected with the candidate node as the end point have been calculated, the kernel function corresponding to the candidate node is used as the kernel function that can be calculated in parallel at the current moment.
[0095] During implementation, if the current moment is the first moment of the simulation frame period, the kernel function that can be calculated in parallel is each node connected to the initial node in the directed graph, for example Figure 3 Among them, basic computing unit a, basic computing unit j, and basic computing unit m.
[0096] If the current moment is not the first moment, it is necessary to determine the candidate nodes based on the kernel function for parallel calculation determined at the previous moment, and further screen the kernel functions that can be calculated in parallel at the current moment among the candidate nodes.
[0097] Specifically, the candidate nodes are determined based on the kernel function calculated in parallel at the last moment, including:
[0098] For each kernel function calculated in parallel at the last moment, each end point connected by all directed edges starting from the node corresponding to the kernel function in the directed graph is taken as a candidate node.
[0099] For example, the kernel function of the parallel calculation at the last moment is Figure 3 In the directed graph, the kernel functions corresponding to the nodes of basic computing unit b, basic computing unit c, basic computing unit d, basic computing unit e and basic computing unit k are the candidate nodes. Figure 3 Among them, basic computing unit f, basic computing unit g, basic computing unit h, basic computing unit i and basic computing unit l are candidate nodes.
[0100] For each candidate node, if the kernel functions corresponding to all the starting points of the directed edges connected with the candidate node as the end point have been calculated, the kernel function corresponding to the candidate node is used as the kernel function that can be calculated in parallel at the current moment. For example, if the basic computing units b, basic computing units c, basic computing units d, and basic computing units e connected by the directed edges with the basic computing unit f as the end point have all been calculated, then the kernel function corresponding to the basic computing unit f is the kernel function that can be calculated in parallel at the current moment; the kernel function corresponding to the basic computing unit f connected by the directed edges with the basic computing unit h as the end point has not been calculated, so the kernel function corresponding to the basic computing unit h is not the kernel function that can be calculated in parallel at the current moment.
[0101] After determining the kernel functions that can be calculated in parallel at the current moment, the calculation instructions of the kernel functions that can be calculated in parallel at the current moment are sent to the GPU at the same time. The GPU generates threads corresponding to each kernel function according to the number of thread bundles required by each kernel function. The threads obtain the data of the corresponding entity according to their reference indexes for calculation, that is, the calculation instructions of the kernel function are executed in parallel. For example, the number of thread bundles required by the kernel function is 3, that is, 3 thread bundles need to be started, so as to ensure that there will be no differentiation problem when the thread bundle parallel calculation encounters branches.
[0102] Reference redirection is to redirect the reference index of a group of threads to the data of the same data group, so that the same thread warp executes the same instruction. In GPU programming, threads obtain input data from the corresponding position in the data set according to the reference index. The reference index is usually the thread ID or its arithmetic expression. By changing the index, the threads in the thread warp can obtain data from the same data group from the data set.
[0103] Specifically, the GPU generates threads corresponding to each kernel function according to the number of thread bundles required by each kernel function, so as to process the data of the corresponding entity and complete the calculation; when executing the branch calculation instruction of the kernel function, the entity corresponding to each thread is re-determined through double reference remapping, including:
[0104] For each kernel function, a parallel computing thread corresponding to the kernel function is generated and the original ID and index ID of the thread are determined. The index ID of the thread is used to determine the entity corresponding to the thread.
[0105] If the current instruction to be executed is a branch calculation instruction, each current valid thread determines the group, block and position in the block to which the entity corresponding to the current index ID of the valid thread belongs according to the branch judgment condition;
[0106] Redirect references to each thread warp and determine the grouping corresponding to each thread warp;
[0107] Each thread redirects the reference of the thread according to the group corresponding to the thread bundle to which the thread belongs, determines the block corresponding to the thread and the position in the block, and obtains the new index ID of the thread;
[0108] If the current instruction to be executed is a branch calculation end instruction, the index ID value of each thread is modified to the original ID value;
[0109] Otherwise, each thread determines whether the thread is valid according to the index ID. If so, the entity corresponding to the thread is determined according to the index ID, and the calculation of the current instruction to be executed is performed.
[0110] It should be noted that for a kernel function, the original ID and index ID of the corresponding thread are initially the same, both are entity IDs. The number of generated threads may exceed the number of entities. According to the thread numbering sequence, for threads whose numbers are greater than the number of entities, their original ID and index ID can be assigned other values, which are different from the entity IDs in the cluster. During implementation, the index ID is used to determine whether the thread is a valid ID. If the index ID of the thread is the same as an entity ID, it is a valid thread, otherwise it is not a valid thread. The following takes a thread corresponding to a kernel function as an example to illustrate the double reference remapping process.
[0111] After the threads are generated, they execute the computation instructions of the kernel function in parallel.
[0112] Branch calculation instructions, such as if-else statements, execute different branch instructions based on different judgment conditions.
[0113] If the instruction to be executed is not a branch calculation instruction, each thread first determines whether it is a valid thread based on its index ID. If so, it directly obtains the data of the corresponding entity from the corresponding position in the data set according to its index ID (i.e., the reference index) to perform corresponding processing and complete the calculation. Otherwise, it waits.
[0114] If the current instruction to be executed is a branch calculation instruction, each current valid thread determines the group, block and position in the block to which the entity corresponding to the current index ID of the valid thread belongs according to the branch judgment condition, specifically including:
[0115] S411, determining the group to which the entity corresponding to the current index ID of the valid thread belongs according to the branch judgment condition;
[0116] S412, determining the block to which the entity belongs in the group according to the entity ID;
[0117] S413. Calculate the position of the entity in the corresponding block in an atomic manner.
[0118] Take the first group of branch calculations as an example for explanation. The judgment object yy1 is a certain data of the entity. According to the entity data yy1, the entity is divided into two groups, that is, entities with yy1 greater than 0 are in one group, and entities with yy1 less than or equal to 0 are in another group. Each group is executed by one or more thread bundles, that is, the same instructions are executed in each thread bundle, so there is no differentiation.
[0119] It should be noted that, since all entities may be grouped into one group, the reserved length of each group is the number of entities x.
[0120] Since the atomic operation of multi-threading is a serial process, in order to further improve efficiency, the group is further divided into blocks, and the block to which the entity belongs in the group is determined according to the entity ID. The thread uses atomic method to calculate the position of the entity corresponding to the current index ID of the thread in the corresponding block, thereby improving computing efficiency.
[0121] During implementation, for example, if the number of blocks is determined to be m and the reserved length of the group is x, then entities with entity IDs of 1 to x / m belong to the first block (and may be included in the first block of the first group or the first block of the second group according to the branch judgment conditions), and entities with serial numbers of x / m+1 to 2 (x / m) belong to the second block (and may be included in the second block of the first group or the second block of the second group according to the branch judgment conditions), and so on.
[0122] During implementation, each valid thread determines which group and which block the entity corresponding to its current index ID belongs to, and then atomically calculates the position of the entity in the block:
[0123] count=atomic(G_RR_Order[i][j],1) (2)
[0124] G_RR ij [count] = fid (3)
[0125] Among them, G_RR_Order[i][j] represents the number of entities in the jth block of the current i-th group, G_RR ij Represents an array storing the entity ID of the jth block of the i-th group, and count represents the position of the entity in the jth block of the i-th group, that is, in the array G_RR ij The entity ID (fid) is stored in the array G_RR at the index position in ij The corresponding position of the reference is convenient for subsequent accurate reference redirection.
[0126] Since threads in the same warp use atomic methods to parallelly calculate the block index, that is, the position in the block, they can obtain continuous index numbers, which can reduce the memory merging access overhead and improve computing efficiency during multi-threaded parallel computing after reference redirection.
[0127] After determining the group, block, and block index to which the entity belongs, it is necessary to redirect the references of the thread warp according to the entity group, that is, to determine which group of entity data the thread warp calculates.
[0128] Specifically, reference redirection is performed on each thread bundle to determine the group corresponding to each thread bundle, including:
[0129] S421, determining the number of warps required for each group and the warp start index and warp end index of each group according to the number of entities in each block in each group;
[0130] S422: Obtain the group corresponding to each warp according to the warp start index and the warp end index of each group.
[0131] Specifically, the number of thread warps required for each group is determined using the following formula according to the number of entities in each block in each group:
[0132]
[0133] Among them, b ij represents the number of entities in the jth block in the i-th group, m i represents the number of blocks in the i-th group, w i represents the number of thread warps required for the i-th group, w c Indicates the warp size.
[0134] During implementation, the number of warps required for each group is determined according to the number of entities corresponding to each block of each group.
[0135] After calculating the number of thread bundles required for each group, the thread bundles are sorted by index, and the thread bundle start index and thread bundle end index of each group are determined, so as to determine which group each thread bundle corresponds to.
[0136] Specifically, the following formula is used to calculate the thread warp start index and thread warp end index of each group:
[0137]
[0138] Among them, w j represents the number of thread warps required for the jth group, gS i represents the starting index of the thread warp of the i-th group, gE i Indicates the warp end index of the i-th group.
[0139] The group corresponding to each thread bundle is obtained according to the thread bundle start index and thread bundle end index of each group, that is, if the index wid of the kth thread bundle is k ∈[gS i ,gE i ), then the kth thread warp corresponds to the i-th group.
[0140] During implementation, in order to reduce the amount of calculation, with the help of the shared memory variables of the GPU, only one thread in each thread warp needs to determine the group corresponding to the thread warp according to steps S421 to S422, and other threads in the same thread warp can obtain the group ID corresponding to the thread warp, that is, the group number gid corresponding to the kth thread warp k is a shared memory variable. In addition, the starting index gS of the thread warp of the i-th group i It is also a shared memory variable, thus reducing the amount of calculation.
[0141] After determining the group corresponding to the thread warp, it is necessary to further determine which entity data each thread executes the calculation for. Therefore, each thread redirects the reference to the thread according to the group corresponding to the thread warp to which the thread belongs, determines the block corresponding to the thread and the position in the block, and obtains the new index ID of the thread. Specifically, it includes:
[0142] S431, each thread calculates a thread start index and a thread end index corresponding to each block in the group corresponding to the thread warp to which the thread belongs;
[0143] S432, calculating the neighborhood index of the thread according to the warp start index of the group corresponding to the warp to which the thread belongs;
[0144] S433, determining the block corresponding to the thread according to the thread start index and thread end index corresponding to each block in the group corresponding to the thread warp to which the thread belongs, and the neighborhood index of the thread;
[0145] S434: Determine the position of the block corresponding to the thread according to the neighborhood index of the thread and the thread start index of the block corresponding to the thread, and obtain a new index ID of the thread.
[0146] In implementation, warps corresponding to the same group are called neighborhoods.
[0147] When implemented, the thread is identified by its neighborhood index nid in the neighborhood. kw , then according to nid kw Determine the position of its reference index, that is, the position of the reference index in the block, so as to find its corresponding entity and complete the corresponding calculation of the entity data.
[0148] Specifically, the neighborhood index of a thread is calculated according to the following formula:
[0149] nid kw =(wid k -gS i )*w c +twid kw (7)
[0150] Among them, nidkw Indicates the neighborhood index corresponding to the wth thread of the kth thread warp, wid k The index of the kth warp, gS i represents the starting index of the thread warp of the i-th group, w c Indicates the thread bundle size, twid kw Indicates the number of the wth thread in the kth warp.
[0151] Specifically, the following formula is used to calculate the thread start index and thread end index corresponding to each block in the group corresponding to the thread warp to which the thread belongs:
[0152]
[0153] Among them, b il represents the number of entities in the jth block in the i-th group, bS ij represents the thread start index of the jth block of the i-th group, bE ij Indicates the thread end index of the j-th block of the i-th group.
[0154] Then, the block corresponding to the thread is determined according to the thread start index and thread end index corresponding to each block in the group corresponding to the thread warp to which the thread belongs, as well as the neighborhood index of the thread. kw ∈[bS ij ,bE ij ), then the wth thread of the kth thread bundle corresponds to the jth block of the ith group, so the block ID corresponding to the thread is obtained, which is expressed as bid kw .
[0155] After obtaining the block corresponding to the thread, the position in the block corresponding to the thread is determined according to the neighborhood index of the thread and the thread start index of the block corresponding to the thread, and a new index ID of the thread is obtained.
[0156] During implementation, according to nid kw -bS ij Get the position of the thread in the block, array G_RR ij To store the entity ID of the jth block of the i-th group, take the array The value stored in is used to obtain the new index ID of the wth thread of the kth warp. It should be noted that if the kth warp corresponds to the ith group, and the neighborhood index of the wth thread of the kth warp is not within the thread index range corresponding to any block of the ith group, then the index ID of the wth thread of the kth warp is set to a value different from the instance ID, that is, the thread does not correspond to a real instance.
[0157] After obtaining the new index ID, the thread obtains the data of the corresponding entity according to its index ID for calculation, thereby improving the efficiency of parallel computing.
[0158] When the branch calculation is finished, that is, the instruction to be executed is the branch calculation end instruction, the index ID value of each thread is still modified to the original ID value, so as to facilitate the accurate determination of the entity corresponding to the thread when the branch calculation is performed next time, and at the same time, the memory merge access can be reduced, and the efficiency of memory reading can be improved. Before executing the instruction, the instruction to be executed is judged according to the instruction to be executed. If the instruction to be executed is a branch calculation instruction, the entity corresponding to the thread index ID is grouped, divided into blocks, and the position in the block is determined according to the branch judgment condition, and then the thread bundle is referenced and redirected, and then the thread is referenced and redirected to determine the new index ID of the thread. When the branch calculation is finished, the thread index ID is still modified to the original ID, so that when the instruction in the branch is executed, the corresponding entity is determined according to the index ID, ensuring that the same thread bundle executes the same branch path, so that all entities can be calculated in parallel, shortening the calculation time, improving the calculation efficiency, avoiding the problem of differentiation causing the thread bundle to be converted from all parallel execution to partial thread serial execution to increase the calculation time, and because the thread remapping is performed in the GPU, the problem of additional kernel startup and round-trip data transmission overhead caused by kernel splitting on the CPU side is avoided, thereby improving the efficiency of parallel calculation.
[0159] To illustrate the effect of the present invention, Ubuntu 20.04 is used as the test platform operating system. Taking a certain entity model as an example, directed graph disassembly is performed to realize cluster simulation parallel computing.
[0160] When the GPU simulates a cluster model of entities, the calculation method can be a method of solving an entity instance with a single thread of the GPU and a method based on the present invention (GPU directed graph). To verify the simulation efficiency of these two methods, all entity instantiation objects are made to read the same initial condition. The GPU single-thread solution process is the same as the serial execution model calculation when the CPU performs a single entity simulation, that is, one entity model is placed in one thread for calculation, and multiple entity models are placed in threads with the same number according to the number to complete the calculation.
[0161] After actual testing, the results are shown in Table 1. It can be seen that when the number of entity models running is small, the directed graph-based method can shorten the calculation time. As the number of entities increases, the time difference between the two gradually narrows. The reason is that as the number of entities increases, the utilization of the SM core computing power and the bandwidth utilization of the global memory gradually become saturated.
[0162] Table 1: Time comparison between directed graph and single-threaded mode when running on the device
[0163] Number of entities 32 320 640 1280 2560 3200 4096 4800 6400 GPU directed graph (ms) 0.115 0.121 0.129 0.154 0.235 0.324 0.384 0.463 0.625 GPU single thread (ms) 0.382 0.385 0.385 0.388 0.449 0.475 0.530 0.616 0.751
[0164] Secondly, to ensure real-time performance, the deadline for entity model calculation is set to 0.5ms, and the number of entity model calculations that can be completed by both within the deadline is counted, and the results are shown in Tables 2 to 4. The GPU completes the calculation and data transmission within the cycle, and each entity instance object transmits 50 double data; the CPU only needs to complete the calculation within the cycle, and the compilation model is selected as Release. It can be seen from the table that within the deadline, the GPU can run 3840 entity models and the CPU can run 704 entity models. The method of the present invention greatly improves the calculation efficiency.
[0165] Table 2: CPU single-thread test results
[0166] Number of entities 32 96 128 160 320 640 1280 2560 CPU single thread (ms) 0.114 0.365 0.507 0.650 1.695 5.364 12.156 24.456
[0167] Table 3: CPU 16-thread test results
[0168] Number of entities 32 320 640 672 704 800 1280 2560 16 threads (ms) 0.016 0.150 0.436 0.468 0.503 0.628 1.400 3.590
[0169] Table 4: GPU directed graph test results
[0170] Number of entities 32 320 640 1280 2560 3200 3840 4096 GPU directed graph (ms) 0.126 0.140 0.161 0.203 0.324 0.395 0.503 0.526
[0171] In order to test the effectiveness of the double reference remapping algorithm, a prototype test is carried out on a sub-model, and the sub-model solution and 50 double data transmission of each instantiated object are completed within one frame cycle.
[0172] Two sets of data are generated, one set is data that will not cause the thread warp to execute different branches, and the other set is data that will cause the thread warp to execute different branches. When differentiation occurs, there will be 4 branch conditions.
[0173] The results of parallel computing on the GPU for the first set of data are shown in the first row of Table 5. For the second set of data, two methods are used for parallel computing: parallel computing using the data dual mapping of the present invention and parallel computing not using the data dual mapping of the present invention. The results are shown in the second and third rows of Table 5, respectively. It can be seen that the method of the present invention can solve the thread bundle differentiation problem very well, and the difference between the consumed time and the computing time of the data without differentiation is small, thereby improving the computing efficiency.
[0174] Table 5: Test results of undifferentiated, algorithm of the present invention and existing method
[0175]
[0176] Those skilled in the art will appreciate that all or part of the processes of the above-mentioned embodiments can be implemented by instructing related hardware through a computer program, and the program can be stored in a computer-readable storage medium, wherein the computer-readable storage medium is a disk, an optical disk, a read-only storage memory, or a random access memory, etc.
[0177] The above description is only a preferred specific implementation manner of the present invention, but the protection scope of the present invention is not limited thereto. Any changes or substitutions that can be easily conceived by any technician familiar with the technical field within the technical scope disclosed by the present invention should be covered within the protection scope of the present invention.
Claims
1. A parallel simulation method for multi-entity cluster models based on directed graphs, characterized in that: The following steps are involved: Decomposing the entity simulation model into basic operator units, and constructing a directed graph of the entity simulation model according to the data flow dependency relationship between the basic operator units; Encapsulate each basic operator unit into a kernel function; determine the number of thread bundles required for each kernel function based on the number of entities in the cluster and the maximum number of branches of each kernel function; At each moment, the kernel function that can be calculated in parallel at the current moment is determined based on the directed graph of the entity simulation model; Send the calculation instructions of the kernel functions that can be calculated in parallel at the current moment to the GPU at the same time; The GPU generates threads corresponding to each kernel function according to the number of thread bundles required by each kernel function, which are used to process the data of the corresponding entity and complete the calculation; when executing the branch calculation instructions of the kernel function, the entity corresponding to each thread is re-determined through double reference remapping.
2. The directed graph-based multi-entity cluster model parallel simulation method according to claim 1, characterized in that: The entity simulation model is decomposed into basic operator units, and a directed graph of the entity simulation model is constructed according to the data flow dependency relationship between the basic operator units, including: Decompose the entity simulation model into sub-models that can be simulated in parallel; For each sub-model, the sub-model is decomposed into basic operator units according to the functional points; a directed graph of the basic operator units of each sub-model is constructed with the basic operator units as nodes and the data flow dependencies between the basic operator units as edges to obtain a directed graph of the entity simulation model.
3. The directed graph-based multi-entity cluster model parallel simulation method according to claim 2, characterized in that: Based on the directed graph of the entity simulation model, the kernel function that can be calculated in parallel at the current moment is determined, including: If the current moment is the first moment of the frame period, the kernel function that can be calculated in parallel at the current moment is the kernel function corresponding to each node connected by the directed edge starting from the initial node in the directed graph of the entity simulation model; Otherwise, the candidate node is determined based on the kernel function calculated in parallel at the last moment; For each candidate node, if the kernel functions corresponding to all the starting points of the directed edges connected with the candidate node as the end point have been calculated, the kernel function corresponding to the candidate node is used as the kernel function that can be calculated in parallel at the current moment.
4. The directed graph-based multi-entity cluster model parallel simulation method according to claim 3, characterized in that: Determine the candidate nodes based on the kernel function calculated in parallel at the last moment, including: For each kernel function calculated in parallel at the last moment, each end point connected by all directed edges starting from the node corresponding to the kernel function in the directed graph is taken as a candidate node.
5. The directed graph-based multi-entity cluster model parallel simulation method according to claim 1, characterized in that: The GPU generates threads corresponding to each kernel function according to the number of thread bundles required by each kernel function, which are used to process the data of the corresponding entity and complete the calculation; When executing the branch calculation instruction of the kernel function, the entity corresponding to each thread is re-determined through double reference remapping, including: For each kernel function, a parallel computing thread corresponding to the kernel function is generated and the original ID and index ID of the thread are determined. The index ID of the thread is used to determine the entity corresponding to the thread. If the current instruction to be executed is a branch calculation instruction, each current valid thread determines the group, block and position in the block to which the entity corresponding to the current index ID of the valid thread belongs according to the branch judgment condition; Redirect references to each thread bundle and determine the grouping corresponding to each thread bundle; redirect references to each thread according to the grouping corresponding to the thread bundle to which the thread belongs, determine the block corresponding to the thread and the position in the block, and obtain a new index ID for the thread; If the current instruction to be executed is a branch calculation end instruction, the index ID value of each thread is modified to the original ID value; Otherwise, each thread determines whether the thread is valid according to the index ID. If so, the entity corresponding to the thread is determined according to the index ID, and the calculation of the current instruction to be executed is performed.
6. The directed graph-based multi-entity cluster model parallel simulation method according to claim 5, characterized in that: Each current valid thread determines the group, block and position in the block to which the entity corresponding to the current index ID of the valid thread belongs according to the branch judgment condition, specifically including: Determine the group to which the entity corresponding to the current index ID of the valid thread belongs according to the branch judgment condition; Determine the block to which the entity belongs in the group according to the entity ID; Atomically calculate the position of an entity within its chunk.
7. The directed graph-based multi-entity cluster model parallel simulation method according to claim 5, characterized in that: Redirect references to each warp and determine the grouping corresponding to each warp, including: Determine the number of warps required for each group and the warp start index and warp end index of each group according to the number of entities in each block in each group; The group corresponding to each warp is obtained according to the warp start index and the warp end index of each group.
8. The directed graph-based multi-entity cluster model parallel simulation method according to claim 7, characterized in that: The number of warps required for each group is determined using the following formula based on the number of entities in each block in each group: Among them, b ij represents the number of entities in the jth block in the i-th group, m i represents the number of blocks in the i-th group, w i represents the number of thread warps required for the i-th group, w c Indicates the warp size.
9. The directed graph-based multi-entity cluster model parallel simulation method according to claim 7, characterized in that: The warp start index and warp start index of each group are calculated using the following formula: Among them, w j represents the number of thread warps required for the jth group, gS i represents the starting index of the thread warp of the i-th group, gE i Indicates the warp end index of the i-th group.
10. The directed graph-based multi-entity cluster model parallel simulation method according to claim 5, characterized in that: Each thread redirects the reference of the thread according to the group corresponding to the thread warp to which the thread belongs, determines the block corresponding to the thread and the position in the block, and obtains the new index ID of the thread, including: Each thread calculates the thread start index and thread end index corresponding to each block in the group corresponding to the thread warp to which the thread belongs; Calculate the neighborhood index of the thread according to the thread warp start index of the group corresponding to the thread warp to which the thread belongs; Determine the block corresponding to the thread according to the thread start index and thread end index corresponding to each block in the group corresponding to the thread warp to which the thread belongs, and the neighborhood index of the thread; The position of the block corresponding to the thread is determined according to the neighborhood index of the thread and the thread start index of the block corresponding to the thread, and a new index ID of the thread is obtained.
Citation Information
Cited By
Dynamic thread allocation method, electronic equipment and storage medium
CN120578479A