Hardware resource allocation method, electronic device and storage medium
By allocating processing units to process computing tasks in multiple dimensions of tensor data, calculating the hardware resource overhead of each allocation scheme and selecting the target scheme, the problem that the hardware resource allocation strategy in the existing technology is difficult to adapt to different application scenarios is solved, and the problem is improved. Improves the parallel execution efficiency and hardware performance of the processing unit.
Patent Information
- Application Number
- CN202410727538.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-06
- Publication Date
- 2024-10-22
- Estimated Expiration
- 2044-06-06
AI Technical Summary
Existing hardware resource allocation strategies are difficult to achieve optimal performance in different application scenarios and cannot be dynamically adjusted, resulting in low parallel execution efficiency of processing units, waste of hardware resources, and high synchronization overhead.
By obtaining the tensor data shape of the operator, allocate processing units to handle computing tasks in multiple dimensions, calculate the hardware resource overhead of each allocation plan, select the target allocation plan to configure the operator, and improve the parallel execution efficiency of the processing unit.
It achieves adaptive optimization of hardware resource allocation in different application scenarios, improves the parallel execution efficiency and overall performance of the processing unit, and reduces hardware resource waste and synchronization overhead.
Smart Images

Figure CN118312327B_ABST
Abstract
Description
Technical Field
[0001] Embodiments of the present disclosure relate to a hardware resource allocation method, an electronic device, and a storage medium. Background Art
[0002] In current hardware devices, data processing integrated circuits such as central processing units (CPUs), graphics processing units (GPUs), and general-purpose computing on graphics processing units (GPGPUs) can execute programs to complete various computing tasks. As computing demands increase, hardware devices have higher and higher performance requirements for operators. Better performance means faster calculations and reduced computing overhead. However, the computing requirements in different applications vary greatly, and the distribution of processing units in different hardware devices is also different. How to maximize the parallel execution efficiency of processing units has become the key to performance improvement. Summary of the invention
[0003] At least one embodiment of the present disclosure provides a hardware resource allocation method, wherein the hardware resources include multiple processing units, and the hardware resource allocation method includes: obtaining a data shape of tensor data of an operator, wherein the data shape of the tensor data includes multiple dimensions; allocating at least one processing unit among the multiple processing units on the multiple dimensions to process computing tasks on the multiple dimensions, and obtaining multiple allocation schemes; calculating the hardware resource overhead of each of the multiple allocation schemes; selecting a target allocation scheme from the multiple allocation schemes based on the hardware resource overhead of each allocation scheme; and configuring the operator using the target allocation scheme.
[0004] For example, in the hardware resource allocation method provided in at least one embodiment of the present disclosure, the multiple dimensions include a computing dimension, the tensor data includes multiple data elements on the computing dimension, and the allocating at least one of the multiple processing units on the multiple dimensions to process the computing tasks on the multiple dimensions includes: allocating M processing units of the at least one processing unit to the multiple data elements on the computing dimension to process the computing tasks on the computing dimension, where M is a positive integer.
[0005] For example, in the hardware resource allocation method provided in at least one embodiment of the present disclosure, the multiple allocation schemes include a first allocation scheme, and the first allocation scheme includes that the computing task on the computing dimension is processed by a first processing unit among the M processing units.
[0006] For example, in the hardware resource allocation method provided in at least one embodiment of the present disclosure, the multiple allocation schemes include a second allocation scheme, and the second allocation scheme includes processing the computing tasks on the computing dimension by multiple different first processing units among the M processing units.
[0007] For example, in the hardware resource allocation method provided in at least one embodiment of the present disclosure, the multiple data elements on the calculation dimension are divided into multiple data subgroups, and the multiple data subgroups correspond one-to-one to the multiple different first processing units. In the second allocation scheme, the multiple different first processing units among the M processing units process the computing tasks on the calculation dimension, including: each of the multiple different first processing units processes at least one element in the corresponding data subgroup in the multiple data subgroups to obtain the processing result of each first processing unit; and performs data interaction between the multiple different first processing units to synchronize the processing results of the multiple different first processing units to obtain the processing result of the computing task on the calculation dimension.
[0008] For example, in the hardware resource allocation method provided in at least one embodiment of the present disclosure, the multiple dimensions include a computing dimension, the tensor data includes multiple data elements on the computing dimension, the hardware resources include multiple levels of processing units, the multiple levels of processing units include first-level processing units, and allocating at least one of the multiple processing units on the multiple dimensions to process computing tasks on the multiple dimensions includes: allocating at least one first-level processing unit to the multiple data elements on the computing dimension to process the computing tasks on the computing dimension.
[0009] For example, in the hardware resource allocation method provided in at least one embodiment of the present disclosure, the multiple dimensions also include a non-computational dimension, the tensor data is divided into multiple computing groups on the non-computational dimension, the multiple data elements in each of the multiple computing groups are arranged in the direction of the computing dimension, and the allocating at least one processing unit of the multiple processing units on the multiple dimensions to process the computing tasks on the multiple dimensions also includes: allocating the at least one first-level processing unit to the multiple data elements in each computing group to process the multiple data elements in each computing group in parallel on the non-computational dimension.
[0010] For example, in the hardware resource allocation method provided by at least one embodiment of the present disclosure, the multiple dimensions also include a non-computing dimension, the multiple levels of processing units also include a second-level processing unit, the second-level processing unit includes the at least one first-level processing unit, and the allocating at least one of the multiple processing units on the multiple dimensions to process the computing tasks on the multiple dimensions also includes: allocating at least one second-level processing unit on the non-computing dimension to process the computing tasks on the multiple dimensions in parallel on the non-computing dimension.
[0011] For example, in the hardware resource allocation method provided in at least one embodiment of the present disclosure, the calculation of the hardware resource overhead of each of the multiple allocation schemes includes: calculating the computational overhead of each allocation scheme and the synchronization overhead of each allocation scheme; merging the computational overhead of each allocation scheme and the synchronization overhead of each allocation scheme to obtain the hardware resource overhead of each allocation scheme.
[0012] For example, in the hardware resource allocation method provided in at least one embodiment of the present disclosure, the number of the multiple allocation schemes is N, N is a positive integer, and the calculation of the computational overhead of each allocation scheme includes: calculating the computational overhead of the i-th allocation scheme among the multiple allocation schemes :
[0013] ,
[0014] in, Indicates the utilization of hardware resources. α represents the normalized coefficient of the computational overhead of the i-th allocation scheme, i = 1, 2, …, N.
[0015] For example, in the hardware resource allocation method provided in at least one embodiment of the present disclosure, the number of the multiple processing units included in the hardware resources is P, the number of processing units used in the i-th allocation scheme is Q, P and Q are positive integers, and the utilization rate of the hardware resources of the i-th allocation scheme is It is expressed as:
[0016] .
[0017] For example, in the hardware resource allocation method provided in at least one embodiment of the present disclosure, the number of the multiple allocation schemes is N, the hardware resources include multiple levels of processing units, the number of the multiple levels of processing units is K, N and K are positive integers, and the calculation of the synchronization overhead of each allocation scheme includes: calculating the synchronization overhead of the i-th allocation scheme among the multiple allocation schemes :
[0018] ,
[0019] in, represents the synchronization overhead generated by data interaction between the k-th level of processing units in the multiple levels of processing units, represents the number of data interactions between the processing units at the kth level, β represents the normalized coefficient of the synchronization overhead of the i-th allocation scheme, i = 1, 2, …, N, k = 1, 2, …, K.
[0020] For example, in the hardware resource allocation method provided in at least one embodiment of the present disclosure, the number of the multiple allocation schemes is N, N is a positive integer, and the merging of the computational overhead of each allocation scheme and the synchronization overhead of each allocation scheme to obtain the hardware resource overhead of each allocation scheme includes: merging the computational overhead of the i-th allocation scheme among the multiple allocation schemes and the synchronization overhead of the i-th allocation scheme , get the hardware resource overhead of the i-th allocation scheme :
[0021] ,
[0022] Where i = 1, 2, …, N.
[0023] For example, in the hardware resource allocation method provided in at least one embodiment of the present disclosure, the target allocation scheme includes an allocation scheme with the smallest hardware resource overhead among the multiple allocation schemes.
[0024] At least one embodiment of the present disclosure further provides an electronic device. The electronic device includes: a processor; a memory including one or more computer program modules; wherein the one or more computer program modules are stored in the memory and configured to be executed by the processor, and the one or more computer program modules are used to implement the hardware resource allocation method provided in any embodiment of the present disclosure.
[0025] At least one embodiment of the present disclosure further provides a storage medium storing non-transitory computer-readable instructions, which, when executed by a computer, implements the hardware resource allocation method provided by any embodiment of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] In order to more clearly illustrate the technical solutions of the embodiments of the present disclosure, the drawings of the embodiments will be briefly introduced below. Obviously, the drawings in the following description only relate to some embodiments of the present disclosure, but are not intended to limit the present disclosure.
[0027] Figure 1A A schematic diagram of a processing unit allocation method in tensor data;
[0028] Figure 1B A schematic diagram of another way of allocating processing units in tensor data;
[0029] Figure 2 An exemplary flow chart of a method for allocating hardware resources provided for at least one embodiment of the present disclosure;
[0030] Figure 3 A schematic diagram of an example of a processing unit at multiple levels provided for at least one embodiment of the present disclosure;
[0031] Figure 4 Another exemplary flow chart of a method for allocating hardware resources provided by at least one embodiment of the present disclosure;
[0032] Figure 5A A schematic diagram of an example of a method for allocating hardware resources provided by at least one embodiment of the present disclosure;
[0033] Figure 5B A schematic diagram of another example of a hardware resource allocation method provided by at least one embodiment of the present disclosure;
[0034] Fig. 6A A schematic diagram of another example of a hardware resource allocation method provided by at least one embodiment of the present disclosure;
[0035] Figure 6B A schematic diagram of another example of a hardware resource allocation method provided by at least one embodiment of the present disclosure;
[0036] Figure 7 A schematic block diagram of a hardware resource allocation device provided for at least one embodiment of the present disclosure;
[0037] Figure 8 A schematic block diagram of an electronic device provided for at least one embodiment of the present disclosure;
[0038] Fig. 9 A schematic block diagram of another electronic device provided for at least one embodiment of the present disclosure; and
[0039] Fig.10 A schematic diagram of a storage medium provided for at least one embodiment of the present disclosure. DETAILED DESCRIPTION
[0040] In order to make the purpose, technical solution and advantages of the embodiments of the present disclosure clearer, the technical solution of the embodiments of the present disclosure will be clearly and completely described below in conjunction with the drawings of the embodiments of the present disclosure. Obviously, the described embodiments are part of the embodiments of the present disclosure, not all of the embodiments. Based on the described embodiments of the present disclosure, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present disclosure.
[0041] Unless otherwise defined, the technical terms or scientific terms used in the present disclosure should be understood by people with ordinary skills in the field to which the present disclosure belongs. The "first", "second" and similar words used in the present disclosure do not indicate any order, quantity or importance, but are only used to distinguish different components. Similarly, similar words such as "one", "one" or "the" do not indicate quantity restrictions, but indicate that there is at least one. Similar words such as "include" or "comprise" mean that the elements or objects appearing before the word cover the elements or objects listed after the word and their equivalents, without excluding other elements or objects. Similar words such as "connect" or "connected" are not limited to physical or mechanical connections, but can include electrical connections, whether direct or indirect. "Up", "down", "left", "right" and the like are only used to indicate relative positional relationships. When the absolute position of the described object changes, the relative positional relationship may also change accordingly.
[0042] The present disclosure is described below through several specific embodiments. In order to keep the following description of the embodiments of the present disclosure clear and concise, detailed descriptions of known functions and known components may be omitted. When any component of the embodiments of the present disclosure appears in more than one figure, the component is represented by the same or similar reference numeral in each figure.
[0043] In the field of artificial intelligence (AI), deep neural networks (DNN) have become the foundation of the most advanced technology and the core driving force of many applications. With the continuous generalization of the application scenarios of deep learning, deep learning computing tasks also need to be deployed on deep neural networks. Deep learning computing tasks are implemented by multiple operators (Operators, Op). In the neural network model, operators correspond to the computing logic of layers or nodes. For example, the convolution computing task in the convolution layer can be an operator; the weight summing computing task in the fully-connected layer (FC layer) can also be an operator. When implementing a neural network, operators can be implemented in software (for example, through a computer program) or in hardware (for example, through a circuit).
[0044] Deep learning computing tasks need to be deployed on different hardware devices, such as graphics processing units (GPUs), general-purpose graphics processing units (GPGPUs), or other types of hardware devices. For example, hardware devices include processing units (PUs) at different levels; since the tensor data of operators contain different dimensions, the processing units of hardware devices need to be mapped to different dimensions of tensor data in a certain combination to perform tensor processing of different dimensions.
[0045] Figure 1A A schematic diagram of the allocation of processing units in tensor data. Figure 1B A schematic diagram of another way of allocating processing units in tensor data.
[0046] For example, taking the two-dimensional input tensor of the accumulation operator as an example, the accumulation operator needs to accumulate a certain dimension of the input tensor (for example, the accumulation dimension). Since different processing units (PUs) of hardware devices (for example, GPGPU, etc.) use their own independent hardware resources, the accumulation of tensor data can be done through Figure 1A and Figure 1B way to achieve it.
[0047] For example, in Figure 1A In this way, the accumulation of all data elements in the accumulation dimension can be completed by a single processing unit (for example, each square represents a data element). Figure 1AAs shown, in the accumulation dimension, the processing unit PUa performs the accumulation calculation task of all data elements in the first row of the input tensor, the processing unit PUb performs the accumulation calculation task of all data elements in the second row of the input tensor, the processing unit PUc performs the accumulation calculation task of all data elements in the third row of the input tensor, and the processing unit PUd performs the accumulation calculation task of all data elements in the fourth row of the input tensor... until all data elements of the input tensor are accumulated.
[0048] For example, in Figure 1B In this way, multiple different processing units can complete the partial accumulation on the accumulation dimension respectively, and then the different processing units can cooperate to complete the accumulation of all data elements through data interaction (for example, each square represents a data element). Figure 1B As shown, for each row of data of the input tensor, in the accumulation dimension, the processing unit PUa performs the accumulation of the 1st-2nd data elements of the row, the processing unit PUb performs the accumulation of the 3rd-4th data elements of the row, the processing unit PUc performs the accumulation of the 5th-6th data elements of the row, and the processing unit PUd performs the accumulation of the 7th-8th data elements of the row, and then data is exchanged between different processing units PUa~PUd to synchronize the accumulation results of PUa~PUd to obtain the processing result of the accumulation calculation task of the row.
[0049] For example, if the shape of the tensor data is large, using Figure 1B The allocation of processing units will incur additional synchronization overhead for data exchange between multiple processing units in the cumulative dimension. For example, in this case, Figure 1A The method is more applicable, which can avoid the synchronization overhead between processing units and improve computing efficiency.
[0050] For example, for scenarios where the shape of tensor data has fewer non-accumulative dimensions (i.e., dimensions other than the cumulative dimensions), Figure 1A The number of processing units used in the processing unit allocation method is small, the utilization rate of the processing units is reduced, and a large amount of hardware resources are wasted. For example, for a tensor data with a shape of (1, 1024), when the first dimension "1" of the tensor data is a non-accumulative dimension and the second dimension "1024" is an accumulative dimension, Figure 1A In this way, only one processing unit can participate in the operation (for example, only PUa participates in the operation), resulting in the idleness of a large number of remaining processing units (for example, PUb~PUd). Figure 1B The approach still has the problem of additional synchronization overhead; in this case, it is impossible to determine the hardware resource allocation scheme with better performance between the two approaches.
[0051] Therefore, it can be seen that due to the large differences in computing requirements in different applications and the different distribution of processing units in different hardware devices, a single hardware resource allocation strategy is difficult to achieve optimal performance in all usage scenarios. For example, the current hardware resource allocation strategy has the following problems.
[0052] 1. The hardware resource allocation strategy used needs to be clarified during the operator development phase (for example, how to allocate multiple processing units in multiple dimensions of tensor data), and the hardware resource allocation strategy used depends on the experience of the operator developers. In the kernel function implemented by a single operator, the allocation method of hardware resources is fixed and cannot be dynamically adjusted according to the application scenario.
[0053] 2. In actual applications, it is impossible to obtain the information involved in calling a certain operator in advance, such as tensor information, dimension information, etc., and it can only be obtained at runtime. In order to use the operator in different application scenarios, different versions of operators need to be developed. On the one hand, in actual use, various branch judgments need to be made at the upper level to select the required operator version, which brings great difficulty to the early operator development. On the other hand, the overall adaptability of multiple versions is weak, especially for the explosive growth of the number of operators in the later stage, which greatly increases the difficulty of the entire development and maintenance.
[0054] At least one embodiment of the present disclosure provides a method for allocating hardware resources, wherein the hardware resources include multiple processing units. The method for allocating hardware resources includes: obtaining the data shape of tensor data of an operator, wherein the data shape of the tensor data includes multiple dimensions; allocating at least one processing unit among multiple processing units in multiple dimensions to process computing tasks in multiple dimensions, and obtaining multiple allocation schemes; calculating the hardware resource overhead of each allocation scheme in the multiple allocation schemes; selecting a target allocation scheme from the multiple allocation schemes based on the hardware resource overhead of each allocation scheme; and configuring the operator using the target allocation scheme.
[0055] At least one embodiment of the present disclosure further provides a hardware resource allocation device, an electronic device, and a storage medium, which are used to implement the hardware resource allocation method of the above embodiment.
[0056] The method, apparatus, electronic device, and storage medium provided by at least one embodiment of the present disclosure can adaptively calculate the hardware resource overhead of multiple allocation schemes in different application scenarios of the operator to select a target allocation scheme, thereby improving the parallel execution efficiency of multiple processing units and thus improving the overall performance of the hardware and operators.
[0057] Hereinafter, at least one embodiment of the present disclosure will be described in detail with reference to the accompanying drawings. It should be noted that the same reference numerals in different drawings will be used to refer to the same elements described.
[0058] In at least one embodiment of the present disclosure, the hardware resources include multiple processing units. It should be noted that the hardware resources may be hardware devices (GPU, GPGPU, etc.) required for deep learning computing tasks, and the processing units may be processing units (PUs) of the same or different levels in the hardware devices, which may be selected according to actual needs, and the embodiments of the present disclosure are not limited to this.
[0059] The hardware resource allocation method provided in at least one embodiment of the present disclosure is used for an operator, which may refer to any operator in a computing model. The operator may be a single operator or a fused operator, etc., and the operator may include different types. The embodiments of the present disclosure do not limit the type of operator and the specific implementation method.
[0060] Figure 2 An exemplary flow chart of a method for allocating hardware resources provided for at least one embodiment of the present disclosure.
[0061] For example, Figure 2 As shown, at least one embodiment of the present disclosure provides a method for allocating hardware resources. The method for allocating hardware resources may include the following steps S110 to S150.
[0062] Step S110: Obtain the data shape of the tensor data of the operator.
[0063] For example, in step S110, the tensor data may be an input tensor, an output tensor, or a weight tensor of an operator, etc., which may be selected according to actual needs, and the embodiments of the present disclosure do not limit this. For example, the data shape of the tensor data includes multiple dimensions, which may be two-dimensional, three-dimensional, four-dimensional, etc., and the embodiments of the present disclosure do not limit this. For example, taking four dimensions [N, C, H, W] as an example, the tensor data with a layout of [N, C, H, W] may include N samples, and the data corresponding to each sample includes multiple channels, and C represents the number of channels; in each channel, multiple data elements are arranged in two dimensions to form an array, and the height of the data in each channel in the vertical dimension is H, and H represents the number of data elements in the array along the column direction, and the width of the data in each channel in the horizontal dimension is W, and W represents the number of data elements in the array along the row direction. For example, the layout of tensor data of different dimensions may also include row-major order (height×width), column-major order (width×height), [N, H, W, C], etc., and the embodiments of the present disclosure do not limit this.
[0064] Step S120: Allocate at least one of the multiple processing units in multiple dimensions to process computing tasks in multiple dimensions, and obtain multiple allocation schemes.
[0065] For example, in step S120, the computing task of the operator includes processing tensor data of different dimensions; at least one processing unit among the multiple processing units allocated in multiple dimensions may be all processing units in the hardware resources, or may be part of the processing units in the hardware resources, and the embodiments of the present disclosure are not limited to this.
[0066] For example, in step S120, at least one dimension from among the multiple dimensions may be selected according to actual needs, and a predetermined number and type of processing units may be allocated on the selected dimension to perform the required computing task; based on the different predetermined numbers and types of allocated processing units, multiple different allocation schemes may be obtained (e.g. Figure 1A and Figure 1B two allocation schemes shown).
[0067] For example, in step S120, the type of computing task, the selection of dimension, the allocation method of processing units and the number of allocation schemes, etc. can all be selected according to actual needs, and the embodiments of the present disclosure do not limit this.
[0068] Step S130: Calculate the hardware resource overhead of each allocation scheme in the plurality of allocation schemes.
[0069] For example, in step S130, the hardware resource overhead may be the total time taken by one or more processing units allocated in the corresponding allocation scheme to execute the computing task. For example, by traversing multiple allocation schemes of the operator in step S130, the hardware resource overhead of each allocation scheme may be obtained.
[0070] For example, hardware resource overhead may include the time consumed by the assigned processing unit for the specific execution of data processing and the time consumed by data synchronization generated by data interaction between the assigned processing units. It may also include other types of hardware resource time consumption based on the actual execution of the operator's computing tasks. The embodiments of the present disclosure are not limited to this.
[0071] Step S140: selecting a target allocation scheme from multiple allocation schemes based on the hardware resource overhead of each allocation scheme.
[0072] Step S150: configuring operators using the target allocation scheme.
[0073] For example, in step S140, based on the hardware resource overhead of each allocation scheme obtained in step S130, a target allocation scheme can be selected from them; further, in step S150, the target allocation scheme selected in step S140 is used to configure the operator, that is, the target allocation scheme is used to allocate one or more processing units on multiple dimensions of the data tensor.
[0074] In some examples, the target allocation scheme may be an allocation scheme with the lowest hardware resource overhead among multiple allocation schemes. Figure 2 In step S140, the allocation scheme with the smallest hardware resource overhead is selected as the optimal target allocation scheme, and Figure 2 Step S150 uses the target allocation scheme to configure the target allocation scheme operator, which can obtain the minimum operator running time and greatly improve the calculation efficiency of the operator.
[0075] In other examples, the target allocation scheme may be an allocation scheme whose hardware resource overhead is less than a predetermined threshold among multiple allocation schemes. Figure 2 In step S140, one or more allocation schemes whose hardware resource overhead is less than a predetermined threshold may be preliminarily selected from multiple allocation schemes, and then further selected from the preliminarily selected one or more allocation schemes according to the application scenario of the operator to obtain the optimal target allocation scheme in the current application scenario, and Figure 2 Step S150 configures the operator using the target allocation scheme. For example, in this case, the selected target allocation scheme is more suitable for the specific application scenario of the operator, thereby improving the hardware performance as a whole.
[0076] It should be noted that the specific selection method of the target allocation scheme, the application scenario of the operator, the setting of the predetermined threshold, etc. can all be selected according to actual conditions, and the embodiments of the present disclosure are not limited to this.
[0077] In some examples, the plurality of dimensions include a computation dimension, and the tensor data includes a plurality of data elements on the computation dimension. Figure 2 The step S120 may further include a step S121: allocating M processing units of at least one processing unit to multiple data elements on the calculation dimension to process the calculation tasks on the calculation dimension, where M is a positive integer.
[0078] For example, in step S121, at least one dimension among multiple dimensions may be selected as a calculation dimension. The calculation dimension may be selected according to actual needs, and the embodiments of the present disclosure are not limited to this.
[0079] For example, in step S121, a predetermined number (M) and a predetermined type of processing units can be allocated to multiple data elements on the selected calculation dimension to perform the calculation tasks on the calculation dimension; based on the different predetermined numbers (M) or predetermined types of allocated processing units, multiple different allocation schemes can be obtained.
[0080] In some examples, the plurality of allocation schemes may include a first allocation scheme. For example, the first allocation scheme includes processing the computing tasks on the computing dimension by a first processing unit among the M processing units.
[0081] For example, the first processing unit may be any one of the M processing units, and may be specifically configured according to actual needs, and the embodiments of the present disclosure are not limited thereto. Figure 1A Taking the example of as the first allocation scheme, the row direction dimension among multiple dimensions of tensor data is selected as the calculation dimension (for example, the accumulation dimension), and the first processing unit (PUa, PUb, PUc or PUd) is allocated to the multiple data elements on the calculation dimension to complete the accumulation calculation task of the multiple data elements on the calculation dimension.
[0082] In some examples, the multiple allocation schemes may further include a second allocation scheme. For example, the second allocation scheme includes processing the computing tasks on the computing dimension by multiple different first processing units among the M processing units.
[0083] For example, the multiple different first processing units may be any multiple different processing units among the M processing units, and may be specifically configured according to actual needs, and the embodiments of the present disclosure are not limited to this.
[0084] For example, in some examples, multiple data elements on the calculation dimension are divided into multiple data subgroups, and the multiple data subgroups correspond one-to-one to multiple different first processing units. For example, in the second allocation scheme, multiple different first processing units among the M processing units process the calculation tasks on the calculation dimension, which may further include steps S1211-S1212.
[0085] Step S1211: each of the plurality of different first processing units processes at least one element in a corresponding data subgroup in the plurality of data subgroups to obtain a processing result of each first processing unit;
[0086] Step S1212: Data is exchanged between the multiple different first processing units to synchronize the processing results of the multiple different first processing units and obtain the processing results of the computing tasks in the computing dimension.
[0087] For example, Figure 1B As an example of the second allocation scheme, the row-wise dimension of the multiple dimensions of the tensor data is selected as the calculation dimension (e.g., the accumulation dimension). For example, multiple data elements on the calculation dimension are divided into multiple data subgroups; specifically, in Figure 1B In the example, each two elements are regarded as a data subgroup. For example, a plurality of data subgroups correspond one-to-one to a plurality of different first processing units (PUa, PUb, PUc and PUd).
[0088] For example, in Figure 1BIn the example, step S1211 is executed, and the first processing unit PUa executes the cumulative calculation task of the first data subgroup (including the 1st-2nd data elements) on the calculation dimension, the first processing unit PUb executes the cumulative calculation task of the second data subgroup (including the 3rd-4th data elements) on the calculation dimension, the first processing unit PUc executes the cumulative calculation task of the third data subgroup (including the 5th-6th data elements) on the calculation dimension, and the first processing unit PUd executes the cumulative calculation task of the fourth data subgroup (including the 7th-8th data elements) on the calculation dimension, and the cumulative processing results of each first processing unit are obtained respectively. For example, further, step S1212 is executed to perform data interaction between multiple different first processing units PUa~PUd to synchronize the cumulative processing results of PUa~PUd and obtain the processing results of the cumulative calculation tasks on the calculation dimension.
[0089] It should be noted that Figure 1A and Figure 1B The first allocation scheme and the second allocation scheme shown are only exemplary, and at least one embodiment of the present disclosure does not limit the specific configuration of the first allocation scheme and the second allocation scheme.
[0090] In some examples, the hardware resources include multiple levels of processing units, the multiple levels of processing units including a first level of processing units. Figure 2 The step S120 may further include a step S122: allocating at least one first-level processing unit to the plurality of data elements on the calculation dimension to process the calculation tasks on the calculation dimension.
[0091] For example, in step S122, for different allocation schemes, different numbers of first-level processing units may be allocated to multiple data elements on a calculation dimension to process the calculation tasks on the calculation dimension. For example, the hardware resources include multiple levels of processing units, and the first-level processing units may be the processing units of the first level in the hardware resources, and the first level may be the lowest level of the hardware resources; the first-level processing units may also be selected as processing units of other levels according to actual needs, and the embodiments of the present disclosure are not limited to this.
[0092] For example, in the first allocation scheme, a first-level processing unit can be allocated to multiple data elements on the calculation dimension as the first processing unit described above; in the second allocation scheme, multiple different first-level processing units can be allocated to multiple data elements on the calculation dimension as the multiple different first processing units described above; the specific allocation and calculation process can refer to the description of the first allocation scheme and the second allocation scheme above, and will not be repeated here.
[0093] For example, the multiple dimensions also include non-computational dimensions, and the tensor data is divided into multiple computational groups on the non-computational dimensions, and multiple data elements in each computational group are arranged in the direction of the computational dimensions. Figure 2 The step S120 may further include a step S123: allocating at least one first-level processing unit to each of the multiple data elements in the calculation group to process the multiple data elements in each calculation group in parallel in the non-calculation dimension.
[0094] For example, for multiple dimensions of tensor data, dimensions other than the computational dimensions can be used as non-computational dimensions, and the tensor data can be divided into multiple computational groups on the non-computational dimensions. Multiple data elements in each computational group are arranged in the direction of the computational dimensions, and the computational tasks on the computational dimensions are used to process multiple data elements in each computational group. For example, in step S123, one or more first-level processing units can be assigned to multiple data elements in each computational group; on the non-computational dimensions, the computational tasks on multiple computational groups are executed in parallel. For example, for each computational group in parallel computing, multiple data elements in the computational group are processed by the assigned one or more first-level processing units.
[0095] For example, the multiple levels of processing units also include a second level of processing units, and the second level of processing units includes at least one first level of processing units. Figure 2 The step S120 may further include a step S124: allocating at least one second-level processing unit in a non-computing dimension to process computing tasks in multiple dimensions in parallel in the non-computing dimension.
[0096] For example, in step S124, the second-level processing unit may include one or more first-level processing units; by allocating one or more second-level processing units on the non-computing dimension, one or more first-level processing units in each second-level processing unit may process multiple data elements in the computing group on each computing dimension, thereby processing computing tasks of multiple computing groups in parallel on the non-computing dimension.
[0097] Figure 3 A schematic diagram of an example of a processing unit at multiple levels provided by at least one embodiment of the present disclosure. For example, Figure 3 A specific example of a first-level processing unit and a second-level processing unit provided in at least one embodiment of the present disclosure.
[0098] For example, in Figure 3In the example, the hardware resource 100 includes 2 levels of processing units, the 2 levels of processing units include x second-level processing units PU1, and each second-level processing unit PU1 includes y first-level processing units PU0, where x and y are positive integers. For example, in some examples, the hardware resources include multiple computing units (ComputeUnit, CU), each computing unit includes multiple execution units (Execution Unit, EU), that is, the first-level processing unit PU0 can be an execution unit (EU), and the second-level processing unit PU1 can be a computing unit (CU). For example, in other examples, the first-level processing unit PU0 and the second-level processing unit PU1 can also be other types of processing units, which can be selected according to actual needs, and the embodiments of the present disclosure are not limited to this.
[0099] For example, taking a two-dimensional tensor data of shape (X, Y) as an example, the tensor data is divided into Y computing groups in the non-computational dimension, and the X data elements in each computing group are arranged in the direction of the computing dimension. For example, in step S123, M first-level processing units PU0 are allocated to the X data elements in each computing group, where M = 1, 2, …, y; in the non-computational dimension, the computing tasks on the Y computing groups are executed in parallel. For example, for each computing group in the parallel computing, the X data elements in the computing group are processed by the allocated M PU0s.
[0100] For example, in step S124, by allocating one or more second-level processing units PU1 on the non-computing dimension, M PU0s in each PU1 can process X data elements in each computing group, so that computing tasks of Y computing groups can be processed in parallel on the non-computing dimension.
[0101] For example, in Figure 3 In the example of FIG. 1 , for different allocation schemes, different numbers of first-level processing units PU0 may be allocated to X data elements on a calculation dimension to process the calculation tasks of the calculation group on the calculation dimension.
[0102] For example, specifically, in the first allocation scheme, in the computing dimension, X data elements in each computing group are processed by a single first-level processing unit PU0 (i.e., M = 1), that is, in the non-computing dimension, different PU0s process the data in Y computing groups in parallel, and there is no need for data interaction between multiple PU0s.
[0103] For example, specifically, in the second allocation scheme, in the computing dimension, the computing tasks of each computing group are evenly distributed to all y PU0s (i.e., M = y) in a single PU1. For example, the X data elements of each computing group are divided into y data subgroups, and the y data subgroups correspond one-to-one to the y PU0s in a single PU1. For example, for each computing group, the 1st PU0 to the y-1th PU0 respectively process the calculation of celing(X, y) data elements (here celing(X, y) represents the rounded-up part of the calculation result of X / y), and obtain their respective processing results sub-result; the yth PU0 processes the calculation of X - (y-1) *ceiling(X, y) data elements (i.e., the remaining data elements) to obtain the corresponding processing result sub-result. For example, further, by data interaction between the y PU0s, the y processing results sub-results of the y PU0s are synchronized to obtain the processing results of the X data elements of the computing group.
[0104] For example, in the second allocation scheme, on the non-computing dimension, by allocating one or more PU1s on the non-computing dimension, the X data elements in each computing group can be processed by y PU0s in each PU1 in the manner described above, so that the data in Y computing groups can be processed in parallel on the non-computing dimension.
[0105] It should be noted that Figure 3 The two levels of processing units PU0 and PU1 are merely exemplary, and the embodiments of the present disclosure do not limit the number of levels and the setting method of the multiple levels of processing units in the hardware resources; in addition, the allocation scheme is not limited to the first allocation scheme and the second allocation scheme described above, especially when the number of levels of the multiple levels of processing units is greater than 2, and a more complex allocation scheme will be set accordingly, and the embodiments of the present disclosure do not limit this either.
[0106] In some examples, Figure 2 The step S130 may further include steps S131~S132.
[0107] Step S131: Calculate the computational overhead of each allocation scheme and the synchronization overhead of each allocation scheme;
[0108] Step S132: Combining the computational overhead of each allocation scheme and the synchronization overhead of each allocation scheme to obtain the hardware resource overhead of each allocation scheme.
[0109] For example, the number of the multiple allocation schemes is N, where N is a positive integer. For example, in step S131, calculating the computational overhead of each allocation scheme includes: calculating the computational overhead of the i-th allocation scheme among the multiple allocation schemes by the following formula (1): .
[0110] Formula (1)
[0111] in, Indicates the utilization of hardware resources. α is the normalized coefficient representing the computational cost of the i-th allocation scheme, i = 1, 2, …, N. For example, the normalized coefficient α Related to the performance of the hardware resources themselves, the normalization coefficient of different hardware resources α different.
[0112] For example, the number of processing units included in the hardware resources is P, and the number of processing units used in the i-th allocation scheme is Q, where P and Q are positive integers. For example, the utilization rate of the hardware resources in the i-th allocation scheme is It can be expressed by the following formula (2).
[0113] Formula (2)
[0114] For example, the hardware resource utilization calculated by formula (1) using formula (2) is to evaluate the computational overhead; compared with the method of accurately calculating the actual hardware running time, the utilization of hardware resources The computational complexity is low and it has good adaptability to different hardware resource layouts, thus improving the evaluation efficiency of computational overhead.
[0115] For example, the number of levels of the processing units included in the hardware resources is K, where K is a positive integer. For example, in step S131, the synchronization overhead of each allocation scheme is calculated, including: the synchronization overhead of the i-th allocation scheme among the multiple allocation schemes is calculated by the following formula (3): .
[0116] Formula (3)
[0117] in, represents the synchronization overhead generated by data interaction between the k-th level processing units in multiple levels of processing units, Indicates the number of data interactions between the k-th level processing units. β represents the normalized coefficient of the synchronization overhead of the i-th allocation scheme, where i = 1, 2, …, N and k = 1, 2, …, K. For example, the normalized coefficient β Related to the performance of the hardware resources themselves, the normalization coefficient of different hardware resources β different.
[0118] For example, step S132 may further include: merging the computational overhead of the i-th allocation scheme among the multiple allocation schemes and the synchronization overhead of the i-th allocation scheme , get the hardware resource overhead of the i-th allocation scheme , expressed by the following formula (4).
[0119] Formula (4)
[0120] Figure 4 Another exemplary flow chart of a method for allocating hardware resources provided by at least one embodiment of the present disclosure. For example, Figure 4 for Figure 2 A specific example of the hardware resource allocation method shown.
[0121] For example, Figure 4 As shown, first execute Figure 2 In step S110, the data shape of the tensor data of the operator is obtained; in addition, a calculation dimension is selected from multiple dimensions to initialize the target hardware resource overhead. total opt is infinite (i.e. total opt =+ inf ), and initialize i = 1.
[0122] For example, Figure 4 As shown, assuming Figure 2 The number of the multiple allocation schemes obtained in step S120 is N. Further, executing Figure 2 Step S130, traverse N allocation schemes, that is, traverse and select the i-th allocation scheme among the N allocation schemes s i , to calculate the i-th allocation plan s i Hardware resource overhead total i For example, specifically, step S131 is executed to calculate the i-th allocation scheme according to formula (1) and formula (2): s i The computational overhead comp i , and calculate the i-th allocation scheme according to formula (3) s i The synchronization overhead sync i ; Further, execute step S132, according to formula (4), merge the i-th allocation scheme s i The computational overhead compi and synchronization overhead sync i , get the i-th allocation plan s i Hardware resource overhead total i .
[0123] For example, Figure 4 As shown, further, execute Figure 2 In step S140, based on the hardware resource overhead of each allocation scheme obtained in step S130, a target allocation scheme is selected from the N allocation schemes. For example, the allocation scheme with the smallest hardware resource overhead among the N allocation schemes can be selected as the target allocation scheme. For example, specifically, the i-th allocation scheme s i Hardware resource overhead total i Compared to the current target hardware resource overhead total opt Compare and use the smaller value to update the target hardware resource cost total opt (Right now total opt = min( total opt , total i )), and if total opt Updated to total i , then the current target allocation plan s opt Is synchronously updated to the i-th allocation scheme s i ; Then traverse to the next allocation scheme (i.e., i = i + 1). For example, further, determine whether there are any allocation schemes that have not been traversed among the N allocation schemes (i.e., determine whether i > N). If there are any allocation schemes that have not been traversed (i.e., i ≤ N), traverse and calculate the current allocation scheme according to the above steps; if all N allocation schemes have been traversed (i.e., i > N), select the target hardware resource cost total opt The corresponding allocation plan is used as the final target allocation plan s opt , that is, the target allocation scheme s opt This is the allocation scheme with the lowest hardware resource overhead.
[0124] For example, Figure 4 As shown, further, execute Figure 2 Step S150, using the selected target allocation scheme s opt To configure the operator, that is, to use the target allocation scheme s opt Distribute one or more processing units across multiple dimensions of a data tensor.
[0125] The hardware resource allocation method provided by at least one embodiment of the present disclosure can adaptively calculate the hardware resource overhead of multiple allocation schemes in different application scenarios of operators to select a target allocation scheme, thereby improving the parallel execution efficiency of multiple processing units and thus improving the overall performance of hardware and operators.
[0126] Figure 5A A schematic diagram of an example of a hardware resource allocation method provided by at least one embodiment of the present disclosure, Figure 5B A schematic diagram of another example of a hardware resource allocation method provided by at least one embodiment of the present disclosure. For example, Figure 5A and Figure 5B for Figure 2 Two specific examples of the hardware resource allocation method are shown.
[0127] For example, in Figure 5A and Figure 5B In the example, the hardware resources include 2 levels of processing units, the 2 levels of processing units include 4 second-level processing units (PU1-0, PU1-1, PU1-2, PU1-3), and each second-level processing unit PU1 includes 4 first-level processing units (PU0-0, PU0-1, PU0-2, PU0-3). For example, the first-level processing unit can be represented by PU(m, n), where m represents the number of the second-level processing unit PU1 where the first-level processing unit PU0 is located, and n represents the number of the first-level processing unit PU0 in the second-level processing unit PU1, where m = 0,1,2,3, and n = 0,1,2,3. For example, taking PU(0,3) as an example, PU(0,3) represents the first-level PU0-3 included in the second-level PU1-0.
[0128] For example, Figure 5A and Figure 5B As shown, execute Figure 2 In step S110, a two-dimensional tensor data with a shape of (16, 16) is obtained. For example, the row dimension of the tensor data is selected as the calculation dimension, and the column direction is selected as the non-calculation dimension. For example, the tensor data is divided into 16 calculation groups in the non-calculation dimension (for example, the column direction), and the 16 data elements in each calculation group are arranged in the direction of the calculation dimension (for example, the row direction).
[0129] For example, in Figure 2 Among the multiple allocation schemes obtained in step S120, the first allocation scheme is selected and applied to Figure 5A For example, the second allocation scheme is selected for Figure 5B .
[0130] For example, Figure 5A As shown, in the first allocation scheme, in the computing dimension, the 16 data elements in each computing group are processed by a single first-level processing unit PU0, specifically, the first computing group is processed by PU(0, 0), the second computing group is processed by PU(0, 1) ... and the 16th computing group is processed by PU(3, 3). For example, in the non-computing dimension, the data in the 16 computing groups are processed in parallel by 16 first-level processing units (PU(0, 0), PU(0, 1) ... PU(3, 3)), and there is no need for data interaction between the 16 first-level processing units PU0.
[0131] For example, Figure 5B As shown, in the second allocation scheme, in the computing dimension, the computing tasks of each computing group are evenly allocated to the four first-level processing units PU0 in a single second-level processing unit PU1. For example, the 16 data elements of each computing group are divided into four data subgroups, and the four data subgroups correspond one-to-one to the four PU0s in a single PU1. For example, taking the first calculation group as an example, in the calculation dimension, PU (0, 0) processes the 4 data elements in the first data sub-group, PU (0, 1) processes the 4 data elements in the second data sub-group, PU (0, 2) processes the 4 data elements in the third data sub-group, and PU (0, 3) processes the 4 data elements in the fourth data sub-group, and obtains 4 corresponding processing results sub-result respectively; further, through data interaction between PU (0, 1), PU (0, 2), PU (0, 3) and PU (0, 4), the 4 processing results sub-result are synchronized to obtain the processing results of 16 data elements of the calculation group.
[0132] For example, further executing Figure 2 Step S130, respectively calculate Figure 5A The first allocation scheme and Figure 5B The hardware resource overhead of the second allocation scheme is to execute Figure 2 In step S140, the allocation scheme with the smaller hardware resource overhead is selected as the target allocation scheme.
[0133] For example, specifically, step S131 is executed to calculate the computational overhead of the first allocation scheme and the second allocation scheme according to formula (1) and formula (2): comp 1 and comp 2 , and calculate the synchronization overhead of the first allocation scheme and the second allocation scheme according to formula (3) sync 1 and sync 2 ; Further, executing step S132, according to formula (4), the computational overhead of the first allocation scheme is merged comp 1 and synchronization overhead sync 1 , get the hardware resource overhead of the first allocation scheme total 1 , and, merging the computational overhead of the second allocation scheme comp 2 and synchronization overhead sync 2 , get the hardware resource overhead of the second allocation scheme total 2 .
[0134] For example, further executing Figure 2 Step S140, total 1 and total 2 After comparison, the allocation scheme corresponding to the smaller hardware resource overhead of the two is selected as the target allocation scheme, that is, the target allocation scheme is the allocation scheme with the smallest hardware resource overhead.
[0135] For example, in Figure 5A and Figure 5B In the example, for the computational overhead, the number of the multiple processing units included in the hardware resources is 16, and the number of processing units used in the first allocation scheme and the second allocation scheme is 16; according to formula (2), the hardware resource utilization of the first allocation scheme and the second allocation scheme is are both 1, and substituting them into formula (1), the calculation costs of the two allocation schemes are calculated. comp 1 and comp 2 same.
[0136] For example, in Figure 5A and Figure 5B In the example of FIG. 1 , for synchronization overhead, since the 16 processing units used in the first allocation scheme do not need to exchange data, the synchronization overhead of the first allocation scheme is sync 1 = 0; In the second allocation scheme, since each calculation group in the calculation dimension requires data exchange between four processing units, the synchronization overhead of the second allocation scheme is sync 2 Much greater than 0.
[0137] For example, according to the above calculation results, the hardware resource overhead of the first allocation scheme obtained by formula (4) is total 1 Less hardware resource overhead than the second allocation scheme total 2 , thus selecting the first allocation scheme as the target allocation scheme.
[0138] Fig. 6A A schematic diagram of another example of a hardware resource allocation method provided in at least one embodiment of the present disclosure, Figure 6B A schematic diagram of another example of a hardware resource allocation method provided in at least one embodiment of the present disclosure. For example, Fig. 6A and Figure 6B for Figure 2 Two other specific examples of the hardware resource allocation method are shown.
[0139] For example, in Fig. 6A and Figure 6B In the example, the level, quantity, and specific configuration of hardware resources are similar to Figure 5A and Figure 5B The example is the same as that of , so I will not repeat it here.
[0140] For example, Fig. 6A and Figure 6B As shown, execute Figure 2 In step S110, a two-dimensional tensor data with a shape of (4, 16) is obtained. For example, the row dimension of the tensor data is selected as the calculation dimension, and the column dimension is selected as the non-calculation dimension. For example, the tensor data is divided into 4 calculation groups in the non-calculation dimension, and the 16 data elements in each calculation group are arranged in the direction of the calculation dimension.
[0141] For example, in Figure 2 Among the multiple allocation schemes obtained in step S120, the first allocation scheme is selected and applied to Fig. 6A For example, the second allocation scheme is selected for Figure 6B .
[0142] For example, Fig. 6AAs shown, in the first allocation scheme, only the four first-level processing units (PU(0, 0), PU(0, 1), PU(0, 2) and PU(0, 3)) included in the first second-level processing unit PU1-0 are used for data processing, while the remaining PU1-1, PU1-2 and PU1-3 and the 12 PU0s included therein are idle. For example, in the calculation dimension, the 16 data elements in each calculation group are processed by a single first-level processing unit PU0, specifically, the first calculation group is processed by PU(0, 0), the second calculation group is processed by PU(0, 1), the third calculation group is processed by PU(0, 2), and the fourth calculation group is processed by PU(0, 3). For example, in the non-computing dimension, four first-level processing units (PU(0, 0), PU(0, 1), PU(0, 2) and PU(0, 3)) process data in four computing groups in parallel, and there is no need for data interaction between the four first-level processing units PU0.
[0143] For example, Figure 6B As shown, in the second allocation scheme, in terms of the computing dimension, the computing tasks of each computing group are evenly distributed to the four first-level processing units PU0 in a single second-level processing unit PU1. For example, the 16 data elements of each computing group are divided into four data subgroups, and the four data subgroups correspond one-to-one to the four PU0s in a single PU1. For example, Figure 6B The specific processing process of each calculation group in Figure 5B The example is the same as that of , and will not be repeated here.
[0144] For example, further executing Figure 2 Step S130, respectively calculate Fig. 6A The first allocation scheme and Figure 6B The hardware resource overhead of the second allocation scheme, the specific execution process of steps S131-S132 can refer to Figure 5A and Figure 5B The description will not be repeated here.
[0145] For example, in Fig. 6A and Figure 6B In the example, for the computational overhead, the number of the plurality of processing units included in the hardware resources is 16, the number of processing units used in the first allocation scheme is 4, and the number of processing units used in the second allocation scheme is 16. For example, according to formula (2), the hardware resource utilization of the first allocation scheme is The hardware resource utilization of the second allocation scheme is 1 / 4. is 1; Substituting it into formula (1), the computational cost of the first allocation scheme is calculated comp 1 Greater than the computational overhead of the second allocation scheme comp 2 .
[0146] For example, in Fig. 6A and Figure 6B In the example of , for synchronization overhead, since there is no need for data exchange between the four processing units used in the first allocation scheme, the synchronization overhead of the first allocation scheme is sync 1 = 0; In the second allocation scheme, since each calculation group in the calculation dimension requires data exchange between four processing units, the synchronization overhead of the second allocation scheme is sync 2 Much greater than 0.
[0147] For example, according to the above calculation results, the calculation cost of the first allocation scheme is comp 1 Greater than the computational overhead of the second allocation scheme comp 2 , while the computational overhead and synchronization overhead of the first allocation scheme are sync 1 Less synchronization overhead than the second allocation scheme sync 2 Therefore, the hardware resource overhead of the first allocation scheme needs to be calculated according to formula (4): total 1 and the hardware resource overhead of the second allocation scheme total 2 , by executing Figure 2 Step S140, total 1 and total 2 After comparison, the allocation scheme corresponding to the smaller hardware resource overhead of the two is selected as the target allocation scheme.
[0148] contrast Figure 5A to Figure 6B As can be seen from the example, for different shapes of tensor data, the hardware resource overhead of the first allocation scheme and the second allocation scheme is different. For example, for a scenario with a large shape of tensor data (i.e. Figure 5A and Figure 5B In this case, the second allocation scheme will generate additional synchronization overhead. In this case, the first allocation scheme can avoid the synchronization overhead between processing units and improve the computational efficiency. For example, for a scenario where the shape of tensor data has fewer non-computational dimensions (i.e. Fig. 6A and Figure 6BIn the example of ), the first allocation scheme uses a smaller number of processing units, and the utilization rate of the processing units is reduced, resulting in a waste of hardware resources, while the second allocation scheme still has synchronization overhead; in this case, by evaluating the hardware resource overhead of the two allocation schemes, a hardware resource allocation scheme with better performance can be determined in the two methods, thereby improving the parallel execution efficiency of multiple processing units and achieving better hardware performance.
[0149] It should be noted that Figure 5A to Figure 6B The allocation scheme shown is only exemplary. Various different allocation schemes can be set according to the tensor information, dimension information, etc. of the operator and the distribution mode of the processing units in the hardware resources. The embodiments of the present disclosure are not limited to this.
[0150] In the hardware resource allocation method provided in at least one embodiment of the present disclosure, developers can use the hardware resource allocation method to evaluate a variety of different allocation schemes in the early stage of developing operators, adaptively calculate the hardware resource overhead of each allocation scheme in a plurality of different allocation schemes to select a target allocation scheme, and use the target allocation scheme to configure the operator; in addition, when the user uses the operator, the hardware resource allocation method can also be used to adaptively calculate the hardware resource overhead of multiple allocation schemes in different application scenarios of the operator to select a target allocation scheme. Therefore, the hardware resource allocation method provided in at least one embodiment of the present disclosure can adaptively and efficiently obtain the optimal allocation scheme for hardware resources, improve the parallel execution efficiency of multiple processing units, and thus improve the overall performance of hardware and operators.
[0151] Figure 7 A schematic block diagram of a hardware resource allocation device provided for at least one embodiment of the present disclosure.
[0152] For example, Figure 7 As shown, the hardware resource allocation device 200 includes an acquisition module 210 , an allocation module 220 , a calculation module 230 , a selection module 240 and a configuration module 250 .
[0153] For example, the acquisition module 210 is configured to acquire the data shape of the tensor data of the operator; in some examples, the data shape of the tensor data includes multiple dimensions. That is, the acquisition module 210 can be configured to perform, for example Figure 2 Step S110 is shown.
[0154] For example, the allocation module 220 is configured to allocate at least one of the multiple processing units in multiple dimensions to process computing tasks in multiple dimensions, thereby obtaining multiple allocation schemes. That is, the allocation module 220 may be configured to perform, for example, Figure 2 Step S120 is shown.
[0155] For example, the calculation module 230 is configured to calculate the hardware resource overhead of each allocation scheme in the plurality of allocation schemes. That is, the calculation module 230 may be configured to perform, for example Figure 2 Step S130 is shown.
[0156] For example, the selection module 240 is configured to select a target allocation scheme from multiple allocation schemes based on the hardware resource overhead of each allocation scheme. That is, the selection module 240 can be configured to perform, for example Figure 2 Step S140 is shown.
[0157] For example, the configuration module 250 is configured to configure the operator using the target allocation scheme. That is, the configuration module 250 can be configured to perform, for example Figure 2 Step S150 is shown.
[0158] In some examples, the target allocation scheme includes an allocation scheme with the least hardware resource overhead among multiple allocation schemes.
[0159] In some examples, the multiple dimensions include a computational dimension, and the tensor data includes multiple data elements on the computational dimension. For example, the allocation module 220 is further configured to allocate M processing units in at least one processing unit to the multiple data elements on the computational dimension to process the computational tasks on the computational dimension, where M is a positive integer.
[0160] For example, the multiple allocation schemes include a first allocation scheme, in which the allocation module 220 is further configured to process the computing tasks on the computing dimension by a first processing unit among the M processing units.
[0161] For example, the multiple allocation schemes also include a second allocation scheme, in which the allocation module 220 is further configured to process the computing tasks on the computing dimension by multiple different first processing units among the M processing units.
[0162] For example, multiple data elements on the calculation dimension are divided into multiple data subgroups, and the multiple data subgroups correspond one-to-one to multiple different first processing units. For example, in the second allocation scheme, the allocation module 220 is also configured to: each of the multiple different first processing units processes at least one element in the corresponding data subgroup in the multiple data subgroups to obtain the processing result of each first processing unit; and perform data interaction between the multiple different first processing units to synchronize the processing results of the multiple different first processing units to obtain the processing result of the computing task on the calculation dimension.
[0163] In some examples, the multiple dimensions include a computational dimension, the tensor data includes multiple data elements on the computational dimension, the hardware resources include multiple levels of processing units, and the multiple levels of processing units include first-level processing units. For example, the allocation module 220 is further configured to allocate at least one first-level processing unit to the multiple data elements on the computational dimension to process the computational tasks on the computational dimension.
[0164] For example, the multiple dimensions also include a non-computational dimension, the tensor data is divided into multiple computational groups on the non-computational dimension, and the multiple data elements in each of the multiple computational groups are arranged in the direction of the computational dimension. For example, the allocation module 220 is further configured to allocate at least one first-level processing unit to the multiple data elements in each computational group to process the multiple data elements in each computational group in parallel on the non-computational dimension.
[0165] For example, the multiple levels of processing units also include a second level of processing units, and the second level of processing units includes at least one first level of processing units. For example, the allocation module 220 is also configured to allocate at least one second level of processing units on a non-computational dimension to parallelly process computing tasks on multiple dimensions on the non-computational dimension.
[0166] In some examples, the computing module 230 is further configured to: calculate the computing overhead of each allocation scheme and the synchronization overhead of each allocation scheme; and combine the computing overhead of each allocation scheme and the synchronization overhead of each allocation scheme to obtain the hardware resource overhead of each allocation scheme.
[0167] For example, the number of the multiple allocation schemes is N, where N is a positive integer. For example, the calculation module 230 is further configured to calculate the calculation overhead of the i-th allocation scheme among the multiple allocation schemes. :
[0168] ,
[0169] in, Indicates the utilization of hardware resources. α represents the normalized coefficient of the computational overhead of the i-th allocation scheme, i = 1, 2, …, N.
[0170] For example, the number of processing units included in the hardware resources is P, the number of processing units used in the i-th allocation scheme is Q, and P and Q are positive integers. For example, the utilization rate of the hardware resources of the i-th allocation scheme is It is expressed as:
[0171] .
[0172] For example, the number of the multiple allocation schemes is N, the hardware resources include multiple levels of processing units, the number of levels of the multiple levels of processing units is K, and N and K are positive integers. For example, the calculation module 230 is further configured to calculate the synchronization overhead of the i-th allocation scheme in the multiple allocation schemes :
[0173] ,
[0174] in, represents the synchronization overhead generated by data interaction between the k-th level processing units in multiple levels of processing units. Indicates the number of data interactions between the k-th level processing units. β represents the normalized coefficient of the synchronization overhead of the i-th allocation scheme, i = 1, 2, …, N, k = 1, 2, …, K.
[0175] For example, the calculation module 230 is further configured to combine the calculation overhead of the i-th allocation scheme among the multiple allocation schemes. and the synchronization overhead of the i-th allocation scheme , get the hardware resource overhead of the i-th allocation scheme :
[0176] ,
[0177] Where i = 1, 2, …, N.
[0178] Since in the above description, for example Figure 2~Figure 6B In the process of the hardware resource allocation method shown in FIG. 1 , the details of the operation of the hardware resource allocation device 200 have been introduced, so for the sake of brevity, they will not be repeated here. For relevant details, please refer to the above Figure 2~Figure 6B Description.
[0179] It should be noted that Figure 7 The modules in the hardware resource allocation device 200 can be configured as software, hardware, firmware or any combination of the above items to perform specific functions. For example, these modules can correspond to dedicated integrated circuits, pure software codes, or modules that combine software and hardware. Figure 7 The described device may be a PC computer, a tablet device, a personal digital assistant, a smart phone, a web application, or other device capable of executing program instructions, but is not limited thereto.
[0180] In addition, although the hardware resource allocation device 200 is described above as being divided into modules for respectively performing corresponding processes, it is clear to those skilled in the art that the processes performed by each module may also be performed without any specific module division in the device or without clear demarcation between the modules. Figure 7 The described hardware resource allocation device 200 is not limited to include the modules described above, but some other modules (eg, a reading module, a control module, etc.) may be added as needed, or the above modules may also be combined.
[0181] At least one embodiment of the present disclosure further provides an electronic device, the electronic device comprising a processor and a memory; the memory comprising one or more computer program modules; the one or more computer program modules are stored in the memory and configured to be executed by the processor, and the one or more computer program modules include a method for implementing the hardware resource allocation method provided by the embodiment of the present disclosure described above. For example, the processor may be a single-core processor or a multi-core processor.
[0182] Figure 8 A schematic block diagram of an electronic device provided for at least one embodiment of the present disclosure.
[0183] For example, Figure 8 As shown, the electronic device 300 includes a processor 310 and a memory 320. For example, the memory 320 is used to store non-transitory computer-readable instructions (e.g., one or more computer program modules). The processor 310 is used to run non-transitory computer-readable instructions, and when the non-transitory computer-readable instructions are run by the processor 310, one or more steps of the hardware resource allocation method described above can be executed. The memory 320 and the processor 310 can be interconnected through a bus system and / or other forms of connection mechanisms (not shown).
[0184] For example, the processor 310 may be a central processing unit (CPU), a graphics processing unit (GPU), a general purpose graphics processing unit (GPGPU), a digital signal processor (DSP), or other forms of processing units with hardware resource allocation capabilities and / or program execution capabilities, such as a field programmable gate array (FPGA), etc.; for example, the central processing unit (CPU) may be an X86, RISC-V, or ARM architecture, etc. The processor 310 may be a general-purpose processor or a dedicated processor, and may control other components in the electronic device 300 to perform desired functions.
[0185] For example, the memory 320 may include any combination of one or more computer program products, and the computer program product may include various forms of computer-readable storage media, such as volatile memory and / or non-volatile memory. Volatile memory may include, for example, random access memory (RAM) and / or cache memory (cache), etc. Non-volatile memory may include, for example, read-only memory (ROM), hard disk, erasable programmable read-only memory (EPROM), portable compact disc read-only memory (CD-ROM), USB memory, flash memory, etc. One or more computer program modules may be stored on the computer-readable storage medium, and the processor 310 may run one or more computer program modules to implement various functions of the electronic device 300. Various applications and various data, as well as various data used and / or generated by the application, etc. may also be stored in the computer-readable storage medium.
[0186] It should be noted that, in the embodiments of the present disclosure, the specific functions and technical effects of the electronic device 300 can refer to the above description of the hardware resource allocation method provided in at least one embodiment of the present disclosure, and will not be repeated here.
[0187] Fig. 9 A schematic block diagram of another electronic device provided for at least one embodiment of the present disclosure.
[0188] For example, Fig. 9 As shown, the electronic device 400 is suitable for implementing the hardware resource allocation method provided in the embodiment of the present disclosure. It should be noted that, Fig. 9 The electronic device 400 shown is only an example and does not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.
[0189] For example, Fig. 9As shown, the electronic device 400 may include a processing device (e.g., a central processing unit, a graphics processor, etc.) 41, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 42 or a program loaded from a storage device 48 to a random access memory (RAM) 43. In the RAM 43, various programs and data required for the operation of the electronic device 400 are also stored. The processing device 41, the ROM 42, and the RAM 43 are connected to each other through a bus 44. An input / output (I / O) interface 45 is also connected to the bus 44. Generally, the following devices can be connected to the I / O interface 45: an input device 46 including, for example, a touch screen, a touch pad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; an output device 47 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 48 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 49. The communication device 49 can allow the electronic device 400 to communicate with other electronic devices wirelessly or by wire to exchange data.
[0190] Although Fig. 9 The electronic device 400 is shown to have various devices, but it should be understood that it is not required to implement or possess all the devices shown, and the electronic device 400 may alternatively implement or possess more or fewer devices.
[0191] For the detailed description and technical effects of the electronic device 400, please refer to the above description of the hardware resource allocation method, which will not be repeated here.
[0192] Fig.10 A schematic diagram of a storage medium provided for at least one embodiment of the present disclosure.
[0193] For example, Fig.10 As shown, the storage medium 500 stores non-transitory computer-readable instructions 510. For example, when the non-transitory computer-readable instructions 510 are executed by a computer, one or more steps in the hardware resource allocation method described above are performed.
[0194] For example, the storage medium 500 can be applied to Figure 8 For example, the storage medium 500 may be the memory 320 in the electronic device 300. For example, the description of the storage medium 500 may refer to Figure 8 The corresponding description of the memory 320 in the electronic device 300 is shown and will not be repeated here.
[0195] There are a few points to note about this disclosure:
[0196] (1) In the drawings of the embodiments of the present disclosure, only the structures related to the embodiments of the present disclosure are involved, and other structures can refer to the general design.
[0197] (2) Unless there is a conflict, the features of the same embodiment or different embodiments of the present disclosure may be combined with each other.
[0198] The above are only specific embodiments of the present disclosure, but the protection scope of the present disclosure is not limited thereto. Any technician familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed in the present disclosure, which should be included in the protection scope of the present disclosure. Therefore, the protection scope of the present disclosure should be based on the protection scope of the claims.
Claims
1. A method for allocating hardware resources, wherein: The hardware resources include a plurality of processing units, The hardware resource allocation method comprises: Obtaining a data shape of tensor data of an operator, wherein the data shape of the tensor data includes multiple dimensions; Allocating at least one of the plurality of processing units in the plurality of dimensions to process computing tasks in the plurality of dimensions, to obtain a plurality of allocation schemes; Calculating the hardware resource overhead of each allocation scheme in the multiple allocation schemes, wherein the hardware resource overhead of each allocation scheme includes the computation overhead and synchronization overhead of the corresponding allocation scheme, and the synchronization overhead includes the time consumption of data synchronization generated by data interaction between different processing units allocated in the corresponding allocation scheme; Selecting a target allocation scheme from the multiple allocation schemes based on the hardware resource overhead of each allocation scheme; configuring the operator using the target allocation scheme, The step of calculating the hardware resource overhead of each allocation scheme in the plurality of allocation schemes includes: Calculating a computational overhead of each allocation scheme and a synchronization overhead of each allocation scheme; Combining the computational overhead of each allocation scheme and the synchronization overhead of each allocation scheme to obtain the hardware resource overhead of each allocation scheme, The number of the multiple allocation schemes is N, the hardware resources include multiple levels of processing units, the number of the multiple levels of processing units is K, N and K are positive integers, The calculating the synchronization overhead of each allocation scheme comprises: Calculate the synchronization overhead sync of the i-th allocation scheme in the multiple allocation schemes i : Among them, so k represents the synchronization overhead generated by data interaction between the k-th level of processing units in the multiple levels of processing units, j k represents the number of data interactions between the processing units at the kth level, β represents the normalized coefficient of the synchronization overhead of the ith allocation scheme, i=1,2,…,N, k=1,2,…,K.
2. The method for allocating hardware resources according to claim 1, wherein: The multiple dimensions include a calculation dimension, the tensor data includes multiple data elements on the calculation dimension, The allocating at least one of the plurality of processing units in the plurality of dimensions to process computing tasks in the plurality of dimensions comprises: M processing units in the at least one processing unit are allocated to the multiple data elements on the calculation dimension to process the calculation tasks on the calculation dimension, wherein M is a positive integer.
3. The method for allocating hardware resources according to claim 2, wherein: The plurality of allocation schemes include a first allocation scheme, The first allocation scheme includes processing the computing tasks on the computing dimension by a first processing unit among the M processing units.
4. The method for allocating hardware resources according to claim 2, wherein: The plurality of allocation schemes include a second allocation scheme, The second allocation scheme includes processing the computing tasks on the computing dimension by a plurality of different first processing units among the M processing units.
5. The method for allocating hardware resources according to claim 4, wherein: The plurality of data elements on the calculation dimension are divided into a plurality of data subgroups, and the plurality of data subgroups correspond one-to-one to the plurality of different first processing units. In the second allocation scheme, the processing of the computing tasks on the computing dimension by a plurality of different first processing units among the M processing units includes: Each of the plurality of different first processing units processes at least one element in a corresponding data subgroup in the plurality of data subgroups to obtain a processing result of each first processing unit; Data interaction is performed between the multiple different first processing units to synchronize processing results of the multiple different first processing units and obtain processing results of the computing tasks on the computing dimension.
6. The method for allocating hardware resources according to claim 1, wherein: The plurality of dimensions include a computation dimension, the tensor data includes a plurality of data elements on the computation dimension, the plurality of levels of processing units include a first level of processing units, The allocating at least one of the plurality of processing units in the plurality of dimensions to process computing tasks in the plurality of dimensions comprises: At least one first-level processing unit is allocated to a plurality of data elements on the calculation dimension to process the calculation tasks on the calculation dimension.
7. The method for allocating hardware resources according to claim 6, wherein: The multiple dimensions further include a non-computational dimension, the tensor data is divided into multiple computational groups on the non-computational dimension, and multiple data elements in each of the multiple computational groups are arranged in a direction of the computational dimension. The allocating at least one of the plurality of processing units in the plurality of dimensions to process the computing tasks in the plurality of dimensions further includes: The at least one first-level processing unit is assigned to the plurality of data elements in each computation group to process the plurality of data elements in each computation group in parallel in the non-computation dimension.
8. The method for allocating hardware resources according to claim 6, wherein: The plurality of dimensions further include non-computational dimensions, the plurality of levels of processing units further include second level processing units, the second level processing units including the at least one first level processing unit, The allocating at least one of the plurality of processing units in the plurality of dimensions to process the computing tasks in the plurality of dimensions further includes: At least one second-level processing unit is allocated on the non-computation dimension to process the computing tasks on the multiple dimensions in parallel on the non-computation dimension.
9. The method for allocating hardware resources according to claim 1, wherein: The calculating of the computational overhead of each allocation scheme includes: Calculate the computational cost comp of the i-th allocation scheme among the multiple allocation schemes i : comp i =a / s i Among them, σ i represents the utilization rate of hardware resources, α represents the normalized coefficient of the computational overhead of the i-th allocation scheme, i=1,2,…,N.
10. The method for allocating hardware resources according to claim 9, wherein: The number of the multiple processing units included in the hardware resources is P, the number of the processing units used in the i-th allocation scheme is Q, P and Q are positive integers, and the utilization rate σ of the hardware resources of the i-th allocation scheme is i It is expressed as: σ i = Q / P.
11. The method for allocating hardware resources according to claim 1, wherein: The combining the computational overhead of each allocation scheme and the synchronization overhead of each allocation scheme to obtain the hardware resource overhead of each allocation scheme includes: The computational cost of combining the i-th allocation scheme among the multiple allocation schemes comp i and the synchronization overhead of the i-th allocation scheme i , get the total hardware resource cost of the i-th allocation scheme i : total i =comp i +sync i Where i=1,2,…,N.
12. The method for allocating hardware resources according to any one of claims 1 to 11, wherein: The target allocation scheme includes an allocation scheme with the smallest hardware resource overhead among the multiple allocation schemes.
13. An electronic device comprising: processor; a memory including one or more computer program modules; The one or more computer program modules are stored in the memory and configured to be executed by the processor, and the one or more computer program modules are used to implement the hardware resource allocation method according to any one of claims 1 to 12.
14. A storage medium storing non-transitory computer-readable instructions, which, when executed by a computer, implements the hardware resource allocation method according to any one of claims 1 to 12.
Citation Information
Patent Citations
Reconfigurable computing chip
CN113986816A
Implementation mode of neural network in multi-core hardware
CN114358237A
Neural network model processing method and device
CN116187391A
Calculation resource allocation method and device for tensor calculation graph and readable storage medium
CN116483550A
Operator parallel segmentation method and system for general tensor processor
CN117077744A
