Initialization method of execution unit, chip and shared memory

CN123036582APending Publication Date: 2026-11-03GLENFLY TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202680002029.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-05-15
Publication Date
2026-11-03

AI Technical Summary

Technical Problem

In existing technologies, implementing shared memory initialization through software patches is complex and insecure, making it difficult to meet the requirements for flexibility and security.

Method used

By introducing a thread constructor and a shared memory controller into the execution unit, and utilizing the initialization control register and workgroup table, hardware-based shared memory initialization, including initialization and write units, is achieved, simplifying compiler work and improving security.

Benefits of technology

It achieves hardware initialization of shared memory, simplifies compiler work, improves security and flexibility, and adapts to the performance and security requirements of different application scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123036582A_ABST
    Figure CN123036582A_ABST
Patent Text Reader

Abstract

The application relates to an execution unit, a chip and a shared memory initialization method. The execution unit comprises a thread constructor and a shared memory controller. The thread constructor is used for informing the shared memory controller to perform an initialization operation on the shared memory after determining that the received work group is subjected to the initialization operation on the shared memory. The shared memory controller is used for performing the initialization operation by writing an initialization value into the shared memory. The technical scheme of the application can avoid performing the initialization of the shared memory through a software patch, simplify the work of a compiler, and improve safety by performing the initialization of the shared memory through hardware.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of parallel computing technology, specifically to an initialization method for an execution unit, a chip, and shared memory. Background Technology

[0002] In the field of computer computing, most current computing tasks do not require initializing the workgroup's Storage Manager (SM) because this operation is time-consuming and not particularly necessary. However, sometimes it is necessary to debug and verify the SM, or in certain special situations, to prevent malicious applications from illegally obtaining special data stored in the SM, so initialization is still necessary. Therefore, Vulkan 1.3 introduced a new extension that allows setting a variable; if this variable is true, the corresponding SM space is initialized to 0 when each workgroup starts, preventing potential malicious attacks.

[0003] To implement extended functionality in Vulkan 1.3, a software patch can be used. This involves adding a write instruction to the SM (Site Controller) at the beginning of a client-server (CS) program, allowing each thread to write a portion of the SM space to zero.

[0004] Because the number of waves that a workgroup may split into can vary, and the size of the SM space is not fixed, the number of write instructions and the SM address required each time will also differ, which brings more complex design work to the compiler. Furthermore, this operation is not safe; if these write instructions are modified or masked, the SM initialization operation can be easily bypassed. Summary of the Invention Technical issues

[0005] The technical problem to be solved by this application is to provide an execution unit, chip, and shared memory initialization method that avoids the need for software patching to initialize shared memory, simplifies the compiler's work, and improves security by implementing shared memory initialization through hardware. Technical solution

[0006] To address the aforementioned technical problems, according to a first aspect of the present application, an execution unit is provided, applied to a chip performing general computing tasks, comprising: a thread constructor, configured to notify the shared memory controller to perform an initialization operation on the shared memory after determining that an initialization operation will be performed on the shared memory of a received workgroup; and a shared memory controller, configured to perform the initialization operation by writing an initialization value to the shared memory.

[0007] In one implementation, the thread constructor may include an initialization control register, the value of which indicates whether to initialize the shared memory. The thread constructor is used to notify the shared memory controller whether to initialize the shared memory of the workgroup based on the value of the initialization control register. By introducing an initialization control register into the thread constructor, the function of initializing shared memory can be enabled or disabled through its value. This allows for flexibility by enabling or disabling the initialization of shared memory according to different performance and security requirements of the application scenario.

[0008] In one embodiment, the shared memory controller may store a workgroup table, which may include the following entries: workgroup identifier, valid flag, base address of the workgroup in the shared memory, address range length of the workgroup in the shared memory, and initialization flag; the value of the valid flag indicates whether the corresponding workgroup is valid; the value of the initialization flag indicates whether the shared memory of the corresponding workgroup has completed the initialization operation; when the value of the initialization flag is a first value, it can be used to indicate that the shared memory of the corresponding workgroup has not completed the initialization operation, and when the value of the initialization flag is a second value, it can be used to indicate that the shared memory of the corresponding workgroup has completed the initialization operation; the first value... The value is different from the second value; before the initialization operation is completed, the value of the initialization flag is the first value; the shared memory controller may include an initialization unit and a write unit, the initialization unit may include an initialization value register, the initialization value register is used to store the initialization value; when the shared memory controller performs an initialization operation on the shared memory of the workgroup, the initialization unit writes the initialization value to all rows in the address range of the shared memory of the workgroup through the write unit; the address range is obtained based on the base address and the address interval length; after the initialization operation is completed, the initialization unit adjusts the value of the initialization flag to the second value.

[0009] In one implementation, the initialization unit can write one line of the initialization value to the address range of the shared memory of the workgroup each time through the write unit, until all lines in the address range of the shared memory of the workgroup have been written with the initialization value. The function of initializing shared memory can be implemented in hardware by updating and modifying existing thread constructors and shared memory controllers, and the initialization work is converted into a series of write operations to shared memory, making hardware implementation relatively simple.

[0010] In one implementation, when the value of the valid flag bit is a third value, it can be used to indicate that the corresponding workgroup is invalid; when the value of the valid flag bit is a fourth value, it can be used to indicate that the corresponding workgroup is valid; the third value and the fourth value are different; after receiving the workgroup, the thread constructor notifies the shared memory controller of the workgroup identifier, the base address of the workgroup in the shared memory, the address range length of the workgroup in the shared memory, and the value of the initialization control register; after receiving the workgroup identifier, the base address of the workgroup in the shared memory, the address range length of the workgroup in the shared memory, and the value of the initialization control register, the shared memory controller fills the workgroup identifier into the workgroup table. The shared memory controller sets the value of the valid flag corresponding to the workgroup identifier in the workgroup table to the fourth value, and then fills the base address of the workgroup in the shared memory and the address range length of the workgroup in the shared memory into the workgroup table. When the value of the initialization control register indicates that the shared memory should be initialized, the shared memory controller first sets the value of the initialization flag corresponding to the workgroup identifier to the first value, then performs the initialization operation on the shared memory, and after the initialization operation is completed, adjusts the value of the initialization flag to the second value. When the value of the initialization control register indicates that the shared memory should not be initialized, the value of the initialization flag corresponding to the workgroup identifier is set to the second value.

[0011] In one implementation, after receiving an access instruction for the shared memory of the workgroup, the shared memory controller can determine whether the shared memory of the workgroup has completed the initialization operation through the initialization flag; if it is determined that the shared memory of the workgroup has not completed the initialization operation, the access instruction is suspended; if it is determined that the shared memory of the workgroup has completed the initialization operation, the access instruction is executed.

[0012] In one embodiment, the execution unit may further include a thread scheduler; during the initialization operation of the shared memory, the thread constructor is also used to construct the thread bundles of the workgroup, and the thread bundles are scheduled to be executed by the thread scheduler; after all the thread bundles of the workgroup have been executed, the thread constructor notifies the shared memory controller to clear the data in the table entry corresponding to the workgroup identifier of the workgroup, and sets the value of the valid flag bit to the third value, and sets the value of the initialization flag bit to the first value.

[0013] According to a second aspect of the embodiments of this application, a chip is provided, including the execution unit described above.

[0014] In one embodiment, the chip is a graphics processor or an artificial intelligence chip.

[0015] According to a third aspect of the embodiments of this application, a method for initializing shared memory is provided, applied to the aforementioned execution unit. The method includes: after determining that a shared memory initialization operation is to be performed on the received workgroup's shared memory, the thread constructor notifies the shared memory controller to perform an initialization operation on the shared memory; the shared memory controller performs the initialization operation by writing an initialization value to the shared memory. Invention Overview Beneficial effects

[0016] Compared with the prior art, the beneficial effects of this application are as follows:

[0017] After the thread constructor in the execution unit determines that the shared memory of the received workgroup needs to be initialized, it notifies the shared memory controller in the execution unit to initialize the shared memory. The shared memory controller performs the initialization operation by writing initialization values ​​to the shared memory. In this way, the initialization of shared memory is avoided by using software patches, which simplifies the compiler's work. Implementing the initialization of shared memory in hardware can improve security. Attached Figure Description

[0018] Figure 1 This is a schematic diagram of the structure of an execution unit according to an exemplary embodiment.

[0019] Figure 2 This is a flowchart illustrating a shared memory initialization method according to an exemplary embodiment.

[0020] Figures 3-5 This is a flowchart illustrating a shared memory initialization method according to another exemplary embodiment. Embodiments of the present invention

[0021] Unless otherwise defined, the technical or scientific terms used in this specification and claims shall have the ordinary meaning understood by one of ordinary skill in the art to which this application pertains. Specific embodiments of this application will be described below in conjunction with the accompanying drawings. It should be noted that, in order to provide a concise description, this specification cannot exhaustively describe all features of the actual embodiments. Without departing from the spirit and scope of this application, those skilled in the art can modify and substitute the embodiments of this application, and the resulting embodiments are also within the protection scope of this application.

[0022] In related technologies, Graphics Processing Units (GPUs) contain a large number of parallel processing units that can be programmed to perform Single Instruction Multiple Data (SIMD) parallel computations. This allows GPUs to be used not only for hardware acceleration of graphics rendering but also for general-purpose parallel computing. To this end, several companies and researchers have launched the Open Computing Language (OpenCL) platform, which allows the writing of kernel functions, similar to the C language, and provides an Application Programming Interface (API) to control the platform. Furthermore, graphics rendering platforms such as DirectX (Direct eXtension, DX), the Open Graphics Library (OpenGL), and Vulkan have all incorporated general-purpose computing program functionality, generally called Compute Shaders (CS), similar to OpenCL. Through CS or OpenCL, programmers can easily utilize GPUs as parallel processors for fields such as image processing, physics simulation, artificial intelligence, and scientific computing.

[0023] OpenCL and CS commonly use three-dimensional parameters to represent computational tasks, dividing the computation space into a series of workgroups. Each workgroup is scheduled to an execution unit (EU) on the chip, and then further subdivided into multiple wavelets. Each wavelet is typically in simd32 or simd64 form. simd32 represents 32 sub-units (threads (lanes)) executing simultaneously, while simd64 represents 64 sub-units (threads) executing simultaneously. To facilitate data exchange among multiple wavelets within the same workgroup, the EU also has a piece of static random-access memory (SRAM) for recording intermediate data, called shared memory (SM). Each workgroup has its own SM space, allowing different wavelets within the same workgroup to read and write data to the SM via instructions. The following describes some embodiments of this application in detail with reference to the accompanying drawings. Unless otherwise specified, the following embodiments and features can be combined with each other.

[0024] One embodiment of this application provides an execution unit. This execution unit can be applied to a chip that performs general-purpose computing tasks. The chip can be a graphics processing unit (GPU) or an artificial intelligence chip. The artificial intelligence chip can be a general-purpose graphics processing unit (GPGPU) or a neural processing unit (NPU), but is not limited thereto.

[0025] Figure 1 This is a schematic diagram of the structure of an execution unit according to an exemplary embodiment.

[0026] like Figure 1 As shown, the execution unit may include: a thread constructor 11, a thread scheduler 12, multiple computing units 13, an instruction cache 14, shared memory 15, and a shared memory controller 16.

[0027] The following section will first introduce the execution unit and the original functions of each hardware component, and then introduce how the execution unit initializes shared memory 15.

[0028] The Thread Constructor (CSTC)11 is used to split the input workgroup into a series of Waves based on the three-dimensional computation space. Each Wave is generally in the form of simd32 or simd64. simd32 means that 32 threads execute simultaneously, and simd64 means that 64 threads execute simultaneously.

[0029] The Wave Controller (WVC) 12 is a control unit used to manage and schedule each thread bundle, performing steps such as scheduling thread bundles, fetching instructions, decoding, and issuing. Each clock cycle, a suitable thread bundle is selected from multiple thread bundles according to priority, instructions are read from the instruction cache 14, and executed.

[0030] The computation unit 13 is the core component of the execution unit, used to complete the computation function of the thread bundle. It can process the computation of multiple threads simultaneously in a SIMD manner, including arithmetic operations, logical operations, bitwise operations, jump judgments, and special functions. Figure 1 The diagram shows two computing units 13, but in a specific implementation, the execution unit may include more computing units 13.

[0031] Instruction cache 14 is used to read instructions for each thread bundle based on the requested instruction offset address. Instruction cache 14 can be a cache that includes cache space, matching control logic, tag units, etc. The cache space of instruction cache 14 can be organized and managed in the form of multiple cache lines.

[0032] Shared memory 15 can be a readable and writable SRAM, but is not limited to this. Each workgroup can be allocated a block of shared memory 15 for data exchange among multiple thread bundles of the workgroup. In one embodiment, the total size of shared memory 15 can be 1024 rows, numbered from 0 to 1023.

[0033] The thread bundle can access the shared memory 15 by reading and writing through the shared memory controller 16. The access instructions for the shared memory 15 can be divided into three types: read instructions, write instructions and atomic operation instructions.

[0034] like Figure 1 As shown, the shared memory controller 16 may include a write unit 161, a read unit 162, and an atomic operation unit 163.

[0035] The write unit 161 can be used to execute write instructions to write the data of the thread bundle into the shared memory 15. The read unit 162 is used to execute read instructions to read data from the shared memory 15 and return it to the corresponding thread bundle. The atomic operation unit 163 is used to execute atomic operation instructions to read data from the shared memory 15 and return it to the corresponding thread bundle, and to perform operations such as addition, subtraction, maximum value, minimum value, exch, and comparison and swap (cmp_exch), and write the operation results back to the shared memory 15.

[0036] The shared memory controller 16 may store a workgroup table to record shared memory information for each workgroup. The workgroup table may include the following entries: workgroup identifier, valid flag, base address of the workgroup in shared memory 15, and address range length of the workgroup in shared memory 15.

[0037] In one embodiment, a third value for the valid flag indicates that the corresponding workgroup is invalid. A fourth value for the valid flag indicates that the corresponding workgroup is valid. The third and fourth values ​​are different.

[0038] In one embodiment, the third value can be 0, and the fourth value can be 1. When the value of the valid flag is 0, it indicates that the corresponding workgroup is invalid. When the value of the valid flag is 1, it indicates that the corresponding workgroup is valid. It should be noted that the value of the third value is not limited to 0, and the value of the fourth value is not limited to 1.

[0039] The workgroup table can contain 0 to M-1 rows, where M is the number of workgroups that the current execution unit can execute simultaneously, typically 32 or 64, but not limited to these values. Each row's entries record the shared memory information of the corresponding workgroup.

[0040] Assuming the entire shared memory 15 has 1024 rows, the base address is 10 bits, used to represent the base address of rows 0 to 1023 of shared memory 15. The address range length is 11 bits, indicating that each workgroup occupies rows 0 to 1024, and 0 indicates that no space in shared memory 15 is occupied.

[0041] The thread constructor 11 provides an identifier for each input workgroup, called the workgroup identifier (groupID), which can be 0 to M-1. For each new workgroup, the thread constructor 11 will notify the shared memory controller 16 of the workgroup identifier, the validity flag, the base address of the workgroup in shared memory 15, and the address range length of the workgroup in shared memory 15. The shared memory controller 16 fills the workgroup identifier, the base address of the workgroup in shared memory 15, and the address range length of the workgroup in shared memory 15 into the workgroup table, and sets the corresponding validity flag to 1, indicating that the workgroup corresponding to the workgroup identifier is valid.

[0042] The thread constructor 11 divides the three-dimensional computation space of the workgroup into a series of thread bundles according to the current thread bundle width mode, and then sends the obtained thread bundles to the thread bundle scheduler for scheduling and execution. The thread bundle scheduler selects a thread bundle, retrieves instructions from the instruction cache 14, and if it is a normal arithmetic or logical operation instruction, it is sent to the computation unit 13 for execution; if it is an access instruction to shared memory 15, it is sent to the shared memory controller 16 for processing. The thread bundle width mode is either SIMD32 mode or SIMD364 mode. SIMD32 mode means that a single thread bundle contains 32 parallel threads, and the hardware executes instructions with a 32-way width; SIMD364 mode means that a single thread bundle contains 64 parallel threads, and the hardware executes instructions with a 64-way width.

[0043] After receiving the access instruction from the shared memory 15, the shared memory controller 16 finds the base address of the workgroup and the address range length of the workgroup in the shared memory 15 from the workgroup table according to the workgroup identifier of the corresponding thread bundle. If the address of the access instruction of the shared memory 15 exceeds the address range of the shared memory 15 of the workgroup, it is considered to be out of bounds and out of bounds processing is performed: the read unit 162 and the atomic operation unit 163 return 0 value, and the write unit 161 discards the write operation.

[0044] If the address of the access instruction for shared memory 15 is within the address range of shared memory 15 in the workgroup, then the shared memory controller 16 calculates the sum of base and offset based on the address offset value of each thread attached to the access instruction (this address offset value is the offset address of each thread within the shared memory 15 in the current workgroup, which can be denoted as offset), to obtain the actual address in shared memory 15, and then performs the corresponding access operation on shared memory 15.

[0045] Once all thread bundles in the workgroup have finished executing, the thread constructor 11 will notify the workgroup table of the shared memory controller 16 to clear all the data in the table entry corresponding to the workgroup identifier and set the value of the valid flag bit to 0, indicating that the workgroup has finished executing.

[0046] The above describes the execution unit and the original functions of each hardware component. The following describes how the execution unit initializes shared memory 15.

[0047] Upon receiving a new workgroup, thread constructor 11 determines whether to initialize the shared memory 15 of the received workgroup. If it determines to initialize the shared memory 15, it notifies shared memory controller 16 to initialize shared memory 15. Upon receiving the notification to initialize shared memory 15, shared memory controller 16 performs the initialization operation by writing initialization values ​​to shared memory 15. This avoids initializing shared memory 15 through software patches, simplifying the compiler's work. Hardware-based initialization of shared memory 15 improves security.

[0048] like Figure 1 As shown, the thread constructor 11 includes an initialization control register 111. The value of the initialization control register 111 is used to indicate whether to perform an initialization operation on the shared memory 15. The thread constructor 11 is used to notify the shared memory controller 16 whether to perform an initialization operation on the shared memory 15 of the workgroup based on the value of the initialization control register 111.

[0049] In one embodiment, when the initialization control register 111 is set to a fifth value, it indicates that the shared memory 15 should not be initialized; when the initialization control register 111 is set to a sixth value, it indicates that the shared memory 15 should be initialized. The fifth and sixth values ​​are different.

[0050] In one embodiment, the fifth value is 0 and the sixth value is 1. When the value of the initialization control register 111 is 0, it indicates that the shared memory 15 should not be initialized; when the value of the initialization control register 111 is 1, it indicates that the shared memory 15 should be initialized. In other embodiments, the value of the fifth value is not limited to 0, and the value of the sixth value is not limited to 1.

[0051] In one embodiment, the storage space occupied by the value of the initialization control register 111 can be 1 bit.

[0052] Since initializing shared memory 15 is time-consuming and affects performance, and many computing tasks do not require initializing shared memory 15, an initialization control register 111 can be defined in the thread constructor 11. By default, when the value of initialization control register 111 is 0, it is used to indicate that shared memory 15 is not initialized. Only in certain special cases is the value of initialization control register 111 set to 1 to enable the function of initializing shared memory 15.

[0053] By introducing an initialization control register 111 in the thread constructor 11, the function of initializing shared memory 15 can be enabled or disabled by initializing the value of the control register 111. This allows for the opening or closing of the initialization function of shared memory 15 according to different performance and security requirements of the application scenario, thus improving flexibility.

[0054] The shared memory controller 16 stores a workgroup table, which includes the following entries: workgroup identifier, valid flag, base address of the workgroup in shared memory 15, address range length of the workgroup in shared memory 15, and initialization flag. The value of the valid flag indicates whether the corresponding workgroup is valid. The value of the initialization flag indicates whether the shared memory 15 of the corresponding workgroup has completed the initialization operation.

[0055] In one embodiment, the storage space occupied by the initialization flag bit can be 1 bit.

[0056] As shown in Table 1, the entries in the workgroup table of the shared memory controller 16 include, in addition to the workgroup identifier, valid flag, base address of the workgroup in shared memory 15, and address range length of the workgroup in shared memory 15, an initialization flag (sm_init_done). The value of the valid flag indicates whether the corresponding workgroup is valid.

[0057] When the initialization flag is set to the first value, it indicates that the shared memory 15 of the corresponding workgroup has not completed the initialization operation. When the initialization flag is set to the second value, it indicates that the shared memory 15 of the corresponding workgroup has completed the initialization operation. The first and second values ​​are different. Before the initialization operation is completed, the initialization flag is set to the first value.

[0058] In one embodiment, the first value is 0 and the second value is 1. When the initialization flag is 0, it indicates that the shared memory 15 of the corresponding workgroup has not completed the initialization operation; when the initialization flag is 1, it indicates that the shared memory 15 of the corresponding workgroup has completed the initialization operation. In other embodiments, the value of the first value is not limited to 0, and the value of the second value is not limited to 1.

[0059] Table 1

[0060]

[0061] For example, thread constructor 11 notifies shared memory controller 16 to perform initialization operation on shared memory 15 of workgroup with groupID 1. When the corresponding sm_init_done value is 0, it means that shared memory 15 of workgroup with groupID 1 has not completed the initialization operation.

[0062] like Figure 1 As shown, the shared memory controller 16 also includes an initialization unit 164, which includes an initialization value register 1641 for storing initialization values. The initialization value can be 0 or any other arbitrary value, and can be flexibly set according to requirements. Because of the initialization value register 1641, it supports setting the initialization value to any value, providing good scalability and increased flexibility.

[0063] In one embodiment, the initialization value register 1641 can be a 32-bit register, but is not limited to this.

[0064] When the shared memory controller 16 performs an initialization operation on the shared memory 15 of the workgroup, the initialization unit 164 can obtain the address range of the shared memory 15 of the workgroup based on the base address and the address range length, and write the initialization value to all rows in the address range of the shared memory 15 of the workgroup through the write unit 161.

[0065] For example, thread constructor 11 notifies shared memory controller 16 to perform initialization operation on shared memory 15 of workgroup with groupID 1, and initialization unit 164 writes initialization values ​​to all rows of shared memory 15 with address range (0X100, 0X100+20).

[0066] In one embodiment, the initialization unit 164 writes one line of initialization value to the address range of the shared memory 15 of the workgroup each time through the write unit 161, until all lines in the address range of the shared memory 15 of the workgroup are written with initialization values. For example, the initialization unit 164 can perform a cyclic write operation through the write unit 161 in ascending order of the addresses of the shared memory 15 of the workgroup, writing one line of initialization value to the address range of the shared memory 15 of the workgroup each time, until all lines in the address range of the shared memory 15 of the workgroup are written with initialization values. The initialization unit 164 completes the initialization operation of the shared memory 15 by performing multiple cyclic write operations, which can save hardware overhead.

[0067] In one embodiment, the initialization unit 164 can complete the shared memory 15 initialization operation by executing the code shown in Table 2 below.

[0068] Table 2

[0069]

[0070] After the initialization operation is completed, the initialization unit 164 adjusts the value of the initialization flag to the second value. When the second value is 1, it indicates that the shared memory 15 of the workgroup has completed the initialization operation.

[0071] In this embodiment, the function of initializing the shared memory 15 can be implemented in hardware by updating and modifying the existing thread constructor 11 and shared memory controller 16, and the initialization work is converted into a series of write operations on the shared memory 15, which is relatively simple to implement in hardware.

[0072] The above describes the functions of the thread constructor 11 and the shared memory controller 16 used by the execution unit to initialize the shared memory 15. The following describes the process of the execution unit initializing the shared memory 15.

[0073] After receiving the work group, thread constructor 11 notifies shared memory controller 16 of the work group identifier, the base address of the work group in shared memory 15, the length of the address range of the work group in shared memory 15, and the value of initialization control register 111.

[0074] After receiving the workgroup identifier of the workgroup, the base address of the workgroup in shared memory 15, the address range length of the workgroup in shared memory 15, and the value of the initialization control register 111, the shared memory controller 16 fills the workgroup identifier into the workgroup table and sets the value of the valid flag bit corresponding to the workgroup identifier in the workgroup table to the fourth value (for example, the fourth value can be 1, indicating that the workgroup is valid). Then, it fills the base address of the workgroup in shared memory 15 and the address range length of the workgroup in shared memory 15 into the workgroup table.

[0075] When the value of the initialization control register 111 (e.g., the value of the initialization control register 111 is 1) indicates that the shared memory 15 should be initialized, the shared memory controller 16 first sets the value of the initialization flag corresponding to the workgroup identifier to a first value (e.g., the first value is 0, indicating that the shared memory 15 of the workgroup has not completed the initialization operation), then performs the initialization operation on the shared memory 15, and after the initialization operation is completed, adjusts the value of the initialization flag to a second value (e.g., the second value is 1, indicating that the shared memory 15 of the workgroup has completed the initialization operation).

[0076] When the value of the initialization control register 111 (e.g., the value of the initialization control register 111 is 0) indicates that the shared memory 15 should not be initialized, the shared memory controller 16 sets the value of the initialization flag corresponding to the workgroup identifier to a second value (e.g., the second value is 1).

[0077] If the shared memory controller 16 receives an access instruction for the shared memory 15 of the workgroup, it determines whether the shared memory 15 has completed its initialization operation by checking the initialization flag. If it determines that the shared memory 15 has not completed its initialization operation, it suspends the access instruction. The access instruction is then executed once the shared memory 15 has completed its initialization operation.

[0078] In this embodiment of the application, since the initialization process of shared memory 15 is a cyclic write operation, it may take some time. During the initialization operation of shared memory 15, thread constructor 11 is also used to construct the thread bundle of the work group, and the thread bundle is scheduled and executed by thread scheduler 12.

[0079] After all threads in the workgroup have finished executing, the thread constructor 11 notifies the shared memory controller 16 to clear the data in the table entry corresponding to the workgroup identifier of the workgroup, set the value of the valid flag bit to the third value (for example, the third value can be 0), and set the value of the initialization flag bit to the first value (for example, the first value can be 0), indicating that the workgroup has finished executing.

[0080] In this embodiment, after the thread constructor 11 in the execution unit determines that the shared memory 15 of the received workgroup needs to be initialized, it notifies the shared memory controller 16 in the execution unit to initialize the shared memory 15. The shared memory controller 16 performs the initialization operation by writing initialization values ​​to the shared memory 15. In this way, the initialization of the shared memory 15 is avoided by using software patches, which simplifies the compiler's work. The initialization of the shared memory 15 is implemented by hardware, which can improve security.

[0081] Another embodiment of this application provides a chip. The chip includes the execution unit of any of the above embodiments.

[0082] In one implementation, the chip described above may be a graphics processor or an artificial intelligence chip.

[0083] In one implementation, the aforementioned artificial intelligence chip may be a general-purpose graphics processor or a neural network processor.

[0084] Figure 2 This is a flowchart illustrating a shared memory initialization method according to an exemplary embodiment.

[0085] Please see Figure 2 Another embodiment of this application provides a method for initializing shared memory. This shared memory initialization method is applied to the execution unit of any of the above embodiments. The shared memory initialization method may include the following steps S201 to S202:

[0086] In step S201, after determining that the shared memory of the received workgroup needs to be initialized, the thread constructor notifies the shared memory controller to initialize the shared memory.

[0087] In step S202, the shared memory controller performs an initialization operation by writing initialization values ​​to the shared memory.

[0088] In this embodiment, after the thread constructor 11 in the execution unit determines that the shared memory 15 of the received workgroup needs to be initialized, it notifies the shared memory controller 16 in the execution unit to initialize the shared memory 15. The shared memory controller 16 performs the initialization operation by writing initialization values ​​to the shared memory 15. In this way, the initialization of the shared memory 15 is avoided by using software patches, which simplifies the compiler's work. The initialization of the shared memory 15 is implemented by hardware, which can improve security.

[0089] Figures 3-5 This is a flowchart illustrating a shared memory initialization method according to another exemplary embodiment.

[0090] like Figures 3-5 As shown, another exemplary embodiment of this application also provides a method for initializing shared memory. In this embodiment, the initialization process of shared memory 15 includes a shared memory initialization stage and an instruction execution stage. The two stages are executed in parallel. When the shared memory controller 16 receives an access instruction for shared memory 15, it needs to check whether the shared memory 15 of the workgroup to which the access instruction belongs has been initialized. Only after initialization is completed will the access instruction for shared memory 15 be executed.

[0091] like Figures 3-5 As shown, the shared memory initialization method may include the following steps S301 to S313:

[0092] In step S301, the driver sets the value of the initialization control register and the initialization value according to the application's requirements.

[0093] In step S302, after receiving the workgroup, the thread constructor assigns a workgroup identifier to the workgroup and sends the shared memory information of the workgroup to the shared memory controller. The shared memory information includes the workgroup identifier, valid flag bits, the base address of the workgroup in shared memory, the address range length of the workgroup in shared memory, and the value of the initialization control register.

[0094] Step S303: The shared memory controller checks whether the value of the initialization control register is 1. When the value of the initialization control register 111 is not 1, that is, when the value of the initialization control register 111 is 0, proceed to step S304. When the value of the initialization control register 111 is 1, proceed to step S305.

[0095] In step S304, the shared memory controller updates the workgroup table based on the received shared memory information, sets the value of the valid flag bit in the row where the workgroup identifier is located to 1, and sets the value of the initialization flag bit to 1.

[0096] If the value of the initialization control register 111 is 0, it means that no initialization is required.

[0097] In step S305, the shared memory controller updates the workgroup table based on the received shared memory information, sets the value of the valid flag bit in the row where the workgroup identifier is located to 1, and sets the value of the initialization flag bit to 0.

[0098] If the value of the initialization control register 111 is 1, it means that initialization is required.

[0099] In step S306, the initialization unit writes initialization values ​​to all rows in the address range of the shared memory of the workgroup through the write unit.

[0100] For example, initialization unit 164 can perform a cyclic write operation through write unit 161, following the ascending order of the addresses of shared memory 15 in the workgroup. Each time, it writes an initialization value within the address range of shared memory 15, until all lines within the address range of shared memory 15 are filled with initialization values. Initialization unit 164 completes the initialization of shared memory 15 by performing multiple cyclic write operations, thus saving hardware overhead.

[0101] Step S307: After confirming that the initialization operation of the shared memory is complete, adjust the value of the initialization flag to 1.

[0102] Steps S303 to S307 belong to the shared memory initialization stage.

[0103] In step S308, the thread constructor splits the workgroup into multiple thread bundles and schedules the thread bundles to the thread scheduler for execution.

[0104] In step S309, the thread scheduler dynamically schedules thread bundles and reads instructions from the instruction cache.

[0105] In step S310, if the instruction read by the thread scheduler is a shared memory access instruction, it is sent to the shared memory controller for processing.

[0106] If the instruction read by thread scheduler 12 is a normal computation instruction, it will be scheduled to be executed by computation unit 13.

[0107] Step S311: The shared memory controller checks whether the value of the corresponding initialization flag bit is 1 according to the workgroup identifier. If the value of the initialization flag bit is 1, it means that the corresponding shared memory has completed the initialization operation, and then proceeds to step S312. If the value of the initialization flag bit is not 1, for example, 0, it means that the corresponding shared memory has not completed the initialization operation, and then proceeds to step S313.

[0108] In step S312, the shared memory controller executes the shared memory access instructions.

[0109] In step S313, the shared memory controller suspends shared memory access instructions until the initialization flag is set to 1. After the initialization flag is set to 1, the process proceeds to step S312, where the shared memory controller executes the shared memory access instructions.

[0110] Steps S309 to S313 belong to the instruction execution stage.

[0111] In this embodiment, after the thread constructor 11 in the execution unit determines that the shared memory 15 of the received workgroup needs to be initialized, it notifies the shared memory controller 16 in the execution unit to initialize the shared memory 15. The shared memory controller 16 performs the initialization operation by writing initialization values ​​to the shared memory 15. In this way, the initialization of the shared memory 15 is avoided by using software patches, which simplifies the compiler's work. The initialization of the shared memory 15 is implemented by hardware, which can improve security.

[0112] It should be noted that the method embodiments and device embodiments of this application can complement each other. Industrial applicability

[0113] The execution unit, chip, and shared memory initialization method provided in this application solve the problem of avoiding the need for software patching to initialize shared memory, simplifying the compiler's work. Implementing shared memory initialization through hardware can improve security and can be widely applied to the optimization of computer operating programs.

[0114] In this application, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance. The term "multiple" refers to two or more unless otherwise expressly defined.

[0115] The above description of the embodiments is intended to enable those skilled in the art to understand and apply this application. It will be apparent to those skilled in the art that various modifications can be easily made to these embodiments, and the general principles described herein can be applied to other embodiments without creative effort. Therefore, this application is not limited to the embodiments described herein, and any improvements and modifications made by those skilled in the art based on the disclosure of this application without departing from the scope and spirit of this application are within the scope of this application.

Claims

1. An execution unit, applied to a chip for performing general-purpose computing tasks, comprising: A thread constructor is used to notify the shared memory controller to initialize the shared memory after determining that the shared memory of the received workgroup needs to be initialized. as well as A shared memory controller is used to perform initialization operations by writing initialization values ​​to the shared memory.

2. The execution unit as claimed in claim 1, wherein, The thread constructor includes an initialization control register to indicate whether to initialize the shared memory, and the thread constructor notifies the shared memory controller whether to initialize the shared memory of the workgroup based on the value of the initialization control register.

3. The execution unit as described in claim 2, wherein, The shared memory controller stores a workgroup table, including the following entries: workgroup identifier, valid flag, base address of the workgroup in the shared memory, address range length of the workgroup in the shared memory, and initialization flag; the value of the valid flag indicates whether the corresponding workgroup is valid; the value of the initialization flag indicates whether the shared memory of the corresponding workgroup has completed the initialization operation. When the value of the initialization flag is a first value, it is used to indicate that the shared memory of the corresponding workgroup has not completed the initialization operation; when the value of the initialization flag is a second value, it is used to indicate that the shared memory of the corresponding workgroup has completed the initialization operation; the first value and the second value are different; before the initialization operation is completed, the value of the initialization flag is the first value. The shared memory controller includes an initialization unit and a write unit. The initialization unit includes an initialization value register, which is used to store the initialization value. When the shared memory controller performs an initialization operation on the shared memory of the workgroup, the initialization unit writes the initialization value to all rows within the address range of the shared memory of the workgroup through the write unit; the address range is obtained based on the base address and the address interval length; and After the initialization operation is completed, the initialization unit adjusts the value of the initialization flag to the second value.

4. The execution unit as described in claim 3, wherein, The initialization unit writes one line of the initialization value to the address range of the shared memory of the workgroup each time through the write unit, until all lines in the address range of the shared memory of the workgroup have been written with the initialization value.

5. The execution unit as claimed in claim 3, wherein, When the value of the valid flag is the third value, it is used to indicate that the corresponding workgroup is invalid; when the value of the valid flag is the fourth value, it is used to indicate that the corresponding workgroup is valid; the third value and the fourth value are different. Upon receiving the workgroup, the thread constructor notifies the shared memory controller of the workgroup identifier, the base address of the workgroup in the shared memory, the address range length of the workgroup in the shared memory, and the value of the initialization control register. After receiving the workgroup identifier of the workgroup, the base address of the workgroup in the shared memory, the address range length of the workgroup in the shared memory, and the value of the initialization control register, the shared memory controller fills the workgroup identifier into the workgroup table, sets the value of the valid flag bit corresponding to the workgroup identifier in the workgroup table to the fourth value, and then fills the base address of the workgroup in the shared memory and the address range length of the workgroup in the shared memory into the workgroup table. When the value of the initialization control register indicates that the shared memory should be initialized, the shared memory controller first sets the value of the initialization flag corresponding to the workgroup identifier to the first value, then performs the initialization operation on the shared memory, and after the initialization operation is completed, adjusts the value of the initialization flag to the second value; and When the value of the initialization control register indicates that the shared memory should not be initialized, the value of the initialization flag corresponding to the workgroup identifier is set to the second value.

6. The execution unit as claimed in claim 3, wherein, After receiving an access instruction for the shared memory of the workgroup, the shared memory controller determines whether the shared memory of the workgroup has completed the initialization operation by using the initialization flag. When it is determined that the shared memory of the workgroup has not completed the initialization operation, the access command is suspended; and The access instruction is executed only after it is determined that the shared memory of the workgroup has completed the initialization operation.

7. The execution unit as described in claim 5 further includes a thread scheduler; wherein... During the initialization of the shared memory, the thread constructor is also used to construct the thread bundles of the workgroup, which are then scheduled for execution by the thread scheduler; and After all thread bundles of the workgroup have been executed, the thread constructor notifies the shared memory controller to clear the data in the table entry corresponding to the workgroup identifier of the workgroup, and sets the value of the valid flag bit to the third value, and sets the value of the initialization flag bit to the first value.

8. A chip comprising an execution unit as described in any one of claims 1 to 7.

9. The chip as described in claim 8, wherein, The chip is a graphics processor or an artificial intelligence chip.

10. A method for initializing shared memory, applied to an execution unit as described in any one of claims 1 to 7, comprising: After determining that the shared memory of the received workgroup needs to be initialized, the thread constructor notifies the shared memory controller to initialize the shared memory. as well as The shared memory controller performs initialization operations by writing initialization values ​​to the shared memory.