Cache use optimization method and device, storage medium and program product

By splitting the input tensor into sub-tensors and selecting the best cache strategy, the problem of underutilization of cache resources in convolutional calculations is solved, improving computational efficiency and optimizing computational performance.

CN119149484APending Publication Date: 2024-12-17SHANGHAI BIREN TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411187939.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-27
Publication Date
2024-12-17

AI Technical Summary

Technical Problem

In the convolutional calculation, the preset fixed cache usage strategy cannot adapt to the diverse input feature graph shape, resulting in underutilization of cache resources, which affects the computing efficiency.

Method used

By splitting the input tensor into multiple sub-tensters, obtain multiple cache usage strategies based on the shape of each sub-tenster, calculate the expected processing performance, select the best cache strategy for convolutional calculation, make full use of cache resources and improve calculation efficiency .

Benefits of technology

The optimal cache usage strategy selection for input tensors of different shapes is realized, the efficiency of convolutional calculation is improved, and generalized to any scenario, optimizing the computing performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119149484A_ABST
    Figure CN119149484A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a cache use optimization method and device, a storage medium and a program product, and relates to the technical field of artificial intelligence, and the method comprises the steps: segmenting an input tensor into a plurality of sub-tensors according to the shape of the input tensor and the number of calculation units; and for each sub-tensor, a plurality of candidate strategy groups are selected based on the shape of the sub-tensor, and each candidate strategy group comprises a cache use strategy and a pipeline configuration strategy. And calculating corresponding predicted processing performance when convolution calculation is performed on the sub-tensor by adopting each candidate strategy group, and selecting an optimal target strategy group from the plurality of candidate strategy groups based on a plurality of obtained predicted processing performance. In this way, for input tensors of different shapes, the optimal cache use strategy and the optimal pipeline configuration strategy can be selected for convolution calculation, the efficiency of convolution calculation is improved, cache resources are fully utilized, and the method can be generalized to various scenes, so that the calculation performance of a convolution operator in various scenes is optimized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present application relate to the field of artificial intelligence technology, and in particular to a cache usage optimization method, device, storage medium, and program product. Background Art

[0002] Artificial intelligence models usually refer to neural network models that are trained to perform inference and prediction, such as image inference models, speech inference models, etc. The calculation of artificial intelligence models can be implemented by operators in the computation graph. Operators refer to various calculations performed on tensors at each layer in the artificial intelligence model. For example, the convolution calculation performed by the convolution layer of the artificial intelligence model on the input data of the artificial intelligence model is the convolution operator.

[0003] In the related technology, during the execution of the convolution operator, the feature map (activation) and weight (weight) are first loaded from the video memory to the on-chip cache, and then the convolution calculation is performed on the feature map and weight according to the preset fixed cache usage strategy.

[0004] In practical applications, the shapes of input feature maps are diverse, and the preset fixed cache usage strategy is only applicable to input feature maps of several shapes. It is difficult to achieve good results in the convolution calculation of diverse input feature maps, resulting in insufficient utilization of cache resources and affecting the efficiency of convolution calculation. Summary of the invention

[0005] The embodiments of the present application provide a cache usage optimization method, device, storage medium and program product for improving the utilization of cache resources while improving the efficiency of convolution calculations.

[0006] On the one hand, an embodiment of the present application provides a cache usage optimization method, including:

[0007] Based on the shape of the input tensor and the number of computing units, the input tensor is split into multiple sub-tensors; for each of the multiple sub-tensors, the following operations are performed:

[0008] Based on the shape of a sub-tensor, obtain a corresponding plurality of cache usage strategies, and based on the plurality of cache usage strategies, respectively calculate an estimated processing performance corresponding to the sub-tensor;

[0009] Based on the obtained multiple estimated processing performances, a target cache strategy corresponding to the one sub-tensor is obtained from the multiple cache usage strategies.

[0010] On the one hand, an embodiment of the present application provides a cache usage optimization device, including:

[0011] A splitting module, used for splitting the input tensor into multiple sub-tensors based on the shape of the input tensor and the number of computing units;

[0012] The strategy selection module is used to perform the following operations on the multiple sub-tensors:

[0013] Based on the shape of a sub-tensor, obtain a corresponding plurality of cache usage strategies, and based on the plurality of cache usage strategies, respectively calculate an estimated processing performance corresponding to the sub-tensor;

[0014] Based on the obtained multiple estimated processing performances, a target cache strategy corresponding to the one sub-tensor is obtained from the multiple cache usage strategies.

[0015] Optionally, the segmentation module is specifically used for:

[0016] The input tensor is split into multiple sub-tensors based on the shape of the input tensor, the number of computing units, and the splitting priorities of multiple dimensions of the input tensor.

[0017] Optionally, the strategy selection module is specifically used to:

[0018] Based on the shape of the one sub-tensor and the cache configuration information of the computing unit used to calculate the one sub-tensor, a corresponding plurality of cache usage strategies are obtained.

[0019] Optionally, the strategy selection module is further used to:

[0020] Based on the obtained multiple estimated processing performances, after obtaining the target cache strategy corresponding to the one sub-tensor from the multiple cache usage strategies, convolution calculation is performed on the one sub-tensor according to the target cache strategy to obtain a calculation result.

[0021] Optionally, the strategy selection module is further used to:

[0022] After obtaining multiple corresponding cache usage strategies based on the shape of a sub-tensor, the following operations are performed for the multiple cache usage strategies:

[0023] Acquire at least one pipeline configuration strategy corresponding to a cache usage strategy, and combine the cache usage strategy with the at least one pipeline configuration strategy to obtain at least one corresponding candidate strategy group;

[0024] The strategy selection module is specifically used for:

[0025] For the multiple cache usage strategies, the following operations are performed respectively: based on at least one candidate strategy group corresponding to one cache usage strategy, the estimated processing performance corresponding to the one sub-tensor is calculated respectively.

[0026] Optionally, the strategy selection module is specifically used to:

[0027] Based on the obtained multiple estimated processing performances, a target strategy group corresponding to the one sub-tensor is obtained from the candidate strategy groups corresponding to the multiple cache usage strategies, and the target strategy group includes the target cache strategy and the corresponding pipeline configuration strategy.

[0028] Optionally, the strategy selection module is further used to:

[0029] Based on the obtained multiple estimated processing performances, after obtaining the target strategy group corresponding to the one sub-tensor from the candidate strategy groups corresponding to the multiple cache usage strategies, convolution calculation is performed on the one sub-tensor according to the target strategy group to obtain a calculation result.

[0030] On the one hand, an embodiment of the present application provides a computer device, including a memory, an artificial intelligence chip, and a computer program stored in the memory and executable on the artificial intelligence chip, wherein the artificial intelligence chip implements the steps of the above-mentioned cache usage optimization method when executing the computer program.

[0031] On the one hand, an embodiment of the present application provides a computer-readable storage medium, which stores a computer program executable by a computer device. When the computer program runs on the computer device, the computer device executes the steps of the above-mentioned cache usage optimization method.

[0032] On the one hand, an embodiment of the present application provides a computer program product, which includes a computer program stored on a computer-readable storage medium, and the computer program includes program instructions. When the program instructions are executed by a computer device, the computer device executes the steps of the above-mentioned cache usage optimization method.

[0033] In an embodiment of the present application, the input tensor is divided into multiple sub-tensors according to the shape of the input tensor and the number of computing units. According to the shape of each sub-tensor, multiple corresponding cache usage strategies are obtained, and based on each cache usage strategy, the estimated processing performance corresponding to the sub-tensor is calculated, so that the target cache strategy corresponding to the sub-tensor can be obtained from multiple cache usage strategies based on the obtained multiple estimated processing performances. Then, for input tensors of different shapes, the best cache usage strategy can be selected for convolution calculation, which can not only make full use of cache resources, but also improve the efficiency of convolution calculation, and this method can be generalized to any scenario, thereby optimizing the computing performance of the convolution operator in various scenarios. BRIEF DESCRIPTION OF THE DRAWINGS

[0034] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.

[0035] Figure 1 A schematic diagram of the structure of an artificial intelligence chip provided in an embodiment of the present application;

[0036] Figure 2 A schematic diagram of a process flow of a cache usage optimization method provided in an embodiment of the present application;

[0037] Figure 3 A schematic diagram of the shape of a tensor provided in an embodiment of the present application;

[0038] Figure 4 A schematic diagram of the structure of a cache usage optimization device provided in an embodiment of the present application;

[0039] Figure 5 A schematic diagram of the structure of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0040] In order to make the purpose, technical solution and beneficial effects of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention.

[0041] refer to Figure 1 , which is a structural diagram of an artificial intelligence chip applicable to an embodiment of the present application. The artificial intelligence chip 100 includes at least: a video memory 101, an on-chip cache 102 and multiple computing units 103.

[0042] The video memory 101 may be a high bandwidth memory (HBM) or other types of memory. The on-chip cache 102 is a temporary memory, which has a smaller capacity than the video memory 101 but has a faster data reading and writing speed than the video memory 101.

[0043] The computing unit 103 may be used to execute various types of operators, including but not limited to: a convolution operator, an attention mechanism operator, and a matrix multiplication operator.

[0044] The computing unit 103 can read and write data to the video memory 101, and can also read and write data to the on-chip cache 102. For example, the computing unit 103 can read data from the video memory 101 for calculation; it can also read data from the video memory 101 and then write the read data to the on-chip cache 102. If the subsequent calculation process needs to use the data multiple times, the data can be read from the on-chip cache 102 for calculation multiple times. Compared with reading the data from the video memory 101 multiple times, reading the data from the on-chip cache 102 multiple times can greatly improve the efficiency of data reading.

[0045] In addition to the above-mentioned structure, the artificial intelligence chip 100 in the present application may also include other structures, which are not specifically limited in the present application.

[0046] The artificial intelligence chip 100 may be: a graphics processing unit (GPU), a general-purpose graphics processing unit (GPGPU), a domain specific architecture (DSA), etc.

[0047] During the execution of the convolution operator, the feature map (activation) and weight (weight) are first loaded from the video memory to the on-chip cache, and then the convolution calculation is performed on the feature map and weight according to the preset fixed cache usage strategy.

[0048] In practical applications, feature maps have various shapes. For feature maps of different shapes, the performance of the convolution operator is different when the cache usage method is different. The preset fixed cache usage strategy is only applicable to input feature maps of several shapes, and it is difficult to achieve good results in the convolution calculation of diverse input feature maps, resulting in insufficient utilization of cache resources and affecting the efficiency of convolution calculation.

[0049] In view of this, the present application provides a process of a cache usage optimization method, such as Figure 2 As shown, the process of the method is executed by a computer device, the computer device comprising Figure 1 The artificial intelligence chip shown includes the following steps:

[0050] Step 201, based on the shape of the input tensor and the number of computing units, split the input tensor into multiple sub-tensors.

[0051] Specifically, the input tensor can be a scalar or a one-dimensional or multi-dimensional array. The shape of the input tensor refers to the size of the input tensor in each dimension.

[0052] For example, see Figure 3 , when the input tensor is a one-dimensional tensor (i.e., a one-dimensional array, also called a vector), the input tensor includes 3 elements in one dimension, then the shape of the input tensor is (3).

[0053] When the input tensor is a two-dimensional tensor (i.e., a matrix), the input tensor contains 3 elements in each of the two dimensions, then the shape of the input tensor is (3, 3).

[0054] During the convolution calculation process, the input tensor can be a feature map for convolution calculation or a weight for convolution calculation.

[0055] In this application, the total number of computing units contained in an artificial intelligence chip is a hardware property of the artificial intelligence chip, and the total number of computing units contained in different types of artificial intelligence chips may be different.

[0056] When splitting the input tensor, the number of computing units used can be the number of computing units in an available state in the artificial intelligence chip, the number of partial computing units selected from the computing units in an available state, or the total number of computing units contained in the artificial intelligence chip. This application does not make any specific limitations on this.

[0057] Assuming that the number of computing units is the number of computing units in an available state, when splitting the input tensor, first determine the number of computing units in an available state in the artificial intelligence chip, and then split the input tensor into multiple sub-tensors according to the shape of the input tensor and the number of computing units in an available state. The number of sub-tensors obtained by splitting is the same as the number of computing units in an available state, and then the computing task of each sub-tensor is scheduled to a computing unit in an available state for calculation. Multiple computing units in an available state can calculate the assigned sub-tensors in parallel. In practical applications, the shapes of the sub-tensors calculated by multiple computing units may be the same or different.

[0058] In some embodiments, the input tensor is split into multiple sub-tensors based on the shape of the input tensor, the number of computing units, and the splitting priority of multiple dimensions of the input tensor.

[0059] Specifically, the splitting priorities of multiple dimensions of the input tensor can be set according to actual conditions. The dimension with the highest splitting priority can be selected from multiple dimensions as the splitting dimension to split the input tensor. Of course, dimensions with other splitting priorities can be selected as the splitting dimensions to split the input tensor, and this application does not make specific limitations on this.

[0060] For example, the multiple dimensions of the input tensor are: batch (N) dimension, channel (C) dimension, width (W) dimension, height (H) dimension. The splitting priorities of these four dimensions (in order from high to low) are set to: batch (N) dimension, width (W) dimension, height (H) dimension, channel (C) dimension.

[0061] Since the batch dimension has the highest priority for segmentation, the batch dimension is selected as the segmentation dimension, that is, based on the shape of the input tensor and the number of computing units, the input tensor is segmented on the batch dimension of the input tensor to obtain multiple sub-tensors.

[0062] Specifically, if the batch number corresponding to the input tensor can divide the number of computing units, the integer division result of the batch number corresponding to the input tensor and the number of computing units is used as the batch number corresponding to each sub-tensor after segmentation. The number of computing units is used as the number of sub-tensors that need to be segmented. Then, according to the batch number corresponding to each sub-tensor obtained and the number of sub-tensors, the input tensor is evenly segmented on the batch dimension of the input tensor to obtain multiple sub-tensors of the same shape.

[0063] For example, set the number of batches corresponding to the input tensor to 8, the number of computing units to 4, divide the number of batches corresponding to the input tensor by the number of computing units, and obtain the number of batches corresponding to each sub-tensor after segmentation: 2. Since the number of computing units is 4, 4 sub-tensors need to be segmented. On this basis, the 8 batches contained in the input tensor are evenly divided into 4 data (i.e., 4 sub-tensors) calculated by 4 computing units respectively. Each data includes 2 batches in the input tensor, and each computing unit calculates one sub-tensor.

[0064] Since the shapes of the sub-tensors calculated by multiple computing units are the same, when multiple computing units calculate multiple sub-tensors in parallel, the consistency of the calculation progress of the multiple computing units can be improved, and the computing resources of each computing unit can be fully utilized.

[0065] If the batch number corresponding to the input tensor cannot divide the number of computing units, the batch number corresponding to the input tensor is divided by the number of computing units and rounded up to obtain the batch number corresponding to each sub-tensor after segmentation. The number of computing units is used as the number of sub-tensors to be segmented. Then, according to the batch number corresponding to each sub-tensor and the number of sub-tensors obtained, the input tensor is segmented on the batch dimension of the input tensor to obtain multiple sub-tensors.

[0066] In practical applications, the number of batches required for each sub-tensor is obtained by dividing the number of batches corresponding to the input tensor by the number of computing units and then rounding up. Therefore, the number of batches actually corresponding to the input tensor is difficult to meet the number of batches required for each sub-tensor. In this case, first cut out the sub-tensors calculated by some computing units in multiple calculations from the input tensor according to the number of batches required for each sub-tensor. When the number of batches remaining in the input tensor is less than the number of batches required for each sub-tensor, the remaining batches in the input tensor are used as a sub-tensor (the sub-tensor is calculated by one computing unit remaining in multiple calculations).

[0067] For example, the number of batches corresponding to the input tensor is set to 10, namely batches 1 to 10; the number of computing units is 4, namely computing units 1 to 4. Divide the number of batches corresponding to the input tensor by the number of computing units and round up to get the number of batches corresponding to each sub-tensor after segmentation: 3. Since the number of computing units is 4, 4 sub-tensors need to be segmented.

[0068] First, according to the number of batches "3" that each sub-tensor needs to correspond to, the input tensor is split into sub-tensor 1 (including batches 1 to 3) calculated by computing unit 1, sub-tensor 2 (including batches 4 to 6) calculated by computing unit 2, and sub-tensor 3 (including batches 7 to 9) calculated by computing unit 3. At this time, there is one batch left in the input tensor (i.e., batch 10), and this batch is used as sub-tensor 4 calculated by computing unit 4.

[0069] It should be noted that when the input tensor is split, the shapes of the corresponding sub-tensors obtained are different when the split dimensions are different. For example, the shape of the sub-tensor obtained by splitting with the batch dimension as the split dimension is different from the shape of the sub-tensor obtained by splitting with the width dimension as the split dimension.

[0070] Step 202, for multiple sub-tensors, perform the following steps 2021 and 2022 respectively:

[0071] Step 2021, based on the shape of a sub-tensor, obtain the corresponding multiple cache usage strategies, and based on the multiple cache usage strategies, respectively calculate the expected processing performance corresponding to the sub-tensor.

[0072] Specifically, the cache usage strategy includes: cache resource types and corresponding cache implementation rules. A cache usage strategy may include one or more cache resource types. The cache implementation rules include: usage rules for each cache resource type included in the cache usage strategy during operator execution. When a cache resource type needs to be reused, the cache implementation rules also include reuse rules for the cache resource type.

[0073] The cache resource types may be: general matrix main buffer (Gemm Main Buffer, referred to as GMB), group shared memory (Group-Shared Memory, referred to as GSM), video memory workspace (Workspace), etc.

[0074] For example, the convolution calculation process is set to include a data preloading step and a calculation step. The cache resource type in the cache usage strategy is GMB, and the cache implementation rule for this cache resource type is: when performing convolution calculations on multiple data blocks in a sub-tensor in sequence, different data blocks of the input tensor are loaded into different GMBs.

[0075] In some embodiments, based on the shape of a sub-tensor and cache configuration information of a computing unit used to calculate the sub-tensor, corresponding multiple cache usage strategies are obtained.

[0076] Specifically, the cache configuration information of the computing unit includes: the type of cache resources included in the computing unit, the size of each type of cache resources, the bandwidth of each type of cache resources, and the like.

[0077] Based on the shape of the sub-tensor and the cache configuration information of the computing unit, the required cache resource type is selected from the various cache resources included in the computing unit. Specifically, based on the cache configuration information of the computing unit, the various cache resources included in the computing unit and the attribute information of each cache resource (such as the size and bandwidth of the cache resource) can be determined.

[0078] When the calculation process of a sub-tensor only requires one type of cache resource, for each type of cache resource in the calculation unit, based on the attribute information of the cache resource and the shape of the sub-tensor, the estimated processing performance of using the cache resource to calculate the sub-tensor is calculated. Then, according to the estimated processing performance of each type of cache resource in the calculation unit, the required cache resource type is selected from the various cache resources.

[0079] When the calculation process of a sub-tensor requires multiple types of cache resources, the various types of cache resources contained in the computing unit are combined to obtain multiple resource combinations that meet the calculation of the sub-tensor. For each resource combination, based on the shape of the sub-tensor and the attribute information of the various types of cache resources in the resource combination, the estimated processing performance when the sub-tensor is calculated using the resource combination is calculated. Then, according to the estimated processing performance of each resource combination, the required resource combination is selected from each resource combination.

[0080] When actually selecting a cache resource type, there may be multiple selection results, each of which corresponds to at least one cache resource type (ie, one type of cache resource may be selected, or a resource combination consisting of multiple types of cache resources may be selected).

[0081] At least one cache implementation rule is selected for each selection result. Specifically, at least one cache implementation rule is set in advance for each of the multiple cache resource types included in the computing unit, and each cache resource type is associated with the corresponding at least one cache implementation rule and saved.

[0082] In addition, various cache resources included in the computing unit are randomly combined to obtain multiple resource combinations included in the computing unit. At least one cache implementation rule is pre-set for each of the multiple resource combinations included in the computing unit, and the identifier of each resource combination is associated with the corresponding at least one cache implementation rule and saved.

[0083] For each selection result, based on the identifier of the cache resource type or resource combination in the selection result, at least one matching cache implementation rule is searched from various pre-saved cache implementation rules.

[0084] Each selection result is combined with a cache implementation rule to obtain a cache usage strategy.

[0085] For example, when the cache resource type is selected based on the shape of the sub-tensor and the cache configuration information of the computing unit, two selection results are obtained, namely, selection result 1 (cache resource type 1 and cache resource type 2) and selection result 2 (cache resource type 3).

[0086] Then, for selection result 1 (i.e., cache resource type 1 and cache resource type 2), two cache implementation rules are selected, namely, cache implementation rule 1 and cache implementation rule 2. Then, cache resource type 1 and cache resource type 2 can be combined with cache implementation rule 1 to obtain cache usage strategy 1. Cache resource type 1 and cache resource type 2 can be combined with cache implementation rule 2 to obtain cache usage strategy 2.

[0087] A cache implementation rule is selected for selection result 2 (ie, cache resource type 3), namely, cache implementation rule 3. Cache resource type 3 is combined with cache implementation rule 3 to obtain cache use strategy 3.

[0088] In summary, a total of three candidate cache usage strategies are obtained, namely cache usage strategy 1, cache usage strategy 2 and cache usage strategy 3.

[0089] In some embodiments, when implementing convolution calculations in different scenarios, the specific steps performed may also be different. Therefore, when selecting a cache usage strategy, in addition to considering the shape of the sub-tensor and the cache configuration information of the computing unit, the specific steps performed during the convolution calculation process may also be considered. In other words, based on the shape of the sub-tensor, the cache configuration information of the computing unit, and the steps in the convolution calculation, multiple corresponding cache usage strategies are obtained.

[0090] For example, in some scenarios, the data type of the input sub-tensor is BF16 (16-bit floating point number). After the sub-tensor is loaded from the video memory to the GMB, in order to ensure the calculation accuracy, the data type of the sub-tensor is converted from BF16 to FP32 (32-bit floating point number) and then calculated with the weight to obtain the FP32 calculation result. Then the FP32 calculation result is converted to the BF16 calculation result and output. In the above convolution calculation process, there are two data type conversion operations (BF16 to FP32, and FP32 to BF16). The results of these two data type conversions require additional allocation of cache resources (such as Workspace) for storage. Therefore, in this scenario, the convolution calculation process requires not only cache resources GMB, but also cache resources Workspace. Then, when selecting the cache usage strategy, the selected cache resource types include: GMB and Workspace; correspondingly, the cache implementation rules of the two cache resources GMB and Workspace are selected.

[0091] In other scenarios, the data type of the input sub-tensor is BF16. After the sub-tensor is loaded from the video memory to the GMB, the BF16 sub-tensor and weight are directly calculated to obtain the BF16 calculation result and output. In the above convolution calculation process, only the cache resource GMB is used. Therefore, when selecting the cache usage strategy, the selected cache resource type is: GMB; the cache implementation rules of the GMB cache resource are selected accordingly.

[0092] After obtaining multiple cache usage strategies, for each cache usage strategy, an estimated processing performance when the sub-tensor convolution is calculated using the cache usage strategy is calculated.

[0093] Step 2022: Based on the obtained multiple estimated processing performances, obtain a target cache strategy corresponding to the sub-tensor from multiple cache usage strategies.

[0094] Specifically, the expected processing performance refers to: the computation time required when the cache usage strategy is used to perform convolution calculations on the sub-tensor. The expected processing performance can be specifically characterized by the number of clock cycles. When the number of clock cycles is smaller, it means that the computation time required when the cache usage strategy is used to perform convolution calculations on the sub-tensor is shorter, that is, the computation efficiency is higher (the expected processing performance is also higher). When the number of clock cycles is larger, it means that the computation time required when the cache usage strategy is used to perform convolution calculations on the sub-tensor is longer, that is, the computation efficiency is lower (the expected processing performance is also lower).

[0095] After obtaining multiple estimated processing performances, the highest estimated processing performance (corresponding to the minimum number of clock cycles) is selected, and the cache usage strategy corresponding to the highest estimated processing performance is used as the target cache strategy corresponding to the sub-tensor.

[0096] For example, after obtaining cache usage strategy 1, cache usage strategy 2, and cache usage strategy 3, the number of clock cycles required for performing convolution calculations on sub-tensors using cache usage strategy 1 is calculated. The number of clock cycles required for performing convolution calculations on sub-tensors using other cache usage strategies can be obtained in the same way. The minimum number of clock cycles is selected from the three obtained numbers of clock cycles, and the cache usage strategy corresponding to the minimum number of clock cycles is used as the target cache strategy.

[0097] In some embodiments, the target cache strategies of the multiple sub-tensors are associated with the shape of the input tensor and saved in a configuration file corresponding to the roll operator. It should be noted that the above process of obtaining the target cache strategy is executed by a central processing unit (CPU) in a computer device.

[0098] During the operator execution phase (executed by the artificial intelligence chip in the computer device), the target cache strategies of multiple sub-tensors can be directly obtained from the configuration file. The multiple computing units in the artificial intelligence chip perform convolution calculations on the multiple computing units in parallel according to the target cache strategies of the multiple sub-tensors to obtain the calculation results.

[0099] In some embodiments, as described above, when the input tensor is segmented, if the segmentation dimensions used are different, the shapes of the corresponding sub-tensors obtained are also different. That is to say, for an input tensor of a shape, multiple segmentation methods can also be used for segmentation. Therefore, for each segmentation method, the implementation method described above can be used to obtain the corresponding target cache strategy, and the shape of the input tensor, each segmentation method, and the corresponding target cache strategy are associated and saved in the configuration file. Therefore, in the operator execution stage, the segmentation method of the input tensor can be selected according to actual needs, and then the corresponding target cache strategy is obtained from the configuration file according to the shape of the input tensor and the selected segmentation method, and the convolution calculation is performed on the input tensor according to the target cache strategy to obtain the calculation result.

[0100] In an embodiment of the present application, the input tensor is divided into multiple sub-tensors according to the shape of the input tensor and the number of computing units. According to the shape of each sub-tensor, multiple corresponding cache usage strategies are obtained, and based on each cache usage strategy, the estimated processing performance corresponding to the sub-tensor is calculated, so that the target cache strategy corresponding to the sub-tensor can be obtained from multiple cache usage strategies based on the obtained multiple estimated processing performances. Then, for input tensors of different shapes, the best cache usage strategy can be selected for convolution calculation, which can not only make full use of cache resources, but also improve the efficiency of convolution calculation, and this method can be generalized to any scenario, thereby optimizing the computing performance of the convolution operator in various scenarios.

[0101] In some embodiments, when the computing unit performs convolution calculations on a sub-tensor, the sub-tensor is further split into multiple data blocks (tiles), and then convolution calculations are performed on each data block in turn. When performing convolution calculations on each data block, multiple steps are involved. For example, data preloading steps (i.e., loading data blocks into on-chip cache), calculation steps (i.e., performing matrix multiplication calculations on data blocks and weights), data type conversion, etc. After the preloading of the current data block is completed, the calculation step is entered. At this time, the next data block will not be preloaded synchronously, but will wait until the entire convolution calculation process of the current data block is completed before starting to preload the next data block. Therefore, this solution will cause cache resources to be idle, thereby affecting the utilization of cache resources.

[0102] In view of this, in an embodiment of the present application, a pipeline configuration strategy is used to implement parallel calculation of multiple data blocks. Specifically, the cache resources are divided into multiple resource blocks, and one resource block corresponds to one pipeline. Each pipeline independently performs convolution calculation on a data block, and multiple pipelines can perform convolution calculation on multiple data blocks in parallel.

[0103] For example, the cache resources are divided into resource block 0 and resource block 1. After data block 0 is preloaded into resource block 0, data block 0 is calculated. At this time, data block 1 can be preloaded into resource block 1 synchronously, that is, the calculation step of data block 0 and the preloading step of data block 1 can be performed synchronously.

[0104] Accordingly, in the early stage of strategy selection, it is necessary not only to select a suitable cache usage strategy, but also to select a suitable pipeline configuration strategy. Specifically, based on the shape of a sub-tensor, after obtaining the corresponding multiple cache usage strategies, the following operations are performed for the multiple cache usage strategies: obtaining at least one pipeline configuration strategy corresponding to a cache usage strategy, and combining a cache usage strategy with at least one pipeline configuration strategy to obtain at least one corresponding candidate strategy group.

[0105] Specifically, for each cache resource type included in the computing unit, after setting at least one cache implementation rule for the cache resource type, at least one pipeline configuration strategy is pre-set for each cache implementation rule, and each cache implementation rule is associated with the corresponding at least one pipeline configuration strategy and saved.

[0106] In addition, for each resource combination included in the computing unit, after setting at least one cache implementation rule for the resource combination, at least one pipeline configuration strategy is pre-set for each cache implementation rule; and each cache implementation rule is associated with the corresponding at least one pipeline configuration strategy and saved.

[0107] Therefore, based on the shape of a sub-tensor, after obtaining the corresponding multiple cache usage strategies, for each cache usage strategy, the pre-saved pipeline configuration strategies are queried based on the cache implementation rules in the cache usage strategy to obtain at least one matching pipeline configuration strategy.

[0108] Different pipeline configuration strategies correspond to different cache resource segmentation methods. A cache usage strategy can be combined with a pipeline configuration strategy to obtain a candidate strategy group. A cache usage strategy corresponds to one or more candidate strategy groups.

[0109] When different candidate strategy groups are used to perform convolution calculations on sub-tensors, the processing performance obtained is also different. Therefore, in this application, for multiple cache usage strategies, the following operations are performed respectively: based on at least one candidate strategy group corresponding to a cache usage strategy, the estimated processing performance corresponding to the sub-tensor is calculated respectively. Each candidate strategy group corresponds to an estimated processing performance.

[0110] Based on the obtained multiple estimated processing performances, a target strategy group corresponding to the sub-tensor is obtained from the candidate strategy groups corresponding to the multiple cache usage strategies, and the target strategy group includes a target cache strategy and a corresponding pipeline configuration strategy.

[0111] In a specific implementation, after obtaining multiple expected processing performances, the highest expected processing performance (corresponding to the minimum number of clock cycles) is selected, and the candidate strategy group corresponding to the highest expected processing performance is used as the target strategy group corresponding to the sub-tensor.

[0112] For example, after obtaining cache usage strategy 1, cache usage strategy 2, and cache usage strategy 3, two pipeline configuration strategies are selected for cache usage strategy 1, namely, pipeline configuration strategy 1 and pipeline configuration strategy 2. Cache usage strategy 1 is combined with pipeline configuration strategy 1 to obtain candidate strategy group 1; cache usage strategy 1 is combined with pipeline configuration strategy 2 to obtain candidate strategy group 2.

[0113] A pipeline configuration strategy is selected for cache usage strategy 2, namely, pipeline configuration strategy 3. Cache usage strategy 2 and pipeline configuration strategy 3 are combined to obtain candidate strategy group 3.

[0114] A pipeline configuration strategy is selected for cache usage strategy 3, namely, pipeline configuration strategy 4. Cache usage strategy 3 and pipeline configuration strategy 4 are combined to obtain candidate strategy group 4.

[0115] Calculate the number of clock cycles required to perform convolution calculations on the sub-tensors using candidate strategy group 1. The same method can be used to obtain the number of clock cycles required to perform convolution calculations on the sub-tensors using other candidate strategy groups. Select the minimum number of clock cycles from the four obtained numbers of clock cycles, and use the candidate strategy group corresponding to the minimum number of clock cycles as the target strategy group.

[0116] In some embodiments, the target strategy groups of the plurality of sub-tensors are associated with the shapes of the input tensors and saved in a configuration file corresponding to the convolution operator. It should be noted that the above process of obtaining the target strategy group is executed by the CPU in the computer device.

[0117] During the operator execution stage (executed by the artificial intelligence chip in the computer device), the target strategy groups of multiple sub-tensors can be directly obtained from the configuration file. The multiple computing units in the artificial intelligence chip perform convolution calculations on the multiple computing units in parallel according to the target strategy groups of the multiple sub-tensors to obtain the calculation results.

[0118] In some implementations, when the input tensor is segmented, if the segmentation dimensions used are different, the shapes of the corresponding sub-tensors obtained are also different. That is to say, for an input tensor of a certain shape, multiple segmentation methods can also be used for segmentation. Therefore, for each segmentation method, the implementation method described above can be used to obtain the corresponding target strategy group, and the shape of the input tensor, each segmentation method, and the corresponding target strategy group are associated and saved in the configuration file. Therefore, in the operator execution stage, the segmentation method of the input tensor can be selected according to actual needs, and then the corresponding target strategy group is obtained from the configuration file according to the shape of the input tensor and the selected segmentation method, and the convolution calculation is performed on the input tensor according to the target strategy group to obtain the calculation result.

[0119] In an embodiment of the present application, multiple candidate strategy groups are selected based on the shape of the sub-tensor, and each candidate strategy group includes: a cache usage strategy and a pipeline configuration strategy. Then, based on each candidate strategy group, the estimated processing performance corresponding to the sub-tensor is calculated, and finally, based on the obtained multiple estimated processing performances, the target strategy group corresponding to the sub-tensor is obtained from the multiple candidate strategy groups. Then, for input tensors of different shapes, the best cache usage strategy and pipeline configuration strategy can be selected for convolution calculation, which not only greatly improves the efficiency of convolution calculation, but also makes full use of on-chip cache resources.

[0120] Based on the same technical concept, the embodiment of the present application provides a schematic diagram of the structure of a cache usage optimization device, such as Figure 4 As shown, the cache usage optimization device 400 includes:

[0121] A splitting module 401, configured to split the input tensor into a plurality of sub-tensors based on the shape of the input tensor and the number of computing units;

[0122] The strategy selection module 402 is used to perform the following operations on the multiple sub-tensors:

[0123] Based on the shape of a sub-tensor, obtain a corresponding plurality of cache usage strategies, and based on the plurality of cache usage strategies, respectively calculate an estimated processing performance corresponding to the sub-tensor;

[0124] Based on the obtained multiple estimated processing performances, a target cache strategy corresponding to the one sub-tensor is obtained from the multiple cache usage strategies.

[0125] Optionally, the segmentation module 401 is specifically used for:

[0126] The input tensor is split into multiple sub-tensors based on the shape of the input tensor, the number of computing units, and the splitting priorities of multiple dimensions of the input tensor.

[0127] Optionally, the strategy selection module 402 is specifically configured to:

[0128] Based on the shape of the one sub-tensor and the cache configuration information of the computing unit used to calculate the one sub-tensor, a corresponding plurality of cache usage strategies are obtained.

[0129] Optionally, the strategy selection module is further used to:

[0130] Based on the obtained multiple estimated processing performances, after obtaining the target cache strategy corresponding to the one sub-tensor from the multiple cache usage strategies, convolution calculation is performed on the one sub-tensor according to the target cache strategy to obtain a calculation result.

[0131] Optionally, the strategy selection module 402 is further configured to:

[0132] After obtaining multiple corresponding cache usage strategies based on the shape of a sub-tensor, the following operations are performed for the multiple cache usage strategies:

[0133] Acquire at least one pipeline configuration strategy corresponding to a cache usage strategy, and combine the cache usage strategy with the at least one pipeline configuration strategy to obtain at least one corresponding candidate strategy group;

[0134] The strategy selection module 402 is specifically used for:

[0135] For the multiple cache usage strategies, the following operations are performed respectively: based on at least one candidate strategy group corresponding to one cache usage strategy, the estimated processing performance corresponding to the one sub-tensor is calculated respectively.

[0136] Optionally, the strategy selection module 402 is specifically configured to:

[0137] Based on the obtained multiple estimated processing performances, a target strategy group corresponding to the one sub-tensor is obtained from the candidate strategy groups corresponding to the multiple cache usage strategies, and the target strategy group includes the target cache strategy and the corresponding pipeline configuration strategy.

[0138] Optionally, the strategy selection module 402 is further configured to:

[0139] Based on the obtained multiple estimated processing performances, after obtaining the target strategy group corresponding to the one sub-tensor from the candidate strategy groups corresponding to the multiple cache usage strategies, convolution calculation is performed on the one sub-tensor according to the target strategy group to obtain a calculation result.

[0140] In an embodiment of the present application, the input tensor is divided into multiple sub-tensors according to the shape of the input tensor and the number of computing units. According to the shape of each sub-tensor, multiple corresponding cache usage strategies are obtained, and based on each cache usage strategy, the estimated processing performance corresponding to the sub-tensor is calculated, so that the target cache strategy corresponding to the sub-tensor can be obtained from multiple cache usage strategies based on the obtained multiple estimated processing performances. Then, for input tensors of different shapes, the best cache usage strategy can be selected for convolution calculation, which can not only make full use of cache resources, but also improve the efficiency of convolution calculation, and this method can be generalized to any scenario, thereby optimizing the computing performance of the convolution operator in various scenarios.

[0141] Based on the same technical concept, the embodiment of the present application provides a computer device, such as Figure 5 As shown, it includes at least one artificial intelligence chip 100 and a memory 501 connected to the at least one artificial intelligence chip 100. The specific connection medium between the artificial intelligence chip 100 and the memory 501 is not limited in the embodiment of the present application. Figure 5 In the example, the artificial intelligence chip 100 and the memory 501 are connected via a bus. The bus can be divided into an address bus, a data bus, a control bus, etc.

[0142] In an embodiment of the present application, the memory 501 stores instructions that can be executed by at least one artificial intelligence chip 100. At least one artificial intelligence chip 100 can execute the steps of the above-mentioned cache usage optimization method by executing the instructions stored in the memory 501.

[0143] Among them, the artificial intelligence chip 100 is the control center of the computer device, and various interfaces and lines can be used to connect various parts of the computer device, and cache usage optimization can be achieved by running or executing instructions stored in the memory 501 and calling data stored in the memory 501. Optionally, the artificial intelligence chip 100 may include one or more processing units, and the artificial intelligence chip 100 may integrate an application processor and a modem processor, wherein the application processor mainly processes the operating system, user interface, and application programs, and the modem processor mainly processes wireless communications. It is understandable that the above-mentioned modem processor may not be integrated into the artificial intelligence chip 100. In some embodiments, the artificial intelligence chip 100 and the memory 501 can be implemented on the same chip, and in some embodiments, they can also be implemented separately on independent chips.

[0144] The artificial intelligence chip 100 can be a general-purpose processor, such as a digital signal processor, an application-specific integrated circuit (ASIC), a field programmable gate array or other programmable logic device, a discrete gate or transistor logic device, a discrete hardware component, and can implement or execute the methods, steps, and logic block diagrams disclosed in the embodiments of the present application. A general-purpose processor can be a microprocessor or any conventional processor, etc. The steps of the method disclosed in the embodiments of the present application can be directly embodied as a hardware processor, or can be executed by a combination of hardware and software modules in the processor.

[0145] Memory 501, as a non-volatile computer-readable storage medium, can be used to store non-volatile software programs, non-volatile computer executable programs and modules. Memory 501 may include at least one type of storage medium, such as flash memory, hard disk, multimedia card, card-type memory, random access memory (Random Access Memory, RAM), static random access memory (Static Random Access Memory, SRAM), programmable read-only memory (Programmable Read Only Memory, PROM), read-only memory (Read Only Memory, ROM), electrically erasable programmable read-only memory (Electrically Erasable Programmable Read-Only Memory, EEPROM), magnetic storage, disk, optical disk, etc. Memory 501 is any other medium that can be used to carry or store a desired program code in the form of an instruction or data structure and can be accessed by a computer device, but is not limited thereto. The memory 501 in the embodiment of the present application can also be a circuit or any other device that can realize a storage function, for storing program instructions and / or data.

[0146] Based on the same inventive concept, an embodiment of the present application provides a computer-readable storage medium storing a computer program executable by a computer device. When the computer program runs on the computer device, the computer device executes the steps of the above-mentioned cache usage optimization method.

[0147] Based on the same inventive concept, an embodiment of the present application provides a computer program product, which includes a computer program stored on a computer-readable storage medium, and the computer program includes program instructions. When the program instructions are executed by a computer device, the computer device executes the steps of the above-mentioned cache usage optimization method.

[0148] It will be appreciated by those skilled in the art that embodiments of the present invention may be provided as methods or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0149] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer device or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0150] These computer program instructions may also be stored in a computer readable memory capable of directing a computer device or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer readable memory produce a manufactured product including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0151] These computer program instructions can also be loaded onto a computer device or other programmable data processing device so that a series of operation steps are executed on the computer device or other programmable device to produce a process implemented by the computer device, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0152] Although the preferred embodiments of the present invention have been described, those skilled in the art may make other changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the present invention.

[0153] Obviously, those skilled in the art can make various changes and modifications to the present invention without departing from the spirit and scope of the present invention. Thus, if these modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention is also intended to include these modifications and variations.

Claims

1. A cache usage optimization method, It is characterized in that include: Splitting the input tensor into a plurality of sub-tensors based on the shape of the input tensor and the number of computing units; For the multiple sub-tensors, the following operations are performed respectively: Based on the shape of a sub-tensor, obtain a corresponding plurality of cache usage strategies, and based on the plurality of cache usage strategies, respectively calculate an estimated processing performance corresponding to the sub-tensor; Based on the obtained multiple estimated processing performances, a target cache strategy corresponding to the one sub-tensor is obtained from the multiple cache usage strategies.

2. The method according to claim 1, It is characterized in that The step of dividing the input tensor into a plurality of sub-tensors based on the shape of the input tensor and the number of computing units includes: The input tensor is split into multiple sub-tensors based on the shape of the input tensor, the number of computing units, and the splitting priorities of multiple dimensions of the input tensor.

3. The method according to claim 1, It is characterized in that The method of obtaining corresponding multiple cache usage strategies based on the shape of a sub-tensor includes: Based on the shape of the one sub-tensor and the cache configuration information of the computing unit used to calculate the one sub-tensor, a corresponding plurality of cache usage strategies are obtained.

4. The method according to claim 1, It is characterized in that After obtaining the target cache strategy corresponding to the one sub-tensor from the multiple cache usage strategies based on the obtained multiple estimated processing performances, the method further includes: According to the target cache strategy, a convolution calculation is performed on the one sub-tensor to obtain a calculation result.

5. The method according to any one of claims 1 to 4, It is characterized in that After obtaining the corresponding multiple cache usage strategies based on the shape of a sub-tensor, the method further includes: For the multiple cache usage strategies, the following operations are respectively performed: obtaining at least one pipeline configuration strategy corresponding to a cache usage strategy, and combining the one cache usage strategy with the at least one pipeline configuration strategy to obtain at least one corresponding candidate strategy group; The calculating, based on the multiple cache usage strategies, respectively the estimated processing performance corresponding to the one sub-tensor, comprises: For the multiple cache usage strategies, the following operations are performed respectively: based on at least one candidate strategy group corresponding to one cache usage strategy, the estimated processing performance corresponding to the one sub-tensor is calculated respectively.

6. The method according to claim 5, It is characterized in that The obtaining, based on the obtained multiple estimated processing performances, a target cache strategy corresponding to the one sub-tensor from the multiple cache usage strategies comprises: Based on the obtained multiple estimated processing performances, a target strategy group corresponding to the one sub-tensor is obtained from the candidate strategy groups corresponding to the multiple cache usage strategies, and the target strategy group includes the target cache strategy and the corresponding pipeline configuration strategy.

7. The method according to claim 6, It is characterized in that After obtaining the target strategy group corresponding to the one sub-tensor from the candidate strategy groups corresponding to the multiple cache usage strategies based on the obtained multiple estimated processing performances, the method further includes: According to the target strategy group, a convolution calculation is performed on the one sub-tensor to obtain a calculation result.

8. A computer device comprising a memory, an artificial intelligence chip, and a computer program stored in the memory and executable on the artificial intelligence chip, It is characterized in that When the artificial intelligence chip executes the computer program, the steps of the method as claimed in any one of claims 1 to 7 are implemented.

9. A computer-readable storage medium, It is characterized in that It stores a computer program executable by a computer device. When the computer program is run on the computer device, the computer device executes the steps of the method according to any one of claims 1 to 7.

10. A computer program product, It is characterized in that The computer program product comprises a computer program stored on a computer-readable storage medium, wherein the computer program comprises program instructions, and when the program instructions are executed by a computer device, the computer device is caused to execute the steps of the method according to any one of claims 1 to 7.