Resource allocation device applied to processor, processor, equipment and method
By using parallel computation of gap computing units that do not occupy storage resources, gaps in unoccupied storage units can be quickly found, improving the efficiency of processor storage resource allocation, solving the problem of storage resource fragmentation, reducing storage resource waste, and improving storage efficiency.
Patent Information
- Application Number
- CN202411375646.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-29
- Publication Date
- 2026-03-31
AI Technical Summary
In existing technologies, the method of using a linked list to search for unoccupied storage blocks when allocating storage resources is inefficient, affects the efficiency of storage resource allocation, and easily leads to storage resource fragmentation.
A resource allocation device is designed, comprising a recording unit, an interval calculation unit, and an allocation unit. By calculating the length of unoccupied storage blocks in the storage unit in parallel, a suitable storage block is quickly found and allocated to threads, thereby reducing storage resource fragmentation.
It improves the efficiency of allocating storage resources to threads in the processor, reduces the waste of storage resources, and enhances processor performance.
Smart Images

Figure CN121764637A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of chip technology, and in particular to a resource allocation device, processor, apparatus and method for processors. Background Technology
[0002] Before a processor executes a thread, it needs to allocate memory resources for that thread to use.
[0003] In related technologies, a linked list is used to record the occupied storage blocks in a storage unit. Storage units provide the storage resources needed by threads; for example, a storage unit can be a buffer in a processor. When a new thread is added to the processor, the processor needs to sequentially search through the occupied storage blocks in the storage unit according to the index order of the entries in the linked list (e.g., the order of the addresses of the occupied storage blocks recorded in the entries within the storage unit). This process finds the unoccupied storage blocks in the storage unit (each occupied and unoccupied block has a consecutive address within the storage unit). Then, based on the length of each found unoccupied storage block, the unoccupied storage block allocated to the aforementioned thread is determined. However, this method of searching for unoccupied storage blocks is slow, impacting the efficiency of storage resource allocation.
[0004] For example, if the address of a memory cell is 0-15, and the memory cell contains two occupied memory blocks with addresses 2-3 and 6-9 respectively, then the process first needs to find the occupied memory block with the address closest to 0 (address 2-3) in the linked list, thus obtaining the first unoccupied memory block with a length of 2 (address 0-1). Then, based on the found occupied memory block, the process searches for the other occupied memory block with the closest address (address 6-9), thus obtaining the second unoccupied memory block with a length of 2 (address 4-5). When searching for the next closest occupied memory block based on the occupied memory blocks with addresses 6-9, since no such block can be found, the third unoccupied memory block has a length of 6 (address 10-15). It is evident that in this example, the search for different unoccupied memory blocks is performed serially, resulting in low efficiency. Summary of the Invention
[0005] This application provides a resource allocation device, processor, apparatus, and method for a processor. The technical solutions provided by this application are as follows:
[0006] According to one aspect of the embodiments of this application, a resource allocation device for a processor is provided, the resource allocation device comprising: a recording unit, a gap calculation unit, and an allocation unit;
[0007] The recording unit is used to store M occupancy information, and the i-th occupancy information among the M occupancy information is used to determine the i-th occupied storage block in the processor's storage unit, where M is a positive integer and i is a positive integer less than or equal to M;
[0008] The gap calculation unit is used to calculate the lengths of the M+1 unoccupied storage blocks in the storage unit in parallel based on the M occupancy information.
[0009] The allocation unit is used to determine the storage blocks allocated to the first thread based on the requested space length of the first thread and the length of the M+1 unoccupied storage blocks, wherein the requested space length refers to the length of the storage blocks requested by the first thread.
[0010] According to one aspect of the embodiments of this application, a processor is provided, the processor including the resource allocation device described above.
[0011] According to one aspect of the embodiments of this application, a computer device is provided, the computer device including a processor, the processor including the resource allocation device described above.
[0012] According to one aspect of the embodiments of this application, a chip product is provided, the chip product including the above-described resource allocation device.
[0013] According to one aspect of the embodiments of this application, an artificial intelligence processor is provided, the artificial intelligence processor including the above-described resource allocation device.
[0014] According to one aspect of the embodiments of this application, a graphics processor is provided, the graphics processor including the resource allocation device described above.
[0015] According to one aspect of the embodiments of this application, a graphics card is provided, the graphics card including a processor, the processor including the resource allocation device described above.
[0016] According to one aspect of the embodiments of this application, an artificial intelligence computing cluster is provided, the artificial intelligence computing cluster including a graphics card or a computer device, the graphics card or the computer device including a processor, the processor including the above-described resource allocation device.
[0017] According to one aspect of the embodiments of this application, a resource allocation method based on a resource allocation device is provided. The resource allocation device includes: a recording unit, a gap calculation unit, and an allocation unit. The recording unit is used to store M occupancy information, wherein the i-th occupancy information among the M occupancy information is used to determine the i-th occupied storage block in the storage unit of the processor, where M is a positive integer and i is a positive integer less than or equal to M.
[0018] The method includes:
[0019] The gap calculation unit calculates the lengths of the M+1 unoccupied storage blocks in the storage unit in parallel based on the M occupancy information.
[0020] The allocation unit determines the storage blocks allocated to the first thread based on the requested space length of the first thread and the length of the M+1 unoccupied storage blocks, wherein the requested space length refers to the length of the storage blocks requested by the first thread.
[0021] The technical solutions provided in this application have at least the following beneficial effects:
[0022] By designing an interval calculation unit in the resource allocation device to calculate the length of M+1 unoccupied storage blocks in parallel based on the M occupied storage blocks recorded in the recording unit, the resource allocation device can quickly find the length of each unoccupied storage block in the storage unit, thereby improving the efficiency of allocating storage resources to threads in the processor. Attached Figure Description
[0023] Figure 1 This is a schematic diagram of a linked list for recording occupied storage blocks provided in one embodiment of this application;
[0024] Figure 2 This is a schematic diagram of the hardware structure of a processor provided in one embodiment of this application;
[0025] Figure 3 This is a schematic diagram of a resource allocation device provided in one embodiment of this application;
[0026] Figure 4 This is a schematic diagram illustrating the occupancy of a storage unit and the corresponding resource allocation process according to an embodiment of this application;
[0027] Figure 5 This is a schematic diagram of a resource allocation device provided in another embodiment of this application;
[0028] Figure 6 This is a schematic diagram of a comparison unit provided in one embodiment of this application;
[0029] Figure 7 This is a schematic diagram illustrating the writing of new occupancy information into a recording unit according to an embodiment of this application;
[0030] Figure 8 This is a schematic diagram illustrating the deletion of occupancy information from a recording unit according to an embodiment of this application;
[0031] Figure 9 This is a flowchart of a resource allocation method based on a resource allocation device provided in one embodiment of this application. Detailed Implementation
[0032] To make the objectives, technical solutions, and advantages of this application clearer, the embodiments of this application will be described in further detail below with reference to the accompanying drawings.
[0033] Before introducing the technical solutions of this application, some terms involved in this application will be explained. The following related explanations are optional solutions and can be arbitrarily combined with the technical solutions of the embodiments of this application, all of which fall within the protection scope of the embodiments of this application. The embodiments of this application include at least some of the following contents.
[0034] Threads: A process is an instance of a running program, and a thread is an execution flow within a process. Threads are the basic unit of processor processing and scheduling. A process can have multiple threads running concurrently, each executing different tasks in parallel. During program execution, threads need to utilize the processor's storage resources to perform their tasks; therefore, storage resources must be allocated for a thread before it can be executed.
[0035] Storage unit: A storage unit is used to provide the storage resources required by threads. A storage unit can be composed of any memory bank within the processor, and this application is not limited to this. For example, a storage unit may include one or more buffers. As another example, a storage unit may include one or more registers.
[0036] Storage block: A storage resource with contiguous addresses in a storage unit. Since the storage resources used by threads need to ensure contiguous addresses, storage blocks in a storage unit need to be allocated to threads for use.
[0037] Occupied storage block: The storage block in the storage unit that is being used by the currently executing thread.
[0038] Unoccupied storage blocks: Storage blocks in a storage unit other than the occupied storage blocks. For example, if the address of a storage unit is 0-9, and the addresses of the occupied storage blocks in the storage unit are 2-5, then the storage unit includes two unoccupied storage blocks with addresses 0-1 and 6-9 respectively.
[0039] Length of a storage block: The length of a storage block reflects the size of the storage resources provided by the block. In some embodiments, the length of a storage block is the number of addresses occupied by the block within a storage unit. For example, if the addresses of a storage block are 6 to 9, then the length of the block is 4.
[0040] Linked list: A linked list is a non-contiguous and non-sequential storage structure. The index order of the data stored in a linked list is determined by the index order of the entries in the list (these entries are linked together by pointers).
[0041] Time complexity: Used to measure the relationship between the efficiency of a system in executing a task and the size of the data in the system. For example, time complexity O(1) means that the time for the system to execute a task does not increase with the size of the data; time complexity O(logn) means that the time for the system to execute a task is proportional to logn; and time complexity O(n) means that the time for the system to execute a task is proportional to n, where n represents the size of the data. <O(logn)<O(n)。
[0042] In related technologies, linked lists are used to record occupied storage blocks. Please refer to [reference needed]. Figure 1 The diagram illustrates a linked list for recording occupied storage blocks provided in one embodiment of this application.
[0043] One entry 110 in linked list 100 is used to record an occupied storage block ( Figure 1 (Only one entry 110 is shown for illustrative purposes), entry 110 includes a preceding field 111, a starting field 112, a length field 113, and a following field 114.
[0044] The start field 112 is used to store the starting address of the occupied storage block in the storage unit, and the length field 113 is used to store the length of the occupied storage block.
[0045] The preceding field 111 is used to store the number of the preceding table entry. The address of the occupied storage block recorded in the preceding table entry is located before the occupied storage block recorded in table entry 110.
[0046] The subsequent field segment 114 is used to store the number of the subsequent table entry. The address of the occupied storage block recorded in the subsequent table entry is located after the unoccupied storage block recorded in table entry 110.
[0047] It should be noted that, Figure 1 The arrows connecting the entries in the linked list do not indicate physical connections, but rather the index order determined by the preceding and following entries. In other words, when searching for the size of an unoccupied block in the linked list, it's necessary to search for occupied blocks sequentially from the head of the list, following the guidance of the preceding or following entries. Each time a new occupied block is found, the length of an unoccupied block can be calculated. Similarly, inserting or deleting entries into the linked list requires traversing the list from the head because the preceding and following fields of each entry need to be updated. Therefore, when using a linked list to search for unoccupied blocks to allocate storage resources for threads (as well as for inserting and deleting entries), the time consumed is linearly positively correlated with the size n of the data recorded in the linked list (which can be the number M of occupied blocks recorded in the linked list). The time complexity of using a linked list to allocate storage resources is O(n), which is inefficient.
[0048] Meanwhile, in related technologies, the largest (longest) unoccupied storage block among the various unoccupied storage blocks of the storage unit is directly allocated to the current thread. However, this resource allocation method will cause fragmentation of storage resources and affect processor performance.
[0049] For example, if there are three unoccupied storage blocks in a storage unit with lengths of 2, 4, and 10 respectively, when a newly created thread needs to use a storage block of length 4, the header of an unoccupied storage block of size 10 will be allocated to the newly created thread. In this case, the lengths of the three unoccupied storage blocks in the storage unit will change to 2, 4, and 6. At this time, if a newly created thread needs to use a storage block of length 8, it will need to wait for the already occupied storage block to be released before it can execute.
[0050] To address the aforementioned issues, this application provides a resource allocation device that can improve the allocation efficiency of storage resources and reduce the fragmentation of storage resources.
[0051] Please refer to Figure 2 The diagram illustrates a schematic of the hardware structure of a processor according to an embodiment of this application. The processor includes an instruction decoder 1, a processing unit 2, a resource allocation device 3, and a storage unit 4.
[0052] Instruction decoder 1 is used to decode the instructions received by the processor and provide the decoded instructions to processing unit 2.
[0053] The processing unit 2 is used to execute the actual operation of the instructions. In some embodiments, when the received instruction is an instruction from the first thread that has just occurred in the processor (i.e., the corresponding storage resource has not yet been allocated), the processing unit 2 is used to send a request for space length to the resource allocation device 3, thereby informing the resource allocation device 3 of the length of the storage block requested by the first thread.
[0054] The resource allocation device 3 is used to calculate the length of each unoccupied storage block in the storage unit in parallel, and to determine the storage block to be allocated to the first thread based on the length of each unoccupied storage block and the requested space length. In some embodiments, the resource allocation device 3 is further used to send new occupancy information to the processing unit, the new occupancy information being used to determine the storage block to be allocated to the first thread.
[0055] The processing unit 2 is further configured to, upon receiving the new occupancy information sent by the resource allocation device 3, execute the instructions of the first thread based on the storage block allocated to the first thread in the storage unit 4. In some embodiments, the processing unit 2 is further configured to, after the execution of the first thread's (each instruction) is completed, send a release message to the resource allocation device 3 to indicate the cancellation of the occupancy of the storage block allocated to the first thread.
[0056] The processor may include one or more processing cores, such as a quad-core processor or an octa-core processor. The processor may be implemented using at least one hardware form of DSP (Digital Signal Processing), FPGA (Field Programmable Gate Array), or PLA (Programmable Logic Array). The processor may also include a main processor and coprocessors. The main processor, also known as a CPU (Central Processing Unit), is used to process data in the wake-up state; the coprocessor is a low-power processor used to process data in the standby state. In some embodiments, the processor may be a GPU (Graphics Processing Unit), which is responsible for rendering and drawing the content required to be displayed on the screen. In some embodiments, the processor may also include an AI (Artificial Intelligence) processor, which is used to handle computational operations related to machine learning.
[0057] Those skilled in the art will understand that Figure 2 The structure shown does not constitute a limitation on the processor. The processor may include more or fewer components than shown, or combine certain components, or use different component arrangements.
[0058] Based on the above hardware architecture design, the efficiency of allocating storage resources for newly generated threads in the processor can be improved.
[0059] Please refer to Figure 3 The diagram illustrates a resource allocation device according to an embodiment of this application. The resource allocation device 3 can be a purely hardware structure, which can be mounted on a processor chip. The resource allocation device 3 includes: a recording unit 10, a gap calculation unit 20, and an allocation unit 30.
[0060] In some embodiments, the recording unit 10 is connected to the gap calculation unit 20, and the gap calculation unit 20 is connected to the allocation unit 30.
[0061] Recording unit 10 is used to store M occupancy information. The i-th occupancy information among the M occupancy information is used to determine the i-th occupied storage block in the processor's storage unit. That is, one occupancy information is used to determine one occupied storage block. M is a positive integer, and i is a positive integer less than or equal to M.
[0062] In some embodiments, the occupancy information includes: the starting address of the occupied storage block in the storage unit and the length of the occupied storage block. In some embodiments, the starting address of the storage block is the first address occupied by the storage block in the storage unit. For example, for an occupied storage block that occupies addresses 2 to 3 in the storage unit, the occupancy information includes: starting address 2 and length 2.
[0063] In some embodiments, the occupancy information includes: the tail address of the occupied storage block in the storage unit and the length of the occupied storage block. It should be noted that, to ensure the difference between the tail address and the head address of the storage block directly reflects the length of the storage block, the address following the last address occupied by the storage block in the storage unit is typically used as the tail address of the storage block. For example, for an occupied storage block occupying addresses 2 to 3 in the storage unit, the occupancy information includes: tail address 4 and length 2.
[0064] In some embodiments, the occupancy information includes the starting address and ending address of the occupied storage block within the storage unit. For example, for an occupied storage block occupying addresses 2 to 3 in the storage unit, the occupancy information includes the starting address 2 and the ending address 4.
[0065] The starting and ending addresses of a storage unit are similar to those of a storage block. For example, if the addresses of all storage resources in a storage unit are 0 to 21, then the starting address of the storage unit is 0 and the ending address is 22.
[0066] It should be noted that this application only uses the above-described method of setting the first and last addresses as an example, and this application does not limit it. For example, those skilled in the art may also use the address preceding the first address occupied by the storage block (storage unit) as the first address of the storage block (storage unit), and the last address occupied by the storage block (storage unit) as the last address of the storage block (storage unit).
[0067] The gap calculation unit 20 is used to calculate the length of M+1 unoccupied storage blocks in the storage unit in parallel based on M occupancy information.
[0068] In some embodiments, the gap calculation unit is used to calculate the lengths of M+1 unoccupied storage blocks in the storage unit in parallel using J gap calculation subunits, where J is a positive integer less than or equal to M+1. A gap calculation subunit is used to determine the length of one unoccupied storage block in the storage unit based on at most two occupancy information pieces.
[0069] In some embodiments, the gap calculation subunit is used to calculate the length of an unoccupied storage block based on the starting address of the storage unit and occupancy information. For example, the gap calculation subunit is used to subtract the starting address of the storage unit from the starting address of the occupied storage block obtained based on the occupancy information to obtain the length of an unoccupied storage block.
[0070] In some embodiments, the gap calculation subunit is used to calculate the length of an unoccupied memory block based on two different occupancy information. For example, the gap calculation subunit is used to subtract the tail address of an occupied memory block obtained based on the other occupancy information from the starting address of the occupied memory block obtained based on one occupancy information to obtain the length of an unoccupied memory block.
[0071] In some embodiments, the gap calculation subunit is used to calculate the length of an unoccupied storage block based on occupancy information and the tail address of a storage unit. For example, the gap calculation subunit is used to subtract the tail address of an occupied storage block obtained based on the occupancy information from the tail address of the storage unit to obtain the length of an unoccupied storage block.
[0072] Those skilled in the art will understand that when J equals M+1, the lengths of M+1 unoccupied storage blocks can be obtained in just one round of parallel computation using M+1 gap computation subunits. When J is less than M+1, some or all of the gap computation subunits can perform multiple rounds of parallel computation to obtain the lengths of M+1 unoccupied storage blocks. For example, if M+1 = 8 and J = 4, the lengths of four unoccupied storage blocks can be obtained by performing one round of parallel computation using these four gap computation subunits, and then the lengths of the remaining four unoccupied storage blocks can be obtained by performing the next round of parallel computation.
[0073] The allocation unit 30 is used to determine the storage blocks to be allocated to the first thread based on the requested space length of the first thread and the length of M+1 unoccupied storage blocks. The requested space length refers to the length of the storage blocks requested by the first thread.
[0074] The first thread is a thread in the processor that has issued the corresponding instruction (to the aforementioned processing unit 2), but has not yet started execution because the corresponding storage resources have not yet been allocated.
[0075] In some embodiments, the allocation unit 30 is configured to determine, from the M+1 unoccupied storage blocks, a storage block to be allocated to the first thread based on the requested space length of the first thread and the length of the M+1 unoccupied storage blocks.
[0076] In some embodiments, the storage block allocated to the first thread is the smallest available unoccupied storage block among the storage units (M+1 unoccupied storage blocks). A available unoccupied storage block is an unoccupied storage block whose length is greater than or equal to the length of the storage block requested by the first thread.
[0077] In some embodiments, the allocation unit 30 is configured to determine the smallest available unoccupied storage block in the storage unit as the storage block to be allocated to the first thread, based on the requested space length of the first thread and the lengths of M+1 unoccupied storage blocks.
[0078] In the above embodiment, the resource allocation device 3 allocates the smallest unoccupied storage block that meets the needs of the first thread to the first thread for use, making full use of the unoccupied storage blocks in the storage unit and reducing the fragmentation of storage resources in the storage unit.
[0079] For example, please refer to Figure 4 .exist Figure 4 In the illustrated memory cell occupancy diagram, the starting address of the memory cell is 0, and the ending address is 22, meaning the total length of the memory cell is 22. The memory cell includes three occupied memory blocks: the first occupied block occupies addresses 2-3, the second occupied block occupies addresses 8-9, and the third occupied block occupies addresses 16-19. Correspondingly, the memory cell includes four unoccupied memory blocks: the first unoccupied block has a length of 2 (addresses 0-1), the second unoccupied block has a length of 4 (addresses 4-7), the third unoccupied block has a length of 6 (addresses 10-15), and the fourth unoccupied block has a length of 2 (addresses 20-21). If the first thread requests a space length of 4, then the second and third unoccupied memory blocks are considered ample unoccupied memory blocks. Since the length of the second unoccupied storage block is shorter than the length of the third unoccupied storage block, the allocation unit 30 determines the second unoccupied storage block as the storage block to be allocated to the first thread. In this case, when a subsequent thread needs to use a storage block of length 6, the resource allocation device can directly allocate the third unoccupied storage block to the subsequent thread without waiting for the already occupied storage block to be released. Therefore, the processor's performance is improved.
[0080] In some embodiments, the allocation unit 30 is further configured to output new occupancy information (to the processing unit 2 described above), the new occupancy information being used to determine the storage block allocated to the first thread. For example, the new occupancy information includes the starting address (and length) of the storage block allocated to the first thread within the storage unit.
[0081] The technical solution provided in this application embodiment, by designing a gap calculation unit in the resource allocation device to calculate the length of M+1 unoccupied storage blocks in parallel based on the M occupied storage blocks recorded in the recording unit, enables the resource allocation device to quickly find the length of each unoccupied storage block in the storage unit, thereby improving the efficiency of allocating storage resources to threads in the processor.
[0082] Please refer to Figure 5 The diagram illustrates a resource allocation device according to another embodiment of this application. This resource allocation device 3 can be a purely hardware structure, which can be mounted on a processor chip. The resource allocation device 3 includes: a recording unit 10, a gap calculation unit 20, and an allocation unit 30.
[0083] The recording unit 10 includes Q entries 11. The i-th entry among the Q entries 11 is used to store the i-th occupancy information among the M occupancy information. Q is an integer greater than 1, and M is a positive integer less than or equal to Q.
[0084] In other words, the M occupancy information entries are stored in the first to the Mth entries of the Q entries.
[0085] In some embodiments, each of the Q entries 11 includes: a status field, a start field, and a length field. Occupancy information includes: the starting address of the occupied storage block in the storage unit and the length of the occupied storage block.
[0086] The state field in entry 11 indicates the state of entry 11, which can be one of a first state, a second state, or a third state. Entry 11 in the first state is occupied by occupancy information. Entry 11 in the second state is not occupied by occupancy information, and the preceding entry to entry 11 in the second state is an entry in the first state. Entries in the third state are not occupied by occupancy information and are located after entries in the second state. For example, if the state field indicates true, entry 11 is in the first state; if the state field indicates end, entry 11 is in the second state; and if the state field indicates false, entry 11 is in the third state.
[0087] In some embodiments, if none of the Q entries store occupancy information, then the first entry among the Q entries is in the second state, and the remaining entries among the Q entries are in the third state.
[0088] When entry 11 is in the first state, the start field in entry 11 is used to store the starting address of the occupied storage block in the storage unit, and the length field in entry 11 is used to store the length of the occupied storage block.
[0089] When entry 11 is in the second state, at least one of the start field and length field in entry 11 is used to store end information, which is used to indicate the tail address of the storage unit.
[0090] For example, please refer to Figure 4 This diagram illustrates the occupancy status of a storage unit and the corresponding resource allocation process according to an embodiment of this application. Recording unit 10 includes four entries. The first three entries have a valid field of `true`, indicating that the first three entries are occupied. The first entry has a starting field of 2 and a length field of 2, thus indicating that the address of the first occupied storage block is 2-3. The second entry has a starting field of 8 and a length field of 2, thus indicating that the address of the second occupied storage block is 8-9. The third entry has a starting field of 16 and a length field of 4, thus indicating that the address of the third occupied storage block is 16-19. The fourth entry has a valid field of `end`, indicating that the fourth entry is located at the end of the entries in the first state (the first three entries). The fourth entry has a starting field of 22, thus indicating that the end address of the storage unit is 22. Since recording unit 10 only includes four entries, and the fourth entry is in the second state, recording unit 10 does not include entries in the third state.
[0091] In the above embodiment, entry 11 records the occupied storage block in the form of starting address + length, without needing to store the ending address of the occupied storage block. Since addresses in a processor are generally multi-bit, requiring more storage resources for recording, the above scheme can save storage resources of the recording unit 10. In addition, in the above scheme, entry 11 indicates the status of the entry through a valid field. Since the valid field only needs to indicate three states, the actual value indicated by the valid field can be set relatively simply (e.g., using a value of 0 to indicate the first state, a value of 1 to indicate the second state, and a value of 2 to indicate the third state). The gap calculation unit 20 can know whether entry 11 stores occupied information or the ending address of the storage unit without reading the more complex starting field and length field. This allows the gap calculation unit 20 to read the starting field and length field of entry 11 only when occupied information or the ending address of the storage unit is stored in entry 11, thereby optimizing the working efficiency of the gap calculation unit 20.
[0092] The gap calculation unit 20 includes Q+1 gap calculation sub-units 21. M+1 of the Q+1 gap calculation sub-units 21 are used to calculate the length of M+1 unoccupied storage blocks in the storage unit in parallel based on M occupancy information.
[0093] Each of the Q+1 gap calculation subunits 21 is used to determine the length of an unoccupied storage block in the storage unit based on the occupancy information stored in at most two of the Q entries 11.
[0094] In some embodiments, in addition to the Q entries described above, the recording unit 10 also includes a header 12 and a tail 13. The header 12 stores start information, which indicates the starting address of the storage unit. For example, the start information is simply the starting address of the storage unit; alternatively, the start information includes an address and an offset, and the starting address of the storage unit is obtained by adding or subtracting the address and offset. The tail 13 stores end information, which indicates the ending address of the storage unit. For example, the ending information is simply the ending address of the storage unit; alternatively, the ending information includes an address and an offset, and the ending address of the storage unit is obtained by adding or subtracting the address and offset. In some embodiments, the header 12 and the tail 13 are two different register groups. Each register group includes at least one register.
[0095] In some embodiments, entry 11 is a register group. Q entries 11 constitute Q register groups.
[0096] In some embodiments, the header, the first entry, the second entry, ..., the Qth entry, and the footer are arranged sequentially in a first direction. The first direction is arbitrary and is not limited thereto in this application.
[0097] In some embodiments, the first gap calculation subunit, the second gap calculation subunit, ..., the Q+1 gap calculation subunits are arranged sequentially in a first direction.
[0098] In some embodiments, the first gap calculation subunit of the Q+1 gap calculation subunits is connected to the table header 12 and the first entry, the f-th gap calculation subunit is connected to the (f-1)-th entry and the f-th entry, and the Q+1-th gap calculation subunit is connected to the Q-th entry and the table tail 13. f is an integer greater than 1 and less than Q+1.
[0099] In some embodiments, when M is greater than 1 and i is a positive integer less than M, the (i+1)th entry of the Q entries is used to store the (i+1)th occupancy information among the M occupancy information entries. The (i+1)th occupancy information is used to determine the (i+1)th occupied storage block in the storage unit. The address of the ith occupied storage block in the storage unit is located before the address of the (i+1)th occupied storage block in the storage unit. It should be noted that i can take any value when it is less than M. That is, the addresses of the occupied storage blocks corresponding to the 1st to Mth entries of the Q entries are arranged sequentially in the storage unit.
[0100] In some embodiments, the address of the i-th occupied storage block in the storage unit is located before the address of the (i+1)-th occupied storage block in the storage unit, and there are no other occupied storage block addresses between the address of the i-th occupied storage block in the storage unit and the address of the (i+1)-th occupied storage block in the storage unit.
[0101] For example, please refer to Figure 4 In the four entries included in the recording unit 10, the first three entries store occupancy information. The first entry stores the starting address of the occupied storage block in the storage unit as 2, the second entry stores the starting address of the occupied storage block in the storage unit as 8, and the third entry stores the starting address of the occupied storage block in the storage unit as 16, arranged in order.
[0102] In the above embodiment, the addresses of the occupied storage blocks corresponding to the first to the Mth entries of the Q entries 11 are arranged sequentially in the storage unit. Therefore, based on the occupancy information stored in each pair of adjacent entries 11 of the Q entries 11, the length of an unoccupied storage block can be determined. That is, when the Q entries 11 are arranged sequentially in the first direction, connecting each pair of adjacent entries 11 to the same gap calculation subunit 21 can realize the calculation of the length of an unoccupied storage block. Using the above scheme, as... Figure 5 As shown, the connecting lines used to connect item 11 and gap calculation subunit 21 will not cross, making the wiring relatively simple.
[0103] In some embodiments, the first gap calculation subunit in the Q+1 gap calculation subunits 21 is used to determine the length of the first unoccupied storage block in the M+1 unoccupied storage blocks based on the starting address of the storage unit and the occupancy information stored in the first entry of the Q entries 11.
[0104] In some embodiments, the first gap calculation subunit among the Q+1 gap calculation subunits 21 is used to read the starting address of the first occupied storage block from the starting field of the first entry among the Q entries 11 (when M is a positive integer, the first entry must be in the first state), and to read the starting address of the storage unit from the table header 12. Based on the starting address of the first occupied storage block and the starting address of the storage unit, (the difference between the two) the length of the first unoccupied storage block among the M+1 unoccupied storage blocks is obtained.
[0105] When M is greater than 1 and i is a positive integer less than M, the (i+1)th gap calculation subunit in the Q+1 gap calculation subunits 21 is used to determine the length of the (i+1)th unoccupied storage block in the M+1 unoccupied storage blocks based on the occupancy information stored in the i-th entry of the Q entries and the occupancy information stored in the (i+1)th entry of the Q entries.
[0106] In some embodiments, when M is greater than 1 and i is a positive integer less than M, the (i+1)th gap calculation subunit in the Q+1 gap calculation subunits 21 is used to read the starting address and length of the i-th occupied storage block from the starting field and length field of the i-th entry in the Q entries 11 (when M is greater than 1 and i is a positive integer less than M, the i-th entry and the (i+1)th entry must be in the first state), and add the starting address and length of the i-th occupied storage block to obtain the tail address of the i-th occupied storage block. The starting address of the (i+1)th occupied storage block is read from the starting field of the (i+1)th entry in the Q entries 11. The length of the (i+1)th unoccupied storage block in the M+1 unoccupied storage blocks is obtained based on the difference between the starting address and the tail address of the (i+1)th occupied storage block.
[0107] The (M+1)th gap calculation subunit in the Q+1 gap calculation subunits 21 is used to determine the length of the (M+1)th unoccupied storage block among the M+1 unoccupied storage blocks based on the occupancy information stored in the Mth entry among the Q entries and the tail address of the storage unit.
[0108] In some embodiments, when M = Q, the (M+1)th gap calculation subunit in the Q+1 gap calculation subunits 21 reads the starting address and length of the Mth occupied storage block from the starting field and length field of the Mth entry in the Q entries 11 (when M = Q, the Mth entry must be in the first state), adds the starting address and length of the Mth occupied storage block to obtain the tail address of the Mth occupied storage block, and reads the tail address of the storage unit from the tail of the table 13. Based on the tail address of the storage unit and the tail address of the Mth occupied storage block (and the difference between the two), the length of the (M+1)th unoccupied storage block in the M+1 unoccupied storage blocks is obtained.
[0109] In some embodiments, when M is a positive integer less than Q, the (M+1)th gap calculation subunit in the Q+1 gap calculation subunits 21 is used to read the starting address and length of the Mth occupied storage block from the starting field and length field of the Mth entry (the Mth entry is always in the first state) in the Q entries 11, and add the starting address and length of the Mth occupied storage block to obtain the tail address of the Mth occupied storage block. The tail address of the storage unit is read from the starting field of the (M+1)th entry (when M is a positive integer less than Q, the (M+1)th entry always exists and is in the second state). Based on the tail address of the storage unit and the tail address of the Mth occupied storage block, the length of the (M+1)th unoccupied storage block is obtained (by calculating the difference between the two).
[0110] For example, please refer to Figure 4 In this example, since the recording unit 10 includes 4 entries, the gap calculation unit includes 5 gap calculation sub-units. As can be seen, the first gap calculation subunit subtracts the starting address 0 of the storage unit from the address 2 stored in the starting field segment of the first entry to obtain the length value 2 of the first unoccupied storage block; the second gap calculation subunit subtracts the sum of the address 2 stored in the starting field segment of the first entry and the length 2 stored in the length field segment from the address 8 stored in the starting field segment of the second entry to obtain the length value 4 of the second unoccupied storage block; the third gap calculation subunit subtracts the sum of the address 8 stored in the starting field segment of the second entry and the length 2 stored in the length field segment from the address 16 stored in the starting field segment of the third entry to obtain the length value 6 of the third unoccupied storage block; the fourth gap calculation subunit subtracts the sum of the address 16 stored in the starting field segment of the fourth entry and the length 4 stored in the length field segment from the address 22 stored in the starting field segment of the fourth entry to obtain the length value 2 of the fourth unoccupied storage block. By using the above four gap calculation sub-units, the lengths of all four unoccupied storage blocks in the storage unit can be calculated.
[0111] Specifically, for the case where the record unit 10 does not store any occupancy information, i.e., M=0, the first entry in the Q entries 11 must be in the second state. The first gap calculation subunit in the Q+1 gap calculation subunits 21 is used to obtain the length of the unique unoccupied storage block (i.e., the length of the storage unit) based on the starting address of the storage unit stored in the header 12 and the tail address of the storage unit stored in the first entry (starting field segment).
[0112] In the above embodiment, each gap calculation subunit 21 obtains occupancy information from the corresponding entry 11 to perform the calculation of the length of the unoccupied storage block. The process of each gap calculation subunit 21 calculating the length of the unoccupied storage block is performed independently and without interference. Therefore, the lengths of M+1 unoccupied storage blocks can be calculated in parallel by M+1 gap calculation subunits, which improves the efficiency of finding the length of the unoccupied storage block.
[0113] In some embodiments, the allocation unit 30 includes a difference unit 31 and a comparison unit 35.
[0114] In some embodiments, the difference unit 31 and the comparison unit 35 are connected.
[0115] The difference calculation unit 31 includes Q+1 difference calculation subunits 32. The x-th difference calculation subunit among the Q+1 difference calculation subunits 32 is used to calculate the difference between the length of the x-th unoccupied storage block and the requested space length among the M+1 unoccupied storage blocks, where x is a positive integer less than or equal to M+1. That is, the first to the M+1th difference calculation subunits (a total of M+1 difference calculation subunits) among the Q+1 difference calculation subunits 32 are used to calculate in parallel the difference between the length of each of the M+1 unoccupied storage blocks and the requested space length (a total of M+1 differences).
[0116] In some embodiments, the xth gap calculation subunit among the Q+1 gap calculation subunits 21 is used to provide the length of the xth unoccupied storage block. In some embodiments, the xth gap calculation subunit is also used to determine the location information of the xth unoccupied storage block (based on the occupancy information stored in the recording unit 10), and the location information of the xth unoccupied storage block is used to determine the unoccupied storage block. For example, the location information of the xth unoccupied storage block includes the starting address (and length) of the xth unoccupied storage block in the storage unit.
[0117] In some embodiments, the difference calculation unit 31 is further configured to transmit the location information of the unoccupied storage block provided by the gap calculation unit 20 to the comparison unit 35. In some embodiments, the xth difference calculation subunit is further configured to transmit the location information of the xth unoccupied storage block to the comparison unit 35.
[0118] In some embodiments, Q+1 subunits 32 are connected to the comparison unit 35 respectively.
[0119] In some embodiments, the first difference subunit, the second difference subunit, ..., the Q+1th difference subunit in the difference subunits 32 are arranged sequentially in the first direction.
[0120] In some embodiments, the y-th subunit of the Q+1 subunits 32 is connected to the y-th gap calculation subunit of the Q+1 subunits, where y is a positive integer less than or equal to Q+1.
[0121] For example, please refer to Figure 4 In this example, the length of the first unoccupied storage block is 2, the length of the second unoccupied storage block is 4, the length of the third unoccupied storage block is 6, and the length of the fourth unoccupied storage block is 2. The difference unit 31 in this example includes 5 difference subunits, with a requested space length of 4. It can be seen that the first difference subunit subtracts 4 from 2, obtaining a difference of -2 between the length of the first unoccupied storage block and the requested space length. The second difference subunit subtracts 4 from 4, obtaining a difference of 0 between the length of the second unoccupied storage block and the requested space length. The third difference subunit subtracts 4 from 6, obtaining a difference of 2 between the length of the third unoccupied storage block and the requested space length. The fourth difference subunit subtracts 4 from 2, obtaining a difference of -2 between the length of the fourth unoccupied storage block and the requested space length.
[0122] In some embodiments, unoccupied storage blocks whose length and requested space length differ by a non-negative number are considered ample unoccupied storage blocks. For example, the second and third unoccupied storage blocks in the example above are ample unoccupied storage blocks.
[0123] The comparison unit 35 is used to determine the free unoccupied storage block with the smallest difference between its length and the requested space length among the P free unoccupied storage blocks out of M+1 free storage blocks as the storage block to be allocated to the first thread, where P is a positive integer less than or equal to M+1.
[0124] For example, please refer to Figure 4 In this example, the second and third unoccupied storage blocks are ample unoccupied storage blocks. Since the difference between the length of the second unoccupied storage block and the requested space length is 0, and the difference between the length of the third unoccupied storage block and the requested space length is 2, and 0 is less than 2, the comparison unit 35 determines the second unoccupied storage block as the storage block allocated to the first thread.
[0125] In the following embodiments, for ease of description, the difference between the length of the unoccupied storage block and the requested space length will be simply referred to as the difference. In some embodiments, please refer to Figure 6 The comparison unit 35 includes Q comparators 36 (in this example, Q = 4), which are used to compare the smaller of two differences input to the comparator 36. The difference input to a comparator can be provided by the difference subunit 32 or by other comparators among the Q comparators 36.
[0126] In some embodiments, the comparison unit 35 is used to compare the differences corresponding to P sufficient unoccupied storage blocks, and determine the sufficient unoccupied storage block with the smallest corresponding difference as the storage block to be allocated to the first thread.
[0127] In some embodiments, the comparison unit 35 is further configured to output the location information of the unoccupied storage block determined for use by the first thread as the newly occupied information in the above embodiments.
[0128] For example, please refer to Figure 6 The difference corresponding to the first unoccupied storage block is -2, the difference corresponding to the second unoccupied storage block is 0, the difference corresponding to the third unoccupied storage block is 2, and the difference corresponding to the fourth unoccupied storage block is -2. Since the difference between the first and fourth unoccupied storage blocks is negative, the first and fourth unoccupied storage blocks are not considered as sufficient unoccupied storage blocks and are therefore not included in the comparison. Comparator a directly inputs the difference 0 corresponding to the second unoccupied storage block into comparator c, and comparator b directly inputs the difference 2 corresponding to the third unoccupied storage block into comparator c. Comparator c compares the difference 0 and the difference 2 and inputs the smaller difference 0 into comparator d. Since comparator d has no other input, comparator d directly uses the position information of the second unoccupied storage block corresponding to the difference 0 as the newly occupied information output by allocation unit 30.
[0129] In the above embodiment, the difference unit 31 in the allocation unit 30 includes Q+1 difference subunits 32, which is the same number as the gap calculation subunit 21. Therefore, M+1 difference subunits 32 can also be used to calculate M+1 differences in parallel. The difference process does not increase the time complexity of the resource allocation process, thus ensuring the efficiency of allocating storage resources for the first thread.
[0130] Furthermore, in the above embodiment, the comparator 36 in the comparison unit 35 compares the storage blocks allocated to the first thread using a pairwise comparison method. When there are P sufficient unoccupied storage blocks (i.e., P differences that need to be compared), the delay of the comparison unit 35 in performing the comparison is logP. Since the gap calculation unit 20 and the difference calculation unit 31 in the resource allocation device 3, excluding the comparison unit 35, both employ parallel computation, their computation time is almost unaffected by the data size. Therefore, the time complexity of the resource allocation device 3 can be considered to be affected only by the comparison unit 35 and can be approximately expressed as O(logn), where n is the size of the data involved in the comparison, which can be approximated as the number M of occupancy information stored in the recording unit 10. In summary, when the data size is represented by M, the time complexity of the resource allocation device 3 provided in this application embodiment for performing storage resource allocation is O(logM), which is lower than the time complexity O(M) of the linked list for performing storage resource allocation. Therefore, the resource allocation device 3 provided in this application embodiment has better performance.
[0131] In some embodiments, the resource allocation device 3 further includes a recording control unit 40.
[0132] In some embodiments, the allocation unit 30 (including the comparison unit 35) is connected to the recording control unit 40, and the recording control unit 40 is connected to the recording unit 10. In some embodiments, the recording control unit 40 is connected to Q entries 11 respectively.
[0133] The allocation unit 30 is also used to provide new occupancy information to the recording control unit 40.
[0134] The recording control unit 40 is used to move the occupancy information stored in the j-th entry of the Q entries 11 to the (j+1)-th entry, and write the newly added occupancy information to the k-th entry of the Q entries 11.
[0135] Where j is an integer greater than or equal to k and less than or equal to M. After sorting the occupied storage blocks and the storage blocks allocated to the first thread corresponding to the M occupancy information according to their addresses in the storage unit, the storage block allocated to the first thread is located at the kth position.
[0136] In some embodiments, when k equals M+1, the recording control unit 40 is used to write the newly added occupancy information into the M+1th entry of the Q entries 11.
[0137] It should be noted that j can take any value within the range of greater than or equal to k and less than or equal to M. That is to say, for the Q entries 11, the k-th entry and every entry after the k-th entry that stores occupancy information must have the occupancy information moved to the next entry.
[0138] By using the technical solution provided in the above embodiments, after the newly added occupancy information is written into the recording unit 10, it can be ensured that the occupancy information stored in the recording unit 10 from the first entry to the subsequent entries is still sorted according to the address in the storage unit, thereby ensuring that the subsequent search process for unoccupied storage blocks can still be executed in parallel.
[0139] For example, please refer to Figure 7 In this example, the second unoccupied storage block is determined to be the unoccupied storage block allocated to the first thread. Since the second unoccupied storage block is located in the second position after sorting the second unoccupied storage block and the three occupied storage blocks according to their addresses in the storage unit, the occupancy information stored in the second and third entries of record unit 10 needs to be shifted one entry to the right. Then, the newly added occupancy information (used to determine the second unoccupied storage block) is written into the second entry. It can be seen that in the newly added record unit 15, the starting addresses of the unoccupied storage blocks stored from the first to the fourth entry are still arranged in order in the storage unit.
[0140] In some embodiments, the recording control unit 10 is configured to delete the occupancy information stored in the r-th entry of the Q entries and move the occupancy information stored in the t-th entry of the Q entries to the (t-1)-th entry based on the release information.
[0141] t is an integer greater than r and less than M, where r is a positive integer less than or equal to M. The release information is used to indicate the cancellation of the occupied storage block corresponding to the r-th entry.
[0142] In some embodiments, when r equals M, the recording control unit 10 is used to delete the occupancy information stored in the Mth entry out of the Q entries.
[0143] It should be noted that t can take any value within the range of greater than r and less than M. That is to say, for each of the Q entries 11, after the r-th entry, the occupancy information of each entry must be moved to the previous entry.
[0144] In some embodiments, after the processing unit 2 finishes executing the second thread using the occupied storage block corresponding to the r-th entry, it provides release information to the record control unit. The second thread is a different thread from the first thread.
[0145] With the technical solution provided in the above embodiments, after deleting the occupancy information from the recording unit 10, it can be ensured that the occupancy information stored in the recording unit 10 from the first entry to the subsequent entries is still sorted according to the address in the storage unit, and the entries that store occupancy information are still concentrated at the head of the recording unit 10. There will be no entries that do not store occupancy information between two entries that store occupancy information, thereby ensuring that the subsequent search process for unoccupied storage blocks can still be executed in parallel.
[0146] For example, please refer to Figure 8 In this example, r=2, it is necessary to delete the occupancy information stored in the second entry of record unit 10 (i.e., the second occupied storage block is released), and move the occupancy information stored in the third entry forward one entry. It can be seen that in the deleted record unit 16, the starting addresses of the unoccupied storage blocks stored from the first entry to the second entry are still arranged sequentially, and the entries storing occupancy information (the first and second entries) are all concentrated at the head of the deleted record unit 16; there will be no entries without occupancy information between two entries storing occupancy information.
[0147] The technical solution provided in this application embodiment designs a resource allocation device comprising a recording unit with Q entries and a gap calculation unit with Q+1 gap calculation subunits. When the recording unit stores M occupancy information using M entries, the lengths of M+1 unoccupied storage blocks can be determined using M+1 gap calculation subunits. Since the occupancy information required by each gap calculation subunit to calculate the length of an unoccupied storage block can be directly obtained from at most two entries out of the Q entries, the aforementioned M+1 gap calculation subunits can obtain the required data in parallel and calculate the lengths of the M+1 unoccupied storage blocks in parallel. Therefore, the resource allocation device can quickly find the length of each unoccupied storage block in the storage unit, improving the efficiency of allocating storage resources for newly created threads.
[0148] The following are embodiments of the method of this application. For details not described in the embodiments of the method of this application, please refer to the above embodiments regarding the resource allocation device.
[0149] Please refer to Figure 9 The diagram illustrates a flowchart of a resource allocation method based on a resource allocation device according to an embodiment of this application. The method is applied to the resource allocation device for a processor described above. The resource allocation device includes a recording unit, a gap calculation unit, and an allocation unit. The recording unit is used to store M occupancy information. The i-th occupancy information among the M occupancy information is used to determine the i-th occupied storage block in the processor's storage unit. M is a positive integer, and i is a positive integer less than or equal to M.
[0150] The method includes at least one of the following steps 910 to 920.
[0151] Step 910: The gap calculation unit calculates the length of the M+1 unoccupied storage blocks in the storage unit in parallel based on the M occupancy information.
[0152] Step 920: The allocation unit determines the storage blocks to be allocated to the first thread based on the requested space length of the first thread and the length of M+1 unoccupied storage blocks.
[0153] The requested space length refers to the length of the storage block requested by the first thread.
[0154] In some embodiments, the recording unit includes Q entries, and the i-th entry of the Q entries is used to store the i-th occupancy information among M occupancy information, where Q is an integer greater than 1 and M is a positive integer less than or equal to Q.
[0155] In some embodiments, the gap calculation unit includes Q+1 gap calculation subunits. Step 910 includes: M+1 gap calculation subunits among the Q+1 gap calculation subunits calculate the lengths of M+1 unoccupied storage blocks in the storage unit in parallel based on M occupancy information, wherein each gap calculation subunit among the Q+1 gap calculation subunits is used to determine the length of one unoccupied storage block in the storage unit based on the occupancy information stored in at most two entries among the Q entries.
[0156] In some embodiments, when M is greater than 1 and i is a positive integer less than M, the (i+1)th entry of the Q entries is used to store the (i+1)th occupancy information among the M occupancy information entries. The (i+1)th occupancy information is used to determine the (i+1)th occupied storage block in the storage unit. The address of the ith occupied storage block in the storage unit is located before the address of the (i+1)th occupied storage block in the storage unit.
[0157] In some embodiments, step 910 includes at least one of the following sub-steps 912 to 916.
[0158] Sub-step 912: The first gap calculation sub-unit in the Q+1 gap calculation sub-units determines the length of the first unoccupied storage block in the M+1 unoccupied storage blocks based on the starting address of the storage unit and the occupancy information stored in the first entry in the Q entries.
[0159] Sub-step 914: When M is greater than 1 and i is a positive integer less than M, the (i+1)th gap calculation sub-unit in the Q+1 gap calculation sub-units determines the length of the (i+1)th unoccupied storage block in the M+1 unoccupied storage blocks based on the occupancy information stored in the i-th entry in the Q entries and the occupancy information stored in the (i+1)th entry in the Q entries.
[0160] In sub-step 916, the (M+1)th gap calculation sub-unit in the Q+1 gap calculation sub-units determines the length of the (M+1)th unoccupied storage block in the M+1 unoccupied storage blocks based on the occupancy information stored in the Mth entry in the Q entries and the tail address of the storage unit.
[0161] In some embodiments, the resource allocation device further includes a recording control unit.
[0162] The allocation unit is also used to provide new occupancy information to the record control unit, which is used to determine the storage block allocated to the first thread.
[0163] The above resource allocation method further includes: the record control unit moves the occupancy information stored in the j-th entry of the Q entries to the (j+1)-th entry, and writes the newly added occupancy information into the k-th entry of the Q entries; where j is an integer greater than or equal to k and less than or equal to M, and after sorting the occupied storage blocks corresponding to the M occupancy information and the storage blocks allocated to the first thread according to their addresses in the storage unit, the storage block allocated to the first thread is located at the k-th position.
[0164] In some embodiments, the resource allocation device further includes a recording control unit.
[0165] The above resource allocation method further includes: the record control unit, based on the release information, deleting the occupancy information stored in the r-th entry out of the Q entries, and moving the occupancy information stored in the t-th entry out of the Q entries to the (t-1)-th entry. Here, t is an integer greater than r and less than M, r is a positive integer less than or equal to M, and the release information is used to indicate the cancellation of the occupancy of the occupied storage block corresponding to the r-th entry.
[0166] In some embodiments, each of the Q entries includes: a status field, a start field, and a length field; the occupancy information includes: the starting address of the occupied storage block in the storage unit and the length of the occupied storage block.
[0167] The status field in an entry is used to indicate the status of the entry, which can be one of the following: first status, second status, and third status. An entry in the first status is occupied by occupancy information; an entry in the second status is not occupied by occupancy information, and the entry preceding the entry in the second status is an entry in the first status; an entry in the third status is not occupied by occupancy information and is located after the entry in the second status.
[0168] When an entry is in the first state, the start field of the entry is used to store the starting address of the occupied storage block in the storage unit, and the length field of the entry is used to store the length of the occupied storage block.
[0169] When an entry is in the second state, at least one of the start field and length field in the entry is used to store end information, which is used to indicate the tail address of the storage unit.
[0170] In some embodiments, the allocation unit includes a difference unit and a comparison unit.
[0171] The difference unit includes Q+1 difference sub-units, and step 920 above includes at least one of the following sub-steps 922 to 924.
[0172] Sub-step 922: The xth sub-unit among the Q+1 sub-units calculates the difference between the length of the xth unoccupied storage block among the M+1 unoccupied storage blocks and the requested space length, where x is a positive integer less than or equal to M+1.
[0173] Sub-step 924: The comparison unit determines the ample unoccupied storage block with the smallest difference between its length and the requested space length among the P ample unoccupied storage blocks out of the M+1 unoccupied storage blocks as the storage block to be allocated to the first thread. An ample unoccupied storage block is an unoccupied storage block whose length is greater than or equal to the length of the storage block requested by the first thread, where P is a positive integer less than or equal to M+1.
[0174] In some embodiments, the storage block allocated to the first thread is the smallest available unoccupied storage block in the storage unit. A available unoccupied storage block is an unoccupied storage block whose length is greater than or equal to the length of the storage block requested by the first thread.
[0175] The technical solution provided in this application embodiment, by designing a gap calculation unit in the resource allocation device to calculate the length of M+1 unoccupied storage blocks in parallel based on the M occupied storage blocks recorded in the recording unit, enables the resource allocation device to quickly find the length of each unoccupied storage block in the storage unit, thereby improving the efficiency of allocating storage resources to threads in the processor.
[0176] An exemplary embodiment of this application also provides a processor, which includes the resource allocation device described in the above embodiments.
[0177] An exemplary embodiment of this application also provides a computer device, the computer device including a processor, the processor including the resource allocation device described in the above embodiments.
[0178] Optionally, the computer device may be a server, or a terminal device such as a mobile phone, tablet computer, vehicle terminal, wearable device, smart home device, or any device that uses a processor, such as a robot or base station. This application does not limit the scope of the application.
[0179] An exemplary embodiment of this application also provides a chip product, which includes the resource allocation device described in the above embodiments. In some embodiments, the chip product is an AI processor chip.
[0180] One embodiment of this application also provides an AI processor, which includes the resource allocation device described in the above embodiments.
[0181] One embodiment of this application also provides a GPU, which includes the resource allocation device described in the above embodiments.
[0182] One embodiment of this application also provides a graphics card, which includes a processor, such as a GPU, or an AI processor, which includes the resource allocation device described in the above embodiments.
[0183] One embodiment of this application also provides an AI computing cluster, which includes a graphics card or a computer device, wherein the graphics card or the computer device includes a processor, and the processor includes the resource allocation device described in the above embodiment.
[0184] It should be understood that "multiple" as used herein refers to two or more. "And / or" describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A alone, A and B simultaneously, or B alone. The character " / " generally indicates that the preceding and following related objects are in an "or" relationship. Furthermore, the step numbers described herein are merely illustrative of one possible execution order. In some other embodiments, the steps may not be executed in numerical order, such as two steps with different numbers being executed simultaneously, or two steps with different numbers being executed in the reverse order of the illustration. This application does not limit this.
[0185] The above are merely exemplary embodiments of this application and are not intended to limit this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application shall be included within the protection scope of this application.
Claims
1. A resource allocation apparatus applied to a processor, characterized by, The resource allocation apparatus comprises a recording unit, a gap calculation unit and an allocation unit; The recording unit is configured to store M pieces of occupation information, the i-th piece of occupation information in the M pieces of occupation information is used to determine an i-th occupied memory block in a memory unit of the processor, M is a positive integer, and i is a positive integer less than or equal to M; The gap calculation unit is configured to calculate lengths of M+1 unoccupied memory blocks in the memory unit in parallel according to the M pieces of occupation information; The allocation unit is configured to determine a memory block allocated to a first thread according to a request space length of the first thread and the lengths of the M+1 unoccupied memory blocks, wherein the request space length refers to a length of a memory block requested to be used by the first thread.
2. The apparatus for resource allocation according to claim 1, wherein, The recording unit comprises Q entries, and the i-th entry in the Q entries is configured to store the i-th piece of occupation information in the M pieces of occupation information, Q is an integer greater than 1, and M is a positive integer less than or equal to Q; The gap calculation unit comprises Q+1 gap calculation sub-units, M+1 gap calculation sub-units in the Q+1 gap calculation sub-units are configured to calculate lengths of M+1 unoccupied memory blocks in the memory unit in parallel according to the M pieces of occupation information, and each gap calculation sub-unit in the Q+1 gap calculation sub-units is configured to determine a length of an unoccupied memory block in the memory unit according to occupation information stored in at most two entries in the Q entries.
3. The resource allocation apparatus according to claim 2, wherein, In a case where M is greater than 1 and i is a positive integer less than M, an i+1-th entry in the Q entries is configured to store an i+1-th piece of occupation information in the M pieces of occupation information, and the i+1-th piece of occupation information is used to determine an i+1-th occupied memory block in the memory unit; An address of the i-th occupied memory block in the memory unit is located before an address of the i+1-th occupied memory block in the memory unit.
4. The resource allocation apparatus according to claim 2 or 3, wherein A first gap calculation sub-unit in the Q+1 gap calculation sub-units is configured to determine a length of a first unoccupied memory block in the M+1 unoccupied memory blocks according to a first address of the memory unit and occupation information stored in a first entry in the Q entries; In a case where M is greater than 1 and i is a positive integer less than M, an i+1-th gap calculation sub-unit in the Q+1 gap calculation sub-units is configured to determine a length of an i+1-th unoccupied memory block in the M+1 unoccupied memory blocks according to occupation information stored in an i-th entry in the Q entries and occupation information stored in an i+1-th entry in the Q entries; A M+1-th gap calculation sub-unit in the Q+1 gap calculation sub-units is configured to determine a length of a M+1-th unoccupied memory block in the M+1 unoccupied memory blocks according to occupation information stored in a M-th entry in the Q entries and a last address of the memory unit.
5. The resource allocation apparatus according to any one of claims 2 to 4, characterized by, The resource allocation apparatus further comprises a recording control unit; The allocation unit is further configured to provide new occupation information to the record control unit, the new occupation information being used to determine a storage block allocated to the first thread; The record control unit is configured to move the occupation information stored in the jth entry of the Q entries to the j+1th entry, and write the new occupation information into the kth entry of the Q entries; wherein j is an integer greater than or equal to k and less than or equal to M, and after the M occupied storage blocks corresponding to the M occupation information and the storage block allocated to the first thread are sorted according to addresses in the storage unit, the storage block allocated to the first thread is located at the kth position.
6. The resource allocation apparatus according to any one of claims 2 to 5, characterized by, The resource allocation apparatus further comprises a record control unit; The record control unit is configured to delete the occupation information stored in the rth entry of the Q entries and move the occupation information stored in the tth entry of the Q entries to the t-1th entry according to release information; wherein t is an integer greater than r and less than M, r is a positive integer less than or equal to M, and the release information is used to indicate that the occupied storage block corresponding to the rth entry is cancelled.
7. The resource allocation apparatus according to any one of claims 2 to 6, characterized by, Each of the Q entries comprises a state field segment, a start field segment and a length field segment, and the occupation information comprises a first address of the occupied storage block in the storage unit and a length of the occupied storage block; The state field segment in the entry is used to indicate a state of the entry, and the state of the entry is one of a first state, a second state and a third state; wherein the entry in the first state is occupied by the occupation information; the entry in the second state is not occupied by the occupation information, and a previous entry of the entry in the second state is the entry in the first state; the entry in the third state is not occupied by the occupation information, and is located after the entry in the second state; In a case where the entry is in the first state, the start field segment in the entry is used to store the first address of the occupied storage block in the storage unit, and the length field segment in the entry is used to store the length of the occupied storage block; In a case where the entry is in the second state, at least one of the start field segment and the length field segment in the entry is used to store end information, the end information being used to indicate a tail address of the storage unit.
8. The apparatus for resource allocation according to any one of claims 2 to 7, wherein, The allocation unit comprises a difference obtaining unit and a comparison unit; The difference obtaining unit comprises Q+1 difference sub-units, and an xth difference sub-unit of the Q+1 difference sub-units is used to obtain a difference between a length of an xth unoccupied storage block of the M+1 unoccupied storage blocks and the request space length, x being a positive integer less than or equal to M+1; The comparison unit is configured to compare the difference obtained by the difference obtaining unit with the request space length, and determine the M+1 unoccupied storage blocks according to a comparison result. The comparison unit is configured to determine, from P available unoccupied memory blocks in the M+1 unoccupied memory blocks, an available unoccupied memory block with a smallest difference between a length of the available unoccupied memory block and a length of a requested memory block as the memory block allocated to the first thread, the available unoccupied memory block refers to an unoccupied memory block with a length greater than or equal to the length of the requested memory block, and P is a positive integer less than or equal to M+1.
9. The apparatus for resource allocation according to any one of claims 1 to 8, wherein, The memory block allocated to the first thread is an available unoccupied memory block with a smallest length in the memory unit, the available unoccupied memory block refers to an unoccupied memory block with a length greater than or equal to the length of the requested memory block.
10. A processor, comprising: The processor comprises the resource allocation apparatus according to any one of claims 1 to 9.
11. A computer device, comprising: The computer device comprises a processor, and the processor comprises the resource allocation apparatus according to any one of claims 1 to 9.
12. A chip product, characterized by The chip product comprises the resource allocation apparatus according to any one of claims 1 to 9.
13. A resource allocation method based on a resource allocation apparatus, characterized by, The resource allocation apparatus comprises a recording unit, a gap calculation unit and an allocation unit, the recording unit is configured to store M occupation information, an i-th occupation information in the M occupation information is configured to determine an i-th occupied memory block in a memory unit of the processor, M is a positive integer, and i is a positive integer less than or equal to M; The method comprises: The gap calculation unit is configured to calculate lengths of M+1 unoccupied memory blocks in the memory unit in parallel according to the M occupation information; The allocation unit is configured to determine a memory block allocated to the first thread according to a length of a requested memory block of the first thread and the lengths of the M+1 unoccupied memory blocks, the length of the requested memory block refers to a length of a memory block requested by the first thread.