Data storage method and apparatus

By expanding the tensor data into a first tensor and reading it along the channel dimension, the problem of complex data reading caused by non-channel dimension storage format is solved, and the computational efficiency of convolutional neural networks is improved.

CN115291802BActive Publication Date: 2026-07-21SPREADTRUM COMM (TIANJIN) INC
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
SPREADTRUM COMM (TIANJIN) INC
Filing Date
2022-08-08
Publication Date
2026-07-21

AI Technical Summary

Technical Problem

In convolutional neural networks, data formats that do not start storage in the channel dimension (C direction), such as NCHW and HWCN, result in more data reading operations and complex lookups, affecting computational efficiency.

Method used

The tensor to be converted is expanded into a first tensor and stored in a first storage format to a storage device, such that when reading tensor data, it is first performed in the channel dimension direction, and the number of tensor data read each time is a multiple of the first value, such as 8.

Benefits of technology

It improves the speed of tensor data reading and computation efficiency, reduces useless operations, and meets the high-efficiency computing requirements of hardware performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115291802B_ABST
    Figure CN115291802B_ABST
Patent Text Reader

Abstract

The present application relates to the technical field of computer, and especially relates to a data storage method and device. First, a to-be-converted tensor is acquired, the to-be-converted tensor contains a channel dimension, a width dimension, a height dimension and a quantity dimension, then a first tensor is configured according to the to-be-converted tensor, the number of tensor data of the first tensor in the channel dimension and the quantity dimension direction is a multiple of a first value, finally the first tensor is stored in a storage device in a first storage format, when reading the tensor data of the first tensor stored in the first storage format, reading is first performed in the channel dimension direction, and the number of tensor data read each time is the first value. The first storage format is configured, and specific steps of providing other storage formats to the first storage format are provided, so that the reading speed of data is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of computer technology, and in particular to a data storage method and apparatus. Background Technology

[0002] In common convolutional neural networks, tensors consist of four dimensions: number dimension N, height dimension H, width dimension W, and channel dimension C. Depending on the data storage format, tensor data is stored in memory as one-dimensional data along different dimensional directions. During convolution computation, to improve computational efficiency, eight convolution multiplications can be performed in parallel. The basic method for obtaining tensor data during computation is to retrieve eight data points along the channel dimension C each time. However, for some data storage formats that do not start storage along the channel dimension (C direction), such as NCHW and HWCN, reading data along the channel dimension (C direction) results in a large number of operations and complex lookups because the data arrangement along the channel dimension (C direction) is not continuous. Summary of the Invention

[0003] This invention provides a data storage method and apparatus, which expands the original tensor to be converted into a first tensor, and then stores the first tensor in a first storage format to a storage device, so that the stored first tensor can first read tensor data in the channel dimension direction and specify the number of reads each time, thereby improving the speed of reading tensor data.

[0004] In a first aspect, embodiments of the present invention provide a data storage method, including:

[0005] Obtain the tensor to be converted, which includes channel dimension, width dimension, height dimension and number dimension;

[0006] Configure a first tensor according to the tensor to be converted, wherein the number of tensor data in the first tensor in both the channel dimension and the quantity dimension is a multiple of a first value;

[0007] The first tensor is stored in a storage device in a first storage format. When reading tensor data stored in the first storage format, the tensor is first read in the channel dimension direction, and the number of tensor data read each time is the first value.

[0008] In one implementation, configuring the first tensor based on the tensor to be converted includes:

[0009] The quantity dimension and channel dimension of the tensor to be converted are expanded using 0 as tensor data, and the first tensor is configured.

[0010] In one implementation, configuring the first tensor based on the tensor to be converted includes:

[0011] Obtain the number of tensors C1 in the channel dimension and the number of tensors N1 in the quantity dimension of the tensor to be converted;

[0012] The quotient of C1 and M is determined according to the formula C2 = C1 / M, where M is the first value;

[0013] The number of tensor data in the channel dimension direction of the first tensor is determined according to the formula C3=(C2+1)×M;

[0014] Determine the quotient of N1 and M using the formula N2 = N1 / M;

[0015] The number of tensor data in the quantity dimension of the first tensor is determined according to the formula N3=(N2+1)×M.

[0016] In one implementation, storing the first tensor in a first storage format to the storage device includes:

[0017] Obtain a second storage format, wherein the tensor to be converted is stored in the storage device in the second storage format;

[0018] Based on the first storage format and the second storage format, determine the data sequence number of each tensor data in the first tensor;

[0019] The tensor data in the first tensor are stored in the storage device in the order of the data sequence number.

[0020] In one implementation, determining the data sequence number of each tensor data in the first tensor according to the first storage format and the second storage format includes:

[0021] Set the initial value of the data sequence number to 0;

[0022] The first tensor is traversed according to the specified storage rules, and the data sequence number is associated with the corresponding tensor data. The value of the data sequence number is incremented by one each time a tensor data is traversed.

[0023] In one implementation, the first storage format includes a six-dimensional permutation N. x HWC x NC format;

[0024] The step of traversing the first tensor according to the specified storage rules and associating the data sequence number with the corresponding tensor data includes:

[0025] Step 1: Traverse x times along the channel dimension, traversing one tensor data each time;

[0026] Step 2: Traverse x times in the quantity dimension, each time traversing step 1;

[0027] Step 3: Return to the initial position in the quantity dimension and execute steps 1 and 2 sequentially;

[0028] Step 4: Repeat step 3 until the tensor data in the channel dimension has been traversed.

[0029] Step 5: Traverse along the width dimension, executing steps 1 to 4 sequentially for each traversal, until the tensor data along the width dimension has been traversed.

[0030] Step 6: Traverse along the height dimension, executing steps 1 to 5 sequentially for each traversal, until the tensor data along the height dimension has been traversed.

[0031] Step 7: Traverse along the quantity dimension, executing steps 1 to 6 sequentially for each traversal, until all tensor data has been traversed.

[0032] Wherein, x is the first numerical value.

[0033] In one implementation, the first storage format includes a four-dimensional permutation N. y HWC y Format;

[0034] The step of traversing the first tensor according to the specified storage rules and associating the data sequence number with the corresponding tensor data includes:

[0035] Step 1: Traverse y times along the channel dimension, traversing one tensor data each time;

[0036] Step 2: Traverse along the quantity dimension, executing Step 1 for each traversal, until the tensor data along the quantity dimension has been traversed.

[0037] Step 3: Return to the initial position in the quantity dimension direction, and execute steps 1 and 2 sequentially;

[0038] Step 4: Repeat step 3 until the tensor data in the channel dimension has been traversed.

[0039] Step 5: Traverse along the width dimension, executing steps 1 to 4 sequentially for each traversal, until the tensor data along the width dimension has been traversed.

[0040] Step 6: Traverse along the height dimension, executing steps 1 to 5 sequentially for each traversal, until all tensor data has been traversed.

[0041] Where y is the first value.

[0042] Secondly, embodiments of the present invention provide a data storage device, comprising:

[0043] The acquisition module is used to acquire the tensor to be converted, which includes channel dimension, width dimension, height dimension and number dimension;

[0044] The configuration module is used to configure a first tensor according to the tensor to be converted, wherein the number of tensor data in the channel dimension and the quantity dimension of the first tensor are both multiples of a first value;

[0045] The storage module is used to store the first tensor in a first storage format to a storage device. When reading the tensor data stored in the first storage format, the tensor data is first read in the channel dimension direction, and the number of tensor data read each time is the first value.

[0046] Thirdly, embodiments of the present invention provide an electronic chip, comprising:

[0047] At least one processor; and

[0048] At least one memory communicatively connected to the processor, wherein:

[0049] The memory stores program instructions that can be executed by the processor, and the processor can execute the method provided in the first aspect by calling the program instructions.

[0050] Fourthly, embodiments of the present invention provide a computer-readable storage medium comprising a stored program, wherein the program, when executed, controls the device containing the computer-readable storage medium to perform the method provided in the first aspect.

[0051] In this embodiment of the invention, a tensor to be converted is first obtained. This tensor includes a channel dimension, a width dimension, a height dimension, and a quantity dimension. Then, a first tensor is configured based on the tensor to be converted. The number of tensor data in the channel and quantity dimensions of the first tensor is a multiple of a first value. Finally, the first tensor is stored in a storage device using a first storage format. The first tensor stored in the first storage format first reads tensor data in the channel dimension, and the number of tensor data read each time is the first value. The configuration of the first storage format and the provision of specific steps for converting other storage formats to the first storage format improve the data reading speed. Attached Figure Description

[0052] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0053] Figure 1 A flowchart illustrating a data storage method provided in an embodiment of the present invention;

[0054] Figure 2 A schematic diagram illustrating a data storage method provided in an embodiment of the present invention;

[0055] Figure 3 A schematic diagram illustrating another data storage method provided in an embodiment of the present invention;

[0056] Figure 4A A flowchart illustrating another data storage method provided in an embodiment of the present invention;

[0057] Figure 4B A flowchart illustrating another data storage method provided in an embodiment of the present invention;

[0058] Figure 5 This is a schematic diagram of the structure of a data storage device provided in an embodiment of the present invention;

[0059] Figure 6 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present invention. Detailed Implementation

[0060] To better understand the technical solutions in this specification, the embodiments of the present invention will be described in detail below with reference to the accompanying drawings.

[0061] It should be understood that the described embodiments are merely some, not all, of the embodiments in this specification. All other embodiments obtained by those skilled in the art based on the embodiments in this specification without inventive effort are within the scope of protection of this specification.

[0062] The terminology used in the embodiments of this invention is for the purpose of describing particular embodiments only and is not intended to be limiting of this specification. The singular forms “a,” “the,” and “the” as used in the embodiments of this invention and the appended claims are also intended to include the plural forms unless the context clearly indicates otherwise.

[0063] Figure 1 This is a flowchart illustrating a data storage method provided in an embodiment of the present invention. This method can be applied to processing devices such as servers. Figure 1 As shown, the method may include:

[0064] Step 101: Obtain the tensor to be converted. The tensor to be converted includes the channel dimension, width dimension, height dimension, and number dimension.

[0065] The tensor to be converted in this embodiment of the invention mainly refers to a four-dimensional tensor, including channel dimension C, width dimension W, height dimension H, and quantity dimension N. During neural network computation, there is a significant difference between the network data structure and the underlying hardware storage structure. When a four-dimensional tensor to be converted is stored on a storage device, its contained tensor data is traversed in a certain order, and the tensor data is stored in the storage device as a one-dimensional array. Common storage formats include NHWC, NCHW, and HWCN. Different traversal orders occur when the tensor to be converted is stored on the storage device according to different storage formats. For example, the traversal order of NCHW is: width dimension, height dimension, channel dimension, and quantity dimension; the traversal order of NHWC is: channel dimension, width dimension, height dimension, and quantity dimension.

[0066] With advancements in hardware storage technology, chips such as Neural-network Processing Units (NPUs) that read data sequentially in blocks are increasingly being used to accommodate the parallelism of neural networks. In specific implementations, 8-byte * 8-byte matrices can be used as the computational unit. This computational method maximizes computational efficiency within the constraints of hardware performance parameters. The basic method for acquiring data during computation is that the smallest unit of data acquired each time is an 8-byte data unit (i.e., 8 tensor data units), which are arranged along the channel dimension from the algorithm's perspective. To reduce unnecessary operations when reading tensor data, when traversing and storing tensor data, the channel dimension can be traversed first, followed by the quantity dimension, ensuring that the tensor data in both the channel and quantity dimensions are multiples of 8. When the tensors to be converted are stored in common storage formats such as NHWC, NCHW, and HWCN, the above conditions cannot be met; therefore, the tensors to be converted need to be stored in a new storage format.

[0067] Step 102: Configure a first tensor according to the tensor to be converted. The number of tensor data in the first tensor in both the channel dimension and the quantity dimension is a multiple of the first value.

[0068] In this embodiment of the invention, the processing device can expand the tensor to be converted to configure a first tensor. Specifically, this includes expanding the number of tensor data in the channel dimension and quantity dimension of the tensor to be converted to a multiple of a first value, and filling the expanded positions with 0 as tensor data. The first value depends on the format of the storage device and can be 8 or other values.

[0069] In some embodiments, the step of configuring the first tensor by the processing device specifically includes: obtaining the number of tensors C1 in the channel dimension and the number of tensors N1 in the quantity dimension of the tensor to be converted; determining the quotient of C1 and M according to the formula C2 = C1 / M, where M is a first value; determining the number of tensor data in the channel dimension of the first tensor according to the formula C3 = (C2+1)×M; determining the quotient of N1 and M according to the formula N2 = N1 / M; and determining the number of tensor data in the quantity dimension of the first tensor according to the formula N3 = (N2+1)×M. Through the above steps, the number of tensor data in the channel dimension and the quantity dimension of the first tensor can be a multiple of the first value. For example, if the number of tensors in the channel dimension of the tensor to be converted is 14 and the number of tensors in the quantity dimension is 21, then the number of tensors in the channel dimension of the first tensor is 16 and the number of tensors in the quantity dimension is 24; if the number of tensors in the channel dimension and the quantity dimension of the tensor to be converted is 31 and 7 respectively, then the number of tensors in the channel dimension and the quantity dimension of the first tensor is 32 and 8 respectively.

[0070] Step 103: Store the first tensor in the first storage format to the storage device. When reading the tensor data of the first tensor stored in the first storage format, read it first in the channel dimension direction, and the number of tensor data read each time is the first value.

[0071] In this embodiment of the invention, the step of storing the first tensor in a first storage format to a storage device specifically includes: obtaining a second storage format; determining the data sequence number of each tensor data in the first tensor according to the first and second storage formats; and storing the tensor data in the first tensor in the order of the data sequence numbers to the storage device. The tensor to be converted was originally stored in the storage device in the second storage format, which may include formats such as NHWC, NCHW, and HWCN.

[0072] The first storage format in this embodiment of the invention includes: a six-dimensional permutation N x HWC x NC format and four-dimensional permutation N y HWC y Format. Where the first tensor is N x HWC xIf stored in NC format, the specific steps for traversing the first tensor according to the specified storage rules include: Step 1, traverse x times in the channel dimension, traversing one tensor data each time; Step 2, traverse x times in the quantity dimension, executing Step 1 each time; Step 3, return to the initial position in the quantity dimension and execute Step 1 and Step 2 sequentially; Step 4, repeat Step 3 until the tensor data in the channel dimension has been traversed; Step 5, traverse in the width dimension, executing Step 1 to Step 4 each time, until the tensor data in the width dimension has been traversed; Step 6, traverse in the height dimension, executing Step 1 to Step 5 each time, until the tensor data in the height dimension has been traversed; Step 7, traverse in the quantity dimension, repeating Step 1 to Step 5 each time, until all tensor data has been traversed; where x is the first value.

[0073] If the first tensor is N y HWC y If the format is used for storage, the specific steps for traversing the first tensor according to the specified storage rules include: Step 1, traverse y times in the channel dimension direction, traversing one tensor data each time; Step 2, traverse in the quantity dimension direction, executing Step 1 for each traversal, until the tensor data in the quantity dimension direction has been traversed; Step 3, return to the initial position in the quantity dimension direction, and execute Step 1 and Step 2 sequentially; Step 4, repeat Step 3 until the tensor data in the channel dimension direction has been traversed; Step 5, traverse in the width dimension direction, executing Step 1 to Step 4 for each traversal, until the tensor data in the width dimension direction has been traversed; Step 6, traverse in the height dimension direction, executing Step 1 to Step 5 for each traversal, until all tensor data has been traversed; where y is the first value.

[0074] like Figure 2 As shown, C, H, W, and N represent the channel dimension, height dimension, width dimension, and number dimension, respectively. If the first tensor has N... x HWC xThe data is stored in NC format, and x is 8. The processing device first traverses 8 tensor data points in the channel dimension (the area indicated by arrow 201 represents the initial 8 tensors). Then, it moves in the quantity dimension to N=1, and traverses 8 tensor data points again in the channel dimension, and so on, until the area indicated by arrow 202, where it traverses 8 tensor data points in the channel dimension at N=7. This completes step 2. Then, it returns to the initial position in the quantity dimension and continues traversing 8 data points in the channel dimension (the area indicated by arrow 203), and then continues moving in the quantity dimension until the area indicated by arrow 204. Afterward, it returns to the initial position in the quantity dimension and repeats the above operation until the channel dimension is completely traversed. The area indicated by arrow 205 represents the last part in the channel dimension. After traversing 8 tensor data points here, it continues moving in the quantity dimension until N=7. This completes step 4. Next, move along the width dimension, i.e., move to the area indicated by arrow 206, traverse 8 tensor data points, and then move to N=1 to traverse 8 tensor data points again. Then, repeat steps 5 and 6 above. Figure 2 After all tensor data has been traversed, the first tensor may contain more than just N0 to N7 in the quantity direction. For the remaining tensors, take 8 tensors in the quantity direction each time and execute steps 1 to 6. For example, if the first tensor has 24 tensors in the quantity direction, then after traversing N0 to N7, traverse N8 to N15, then traverse N16 to N23, until the first tensor has been traversed.

[0075] In a specific embodiment, when the processing device determines the data sequence number of each tensor data in the first tensor, it first restores the tensor to be converted according to its original storage format (second storage format). Figure 2 The network data format shown is used. Then, the tensor to be converted is expanded in both the channel and quantity dimensions, with the expanded positions filled with 0s to form the first tensor. The first tensor is then traversed according to the first storage format to determine the data sequence number of each tensor data point. Figure 2 For example, if the tensor to be converted has 7 elements in the quantity dimension, i.e., only N=0 to N=6, then N=7 is the expanded part, and all tensor data at N=7 is 0. The tensor to be converted is associated with a[i], where a[i] is the data index of each tensor data when the tensor to be converted is stored in the second storage format. The first tensor is associated with b[j], where b[j] is the data index of each tensor data when the first tensor is stored in the first storage format. When the processing device operates according to N... x HWC x When traversing the first tensor in NC format storage rules, it is necessary to determine the correspondence between a[i] and b[j]. Figure 3Taking the two-dimensional tensors shown as an example, the tensor data are 4, 0, 7, and 6 respectively. The second storage format is to traverse horizontally first and then vertically, and the data sequence numbers of the tensor data are a[1], a[2], a[3], and a[4] respectively. The first storage format is to traverse vertically first and then horizontally, and the data sequence numbers of the tensor data are b[1], b[2], b[3], and b[4] respectively. If you want to store the above four tensor data in the storage device according to the first storage format, you need to determine the tensor data corresponding to b[1], b[2], b[3], and b[4]. You can determine the correspondence between b[1], b[2], b[3], and b[4] and the tensor data by the correspondence between a[1], a[2], a[3], and a[4] and b[1], b[2], b[3], and b[4]. That is, b[1]-a[1]-4, b[2]-a[3]-7, b[3]-a[3]-0, b[4]-a[4]-6. Tensor data is obtained through the data sequence number in the second storage format, and then the obtained tensor data is associated with the data sequence number in the first storage format according to the correspondence between the first and second storage formats. Previously, the tensor data was stored with the data sequence number in the second storage format, and the storage order was 4, 0, 7, 6. After the data sequence number of the tensor data in the first storage format is determined, the processing device stores the tensor data in the first storage format, and the storage order is 4, 7, 0, 6.

[0076] When the second storage format is different, the correspondence between a[i] and b[j] is also different. This embodiment of the invention provides specific steps for determining the correspondence between a[i] and b[j], using NCHW format and N... x HWC x The NC format will be used as an example for explanation. The tensor to be converted was originally stored in NCHW format, and the data index of the tensor data is a[i]. The first tensor is named N... x HWC x The tensor data is stored in NC format, with the data index b[j] and the first value being 8. The first transformation formula b[i] = a[(kerGroup*8+kerNum)*H*W*cRaw+line*W*cRaw+width*cRaw+chanGroup*8+chanNum] is then compared with... Figure 4A as well as Figure 4B By combining these, the correspondence between each tensor data in a[i] and b[j] can be determined. kerGroup, kerNum, chanGroup, chanNum, line, and width are user-defined variables with an initial value of 0. H is the number of tensor data in the height dimension of the tensor to be converted, W is the number of tensor data in the width dimension of the tensor to be converted, and cRaw is the number of tensor data in the channel dimension of the tensor to be converted.

[0077] Combination Figure 4A , Figure 4B The first conversion formula further describes the overall process.

[0078] Step 401: The processing device first determines whether kerGroup is less than N / 8. Here, the kerGroup variable represents the number of groups in the first tensor in the quantity dimension, which is determined by the aforementioned N. x HWC x According to the traversal rules of NC format, the first tensor starts with N. x HWC x When storing in NC format, iterate through the tensor in groups of 8 (the first value) along the quantity dimension. N is the number of tensor data in the quantity dimension of the first tensor. N / 8 is the quotient of N and 8. Since N is a multiple of 8, the result is an integer. kerGroup is initialized to 0, proceeding to step 402. line is initialized to 0, proceeding to step 403. with is initialized to 0, proceeding to step 404. C is the number of tensor data in the data direction of the first tensor. C / 8 is the quotient of C and 8, the result is also an integer. chanGroup is initialized to 0, proceeding to step 405. kerNum is initialized to 0, proceeding to step 406. In step 406, values ​​are assigned according to specified rules, the specific process of which is as follows... Figure 4B As shown.

[0079] The processing device proceeds to step 412 to determine if there is a zero-padding operation in the N direction. Here, the N direction is the quantity dimension direction, and the zero-padding operation is the expansion operation of the tensor to be converted mentioned above. Zero-padding in the N direction means expanding the tensor in the quantity dimension direction, filling the expansion positions with 0. If there is no zero-padding operation, proceed to step 413, initialize chanNum to 0, and proceed to step 414. The processing device then determines if there is a zero-padding operation in the C direction, which is the channel dimension direction. If there is no zero-padding operation, proceed to step 415 to assign values ​​according to the first conversion formula. At this time, since the initial values ​​of all variables are 0, and j is initially 0, the first conversion formula is b[0] = a[0]. Proceed to step 416, increment j by 1, increment chanNum by 1, and return to step 413. If zero-padding is performed in the C or N direction, the j value is directly increased by the number of zeros padded. This can be understood as the position of the zero padding in the first tensor, where the tensor to be converted has no corresponding tensor data. Steps 417 and 419 respectively handle the operation of the processing device when zero padding is performed in the C and N directions. Figure 4BThe process and the first conversion formula continue to execute, and the results are as follows: b[1] = a[1], b[2] = a[2], b[3] = a[3], b[4] = a[4], b[5] = a[5], b[6] = a[6], b[7] = a[7]. After executing step 416 again, j = 8, chanNum = 8, and step 413 is determined to be negative. Step 418 is then executed, chanNum is set to zero, and the entire assignment process ends. At this point, step 406 is completed according to the specified rules. Step 407 is executed, kerNum is incremented by 1, and the process returns to step 405. At this point, kerNum is 1, which is still less than 8, so step 406 is executed again. Figure 4B The process in the middle. After performing the above steps, the tensor to be converted, stored in NHWC format, and the tensor in N format are... x HWC x The NC format stores the first tensor, which has already traversed 8 tensor data points along the channel dimension, such as... Figure 2 As shown, when the first tensor traverses the 9th tensor data, it needs to jump to N=1. The traversal order of the tensor to be transformed is to first move to the end in the channel dimension, then to the end in the width dimension, and then to the end in the height dimension, until the entire cube with N=0 is traversed before jumping to N=1 to continue traversing. Therefore, the first transformation formula at this time becomes b[8]=a[1*H*W*cRaw+chanNum], as Figure 2 As shown, the result of 1*H*W*cRaw is the number of tensor data contained in the cube with N=0 in the tensor to be converted. After traversing 8 tensor data in the channel dimension direction at N=1, it jumps to N=2 again, and kerNum is incremented by 1 each time it jumps.

[0080] Repeat the above steps until kerNum = 8. If step 405 fails, proceed to step 408, set kerNum to zero, and increment the chanGroup value by 1. Figure 2 As shown, the first tensor moves to N=7 (the area indicated by arrow 202) in the quantity dimension and traverses 8 tensor data. Then it jumps to the initial position in the quantity dimension (the area indicated by arrow 203) and continues to traverse 8 tensor data in the channel dimension. At this time, the first transformation formula is b

[64] =a[chanGroup*8]. At this time, chanGroup is 1, so the first transformation formula is b

[64] =a[8]. It can be understood that the transformation tensor will only move in other dimension directions after it has been traversed in the channel dimension. Figure 2 The position indicated by arrow 203 is the 9th data of the tensor to be converted, with the data number a[8].

[0081] Repeat the above steps until chanGroup is not less than C / 8. If step 404 fails, proceed to step 409, set chanGroup to zero, and increment the with value by 1. Figure 2 As shown, after the first tensor has been traversed in the channel dimension, it moves to the area indicated by arrow 206 in the width dimension. For the tensor to be converted, the area indicated by arrow 206 is the tensor data that will be traversed only after its channel dimension has been traversed. Therefore, the first conversion formula becomes b[j] = a[width*cRaw], where width is 1 and b[j] = a[cRaw].

[0082] Repeat the above steps until `with` is not less than `W`. If step 403 fails, proceed to step 410, increment the `line` value by 1, and set `with` to zero. For example... Figure 2 As shown, after the first tensor has been traversed in the width dimension, it moves in the height dimension. For the tensor to be transformed, all the data of the first layer of the N=0 cube has been traversed. Therefore, the first transformation formula becomes b[j] = a[line*W*cRaw]. At this time, the value of line is 1, and b[j] = a[W*cRaw].

[0083] Repeat the above steps until line is not less than H. If step 402 fails, proceed to step 411, increment the kerGroup value by 1, and set line to zero. Figure 2 As shown, the first tensor N=0 to N=7 has been completely traversed. Then, the second group, N=8 to N=15, is traversed along the quantity dimension, following the same traversal steps as N=0 to N=7. After each group is traversed... Figure 2 (8 cubes in the middle), increment the kerGroup value by 1 until kerGroup is not less than N / 8. If the result of step 401 is negative, the overall traversal ends.

[0084] If the tensor to be converted is stored in NCHW format, the first tensor is in N... x HWC x If stored in NC format, the corresponding second conversion formula is b[i]=a[(kerGroup*8+kerNum)*H*W*cRaw+

[0085] [(chanGroup*8+chanNum)*H*W+line*W+width], combine the second conversion formula with... Figure 4A as well as Figure 4B Combining these methods can achieve NCHW format to N x HWC x NC format conversion. If the tensor to be converted is stored in HWCN format, the first tensor is in N... x HWC xIf stored in NC format, the corresponding third conversion formula is b[i] = a[line*W*nRaw*cRaw + width*nRaw*cRaw + nRaw*

[0086] [(chanGroup*8+chanNum)+(kerGroup*8+kerNum)], where nRaw is the number of tensor data in the quantity dimension of the tensor to be transformed. The third transformation formula is then combined with... Figure 4A as well as Figure 4B Combining these methods will enable the conversion of HWCN format to N format. x HWC x NC format conversion. Conversion from other storage formats not mentioned in this embodiment to the first storage format only requires modifying the conversion formula. The NC format provided in this embodiment... y HWC y The format can also be converted using the above process, but corresponding modifications need to be made to the conversion.

[0087] In this embodiment of the invention, in order to quickly and efficiently extract 8 (first value) tensor data each time, a first storage format is configured, and specific steps for converting other storage formats to the first storage format are provided, so that the tensor to be converted is expanded into the first tensor and stored in the storage device in the first storage format, thereby improving the reading speed of tensor data.

[0088] Figure 5 This is a schematic diagram of a data storage device provided in an embodiment of the present invention. This device can be used as a specific equipment to implement the data storage method provided in the embodiment of the present invention, such as… Figure 5 As shown, the device may include: an acquisition module 510, a configuration module 520, and a storage module 530.

[0089] The acquisition module 510 is used to acquire the tensor to be converted, which includes the channel dimension, width dimension, height dimension and number dimension.

[0090] Configuration module 520 is used to configure the first tensor according to the tensor to be converted. The number of tensor data in the channel dimension and the number dimension of the first tensor are both multiples of the first value.

[0091] The storage module 530 is used to store the first tensor in a first storage format to the storage device. When reading the tensor data of the first tensor stored in the first storage format, it first reads in the channel dimension direction, and the number of tensor data read each time is the first value.

[0092] Figure 6 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present invention. Figure 6The electronic device shown is merely an example and should not impose any limitation on the functionality and scope of use of the embodiments of the present invention.

[0093] like Figure 6 As shown, the electronic device is presented in the form of a general-purpose computing device. The components of the electronic device may include, but are not limited to: one or more processors 610, memory 630, and communication bus 640 connecting different system components (including memory 630 and processor 610).

[0094] Communication bus 640 represents one or more of several bus architectures, including a memory bus or memory controller, a peripheral bus, a graphics acceleration port, a processor, or a local bus using any of the various bus architectures. For example, these architectures include, but are not limited to, Industry Standard Architecture (ISA) buses, Micro Channel Architecture (MAC) buses, Enhanced ISA buses, Video Electronics Standards Association (VESA) local buses, and Peripheral Component Interconnect (PCI) buses.

[0095] Electronic devices typically include a variety of computer-readable media. These media can be any available media that can be accessed by the electronic device, including volatile and non-volatile media, and removable and non-removable media.

[0096] Memory 630 may include computer system readable media in the form of volatile memory, such as random access memory (RAM) and / or cache memory. The electronic device may further include other removable / non-removable, volatile / non-volatile computer system storage media. Although Figure 6Not shown, a disk drive for reading and writing to a removable non-volatile disk (e.g., a "floppy disk") and an optical disc drive for reading and writing to a removable non-volatile optical disc (e.g., a compact disc read-only memory (CD-ROM), a digital video disc read-only memory (DVD-ROM), or other optical media). In these cases, each drive may be connected to the communication bus 640 via one or more data media interfaces. The memory 630 may include at least one program product having a set (e.g., at least one) of program modules configured to perform the functions of the embodiments of the present invention.

[0097] A program / utility having a set (at least one) of program modules can be stored in memory 630. Such program modules include—but are not limited to—an operating system, one or more application programs, other program modules, and program data. Each or some combination of these examples may include an implementation of a network environment. The program modules typically perform the functions and / or methods described in the embodiments of the present invention.

[0098] The electronic device can also communicate with one or more external devices, one or more devices that enable a user to interact with the electronic device, and / or any device that enables the electronic device to communicate with one or more other computing devices (e.g., network interface card, modem, etc.). This communication can be performed through communication interface 620. Furthermore, the electronic device can also communicate through a network adapter ( Figure 6 (Not shown) communicates with one or more networks (e.g., Local Area Network (LAN), Wide Area Network (WAN), and / or public networks, such as the Internet). The aforementioned network adapter can communicate with other modules of the electronic device via the communication bus 640. It should be understood that, although... Figure 6 Not shown, other hardware and / or software modules can be used in conjunction with electronic devices, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, disk arrays (Redundant Arrays of Independent Drives; hereinafter referred to as RAID) systems, tape drives, and data backup storage systems.

[0099] The processor 610 executes various functional applications and data processing by running programs stored in the memory 630, such as implementing the data storage method provided in the embodiments of the present invention.

[0100] This invention also provides a computer-readable storage medium that stores computer instructions, which cause the computer to execute the data storage method provided in this invention.

[0101] The aforementioned computer-readable storage medium may be any combination of one or more computer-readable media. A computer-readable medium may be a computer-readable signal medium or a computer-readable storage medium. A computer-readable storage medium may be, for example,—but not limited to—an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of computer-readable storage media (a non-exhaustive list) include: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM), or flash memory, optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this document, a computer-readable storage medium may be any tangible medium containing or storing a program that may be used by or in connection with an instruction execution system, apparatus, or device.

[0102] Computer-readable signal media may include data signals propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals may take various forms, including—but not limited to—electromagnetic signals, optical signals, or any suitable combination thereof. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, capable of transmitting, propagating, or transmitting programs for use by or in connection with an instruction execution system, apparatus, or device.

[0103] The program code contained on a computer-readable medium may be transmitted using any suitable medium, including—but not limited to—wireless, wire, optical fiber, RF, etc., or any suitable combination thereof.

[0104] In the description of this specification, the references to terms such as "one embodiment," "some embodiments," "example," "specific example," or "some examples," etc., indicate that a specific feature, structure, material, or characteristic described in connection with that embodiment or example is included in at least one embodiment or example of the present invention. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples. Moreover, without contradiction, those skilled in the art can combine and integrate the different embodiments or examples described in this specification, as well as the features of different embodiments or examples.

[0105] Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include at least one of that feature. In the description of this invention, "a plurality of" means at least two, such as two, three, etc., unless otherwise explicitly specified.

[0106] Any process or method description in the flowchart or otherwise herein can be understood as representing a module, segment, or portion of code comprising one or more executable instructions for implementing custom logic functions or processes, and the scope of preferred embodiments of the invention includes additional implementations in which functions may be performed not in the order shown or discussed, including substantially simultaneously or in reverse order depending on the functions involved, as should be understood by those skilled in the art to which embodiments of the invention pertain.

[0107] In the embodiments provided by this invention, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between devices or units may be electrical, mechanical, or other forms.

[0108] Furthermore, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or in the form of hardware plus software functional units.

[0109] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.

Claims

1. A data storage method, characterized in that, include: Obtain the tensor to be converted, which includes channel dimension, width dimension, height dimension and number dimension; Configure a first tensor according to the tensor to be converted, wherein the number of tensor data in the first tensor in both the channel dimension and the quantity dimension is a multiple of a first value; The first tensor is stored in a storage device in a first storage format. When reading tensor data stored in the first storage format, the tensor is first read in the channel dimension direction, and the number of tensor data read each time is the first value. The step of configuring the first tensor according to the tensor to be converted includes: The quantity dimension and channel dimension of the tensor to be converted are expanded using 0 as tensor data, and the first tensor is configured.

2. The method according to claim 1, characterized in that, The step of configuring the first tensor according to the tensor to be converted includes: Obtain the number of tensors C1 in the channel dimension and the number of tensors N1 in the quantity dimension of the tensor to be converted; According to the formula Determine the quotient of C1 and M, where M is the first value; The number of tensor data in the channel dimension direction of the first tensor is determined according to the formula C3=(C2+1)×M; According to the formula Determine the quotient of N1 and M; The number of tensor data in the quantity dimension of the first tensor is determined according to the formula N3=(N2+1)×M; Wherein, C1 is the number of original tensors of the tensor to be converted in the channel dimension direction, N1 is the number of original tensors of the tensor to be converted in the quantity dimension direction, C3 is the number of tensor data of the first tensor in the channel dimension direction, and N3 is the number of tensor data of the first tensor in the quantity dimension direction.

3. The method according to claim 1, characterized in that, Storing the first tensor in a first storage format to the storage device includes: Obtain a second storage format, wherein the tensor to be converted is stored in the storage device in the second storage format; Based on the first storage format and the second storage format, determine the data sequence number of each tensor data in the first tensor; The tensor data in the first tensor are stored in the storage device in the order of the data sequence number.

4. The method according to claim 3, characterized in that, The step of determining the data sequence number of each tensor data in the first tensor according to the first storage format and the second storage format includes: Set the initial value of the data sequence number to 0; The first tensor is traversed according to the specified storage rules, and the data sequence number is associated with the corresponding tensor data. The value of the data sequence number is incremented by one each time a tensor data is traversed.

5. The method according to claim 4, characterized in that, The first storage format includes a six-dimensional arrangement. The format is as follows, where C, H, W, and N represent the channel dimension, height dimension, width dimension, and quantity dimension, respectively. The step of traversing the first tensor according to the specified storage rules and associating the data sequence number with the corresponding tensor data includes: Step 1: Traverse x times along the channel dimension, traversing one tensor data each time; Step 2: Traverse x times along the quantity dimension, executing Step 1 on each traversal; Step 3: Return to the initial position in the quantity dimension and execute steps 1 and 2 sequentially; Step 4: Repeat step 3 until the tensor data in the channel dimension has been traversed. Step 5: Traverse along the width dimension, executing steps 1 to 4 sequentially for each traversal, until the tensor data along the width dimension has been traversed. Step 6: Traverse along the height dimension, executing steps 1 to 5 sequentially for each traversal, until the tensor data along the height dimension has been traversed. Step 7: Traverse along the quantity dimension, executing steps 1 to 6 sequentially for each traversal, until all tensor data has been traversed. Wherein, x is the first numerical value.

6. The method according to claim 4, characterized in that, The first storage format includes a four-dimensional arrangement. The format is as follows, where C, H, W, and N represent the channel dimension, height dimension, width dimension, and quantity dimension, respectively. The step of traversing the first tensor according to the specified storage rules and associating the data sequence number with the corresponding tensor data includes: Step 1: Traverse y times along the channel dimension, traversing one tensor data each time; Step 2: Traverse along the quantity dimension, executing Step 1 for each traversal, until the tensor data along the quantity dimension has been traversed. Step 3: Return to the initial position in the quantity dimension direction, and execute steps 1 and 2 sequentially; Step 4: Repeat step 3 until the tensor data in the channel dimension has been traversed. Step 5: Traverse along the width dimension, executing steps 1 to 4 sequentially for each traversal, until the tensor data along the width dimension has been traversed. Step 6: Traverse along the height dimension, executing steps 1 to 5 sequentially for each traversal, until all tensor data has been traversed. Where y is the first value.

7. A data storage device, characterized in that, include: The acquisition module is used to acquire the tensor to be converted, which includes channel dimension, width dimension, height dimension and number dimension; The configuration module is used to configure a first tensor according to the tensor to be converted, wherein the number of tensor data in the channel dimension and the quantity dimension of the first tensor are both multiples of a first value; The storage module is used to store the first tensor in a first storage format to a storage device. When reading the tensor data stored in the first storage format, the tensor data is first read in the channel dimension direction, and the number of tensor data read each time is the first value. The step of configuring the first tensor according to the tensor to be converted includes: The quantity dimension and channel dimension of the tensor to be converted are expanded using 0 as tensor data, and the first tensor is configured.

8. An electronic device, characterized in that, include: At least one processor; as well as At least one memory communicatively connected to the processor, wherein: The memory stores program instructions that can be executed by the processor, and the processor can execute the method as described in any one of claims 1 to 6 by calling the program instructions.

9. A computer-readable storage medium, characterized in that, The computer-readable storage medium includes a stored program, wherein, when the program is executed, it controls the device on which the computer-readable storage medium is located to perform the method of any one of claims 1 to 6.