A lightweight multithreading processing method based on master-slave model on heterogeneous many-cores
By adopting a lightweight multi-thread processing method based on the master-slave model on Sunway heterogeneous many-core processors, the problem that existing technology is difficult to support the three-level parallel programming model is solved, and flexible and efficient multi-thread acceleration is achieved. Effect.
Patent Information
- Application Number
- CN202110398335.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-04-14
- Publication Date
- 2025-01-10
- Estimated Expiration
- 2041-04-14
AI Technical Summary
The existing software stack of Shenwei heterogeneous multi-core processors is difficult to support a three-level parallel programming model, and the thread creation overhead is high, programming is cumbersome and error-prone.
A lightweight multi-thread processing method based on the master-slave model on heterogeneous many cores is used to run parallel programs in shared mode. Each core group is a process. Shared memory is used to implement collaborative operations of thread groups and four thread states are set. And manage the thread status through the Master_enter, Master_waiting_for_task, Master_spawn, Master_join, and Master_leave interfaces.
It implements an easy-to-use, high-flexibility, low-cost on-chip multi-threading solution, supports a three-level parallel programming model, avoids the performance overhead of traditional multi-threading mechanisms, and provides better multi-thread acceleration effects.
Smart Images

Figure CN114217915B_ABST
Abstract
Description
Technical Field
[0001] The invention relates to a lightweight multi-thread processing method based on a master-slave model on heterogeneous multi-cores, belonging to the technical field of high performance computing. Background Art
[0002] The most prominent advantage of the domestically produced Shenwei heterogeneous multi-core processor is its high performance, which is especially suitable for the field of high-performance computing and is mainly used in large-scale practical systems such as ultra-large-scale parallel machines. Each Shenwei multi-core processor contains multiple core groups, each of which consists of a main core and a large number of slave acceleration cores.
[0003] Currently, the Shenwei multi-core software stack supports three modes: default mode, shared mode, and full-chip shared mode. In the default mode, each core group has one process, and the memory space between processes is isolated. The master core controls the slave cores in the core group to accelerate the calculation. Data interaction is achieved through messages between processes. The memory of each core group is isolated, and multi-threading and three-level shared programming models cannot be implemented; in shared mode, it is similar to the default mode, but the memory is shared between processes in the same processor. Due to memory sharing, processes can be used as threads, but the fragments in the processor that require multi-threaded collaborative computing are scattered throughout the program. Since threads cannot be created and recycled arbitrarily, users must always explicitly maintain the task status of the main process and the slave processes that act as threads according to the process number, and maintain them through frequent synchronization and locking. Operations such as these ensure the correctness of the program, which involves a lot of programmers' energy, makes programming cumbersome and prone to errors. In the full-chip sharing mode, the main core of the No. 0 core group in the processor runs a process and controls all the slave cores in the chip to accelerate computing. Other main cores implement multi-threading in the chip through the No. 0 main core calling the pthread library and the thread migration interface provided by the operating system. The No. 0 main cores of multiple chips implement data interaction through messages, and only support one process in one processor. Users cannot choose the thread group size according to their own needs, and each thread creation needs to be implemented by using the pthread library combined with the operating system thread migration system call interface, which has a large overhead.
[0004] In the past, the software stack on the Shenwei multi-core chip defaulted to organizing the resources of multiple core groups in the same processor in units of processes, with each core group running one process, and could not well support organizing resources in the form of thread groups. This would cause users to either use the full-chip sharing mode provided by the system when developing parallel programs, but this mode is not flexible enough and has a large thread creation overhead, which cannot meet user needs well; or based on the sharing mode, use processes as units to simulate multi-threading in the chip through frequent synchronization, locking and other operations, but the program fragments that require multiple core groups to cooperate in the processor are often scattered throughout the program. Users must always maintain the task status of the main process and the slave process that acts as a thread according to the process number, which makes programming cumbersome and error-prone; or give up using multi-threading in the chip, which to a certain extent forces users to develop programs with a two-level parallel programming model of "sharing within the core group-messages between core groups", making it difficult for users to take advantage of the programming convenience and performance potential brought by the shared memory in the processor.
[0005] Sharing memory in a multi-core group helps reduce communication requirements, but it increases parallel overhead. Therefore, some users hope to support a three-level parallel programming model: multiple processes are set up in the processor according to user needs; data is exchanged between processes through messages; several core groups in a process are organized as thread groups, and collaborative operations are based on shared memory; slave cores are used for acceleration within the core group. However, none of the current three usage modes can support the three-level parallel programming model well. To completely solve this problem, full support from the underlying software stack, such as the job management system, operating system, compilation environment, and communication library, is required, which is a large workload, involves a wide range of areas, and is complex to modify and has a long cycle. Summary of the invention
[0006] The purpose of the present invention is to provide a lightweight multi-thread processing method based on a master-slave model on heterogeneous multi-cores, which provides users with an easy-to-use, more flexible, and lower-overhead on-chip multi-thread solution.
[0007] To achieve the above object, the technical solution adopted by the present invention is: to provide a lightweight multi-thread processing method based on a master-slave model on heterogeneous multi-cores, and to set four thread states: __status_init=0, __status_wait=-1, __status_done=-2 and __status_quit=-3, which respectively mean initialization, waiting for tasks, task completion and thread exit;
[0008] The total number of core groups per processor is recorded as CG_NUM, the size of the thread group is recorded as CG_PER_PROCESS, and the parameter buffer size is recorded as MAX_PARAM_SIZE;
[0009] A long integer array __MASTER_PC[CG_NUM] is allocated in the shared memory to record the thread status and task PC transfer of each core group. When the program starts, the default status of the core group is __status_init;
[0010] Open up the array master_parameter[CG_NUM / CG_PER_PROCESS][MAX_PARAM_SIZE] in the shared memory, which is used by the main thread in the thread group to pass parameters to the slave threads;
[0011] The core group number of each core group is recorded as cgid. The core group with tid=cgid%CG_PER_PROCESS=0 is set as the main thread, and host is set to 1; the core groups with equal gid=cgid / CG_PER_PROCESS are set as a thread group, and the host of the core group of non-main thread in the thread group is set to 0; gid is the logical number of the thread group in the same processor, and tid is the logical number of each core group in the thread group;
[0012] According to the core group number of the main thread and its slave threads, set the mask cgmask of each thread group. The mask has CG_NUM bits. The bit corresponding to the core group number contained in this thread group is 1, and the rest of the bits are 0.
[0013] Run parallel programs in shared mode, with each core group as a process;
[0014] When it is necessary to enter the thread state, the core groups in the same thread group call the Master_enter interface at the same time. The Master_enter interface receives three parameters: host, thread group mask cgmask, and thread group parameter address master_parameter[gid].
[0015] Each core group determines whether it is a master thread or a slave thread through the host. If it is a slave thread, it calls the Master_waiting_for_task interface to enter the thread waiting state. If it is a master thread, it waits for the thread group to be initialized through thread group synchronization.
[0016] The Master_waiting_for_task interface called by the slave thread receives two parameters: the thread group mask and the parameter list address; in the Master_waiting_for_task interface, the slave thread first modifies the __MASTER_PC state corresponding to the core group to _status_wait, and then synchronously waits for the master thread and other slave threads to complete initialization through the thread group, and then enters the task waiting state: the slave thread reads the __MASTER_PC[cgid] state, if it is __status_wait, it continues to wait for the task; otherwise, if it is __status_quit, it exits the task waiting state; otherwise, the task assigned by the master thread is executed according to the PC and parameter list address recorded by __MASTER_PC[cgid]; after the task is executed, it synchronously waits for other threads in the thread group to complete execution through the thread group, and then restores the __MASTER_PC[cgid] state to __status_wait, and continues to wait for the task;
[0017] When multi-threaded concurrent processing is required, the main thread calls the Master_spawn interface to assign tasks to the thread group. According to the thread group mask, the task PC to be assigned to the thread group is written into the corresponding position of the thread group in the __MASTER_PC array, and the parameter list is written into master_parameter[cgid].
[0018] The Master_spawn interface is a non-blocking interface. The master thread returns immediately after calling the interface. It can choose to cooperate with the slave thread to process tasks, or perform other computing tasks or send and receive messages from other thread groups. The slave thread executes tasks based on the task PC and parameter table provided by the master thread.
[0019] The main thread calls the Master_join interface, waits for the slave thread to complete execution through the thread group mask and thread group synchronization, restores its own __MASTER_PC state to __status_wait, and then waits for the status of all threads in the thread group to be restored to __status_wait. This interface is a blocking interface;
[0020] When it is necessary to exit the thread state, the main thread calls the Master_leave interface, releases the threads in the thread group according to the thread group mask, and sets the __MASTER_PC status of all core groups in the thread group to __status_quit; after execution, each core group restores the process state and can continue to execute tasks according to the process number.
[0021] Due to the application of the above technical solution, the present invention has the following advantages compared with the prior art:
[0022] The present invention discloses a lightweight multi-thread processing method based on a master-slave model on heterogeneous multi-cores. The method is based on a sharing mode and utilizes processor shared memory. It can realize a "use-as-you-go, use-as-you-go" usage mode of threads without modifying the underlying software stack as much as possible, and provide users with an easy-to-use, more flexible, and lower-cost on-chip multi-thread solution. It can avoid the negative effects such as error introduction, service interruption, and user development progress delay that may be caused by large-scale and long-term modification of the underlying supporting software, and can quickly provide users with three-level parallel programming interfaces and services. The "use-as-you-go, use-as-you-go" feature of the lightweight service mechanism avoids the performance overhead caused by the traditional multi-thread mechanism frequently calling system calls such as fork / join / bind and frequently creating and destroying threads, and can enable users to obtain better multi-thread acceleration effects. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] Attached Figure 1 This is an example of thread information and space distribution (CG_NUM=6, CG_PER_PROCESS=3);
[0024] Attached Figure 2 This is the Master_enter flow chart;
[0025] Attached Figure 3 It is the Master_waiting_for_task flow chart;
[0026] Attached Figure 4 This is the Master_spawn flow chart;
[0027] Attached Figure 5 This is the Master_join flow chart;
[0028] Attached Figure 6 It is the Master_leave flow chart;
[0029] Attached Figure 7 It is a lightweight multi-threaded mechanism interface prototype and typical usage based on the master-slave model. DETAILED DESCRIPTION
[0030] Embodiment: The present invention provides a lightweight multi-thread processing method based on a master-slave model on heterogeneous multi-cores, and sets four thread states: __status_init=0, __status_wait=-1, __status_done=-2, and __status_quit=-3, which respectively mean initialization, waiting for tasks, task completion, and thread exit;
[0031] The total number of core groups per processor is recorded as CG_NUM, the size of the thread group is recorded as CG_PER_PROCESS, and the parameter buffer size is recorded as MAX_PARAM_SIZE;
[0032] A long integer array __MASTER_PC[CG_NUM] is allocated in the shared memory to record the thread status and task PC transfer of each core group. When the program starts, the default status of the core group is __status_init;
[0033] Open up the array master_parameter[CG_NUM / CG_PER_PROCESS][MAX_PARAM_SIZE] in the shared memory, which is used by the main thread in the thread group to pass parameters to the slave threads;
[0034] The core group number of each core group is recorded as cgid. The core group with tid=cgid%CG_PER_PROCESS=0 is set as the main thread, and host is set to 1; the core groups with equal gid=cgid / CG_PER_PROCESS are set as a thread group, and the host of the core group of non-main thread in the thread group is set to 0; gid is the logical number of the thread group in the same processor, and tid is the logical number of each core group in the thread group;
[0035] According to the core group number of the main thread and its slave threads, set the mask cgmask of each thread group. The mask has CG_NUM bits. The bit corresponding to the core group number contained in this thread group is 1, and the rest of the bits are 0.
[0036] Run parallel programs in shared mode, with each core group as a process;
[0037] When it is necessary to enter the thread state, the core groups in the same thread group call the Master_enter interface at the same time. The Master_enter interface receives three parameters: host, thread group mask cgmask, and thread group parameter address master_parameter[gid].
[0038] Each core group determines whether it is a master thread or a slave thread through the host. If it is a slave thread, it calls the Master_waiting_for_task interface to enter the thread waiting state. If it is a master thread, it waits for the thread group to be initialized through thread group synchronization.
[0039] The Master_waiting_for_task interface called by the slave thread receives two parameters: the thread group mask and the parameter list address; in the Master_waiting_for_task interface, the slave thread first modifies the __MASTER_PC state corresponding to the core group to _status_wait, and then synchronously waits for the master thread and other slave threads to complete initialization through the thread group, and then enters the task waiting state: the slave thread reads the __MASTER_PC[cgid] state, if it is __status_wait, it continues to wait for the task; otherwise, if it is __status_quit, it exits the task waiting state; otherwise, the task assigned by the master thread is executed according to the PC and parameter list address recorded by __MASTER_PC[cgid]; after the task is executed, it synchronously waits for other threads in the thread group to complete execution through the thread group, and then restores the __MASTER_PC[cgid] state to __status_wait, and continues to wait for the task;
[0040] When multi-threaded concurrent processing is required, the main thread calls the Master_spawn interface to assign tasks to the thread group. According to the thread group mask, the task PC to be assigned to the thread group is written into the corresponding position of the thread group in the __MASTER_PC array, and the parameter list is written into master_parameter[cgid].
[0041] The Master_spawn interface is a non-blocking interface. The master thread returns immediately after calling the interface. It can choose to cooperate with the slave thread to process tasks, or perform other computing tasks or send and receive messages from other thread groups. The slave thread executes tasks based on the task PC and parameter table provided by the master thread.
[0042] The main thread calls the Master_join interface, waits for the slave thread to complete execution through the thread group mask and thread group synchronization, restores its own __MASTER_PC state to __status_wait, and then waits for the status of all threads in the thread group to be restored to __status_wait. This interface is a blocking interface;
[0043] When it is necessary to exit the thread state, the main thread calls the Master_leave interface, releases the threads in the thread group according to the thread group mask, and sets the __MASTER_PC status of all core groups in the thread group to __status_quit; after execution, each core group restores the process state and can continue to execute tasks according to the process number.
[0044] The above embodiment is further explained as follows:
[0045] The software stack of Shenwei multi-core chips organizes the resources of multiple core groups in the same processor as processes by default. Each core group runs one process, and users develop applications using a two-level parallel programming model of "intra-core group sharing-inter-core group messaging". Using multi-threading technology on a processor architecture that supports shared memory can reduce communication requirements and help improve program performance. Therefore, some users need a three-level parallel programming model: set the number of processes and thread group size in the processor according to their own needs; exchange data between processes through messages; organize several core groups in a process as thread groups, and coordinate operations based on shared memory; and use slave cores to accelerate within the core group. However, the current software stack of Shenwei multi-core chips is difficult to support the three-level parallel programming model well, or does not support thread creation, or user programming is cumbersome and error-prone, or is not flexible enough and has a large thread creation overhead.
[0046] The present invention is based on the sharing mode and uses shared memory and a master-slave model to implement a lightweight multi-threading mechanism. It does not require modification of the underlying software stack and implements a basic multi-threading mechanism. It adopts a "use-as-you-go, use-as-you-go" model to help users more easily and efficiently implement application development based on the three-level parallel programming model.
[0047] The mechanism is described as follows:
[0048] 1. Set four thread states, __status_init=0, __status_wait=-1, __status_done=-2 and __status_quit=-3, which mean initialization, waiting for task, task completion and thread exit respectively.
[0049] 2. The total number of core groups of each processor is recorded as CG_NUM, the size of the thread group is recorded as CG_PER_PROCESS, and the parameter buffer size is recorded as MAX_PARAM_SIZE. A long integer array __MASTER_PC[CG_NUM] is allocated in shared memory to record the thread status of each core group and the task PC transfer. When the program starts, the default status of the core group is __status_init. An array master_parameter[CG_NUM / CG_PER_PROCESS][MAX_PARAM_SIZE] is allocated in shared memory to pass parameters from the master thread to the slave thread in the thread group. See Figure 1 .
[0050] 3. The core group number of each core group is cgid. The core group with tid=cgid%CG_PER_PROCESS=0 is set as the main thread, and host is set to 1; the core groups with equal gid=cgid / CG_PER_PROCESS are set as a thread group, and the host of the core group of the non-main thread in the thread group is set to 0; gid is the logical number of the thread group in the same processor, and tid is the logical number of each core group in the thread group. According to the core group number of the main thread and its subordinate threads, set the mask cgmask of each thread group. The mask has CG_NUM bits. The bit corresponding to the core group number contained in this thread group is 1, and the rest of the positions are 0. The setting can be completed according to the main thread mask passed by the user, see Figure 1 .
[0051] 4. Use the shared mode to run parallel programs, with each core group as a process. When it is necessary to enter the thread state, the core groups in the same thread group call the Master_enter interface at the same time. The interface receives three parameters, namely host, thread group mask cgmask, and thread group parameter address master_parameter[gid]. Each core group determines whether it is a master thread or a slave thread through the host. The slave thread calls the Master_waiting_for_task interface to enter the thread waiting state. The master thread waits for the thread group to be initialized synchronously through the thread group. See Figure 2 .
[0052] 5. The Master_waiting_for_task interface called by the slave thread receives two parameters, namely the thread group mask and the parameter list address. In this interface, the slave thread first changes the __MASTER_PC state corresponding to the core group to _status_wait, and then waits for the master thread and other slave threads to complete initialization through the thread group synchronization, and then enters the task waiting state: the slave thread reads the __MASTER_PC[cgid] state, if it is __status_wait, it continues to wait for the task; otherwise, if it is __status_quit, it exits the task waiting state; otherwise, it executes the task assigned by the master thread according to the PC and parameter list address recorded by __MASTER_PC[cgid]; after the task is executed, it waits for the completion of other threads in the thread group through the thread group synchronization, and then restores the __MASTER_PC[cgid] state to __status_wait, and continues to wait for the task, see Figure 3 .
[0053] 6. When multi-threaded concurrent processing is required, the main thread calls the Master_spawn interface to dispatch tasks to the thread group. According to the thread group mask, the task PC to be dispatched to the thread group is written into the corresponding position of the thread group in the __MASTER_PC array, and the parameter list is written into master_parameter[cgid]. This interface is a non-blocking interface. The main thread returns immediately after calling this interface. It can choose to process tasks in collaboration with the slave thread, or perform other computing tasks or send and receive messages from other thread groups; the slave thread executes tasks based on the task PC and parameter table provided by the main thread, see Figure 4 .
[0054] 7. The main thread calls Master_join, waits for the slave thread to finish executing through the thread group mask and thread group synchronization, restores its own __MASTER_PC state to __status_wait, and then waits for the state of all threads in the thread group to be restored to __status_wait. This interface is a blocking interface, see Figure 5 .
[0055] 8. When it is necessary to exit the thread state, the main thread calls the Master_leave interface, releases the threads in the thread group according to the thread group mask, and sets the __MASTER_PC status of all core groups in the thread group to __status_quit. After the execution is completed, each core group restores the process state and can continue to execute tasks according to the process number, see Figure 6 .
[0056] 9. The function interface prototype and typical usage of this mechanism are as follows Figure 7 shown.
[0057] The multithreading mechanism proposed in this patent has only four user interfaces, which is easy to use, easy to learn and use; no system call is required, and it is only implemented through state switching and parameter passing on shared memory, with low overhead; the size of the process group and thread group in the processor can be set, which is highly flexible;
[0058] Running programs based on the shared mode does not require modifying the underlying software stack; it can implement a "use-as-you-go, use-as-you-go" multi-threaded acceleration mode, apply for and recycle thread groups on demand, and switch processes and thread states at any time, which is more in line with user programming habits and can effectively support the development of three-level parallel programming model applications.
[0059] When the above-mentioned lightweight multi-thread processing method based on the master-slave model on heterogeneous multi-cores is adopted, it is based on the sharing mode and utilizes the processor shared memory. It can realize the thread "take it as you want, use it and go" usage mode without modifying the underlying software stack as much as possible, providing users with an easy-to-use, more flexible, and lower-cost on-chip multi-thread solution, which can avoid the negative effects such as error introduction, service interruption, and user development progress delay that may be caused by large-scale and long-term modification of the underlying supporting software, and can quickly provide users with three-level parallel programming interfaces and services. The "take it as you want, use it and go" feature of the lightweight service mechanism avoids the performance overhead caused by the traditional multi-thread mechanism frequently calling system calls such as fork / join / bind and frequently creating and destroying threads, so that users can obtain better multi-thread acceleration effects.
[0060] In order to facilitate a better understanding of the present invention, the terms used in this article are briefly explained below:
[0061] Heterogeneous many-core chip: a high-performance heterogeneous central processing unit that integrates a small number of general-purpose main cores that perform management, communication and computing functions and a large number of streamlined slave cores that perform computing functions on a complete chip; the general-purpose main core runs a general-purpose operating system, mainly performs the management and control functions of the entire chip, and also performs certain computing functions and the communication function between the chip and the outside world; the slave core plays the role of accelerating computing.
[0062] Core group: A structure consisting of a master core, several slave cores managed by it, and their supporting peripheral components is called a core group. A Shenwei heterogeneous many-core chip consists of multiple core groups.
[0063] Process: The basic unit for resource allocation and scheduling in the operating system. It is a description of instructions, data and their organizational form, and is the entity of the program.
[0064] Thread: The smallest unit in which the operating system can schedule and dispatch operations. It is contained in the process and is the actual operating unit in the process. A thread refers to a single sequential control flow in a process and is the smallest unit of program execution. A process can have multiple threads concurrently, and each thread performs different tasks.
[0065] Multithreading: refers to the technology of implementing concurrent execution of multiple threads from software or hardware. In this patent, multithreading refers to software multithreading.
[0066] Job: The program that needs to be run is called a job.
[0067] Blocking function / non-blocking function: A blocking function means that after a function is called and before the task is completed, the function will remain suspended and will not return to the calling point until the task is completed; a non-blocking function means that the function returns to the calling point immediately after being called.
[0068] PC: Program counter, used to store the address of the next instruction. The PC of a function in C language is the function name.
[0069] The above embodiments are only for illustrating the technical concept and features of the present invention, and their purpose is to enable people familiar with the technology to understand the content of the present invention and implement it accordingly, and they cannot be used to limit the protection scope of the present invention. Any equivalent changes or modifications made according to the spirit of the present invention should be included in the protection scope of the present invention.
Claims
1. A lightweight multi-thread processing method based on a master-slave model on heterogeneous multi-cores, characterized by: Set four thread states: __status_init=0, __status_wait=-1, __status_done=-2 and __status_quit=-3, which mean initialization, waiting for task, task completion and thread exit respectively; The total number of core groups per processor is recorded as CG_NUM, the size of the thread group is recorded as CG_PER_PROCESS, and the parameter buffer size is recorded as MAX_PARAM_SIZE; A long integer array __MASTER_PC[CG_NUM] is allocated in the shared memory to record the thread status and task PC transfer of each core group. When the program starts, the default status of the core group is __status_init; Open up the array master_parameter[CG_NUM / CG_PER_PROCESS][MAX_PARAM_SIZE] in the shared memory, which is used by the main thread in the thread group to pass parameters to the slave threads; The core group number of each core group is recorded as cgid. The core group with tid=cgid%CG_PER_PROCESS=0 is set as the main thread, and host is set to 1; the core groups with equal gid=cgid / CG_PER_PROCESS are set as a thread group, and the host of the core group of non-main thread in the thread group is set to 0; gid is the logical number of the thread group in the same processor, and tid is the logical number of each core group in the thread group; According to the core group number of the main thread and its slave threads, set the mask cgmask of each thread group. The mask has CG_NUM bits. The bit corresponding to the core group number contained in this thread group is 1, and the rest of the bits are 0. Run parallel programs in shared mode, with each core group as a process; When it is necessary to enter the thread state, the core groups in the same thread group call the Master_enter interface at the same time. The Master_enter interface receives three parameters: host, thread group mask cgmask, and thread group parameter address master_parameter[gid]. Each core group determines whether it is a master thread or a slave thread through the host. If it is a slave thread, it calls the Master_waiting_for_task interface to enter the thread waiting state. If it is a master thread, it waits for the thread group to be initialized through thread group synchronization. The Master_waiting_for_task interface called by the slave thread receives two parameters: the thread group mask and the parameter list address; in the Master_waiting_for_task interface, the slave thread first modifies the __MASTER_PC state corresponding to the core group to _status_wait, and then synchronously waits for the master thread and other slave threads to complete initialization through the thread group, and then enters the task waiting state: the slave thread reads the __MASTER_PC[cgid] state, if it is __status_wait, it continues to wait for the task; otherwise, if it is __status_quit, it exits the task waiting state; otherwise, the task assigned by the master thread is executed according to the PC and parameter list address recorded by __MASTER_PC[cgid]; after the task is executed, it synchronously waits for other threads in the thread group to complete execution through the thread group, and then restores the __MASTER_PC[cgid] state to __status_wait, and continues to wait for the task; When multi-threaded concurrent processing is required, the main thread calls the Master_spawn interface to assign tasks to the thread group. According to the thread group mask, the task PC to be assigned to the thread group is written into the corresponding position of the thread group in the __MASTER_PC array, and the parameter list is written into master_parameter[cgid]. The Master_spawn interface is a non-blocking interface. The master thread returns immediately after calling the interface. It can choose to cooperate with the slave thread to process tasks, or perform other computing tasks or send and receive messages from other thread groups. The slave thread executes tasks based on the task PC and parameter table provided by the master thread. The main thread calls the Master_join interface, waits for the slave thread to complete execution through the thread group mask and thread group synchronization, restores its own __MASTER_PC state to __status_wait, and then waits for the status of all threads in the thread group to be restored to __status_wait. This interface is a blocking interface; When it is necessary to exit the thread state, the main thread calls the Master_leave interface, releases the threads in the thread group according to the thread group mask, and sets the __MASTER_PC status of all core groups in the thread group to __status_quit; after execution, each core group restores the process state and can continue to execute tasks according to the process number.
Citation Information
Patent Citations
Data parallel processing method and device based on many-core processor
CN112035578A
Method and system of a hierarchical task scheduler for a multi-thread system
US20150135183A1