An index conversion method and device based on Ascend AI processor

By converting index information in Ascend AI processor, the calculation speed reduction caused by tensor data layout format conversion is solved, and the corresponding data is quickly indexed without changing the data layout format, thereby improving the Calculate the speed.

CN114281874BActive Publication Date: 2024-12-10PEKING UNIV +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202111373725.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-11-19
Publication Date
2024-12-10
Estimated Expiration
2041-11-19

AI Technical Summary

Technical Problem

The conversion of the tensor data arrangement format in the Ascend AI processor results in a slower calculation speed because it takes a lot of time to match the data arrangement format of the operator.

Method used

By obtaining the index information to be converted corresponding to the operator and the source data layout format of the tensor, converting the index information to be converted according to the source data layout format, obtaining the target index information that matches the source data layout format, so that the change is not done In the case of tensor data layout format, the data directly indexed to the tensor.

Benefits of technology

The calculation speed of operators is improved because the conversion of index information only involves simple numerical operations, avoiding time consumption caused by changing the data layout format.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114281874B_ABST
    Figure CN114281874B_ABST
Patent Text Reader

Abstract

The present invention relates to the field of data indexing, and specifically to an index conversion method and device based on an Ascend AI processor. The present invention converts the index information of an operator according to the data arrangement format of a tensor, so that the index information after the conversion matches the data arrangement format of the tensor. Since the conversion of the index information only involves simple operations on numbers, the corresponding data can still be indexed in the tensor through the converted index information without changing the data arrangement format of the tensor. Since the present invention does not involve changing the data arrangement format of the tensor, the time consumed by changing the data arrangement format of the tensor is avoided, thereby improving the calculation speed of the operator.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of data indexing, and more particularly to an index conversion method and device based on an Ascend AI processor. Background Art

[0002] Operators are computing units in deep learning algorithms. Common operators include convolution, matrix multiplication, weight summation, aggregation operators, etc. The data arrangement format (data arrangement format) of a tensor (a space used to store data) refers to the physical storage order of data. In the Ascend AI processor, in order to improve computing performance, the data arrangement format of the tensor is often converted to a data arrangement format called "Huawei's self-developed data arrangement format"; when the tensor is converted to Huawei's self-developed data arrangement format, the data arrangement format of the tensor before the conversion is called the "source data arrangement format". When the data arrangement format of the tensor is different from the data arrangement format that the operator can operate on, the operator cannot obtain the data in the tensor through its own index information. For example Figure 2 As shown, the prior art is to insert a conversion algorithm before the operator, and the conversion algorithm is used to convert the data arrangement format of the tensor, that is, to convert the physical storage order of the data in the tensor, so that the data arrangement format of the converted tensor matches the data arrangement format that the operator can operate, and then the operator can obtain the data in the tensor through its own index information. However, since a large amount of data is involved in the tensor, if its data arrangement format is converted, it will consume a lot of time, thereby reducing the calculation speed of the operator.

[0003] In summary, the conversion method in the prior art reduces the calculation speed.

[0004] Therefore, the prior art still needs to be improved and enhanced. Summary of the invention

[0005] In order to solve the above technical problems, the present invention provides an index conversion method and device based on the Ascend AI processor, which solves the problem that the conversion method in the prior art reduces the calculation speed.

[0006] To achieve the above object, the present invention adopts the following technical solutions:

[0007] In a first aspect, the present invention provides an index conversion method based on the Ascend AI processor, wherein the index information to be converted corresponding to the operator and the source data arrangement format corresponding to the tensor are obtained, and the source data arrangement format matches the Ascend AI processor;

[0008] According to the source data arrangement format, the to-be-converted index information is converted to obtain target index information matching the source data arrangement format;

[0009] According to the target index information, the data in the tensor is input into the operator.

[0010] In one implementation, converting the to-be-converted index information according to the source data arrangement format to obtain target index information matching the source data arrangement format includes:

[0011] According to the source data arrangement format, the source data dimension information corresponding to the tensor is obtained;

[0012] The index information to be converted is converted according to the source data dimension information to obtain target index information matching the source data arrangement format.

[0013] In one implementation, converting the to-be-converted index information according to the source data arrangement format to obtain target index information matching the source data arrangement format includes:

[0014] According to the source data arrangement format, the source data dimension information corresponding to the tensor is obtained;

[0015] According to the operator, dimension information corresponding to the operator is obtained;

[0016] According to the source data dimension information, the dimension information corresponding to the operator is converted to obtain the dimension information after conversion;

[0017] The index information to be converted is converted according to the dimension information after conversion to obtain target index information matching the arrangement format of the source data.

[0018] In one implementation, converting the dimension information corresponding to the operator according to the source data dimension information to obtain the converted dimension information includes:

[0019] According to the source data dimension information, obtain the block information corresponding to the tensor contained in the source data dimension information;

[0020] According to the block information, the dimension information corresponding to the operator is converted to obtain the dimension information after conversion.

[0021] In one implementation, converting the index information to be converted according to the converted dimension information to obtain target index information matching the source data arrangement format includes:

[0022] According to the operator, an aggregation operator in the operator is obtained;

[0023] According to the aggregation operator, aggregation dimension information corresponding to the aggregation operator is obtained;

[0024] According to the index information to be converted, obtaining an index sequence to be converted in the index information to be converted that corresponds to the aggregation dimension information;

[0025] Arranging the to-be-converted index sequence according to a set order to obtain the to-be-converted index sequence in a one-dimensional coordinate;

[0026] According to the dimension information after the conversion, obtaining the aggregate dimension information after the conversion in the dimension information after the conversion;

[0027] According to the aggregate dimension information after conversion, the to-be-converted index sequence under the one-dimensional coordinate in the to-be-converted index information is converted to obtain target index information matching the source data arrangement format.

[0028] In one implementation, converting the to-be-converted index sequence under the one-dimensional coordinates in the to-be-converted index information according to the converted aggregate dimension information to obtain target index information matching the source data arrangement format includes:

[0029] According to the to-be-converted index sequence under the one-dimensional coordinate, obtaining the to-be-converted index number contained in the to-be-converted index sequence;

[0030] According to the index number to be converted and the aggregation dimension information, coordinate information of the index number to be converted under the aggregation dimension information is obtained, and the coordinate information of the index number to be converted under the aggregation dimension information is recorded as the coordinate to be converted;

[0031] The coordinates to be converted are converted according to the aggregated dimension information after conversion, so as to obtain target coordinate information in the target index information that matches the source data arrangement format.

[0032] In one implementation, obtaining the coordinate information of the index number to be converted under the aggregate dimension information according to the index number to be converted and the aggregate dimension information, and recording the coordinate information of the index number to be converted under the aggregate dimension information as the coordinate to be converted includes:

[0033] According to the aggregated dimension information, obtaining the dimension size in the aggregated dimension information;

[0034] The index number to be converted is converted according to the dimension size to obtain the coordinate to be converted.

[0035] In one implementation, converting the index number to be converted according to the dimension size to obtain the coordinate to be converted includes:

[0036] According to the aggregated dimension information, obtaining a first dimension, a second dimension, a third dimension and a fourth dimension in the aggregated dimension information which are arranged in sequence;

[0037] According to the dimensional dimensions, a first dimension, a second dimension, a third dimension, and a fourth dimension of the dimensional dimensions are obtained;

[0038] Calculate the remainder of the index number to be converted with respect to the fourth dimension to obtain a first remainder, and record the first remainder as the subscript of the index number to be converted in the fourth dimension;

[0039] Divide the index number to be converted by the fourth dimension and then find the remainder with respect to the third dimension to obtain a second remainder, and record the second remainder as the subscript of the index number to be converted in the third dimension;

[0040] Divide the index number to be converted by the fourth dimension and the third dimension in sequence, and then find the remainder with respect to the second dimension to obtain a third remainder, and record the third remainder as the subscript of the index number to be converted in the second dimension;

[0041] Divide the index number to be converted by the fourth dimension, the third dimension, and the second dimension in sequence, and then find the remainder with respect to the first dimension to obtain a fourth remainder, and record the fourth remainder as the subscript of the index number to be converted in the first dimension;

[0042] The coordinates to be converted are obtained according to the subscript in the first dimension, the subscript in the second dimension, the subscript in the third dimension, and the subscript in the fourth dimension.

[0043] In one implementation, the to-be-converted coordinates are converted according to the converted aggregate dimension information to obtain target coordinate information in the target index information that matches the source data arrangement format, including:

[0044] According to the converted aggregation dimension information, obtaining each aggregation dimension size corresponding to the converted aggregation dimension information;

[0045] Each subscript in the coordinate to be converted is converted according to each of the aggregation dimensions to obtain the target coordinate information.

[0046] In one implementation, converting each subscript in the coordinates to be converted according to each of the aggregation dimensions to obtain the target coordinate information includes:

[0047] Using each of the aggregated dimensions as a weight to perform weighted calculation on each subscript in the coordinates to be converted, to obtain a calculation result;

[0048] The target coordinate information is obtained according to the calculation result.

[0049] In a second aspect, an embodiment of the present invention further provides a device for an index conversion method based on an Ascend AI processor, wherein the device includes the following components:

[0050] The information collection module is used to obtain the index information to be converted corresponding to the operator and the source data arrangement format corresponding to the tensor;

[0051] A conversion module, used to convert the index information to be converted according to the source data arrangement format to obtain target index information matching the source data arrangement format;

[0052] A data indexing module is used to input the data in the tensor into the operator according to the target index information.

[0053] In a third aspect, an embodiment of the present invention further provides a terminal device, wherein the terminal device includes a memory, a processor, and an index conversion program based on an Ascend AI processor stored in the memory and executable on the processor, and when the processor executes the index conversion program based on the Ascend AI processor, the steps of the above-mentioned index conversion method based on the Ascend AI processor are implemented.

[0054] In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium, on which an index conversion program based on an Ascend AI processor is stored. When the index conversion program based on an Ascend AI processor is executed by a processor, the steps of the above-mentioned index conversion method based on an Ascend AI processor are implemented.

[0055] Beneficial effects: The present invention converts the index information of the operator according to the data arrangement format of the tensor, so that the converted index information matches the data arrangement format of the tensor. Since the conversion of the index information only involves simple operations on numbers, the corresponding data in the tensor can still be indexed through the converted index information without changing the data arrangement format of the tensor. Since the present invention does not involve changing the data arrangement format of the tensor, the time consumed by changing the data arrangement format of the tensor is avoided, thereby improving the calculation speed of the operator. BRIEF DESCRIPTION OF THE DRAWINGS

[0056] Figure 1 It is the overall flow chart of the present invention;

[0057] Figure 2 A flow chart of the prior art;

[0058] Figure 3 This is the flow chart of the Gather operator. DETAILED DESCRIPTION

[0059] The following is a clear and complete description of the technical solution of the present invention in combination with the embodiments and the accompanying drawings. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0060] Research has found that operators are computing units in deep learning algorithms. Common operators include convolution, matrix multiplication, weight summation, aggregation operators, etc. The data arrangement format of a tensor (a space used to store data) refers to the physical storage order of data. When the data arrangement format of a tensor is different from the data arrangement format that an operator can operate on, the operator cannot obtain the data in the tensor through its own index information. Figure 2 As shown, the prior art is to insert a conversion algorithm before the operator, and the conversion algorithm is used to convert the data arrangement format of the tensor, that is, to convert the physical storage order of the data in the tensor, so that the data arrangement format of the converted tensor matches the data arrangement format that the operator can operate, and then the operator can obtain the data in the tensor through its own index information. However, since a large amount of data is involved in the tensor, if its data arrangement format is converted, it will consume a lot of time, thereby reducing the calculation speed of the operator.

[0061] In order to solve the above technical problems, the present invention provides an index conversion method and device based on the Ascend AI processor, which solves the problem that the conversion method in the prior art reduces the calculation speed. In the specific implementation, the index information to be converted corresponding to the operator and the source data arrangement format corresponding to the tensor are obtained; according to the source data arrangement format, the index information to be converted is converted to obtain the target index information matching the source data arrangement format; according to the target index information, the data in the index tensor is indexed into the operator.

[0062] For example, when the data arrangement format of the tensor is a four-dimensional matrix, and the matrix that the operator can operate is two-dimensional, then the index information corresponding to the operator is also two-dimensional. The two-dimensional index information cannot find the corresponding data in the four-dimensional matrix. This embodiment converts the two-dimensional index information into a subscript in the four-dimensional matrix, and the converted index information can find the corresponding data in the four-dimensional matrix. The conversion of the two-dimensional index information into the four-dimensional index information in this embodiment only involves simple data operations. Therefore, compared with the time spent on rearranging the data arrangement format of the tensor in the prior art, the present invention can improve the calculation speed.

[0063] Exemplary Methods

[0064] An index conversion method based on the Ascend AI processor of this embodiment can be applied to a terminal device. Figure 1 As shown in , the index conversion method based on the Ascend AI processor specifically includes the following steps:

[0065] S100, obtaining the to-be-converted index information corresponding to the operator and the source data arrangement format corresponding to the tensor.

[0066] The operator in this embodiment can be an aggregation operator (Gather operator). The Gather operator has three inputs, namely input_params (input data), input_indices (index) and axis (given axis); there is one output tensor, namely outputs. The function of the Gather operator is to extract slices from the input data (input_params) according to the given axis (specified by the axis parameter) and index (input_indices). In this embodiment, the Gather operator needs to be modified to obtain the CusGather operator (custom aggregation operator). The process of obtaining the CusGather operator from the Gather operator is as follows:

[0067] Rewrite the registration information of the Gather operator and add the Input_params parameter to support data arrangement formats such as FRACTAL_Z, FRACTAL_NZ, and NC1HWC0. FRACTAL_Z, FRACTAL_NZ, and NC1HWC0 are the corresponding data arrangement formats in the Ascend AI processor.

[0068] Modify the InferShape function in the Gather prototype definition so that the output shape (dimensional size) of the CusGather operator is equal to the shape of input_indices_1d_ori (the index number of subsequent conversion in this example).

[0069] The Ascend AI processor in this embodiment has efficient computing capabilities, but the tensors involved in the calculation are all in data arrangement formats such as FRACTAL_Z, FRACTAL_NZ, and NC1HWC0, and the data arrangement formats of the operators are different from the above arrangement formats, so the arrangement order needs to be converted.

[0070] The source data arrangement format corresponding to the tensor in this embodiment is FRACTAL_NZ, which is a data arrangement format used for matrix multiplication. The ori_shape (the size of the original data arrangement format) of the data must be two-dimensional, and the ori_format (that is, the original data arrangement format) is ND. Assuming ori_shape is (M, N), the shape is (N1, M1, M0, N0). Among them, M0 and N0 are related to the hardware architecture. When the data type is float16, M0=N0=16. The conversion process from ND to FRACTAL_NZ is: tensor.reshape([M1,M0,N1,N0]).transpose([2,0,1,3]).

[0071] For example, the following example illustrates the process of extracting data using the Gather operator:

[0072] make

[0073]

[0074] input_indices = [1, 2], axis = 1 (data is extracted according to the columns of the matrix, axis = 0 means data is extracted according to the rows of the matrix).

[0075] The Gather operator slices the columns, i.e. selects the corresponding columns according to input_indices. Since input_indices = [1,2], the Gather operator finally outputs the first and second columns:

[0076]

[0077] S200, converting the index information to be converted according to the source data arrangement format to obtain target index information matching the source data arrangement format.

[0078] In this embodiment, the index information to be converted is composed of input_indices and axis of the Gather operator. Step S200 includes the following steps S201, S202, S203, and S204:

[0079] S201, obtaining source data dimension information corresponding to the tensor according to the source data arrangement format.

[0080] In this embodiment, when the source data arrangement format of the tensor is FRACTAL_NZ, the source data dimension information corresponding to the tensor is four-dimensional, and the dimension size is (2, 1, 8, 8).

[0081] S202: According to the operator, obtain dimension information corresponding to the operator.

[0082] The operator in this embodiment is a Gather operator, and the dimension size of the Gather operator may be (8, 16), so the Gather operator in this embodiment is a two-dimensional matrix.

[0083] S203, converting the dimension information corresponding to the operator according to the source data dimension information to obtain the dimension information after conversion.

[0084] Step S203 includes the following process: according to the source data dimension information, obtaining the block information corresponding to the tensor contained in the source data dimension information; according to the block information, converting the dimension information corresponding to the operator to obtain the dimension information after conversion.

[0085] For example, when the source data dimension information corresponds to FRACTAL_NZ, and the dimension size of FRACTAL_NZ is (2,1,8,8), the block information is an 8x8 matrix, and (8,16) becomes (1,8,2,8) after conversion.

[0086] S204: convert the index information to be converted according to the converted dimension information to obtain target index information matching the source data arrangement format.

[0087] When the index information of the Gather operator is converted in this embodiment, step S204 includes the following steps S2041, S2042, S2043, S2044, S2045, and S2046:

[0088] S2041: According to the operator, obtain an aggregation operator (Gather operator) in the operator.

[0089] This embodiment may be a Gather operator.

[0090] S2042: According to the aggregation operator, obtain aggregation dimension information corresponding to the aggregation operator.

[0091] In this embodiment, the aggregation dimension information corresponding to the aggregation operator may be (8, 16) or other dimension information.

[0092] S2043: Obtain, according to the index information to be converted, a sequence of indexes to be converted in the index information to be converted that corresponds to the aggregation dimension information.

[0093] For example, when the input tensor of the Gather operator is

[0094] The index information to be converted can be input_indices = [1, 2], axis = 1, then the index sequence to be converted is the second and third columns sorted by column (the subscript starts from 0), that is,

[0095] S2044: Arrange the index sequence to be converted according to a set order to obtain the index sequence to be converted in a one-dimensional coordinate.

[0096] In this embodiment, the sequence to be converted is sorted according to the order of the one-dimensional coordinates. The index sequence to be converted under the one-dimensional coordinates of the above input tensor is [1, 2, 5, 6, 9, 10].

[0097] S2045: Obtain the aggregated dimension information after the conversion in the dimension information after the conversion according to the dimension information after the conversion.

[0098] The operator of this embodiment is an aggregation operator (Gather operator), and the dimension information after conversion corresponding to the Gather operator is also aggregated dimension information.

[0099] S2046, according to the aggregate dimension information after conversion, convert the index sequence to be converted under the one-dimensional coordinates in the index information to be converted to obtain target index information matching the source data arrangement format, including: according to the index sequence to be converted under the one-dimensional coordinates, obtain the index number to be converted contained in the index sequence to be converted; according to the index number to be converted and the aggregate dimension information, obtain the coordinate information of the index number to be converted under the aggregate dimension information, and record the coordinate information of the index number to be converted under the aggregate dimension information as the coordinate to be converted; according to the aggregate dimension information after conversion, convert the coordinate to be converted to obtain the target coordinate information in the target index information matching the source data arrangement format.

[0100] Among them, according to the index number to be converted and the aggregation dimension information, the specific process of obtaining the coordinate information of the index number to be converted under the aggregation dimension information is as follows: according to the aggregation dimension information, obtain the first dimension, the second dimension, the third dimension and the fourth dimension arranged in sequence in the aggregation dimension information; according to the dimensional size, obtain the first dimension size, the second dimension size, the third dimension size and the fourth dimension size in the dimensional size; calculate the remainder of the index number to be converted with respect to the fourth dimension size to obtain a first remainder, and record the first remainder as the subscript of the index number to be converted in the fourth dimension; divide the index number to be converted by the fourth dimension size and then calculate the remainder with respect to the third dimension size to obtain a second remainder, and record the first remainder as the subscript of the index number to be converted in the fourth dimension; calculate the remainder of the third dimension size after dividing the fourth dimension size by the index number to be converted The second remainder is recorded as the subscript of the index number to be converted in the third dimension; the index number to be converted is divided by the fourth dimension and the third dimension in sequence, and then the remainder is calculated with respect to the second dimension to obtain a third remainder, and the third remainder is recorded as the subscript of the index number to be converted in the second dimension; the index number to be converted is divided by the fourth dimension, the third dimension, and the second dimension in sequence, and then the remainder is calculated with respect to the first dimension to obtain a fourth remainder, and the fourth remainder is recorded as the subscript of the index number to be converted in the first dimension; the coordinate to be converted is obtained according to the subscript in the first dimension, the subscript in the second dimension, the subscript in the third dimension, and the subscript in the fourth dimension.

[0101] S300, inputting the data in the tensor into the operator according to the target index information.

[0102] After the index information to be converted is converted in step S200, target index information is obtained, and the target index information matches the data arrangement format of the tensor. The Gather operator of this embodiment can directly extract data from the tensor according to the target index information.

[0103] For example, the overall process of the method of the present invention is described by taking the Gather operator and the input tensor as input_params (input data) of the Ascend AI processor as an example:

[0104] like Figure 3 As shown, the index information conversion algorithm of the present invention is inserted to convert the index information that does not match the input to obtain the converted index information. The data in the tensor is indexed into the Gather operator according to the converted index information, and the Gather operator performs calculations and outputs the calculation results.

[0105] The detailed process of the present invention is described below with specific data:

[0106] The shape of the input tensor input_params is equal to (2,1,8,8). The data format of input_params is arranged as follows:

[0107]

[0108] The shape of input_params_ori (input_params_ori represents the tensor after input_params is converted to the original data arrangement format) that can be processed by the Gather operator is equal to (8,16) and is arranged as follows:

[0109]

[0110]

[0111] The data arrangement of input_params is FRACTAL_NZ, the original data format of input_params is ND, and the tensor corresponding to the original data arrangement format is input_params_ori. Let the input parameter input_indices of the Gather operator be equal to [1,3,4], and axis be equal to 1. The input_indices and axis parameters are both based on the original data arrangement format. Therefore, using the method in the present invention, the input_indices and axis parameters are converted into the target index information corresponding to the FRACTAL_NZ data arrangement format.

[0112] Step 1: Based on the index information to be converted: input_indices is equal to [1, 3, 4], axis is equal to 1, and the index sequence to be converted is obtained:

[0113] [1,3,4,17,19,20,33,35,36,49,51,52,65,67,68,81,83,84,97,99,100,113,115,116] (arrange input_params_ori from small to large according to the one-dimensional coordinates to get the index sequence).

[0114] Step 2: Then, according to the shape of input_params_ori being equal to (2,1,8,8), each sequence number in the conversion index sequence is converted respectively, where (2,1,8,8) is the dimension information of input_params_ori, 2,1,8,8 are the sizes of each dimension respectively, let n=8, c=16, this embodiment takes sequence number 65 as an example, and other sequence numbers are converted in the same way:

[0115] 65%c=1, 65%n=4, so the multidimensional subscript of the serial number 65 after conversion is (4, 1).

[0116] Step 3: Convert (8,16) based on (2,1,8,8), where (2,1,8,8) is the source data dimension information, and (8,16) is the dimension information corresponding to the Gather operator, to obtain the dimension information after conversion. The specific process is as follows:

[0117] (8,16) needs to be converted. The block information in (2,1,8,8) is 8x8. The 8 in (8,16) is 1x8, and 16 is 2x8. Therefore, (8,16) becomes (1,8,2,8) after conversion.

[0118] Step 4, transform (4, 1) according to (1, 8, 2, 8): the 1 in (4, 1) modulo the rightmost 8 in (1, 8, 2, 8) is 1, and the 4 modulo the 2 in (1, 8, 2, 8) is 0. Therefore, (4, 1) is transformed to (0, 4, 0, 1). Then transpose the second 0 to the front of the first 0 to become (0, 0, 4, 1), and (1, 8, 2, 8) becomes (2, 1, 8, 8).

[0119] Step 5: 0*(1*8*8)+0*(8*8)+4*(8)+1*(1)=33

[0120] In the above input_params_ori, it can be seen that the data with serial number 65 marked with a box is 1, and from the above input_params, it can also be seen that the data with subscript 33 marked with a box is also 1, so the serial number conversion in this embodiment is correct.

[0121] The ImageNet2012 data set and the ResNet50-seng model were used for testing, and the test results are shown in the table below. It can be seen from the table below that after using the optimization method of the present invention, the calculation time of the Gather operator is shortened to 58.55% (22.36 / 38.19=58.55%) before optimization.

[0122]

[0123] In summary, the present invention converts the index information of the operator according to the data arrangement format of the tensor, so that the index information after the conversion matches the data arrangement format of the tensor. Since the conversion of the index information only involves simple operations on numbers, the corresponding data can still be indexed in the tensor through the converted index information without changing the data arrangement format of the tensor. Since the present invention does not involve changing the data arrangement format of the tensor, the time consumed by changing the data arrangement format of the tensor is avoided, thereby improving the calculation speed of the operator.

[0124] Exemplary Devices

[0125] This embodiment also provides a device for an index conversion method based on an Ascend AI processor, and the device includes the following components:

[0126] The information collection module is used to obtain the index information to be converted corresponding to the operator and the source data arrangement format corresponding to the tensor;

[0127] A conversion module, used to convert the index information to be converted according to the source data arrangement format to obtain target index information matching the source data arrangement format;

[0128] A data indexing module is used to input the data in the tensor into the operator according to the target index information.

[0129] Based on the above embodiments, the present invention also provides a terminal device, which includes a memory, a processor, and an index conversion program based on an Ascend AI processor stored in the memory and executable on the processor. When the processor executes the index conversion program based on the Ascend AI processor, the steps of the above-mentioned index conversion method based on the Ascend AI processor are implemented.

[0130] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided by the present invention can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).

[0131] In summary, the present invention discloses an index conversion method and device based on Ascend AI processor, the method comprising: obtaining the index information to be converted corresponding to the operator and the source data arrangement format corresponding to the tensor; converting the index information to be converted according to the source data arrangement format to obtain the target index information matching the source data arrangement format; inputting the data in the tensor into the operator according to the target index information. The present invention only involves simple operations on numbers in converting index information, which improves the calculation speed of the operator.

[0132] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. An index conversion method based on Ascend AI processor, characterized in that: include: Get the index information to be converted corresponding to the operator and the source data arrangement format corresponding to the tensor; According to the source data arrangement format, the to-be-converted index information is converted to obtain target index information matching the source data arrangement format; According to the target index information, input the data in the tensor into the operator; The converting the index information to be converted according to the source data arrangement format to obtain target index information matching the source data arrangement format includes: According to the source data arrangement format, the source data dimension information corresponding to the tensor is obtained; According to the operator, dimension information corresponding to the operator is obtained; According to the source data dimension information, the dimension information corresponding to the operator is converted to obtain the dimension information after conversion; The index information to be converted is converted according to the dimension information after conversion to obtain target index information matching the arrangement format of the source data.

2. The index conversion method based on Ascend AI processor according to claim 1, characterized in that: The converting the index information to be converted according to the source data arrangement format to obtain target index information matching the source data arrangement format includes: According to the source data arrangement format, the source data dimension information corresponding to the tensor is obtained; The index information to be converted is converted according to the source data dimension information to obtain target index information matching the source data arrangement format.

3. The index conversion method based on Ascend AI processor according to claim 1, characterized in that: The converting the dimension information corresponding to the operator according to the source data dimension information to obtain the converted dimension information includes: According to the source data dimension information, obtain the block information corresponding to the tensor contained in the source data dimension information; According to the block information, the dimension information corresponding to the operator is converted to obtain the dimension information after conversion.

4. The index conversion method based on Ascend AI processor according to claim 1, characterized in that: The step of converting the index information to be converted according to the converted dimension information to obtain target index information matching the source data arrangement format includes: According to the operator, an aggregation operator in the operator is obtained; According to the aggregation operator, aggregation dimension information corresponding to the aggregation operator is obtained; According to the index information to be converted, obtaining an index sequence to be converted in the index information to be converted that corresponds to the aggregation dimension information; Arranging the to-be-converted index sequence according to a set order to obtain the to-be-converted index sequence in a one-dimensional coordinate; According to the dimension information after the conversion, obtaining the aggregate dimension information after the conversion in the dimension information after the conversion; According to the aggregate dimension information after conversion, the to-be-converted index sequence under the one-dimensional coordinate in the to-be-converted index information is converted to obtain target index information matching the source data arrangement format.

5. The index conversion method based on Ascend AI processor according to claim 4, characterized in that: The step of converting the index sequence to be converted under the one-dimensional coordinates in the index information to be converted according to the converted aggregate dimension information to obtain target index information matching the source data arrangement format includes: According to the to-be-converted index sequence under the one-dimensional coordinate, obtaining the to-be-converted index number contained in the to-be-converted index sequence; According to the index number to be converted and the aggregation dimension information, coordinate information of the index number to be converted under the aggregation dimension information is obtained, and the coordinate information of the index number to be converted under the aggregation dimension information is recorded as the coordinate to be converted; The coordinates to be converted are converted according to the aggregated dimension information after conversion, so as to obtain target coordinate information in the target index information that matches the source data arrangement format.

6. The index conversion method based on Ascend AI processor according to claim 5, characterized in that: The step of obtaining coordinate information of the index number to be converted under the aggregation dimension information according to the index number to be converted and the aggregation dimension information, and recording the coordinate information of the index number to be converted under the aggregation dimension information as coordinates to be converted includes: According to the aggregated dimension information, obtaining the dimension size in the aggregated dimension information; The index number to be converted is converted according to the dimension size to obtain the coordinate to be converted.

7. The index conversion method based on Ascend AI processor according to claim 6, characterized in that: The step of converting the index number to be converted according to the dimension size to obtain the coordinate to be converted includes: According to the aggregated dimension information, obtaining a first dimension, a second dimension, a third dimension and a fourth dimension in the aggregated dimension information which are arranged in sequence; According to the dimensional dimensions, a first dimension, a second dimension, a third dimension, and a fourth dimension of the dimensional dimensions are obtained; Calculate the remainder of the index number to be converted with respect to the fourth dimension to obtain a first remainder, and record the first remainder as the subscript of the index number to be converted in the fourth dimension; Divide the index number to be converted by the fourth dimension and then find the remainder with respect to the third dimension to obtain a second remainder, and record the second remainder as the subscript of the index number to be converted in the third dimension; Divide the index number to be converted by the fourth dimension and the third dimension in sequence, and then find the remainder with respect to the second dimension to obtain a third remainder, and record the third remainder as the subscript of the index number to be converted in the second dimension; Divide the index number to be converted into the fourth dimension, the third dimension, and the second dimension in sequence, and then find the remainder with respect to the first dimension to obtain a fourth remainder, and record the fourth remainder as the subscript of the index number to be converted in the first dimension; The coordinates to be converted are obtained according to the subscript in the first dimension, the subscript in the second dimension, the subscript in the third dimension, and the subscript in the fourth dimension.

8. The index conversion method based on Ascend AI processor according to claim 5, characterized in that: The step of converting the coordinates to be converted according to the converted aggregate dimension information to obtain target coordinate information in the target index information that matches the source data arrangement format includes: According to the converted aggregation dimension information, obtaining each aggregation dimension size corresponding to the converted aggregation dimension information; Each subscript in the coordinate to be converted is converted according to each of the aggregation dimensions to obtain the target coordinate information.

9. The index conversion method based on Ascend AI processor according to claim 8, characterized in that: The step of converting each subscript in the coordinates to be converted according to each of the aggregation dimensions to obtain the target coordinate information includes: Using each of the aggregated dimensions as a weight to perform weighted calculation on each subscript in the coordinates to be converted, to obtain a calculation result; The target coordinate information is obtained according to the calculation result.

10. A device for an index conversion method based on an Ascend AI processor, characterized in that: The device comprises the following components: The information collection module is used to obtain the index information to be converted corresponding to the operator and the source data arrangement format corresponding to the tensor; A conversion module, used to convert the index information to be converted according to the source data arrangement format to obtain target index information matching the source data arrangement format; A data indexing module, used for inputting the data in the tensor into the operator according to the target index information; The converting the index information to be converted according to the source data arrangement format to obtain target index information matching the source data arrangement format includes: According to the source data arrangement format, the source data dimension information corresponding to the tensor is obtained; According to the operator, dimension information corresponding to the operator is obtained; According to the source data dimension information, the dimension information corresponding to the operator is converted to obtain the dimension information after conversion; The index information to be converted is converted according to the dimension information after conversion to obtain target index information matching the arrangement format of the source data.

11. A terminal device, characterized in that: The terminal device includes a memory, a processor, and an index conversion program based on the Ascend AI processor stored in the memory and executable on the processor. When the processor executes the index conversion program based on the Ascend AI processor, the steps of the index conversion method based on the Ascend AI processor as described in any one of claims 1 to 9 are implemented.

12. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores an index conversion program based on the Ascend AI processor. When the index conversion program based on the Ascend AI processor is executed by the processor, the steps of the index conversion method based on the Ascend AI processor as described in any one of claims 1 to 9 are implemented.