Tensor compilation method and device based on multi-level storage heterogeneous computing chip
By using an integrated, bound tensor memory descriptor type to verify the validity of operands in multi-level storage heterogeneous computing chips during compile time, the debugging costs and fault risks caused by the separation of storage space and data layout in the tensor compilation framework are resolved, thereby improving compilation quality and computing efficiency.
Patent Information
- Application Number
- CN202611645034.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-10-22
- Publication Date
- 2026-11-20
AI Technical Summary
In existing tensor compilation frameworks, the storage space, data layout, and shape information of tensors are managed separately, which makes it impossible for the compiler to verify the validity of operands at compile time, increasing debugging costs and runtime failure risks.
A tensor memory descriptor type is constructed to integrate storage space information, data layout information, and tensor shape information. Hardware constraint information of the target operator is obtained, and legality is verified during compilation to generate target instructions executable by multi-level storage heterogeneous computing chips.
Intercepting memory space mismatch and layout incompatibility errors during compilation reduces runtime failure risk and debugging costs, and improves compilation quality and computing performance.
Smart Images

Figure CN123137664A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of this application relate to, but are not limited to, the field of compilation technology, and in particular to a tensor compilation method, electronic device, computer-readable storage medium, and computer program product based on a multi-level storage heterogeneous computing chip. Background Technology
[0002] With the development of artificial intelligence and high-performance computing, multi-level storage heterogeneous computing chips (such as tensor processors containing multiple levels of storage space, including DRAM, SMEM, SPM, and DLM) are widely used to accelerate tensor operations. In existing tensor compilation frameworks, the storage space, data layout, and shape information of tensors are usually separated and managed independently, and the compiler cannot obtain the integrated correlation information of the three during the compilation phase. This deficiency leads to the following technical problems: hardware operators such as matrix multiplication and copying have strict constraints on the storage space and data layout of operands, but due to the lack of an integrated description mechanism, the compiler cannot verify the validity of operands during compilation. Errors such as storage space mismatch and layout incompatibility can only be exposed at runtime, increasing debugging costs and runtime failure risks. Summary of the Invention
[0003] This application aims to address one of the technical problems in related technologies to a certain extent, and provides a tensor compilation method, electronic device, computer-readable storage medium, and computer program product based on a multi-level storage heterogeneous computing chip. The technical solution provided by this application includes the following aspects.
[0004] A first aspect of this application provides a tensor compilation method based on a multi-level storage heterogeneous computing chip, the method comprising:
[0005] During the compilation process, a tensor memory descriptor type is constructed, which is used to bind the storage space information, data layout information and tensor shape information corresponding to the tensor in an integrated manner;
[0006] Obtain hardware constraint information corresponding to the operands of the target operator, wherein the hardware constraint information includes storage space constraints and data layout constraints set by the multi-level storage heterogeneous computing chip for the operands;
[0007] The operands are subjected to compile-time validity checks based on the tensor memory descriptor type corresponding to the operands and the hardware constraint information.
[0008] If the operand passes the compile-time validity check, the target operator is compiled based on the tensor memory descriptor type.
[0009] This application's embodiments, through an integrated and bound tensor memory descriptor type, enable precise expression of multi-level storage and data layout at the language layer. This fills the gaps in general tensor pointers, which do not distinguish between SMEM / DLM / SPM storage levels and do not bind to TROW / TCOL data layout encodings. It provides a unified descriptive foundation for fine-grained storage management and layout optimization under multi-level storage architectures. Based on this integrated type, the storage space and layout validity of operator operands such as matrix multiplication and copy are verified at compile time. Errors such as storage space mismatch and layout incompatibility are moved from runtime to compile time interception, reducing runtime failure risks and debugging costs, and improving compilation quality and computational performance.
[0010] In one possible implementation, the compilation of the target operator based on the tensor memory descriptor type includes:
[0011] Obtain the storage space information, data layout information, and tensor shape information that are uniformly bound in the tensor memory descriptor type;
[0012] Based on the data layout information and the tensor shape information, determine the data layout code corresponding to the tensor;
[0013] Based on the storage space information, the data layout encoding, and the tensor shape information, the tensor memory descriptor type is translated into an encoded memory descriptor type in the intermediate representation;
[0014] The target operator is then compiled based on the encoded memory descriptor type.
[0015] In one possible implementation, the method further includes:
[0016] Obtain the storage space information, data layout information, and tensor shape information corresponding to the tensor to be allocated;
[0017] Based on the storage space information and the tensor shape information, a storage buffer is allocated for the tensor to be allocated;
[0018] The data layout code corresponding to the tensor to be allocated is determined based on the data layout information and the tensor shape information;
[0019] Based on the storage buffer, the storage space information, the data layout encoding, and the tensor shape information, a tensor memory descriptor corresponding to the tensor to be allocated is generated.
[0020] In one possible implementation, the method further includes:
[0021] Obtain the first encoded memory descriptor and subview parameters, wherein the subview parameters include offset information and size information;
[0022] Based on the offset information and the size information, a target sub-region is determined from the storage region corresponding to the first encoded memory descriptor;
[0023] If the offset information and the size information meet the preset alignment conditions, then a second coded memory descriptor is constructed based on the target sub-region without physically copying the data in the target sub-region.
[0024] The second coded memory descriptor shares at least a portion of the storage space with the first coded memory descriptor. The tensor shape corresponding to the second coded memory descriptor is determined based on the target sub-region, and the second coded memory descriptor inherits the data layout encoding of the first coded memory descriptor.
[0025] In one possible implementation, the subview parameters further include stride information, which is used to define the target sub-region as a contiguous storage region;
[0026] The offset information includes a dynamic offset determined during the operation phase, and / or the size information includes a dynamic size determined during the operation phase;
[0027] When the size information includes the dynamic size, the second encoded memory descriptor is used for the compilation processing of the matrix multiplication operator.
[0028] In one possible implementation, the method further includes:
[0029] Boundary checks are performed on the offset information and the size information to ensure that the target sub-region is within the tensor range corresponding to the first coded memory descriptor;
[0030] The offset information and / or the size information are aligned and verified according to preset alignment conditions.
[0031] In one possible implementation, the method further includes:
[0032] Obtain the tensor of the subview to be constructed and the subview parameters, and determine the carrier type of the tensor;
[0033] When the carrier type of the tensor is a register tensor, the target sub-tensor corresponding to the register tensor is determined according to the sub-view parameters, and the target sub-tensor is obtained by adjusting the index relationship of the corresponding values in the intermediate representation without actually moving the register data.
[0034] When the carrier type of the tensor is an encoded memory descriptor, memory subview processing is performed according to the subview parameters to obtain the encoded memory descriptor corresponding to the subview.
[0035] In one possible implementation, the step of performing compile-time validity verification on the operand based on the tensor memory descriptor type corresponding to the operand and the hardware constraint information includes:
[0036] Obtain the storage space allowable set and data layout constraints corresponding to the operands;
[0037] Determine whether the storage space information in the tensor memory descriptor type satisfies the allowed set of storage space, and determine whether the data layout information satisfies the data layout constraints;
[0038] When the storage space information satisfies the allowed set of storage space and the data layout information satisfies the data layout constraint, the operand is determined to pass the compile-time validity check.
[0039] When the storage space information does not meet the allowed set of storage space and / or the data layout information does not meet the data layout constraints, a compilation error message is output.
[0040] In one possible implementation, the method further includes:
[0041] Get the base address pointer corresponding to the allocated storage buffer;
[0042] Obtain the target tensor shape information and the target data layout information;
[0043] The target data layout code is determined based on the target data layout information and the target tensor shape information;
[0044] Based on the base address pointer, the target tensor shape information, and the target data layout encoding, a target encoded memory descriptor is constructed so that the target encoded memory descriptor is associated with the allocated storage buffer.
[0045] The target encoded memory descriptor is used for subsequent compilation processing of target operators;
[0046] Specifically, constructing the target encoded memory descriptor does not reallocate the storage buffer used to store the original data in the allocated storage buffer, nor does it move or rearrange the original data.
[0047] In one possible implementation, obtaining the base address pointer corresponding to the allocated storage buffer includes:
[0048] Obtain the source-band encoded memory descriptor corresponding to the buffer allocation operation, wherein the source-band encoded memory descriptor is the direct output of the buffer allocation operation;
[0049] An address fetch operation is performed on the source band-encoded memory descriptor to obtain the base address pointer carrying address space information, wherein no subview construction is performed on the source band-encoded memory descriptor between the buffer allocation operation and the address fetch operation;
[0050] The storage space corresponding to the target encoded memory descriptor is determined based on the address space information carried by the base address pointer.
[0051] In one possible implementation, the data layout represented by the target data layout information may be the same as or different from the source data layout corresponding to the allocated storage buffer;
[0052] The target data layout code is determined based on the target data layout information and the target tensor shape information, and the target data layout code does not inherit the source data layout code corresponding to the allocated storage buffer.
[0053] In one possible implementation, the method further includes:
[0054] Obtain the user-specified data layout information and / or the data layout constraints corresponding to the subsequent target operator;
[0055] The target data layout information is determined based on the user-specified data layout information and / or the data layout constraints corresponding to the subsequent target operator.
[0056] In one possible implementation, the method further includes:
[0057] Determine whether the data layout represented by the target data layout information matches the data layout constraints corresponding to the subsequent target operator;
[0058] When the data layout represented by the target data layout information does not match the data layout constraints, a layout transformation operation is inserted between the target encoded memory descriptor and the subsequent target operator.
[0059] The layout transformation operation is performed to transform the data layout of the data corresponding to the target encoded memory descriptor so that the transformed data layout satisfies the data layout constraints corresponding to the subsequent target operator.
[0060] The layout conversion operation is independent of the pointer reinterpretation, and the layout conversion operation includes register-level data rearrangement and / or memory-level data rearrangement.
[0061] In one possible implementation, the target tensor shape information includes at least one dynamic dimension, which is marked by a preset dynamic identifier, which is used to indicate that the size of the corresponding dimension is determined during the runtime phase.
[0062] When the target tensor shape information includes the dynamic dimension, the target encoded memory descriptor is used for the compilation and processing of the matrix multiplication operator.
[0063] In one possible implementation, the method further includes:
[0064] The target encoded memory descriptor is used as input for subview construction to construct a subview based on the target encoded memory descriptor;
[0065] And / or, reuse the base address pointer to obtain the shape information of another target tensor and the data layout information of another target, determine the data layout encoding of another target based on the data layout information of another target tensor and the shape information of another target tensor, and construct another target encoded memory descriptor based on the base address pointer, the shape information of another target tensor and the data layout encoding of another target.
[0066] In one possible implementation, the multi-level storage heterogeneous computing chip includes dynamic random access memory, shared memory, note-taking memory, and local data memory;
[0067] The target operator includes a matrix multiplication operator. The storage space allowed set corresponding to the first input operand of the matrix multiplication operator includes note-based memory and shared memory. The storage space allowed set corresponding to the second input operand includes dynamic random access memory and shared memory. The storage space allowed set corresponding to the output operand includes note-based memory, shared memory, and local data memory.
[0068] A second aspect of this application provides an electronic device, comprising: at least one processor; at least one memory for storing at least one program; and, when at least one of the programs is executed by at least one of the processors, implementing the tensor compilation method based on a multi-level storage heterogeneous computing chip as described above.
[0069] A third aspect of this application provides a computer-readable storage medium storing computer-executable instructions for executing the tensor compilation method based on a multi-level storage heterogeneous computing chip described above. Attached Figure Description
[0070] Figure 1 This is a flowchart illustrating a tensor compilation method based on a multi-level storage heterogeneous computing chip provided in an embodiment of this application. Figure 1 ;
[0071] Figure 2 yes Figure 1 A schematic diagram of the sub-process of step S104 in the process;
[0072] Figure 3 This is a schematic diagram of the process of allocating storage buffers for tensors to be allocated, provided in an embodiment of this application;
[0073] Figure 4 This is a schematic diagram of the subview construction process provided in an embodiment of this application;
[0074] Figure 5 This is a schematic flowchart illustrating the pointer reinterpretation provided in an embodiment of this application;
[0075] Figure 6 This is a second tensor compilation method based on a multi-level storage heterogeneous computing chip provided in this application embodiment;
[0076] Figure 7 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0077] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0078] To facilitate understanding of the embodiments of this application, the following points will be explained first:
[0079] First, in this application, the indication includes direct indication (also known as explicit indication) and indirect indication (also known as implicit indication). Direct indication information A refers to information containing A; indirect indication information A indicates information A by combining direct indication information B with the direct or indirect correspondence between information A and information B, or by combining direct indication information B with a preset rule that can be used to determine A based on B. The correspondence between information A and information B, and the preset rule, can be predefined, pre-stored, pre-burned, or pre-configured.
[0080] Second, for ease of understanding, this application uses multiple accompanying drawings to illustrate the provided method. These drawings are merely examples and should not be construed as limiting the application in any way. For example, the order of steps shown in the drawings can be adjusted according to their function and internal logic; or, for example, all steps in the drawings can be performed, or only a portion of them can be performed, as long as the same function as the embodiments of this application can be achieved.
[0081] Third, in this application, the use of prefixes such as "first" and "second" is only to distinguish different objects under the same name category, and does not constrain the order, size, or quantity of the objects. For example, "first message" and "second message" simply represent two different messages, and there is no temporal, size, or priority relationship between them; similarly, "first terminal" and "second terminal" simply represent two different terminals, and there is no quantity constraint or priority relationship between them. It should be understood that these descriptive objects can be interchanged where appropriate to describe solutions other than those in the embodiments of this application.
[0082] Fourth, in this application, "at least one" refers to one or more, and "more than one" refers to two or more. "And / or" is used to describe the relationship between related objects, indicating three possibilities: for example, A and / or B can represent only A, both A and B, or only B, where A and B can be singular or plural. The character " / " generally indicates an "or" relationship between the preceding and following related objects, but it does not exclude the possibility of an "and" relationship; the specific meaning can be understood in context. "At least one of the following" or similar expressions refer to any combination of the listed items, including any combination of a single item or multiple items. For example, at least one of a, b, or c can represent: a, b, c; a and b; a and c.
[0083] Fifth, in the embodiments of this application, "when," "if," and "if" all mean that the device will make corresponding processing under certain objective circumstances, without limiting the time, and without requiring the device to perform the judgment action when it is implemented, and do not mean that there are other limitations.
[0084] Sixth, in this application, words such as "example," "exemplarily," "for example," or "likely" are used for illustrative purposes. Any embodiment or design described as "example," "exemplarily," "for example," or "likely" in this application should not be construed as being more preferred or advantageous than other embodiments or designs. Rather, such expressions are used to present the relevant concepts in a specific manner.
[0085] The relevant technologies involved in this application are described below.
[0086] With the development of artificial intelligence and high-performance computing, heterogeneous computing chips with multi-level storage are widely used to accelerate tensor operations. The storage levels of such chips typically include: Dynamic Random Access Memory (DRAM), Shared Memory (SMEM), Scratchpad Memory (SPM), and Data Local Memory (DLM). Hardware operators such as matrix multiplication impose strict constraints on operands: operands must reside in specific storage spaces; for example, input A of a matrix multiplication must be in SPM or SMEM, input B must be in DRAM or SMEM, and output C must be in SPM, SMEM, or DLM. Furthermore, different storage spaces require specific data layouts, such as the tile row-major layout (TROW) or tile column-major layout (TCOL) for matrix multiplication, and the fused layout of on-chip private memory. Compilation refers to the process of translating high-level languages / high-level representations into low-level hardware executable instructions. Therefore, in the tensor compiler of this type of chip, it is necessary to accurately express the semantics of "where the operand is stored and in what data layout" at the language layer.
[0087] To address the aforementioned needs, the relevant technologies have the following three main research directions:
[0088] Firstly, the two-level storage model and tensor pointers of general-purpose GPUs. The general-purpose GPU programming model represented by CUDA / HIP and the tensor pointers in the upstream tensor compiler (such as Triton's make_tensor_ptr) are typical examples. General-purpose GPUs only provide two levels of storage: global memory and shared memory. Tensor pointers are used to describe tensor views on global memory. Its limitations are: (1) There is only one shared address space, and the concept of multi-level private storage such as Bank DLM and SPM is lacking; (2) Tensor pointers do not distinguish between storage levels such as SMEM / DLM / SPM, nor are they bound to hardware data layouts such as TROW / TCOL; (3) The legality of the "storage space and layout" of operands such as matrix multiplication cannot be verified at compile time, and can only be discovered indirectly by runtime errors or subsequent optimization stages.
[0089] Secondly, there's the compiler's type system and compile-time verification. A typical example is the type system of strongly typed languages / compilers, which encodes constraints into types and checks type matching at compile time. However, general-purpose type systems do not integrate the "storage space, data layout encoding, and shape of tensors" into a single memory descriptor type to verify the validity of operands in heterogeneous hardware operators, nor do they handle situations where "the same physical buffer is reinterpreted with different logical shapes, and the layout encoding of the new view is independently inferred according to the new shape."
[0090] Thirdly, the memory view / subview mechanism. Typical examples include subview operations in tensor / tensor compilers (such as `memref.subview` in MLIR), which can retrieve sub-region views from existing memory objects. However, this type of mechanism typically only retrieves static sub-regions from the same storage object. It does not support "reinterpreting and constructing new descriptors with different logical shapes on the base pointer of allocated private memory (DLM / SMEM), and re-inferring the encoding according to the new shape rather than inheriting the source allocation," nor does it achieve unified processing of "dynamic offsets and dynamically sized subviews (dynamic sizing is consumed when the result is multiplied by a matrix)" and "continuous slice constraints."
[0091] In summary, the general GPU tensor pointers of related technologies only cover two levels of storage, are not bound to data layout, and lack compile-time verification; the general type system does not integrate storage space, layout, and shape; and the subview mechanism does not support pointer reinterpretation and independent inference of encoding based on the new shape. None of these three address the core problem of this invention: providing a tensor memory descriptor type that integrates storage space (DRAM / SMEM / SPM / DLM), data layout encoding (TROW / TCOL / fusion, etc.), and shape (which may contain dynamic dimensions), enabling compile-time verification of the storage space and layout validity of hardware operator operands such as matrix multiplication / copy; providing a method for reinterpreting and constructing new memory descriptor views with different logical shapes on allocated private memory base address pointers, where the layout encoding is independently inferred based on the new shape rather than inheriting from the source allocation; and supporting subviews with dynamic offsets and dynamic sizes (dynamic sizes are consumed when the result is multiplied by the matrix), and only continuous slices, while uniformly distinguishing between register tensors (no-operation) and memory descriptors (reduced to memory subview operators).
[0092] Specifically, the relevant technology has at least the following drawbacks:
[0093] 1. Multi-level storage and data layout cannot be accurately expressed at the language level. General-purpose tensor pointers do not distinguish between storage levels such as SMEM / DLM / SPM, nor are they bound to data layouts such as TROW / TCOL. Programmers cannot accurately express the storage and layout constraints of hardware operator operands at the language level.
[0094] 2. Operand validity can only be detected at runtime. Storage space and layout are not integrated with the type, meaning the validity of operands such as matrix multiplication cannot be verified at compile time. It can only be detected during runtime errors or indirectly during subsequent optimization phases, increasing debugging costs and runtime failure risks.
[0095] 3. Lack of pointer reinterpretation and independent encoding inference mechanism. It is impossible to reinterpret and construct a new descriptor with a different logical shape on the base address pointer of the allocated private memory, and to make the layout encoding of the new view independently inferred according to the new shape; if the source allocation encoding is directly inherited, it will not be consistent with the new shape.
[0096] 4. Lack of unified processing for dynamic shape subviews. The constraints of "dynamic offset and dynamic size (dynamic size is consumed when the result is multiplied by the matrix) and only continuous slicing" are not handled uniformly, nor is the semantics of subviews of two types of carriers, register tensors (no operation) and memory descriptors (reduced to memory subview operators), distinguished.
[0097] Therefore, there is an urgent need for a tensor compilation method that can integrate storage space, data layout and shape, and complete operand validity verification during compilation, so as to improve the compilation quality and computing performance of multi-level storage heterogeneous computing chips.
[0098] This application provides a tensor compilation method based on a heterogeneous computing chip with multi-level storage. The heterogeneous computing chip can be a graphics processing unit (GPU), a tensor processing unit (TPU), a neural processing unit (NPU), a field-programmable gate array (FPGA), or an application-specific integrated circuit (ASIC), etc., that has a multi-level storage structure and a matrix operation engine. The multi-level storage of the heterogeneous computing chip can include storage layers such as dynamic random access memory (DRAM), shared memory (SMEM), scratchpad memory (SPM), and data local memory (DLM); the matrix operation engine can include a systolic array or a tensor core, etc. This application does not specifically limit the specific implementation of this method.
[0099] The implementation environment of the tensor compilation method based on multi-level storage heterogeneous computing chips provided in this application embodiment may include a compilation device and a heterogeneous computing chip. Specifically, the tensor compilation method in this application embodiment can be executed by the compilation device, by the heterogeneous computing chip, or by both the compilation device and the heterogeneous computing chip.
[0100] In one possible implementation of this application, the compilation device is a server cluster deployed in the cloud or data center, and the heterogeneous computing chip is an AI acceleration chip deployed in the cloud or at the edge. The compilation device and the heterogeneous computing chip are connected via a PCIe bus or a high-speed network. The user submits a high-level tensor program containing hardware operators such as matrix multiplication and copying to the compilation device. Based on the tensor compilation method provided in this application, the compilation device constructs a tensor memory descriptor type that integrates storage space information, data layout information, and tensor shape information during the compilation process. It obtains the hardware constraint information corresponding to the operands of the target operator and performs compile-time validity checks on the operands. After the checks pass, it performs compilation processing on the target operator, generating target instructions executable by the heterogeneous computing chip and issuing them for execution. During execution, the compilation artifacts can also reuse multiple logical views of the same physical buffer through pointer reinterpretation and subview construction, reducing data migration overhead and improving the computational performance of multi-level storage heterogeneous computing chips.
[0101] Figure 1 This is a flowchart illustrating a tensor compilation method based on a multi-level storage heterogeneous computing chip provided in an embodiment of this application. Figure 1 The method includes the following steps:
[0102] Step S101: During the compilation process, a tensor memory descriptor type is constructed. The tensor memory descriptor type is used to bind the storage space information, data layout information and tensor shape information corresponding to the tensor in an integrated manner.
[0103] Understandably, storage space information is used to indicate the storage location of tensors within the storage hierarchy of a multi-level heterogeneous computing chip. The storage hierarchy of a multi-level heterogeneous computing chip can include external global memory (DRAM), shared memory (SMEM), matrix engine private temporary storage (SPM), and each execution unit's private branched local memory (DLM), etc. Storage space information is used to identify which of these storage hierarchies the tensor data is stored in. Different storage hierarchies have different capacities, bandwidths, and access overheads, and hardware operators impose strict constraints on the storage space of operands. For example, the input A of a matrix multiplication operator must be located in SPM or SMEM, input B must be located in DRAM or SMEM, and output C must be located in SPM, SMEM, or DLM.
[0104] Understandably, data layout information is used to indicate how tensor data is arranged in its storage space. Data layout information can include row layout (TROW), column layout (TCOL), and merge layout, etc. Different data layouts determine the addressing order and access efficiency of tensor elements in the storage space, and hardware operators support different data layouts to varying degrees. For example, matrix multiplication operators require operands to be stored in a specific tile layout to ensure that the matrix operation engine can read operands in a regular data flow.
[0105] Understandably, tensor shape information is used to indicate the dimensional structure of a tensor, that is, the size of each dimension of the tensor. Tensor shape information can include static dimensions or dynamic dimensions marked with preset sentinel values.
[0106] It is understandable that the size corresponding to the dynamic dimension is determined during the runtime phase. Specifically, the size of the dynamic dimension can be determined based on the allocation parameters when performing the buffer allocation operation, or it can be determined based on the actual shape of the upstream input tensor of the tensor through shape propagation, or it can be determined based on the actual shape of the operands involved in the operation according to the operator shape derivation rules when the target operator is executed. In the embodiments of this application, the size corresponding to the dynamic dimension can only be determined when the tensor is consumed as an operand of the matrix multiplication operator, and the output shape of the matrix multiplication operator is derived from the actual shape of each input operand according to the matrix multiplication rules.
[0107] In this embodiment, during compilation, storage space information, data layout information, and tensor shape information are bound together to form a tensor memory descriptor type. This integrated binding allows the compiler to simultaneously obtain the tensor's storage level, data arrangement, and shape structure at compile time. This enables compile-time validity checks on operands based on their corresponding storage space and data layout constraints, shifting errors such as storage space mismatches and data layout incompatibilities from runtime to compile-time interception, thus reducing runtime failure risks and debugging costs.
[0108] In this embodiment, the integrated tensor memory descriptor type serves as a unified semantic carrier, ensuring complete transfer between various stages of the compilation process (such as front-end parsing, intermediate representation, and code generation). This prevents the loss or fragmentation of semantic information regarding storage space and data layout during compilation, thus providing a complete and consistent descriptive foundation for compile-time validity checks and compilation optimizations such as storage allocation and layout selection. Compared to related technologies that manage storage space, data layout, and shape separately, this embodiment overcomes the compiler's inability to obtain the correlation information between storage space, data layout, and shape during compilation through integrated binding.
[0109] Step S102: Obtain the hardware constraint information corresponding to the operands of the target operator. The hardware constraint information includes the storage space constraints and data layout constraints set by the multi-level storage heterogeneous computing chip for the operands.
[0110] In the embodiments of this application, the multi-level storage heterogeneous computing chip includes multiple storage levels such as Dynamic Random Access Memory (DRAM), Shared Memory (SMEM), Scratchpad Memory (SPM), and Data Local Memory (DLM).
[0111] The target operator may include hardware operators such as matrix multiplication operators and copy operators, and this application does not specifically limit this. The hardware constraint information corresponding to the operands of the target operator includes the storage space constraints and data layout constraints set by the multi-level storage heterogeneous computing chip for the operands.
[0112] For example, storage space constraints include the set of storage spaces allowed for operands. Taking a matrix multiplication operator as an example, the set of storage spaces allowed for the first input operands includes SPM and SMEM, the set of storage spaces allowed for the second input operands includes DRAM and SMEM, and the set of storage spaces allowed for the output operands includes SPM, SMEM, and DLM. Data layout constraints include the data layout type required for operands. For example, a matrix multiplication operator may require operands to be stored in a tiled layout such as TROW (row layout) or TCOL (column layout), while on-chip private memory may require operands to be stored in a merged layout. This application does not specifically limit these constraints.
[0113] Step S103: Perform compile-time validity checks on the operands based on the tensor memory descriptor type and hardware constraint information corresponding to the operands.
[0114] Specifically, the validity verification process may involve: obtaining the allowed set of storage space and data layout constraints corresponding to the operand; determining whether the storage space information in the tensor memory descriptor type satisfies the allowed set of storage space and whether the data layout information satisfies the data layout constraints; and determining that the operand passes the compile-time validity verification when the storage space information satisfies the allowed set of storage space and the data layout information satisfies the data layout constraints.
[0115] For example, a compilation error message is output when the storage space information does not meet the allowed set of storage space and / or the data layout information does not meet the data layout constraints. That is, when the operand's storage space information does not belong to the allowed set of storage space and / or the operand's data layout information does not meet the data layout constraints, the operand is determined to have failed the compile-time validity check, and a compilation error message is output. The compilation error message is used to indicate the storage space constraints and / or data layout constraints that the operand does not meet, such as indicating the operand's current storage space information, data layout information, allowed set of storage space, and data layout constraints, so that the programmer can locate and correct the error based on the compilation error message, preventing the error from entering the subsequent compilation processing stage.
[0116] Step S104: If the operands pass the compile-time validity check, then compile the target operator based on the tensor memory descriptor type.
[0117] Specifically, after the operands pass compile-time validity checks, the target operator is compiled based on the tensor memory descriptor type to generate target instructions executable by a multi-level storage heterogeneous computing chip. Conversely, if the operands fail compile-time validity checks, the compilation process for the target operator is terminated to avoid generating compilation results with memory space or data layout errors.
[0118] This application's embodiments, through an integrated and bound tensor memory descriptor type, enable precise expression of multi-level storage and data layout at the language layer. This fills the gaps in general tensor pointers, which do not distinguish between SMEM / DLM / SPM storage levels and do not bind to TROW / TCOL data layout encodings. It provides a unified descriptive foundation for fine-grained storage management and layout optimization under multi-level storage architectures. Based on this integrated type, the storage space and layout validity of operator operands such as matrix multiplication and copy are verified at compile time. Errors such as storage space mismatch and layout incompatibility are moved from runtime to compile time interception, reducing runtime failure risks and debugging costs, and improving compilation quality and computational performance.
[0119] Figure 2 for Figure 1 A schematic diagram of the sub-process of step S104 in the diagram. (See attached diagram.) Figure 2 As shown, step S104, the specific process of compiling the target operator based on the tensor memory descriptor type, may include:
[0120] Step S104-1: Obtain the integrated storage space information, data layout information, and tensor shape information of the tensor memory descriptor type.
[0121] Specifically, during compilation, the compiler extracts three unified elements from the tensor memory descriptor type: the tensor's storage space information, data layout information, and tensor shape information. These serve as input for subsequent data layout encoding inference and intermediate representation translation. Because these three elements are bound to the same descriptor type in an integrated manner, the compiler can simultaneously obtain the tensor's storage level, data arrangement, and dimensional structure during compilation, eliminating the need to query multiple independent data structures separately and avoiding semantic fragmentation and loss of information during the information retrieval process.
[0122] For example, assuming the target operator is a matrix multiplication operator and its output operand C is a tensor of shape (256, 256), when the programmer declares the tensor memory descriptor type of this tensor at the language level, the following information is bound: storage space information indicates that the tensor is stored in data local memory (DLM), data layout information indicates that the tensor adopts a fused layout, and tensor shape information indicates that the tensor shape is (256, 256). The compiler obtains the above three elements from the descriptor type at the beginning of compilation.
[0123] Step S104-2: Determine the data layout code corresponding to the tensor based on the data layout information and tensor shape information.
[0124] Specifically, data layout encoding is used to characterize the specific arrangement of tensor data in its storage space, such as the addressing order of elements in each dimension, the block organization method, and the filling strategy. Data layout encoding is inferred and determined based on data layout information and tensor shape information. That is, the same data layout information can correspond to different data layout codes under different shapes, and the same shape can also correspond to different data layout codes under different data layout information.
[0125] For example, continuing from the previous example, the data layout information of the output operand C is a fused layout, and the tensor shape information is (256, 256). Based on this, the compiler infers the data layout code corresponding to the tensor, such as determining the block organization method of the tensor in each storage bank of the DLM and the addressing order between banks, and generates a fused layout code that matches the tensor shape. If the tensor shape information includes dynamic dimensions marked with sentinel values, the data layout code also includes the arrangement rules corresponding to the dynamic dimensions.
[0126] Step S104-3: Based on the storage space information, data layout encoding, and tensor shape information, translate the tensor memory descriptor type into the encoded memory descriptor type in the intermediate representation.
[0127] Specifically, the compiler translates the language-level tensor memory descriptor type into an encoded memory descriptor type in the compiler's intermediate representation (IR). The encoded memory descriptor type carries at least storage space information, data layout encoding, and tensor shape information, enabling subsequent stages of the compilation process (such as operator scheduling, memory allocation, layout selection, and code generation) to directly obtain the complete storage and layout semantics of the tensor based on the encoded memory descriptor type.
[0128] For example, continuing from the previous example, the compiler translates the unified descriptor type declared in the language layer into an encoded memory descriptor type in the intermediate representation. This encoded memory descriptor type carries the storage space information "DLM", the fusion layout encoding determined in step S104-2, and the tensor shape "(256, 256)", and serves as the unified description carrier of the output operand C in the intermediate representation IR.
[0129] Step S104-4: Perform subsequent compilation processing on the target operator based on the encoded memory descriptor type.
[0130] Specifically, subsequent compilation processing may include operator scheduling, memory allocation, layout selection, and code generation. For example, the compiler allocates a storage buffer for the output operand C in the DLM based on the storage space information carried in the encoded memory descriptor type; selects a memory access instruction sequence matching the data layout encoding carried in the encoded memory descriptor type; determines loop boundaries and block parameters based on the tensor shape information carried in the encoded memory descriptor type; and finally generates the target instructions executable by the multi-level storage heterogeneous computing chip.
[0131] In some embodiments of this application, a process for allocating a storage buffer for the tensor to be allocated is also included. Figure 3 This is a schematic diagram of the process of allocating storage buffers for tensors to be allocated, provided in an embodiment of this application. Figure 3 As shown, the process of allocating storage buffers for the tensor to be allocated may specifically include the following steps:
[0132] Step S201: Obtain the storage space information, data layout information, and tensor shape information corresponding to the tensor to be allocated.
[0133] Specifically, the storage space information, data layout information, and tensor shape information corresponding to the tensor to be allocated are obtained; among them, the storage space information is used to indicate the target storage level where the tensor to be allocated is to be stored, the data layout information is used to indicate the data arrangement of the tensor to be allocated, and the tensor shape information is used to indicate the dimensional structure of the tensor to be allocated.
[0134] Step S202: Allocate storage buffers for the tensors to be allocated based on storage space information and tensor shape information.
[0135] Specifically, the target storage level corresponding to the tensor to be allocated is determined based on the storage space information, and the required storage capacity of the tensor to be allocated is determined based on the tensor shape information. Then, a storage buffer of the corresponding capacity is allocated for the tensor to be allocated in the target storage level.
[0136] Step S203: Determine the data layout code corresponding to the tensor to be assigned based on the data layout information and tensor shape information.
[0137] Specifically, based on the data arrangement method represented by the data layout information and the dimensional structure represented by the tensor shape information, the data layout code corresponding to the tensor to be assigned is inferred and determined.
[0138] Step S204: Generate the tensor memory descriptor corresponding to the tensor to be allocated based on the storage buffer, storage space information, data layout encoding, and tensor shape information.
[0139] Specifically, based on the allocated storage buffer, the storage space information, data layout encoding, and tensor shape information are integrated and bound together to generate a tensor memory descriptor corresponding to the tensor to be allocated. This ensures that the tensor memory descriptor carries the complete storage and layout semantics of the tensor to be allocated from the moment it is generated, making it easy for subsequent operator compilation and processing to reuse directly.
[0140] In some embodiments of this application, a process for constructing subviews may also be included.
[0141] Specifically, the purpose of subview construction is to: avoid data migration. In heterogeneous computing chips with multi-level storage, the overhead of moving data between different storage levels is far greater than the computational overhead. Extracting sub-regions by physical copying will introduce additional storage access and runtime latency. However, by constructing subviews, only a new descriptor carrying parameters such as offset and size needs to be generated, which can reuse the target sub-region in the original buffer, achieving zero-copy data reuse; and avoid redundant storage allocation. On-chip private storage capacity is limited. Allocating a separate storage buffer for each sub-region will waste on-chip storage space. Subviews share physical storage with the source descriptor, which can significantly improve performance. Improve storage utilization; support block computation, where hardware operators such as matrix multiplication consume data in tiles. Compilers typically divide large tensors into multiple tile sub-regions for the matrix engine to process one by one. By constructing subviews, different sub-regions of the same large buffer can be used as operands for each operator without moving data, reducing the data movement overhead in block computation; enable the reuse of multiple operators in the same physical buffer. When multiple operators need to use different sub-regions of the same buffer as operands, the same buffer can be reused by constructing multiple subview descriptors, without having to allocate independent buffers for each operator, thus reducing the storage footprint of the compilation output.
[0142] Figure 4 This is a schematic diagram of the subview construction process provided in the embodiments of this application, such as... Figure 4 As shown, the process of constructing a subview may specifically include the following steps:
[0143] Step S301: Obtain the first encoded memory descriptor and subview parameters, including offset information and size information.
[0144] Specifically, the offset information is used to indicate the starting position of the target sub-region in the tensor corresponding to the first-band encoded memory descriptor, and the size information is used to indicate the size of the target sub-region in each dimension of the tensor.
[0145] Step S302: Determine the target sub-region from the storage area corresponding to the first coded memory descriptor based on the offset and size information in the sub-view parameters.
[0146] Specifically, starting from the starting position indicated by the offset information, the target sub-region is determined within the storage area corresponding to the first coded memory descriptor, according to the dimensions indicated by the size information. For example, the tensor shape corresponding to the first coded memory descriptor is (M, N), and the offset information is (M, N). , The size information is (). , If ), then the target subregion is the region from the tensor of the first... line, number Listed in order, size is × , and + ≤M、 + ≤N.
[0147] Step S303: If the offset information and size information meet the preset alignment conditions, then without physically copying the data in the target sub-region, construct a second coded memory descriptor based on the target sub-region.
[0148] The second-band encoded memory descriptor shares at least part of the storage space with the first-band encoded memory descriptor. The tensor shape corresponding to the second-band encoded memory descriptor is determined according to the target sub-region, and the second-band encoded memory descriptor inherits the data layout encoding of the first-band encoded memory descriptor.
[0149] Specifically, the preset alignment conditions are used to constrain the alignment relationship between the offset information and the size information and the storage block boundary represented by the data layout code corresponding to the first coded memory descriptor. For example, the starting position indicated by the offset information and the size of the region indicated by the size information must be an integer multiple or a preset multiple (such as half or a quarter of a tile basic block) of the storage block (such as a basic tile block) corresponding to the data layout code. When the offset information and the size information meet the preset alignment conditions, the data in the target sub-region is not physically copied. Instead, the second coded memory descriptor is directly constructed based on the target sub-region, thereby avoiding the data migration overhead during the sub-view construction process and reducing storage bandwidth usage and running latency.
[0150] For example, the subview parameters may also include stride information, which is used to define the target sub-region as a contiguous storage region.
[0151] It should be noted that the subview operation in this embodiment only supports unit stride, i.e., only continuous slices. Subview parameters include offset information, size information, and stride information; wherein, offset information indicates the starting position of the target sub-region in the tensor, size information indicates the size of the target sub-region in each dimension of the tensor, and stride information defines the target sub-region as a contiguous storage region. Specifically, a unit stride means that the interval between adjacent elements in each dimension of the target sub-region in the storage space is a unit interval, and the target sub-region is a contiguous storage region; under a unit stride, the offset information and size information are sufficient to uniquely locate the target sub-region. If the stride information indicates a non-unit stride, i.e., the target sub-region is a non-contiguous storage region, an error message is output.
[0152] For example, the offset information may include a dynamic offset determined during the runtime phase, and / or the size information may include a dynamic size determined during the runtime phase; when the size information includes a dynamic size, the second encoded memory descriptor is used for the compilation processing of the matrix multiplication operator.
[0153] For example, the offset information and size information can also be boundary-checked to ensure that the target sub-region is within the tensor range corresponding to the first coded memory descriptor; then the offset information and / or size information can be aligned according to a preset alignment condition.
[0154] Specifically, boundary checking is used to verify whether the target sub-region is completely within the tensor range corresponding to the first encoded memory descriptor. That is, it verifies whether the sum of the starting position indicated by the offset information and the region size indicated by the size information does not exceed the size of the tensor in each corresponding dimension. For example, when both the offset and size information are compile-time constants, boundary checking is performed at compile time; if the sum of the offset and size information exceeds the size of the corresponding dimension of the tensor, the target sub-region is determined to be out of bounds, and an out-of-bounds error message is output. When the offset and / or size information are dynamic values determined at runtime, boundary checking code is generated for the target sub-region at compile time and executed at runtime; if the target sub-region determined at runtime is out of bounds, execution is terminated and an out-of-bounds log is recorded to avoid hardware exceptions caused by out-of-bounds access and to facilitate location of the problem.
[0155] Alignment verification is used to check whether the offset information and / or size information meet preset alignment conditions. Specifically, the preset alignment conditions constrain the alignment relationship between the starting position indicated by the offset information and the area size indicated by the size information, and the storage block boundary represented by the data layout code corresponding to the first coded memory descriptor; for example, the starting position and area size must be an integer multiple or a preset multiple (such as half or a quarter of a tile basic block) of the storage block. When the target sub-region meets the preset alignment conditions, the second coded memory descriptor can directly inherit the specific data layout code of the first coded memory descriptor, ensuring semantic consistency of data arrangement; if the offset information and / or size information do not meet the preset alignment conditions, an alignment error message is output. Boundary verification and alignment verification are performed sequentially, first ensuring that the target sub-region is within the tensor range, and then ensuring that the target sub-region is aligned with the storage block boundary, so as to simultaneously ensure the legality of the access range and the inheritability of the layout code.
[0156] For example, the tensor to be constructed and the subview parameters can also be obtained, and the carrier type of the tensor can be determined. When the carrier type of the tensor is a register tensor, the target sub-tensor corresponding to the register tensor is determined according to the subview parameters, and the target sub-tensor is obtained by adjusting the index relationship of the corresponding values in the intermediate representation without actually moving the register data. When the carrier type of the tensor is an encoded memory descriptor, memory subview processing is performed according to the subview parameters to obtain the encoded memory descriptor corresponding to the subview.
[0157] Specifically, before constructing a subview, the carrier type of the tensor to be constructed is determined; the carrier type includes register tensors and encoded memory descriptors.
[0158] When the tensor's carrier type is a register tensor, the target sub-tensor corresponding to the register tensor is determined based on the subview parameters. The data of the register tensor is already stored in the registers, and the target sub-tensor is only the portion of the register tensor defined by the subview parameters. Since the target sub-tensor and the register tensor share the same set of register data, there is no need to actually move the register data; only the index relationship of the corresponding values in the intermediate representation needs to be adjusted to obtain the target sub-tensor. That is, the subview construction is a no-operation for register tensors, only changing the index relationship of the corresponding values in the intermediate representation at the Static Single Assignment (SSA) / value level. Among them, the offset information and size information must be compile-time constants so that the index relationship can be determined at compile time; the subview construction is mapped to the register slice operator during the compilation process.
[0159] When the tensor's carrier type is an encoded memory descriptor, memory subview processing is performed according to the subview parameters, including: determining the target sub-region in the storage area corresponding to the encoded memory descriptor based on offset and size information; after boundary and alignment checks, constructing the encoded memory descriptor corresponding to the subview without physically copying data; the encoded memory descriptor corresponding to the subview inherits the data layout encoding of the encoded memory descriptor; the subview construction is mapped to a memory subview operator during compilation.
[0160] In this embodiment, for two types of carriers, register tensors and encoded memory descriptors, the slicing semantics and reduction targets of their subviews are uniformly distinguished, taking into account both implementation overhead and slicing correctness.
[0161] In some embodiments of this application, a pointer reinterpretation process is also included. Pointer reinterpretation refers to reinterpreting the same block of physical data on the base address pointer of the allocated storage buffer with a different logical shape (and / or a different data layout type) to construct a new compilation operation with encoded memory descriptors.
[0162] Figure 5 This is a flowchart illustrating the pointer reinterpretation process provided in an embodiment of this application, as shown below. Figure 5 As shown, the pointer reinterpretation process specifically includes the following steps:
[0163] Step S401: Obtain the base address pointer corresponding to the allocated storage buffer.
[0164] Specifically, the base pointer is obtained from the allocation result of the allocated storage buffer and is used to point to the starting physical address of the allocated storage buffer.
[0165] Step S402: Obtain the target tensor shape information and target data layout information.
[0166] Specifically, the target tensor shape information is used to indicate the logical shape of the reinterpreted view, and the target data layout information is used to indicate the data layout type of the reinterpreted view.
[0167] Step S403: Determine the target data layout code based on the target data layout information and the target tensor shape information.
[0168] It should be noted that the target data layout encoding is determined by inferring from the target data layout information and the target tensor shape information, rather than using the original data layout encoding of the allocated storage buffer.
[0169] Step S404: Construct a target encoded memory descriptor based on the base address pointer, target tensor shape information, and target data layout encoding, so that the target encoded memory descriptor is associated with the allocated storage buffer.
[0170] In this embodiment, a target encoded memory descriptor is constructed based on the base address pointer, target tensor shape information, and target data layout encoding. That is, the association between the target encoded memory descriptor and the allocated storage buffer is established, so that the target encoded memory descriptor becomes a new logical view of the allocated storage buffer.
[0171] Step S405: Use the target encoded memory descriptor for subsequent target operator compilation processing.
[0172] Specifically, constructing a target encoded memory descriptor does not reallocate the storage buffer used to store the original data in the allocated storage buffer, nor does it move or rearrange the original data. In other words, constructing a target encoded memory descriptor only generates a new descriptor at the logical level, without reallocating the storage buffer used to store the original data, nor moving or rearranging the original data. That is, pointer reinterpretation only changes how the subsequent compilation and execution processes interpret the same physical data.
[0173] For example, the target tensor shape information may include at least one dynamic dimension, which is marked by a preset dynamic identifier. The preset dynamic identifier is used to indicate that the size of the corresponding dimension is determined during the runtime phase. When the target tensor shape information includes a dynamic dimension, the target encoded memory descriptor is used for the compilation processing of the matrix multiplication operator.
[0174] It should be noted that the preset dynamic identifier is a special marker value agreed upon at compile time, used to indicate that the size of the corresponding dimension is unknown at compile time and must be determined at runtime. The size of the dynamic dimension can be determined according to the allocation parameters when performing buffer allocation operations, or according to the actual shape of the upstream input tensor, or according to the operator shape derivation rules based on the actual shape of the operands involved in the operation when the target operator is executed. Since the output shape of the matrix multiplication operator can be deterministically derived from the actual shape of each input operand, the compiler can statically establish the shape derivation rules. Therefore, target encoded memory descriptors containing dynamic dimensions are limited to the compilation processing of matrix multiplication operators; they are not applicable to other consumption scenarios where the derivability of dynamic dimensions cannot be guaranteed.
[0175] In some embodiments of this application, the target encoded memory descriptor is also used as input for subview construction to construct a subview based on the target encoded memory descriptor; and / or, the base address pointer is reused to obtain the shape information of another target tensor and the data layout information of another target, the encoding of another target data layout is determined according to the other target data layout information and the shape information of another target tensor, and another target encoded memory descriptor is constructed according to the base address pointer, the shape information of another target tensor and the encoding of another target data layout.
[0176] Specifically, the target encoded memory descriptor can be used as input for subview construction. That is, based on the storage area associated with the target encoded memory descriptor, sub-regions are further extracted to construct subviews, enabling the cascading use of reinterpreted views and subviews.
[0177] Furthermore, for the same allocated storage buffer, multiple reinterpreted views can be constructed using the base address pointer, allowing the allocated storage buffer to be used by subsequent target operators with multiple different logical shapes and / or data layouts. Specifically, after constructing the first target encoded memory descriptor based on the base address pointer, the shape information of another target tensor and the data layout information of another target can be obtained. Following the same inference method, the encoding of another target data layout is determined based on the other target data layout information and the other target tensor shape information. Based on the base address pointer, the shape information of another target tensor, and the other target data layout encoding, another target encoded memory descriptor associated with the allocated storage buffer is constructed, thereby using the same physical storage to carry multiple different logical views. It should be noted that each reinterpreted view is constructed based on the same base address pointer initially obtained from the allocated storage buffer, without needing to perform address fetch operations again on the constructed reinterpreted descriptor, thus reducing the number of address fetch operations and maintaining a consistent association between each reinterpreted view and the same physical buffer.
[0178] For example, the process of obtaining the base address pointer corresponding to the allocated storage buffer may include: obtaining the source band-coded memory descriptor corresponding to the buffer allocation operation, wherein the source band-coded memory descriptor is the direct output of the buffer allocation operation; performing an address fetch operation on the source band-coded memory descriptor to obtain the base address pointer carrying address space information, wherein no subview construction is performed on the source band-coded memory descriptor between the buffer allocation operation and the address fetch operation; and determining the storage space corresponding to the target band-coded memory descriptor based on the address space information carried by the base address pointer.
[0179] Specifically, the direct output of the buffer allocation operation is the source band-coded memory descriptor, meaning the source band-coded memory descriptor must be the original descriptor generated by the buffer allocation operation, without any intermediate transformation. An address-fetching operation (such as `get_memdesc_addr`) is performed on the source band-coded memory descriptor to obtain a base pointer carrying address space information. No sub-view construction is performed on the source band-coded memory descriptor between the buffer allocation and address-fetching operations to ensure that the base pointer points to the original starting position of the memory region allocated by the buffer allocation operation, rather than an offset position of a sub-region. Since the base pointer carries address space information, the memory space corresponding to the target band-coded memory descriptor can be determined accordingly, thus eliminating the need to re-specify the memory space when constructing the target band-coded memory descriptor. The direct output of the buffer allocation operation and the absence of sub-view construction between the buffer allocation and address-fetching operations are necessary constraints for the pointer reinterpretation mechanism itself, ensuring the originality of the pointer upon which the reinterpretation is based and the integrity of the address space information.
[0180] It should be noted that the above constraints are not arbitrarily set, but are determined by the compile-time deterministic requirements of pointer reinterpretation. Specifically: On the one hand, the encoded memory descriptor obtained by the subview construction describes a sub-region in the allocated storage buffer, not the entire buffer. The starting position of the sub-region is offset relative to the original base address of the buffer. If the result of the subview construction is used as the source of the addressing operation, the resulting base address pointer will point to the starting position of the sub-region, not the original base address of the allocated storage buffer. The correspondence between the target encoded memory descriptor constructed accordingly and the allocated storage buffer will no longer be uniquely determined. On the other hand, the offset information and / or size information of the subview can be dynamic values determined at runtime. The physical region defined by the subview can only be determined at runtime. If the result of the subview construction is allowed as the source of addressing, the re-inferred target data layout needs to be encoded, and the boundary of the dynamic region and its alignment with the storage block boundary need to be verified at runtime. This introduces complex runtime checks and cannot guarantee the correctness of the reinterpretation result at compile time. When the addressing source is limited to the direct output of the buffer allocation operation, the base pointer will necessarily point to the original starting address of the allocated storage buffer and carry complete address space information. The target data layout encoding can be independently inferred at compile time based solely on the target data layout information and the target tensor shape information. This ensures that the entire process of addressing, encoding inference, and pointer reinterpretation of descriptor construction is deterministically completed at compile time. Furthermore, limiting the parameters of the addressing operation to the direct output of the buffer allocation operation also enables the process to trace back to the source allocation based on the parameters of the addressing operation, correctly establishing the association between the reinterpreted view and the allocated storage buffer.
[0181] It should be noted that the data layout represented by the target data layout information can be the same as or different from the source data layout corresponding to the allocated storage buffer; the target data layout code is determined based on the target data layout information and the target tensor shape information, and the target data layout code does not inherit the source data layout code corresponding to the allocated storage buffer.
[0182] Specifically, pointer reinterpretation allows the data layout represented by the target data layout information to be the same as or different from the source data layout corresponding to the allocated storage buffer. That is, the reinterpreted view can retain the original layout type or actively specify a different layout type. Regardless of whether the target data layout is the same as the source data layout, the target data layout encoding is independently inferred and determined based on the target data layout information and the target tensor shape information, rather than inheriting the source data layout encoding corresponding to the allocated storage buffer. This is because if the source data layout encoding is inferred based on the source data layout and source shape, directly using it for the target encoded memory descriptor may result in a mismatch with the new target tensor shape, leading to semantic errors in data arrangement. Independent inference based on the target data layout information and target tensor shape information ensures that the data layout encoding of the target encoded memory descriptor precisely matches its shape.
[0183] In some embodiments of this application, user-specified data layout information and / or data layout constraints corresponding to subsequent target operators are also obtained; target data layout information is determined based on user-specified data layout information and / or data layout constraints corresponding to subsequent target operators.
[0184] Specifically, the determination of target data layout information includes two sources: user intent and downstream operator requirements. On the one hand, user-specified data layout information can be obtained, i.e., the target layout type is explicitly specified by the developer when calling pointer reinterpretation; on the other hand, the data layout constraints corresponding to subsequent target operators can be obtained, i.e., the target layout type is automatically inferred by the compiler based on the layout requirements of subsequent consuming operators. These two methods can be used individually or in combination; that is, this embodiment supports both explicit developer specification and automatic compiler inference. When the user-specified data layout information is inconsistent with the data layout constraints corresponding to subsequent target operators, the compiler can insert layout transformation operations during compilation to eliminate the differences (detailed later), thereby ensuring that the reinterpreted view conforms to both user intent and the execution requirements of downstream operators.
[0185] In some embodiments of this application, it is further determined whether the data layout represented by the target data layout information matches the data layout constraints corresponding to the subsequent target operator; when the data layout represented by the target data layout information does not match the data layout constraints, a layout transformation operation is inserted between the target encoded memory descriptor and the subsequent target operator; the layout transformation operation is performed to transform the data layout corresponding to the target encoded memory descriptor so that the transformed data layout satisfies the data layout constraints corresponding to the subsequent target operator; wherein, the layout transformation operation is independent of pointer reinterpretation, and the layout transformation operation includes register-level data rearrangement and / or memory-level data rearrangement.
[0186] Specifically, the compiler first determines whether the data layout represented by the target data layout information matches the data layout constraints corresponding to the subsequent target operators. If they match, no additional processing is required, and the target encoded memory descriptor can be directly used as an operand of the subsequent target operators. If they do not match, a layout transformation operation is inserted between the target encoded memory descriptor and the subsequent target operators, and this layout transformation operation is executed to perform an actual data layout transformation on the data corresponding to the target encoded memory descriptor, so that the transformed data layout satisfies the data layout constraints corresponding to the subsequent target operators.
[0187] In this embodiment, pointer reinterpretation is used to change the logical interpretation of data corresponding to the same storage buffer. It is achieved by re-inferring the specific data layout encoding based on the target tensor shape and target layout type, and constructing a new encoded memory descriptor based on the base address pointer of the original storage buffer. Pointer reinterpretation itself does not reallocate the storage buffer used to carry the original data, nor does it physically move or rearrange the data layout in the original storage buffer.
[0188] It should be noted that pointer reinterpretation and layout transformation are different compilation operations. When the data layout corresponding to the target encoded memory descriptor obtained through pointer reinterpretation does not match the data layout constraints of subsequent consumer operators, a layout transformation operation can be inserted after the pointer reinterpretation operation. The layout transformation operation changes the actual data layout through register-level data rearrangement and / or memory-level data rearrangement so that the transformed data layout meets the data layout constraints of subsequent consumer operators.
[0189] When multiple reinterpreted views with different logical shapes and / or different layout types need to be constructed for the same allocated storage buffer, the base address pointer obtained from the direct allocation result corresponding to the allocated storage buffer can be reused. The specific data layout encoding can then be re-inferred based on the target tensor shape and target layout type corresponding to each reinterpreted view, thereby constructing multiple target encoded memory descriptors. Subsequent reinterpretations do not need to retrieve the base address pointer from the encoded memory descriptor obtained in the previous reinterpretation.
[0190] Figure 6 This application provides a second method for tensor compilation based on a multi-level storage heterogeneous computing chip, which includes the following steps:
[0191] Step S501: Obtain the memory layout information declared in the language layer.
[0192] Specifically, the memory layout information declared at the language layer is obtained. This memory layout information includes storage space, data layout, and shape. The storage space indicates the storage level where the tensor will be stored, the data layout indicates the arrangement of the tensor data, and the shape indicates the size of each dimension of the tensor. For example, when a programmer declares a tensor at the language layer, they simultaneously specify its storage space as DLM, its data layout as a merged layout, and its shape as (M, N).
[0193] Step S502: Construct a tensor memory descriptor type.
[0194] Specifically, storage space information, data layout information, and tensor shape information are integrated and bound together to construct a tensor memory descriptor type. This integrated descriptor type serves as a unified semantic carrier, enabling each stage of the compilation process to simultaneously obtain the tensor's storage level, data arrangement, and shape structure, thus avoiding information fragmentation caused by the separation of the three.
[0195] Step S503: Determine whether the tensor memory descriptor type is used as an operand for hardware operators such as matrix multiplication and copying.
[0196] Specifically, it is determined whether the tensor described by the tensor memory descriptor type will be used as an operand for matrix multiplication operators or other tensor operators. If it is used as an operand for matrix multiplication operators or tensor operators, step S504 is executed to perform compile-time validity verification; if it is not used for the above operators (e.g., only as a general storage object), the validity verification can be skipped, and step S507 can be executed directly.
[0197] Step S504: Compilation-time validity check.
[0198] Specifically, the allowed set of storage space and data layout constraints corresponding to the operands are obtained; it is determined whether the storage space information in the tensor memory descriptor type belongs to the allowed set of storage space, and whether the data layout information satisfies the data layout constraints. For example, the allowed set of storage space for the first input operand of the matrix multiplication operator includes SPM and SMEM, the second input operand allows DRAM and SMEM, and the output operand allows SPM, SMEM, and DLM. Operand validity verification can be achieved through the following equation (1): (1) A matrix multiplication operand X∈{A,B,C} is valid if and only if its storage space sp(X) belongs to the allowed set S_X of the operand, and its data layout L(X) matches the layout requirement L_X of the operand. For example, S_A={SPM,SMEM}, S_B={DRAM,SMEM}, S_C={SPM,SMEM,DLM}.
[0199] Step S505: Determine whether the legality verification has passed.
[0200] Specifically, if the storage space information belongs to the allowed set of storage spaces and the data layout information satisfies the data layout constraints, then the operand is determined to pass the compile-time validity check, and step S507 is executed; otherwise, it is determined to fail, and step S506 is executed.
[0201] Step S506: Compilation error.
[0202] Specifically, compilation error information is output, which is used to indicate the storage space constraints and / or data layout constraints that the operand does not satisfy. For example, it indicates the current storage space information, data layout information, allowed storage space set, and data layout constraints of the operand, so that the programmer can locate and correct the error and terminate the compilation process of the corresponding operator.
[0203] Step S507: Translate into an encoded memory descriptor.
[0204] Specifically, if the validity check passes (or no check is required), the tensor memory descriptor type continues to be compiled, and it is translated into an encoded memory descriptor in the intermediate representation, carrying storage space information, data layout encoding and tensor shape information for use in subsequent compilation stages.
[0205] Step S508: Determine whether the shape of the same buffer needs to be reinterpreted.
[0206] Specifically, it is determined whether the allocated storage buffer needs to be reinterpreted with a different logical shape, i.e., whether a pointer reinterpretation operation should be performed. If so, steps S509 and S510 are executed; otherwise, subsequent compilation processing continues.
[0207] Step S509: Obtain the base address pointer.
[0208] Specifically, an address fetch operation (get_memdesc_addr) is performed on the source band-coded memory descriptor generated by the buffer allocation operation to obtain the corresponding base address pointer. The base address pointer points to the starting address of the allocated storage buffer and carries corresponding address space information. Between the buffer allocation operation and the address fetch operation, no subview construction operation is performed on the source band-coded memory descriptor to ensure that the obtained base address pointer corresponds to the original starting address of the allocated storage buffer. Exemplarily, the address fetch operation only supports obtaining the base address from DLM or SMEM storage space; in other embodiments, the address fetch operation can also obtain the base address from other allocatable storage spaces (such as SPM, DRAM), and this application embodiment does not limit this.
[0209] Furthermore, limiting the input of the address fetch operation to the source-band encoded memory descriptor directly generated by the buffer allocation operation is because the subview describes a local storage region within the allocated storage buffer. This local storage region may have an address offset relative to the base address of the original storage buffer, and its offset and / or region size may be dynamically determined at runtime. If the memory descriptor constructed through the subview is used as the input of the address fetch operation, the storage region corresponding to the obtained pointer may depend on parameters determined at runtime. Consequently, it is necessary to verify the boundary constraints and alignment constraints between the re-inferred target data layout encoding and this storage region at runtime, which is not conducive to completing the static verification of relevant constraints at the compilation stage.
[0210] In contrast, using the source-band encoded memory descriptor directly generated by the buffer allocation operation as the input to the address fetch operation ensures that the obtained base address pointer corresponds to the starting address of the originally allocated storage buffer and retains the corresponding address space information. This avoids the impact of dynamic offsets introduced by subview construction on subsequent pointer reinterpretation, which is beneficial for completing the inference of target data layout encoding, verification of relevant constraints, and construction of target memory descriptors during the compilation phase.
[0211] Step S510: Create a new logical shape descriptor.
[0212] Specifically, the base address pointer is reinterpreted with the target logical shape through the descriptor construction operation (make_memdesc) to construct the target encoded memory descriptor. The reinterpreted encoded independent inference satisfies equation (2): (2); In the formula, p is the base address pointer derived from buffer allocation a, s' is the target logical shape, L is the data layout, s_a is the shape of the source allocation a, and enc() represents the specific data layout encoding inferred from the layout and shape. That is, the specific encoding of the target encoded memory descriptor is inferred and determined by the target logical shape s' and the data layout L, rather than inheriting the specific encoding of the source encoded memory descriptor; when s' and s_a are different, enc(p') and enc(p) are different, thereby avoiding mismatch between the source encoding and the new shape.
[0213] The data layout encoding of the target encoded memory descriptor is independently inferred and determined based on the target data layout information and the target tensor shape information, rather than inheriting the data layout encoding of the source encoded memory descriptor, to avoid mismatch between the source encoding and the new shape. During construction, the storage buffer used to store the original data is not reallocated, nor is the original data moved or rearranged; only the subsequent interpretation method of the same physical data block is changed. It should be noted that when constructing multiple reinterpreted views for the same allocated storage buffer, the same initially obtained base address pointer can be reused, without needing to perform address fetching operations again on the constructed reinterpreted descriptor.
[0214] Step S511: Determine whether it is necessary to construct an operator view.
[0215] Specifically, it is determined whether it is necessary to extract a subview of the tensor to construct an operator view as an operand for subsequent operators. If so, step S512 is executed; otherwise, step S515 is executed directly to translate it into an encoded memory descriptor.
[0216] Step S512: Determine the carrier type of the tensor.
[0217] Specifically, the tensor of the subview to be constructed and the subview parameters are obtained, and the carrier type of the tensor is determined; the carrier type includes register tensors and memory descriptors.
[0218] Step S513: Register tensor branch processing.
[0219] Specifically, if the carrier type of the tensor is a register tensor, then the subview construction is a no-operation: the offset information and size information of the subview must be compile-time constants, the target sub-tensor corresponding to the register tensor is determined according to the subview parameters, and no actual register data is moved, but the target sub-tensor is obtained only by adjusting the index relationship of the corresponding values in the intermediate representation; the subview construction is converted into a register tensor slice operator during the compilation process.
[0220] Step S514: Memory descriptor branch processing.
[0221] Specifically, if the carrier type of the tensor is a memory descriptor, then memory subview processing is performed: based on the offset information and the size information, a target sub-region is determined from the storage area corresponding to the memory descriptor; wherein, the offset information may include a dynamic offset determined during the runtime phase, and the size information may include a dynamic size determined during the runtime phase, wherein the dynamic size is only allowed to be used when the result of the subview is consumed by the matrix multiplication operator. The subview constraints satisfy equation (3): (3); where, This represents the stride of the subview in the k-th dimension. This indicates that the size of the subview is a dynamic size determined during the runtime phase. This indicates that the result of the subview is consumed by the matrix multiplier operator. Specifically, the subview must have a unit step (continuous slice) in each dimension; when the size of the subview is dynamic, the result of the subview is only allowed to be consumed by the matrix multiplier operator.
[0222] The subview only supports continuous slices with a unit stride; non-continuous slices with a non-unit stride will result in an error. Before constructing the subview, boundary checks are performed on the offset information and the size information to ensure that the target sub-region is within the tensor range corresponding to the memory descriptor. Then, alignment checks are performed on the offset information and / or the size information according to preset alignment conditions to ensure that the target sub-region is aligned with the storage block boundary corresponding to the data layout code. After satisfying the boundary and alignment checks, no physical copy is performed on the data in the target sub-region. An encoded memory descriptor corresponding to the subview is constructed based on the target sub-region, and the encoded memory descriptor corresponding to the subview inherits the specific data layout code of the memory descriptor. The subview construction is converted into a memory subview operator during the compilation process.
[0223] Step S515: Translate into an encoded memory descriptor.
[0224] Specifically, the tensor memory descriptor type (or the descriptor obtained through reinterpretation and subview construction) is reduced to the encoded memory descriptor type in the intermediate representation. The encoded memory descriptor type carries at least storage space information, data layout encoding, and tensor shape information, serving as a unified description carrier for subsequent stages of the compilation process.
[0225] Step S516 is used for the compilation and processing of subsequent target operators.
[0226] Specifically, based on the type of the encoded memory descriptor, subsequent compilation processing is performed on the target operator, including operator scheduling, memory allocation, layout selection, and code generation, to generate target instructions executable by the multi-level storage heterogeneous computing chip. Further, if the data layout of the reinterpreted target encoded memory descriptor does not match the data layout constraints of the subsequent consumer operator, a layout transformation operation can be inserted between the target encoded memory descriptor and the subsequent operator. This involves actual layout transformation of the data through register-level data rearrangement and / or memory-level data rearrangement, so that the transformed data layout satisfies the data layout constraints of the subsequent operator.
[0227] This application also provides a tensor compilation device based on a multi-level storage heterogeneous computing chip, the device comprising:
[0228] The unified type module (buffered type) is used to bind storage space information, data layout encoding, and tensor shape information into tensor memory descriptor types. The tensor shape information may include dynamic dimensions, which are marked with sentinel values and specially processed in areas such as element counting. During compilation, the tensor memory descriptor types are mapped to encoded memory descriptor types. Its function is to uniformly represent "where to put data, in what layout, and in what shape" at the language layer.
[0229] The compile-time validity verification module is used to verify whether the storage space and data layout of hardware operator operands such as matrix multiplication and copy meet hardware constraints based on the tensor memory descriptor type. For example, the first input operand of the matrix multiplication operator is located in SPM / SMEM, the second input operand is located in DRAM / SMEM, and the output operand is located in SPM / SMEM / DLM. Its function is to move operand validity verification from runtime to compile time.
[0230] The allocation module (alloc) is used to allocate buffers on allocatable private storage spaces (such as SMEM, DLM), the shape of which must be a compile-time constant, and returns a handle to the homogeneous type. Its function is to generate memory descriptors with storage space and data layout information.
[0231] The `get_memdesc_addr` module is used to perform an address-fetch operation on the source-encoded memory descriptor directly generated by the buffer allocation operation to obtain the base address pointer of the allocated private memory buffer. This base address pointer corresponds to a DLM or SMEM memory space and carries the corresponding address space information. The address-fetch operation takes the direct result of the buffer allocation operation as input, and no subview construction operation is performed between the buffer allocation operation and the address-fetch operation. This allows the compiler to backtrack to the original buffer allocation operation along the defined operators during the compilation downscaling phase, thereby providing the base address pointer for subsequent pointer reinterpretation.
[0232] The pointer reinterpretation view module (make_memdesc) constructs a new memory descriptor view on a base pointer with an explicit new logical shape and stride. The address space of the new view is inferred from the base pointer. The data layout encoding of the new view is inferred independently of the new shape, rather than inheriting the data layout encoding allocated from the source. Dynamically shaped views are only allowed to be consumed by matrix multiplication operators. Integer descriptors do not support filling with special values (NaN). Its function is to reinterpret the same physical buffer with different logical shapes.
[0233] The subview module (extract_slice / make_subview) is used to extract subviews, supporting dynamic offsets and dynamic dimensions. The dynamic dimensions are only allowed when the result of the subview is consumed by the matrix multiplication operator. The subview only supports continuous slices with a unit step size; non-continuous slices with a non-unit step size will result in an error. When the tensor's carrier type is a register tensor, the subview construction is a no-operation, supporting only shape indices, and the offset and size must be compile-time constants, mapped to register slice operators during compilation. When the tensor's carrier type is a memory descriptor, the subview construction is mapped to memory subview operators during compilation. Its purpose is to uniformly distinguish the slicing semantics of register tensors and memory descriptors and to reduce the target.
[0234] Please see Figure 7 This application also provides an electronic device 1000, which includes: at least one processor 1010; at least one memory 1020 for storing at least one program; the at least one program is executed by at least one processor 1010 to implement the tensor compilation method based on multi-level storage heterogeneous computing chips in any of the foregoing embodiments.
[0235] The processor 1010 can be an integrated circuit chip with signal processing capabilities, such as a general-purpose processor, a digital signal processor (DSP), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. Among them, the general-purpose processor can be a microprocessor or any conventional processor, etc.
[0236] The memory 1020 may include volatile memory or non-volatile memory, or both. The non-volatile memory may be read-only memory (ROM), and the volatile memory may be random access memory (RAM). The memory 1020 described in this application embodiment is intended to include any suitable type of memory. The memory 1020 may optionally include one or more storage devices physically located away from the processor 1010.
[0237] This application provides a computer program product, which includes a computer program or computer-executable instructions stored in a computer-readable storage medium. The processor of an electronic device reads the computer-executable instructions from the computer-readable storage medium and executes the computer-executable instructions, causing the electronic device to perform the tensor compilation method based on a multi-level storage heterogeneous computing chip described above in this application.
[0238] This application provides a computer-readable storage medium storing computer-executable instructions or computer programs. When the computer-executable instructions or computer programs are executed by a processor, the processor will execute the tensor compilation method based on a multi-level storage heterogeneous computing chip provided in this application.
[0239] In some embodiments of this application, the computer-readable storage medium may be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), flash memory, magnetic surface memory, optical disk, or CD-ROM, etc.; or it may be various devices including one or any combination of the above-mentioned memories.
[0240] In some embodiments of this application, computer-executable instructions may take the form of programs, software, software modules, scripts, or code, written in any form of programming language (including compiled or interpreted languages, or declarative or procedural languages), and may be deployed in any form, including being deployed as stand-alone programs or as modules, components, subroutines, or other units suitable for use in a computing environment.
[0241] As an example, computer-executable instructions may, but do not necessarily, correspond to files in a file system. They may be stored as part of a file that holds other programs or data, for example, in one or more scripts in a HyperText Markup Language (HTML) document, in a single file dedicated to the program in question, or in multiple co-located files (e.g., files that store one or more modules, subroutines, or code sections).
[0242] As an example, computer-executable instructions can be deployed to execute on a single electronic device, or on multiple electronic devices located at one location, or on multiple electronic devices distributed across multiple locations and interconnected via a communication network.
[0243] The above are merely embodiments of this application and are not intended to limit the scope of protection of this application. Any modifications, equivalent substitutions, and improvements made within the spirit and scope of this application are included within the scope of protection of this application.
Claims
1. A tensor compilation method based on a multi-level storage heterogeneous computing chip, characterized in that, The method includes: During the compilation process, a tensor memory descriptor type is constructed, which is used to bind the storage space information, data layout information and tensor shape information corresponding to the tensor in an integrated manner. Obtain hardware constraint information corresponding to the operands of the target operator, wherein the hardware constraint information includes storage space constraints and data layout constraints set by the multi-level storage heterogeneous computing chip for the operands; The operands are subjected to compile-time validity checks based on the tensor memory descriptor type corresponding to the operands and the hardware constraint information. If the operand passes the compile-time validity check, the target operator is compiled based on the tensor memory descriptor type.
2. The method according to claim 1, characterized in that, The compilation process of the target operator based on the tensor memory descriptor type includes: Obtain the storage space information, data layout information, and tensor shape information that are uniformly bound in the tensor memory descriptor type; Based on the data layout information and the tensor shape information, determine the data layout code corresponding to the tensor; Based on the storage space information, the data layout encoding, and the tensor shape information, the tensor memory descriptor type is translated into an encoded memory descriptor type in the intermediate representation; The target operator is then compiled based on the encoded memory descriptor type.
3. The method according to claim 1, characterized in that, The method further includes: Obtain the storage space information, data layout information, and tensor shape information corresponding to the tensor to be allocated; Based on the storage space information and the tensor shape information, a storage buffer is allocated for the tensor to be allocated; The data layout code corresponding to the tensor to be allocated is determined based on the data layout information and the tensor shape information; Based on the storage buffer, the storage space information, the data layout encoding, and the tensor shape information, a tensor memory descriptor corresponding to the tensor to be allocated is generated.
4. The method according to claim 2, characterized in that, The method further includes: Obtain the first encoded memory descriptor and subview parameters, wherein the subview parameters include offset information and size information; Based on the offset information and the size information, a target sub-region is determined from the storage region corresponding to the first encoded memory descriptor; If the offset information and the size information meet the preset alignment conditions, then a second coded memory descriptor is constructed based on the target sub-region without physically copying the data in the target sub-region. The second coded memory descriptor shares at least a portion of the storage space with the first coded memory descriptor. The tensor shape corresponding to the second coded memory descriptor is determined based on the target sub-region, and the second coded memory descriptor inherits the data layout encoding of the first coded memory descriptor.
5. The method according to claim 4, characterized in that, The subview parameters also include stride information, which is used to define the target sub-region as a continuous storage region; The offset information includes a dynamic offset determined during the operation phase, and / or the size information includes a dynamic size determined during the operation phase; When the size information includes the dynamic size, the second encoded memory descriptor is used for the compilation processing of the matrix multiplication operator.
6. The method according to claim 4, characterized in that, The method further includes: Boundary checks are performed on the offset information and the size information to ensure that the target sub-region is within the tensor range corresponding to the first coded memory descriptor; The offset information and / or the size information are aligned and verified according to preset alignment conditions.
7. The method according to claim 2, characterized in that, The method further includes: Obtain the tensor of the subview to be constructed and the subview parameters, and determine the carrier type of the tensor; When the carrier type of the tensor is a register tensor, the target sub-tensor corresponding to the register tensor is determined according to the sub-view parameters, and the target sub-tensor is obtained by adjusting the index relationship of the corresponding values in the intermediate representation without actually moving the register data. When the carrier type of the tensor is an encoded memory descriptor, memory subview processing is performed according to the subview parameters to obtain the encoded memory descriptor corresponding to the subview.
8. The method according to claim 1, characterized in that, The step of performing compile-time validity verification on the operands based on the tensor memory descriptor type corresponding to the operands and the hardware constraint information includes: Obtain the storage space allowable set and data layout constraints corresponding to the operands; Determine whether the storage space information in the tensor memory descriptor type satisfies the allowed set of storage space, and determine whether the data layout information satisfies the data layout constraints; When the storage space information satisfies the allowed set of storage space and the data layout information satisfies the data layout constraint, the operand is determined to pass the compile-time validity check. When the storage space information does not meet the allowed set of storage space and / or the data layout information does not meet the data layout constraints, a compilation error message is output.
9. The method according to claim 2, characterized in that, The method further includes: Get the base address pointer corresponding to the allocated storage buffer; Obtain the target tensor shape information and the target data layout information; The target data layout code is determined based on the target data layout information and the target tensor shape information; Based on the base address pointer, the target tensor shape information, and the target data layout encoding, a target encoded memory descriptor is constructed so that the target encoded memory descriptor is associated with the allocated storage buffer. The target encoded memory descriptor is used for subsequent compilation processing of target operators; Specifically, constructing the target encoded memory descriptor does not reallocate the storage buffer used to store the original data in the allocated storage buffer, nor does it move or rearrange the original data.
10. The method according to claim 9, characterized in that, The step of obtaining the base address pointer corresponding to the allocated storage buffer includes: Obtain the source-band encoded memory descriptor corresponding to the buffer allocation operation, wherein the source-band encoded memory descriptor is the direct output of the buffer allocation operation; An address fetch operation is performed on the source band-encoded memory descriptor to obtain the base address pointer carrying address space information, wherein no subview construction is performed on the source band-encoded memory descriptor between the buffer allocation operation and the address fetch operation; The storage space corresponding to the target encoded memory descriptor is determined based on the address space information carried by the base address pointer.
11. The method according to claim 9, characterized in that, The data layout represented by the target data layout information may be the same as or different from the source data layout corresponding to the allocated storage buffer; The target data layout code is determined based on the target data layout information and the target tensor shape information, and the target data layout code does not inherit the source data layout code corresponding to the allocated storage buffer.
12. The method according to claim 9, characterized in that, The method further includes: Obtain the user-specified data layout information and / or the data layout constraints corresponding to the subsequent target operator; The target data layout information is determined based on the user-specified data layout information and / or the data layout constraints corresponding to the subsequent target operator.
13. The method according to claim 12, characterized in that, The method further includes: Determine whether the data layout represented by the target data layout information matches the data layout constraints corresponding to the subsequent target operator; When the data layout represented by the target data layout information does not match the data layout constraints, a layout transformation operation is inserted between the target encoded memory descriptor and the subsequent target operator. The layout transformation operation is performed to transform the data layout of the data corresponding to the target encoded memory descriptor so that the transformed data layout satisfies the data layout constraints corresponding to the subsequent target operator. The layout conversion operation is independent of the pointer reinterpretation, and the layout conversion operation includes register-level data rearrangement and / or memory-level data rearrangement.
14. The method according to claim 9, characterized in that, The target tensor shape information includes at least one dynamic dimension, which is marked by a preset dynamic identifier. The preset dynamic identifier is used to indicate that the size of the corresponding dimension is determined during the runtime phase. When the target tensor shape information includes the dynamic dimension, the target encoded memory descriptor is used for the compilation and processing of the matrix multiplication operator.
15. The method according to claim 9, characterized in that, The method further includes: The target encoded memory descriptor is used as input for subview construction to construct a subview based on the target encoded memory descriptor; And / or, reuse the base address pointer to obtain the shape information of another target tensor and the data layout information of another target, determine the data layout encoding of another target based on the data layout information of another target tensor and the shape information of another target tensor, and construct another target encoded memory descriptor based on the base address pointer, the shape information of another target tensor and the data layout encoding of another target.
16. The method according to claim 1, characterized in that, The multi-level storage heterogeneous computing chip includes dynamic random access memory, shared memory, note memory, and local data memory; The target operator includes a matrix multiplication operator. The storage space allowed set corresponding to the first input operand of the matrix multiplication operator includes note-based memory and shared memory. The storage space allowed set corresponding to the second input operand includes dynamic random access memory and shared memory. The storage space allowed set corresponding to the output operand includes note-based memory, shared memory, and local data memory.
17. An electronic device, characterized in that, include: At least one processor; At least one memory for storing at least one program; The method of any one of claims 1 to 16 is implemented when at least one of the programs is executed by at least one of the processors.
18. A computer-readable storage medium storing computer-executable instructions, characterized in that, The computer-executable instructions are used to perform the method described in any one of claims 1 to 16.
