Heterogeneous computing system, server and heterogeneous computing method
By setting a shadow variable queue->index on the server side in a heterogeneous computing system and implementing mutual exclusion protection through atomic operations, the performance loss caused by the high frequency of remote atomic operations is solved, thereby improving the data correctness and performance of the system.
Patent Information
- Application Number
- CN202411548074.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-31
- Publication Date
- 2026-05-01
AI Technical Summary
In a multi-threaded environment, heterogeneous computing systems suffer from high frequency of remote atomic operations, leading to performance loss. Furthermore, when multiple producers operate concurrently, it cannot be guaranteed that each producer can safely add messages to the lock-free circular buffer, resulting in a decline in system performance.
A shadow variable queue->index is set on the server side, and mutual exclusion protection is achieved by preempting this shadow variable through atomic operations. This ensures that multiple threads perform atomic operations on the server side and avoids frequent updates of remote write pointers.
By centralizing atomic operations on the server side, the frequency of remote operations is reduced, system performance is improved, and the correctness and consistency of data are guaranteed.
Smart Images

Figure CN121957925A_ABST
Abstract
Description
Heterogeneous computing systems, servers, and heterogeneous computing methods Technical Field
[0001] This application belongs to the field of heterogeneous computing technology, and in particular relates to heterogeneous computing systems, servers and heterogeneous computing methods. Background Technology
[0002] With increasingly complex computing demands, heterogeneous computing has gradually become one of the key technologies for improving overall system performance and energy efficiency. Heterogeneous computing systems integrate different types of computing devices, such as central processing units (CPUs), graphics processing units (GPUs), digital signal processors (DSPs), and field-programmable gate arrays (FPGAs), onto the same computing platform. By using these different types of computing devices collaboratively, computing tasks can run on the most suitable hardware, thereby maximizing performance and minimizing energy consumption. For example, in artificial intelligence inference, the computational part of the deep learning model can be accelerated by the GPU, while control logic and data preprocessing are executed by the CPU.
[0003] In multi-threaded systems that share resources, lock-free ring buffers are commonly used to achieve efficient data transfer. A lock-free ring buffer is a data structure used in multi-threaded environments to safely transfer data between producers and consumers without the need for traditional locking mechanisms.
[0004] However, the inventors found in practical applications that there is still room for improvement in the performance of these heterogeneous computing systems. Summary of the Invention
[0005] This application provides a heterogeneous computing system, server, and heterogeneous computing method to improve the performance of the heterogeneous computing system.
[0006] In a first aspect, embodiments of this application provide a heterogeneous computing system, comprising a server and a computing device, wherein the server and the computing device share a data queue, and the server has a shadow variable used to indicate the value of the write pointer of the data queue; the server comprises n threads, where n is an integer greater than 1; when K threads among the n threads concurrently add messages to the data queue, the K threads are configured such that: the K threads respectively preempt the shadow variable through atomic operations; when any one of the K threads successfully preempts the shadow variable through an atomic operation, the shadow variable is updated, and the thread that successfully preempts the shadow variable can write the message to the data queue, and after writing the message to the data queue, update the value of the write pointer of the data queue according to the updated shadow variable, wherein K is greater than 1 and less than or equal to n; the threads in the computing device are configured to read messages from the data queue for processing, and after reading the messages, update the value of the read pointer of the data queue.
[0007] In some implementations, the data queue is located in the computing device or the server.
[0008] In some implementations, the high address bits of the shadow variable are used to indicate the flag information of the thread that successfully preempted the shadow variable, and the low address bits of the shadow variable are used to indicate the value of the write pointer of the data queue.
[0009] In some implementations, updating the shadow variable includes: the high address bit of the shadow variable indicating the marker information of the thread that has successfully preempted the shadow variable, and the low address bit of the shadow variable indicating the value of the write pointer of the data queue being incremented; updating the value of the write pointer of the data queue according to the updated shadow variable includes: updating the value of the write pointer of the data queue according to the value of the write pointer indicated by the updated low address bit of the shadow variable.
[0010] In some implementations, the tagging information is the ID of the thread that successfully preempted the shadow variable.
[0011] In some implementations, after the thread that successfully preempts the shadow variable updates the value of the write pointer of the data queue according to the updated shadow variable, it is also used to clear the marking information of the thread indicated by the high address bit of the shadow variable.
[0012] In some implementations, the server maps the memory of the computing device to its local memory via PCIe memory-mapped I / O.
[0013] In some implementations, the data queue is implemented using a lock-free circular buffer.
[0014] In some implementations, the atomic operation is a compare-and-swap operation.
[0015] In some implementations, the computing device is configured to perform the following steps: determining whether there is a message to be read in the data queue based on the values of the read pointer and the write pointer of the data queue; if there is a message to be read in the data queue, reading the message from the data queue for processing; and updating the value of the read pointer of the data queue.
[0016] Secondly, embodiments of this application provide a server applied to a heterogeneous computing system. The system further includes a computing device communicatively connected to the server. The server and the computing device share a data queue. The server has a shadow variable, which is used to indicate the value of the write pointer of the data queue. The server includes n threads, where n is an integer greater than 1. When K threads among the n threads concurrently add messages to the data queue, the K threads are configured such that: the K threads each preempt the shadow variable through atomic operations; when any one of the K threads successfully preempts the shadow variable through an atomic operation, the shadow variable is updated, and the thread that successfully preempts the shadow variable can write the message to the data queue. After writing the message to the data queue, the write pointer value of the data queue is updated according to the updated shadow variable, where K is greater than 1 and less than or equal to n.
[0017] Thirdly, embodiments of this application provide a heterogeneous computing method. This method is applied to a server in a heterogeneous computing system. The system further includes a computing device communicatively connected to the server. The server and the computing device share a data queue. The server has a shadow variable used to indicate the value of the write pointer of the data queue. The server includes n threads, where n is an integer greater than 1. When K threads among the n threads concurrently add messages to the data queue, the heterogeneous computing method includes: the K threads each preempting the shadow variable through atomic operations, where K is greater than 1 and less than or equal to n; when any one of the K threads successfully preempts the shadow variable through an atomic operation, the shadow variable is updated, and the thread that successfully preempted the shadow variable writes the message to the data queue and updates the value of the write pointer of the data queue according to the updated shadow variable.
[0018] This application embodiment sets a shadow variable on the server side, and focuses the atomic operations of multiple threads on the server side on this shadow variable. This constrains the atomic operations of the server-side threads to the server side, avoiding remote atomic operations by the server on the write pointer of the computing device, which is beneficial to improving system performance.
[0019] In this embodiment, the atomic operation can be a CAS operation. When any thread successfully completes a CAS operation, the thread's flag information is first stored in a shadow variable to lock the shadow variable, and the value of the write pointer indicated by the shadow variable is updated. After the thread writes the message to the data queue, the value of the write pointer in the data queue is updated according to the updated write pointer value in the shadow variable. Only then is the thread's flag information indicated by the shadow variable removed to unlock the shadow variable. This allows the message writing operation and the update of the write pointer to be completed under a complete mutual exclusion protection mechanism, ensuring the correctness of the data. Attached Figure Description
[0020] Figure 1 shows an architecture diagram of a heterogeneous computing system.
[0021] Figure 2 shows a schematic diagram of the heterogeneous computing system provided in an embodiment of this application.
[0022] Figure 3 shows a flowchart of adding messages to a thread on the server side in an embodiment of this application.
[0023] Figure 4 shows a flowchart of a computing device reading messages in an embodiment of this application. Detailed Implementation
[0024] The following specific examples illustrate the implementation of this application. Those skilled in the art can easily understand other advantages and effects of this application from the content disclosed in this specification. This application can also be implemented or applied through other different specific embodiments, and various details in this specification can also be modified or changed based on different viewpoints and applications without departing from the spirit of this application. It should be noted that, unless otherwise specified, the following embodiments and features in the embodiments can be combined with each other.
[0025] It should be noted that the illustrations provided in the following embodiments are only schematic representations of the basic concept of this application. Therefore, the illustrations only show the components related to this application and are not drawn according to the number, shape and size of the components in actual implementation. In actual implementation, the form, quantity and proportion of each component can be arbitrarily changed, and the layout of the components may also be more complex.
[0026] Figure 1 shows an architecture diagram of a heterogeneous computing system. As shown in Figure 1, the heterogeneous computing system includes servers and computing devices. The servers and computing devices are connected via a heterogeneous computing interconnect bus, such as a PCIe bus. In the producer-consumer model, consumers and producers share a fixed-size buffer, such as a lock-free circular buffer. This buffer can be set up, for example, in the computing device. Producers (such as threads on the server side) put messages into the buffer, and consumers (such as threads on the computing device side) retrieve messages from the buffer for processing.
[0027] In a multithreaded environment, lock-free circular buffers can employ atomic operations to ensure thread safety. An atomic operation is an operation that cannot be interrupted by the thread scheduling mechanism. Once started, it runs continuously until completion without switching to another thread, thus ensuring data consistency and integrity while avoiding the overhead and complexity of using explicit locks. However, in the heterogeneous computing system shown in Figure 1, producers and consumers reside on two different devices. The aforementioned atomic operations need to traverse the heterogeneous computing interconnect bus. In scenarios with multiple concurrent producers, the frequency of remote atomic operations increases, leading to performance degradation. Furthermore, atomic operations are typically implemented by preempting the write pointer of the lock-free circular buffer. However, in scenarios with multiple concurrent producers, simply preempting the write pointer cannot guarantee that each producer can safely add messages to the lock-free circular buffer. This is because writing messages to the lock-free circular buffer and updating the write pointer value must be completed within a complete mutual exclusion protection mechanism. Otherwise, the write pointer value may continuously increment due to preemption by various producers, while the message has not been written to the lock-free circular buffer. When a consumer in a computing device detects an increment in the write pointer, it assumes the message has been written to the lock-free circular buffer and attempts to read it, causing errors in the consumer's read operation. This can significantly impact system performance.
[0028] To address at least the aforementioned problems, embodiments of this application provide a heterogeneous computing system. The technical solutions in these embodiments will be described in detail below with reference to the accompanying drawings.
[0029] Figure 2 shows a schematic diagram of the heterogeneous computing system provided in an embodiment of this application. As shown in Figure 2, the heterogeneous computing system 2 includes a server 21 and a computing device 22. The server 21 can, for example, map the memory of the computing device 22 to its local memory via PCIe Memory-Mapped I / O (PCIe MMIO), but this application is not limited thereto. Furthermore, it should be noted that this embodiment is illustrated using a multi-producer-single-consumer model (i.e., multiple producers exist on the server side, and one consumer exists on the computing device side). However, those skilled in the art will understand that the heterogeneous computing strategy provided in this embodiment can also be applied to a multi-producer-multi-consumer model or a single-producer-multi-consumer model.
[0030] In the heterogeneous computing system 2, server 21 and computing device 22 share a data queue, which can be implemented using a lock-free circular buffer. Exemplarily, this data queue can be located in the high-bandwidth memory (HBM) of computing device 22. The data queue may include a read pointer (read_index in Figure 2) and a write pointer (write_index in Figure 2). The write pointer points to the position in the data queue where a message can be added. When a message is written, the value of the write pointer is incremented by 1, and the write pointer points to the next write position. The read pointer points to the position in the data queue where a message can be read. When a message is read, the value of the read pointer is also incremented by 1, and the read pointer points to the next readable message position.
[0031] The data queue comprises multiple storage areas for storing messages, such as storage area 0, storage area 1, ..., storage area N. Both the write pointer and read pointer are initialized to point to storage area 0, and their values are equal, for example, 0. As messages are written, the value of the write pointer gradually increases, and its position changes accordingly. When a message is written to storage area N, the write pointer will return to the location in storage area 0. Similarly, as messages are read, the value of the read pointer also gradually increases, and its position changes accordingly. After a message stored in storage area N is read, the read pointer can also return to the location in storage area 0. The write pointer value will be equal to the read pointer value in two cases: one is when the data queue is full, i.e., storage areas 0-N all contain messages; the other is when the data queue is empty. Regarding the first scenario, in some implementations, before each message is written to the data queue, the values of the write pointer and read pointer can be obtained, and it can be determined whether the value of the write pointer is equal to the value of the read pointer after the current write operation. If they are equal, it means that the data queue will be full after this write operation. Similarly, regarding the second scenario, in some implementations, before each message is read from the data queue, the values of the write pointer and read pointer can also be obtained, and it can be determined whether the value of the read pointer is equal to the value of the write pointer after the current read operation. If they are equal, it means that the data queue will be empty after this read operation.
[0032] In this embodiment of the application, the consumer on the computing device side is used to read messages from the data queue and update the value of the read pointer, while the producer on the server side is used to write messages to the data queue and update the value of the write pointer.
[0033] Server 21 may include multiple producers. Figure 2 shows threads T0, T1, ..., Tn-1, all of which are producers, where n is a positive integer greater than 1. Threads T0 to Tn-1 may concurrently add messages to the data queue in computing device 22. In this case, a mutual exclusion mechanism is needed to ensure that multiple threads access the data queue mutually exclusively. The mutual exclusion mechanism can be implemented through atomic operations. In this embodiment, a shadow variable (queue->index) is set on the server 21 side. This queue->index is used to indicate the value of the write pointer of the data queue. Exemplarily, this queue->index can be stored in the local memory of server 21. Multiple threads T0 to Tn-1 in server 21 can focus atomic operations on this queue->index; that is, multiple threads T0 to Tn-1 can each perform atomic operations by preempting this queue->index.
[0034] In some embodiments, the high-address bits of queue->index can be used to indicate the marking information of the thread that successfully preempted queue->index, such as the thread ID, and the low-address bits of queue->index can be used to indicate the value of the write pointer of the data queue. For example, queue->index can be set to 64 bits, where the size of the thread marking information can be 32 bits and the size of the write pointer can be 32 bits. However, this application is not limited to this; the size of queue->index can be adjusted as needed, for example, it can be 8 bits, 16 bits, 32 bits, 64 bits, etc. Similarly, the size of the write pointer can also be adjusted as needed. It is understood that at initialization, queue->index is 0.
[0035] When multiple threads in server 21 need to add messages to the data queue, these threads can each preempt the queue->index on the server side through atomic operations. It can be understood that queue->index can only be successfully preempted by one thread at a time through an atomic operation. Other threads that fail in their atomic operations need to retry until the atomic operation succeeds.
[0036] In some implementations, the atomic operation in this application is a Compare and Swap (CAS) operation. The execution process of the CAS operation includes: when the expected value is the same as the value of the write pointer indicated by the low address bit of queue->index, the value of the write pointer indicated by the low address bit of queue->index is atomically incremented.
[0037] For example, during initialization, the values of the read pointer, write pointer, and queue->index are all 0. At this time, server-side threads T0, T1, ..., Tn-1 simultaneously execute CAS operations:
[0038] CAS(&q->index,¤t,tidTn-1|index+1);
[0039] ...
[0040] CAS(&q->index,¤t,tidTi|index+1);
[0041] ...
[0042] CAS(&q->index,¤t,tidT1|index+1);
[0043] CAS(&q->index,¤t,tid T0|index+1);
[0044] Here, `current` is the expected value, `current = q->index & 0xffffffff`, initially `current` is 0. In `tidTi|index+1`, `tidTi` represents the ID of thread Ti, where i ∈ [0, n-1]; `index+1` represents the value of the write pointer indicated by the low address bit of `queue->index` after atomic increment. The initial value of `index` is 0. When any thread's CAS operation succeeds, for example, when thread T1's CAS operation succeeds, the thread's marker information indicated by the high address bit of `queue->index` becomes `tidT1`, and the value of the write pointer indicated by the low address bit changes from 0 to 1.
[0045] Once any thread on the server side successfully preempts queue->index via an atomic operation, that thread will be executed. The thread that successfully preempted queue->index can send a message to the data queue and update the write pointer of the data queue using the value indicated by the lower address bit of the updated queue->index to keep them synchronized.
[0046] The following example illustrates the process of concurrent message addition by multiple threads, where n is an integer greater than 1 and K is an integer greater than 1 and less than or equal to n.
[0047] Please refer to Figure 3. In this embodiment of the application, the process of adding messages by a thread on the server side includes:
[0048] S31, K threads on the server side preempt the queue->index in the server through atomic operations.
[0049] S32, when any one of the K threads successfully preempts queue->index through an atomic operation, the value of the write pointer indicated by the low address bit of queue->index is updated, and the high address bit of queue->index indicates the marking information of the thread that successfully preempted queue->index.
[0050] It's understandable that once the high address bit of `queue->index` indicates the marker information of the thread that successfully preempted `queue->index`, `queue->index` is essentially locked, and atomic operations by other threads will fail. However, when the atomic operation is a CAS operation, the value of the write pointer indicated by the low address bit of `queue->index` is atomically incremented when any thread's atomic operation succeeds.
[0051] S33, the thread that successfully preempted queue->index writes the message to the data queue, and after the message is written to the data queue, updates the value of the write pointer of the data queue according to the value of the write pointer indicated by the low address bit of queue->index. This ensures that the value of the write pointer of the data queue is consistent with the value of the write pointer indicated by the low address bit of queue->index.
[0052] S34, the thread that successfully preempted queue->index clears the thread's marker information indicated by the high address bit of queue->index.
[0053] It is understandable that when the thread's marking information indicated by the high address bit of queue->index is removed, queue->index is essentially unlocked, and only then can atomic operations of other threads succeed.
[0054] Referring to Figure 4, in some implementations, the computing device is configured to perform the following steps:
[0055] S41, determine whether there is a message to be read in the data queue based on the values of the read pointer and write pointer of the data queue.
[0056] S42, if there is a message to be read in the data queue, read the message from the data queue for processing.
[0057] S43, Update the value of the read pointer of the data queue.
[0058] It is worth noting that this embodiment is illustrated using the example of a data queue being set up in computing device 22. During multi-threaded concurrency on server 21, after any thread successfully adds a message to the data queue, that thread updates the write pointer value of the data queue. Threads on computing device 22 acquire, distribute, and process messages through a multi-core pipeline. Since both the read and write pointers of the data queue are on the computing device side, computing device 22 can quickly read data. However, this application is not limited to this; in other embodiments, the data queue can also be set up in server 21. In these embodiments, computing device 22 can read messages in the data queue using methods such as DMA (Direct Memory Access).
[0059] This embodiment sets a queue->index on the server side, focusing atomic operations of multiple threads on this queue->index. This confines the atomic operations of server-side threads to the server side, preventing remote atomic operations on the write pointer of the computing device and improving system performance. Furthermore, atomic operations can utilize CAS (Compare-and-Swap) operations. When any thread successfully performs a CAS operation, its marker information is stored in queue->index to lock queue->index, and the write pointer value indicated by queue->index is updated. After the thread writes the message to the data queue, the write pointer value of the data queue is updated based on the updated write pointer value in queue->index. Only then is the thread marker information indicated by queue->index removed to unlock queue->index. This ensures that message writing and write pointer updates are completed within a complete mutual exclusion protection mechanism, guaranteeing data integrity.
[0060] It is understood that this application can also be applied to other producer-consumer models, such as multi-producer-multi-consumer models or single-producer-multi-consumer models. When the server side includes multiple threads, the message addition process can be referred to the multi-producer-single-consumer model above. When the device side includes multiple threads, a queue->index needs to be set for the read pointer on the device side. A portion of its address bits (such as the high address bits of queue->index) is used to indicate the flag information of the thread that successfully preempted the queue->index, and another portion of the address bits (such as the low address bits of queue->index) is used to indicate the value of the read pointer. Similar to the above-mentioned multiple threads on the server side focusing atomic operations on the queue->index on the server side, the atomic operations of multiple threads on the device side are all focused on the queue->index on the device side. When a thread on the device side successfully preempts the queue->index on the device side, the high address bits of queue->index indicate the flag information of that thread, and the low address bits indicate the updated value of the read pointer. At this point, the thread can read a message from the data queue; then, the thread can update the value of the read pointer of the data queue according to the updated read pointer value in queue->index; finally, the thread clears the marking information of the thread indicated by queue->index, so that other threads on the device side can successfully perform atomic operations.
[0061] The above embodiments are merely illustrative of the principles and effects of this application and are not intended to limit this application. Any person skilled in the art can modify or alter the above embodiments without departing from the spirit and scope of this application. Therefore, all equivalent modifications or alterations made by those skilled in the art without departing from the spirit and technical concept disclosed in this application should still be covered by the claims of this application.
Claims
1. A heterogeneous computing system, characterized in that, The system includes a server and a computing device, which share a data queue. The server has a shadow variable that indicates the value of the write pointer to the data queue. The server includes n threads, where n is an integer greater than 1. When K threads concurrently add messages to the data queue, the K threads are configured to: preempt the shadow variable through atomic operations; when any one of the K threads successfully preempts the shadow variable, the shadow variable is updated, and the thread that successfully preempts the shadow variable can write the message to the data queue. After writing the message to the data queue, the thread updates the write pointer of the data queue according to the updated shadow variable, where K is greater than 1 and less than or equal to n. The threads in the computing device are configured to read messages from the data queue for processing and, after reading the message, update the read pointer of the data queue.
2. The heterogeneous computing system according to claim 1, characterized in that, The data queue is set up in the computing device or the server.
3. The heterogeneous computing system according to claim 1, characterized in that, The high address bits of the shadow variable are used to indicate the marker information of the thread that successfully preempted the shadow variable, and the low address bits of the shadow variable are used to indicate the value of the write pointer of the data queue.
4. The heterogeneous computing system according to claim 3, characterized in that, The shadow variable update includes: the high address bit of the shadow variable indicates the marker information of the thread that has successfully preempted the shadow variable, and the low address bit of the shadow variable indicates the value of the write pointer of the data queue is incremented; the update of the write pointer value of the data queue according to the updated shadow variable includes: updating the write pointer value of the data queue according to the value of the write pointer indicated by the updated low address bit of the shadow variable.
5. The heterogeneous computing system according to claim 4, characterized in that, The marker information is the ID of the thread that successfully preempted the shadow variable.
6. The heterogeneous computing system according to claim 4, characterized in that, After the thread that successfully preempts the shadow variable updates the value of the write pointer of the data queue according to the updated shadow variable, it is also used to clear the marking information of the thread indicated by the high address bit of the shadow variable.
7. The heterogeneous computing system according to claim 1, characterized in that, The server maps the memory of the computing device to its local memory via PCIe memory-mapped I / O.
8. The heterogeneous computing system according to claim 1, characterized in that, The data queue is implemented using a lock-free circular buffer.
9. The heterogeneous computing system according to claim 1, characterized in that, The atomic operation is a compare-and-swap operation.
10. The heterogeneous computing system according to claim 1, characterized in that, The computing device is configured to perform the following steps: determine whether there is a message to be read in the data queue based on the value of the read pointer and the value of the write pointer of the data queue; if there is a message to be read in the data queue, read the message from the data queue for processing; and update the value of the read pointer of the data queue.
11. A server, characterized in that, This invention is applied to a heterogeneous computing system, which also includes a computing device communicatively connected to the server. The server and the computing device share a data queue. The server has a shadow variable that indicates the value of the write pointer of the data queue. The server includes n threads, where n is an integer greater than 1. When K threads out of the n threads concurrently add messages to the data queue, the K threads are configured such that: each of the K threads preempts the shadow variable through an atomic operation; when any one of the K threads successfully preempts the shadow variable through an atomic operation, the shadow variable is updated, and the thread that successfully preempts the shadow variable can write the message to the data queue. After writing the message to the data queue, the thread updates the value of the write pointer of the data queue according to the updated shadow variable, where K is greater than 1 and less than or equal to n.
12. A heterogeneous computing method, characterized in that, A server is applied in a heterogeneous computing system. The system further includes a computing device communicatively connected to the server. The server and the computing device share a data queue. The server has a shadow variable that indicates the value of the write pointer of the data queue. The server includes n threads, where n is an integer greater than 1. When K threads out of the n threads concurrently add messages to the data queue, the heterogeneous computing method includes: the K threads each preempting the shadow variable through atomic operations, where K is greater than 1 and less than or equal to n; when any one of the K threads successfully preempts the shadow variable through an atomic operation, the shadow variable is updated, and the thread that successfully preempted the shadow variable writes the message to the data queue and updates the value of the write pointer of the data queue according to the updated shadow variable.
