Method and apparatus for memory-aware stream processing for transformer-based foundation models
By employing parallelized matrix-based computations and proactive buffer management, the method optimizes memory usage and reduces latency for transformer-based models on edge devices, addressing the challenges of high memory and computational demands.
Patent Information
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- HUAWEI TECH CO LTD
- Filing Date
- 2024-11-08
- Publication Date
- 2026-05-15
AI Technical Summary
The deployment of transformer-based foundation models on edge devices is hindered by high memory and computational demands, particularly due to limited processing power and on-chip memory, which existing optimization methods like FlashAttention and graph fusion techniques are not effectively addressing.
A method and apparatus for implementing AI transformers using a computing device with a MAC unit and VEC unit, employing parallelization and pipelining of matrix-based computations, including matrix multiplication and softmax operations, with fine-grained tiling and proactive buffer management to optimize memory usage and reduce latency.
This approach enhances computational efficiency and reduces latency by effectively utilizing on-chip memory, minimizing off-chip memory access, and enabling efficient deployment of AI transformers on resource-constrained edge devices.
Smart Images

Figure CN2024131012_15052026_PF_FP_ABST
Abstract
Description
METHOD AND APPARATUS FOR MEMORY-AWARE STREAM PROCESSING FOR TRANSFORMER-BASED FOUNDATION MODELSTECHNICAL FIELD
[0001] The present disclosure generally pertains to transformers in artificial intelligence and, in particular, to a method and apparatus for performing computer processing operations to implement such transformers.BACKGROUND
[0002] Artificial Intelligence (AI) can be viewed roughly as the field of study and application focused on creating machines and software capable of performing tasks that typically require human intelligence. AI encompasses various techniques, including machine learning, natural language processing, and computer vision. Transformers have driven significant advancements in generative AI, particularly in large language models (LLMs) and text-to-image models. Central to these models is the attention mechanism, which captures long-range dependencies and contextual nuances among tokens. However, the necessity, in the attention mechanism, to maintain pairwise interactions between input tokens results in quadratic memory and computational complexity. This complexity poses substantial challenges when deploying foundation models, particularly in terms of the high demands on memory, processing power, and energy consumption. These issues are especially problematic for edge devices of computer networks, where processing power and on-chip memory are limited.
[0003] To address these challenges, research has been performed on optimizing attention computation for hardware efficiency. In cloud environments, multi-core parallelism and advanced on-chip memory hierarchies on GPUs have been utilized to boost performance. Approaches such as FlashAttention and Flash-Decoding exploit the parallelism of graphics processing unit (GPU) cores and the on-chip static random access memory (SRAM) to design I / O-aware exact attention algorithms. These approaches employ tiling and on-chip memory to minimize high-bandwidth memory (HBM) data access, resulting in memory savings and runtime acceleration. However, these and related methods are primarily tailored for cloud servers, where multi-core architectures are readily available. FlashAttention is described in T. Dao, D. Fu, S. Ermon, A. Rudra, and C. Re, “Flashattention: Fast and memory-efficient exact attention with io-awareness, ” Advances in Neural Information Processing Systems, vol. 35, pp. 16 344–16 359, 2022, T. Dao, “Flashattention-2: Faster attention with better parallelism and work partitioning, ” arXiv preprint arXiv: 2307.08691, 2023, and J. Shah, G. Bikshandi, Y. Zhang, V. Thakkar, P. Ramani, and T. Dao, “Flashattention-3: Fast and accurate attention with asynchrony and low precision, ” arXiv preprint arXiv: 2407.08608, 2024. Flash-Decoding is described in “T. Dao, D. Haziza, F. Massa, G. Sizov, Flash-Decoding for long-context inference, ” https: / / crfm. stanford. edu / 2023 / 10 / 12 / flashdecoding. html, accessed: 2023-10-12, and K. Hong, G. Dai, J. Xu, Q. Mao, X. Li, J. Liu, K. Chen, H. Dong, and Y. Wang, “Flashdecoding++: Faster large language model inference on gpus, ” arXiv preprint arXiv: 2311.01282, 2023.
[0004] On edge devices, researchers have explored graph fusion techniques to minimize data transfers between off-chip and on-chip memory during attention inference. For instance, oneDNN introduces graph fusion templates with microkernels to accelerate attention on Intel CPUs. FLAT proposes an attention fusion algorithm that uses row-granularity tiling and on-chip storage of intermediate data to alleviate off-chip memory bandwidth bottlenecks, achieving significant speedup and energy savings.
[0005] Despite these efforts to enhance operator fusion and data locality, optimizing attention computation on edge devices remains a significant challenge. First, the limited cores and on-chip memory available on edge accelerators make it difficult to deploy parallel computing schemes like FlashAttention. Second, efficiently utilizing heterogeneous compute units in parallel on edge accelerators remains challenging, as these units are typically designed for processing non-parallel workloads, such as matrix multiplications and softmax. Third, the optimization of tiling strategies and granularity in fused attention kernels is still under-explored for resource-constrained edge devices.
[0006] Therefore, there is a need for methods and apparatus for implementing AI transformers that obviates or mitigates one or more limitations in the prior art.
[0007] This background information is provided to reveal information believed by the applicant to be of possible relevance to the present invention. No admission is necessarily intended, nor should be construed, that any of the preceding information constitutes prior art against the present invention.SUMMARY
[0008] Embodiments of this disclosure provide for methods and apparatus for implementing artificial intelligence (AI) transformers and related computational tools. The implementation can involve a particular usage pattern for computing components such as processing elements, on-chip memory and off-chip memory. Related operations can be scheduled and pipelined appropriately in a particular manner. Accordingly, a hardware accelerator and associated methods and apparatus can be provided.
[0009] According to embodiments, there is provided a method for performing a matrix-based computation in a computing device is provided. The term "matrix-based computation" may refer to a computation involving both matrix multiplications and vector computations such as the softmax. The computing device includes a multiply-accumulate (MAC) unit for performing matrix multiplication, and a vector (VEC) unit, on-chip cache memory (shared by the MAC unit and the VEC unit) . The computing device may include an off-chip memory operatively coupled to the on-chip cache memory.
[0010] The method includes obtaining (e.g. receiving / producing) a first plurality of tiles, denoted as Qi, which collectively represent a matrix Q, which is typically a query matrix and which is referred to here as a first matrix. The method further includes, according to a first set of multiplication operations, multiplying, using the MAC unit, each of the first plurality of tiles (Qi) by a second matrix (K) to produce first intermediate result tiles (Ci) . The method further includes writing the first intermediate result tiles (Ci) to the on-chip cache memory as they are produced by the first set of multiplication operations. The method further includes obtaining, in turn, each of the first intermediate result tiles (Ci) from the on-chip cache memory and as written to the on-chip cache memory by said writing the first intermediate result tiles and, using the VEC unit and according to a set of softmax operations, producing second intermediate result tiles (Pi) indicative of respective softmaxes of each of the first intermediate result tiles (Ci) . That is, the method includes, using the VEC unit, producing second intermediate result tiles (Pi) which represent the softmax calculations of the corresponding first intermediate result tiles (Ci) . The method further includes writing the second intermediate result tiles (Pi) to the on-chip cache memory as they are produced by the set of softmax operations. The method further includes obtaining, in turn, each of the second intermediate result tiles (Pi) from the on-chip cache memory and as written to the on-chip cache memory by said writing the second intermediate result tiles and, using the MAC unit and according to a second set of multiplication operations, multiplying each of the second intermediate result tiles (Pi) by a third matrix (V) to produce output result tiles (Oi) . The method may further include, according to a first parallelization, at least one of the first set of multiplication operations, performed by the MAC unit to produce one of the first intermediate result tiles (Ci) , is performed in parallel with at least one of the softmax operations as performed by the VEC unit on another one of the first intermediate result tiles (Ci) . The method may further include, according to a second parallelization, at least one of the second set of multiplication operations, performed by the MAC unit on one of the second intermediate result tiles (Pi) , is performed in parallel with at least one of the softmax operations as performed by the VEC unit to produce another one of the second intermediate result tiles (Pi) . The method may allow for increased throughput by overlapping MatMul and Softmax computations. The method may further allow for reduced latency and improved computational efficiency.
[0011] In some embodiments, the method further includes, as part of the (e.g. first) parallelization, for at least one of the first set of multiplication operations, as soon as feasible following completion of a respective one of the second set of multiplication operations, performing said at least one of the first set of multiplication operations, whether or not one of the softmax operations is currently being performed. In some embodiments, the method further includes, as part of the second parallelization: as soon as feasible following completion of a final one of the softmax operations and when the MAC unit is available for use, performing a final one of the second set of multiplication operations.
[0012] In some embodiments, the matrix-based computation is part of an attention mechanism computation for an artificial intelligence or machine learning application. In some embodiments, the computing device is an edge computing device which has limited computational power compared to a data center computing device. In some embodiments, some or all of: the first matrix, the second matrix, the third matrix, and an output matrix (O) formed from the output result tiles (Oi) are four-dimensional tensors.
[0013] In some embodiments, the method further includes, in response to insufficient capacity in the on-chip cache memory during one of the softmax operations, when one of the first set of multiplication operations is being performed concurrently with said one of the softmax operations: halting said one of the first set of multiplication operations; and overwriting portions of the on-chip cache memory, previously allocated for storing components of the second matrix (K) used as input in said one of the first set of multiplication operations, with results of said one of the softmax operations. In some embodiments, the method further includes, in response to insufficient capacity in the on-chip cache memory during one of the softmax operations, when one of the second set of multiplication operations is being performed concurrently with said one of the softmax operations: halting said one of the second set of multiplication operations, and overwriting portions of the on-chip cache memory, previously allocated for storing components of the third matrix (V) used as input in said one of the second set of multiplication operations, with results of said one of the softmax operations. The method may allow for improved memory usage by ensuring effective use of on-chip memory by balancing buffer space and computation needs. The method may further allow for reduced pipeline stalls.
[0014] In some embodiments, the method further includes following completion of said one of the softmax operations, restarting or resuming said one of the first set of multiplication operations or said one of the second set of multiplication operations, said repeating or resuming comprising reloading data from the off-chip memory to the on-chip cache memory. The method may allow for improved memory usage by ensuring effective use of on-chip memory by balancing buffer space and computation needs. The method may further allow for reduced pipeline stalls.
[0015] In some embodiments, at least one of the first plurality of tiles (Qi) is a four-dimensional tensor having dimension sizes Bb, Hh, NQ and E. In some embodiments, the second matrix (K) is a four-dimensional tensor having dimension sizes B, H, N and E. In some embodiments, at least one of the first set of multiplication operations, to produce one of the first intermediate result tiles (Ci) , includes selecting a portion (Ki) of the second matrix (K) , the portion (Ki) having dimension sizes Bb, Hh, NK, V and E, wherein NK, V is less than or equal to N and is based at least in part on a criterion of fitting computation results into the on-chip cache memory. In some embodiments, the at least one of the first set of multiplication operations, to produce one of the first intermediate result tiles (Ci) , further includes dividing the portion (Ki) of the second matrix (K) into a second plurality of tiles (Kij) . In some embodiments, the at least one of the first set of multiplication operations, to produce one of the first intermediate result tiles (Ci) , further includes loading said one of the first plurality of tiles (Qi) into the on-chip cache memory. In some embodiments, the at least one of the first set of multiplication operations, to produce one of the first intermediate result tiles (Ci) , further includes for each one of the second plurality of tiles (Kij) , separately: loading said one of the second plurality of tiles into the on-chip cache memory, computing a matrix product (Cij) of said one of the first plurality of tiles (Qi) times said one of the second plurality of tiles (Kij) , and storing the matrix product (Cij) to the on-chip cache memory as a portion of said one of the first intermediate result tiles (Ci) . The method may allow for improved memory utilization by using fine-grained tiling to manage large matrices effectively within memory constraints.
[0016] In some embodiments, the dimension sizes Bb, Hh, NQ and NK, V are defined by an optimization routine which is configured based on hardware parameters of the computing device. In some embodiments, the hardware parameters include one or more of: size of the on-chip cache memory; bandwidth of the on-chip cache memory; size of the off-chip memory; and bandwidth of the off-chip memory.
[0017] In some embodiments, at least one of the set of softmax operations, to produce one of the second intermediate result tiles (Pi) , includes dividing a corresponding one of the first intermediate result tiles (Ci) , already held in the on-chip cache memory, into a plurality of sub-tiles (Cij) . In some embodiments, the at least one of the set of softmax operations, to produce one of the second intermediate result tiles (Pi) , further includes, for each one of the plurality of sub-tiles (Cij) , separately, performing a softmax computation on said one of the plurality of sub-tiles (Cij) , and storing a result of the softmax computation to the on-chip cache memory as a portion (Pij) of said one of the second intermediate result tiles (Pi) . The method may allow for improved computational efficiency by employing row-granularity tiling.
[0018] In some embodiments, the softmax computation includes a plurality of sub-computations. In some embodiments, all of the sub-computations are performed without reading to or writing from the off-chip memory. In some embodiments, each of the plurality of sub-tiles (Cij) has dimension sizes Bb, Hh, 1 and N.
[0019] In some embodiments, at least one of the second set of multiplication operations, to produce one of the output result tiles (Oi) , includes dividing one of the second intermediate result tiles (Pi) , already held in the on-chip cache memory, into a second plurality of tiles (Pij) . In some embodiments, the at least one of the second set of multiplication operations, to produce one of the output result tiles (Oi) , further includes selecting a corresponding portion (Vi) of the third matrix (V) . In some embodiments, the at least one of the second set of multiplication operations, to produce one of the output result tiles (Oi) , further includes dividing the portion (Vi) of the third matrix into a third plurality of tiles (Vij) . In some embodiments, a total number (Tc) of the second plurality of tiles equals a total number of the third plurality of tiles. In some embodiments, the at least one of the second set of multiplication operations, to produce one of the output result tiles (Oi) , further includes initializing a portion of the on-chip cache memory to hold the output result tile (Oi) . In some embodiments, the at least one of the second set of multiplication operations, to produce one of the output result tiles (Oi) , further includes for each one of the third plurality of tiles (Vij) , sequentially in turn, loading said one of the third plurality of tiles (Vij) into the on-chip cache memory, computing a matrix product of a corresponding one of the second plurality of tiles (Pij) times said one of the third plurality of tiles (Vij) to produce a partial product, and adding the partial product to contents of the portion of the on-chip cache memory to thereby additively accumulate the partial products produced over all of the second plurality of tiles in the portion of the on-chip cache memory. The method may allow improve memory utilization by using fine-grained tiling to manage matrices effectively within limited memory constraints.
[0020] In some embodiments, the total number (Tc) equals approximately N / NK, V, where N is a dimension size of said one of the second intermediate result tiles (Pi) and also a dimension size of said one of the portion (Vi) of the third matrix, and NK, V is a dimension size of each one of the second plurality of tiles (Pij) and also a dimension size of each one of the third plurality of tiles (Vij) .
[0021] In some embodiments, the first matrix (Q) , the second matrix (K) and the third matrix (V) are four-dimensional tensors having dimension sizes B, H, N and E. In some embodiments, each one of the first plurality of tiles (Qi) is a four-dimensional tensor having dimension sizes Bb, Hh, NQ and E. In some embodiments, each one of the first intermediate result tiles (Ci) is a four-dimensional tensor having dimension sizes Bb, Hh, NQ and N. In some embodiments, each one of the second intermediate result tiles (Pi) is a four-dimensional tensor having dimension sizes Bb, Hh, NQ and N. In some embodiments, each one of the output result tiles (Oi) is a four-dimensional tensor having dimension sizes Bb, Hh, NQ and E. In some embodiments, each one of the second matrix (K) , the third matrix (V) , and the second intermediate result tiles (Pi) are divided so as to have a size NK, V along a respective dimension thereof. In some embodiments, the dimension sizes Bb, Hh, NQ and NK, V are defined by an optimization routine which is configured based on hardware parameters of the computing device. The method may allow for adaptive tiling in real-time by adjusting to varying conditions.
[0022] In some embodiments, the hardware parameters include one or more of: size of the on-chip cache memory, bandwidth of the on-chip cache memory, size of the off-chip memory, and bandwidth of the off-chip memory.
[0023] In some embodiments, Bb<B, Hh<H, NQ<N and NK, V<N. In some embodiments, Bb, Hh, NQ and NK, V specify tiling sizes for subdividing one or more of the first matrix (Q) , the second matrix (K) and the third matrix (V) to facilitate reduction in usage of the off-chip memory.
[0024] According to embodiments, there is provided another method for performing a matrix-based computation in a computing device. The computing device includes a multiply-accumulate (MAC) unit and a vector (VEC) unit. The method includes, performing in parallel, a matrix multiplication operation of a plurality of matrix multiplication operations performed on the MAC unit, and a softmax operation of a plurality of softmax operations performed on the VEC unit.
[0025] In some embodiments, each softmax operation is based on an output of a corresponding one of the plurality of matrix multiplication operations. In some embodiments, the plurality of matrix multiplication operations and the plurality of softmax operations interact with one another via inputs and outputs written to, remaining in, and read from an on-chip cache memory of the computing device. In some embodiments, the plurality of matrix multiplication operations include a first subset of matrix multiplication operations, each of which provides an output for use by a corresponding one of the plurality of softmax operations. In some embodiments, the plurality of matrix multiplication operations further include a second subset of matrix multiplication operations, each of which operates based on output of said corresponding one of the plurality of softmax operations or another corresponding one of the plurality of softmax operations.
[0026] In some embodiments, the method further includes subdividing matrices into tiled matrices having a size which is sufficiently small to be held in an on-chip cache memory of the computing device. In some embodiments, the plurality of matrix multiplication operations and the plurality of softmax operations operate on said tiled matrices and produce further corresponding tile matrices which are also sufficiently small to be held in the on-chip cache memory of the computing device.
[0027] In some embodiments, the plurality of matrix multiplication operations involve at least one matrix from matrices Q, K, V of an attention mechanism computation for an artificial intelligence or machine learning application. In some embodiments, the computing device is an edge computing device.
[0028] In some embodiments, the matrix-based computation is a mixed computation involving matrix-based operations and vector-based operations performed in a pipelined manner and parallelized due to concurrent usage of the MAC unit and the VEC unit.
[0029] According to embodiments, there is provided a computing device configured to perform one or more methods described herein. For example, the computing device is configured to perform a matrix-based computation. The computing device includes a MAC unit for performing matrix multiplication, a VEC unit. The computing device may further include an on-chip cache memory shared by the MAC unit and the VEC unit. The computing device may further include an off-chip memory operatively coupled to the on-chip cache memory. The computing device is configured to obtain (e.g. receiving / producing) a first plurality of tiles (Qi) which collectively represent a first matrix (Q) . The computing device is further configured to, according to a first set of multiplication operations, multiply, using the MAC unit, each of the first plurality of tiles (Qi) by a second matrix (K) to produce first intermediate result tiles (Ci) . The computing device is further configured to write the first intermediate result tiles (Ci) to the on-chip cache memory as they are produced by the first set of multiplication operations. The computing device is further configured to obtain, in turn, each of the first intermediate result tiles (Ci) from the on-chip cache memory and as written to the on-chip cache memory by said writing the first intermediate result tiles and, using the VEC unit and according to a set of softmax operations, produce second intermediate result tiles (Pi) indicative of respective softmaxes of each of the first intermediate result tiles (Ci) (i.e. which represent the softmax calculation results of corresponding tiles Ci) . The computing device is further configured to write the second intermediate result tiles (Pi) to the on-chip cache memory as they are produced by the set of softmax operations. The computing device is further configured to obtain, in turn, each of the second intermediate result tiles (Pi) from the on-chip cache memory and as written to the on-chip cache memory by said writing the second intermediate result tiles and, using the MAC unit and according to a second set of multiplication operations, multiply each of the second intermediate result tiles (Pi) by a third matrix (V) to produce output result tiles (Oi) . The computing device is further configured, according to a first parallelization, to perform at least one of the first set of multiplication operations, by the MAC unit to produce one of the first intermediate result tiles (Ci) , in parallel with at least one of the softmax operations as performed by the VEC unit on another one of the first intermediate result tiles (Ci) . The computing device is further configured, according to a second parallelization, to perform at least one of the second set of multiplication operations, performed by the MAC unit on one of the second intermediate result tiles (Pi) , in parallel with at least one of the softmax operations as performed by the VEC unit to produce another one of the second intermediate result tiles (Pi) .
[0030] According to some embodiments, a computing device is configured to perform a matrix-based computation. The computing device includes a MAC unit and a vector (VEC) unit. The computing device configured to perform in parallel, a matrix multiplication operation of a plurality of matrix multiplication operations performed on the MAC unit and a softmax operation of a plurality of softmax operations performed on the VEC unit.
[0031] In accordance with embodiments, there is provided an electronic apparatus in a communication network (e.g. at the edge thereof) , the apparatus comprising a processor, a network interface and a memory and configured to perform one or more of the methods as described herein. In accordance with embodiments, there is provided a system of such electronic apparatuses, networked together and configured to interact to perform one or more of the methods as described herein. These apparatuses may be in the form of an edge computing device or component thereof.
[0032] In accordance with an embodiment of the present disclosure, there is provided a computer configured to implement one or more methods described herein. In some embodiments, the computer includes the computing device.
[0033] In accordance with an embodiment of the present disclosure, there is provided a computer program product comprising a (e.g. non-transitory) computer readable medium having statements and instructions stored thereon which, when executed by one or more computer processors, cause the computer processors to perform the method as set forth above. The computer processors may be parts of one or more electronic apparatuses (e.g. network entities) as described herein.
[0034] Embodiments have been described above in conjunctions with aspects of the present invention upon which they can be implemented. Those skilled in the art will appreciate that embodiments may be implemented in conjunction with the aspect with which they are described, but may also be implemented with other embodiments of that aspect. When embodiments are mutually exclusive, or are otherwise incompatible with each other, it will be apparent to those skilled in the art. Some embodiments may be described in relation to one aspect, but may also be applicable to other aspects, as will be apparent to those of skill in the art.BRIEF DESCRIPTION OF THE DRAWINGS
[0035] Further features and advantages of the present invention will become apparent from the following detailed description, taken in combination with the appended drawings, in which:
[0036] FIG. 1 illustrates a hardware configuration for edge devices which may implement embodiments of the present disclosure.
[0037] FIG. 2 illustrates a multi-tiered tiling and computation strategy for attention computation, according to an embodiment.
[0038] FIG. 3A illustrates a set of operations for efficient processing of first matrix multiplications in an attention mechanism, according to an embodiment.
[0039] FIG. 3B illustrates a flowchart outlining a method for processing of first matrix multiplication in an attention mechanism using a multi-tiered tiling strategy, according to an embodiment.
[0040] FIG. 4A illustrates a set of operations for an efficient Softmax computation forming part of a pipelined approach with row-granularity tiling, according to an embodiment.
[0041] FIG. 4B illustrates a flowchart outlining a method for performing a Softmax computation with row-granularity tiling, according to an embodiment.
[0042] FIG. 5A illustrates a set of operations for generating an output matrix in the attention mechanism via matrix multiplication, according to an embodiment.
[0043] FIG. 5B illustrates a flow chart outlining a method for matrix multiplication to produce output matrix in the attention mechanism, according to an embodiment.
[0044] FIG. 6A illustrates a set of operations for a pipelined attention mechanism, according to an embodiment.
[0045] FIG. 6B illustrates a flowchart outlining a method for pipelined attention mechanism with parallel MAC and VEC operations, according to an embodiment.
[0046] FIG. 7 illustrates a scheduling of operations in an attention mechanism, according to an embodiment.
[0047] FIG. 8 illustrates a process for a multi-tiered attention mechanism, according to an embodiment.
[0048] FIG. 9A illustrates a selective overwriting strategy for use with limited on-chip memory, according to an embodiment.
[0049] FIG. 9B illustrates another selective overwriting strategy for use with limited on-chip memory, according to an embodiment.
[0050] FIG. 10 illustrates an electronic device which may be configured to perform operations according to embodiments of the present disclosure.
[0051] FIG. 11A illustrates an example of an apparatus, according to an embodiment.
[0052] FIG. 11B illustrates an example apparatus, according to an embodiment.
[0053] FIG. 12A illustrates a method for performing a matrix-based computation in a computing device, according to an embodiment.
[0054] FIG. 12B illustrates another method for performing a matrix-based computation in a computing device, according to an embodiment.
[0055] It will be noted that throughout the appended drawings, like features are identified by like reference numerals.DETAILED DESCRIPTION
[0056] Embodiments of the present disclosure provide for methods and apparatus for implementing computing operations in support of AI transformers, particularly the attention mechanism thereof. The methods can be viewed as hardware acceleration methods and the apparatus can be viewed as a hardware accelerator, for accelerating the attention mechanism. The methods and apparatus can be implemented on an edge device of a network, and indeed various embodiments may be particularly suitable for implementation on such edge devices, where processing power and memory are limited, e.g. relative to core devices typical of cloud computing environments.
[0057] Edge devices may include smartphones, mobile devices, personal computers, laptops, Internet of Things (IoT) devices, augmented reality (AR) or virtual reality (VR) headsets, or the like. The edge devices may run a neural network inference for just its owner or local user. The edge devices may only have a limited number of computing units (MAC and VEC units) , e.g., having 2 cores each with only one MAC and VEC unit. In contrast, data center or cloud computing devices can relate to large data centers and can have a comparatively large number of computing chip (GPU, TPU, etc. ) clusters, which can handle the neural network inference requests from multiple users. A computing device in a data center or cloud generally has significantly higher processing power, more cores, larger and faster memory, etc.
[0058] Embodiments incorporate parallelization to facilitate performance of the attention mechanism. In the parallelization, multiple processors or cores (e.g. of a multi-core GPU) , if present, can potentially be utilized in an organized manner. Sub-components of a core, e.g. the MAC and VEC units, are also operated in parallel.
[0059] Embodiments are configured to make efficient use of available memory. In particular, memory access patterns can be implemented in an efficient or optimized pattern. The sizes of matrix tiles can be configured to support this feature, by working on suitable matrix tiles which can fit into available on-chip memory. Tiles, also referred to as blocks, are different (typically non-overlapping) portions of a matrix, such as a four-dimensional matrix. Sub-tiles / sub-blocks are tiles / blocks that are portions of a referred-to tile / block. The term “sub-matrix” can be similarly used.
[0060] Embodiments incorporate on-chip computation, in which intermediate computations are performed on computing device (e.g. edge device) chips, to limit or minimize off-chip operations such as memory accesses, and also performing efficient memory utilization. Thus for example the number of transfers between on-chip memory (also referred to as on-chip cache memory) and off-chip memory can be limited. Accordingly, in various instances herein, information is obtained from on-chip cache memory and as written to the on-chip cache memory by an earlier process, to emphasize that the information is not transferred to off-chip memory and then later reloaded to on-chip memory. (It is noted that the information can nevertheless be transferred to off-chip memory at any time. ) As such, various operations interact with one another via respective inputs and outputs (information) where the inputs are written to and remain in on-chip memory, and are subsequently read from such on-chip memory from this written and remaining aspect. This results in a significant reduction in data movement, and corresponding reduction in resource (e.g. time, power) consumption.
[0061] Embodiments provide for a particular stream processing scheme that handles tiled matrix multiplication (MatMul) and Softmax computations in a pipelined manner. As will be readily understood, the Softmax function is a generalization of a logistic function, which is used in neural networks and other artificial intelligence implementations. Embodiments utilize both matrix accumulator (MAC) units and vector (VEC) units in parallel with semi-synchronous computation. Various embodiments are configured to be adaptable to edge device hardware (e.g. rather than optimized solely for GPU architectures) , thus providing a versatile solution for various deployment scenarios.
[0062] As will be readily understood, MAC units and VEC units are types of hardware processing units optimized for their respective tasks. MAC units accumulate the results of matrix multiplications and are useful for executing operations in AI workloads, such as in deep learning models, e.g. where they efficiently handle dot product calculations. VEC units process vectors (sequences of data elements) and may accelerate operations such as vector addition, multiplication, and other linear algebra tasks commonly encountered in machine learning and AI workloads.
[0063] Embodiments of the present disclosure provide for a particular execution strategy. In particular, embodiments leverage a pipelined execution model, allowing parallel processing of matrix operations and Softmax calculations. For example, the intermediate results of attention mechanisms can be computed on-chip and only the final output stored in DRAM, utilizing a pipelined and parallel (rather than sequential) execution strategy. This approach not only reduces overall latency but also enhances the utilization of on-chip resources, making such embodiments potentially suitable for high-performance tasks on edge devices. An intermediate result is stored to on-chip memory and subsequently retrieved from the on-chip memory, without transferring, or at least without necessarily transferring, the result to off-chip memory in the interim.
[0064] Embodiments of the present disclosure provide for a proactive buffer overwrite strategy to facilitate efficient on-chip memory utilization, even under the constraints of edge devices.
[0065] Moreover, and in view of the above, embodiments of the present disclosure provide for a combination of pipelined execution, parallelism, and memory management for accelerating AI tasks in resource-constrained environments such as those of edge devices.
[0066] FIG. 1 illustrates a hardware configuration for edge devices, such as a mobile device. The hardware 100 includes off-chip memory 125, such as DRAM, which may be 6GB, 16GB, or other capacities, connected to one or more cores. In this example, the mobile device includes two cores (Core [0] 110 and Core [1] 120) , each connected to processing units and memory hierarchies that facilitates data processing for various operations.
[0067] Each core is equipped with two processing units: a MAC unit 112 and 122 and a VEC unit 122 and 124. The MAC unit may be dedicated to performing matrix multiplication operations, for example involving the matrices Q, K, and V as described herein. The VEC unit handles vector operations, including operations such as Softmax, used for maintaining computational precision during tasks like attention mechanism inference.
[0068] In some embodiments, each core is connected to an L1 cache (e.g., 5MB) shared by the MAC unit and the VEC for efficient memory access . This memory hierarchy is further supported by an L0 cache for data locality and reduce off-chip memory accesses. The multi-tiered memory structure supports optimized workload balancing, allowing for real-time adjustments based on the computation demands of the system.
[0069] As used herein, on-chip cache memory may include both of the L0 cache and L1 cache. For operations which require transferring of information between the MAC and VEC units of a same core, the L1 cache is generally used. It should be understood that L0 cache memory size is generally smaller than L1 cache memory size, which is in turn generally smaller than L2 memory size. At the same time, accesses to L0 cache memory are generally faster and more energy efficient than access to L1 cache memory, which in turn are generally faster and more energy efficient than access to L2 cache memory.
[0070] The coordination between the multiple cores and the memory hierarchy may support operations involving matrix computations as described in one or more embodiments herein. Computing tasks can be separated into portions, each of which is performed by a different core in parallel. Parallelization within a core is also implemented, as described in detail herein.
[0071] FIG. 2 illustrates a multi-tiered tiling strategy for attention computation, according to an embodiment. FIG. 2 shows an overview of various embodiments of the present disclosure. Computing resources include a processing element 205, on-chip memory 210 and off-chip memory 215. The processing element (PE) 205 may be the smallest computational unit within a larger processing architecture, responsible for executing arithmetic and logic operations. The PE 205 may be equipped with at least one MAC unit for matrix multiplication and at least one VEC units for vector operations, as detailed in FIG. 1. Multiple PEs can work in parallel, and perform tasks such as matrix multiplication (handled by MAC unit (s) ) and vector processing such as Softmax (handled by VEC unit (s) ) , enhancing the overall speed of AI computations. The on-chip memory 210 may be Static Random Access Memory (SRAM) . As will be readily understood, SRAM is a type of memory that uses bistable latching circuitry to store data. Unlike Dynamic Random Access Memory (DRAM) , SRAM is typically faster and does not require refreshing, making it useful for cache memory and other applications where speed is important. For example, the SRAM may offer fast access to frequently used data, making it suitable for caching tiles of matrices Q, K, V and intermediate data such as tiles of matrices C and P from the attention mechanism as described herein. The off-chip memory 215 can be DRAM, which is a type of volatile memory that stores data temporarily while a computer is running. DRAM is widely used in systems where high memory bandwidth and low latency are important, such as in AI and deep learning tasks.
[0072] In some embodiments, off-chip memory 115 stores the larger matrices Q116, K117, V118, and the output matrix O 119 after computing the output matrix. This memory is used for bulk data storage and provides the data in tiles to the on-chip memory during processing. In some embodiments, the on-chip memory 210 serves as the temporary high-speed storage for frequently accessed data. It holds tiles (e.g., 216, 217, 218 and 219) of the matrices Q, K, V, and Q respectively, as well as tiles of the intermediate matrices C and P (e.g., 221, and 222) , facilitating pipelined computation by the PE 205.
[0073] In some embodiments, the PE 205 handles both matrix multiplication 230 and 232 using its MAC unit and vector-based operations 231 using its VEC unit. The PE works on tiles of the matrices Q and K to produce intermediate matrix C tiles, and later on the matrices P and V to compute the final output tiles of O.
[0074] FIG. 2 shows the various stages of computation, with the tiles of Q, K, V, and O moving between three stages. These stages reflect the different phases of the tiling process, starting with the loading of the initial tiles into the on-chip memory and progressing through matrix multiplication and Softmax operations.
[0075] FIG. 2 is directed in particular to processing operations for supporting an attention calculation, defined for example as follows. Given Q, K, V∈RB×H×N×E where B, H, N, and E represent batch, head, sequence length, and embedding size respectively, the attention calculation can be expressed as:
[0076] C=QKT∈RB×H×N×N
[0077] P=Softmax (C) ∈RB×H×N×N
[0078] O=PV∈RB×H×N×E
[0079] In more detail, Q represents a query matrix, K represents a key matrix, and V represents a value matrix. These matrices are separated into smaller component tiles and processed. The matrices are illustrated as having four dimensions, each with a particular respective dimension size, e.g. B, H, N and E (or the like) . Such a four-dimensional matrix, or any matrix with dimension higher than two, is also referred to herein as generalized matrix, a tensor or an array of values. In various embodiments, such a four-dimensional matrix / tensor may be treated during processing as a collection of two-dimensional matrices residing within a pair of nested loops. At each iteration of the outer loop (e.g. a FOR loop indexing from 1 to B or Bb, an inner loop is executed. At each iteration of the inner loop (e.g. a FOR loop with indexing from 1 to H or Hh) , a two-dimensional matrix processing operation is performed.
[0080] Embodiments provide for an optimized dataflow and software mapping suitable for (e.g. exact) attention calculations on edge spatial accelerators. These accelerators typically possess at least one MAC unit for matrix multiplications and at least one VEC processing unit for element-wise and reduction operations. Embodiments can operate to limit or minimize latency, energy consumption, and DRAM access, so that both compute units are effectively utilized in parallel, even under the constraints of limited on-chip memory.
[0081] Embodiments provide for a stream processing scheme that pipelines tiled matrix multiplication (MatMul) and Softmax workloads. By scheduling these tasks onto MAC and VEC units in a semi-synchronous manner, embodiments can increase or maximize parallelism while maintaining data dependency correctness.
[0082] Embodiments provide for a multi-tiered tiling scheme, with fine-grained tiling for MatMul inputs and row-granularity tiling for Softmax data. This approach balances compute unit utilization and limits or minimizes memory access overhead, using appropriate search operations for optimal tiling factor selection.
[0083] To handle scenarios with insufficient on-chip buffer, embodiments provide for a proactive buffer overwrite strategy. This technique prioritizes Softmax completion by selectively overwriting data, facilitating continuous pipeline operation without or with limited stalling, even with longer input sequences.
[0084] FIG. 2 also illustrates a multi-tiered tiling strategy, according to an embodiment. This involves adjusting (e.g. optimizing) tiling factors across multiple different levels of memory hierarchy, for a desirable performance and efficiency. The adjustments can be performed automatically and dynamically over time, according to an automatic tuning. According to various embodiments, by employing such a multi-tiered tiling strategy, optimized workload balancing and efficient memory usage can potentially be achieved. This can lead to improved overall performance and resource management for the attention mechanism.
[0085] The tiling strategy can include a fine-grained sub-matrix tiling. In more detail, the tiling sizes for the input matrices Q, K, and V are configured (or optimized) to fit within available memory constraints. This approach helps manage large matrices effectively by dividing them into smaller, manageable tiles that may improve computational efficiency. In some embodiments, the multi-tiered tiling strategy handles the Q, K and V matrices, where tiling breaks these large matrices into smaller sub-matrices or tiles that fit into on-chip memory, to leverage improved use of both MAC and VEC units as described herein. For instance, as described in FIG. 3A, the matrix multiplication step involves loading tiles of Q and K, performing matrix multiplication using the MAC unit, and writing the partial result (tiles of C) into on-chip memory, reducing the frequency of off-chip DRAM accesses. FIG. 2 schematically illustrates matrices Q, K, V and output matrix O separated into tiles, and certain tiles (with index s) being loaded into on-chip memory. Different sets of Q, K and V input tiles are processed together to generate different corresponding output tiles of O.
[0086] A sub-matrix size (rows and columns) is configured so that, given a current capacity in memory, the sub-matrix and other sub-matrices to be processed with it, are able to be fully contained in on-chip memory. Given constrained memory, e.g. of edge devices, the matrices Q, K, V may be tiled into smaller sub-matrices. Q is typically partitioned into smaller “row wise sub-matrices, ” e.g. having a unit length in a certain dimension. The row-wise condition is not necessary for K and V partitioning.
[0087] The tiling strategy can include a row-granularity tiling for intermediate data. For intermediate data (e.g. C and P matrices) used in the Softmax operations, row-granularity tiling is applied, in which a tile has dimension size of one, along at least one dimension. This facilitates accurate execution of the Softmax across all data rows, which in turn facilitates maintaining computation precision and performance. For example, the tiling strategy includes row-granularity tiling for Softmax computations, as described in reference to FIG. 4A. By dividing intermediate matrices, such as C, into rows and performing the Softmax operation tile-by-tile, the VEC unit can handle the necessary vector operations.
[0088] Once the Softmax operation is completed, the results (tiles of P) are used in a second matrix multiplication with (tiles of) the V matrix to generate (tiles of) the final output matrix (O) as described in reference to FIG. 5A This stage, too, follows the multi-tiered tiling strategy where both P and V are tiled to fit into on-chip memory, and the MAC unit is employed to perform the necessary matrix multiplications on the tiles. The completed output tiles (tiles of O) are written to off-chip memory for further use, for example as such ofO tiles are generated.
[0089] The tiling strategy can include establishing or using a comprehensive search space for tiling parameters across each memory hierarchy level. The space is searched with the goal of identifying optimal (or at least adequately good) tiling factors that streamline the entire attention computation process. A Genetic Algorithm, Monte Carlo Tree Search (MCTS) , and Grid Search may be used as searching algorithms for the proposed search space. MCTS is a heuristic search algorithm used for decision-making in AI, particularly in games and planning problems. MCTS explores possible moves in a tree structure by simulating random samples, making it effective for optimizing strategies in complex environments.
[0090] In various embodiments, the tiling strategy involves defining a comprehensive search space for tiling parameters across each memory hierarchy level, particularly focusing on tiles for B (batch size) , H (number of heads) , NQ (query sequence length) , and NK, V (key and value sequence lengths) . These searchable parameters are defined at each level of the memory hierarchy so that, given the algorithm and the user's input, the optimized parameters are identified for off-chip and on-chip load and store operations. This search aims to identify optimal-or at least sufficiently effective-tiling factors that streamline the entire attention computation process. The search may be important due to the dual dependency on hardware and the stream-processing algorithm. Given the pipelined execution across operators and the shared use of memory in embodiments of the present disclosure, memory constraints become even tighter. Therefore, selecting the best tiling configuration can be important for maintaining efficiency.
[0091] To explore this search space, algorithms such as Genetic Algorithm, Grid Search, and Monte Carlo Tree Search (MCTS) may be employed. MCTS, a heuristic search algorithm typically used for decision-making in AI tasks like games and planning, is especially useful here as it simulates various tile configurations in a tree structure. By randomly sampling and evaluating different tiling strategies, MCTS can effectively optimize the process in the complex environment of pipelined attention execution.
[0092] In some embodiments, each of a first matrix (Q) , a second matrix (K) and a third matrix (V) is a four-dimensional tensors having dimension sizes B, H, N and E. In some embodiments, each one of the first plurality of tiles (Qi) (as defined herein) is a four-dimensional tensor having dimension sizes Bb, Hh, NQ and E. In some embodiments, each one of the first intermediate result tiles (Ci) (as defined herein) is a four-dimensional tensor having dimension sizes Bb, Hh, NQ and N. In some embodiments, each one of the second intermediate result tiles (Pi) (as defined herein) is a four-dimensional tensor having dimension sizes Bb, Hh, NQ and N. In some embodiments, each one of the output result tiles (Oi) is a four-dimensional tensor having dimension sizes Bb, Hh, NQ and E. In some embodiments, each one of the second matrix (K) , the third matrix (V) , and the second intermediate result tiles (Pi) are divided so as to have a size NK, Valong a respective dimension thereof. In some embodiments, the dimension sizes Bb, Hh, NQ and NK, V are defined by an optimization routine which is configured based on hardware parameters of the computing device. In some embodiments, these dimension sizes represent the tiling sizes used for each respective dimension. For example, Bb refers to the subdivision of the batch size B into smaller segments, i.e., B → Bb. Bb denotes the optimal batch size that can be loaded into the on-chip memory during each processing stage, allowing for improved memory usage and computation.
[0093] In some embodiments, hardware parameters may include one or more of: size of the on-chip cache memory, bandwidth of the on-chip cache memory, size of the off-chip memory, and bandwidth of the off-chip memory.
[0094] In some embodiments, the dimension sizes Bb, Hh, NQ and NK, V are less than their corresponding values, B, H, N, and N respectively, which may facilitate improved tiling. In some embodiments, these dimension sizes Bb, Hh, NQ and NK, V specify tiling sizes for subdividing one or more of the first matrix (Q) , the second matrix (K) and the third matrix (V) to facilitate reduction in usage of the off-chip memory.
[0095] In some embodiments, the tiling strategy may include adaptive tiling. The optimization process may be adaptive, and may include adjusting tiling factors in real-time based on workload and available resources. This adaptation facilitates sustained high performance under varying conditions.
[0096] The tiling strategy may include an effective utilization of tiling parameters, such as Bb, Hh, NQ and NK, V, which specify sizes (dimension sizes) of tiles in respective dimensions of a four-dimensional matrix / tensor. After search and evaluation, an effective (possibly: most effective) set of tiling parameters can be determined for use in the attention mechanism. The tiling parameters may be optimized and may result in balanced workload distribution and desirably good memory management.
[0097] FIG. 3A illustrates a set of operations for efficient processing of first matrix multiplications in an attention inference. The operations 300 employ a multi-tiered tiling strategy that provides for (e.g. optimizes, balances) memory usage and processing efficiency. The operations are for producing Ci tiles, i.e. tiles of a first intermediate matrix C.
[0098] The operations begin with a matrix setup, in operation 301. Matrices Qiand K are defined, where Qi (atile of Q) is of size Bb× Hh × NQ × E and K is of size B× H × N × E. The goal is to compute the output matrix Ci , where Ci equals Qi multiplied by the transpose of Kmatrix. The matrices Qi and K are to be stored in off-chip memory (e.g. DRAM) . Bb, Hh, NQand E are dimension sizes (also referred to as tiling parameters) for the matrix tile Qi. In other words, Qi is a four-dimensional matrix / tensor having, in each dimension, a number of elements / entries corresponding to one of these dimension sizes. Because operations are performed on Qi, only an optimized sub-matrix (tile) is loaded into on-chip memory. The dimension sizes of sub-matrix Qi are batch size Bb, head size Hh, and sequence length NQ (rows of query) which may have been determined from a search as described already above.
[0099] It is also noted that, in operation 301, subscripts b and e on values b, h and n related to index I mean “beginning” and “end, ” respectively, while the values b, h and n themselves refer to batch size, head size and sequence length.
[0100] According to a tiling strategy, in operations 302 and 303, the matrix K is divided into smaller tiles Kiwith dimensions (dimension sizes) Bb × Hh × NK, V × E, where NK, V represents a dimension size such that the tile fits within the on-chip memory (e.g. SRAM) . In some embodiments, the dimension sizes Bb, Hh, NQ and NK,V are defined by an optimization routine which is configured based on hardware parameters of the computing device. In some embodiments, the hardware parameters include one or more of: size of the on-chip cache memory; bandwidth of the on-chip cache memory; size of the off-chip memory; and bandwidth of the off-chip memory. Operations 302 and 303 impose the searched optimal tile sizes on batch size (Bb) , head size (Hh) and sequence length on K, V (NK, V) as inputs.
[0101] In operation 302 a tile of K, namely Ki, is selected. In operation 303, this tile Kiis divided into tiles. The function is the ceiling function.
[0102] Memory Allocationis performed in operation 304. On-chip memory (e.g. SRAM) is allocated for the matrices Qi , Ki, j (the above-defined tiles of K) , and Ci. This memory management facilitates data locality, reducing the need for off-chip memory accesses.
[0103] Tiled multiplication is performed in operations 305 to 310. The matrix Qi is first loaded 305 from off-chip memory (e.g. DRAM) into on-chip memory. This is accompanied (e.g. followed) by iterative loading and multiplication of Ki, j tiles with Qi. The partial products are accumulated to form the final Ci matrix. In more detail, a Ki, j tile is loaded 307 in turn from off-chip memory into on-chip memory and then multiplied 308 with Qi. Each Ki, j tile is loaded in turn into on-chip memory and then multiplied with its Qi tile, the result sent to the accumulator, and then the next Ki, j tile loaded and the process repeats. The result of the multiplication is set as a tile of theCi matrix, which is written 309 to memory. The process then repeats (306, 310) for the next Ki,j tile and so on.
[0104] FIG. 3B illustrates a flowchart outlining a method for processing matrix multiplication in an attention mechanism using a multi-tiered tiling strategy, according to an embodiment. Method 350 may be based on operations 300 and involve obtaining tiles of matrices, performing multiplications using MAC unit, and storing intermediate results in on-chip cache memory.
[0105] The method 350 includes obtaining or receiving 351 a first plurality of tiles (Qi) , which collectively represent the first matrix Q. Some or all of the first plurality of tiles may a four-dimensional tensor with dimensions (dimension sizes) Bb × Hh × NQ × E. A second matrix K, also a four-dimensional tensor with dimensions (dimension sizes) B × H × N × E, may be similarly defined. Both Qi and K may be stored in off-chip memory (DRAM) for subsequent access for example as described below.
[0106] In some embodiments, method 350 further includes selecting 352 a portion of the second matrix K, denoted Ki, for processing. The dimensions (dimension sizes) of Ki may be Bb×Hh×NK, V×E, where NK, Vis less than or equal to N and is based at least in part on a criterion of fitting computation results into the on-chip cache memory. This selection may improve memory usage, for example by allowing such portions to be small enough for holding in on-chip memory. It is noted that NK, v is a parameter that is used for both K and V matrices. In some embodiments, the dimension sizes Bb, Hh, NQ and NK, V are defined by an optimization routine which is configured based on hardware parameters of the computing device. In some embodiments, the hardware parameters include one or more of: size of the on-chip cache memory; bandwidth of the on-chip cache memory; size of the off-chip memory; and bandwidth of the off-chip memory.
[0107] In some embodiments, method 350 further includes dividing 353 the selected portion Ki into a second plurality of tiles, labeled Ki, j. These tiles may be processed individually to manage memory and computational resources effectively, reducing the need for frequent access to off-chip memory. In some embodiments, the selecting 352 and dividing 353 operations may be integrated together into a single operation.
[0108] In some embodiments, method 350 further includes allocating 354 on-chip cache memory (e.g., SRAM) for the following: the first plurality of tiles (Qi) , the second plurality of tiles (Ki, j) , and a first intermediate result tile (Ci) . This memory allocation may ensure that all necessary data for the computations remains close to the processing units, minimizing delays caused by accessing off-chip memory.
[0109] In some embodiments, method 350 further includes loading 355 each tile Qi from off-chip memory into on-chip cache memory. In some embodiments, method 350 further includes performing iterative tiling and multiplication 356. This involves, for each tile Ki, j in the second plurality of tiles, performing the following operations. For each tile Ki, j, the tile Ki, j is loaded from off-chip memory into on-chip cache memory. Further, a MAC unit is used to perform the multiplication of Qi and Ki, j, producing a matrix product Ci, j. As (soon as) the matrix product Ci, j is produced, it is stored or written in on-chip cache memory as a portion of said one of the first intermediate result tiles (Ci) . Notably the intermediate result tiles can remain in on-chip memory for use in subsequent processing for example according to the operations of FIGs. 4A and 4B.
[0110] FIG. 4A illustrates a set of operations for an efficient Softmax computation forming part of a pipelined approach with row-granularity tiling. The operations 400 are for producing Pi tiles from Ci tiles, e.g. as obtained from the operations of FIG. 3A and method 350 of FIG. 3B.
[0111] In operation 401, which can represent an initial state or requirement, the matrix Ci with dimensions (dimension sizes) Bb×Hh×NQ×N is present in on-chip memory, e.g. due to its presence there already from the operations of FIG. 3A.
[0112] Matrix division occurs in operation 402. The matrix Ci is divided into tiles of sizeBb×Hh×1×N, where each tile represents one row of Ci. There will be NQ such tiles. Thus the tiling is of row granularity.
[0113] In operation 403, appropriate memory space is allocated in on-chip memory for holding matrix Pi, the computation of which is described below.
[0114] A row-wise maximum calculation is performed, as shown for example with respect to operation 405. For each row-tile Ci, j, the maximum value (m) in that row is computed to prevent numerical overflow during exponentiation.
[0115] An on-chip Softmax execution is performed in operations 406 to 409. After adjusting by subtracting m (from operation 405) in operation 406, the exponentiation is performed on-chip in operation 407, followed by normalization (operations 408 and 409) to produce the final probabilities in matrix Pi. The probabilities are written to on-chip memory in operation 410.
[0116] The row-wise maximum calculation and on-chip Softmax execution process repeats (operations 404 and 411) for all the tiles of Ci.
[0117] The above process may be pipelined, allowing for the Softmax calculations to be performed efficiently on each row-tile sequentially. Pipelining is described for example with respect to FIGs. 6A, 6B, 7 and 8. As described there, pipelining may pertain in particular to the pipelining of matrix multiplication operations and softmax operations. Further, the pipelining may pertain to such instances where the softmax operations depend on outputs of some of the matrix multiplications and other instances of the matrix multiplications depend on outputs of the softmax operations.
[0118] FIG. 4B illustrates a flowchart outlining a method for performing a Softmax computation with row-granularity tiling, according to an embodiment. Method 450 may be based on operations 400 and illustrate the division of intermediate result tiles (Ci) into sub-tiles and the Softmax operations on each sub-tile, with the result of the Softmax computation being written to on-chip cache memory.
[0119] According to an embodiment, method 450 includes obtaining 451 each of the first intermediate result tiles (Ci) from the on-chip cache memory. These tiles were previously written to on-chip cache memory as part of the matrix multiplication operations (operations 300) , using MAC units. The tiles may be obtained as originally written, e.g. without them being transferred off-chip and subsequently transferred back to on-chip memory. Each tile Ci may be a four-dimensional tensor with dimensions (dimension sizes) Bb×Hh×NQ×N, representing the result of earlier matrix operations.
[0120] In some embodiments, method 450 further includes dividing 452 each Ci tile into a plurality of sub-tiles Ci, j. Each sub-tile may have dimensions (dimension sizes) Bb×Hh×1×N, where NQ represents the number of sub-tiles. Notably, the dimension size of 1 may facilitate appropriateness for processing by the VEC unit, with the VEC unit performing the below-described Softmax operations.
[0121] In some embodiments, method 450 further includes allocating 453 memory in on-chip cache memory for a second intermediate result tiles Pi with dimensions (dimension sizes) Bb, Hh, NQ, N. This step may facilitate that there is sufficient on-chip memory space for the Softmax results to be written after computation.
[0122] In some embodiments, method 450 further includes performing 454Softmax operation on each sub-tile Ci, j. In some embodiments, the softmax operation on each sub-tile includes a plurality of sub-computations, and wherein all of the sub-computations are performed without reading to or writing from the off-chip memory
[0123] In some embodiments, operations 454 include, for each sub-tile Ci, j, computing a row-wise maximum value of Ci, j to prevent numerical overflow during exponentiation. Operations 454 further include, for each sub-tile Ci, j, subtracting the row-wise maximum from each element of Ci, j. Each adjusted element of Ci, j is then exponentiated. Further, the row elements are summed, forming a row-wise sum. Each element is then divided by the row-wise sum to normalize the values. This normalization step finalizes the Soft max computation for each sub-tile Ci, j. One or more Softmax operations may use the VEC unit, which is designed for performing vector operations such as exponentiation and normalization.
[0124] In some embodiments, method 450 further includes writing 455 the result of the Softmax computation Pi, j for each sub-tile Ci, j to on-chip cache memory as part of the second intermediate result tiles Pi. Each sub-tile Pi, j forms a portion of the second intermediate result tile Pi. Once all sub-tiles Ci, j have been processed and their corresponding Softmax results Pi, j have been written to on-chip cache memory, the results are accumulated to form the complete second intermediate result tiles Pi. The second intermediate result tiles Pi are stored in on-chip cache memory for further steps in the attention mechanism, such as matrix multiplication with V to produce the output matrix (as described in reference to FIG. 5A and 5B) . Similarly to the case for the tiles Pimay be obtained as originally written, e.g. without them being transferred off-chip and subsequently transferred back to on-chip memory.
[0125] FIG. 5A illustrates a set of operations for generating an output matrix in the attention mechanism via matrix multiplication. The operations use a multi-tiered tiling approach which may facilitate efficiency. The operations are for producing Oi tiles in part from Pi tiles, e.g. as obtained from the operations of FIG. 4A.
[0126] In operation 501, which can represent an initial state or requirement, the matrix Pi is present in on-chip memory, e.g. due to its presence there already from the operations of FIG. 4A or 4B. The matrix V is present in off-chip memory (e.g. DRAM) . The output matrix O (or memory space allocated for same) is also present or established in off-chip memory. The matrices Pi and V have dimensions (dimension sizes) Bb×Hh×NQ×N and B×H×N×E, respectively. The goal is to compute the output matrix Oi where Oi equals Pi multiplied by V. The matrices Oi (as tile portions of O) are to be stored in the off-chip memory.
[0127] In operations 502 to 504, atiling strategy is implemented. Similar to the operations of FIG. 3A, a multi-tiered tiling approach is applied to V, such that this matrix is divided into smaller tiles to fit within the available on-chip memory during the pipelining stages, as memory constraints become even more stringent in a pipelined execution. Matrix P is also subjected to (multi-tiered) tiling in operation 504. It is noted that Viand Pi are tiled so as to have the same numbers of tiles and with the tiles having compatible sizes, which facilitates the subsequent multiplication.
[0128] In operation 505, on-chip memory is allocated for the tiles Vi, j of matrix V, facilitating data locality being maintained and limiting or minimizing off-chip memory access. On-chip memory is also allocated for output matrix Oi.
[0129] In operations 506 to 511, a tiled multiplication is set up and implemented. First, in operation 506, the (previously allocated) on-memory locations for representing entries of Oi are initialized to zero, if necessary, setting up a subsequent accumulation. This is followed by the iterative loading and multiplication of Vi, j tiles with Pi. That is, Vi, j tiles are loaded from off-chip memory to on-chip memory in operation 508. The partial products are accumulated in operation 509 to form the final output matrix (tile) Oi. The iteration is represented by operations 507 and 510. Once all partial products are accumulated, the completed final output matrix (tile) Oi is written to off-chip memory in operation 511, as a part of final overall output matrix O. The accumulation of partial products may be performed without loading the partial product to off-chip memory and then subsequently reloading to on-chip memory.
[0130] FIG. 5B illustrates a flow chart outlining a method for matrix multiplication to produce output matrix in attention mechanism, according to an embodiment. Method 550 is based on operations 500 and performed at the MAC unit. Method 550 outlines the process of multiplying a second intermediate result tile Pi by the third matrix V to produce an output result tile Oi.
[0131] According to an embodiment, method 550 includes obtaining 551 the second intermediate result tile (Pi) from on-chip cache memory. This tile was previously written to on-chip cache memory as part of the Softmax operations described in reference to FIG. 4A and 4B. Each second intermediate result tile (Pi) may be a four-dimensional tensor with dimensions (dimension sizes) Bb×Hh×NQ×N.
[0132] In some embodiments, method 550 further includes dividing 552 the second intermediate result tile Piinto a second plurality of tiles, labeled Pi, j. Each tile Pi, j may have dimensions (dimension sizes) Bb×Hh×NQ×NK, V, where NK, V is defined by an optimization routine which is configured based on hardware parameters of the computing device.
[0133] In some embodiments, method 550 further includes selecting 553 a corresponding portion of the third matrix V, denoted as Vi, from off-chip memory (DRAM) . The portion Vi may have dimensions (dimension sizes) Bb×Hh×N×E. Method 550 may further include dividing the portion Vi into a third plurality of tiles denoted as Vi, j. Each tile Vi, j may have dimensions (dimension sizes) Bb×Hh×NK, V×E, The total number (Tc) of the second plurality of tiles Pi, j may equal a total number of the third plurality of tiles Vi, j. In some embodiments, the total number (Tc) equals approximately N / NK, V, where N is a dimension size of said one of the second intermediate result tiles (Pi) and also a dimension size of said one of the portion (Vi) of the third matrix, and NK, V is a dimension size of each one of the second plurality of tiles (Pij) and also a dimension size of each one of the third plurality of tiles (Vij) .
[0134] In some embodiments, method 550 further includes allocating 554 a portion of the on-chip cache memory to hold the output result tile Oi with dimension sizes Bb, Hh, NQ, E. Further, method includes allocating another portion of the on-chip cache memory to hold the third plurality of tiles Vi, j with dimension sizes Bb, Hh, NK, V, E.
[0135] In some embodiments, method 550 further includes initializing 555 the output result tile Oi to zero in on-chip cache memory to prepare for accumulating the partial products.
[0136] In some embodiments, method 550 further includes performing 556 iterative tiling and multiplication operations for each tile Vi, j of the third plurality of tiles. These operations include loading said each tile Vi, jfrom off-chip memory (DRAM) into on-chip cache memory for multiplication. Further, a corresponding one of the second plurality of tiles Pi, j is multiplied by said tile Vi, j using the MAC unit to produce a partial product. The partial product is added to the current contents of the output result tile Oi in on-chip cache memory to thereby additively accumulate the partial products produced over all of the second plurality of tiles in the portion of the on-chip cache memory held for the output result tile Oi.
[0137] Once all the second plurality of tiles Vij have been processed, the accumulated partial products form the complete output result tile Oi. The output result tile Oi is then written to or stored in 557 off-chip memory (DRAM) as part of the final output matrix O.
[0138] In various embodiments, the sets of operations as illustrated in FIGs. 3A, 4A, and 5A (or 3B, 4B and 5B) are implemented in a coordinated manner, e.g. according to a stream processing and pipelined scheme, as described below. For purposes of the following discussion, the set of operations 300 of FIG. 3A, or a comparable set of operations for computing values such as those of Ci, is referred to as Routine #1; the set of operations 400 of FIG. 4A, or a comparable set of operations for computing values such as those of Pi, is referred to as Routine #2; and the set of operations 500 of FIG. 5A, or a comparable set of operations for computing values such as those of Oi, is referred to as Routine #3. It should be noted that the operations of FIGs. 3A, 4A and 5A can be varied in a variety of ways, and at least some embodiments of the present disclosure (e.g. as discussed below) can encompass such variations.
[0139] Accordingly, embodiments of the present disclosure provide for a stream processing scheme configured to efficiently handle continuous streams of tiled MatMul and Softmax workloads in a pipelined fashion. This corresponds to a parallelized MAC-VEC execution scheme for attention inference. This embodiment may involve two primary streams: one dedicated to tiled MatMul computation (as outlined in Routines #1 and #3 for production of matrices Ci and Oi) , and the other focused on tiled Softmax computation (as defined in Routine #2 for producing matrix Pi) . These streams are scheduled to overlap the tiled MatMul and Softmax computations, potentially improving or optimizing the execution time by reducing idle periods between operations.
[0140] Reference is now made to FIG. 6A, which illustrates a pipelined attention mechanism operating through three computation rounds, namely warm-up, regular and finalizing rounds. The illustrated operations 600 pertained to a pipelined attention mechanism, and more particularly to a memory-aware stream (MAS) processing of the attention mechanism, also referred to as MAS-Attention.
[0141] Operation 601pertains to requiring input matrices including a first matrix Q, a second matrix K and a third matrix V in off-chip memory. Operation 602 involves obtaining a first plurality of bocks (Qi) by dividing a first matrix Q into tiles of appropriate size according to tiling parameters. Operations 603 involves dividing the output matrix O into tiles of appropriate size according tiling parameters. Operations 604 includes allocating memory space for output matrix O in off-chip memory. Operation 603 may not be necessary, at least explicitly.
[0142] The warm-up computation round involves a first tile MatMul computation and a first tile Softmax computation, corresponding to operations 605 and 611, respectively. (Note, the i=2 case (operation 606) of lines 608 to 611 can be removed from the while loop 607. )
[0143] For the first tile MatMul computation, the process 600 begins by utilizing the MAC unit to compute the first tile for the initial MatMul operation, specifically C1 = Q1KT at operation 605, using Routine #1. This step sets the foundation for subsequent computations by preparing the first part of the output matrix C1.
[0144] For the first tile Softmax computation, once C1 is computed, the VEC unit is employed to execute the first tile of the Softmax operation, resulting in P1 = Softmax (C1) at operation 611, using Routine #2. Concurrently, i.e. in parallel 609, the MAC unit starts computing the second tile for the first MatMul operation, denoted as C2 = Q2KTat operation 610, using Routine #1. This parallel processing marks the beginning of the pipelined execution. Operations 610 and 611 may refer to an instance of a first parallelization, where MAC unit and VEC unit are used concurrently to perform matrix multiplication operation and softmax operations respectively. Operations 615 and 617 may refer to another instance of the first parallelization.
[0145] Operation 612 is where the pipeline moves into the next iteration after the initial computations. In the specific case where i=2, operation 612 concludes the warm-up phase, allowing the system to continue with regular computation rounds. The method handles parallel computation (Softmax and matrix multiplication) by invoking operations 300, 400, and 500 as detailed.
[0146] In the regular computation rounds, a continuous flow of tasks is maintained, as detailed below. A parallel last MatMul tile computationproceeds as follows. For any iteration i≥3, the MAC unit calculates the tile for the final MatMul operation (final in the sense of producing an output tile) as Oi-2=Pi-2V at operation 614, using Routine #3. This facilitates that the final output matrix Ois gradually assembled as each tile Oi-2 is computed.
[0147] Further, a parallel Softmax computationproceeds simultaneously, while the MAC unit processes the final MatMul as above. In this, the VEC unit computes the tile for the Softmax operation as Pi-1=Softmax (Ci-1) at operation 615, using Routine #2. The parallel execution 613 of the VEC unit may enhance the efficiency of the pipeline by keeping both units engaged.
[0148] A parallel (e.g. part of parallel execution 613) next tile of first MatMul computationis also implemented. After completing computation 614 of Oi-2, and due to waiting for this at operation 616, the MAC unit (e.g. immediately) proceeds to compute 617 the tile for the first MatMul operation, represented by Ci=QiKT. This overlap facilitates that the pipeline remains filled, limiting or minimizing idle time and increasing or maximizing throughput. In some embodiments, operations 617 is performed as soon as feasible following completion of operation 614, whether or not the softmax operation 615 is currently being performed.
[0149] Operation 618 may ensure that the next step of matrix multiplication occurs after the previous computations are complete, allowing the MAC unit to process the next tile, Ci= QiKT, in operation 617. At the same time, operation 619 increments i, allowing the loop to continue iterating for further computations until i>Tr.
[0150] Operation 620 may complete the while loop by, for example, checking the termination condition i>Tr. Once all computations are complete, operation 622 initiates the final phase of parallel execution, finalizing the computation of Oi-2 and Pi-1 as described.
[0151] The finalizing computation round, beginning at operation 621, includes the following.
[0152] A parallel final MatMul completionis performed. The MAC unit computes 626 the last tile for the final MatMul operation as Oi-1=Pi-1V, following the completion of the previous Softmax calculation at operation 624. The MAC unit waits 625 for operation 624 to complete, and then (e.g. immediately) performs operation 626. In some embodiments, operation 626 is performed as soon as feasible following completion of the softmax operations 624 and when the MAC unit is available for use.
[0153] A parallel last tile softmax completionis also performed. The VEC unit completes the last tile of the Softmax operation at operation 624, so that Pi-1=Softmax (Ci-1) is fully processed. The final round ties up all loose ends, so that that every element of the output matrix O is accurately computed. Operation 627 concludes the process, with the final output matrix O being returned to be written to the appropriate memory for further processing or output.
[0154] Parallel operations 614 and 615 and parallel operations 623 and 624 may form part of a second parallelization, where MAC unit and VEC unit are used concurrently to perform matrix multiplication operation (from the second set of multiplication operations) and softmax operations respectively.
[0155] In some embodiments, each operation 605, 610, and 617 is part of a first set of multiplication operations, based on multiplying, using the MAC unit, one of the first plurality of tiles (Qi) by a second matrix (K) to produce a corresponding intermediate result tiles (Ci) .
[0156] In some embodiments, each operation 611, 615 and 624 is part of a set of softmax operations, and each operation is performed on VEC unit and is based on a softmax operation of a corresponding one of the first intermediate result tiles (Ci) from the on-chip cache memory, and producing a corresponding intermediate result tile (Pi) .
[0157] In some embodiments, operations 614, 623 and 626 are part of a second set of multiplication operations, where each operation is performed on a MAC unit and is based on a multiplication of one of the second intermediate result tile (Pi) from the on-chip cache memory by the third matrix V to produce an output result tile (Oi) .
[0158] Operations 600 involve performing matrix and vector mixed computations in a pipelined, parallel computing fashion on a computing device. As described herein, the computing device includes a MAC unit for matrix-based computations and a VEC unit for vector-based computations. In some embodiments, the matrix multiplication operations for matrices Q, K, V use the tiling and scheduling techniques to operate on tiled matrices on the MAC unit. As the tiled matrices occupy smaller memory size, embodiments may allow for the use of on-chip memory, which offers improved processing speed than the off-chip memory, albeit with smaller memory size.
[0159] In some embodiments, operations 600 involve scheduling the tiled matrix and vector computations on the MAC and VEC units, respectively, in a pipelined, parallel fashion, as described, for example, in reference to FIG. 7. This pipelined, parallel execution of mixed matrix and vector computations may enable the use of multiple computing units on edge devices simultaneously, potentially reducing execution runtime efficiently.
[0160] Various embodiments may utilize on-chip memory to store intermediate tiled output data, with data movement from off-chip memory only performed for input data in tiles. This scheduling method may further reduce communication delays between the computing and data movement units on devices, which may improve the efficiency of computing networks that employ mixed matrix and vector computing patterns.
[0161] As described herein, operations 600 involve invoking operations 300, 400, and 500, which include detailed computations as well as data movement (reading input data and writing output data) between on-chip and off-chip memory units. In some embodiments, operations 600 use scheduling techniques to read input data from off-chip memory to on-chip memory in tiles, and to write the tiled intermediate output data only to on-chip memory (instead of off-chip memory) in order to reduce data movement time, as described in reference to operations 300, 400, and 500.
[0162] According to the above, a semi-synchronous execution is implemented, in which the overall pipelined attention mechanism operates in a semi-synchronous manner. This facilitates that during regular computation rounds, there is no data dependency among the workloads. This allows the MAC and VEC units to execute the two tiled MatMul operations and the Softmax operation in parallel. However, between computation rounds, data dependencies may need to be carefully managed to maintain the correctness of the computations.
[0163] The semi-synchronous MAC-VEC parallelism for MatMul-Softmax computations can significantly reduce the latency of the attention mechanism. This may provide for a substantial improvement in processing time over traditional sequential methods. This approach may be particularly beneficial for applications where rapid and efficient attention computation is important.
[0164] FIG. 6B illustrates a flowchart outlining a method for pipelined attention mechanism with parallel MAC and VEC operations, according to an embodiment. The method 650 is based on operations 600 of FIG. 6A and uses both MAC and VEC units to process MatMul and Softmax operations in parallel.
[0165] According to an embodiment, method 650 includes obtaining 651 the required matrices Q, K, and V from off-chip memory. These matrices may have dimensions (dimension sizes) B×H×N×E and represent the input to the attention mechanism. The parameters Bb, Hh, NQ, NK, V may control the size of the tiles for tiling and be defined by an optimization routine which is configured based on hardware parameters of the computing device.
[0166] In some embodiments, method 650 further includes dividing 652 matrix Q into Tr tiles, each with dimensions (dimension sizes) Bb×Hh×NQ×E. Similarly, the output matrix O (space allocated in DRAM for holding the output matrix) may be divided, if necessary, into Tr tiles of same dimension sizes. Further, off-chip memory, in DRAM, is allocated for the output matrix, where the final result will be stored.
[0167] In some embodiments, method 650 further includes performing 653 an initial or warm-up computation round. The initial computation round includes performing a first matrix multiplication using the MAC unit according to Routine #1 to compute C1 = Q1KT. This operation sets up the first intermediate result tile C1(operation 605) . Once C1 is ready, the VEC unit performs the softmax computation according to Routine #2 to produce P1 = Softmax (C1) , (operation 611) . While the VEC unit performs the softmax computation for P1, the MAC units begins computing the next matrix multiplication C2 = Q2KT (operation 610) . This parallel execution marks the start of the pipelined process.
[0168] In some embodiments, method 650 further includes performing 654 regular computation rounds. Referring back to FIG. 6A, the regular computation rounds start at i = 2 and proceed while i ≤ Tr. The control is handled by a while loop, with the operations differing depending on the value of i. For i = 2, the MAC unit computes, according to Routine #1, the second matrix multiplication C2 = Q2KT (operation 610) , while the VEC unit concurrently computes, according to Routine #2, P1 = Softmax (C1) (operation 611) . These two tasks (e.g., operation 610 and 611) may refer to an instance of a first parallelization, where at least one of the first set of multiplication operations (e.g., operation 610) , performed by the MAC unit to produce one of the first intermediate result tiles (Ci) , is performed in parallel with at least one of the softmax operations (operation 611) as performed by the VEC unit on another one of the first intermediate result tiles (Ci) .
[0169] For i ≥ 3, the MAC unit performs Oi-2 = Pi-2V (operation 614) using Routine #3, which calculates a portion of the final output matrix O. At the same time, the VEC unit computes Pi-1 = Softmax (Ci-1) (operation 615) . These two operations are in parallel-the MAC unit handles the matrix multiplication for Oi-2, while the VEC unit applies Softmax to Ci-1.
[0170] Once the MAC unit finishes Oi-2, it immediately or as soon as feasible, moves on to the next matrix multiplication, Ci = QiKT (operation 617) . In some embodiments, this matrix multiplication, Ci = QiKT(operation 617) , may be performed while the Softmax operation on Pi-1 may still be ongoing. For example, Ci = QiKT can start in parallel with the remaining part of the Softmax computation on Pi-1. This overlap may facilitate or ensure the pipeline remains active-as soon as the MAC unit completes one operation, it continues with the next, even if the VEC unit is still finishing its task.
[0171] In the regular computation rounds, the sequence of operations proceeds in this repeating pattern, as described above, : Oi-2 = Pi-2V (matrix multiplication by the MAC unit, operation 614) , Pi-1=Softmax (Ci-1) (Softmax operation by the VEC unit, operation 615) , Ci = QiKT (matrix multiplication by the MAC unit, operation 617) . This pattern repeats continuously until i = Tr.
[0172] In some embodiments, method 650 may include a second parallelization, where at least one of the second set of multiplication operations (e.g., operation 614) , performed by the MAC unit on one of the second intermediate result tiles (Pi) , is performed in parallel with at least one of the softmax operations (e.g., operation 615) as performed by the VEC unit to produce another one of the second intermediate result tiles (Pi) .
[0173] In some embodiments, as part of the (e.g. first) parallelization, for at least one of the first set of multiplication operations, as soon as feasible following completion of a respective one of the second set of multiplication operations (e.g., operation 614) , the method 650 further includes performing at least one of the first set of multiplication operations (e.g., operation 617) , whether or not one of the softmax operations (e.g., operation 615) is currently being performed.
[0174] In some embodiments, method 650 includes performing 655 the finalizing computation round. When i = Tr, the method transitions to the finalizing computation round 655. In this round, the MAC unit computes Oi-2=Pi-2V (operation 623) , while the VEC unit concurrently performs the final Softmax operationPi-1=Softmax (Ci-1) (operation 624) . These two tasks run in parallel, similar to the regular computation rounds. In some embodiments, operations 623 and 624 form part of the second parallelization.
[0175] In some embodiments, after the VEC unit completes the Softmax operation Pi-1, the MAC unit waits for this result to become available (operation 625) . Once the Softmax computation for Pi-1 is finished, the MAC unit proceeds with the final matrix multiplication Oi-1= Pi-1V (operation 626) . In some embodiments, operation 626 is performed as soon as feasible following completion of the softmax operations 624 and when the MAC unit is available for use. Operations 624 and 626 may be performed concurrently as part of the second parallelization.
[0176] After the last matrix multiplication is complete, the final matrix O is available in off-chip memory (DRAM) (operation 627) , due to it having been written to the off-chip memory in tile / block stages according to various instances of Routine #3 (operation 500) .
[0177] In view of the above, in some embodiments, method 650 includes, according to a first set of multiplication operations, multiplying, using the MAC unit, each of the first plurality of tiles (Qi) by a second matrix (K) to produce first intermediate result tiles (Ci) . In some embodiments, method 650 further include writing the first intermediate result tiles (Ci) to the on-chip cache memory as they are produced by the first set of multiplication operations.
[0178] Further in view of the above, in some embodiments, method 650 further include obtaining, in turn, each of the first intermediate result tiles (Ci) from the on-chip cache memory and as written to the on-chip cache memory by said writing the first intermediate result tiles and, using the VEC unit and according to a set of softmax operations (e.g., operations 611, 615 and 624) producing second intermediate result tiles (Pi) indicative of respective softmaxes of each of the first intermediate result tiles (Ci) (i.e. which represent the softmax calculation results of corresponding tiles Ci) . In some embodiments, method 650 further include writing the second intermediate result tiles (Pi) to the on-chip cache memory as they are produced by the set of softmax operations.
[0179] Further in view of the above, in some embodiments, method 650 further includes obtaining, in turn, each of the second intermediate result tiles (Pi) from the on-chip cache memory and as written to the on-chip cache memory by said writing the second intermediate result tiles and, using the MAC unit and according to a second set of multiplication operations, multiplying each of the second intermediate result tiles (Pi) by a third matrix (V) to produce output result tiles (Oi) .
[0180] In some embodiments, method 650 refers to matrix-based computation that part of an attention mechanism computation for an artificial intelligence or machine learning application. In some embodiments, method 650 is performed by a computing device or an edge device which has limited computational power compared to a data center computing device.
[0181] Method 650 may allow for a semi-synchronous execution with the repeating sequence of matrix multiplications and Softmax operations as described. Both MAC and VEC units may work in parallel as described, and the tasks being staggered to prevent or reduce idle time.
[0182] FIG. 7 illustrates timing aspects of a processing data flow for implementing operations as shown in FIG. 6A , according to an embodiment. FIG. 7 illustrates the scheduling of operations in an attention mechanism, showing the parallel, pipelined execution of tasks performed by the MAC and VEC units. The MAC and VEC units operate in tandem, with the VEC unit commencing processing on input after it becomes available from the MAC unit, and the MAC unit commencing processing on input after it becomes available from the VEC unit. MAC and VEC units (ideally) wait for their previous tasks to complete before (e.g. substantially immediately) starting a new task. The scheduling 700 of operations is based on the pipelined approach described in FIG. 6A (operations 600) and FIG. 7, method 650. According to some embodiments, the scheduling of operations 700 is structured into different phases, starting with a warm-up phase 702, followed by a series of regular computation rounds 710 spanning form t1 to t4 (including an initial regular computation round 704 and final regular computation round 706) , and concluding with a final computation round 708.
[0183] In the warm-up phase 702, which begins at t0 and ends at t1, the MAC unit first performs the computation of C1 = Q1KT (operation 605, as described in FIG. 6A) , generating the first intermediate result tile. Once C1 is ready, the VEC unit starts computing P1 = Softmax (C1) (operation 611 in FIG. 6A) . While the VEC unit is performing the Softmax computation for P1, the MAC unit moves on to calculate C2 = Q2KT(operation 610 in FIG. 6A) . This marks the beginning of parallel execution in the warm-up phase, where C2 and P1 are processed concurrently by the MAC and VEC units, respectively.
[0184] Following the warm-up phase, the process transitions into the regular computation rounds at t1, continuing until t4. Each regular computation round may include overlapping execution of tasks between the MAC and VEC units. As shown, the first regular computation round 704 occurs between t1 and t2, and the last regular computation round 706 occurs between t3 and t4.
[0185] In each regular computation round, for example, in the first regular computation round 704, the MAC unit performs a portion of the final output matrix calculation, such as O1=P1V (similar to operation 614, Oi-2=Pi-2V , described in FIG. 6A) . Concurrently, the VEC unit computes P2=Softmax (C2) (similar to operation 615, Pi-1=Softmax (Ci-1) , in FIG. 6A) . These two operations-matrix multiplication and Softmax-are executed in parallel. Once the MAC unit completes O1, it (e.g. immediately) moves on to compute C3=Q3KT (similar to operation 617, Ci= QiKT, in FIG. 6A) . In some embodiments, the computation of C3=Q3KT may start while the VEC unit is still finalizing the Softmax computation for P2. This overlap is demonstrated in the figure, where portions of the C3 calculation overlap with the P2 computation in the first regular computation round 704. This overlapping of tasks continues in the last regular computation round 706, as illustrated.
[0186] At t4, the process transitions into the final computation round 708, which continues until t5. During this phase, the MAC unit first computes Oi-2=Pi-2V (operation 623, FIG. 6A) , while the VEC unit simultaneously executes the final Softmax operation Pi-1=Softmax (Ci-1) (operation 624 in FIG. 6A) . Once the VEC unit completes the Softmax computation for Pi-1, the MAC unit proceeds (after it becomes available) to compute the final matrix multiplication Oi-1=Pi-1V (operation 626 in FIG. 6A) . This final multiplication occurs after the Softmax operation is completed. According to some embodiments, the scheduling 700 may allow for improved use of both MAC and VEC.
[0187] FIG. 8 illustrates a process for a multi-tiered attention mechanism, according to an embodiment. FIG. 8 illustrates, according to some embodiments, a process 800 for an attention mechanism that showcases matrix multiplications and Softmax operation involved in producing a final output matrix, using queries (Q) , keys (K) , and values (V) . The process 800 shows how MatMul and Softmax operations are integrated within the attention pipeline, detailing the flow of data and transformations at each stage of the process.
[0188] The query matrix Q, key matrix K, and value matrix V may be shown with two sets of dimensions: [D, D]and [B, H, N, E] . These dimensions (dimension sizes) represent different perspectives of the same matrices based on how they are structured and processed in different stages of the attention mechanism. The first set of dimension sizes [D, D] represents a combined structure of heads and embeddings, where D is expressed as D = H × E. The second set of dimension sizes [B, H, N, E] reflect how the matrices are processed in a multi-head attention mechanism.
[0189] For the query (Q) and key (K) matrices, the [B, H, N, E] structure is used while performing the multi-head attention operations. In the case of the value (V) matrix, the same dimensionality structure applies- [B, H, N, E] during the attention operations.
[0190] In some embodiments, the process 800 involves performing matrix multiplication at various stages. As shown in FIG. 8, the first multiplication 802 occurs between the query matrix Q and the transpose of the key matrix K, which results in an intermediate matrix with dimension sizes [B, H, N, N] . This intermediate matrix then undergoes a Softmax operation 804, which normalizes the values across the rows of the matrix to form attention probabilities. These probabilities are subsequently multiplied 806 by the value matrix V, producing an output matrix O with dimension sizes [B, H, N, E] .
[0191] In some embodiments, the final matrix O is transformed back into its original dimensional space, [D, D] , combining all the heads and embeddings into a single output matrix.
[0192] In some embodiments, process 800 corresponds to the processes described in embodiments herein, such as in FIGs. 6A and 7. The matrix multiplication steps outlined in FIG. 8 align with the operations described as Routine #1 (computation of Ci=QiKT) and Routine #3 (computation of Oi=PiV) in FIG. 6A. Similarly, the Softmax operation corresponds to Routine #2, where the intermediate attention matrix is normalized. The scheduling of these operations, as depicted in FIG. 7, shows how the MAC and VEC units may execute matrix multiplication and Softmax operations in parallel.
[0193] Given the constraints of limited on-chip memory, data management is important to optimizing pipelining, thereby enhancing parallelism and computational throughput. To address this, embodiments provide for a selective overwriting strategy, in relation to parallel MAC-VEC execution.
[0194] During the computation of Pi, the on-chip memory may reach capacity and further calculations may thus be impeded. To address this, two scenarios are considered below.
[0195] A first scenario pertains to MAC Unit processing of Pi-1V. In particular, according to embodiments, if the MAC unit is engaged in processing Pi-1V and on-chip memory reaches capacity, the result Pi is made to overwrite the V matrix stored on-chip. This action halts the MAC unit's current operation, preventing any further writes to the on-chip buffer from the MAC unit.
[0196] FIG. 9A illustrates a selective overwriting strategy for limited on-chip memory, according to an embodiment. According to an embodiment, in response to insufficient capacity in the on-chip cache memory during one of the softmax operations, e.g., operation 902, an overwriting strategy 900 is activated. In some embodiments, when one of the second set of multiplication operations (e.g., operation 904) is being performed concurrently with said one of the softmax operations (e.g., operation 902) , the selective overwriting strategy 900 involves halting said one of the second set of multiplication operations (operation 904) and overwriting portions of the on-chip cache memory, previously allocated for storing components of the third matrix (V) used as input in said one of the second set of multiplication operations (operation 904) , with results of said one of the softmax operations (e.g., Pi-2) .
[0197] In some embodiments, following completion of said one of the softmax operations (operation 902) , the selective overwriting strategy 900 further involves restarting or resuming said one of the second set of multiplication operations (operation 904) . In some embodiments, the repeating or resuming comprising reloading data from the off-chip memory to the on-chip cache memory.
[0198] In some embodiments, When the on-chip memory becomes full during the computation of intermediate results like Pi, the selective overwrite mechanism allows computations to continue by prioritizing specific operations, facilitating that the overall attention mechanism remains efficient despite memory limitations.
[0199] For example, a situation may arise during the computation of Pi (the result of a Softmax operation) , where the on-chip memory reaches capacity. At this point, further computations by the MAC unit, responsible for matrix multiplications such as Oi-3=Pi-3V (operation 904) , are halted to prevent additional data from being written to the already full memory buffer. This stoppage may enable the system to prioritize the continuation and completion of the VEC unit's Softmax operation, ensuring that the result of Pi-2 can overwrite the memory space previously allocated to the V matrix.
[0200] For instance, as shown in FIG. 9A, at time t1, the on-chip memory buffer reaches capacity while a vector operation, such as Pi-2=Softmax (Ci-2) (operation 902) , is being computed. The MAC unit, which is simultaneously processing Oi-3=Pi-3V (operation 904) , halts its operation to prevent memory overflow. This may ensure that the VEC unit can complete the Softmax operation and store the result Pi-2 on-chip, overwriting the existing V matrix (or parts thereof) .
[0201] As shown in FIG. 9A, once the Softmax operation is completed, at t2, and Pi-2 is written into the on-chip memory (overwriting portions of the V matrix previously stored) , the halted MatMul operation Oi-3=Pi-3V (operation 904) is restarted or resumed at time t2 or immediately afterward. This may allow the MAC unit to continue its computations without losing progress. Following the completion of operation 904, the next scheduled operation Ci-1=Qi-1KT (operation 906) is executed by the MAC unit, maintaining the normal scheduling flow as outlined in previous embodiments (e.g., scheduling 700) .
[0202] A second scenario pertains to MAC Unit Processing Qi+1KT. In particular, according to embodiments, if the MAC unit is occupied with computing Qi+1KT and on-chip memory reaches capacity, the result Pi is made to overwrite the K matrix on-chip. This interruption stops the MAC unit's process, preventing further writes to the on-chip memory.
[0203] Once the final result of Pi is fully calculated and stored on-chip, the MAC unit can resume its process. If either the V or K matrix was overwritten, the MAC unit reloads the necessary matrix from DRAM to on-chip memory and redoes the MatMul calculation.
[0204] FIG. 9B illustrates another selective overwriting strategy for limited on-chip memory, according to an embodiment. FIG. 9B illustrates, according to some embodiments, the second scenario in which the selective overwriting strategy 950 is applied when the MAC unit is occupied with matrix multiplication operations involving the Q and K matrices. In this scenario, the selective overwrite allows for the continuation of Softmax operations when the on-chip memory reaches capacity, ensuring that critical computations are prioritized.
[0205] According to an embodiment, in response to insufficient capacity in the on-chip cache memory during one of the softmax operations, e.g., operation 902, an overwriting strategy 950 is activated. In some embodiments, when one of the first set of multiplication operations (e.g., operation 906) is being performed concurrently with said one of the softmax operations (e.g., operation 902) , the selective overwriting strategy 950 involves halting said one of the first set of multiplication operations (operation 906) and overwriting portions of the on-chip cache memory, previously allocated for storing components of the second matrix (K) used as input in said one of the first set of multiplication operations (operation 906) , with results of said one of the softmax operations (e.g., Pi-2) .
[0206] In some embodiments, following completion of said one of the softmax operations (operation 902) , the selective overwriting strategy 950 further involves restarting or resuming said one of the first set of multiplication operations (operation 906) . In some embodiments, the repeating or resuming comprising reloading data from the off-chip memory to the on-chip cache memory.
[0207] For example, the MAC unit may be performing the matrix multiplication Ci-1=Qi-1KT (operation 906) , while the VEC unit is computing Pi-2=Softmax (Ci-2) (operation 902) . As depicted in FIG. 9B, at time t3, the on-chip memory buffer becomes full during the Softmax operation, preventing further storage of results. At this point, the MAC unit halts its ongoing matrix multiplication to ensure that the result of the Softmax operation can be stored in the available memory. This halting prevents the MAC unit from writing more data into the already constrained memory buffer.
[0208] Once the Softmax operation is completed, at t2, and Pi-2 is written into the on-chip memory (overwriting parts of the K matrix) , the MAC unit restarts or resumes its matrix multiplication operation Ci-1=Qi-1KT (operation 906) . This may ensure that the pipeline continues with minimal disruption. The operation scheduling continues as normal once Ci-1 is completed, with subsequent matrix multiplication and Softmax computations proceeding in the next phases of execution.
[0209] The rationale behind this strategy lies in maintaining the integrity of critical operands, which is essential for the pipeline's efficiency. Specifically, the first operands of both matrix multiplications -Q for the first MatMul and P for the last MatMul -remain unaltered. Preserving and finishing Pi=softmax (Ci) is important because the Softmax operation to calculate Pi depends on Ci =QiKT, which was obtained in a previous communication round. Overwriting Pi cannot be remedied by reloading it from DRAM. In contrast, overwriting the K and V matrices can be remedied by reloading them from DRAM without stalling the pipeline computation rounds.
[0210] In view of the above, embodiments comprise, when a capacity of on-chip memory is reached, prioritizing operations of the VEC unit over operations of the MAC unit, for example by halting the operations of the MAC unit and using memory allocated for operations of the MAC unit to complete operations of the VEC unit. Similarly, embodiments comprise, when a capacity of on-chip memory is reached, prioritizing softmax operations over matrix multiplication operations, for example by halting the matrix multiplication operations using memory allocated for the matrix multiplication operations to complete the softmax operations. The memory which is repurposed can hold input or output of the MAC unit operations / matrix multiplication operations. The halted operations are subsequently re-performed.
[0211] The above overwrite strategy facilitates efficient use of on-chip memory and computational resources. This limits or minimizes the impact of the increased number of DRAM reads on overall latency and energy savings. By appropriately managing memory overwrites and reloading only essential data, a balance can be achieved between maximizing parallelism and maintaining computational efficiency, potentially leading to improved performance and energy efficiency.
[0212] Embodiments of the present disclosure are applicable to a variety of AI workloads of foundation model-based tasks that involve attention mechanisms. These may pertain to a wide range of applications in Natural Language Processing (NLP) , Computer Vision, Multimodal tasks, and more. Embodiments may be particularly suited for system architectures involving resource-constrained edge devices, where efficient processing of deep learning workloads, such as attention mechanisms, is important. These edge devices might typically be equipped with specialized hardware, such as a Neural Processing Unit (NPU) or an Application-Specific Integrated Circuit (ASIC) designed specifically for AI acceleration. One notable potential function of using MAS-Attention dataflow on these devices would be to perform real-time inference tasks to facilitate efficient and low-latency processing even under tight resource constraints.
[0213] Various embodiments exhibit particular buffer management and workload balancing techniques, and may include parallelizing the MAC and VEC unit computations within a single core for edge devices.
[0214] Embodiments of the present disclosure addressing the issue of limited cores and resources. Edge devices often have limited processing elements (PEs) and on-chip buffer sizes, unlike cloud hardware that utilizes multi-core parallelism to accelerate computation. Accordingly, embodiments provide an approach that leverages a stream processing scheme that efficiently pipelines attention operations, potentially optimizing resource usage on edge devices. By breaking down computations into smaller, manageable tiles, embodiments facilitate that the limited PEs and buffer are substantially fully utilized without overwhelming the system.
[0215] Embodiments of the present disclosure addressing the issue of overcoming MAC-VEC parallelism challenges. The distinct characteristics of MAC and VEC workloads, including the Softmax operation, make it challenging to run them in parallel, often leading to inefficient use of compute resources on edge devices. Providing that the Softmax operation is efficiently integrated into the pipeline while maintaining data dependencies adds further complexity to achieving optimal parallelism. Accordingly, embodiments provide an approach that introduces a pipelined execution strategy where MAC and VEC units operate in parallel. This strategy appropriately schedules the tiled workloads, maintaining data dependencies while maximizing the utilization of both MAC and VEC units. The approach can facilitate that even with a single MAC and VEC unit, the computation remains efficient and balanced.
[0216] Embodiments of the present disclosure addressing the issue of achieving workload balancing. Balancing the execution times of MAC and VEC operations is important to minimize overall latency, but it is complicated by the need to manage memory hierarchies. Accordingly, embodiments provide a multi-tiered tiling approach is employed, which may optimize tile sizes and strategies based on the workload. This approach facilitates that the tiled MatMul and Softmax operations are balanced in runtime, reducing latency. It also strategically leverages different memory levels to minimize access overhead and energy consumption.
[0217] Embodiments of the present disclosure addressing the issue of resolving the conflict between data locality and buffer size. Limited on-chip buffer size restricts the ability to handle long input sequences, creating a trade-off between data locality and buffer overflow. Accordingly, embodiments provide a proactive buffer overwrite strategy that selectively overwrites less critical data in the buffer. This allows for efficient management of longer sequences while ensuring correct data dependencies. Additionally, fine-grained tiling strategies may be applied to limit or minimize unnecessary data retention on-chip, further optimizing buffer usage.
[0218] Embodiments provide for a stream processing scheme with semi-synchronous MAC-VEC parallelism. This can lead to increased throughput, because overlapping MatMul and Softmax computations enhances overall throughput by ensuring continuous processing. This can also lead to reduced latency, because the pipelined approach and parallel execution of MAC and VEC units limit or minimize idle times and accelerate the computation of large sequences. This can also lead to optimized computational efficiency, because semi-synchronous execution facilitates that both MAC and VEC units are efficiently utilized, potentially improving performance. This can also lead to reducing energy consumption, because efficiently managing the computation flow and limiting or minimizing idle times can lead to lower energy consumption by reducing redundant processing and memory accesses.
[0219] Embodiments provide for a multi-tiered tiling strategy. This can lead to optimized memory utilization, because fine-grained tiling helps manage large matrices effectively within limited memory constraints. This can also lead to enhanced computational efficiency, because row-granularity tiling can facilitate accurate and efficient computation of intermediate data, improving Softmax operation performance.
[0220] Embodiments provide for a proactive buffer overwrite strategy. This can lead to efficient memory usage, which facilitates effective use of on-chip memory by balancing buffer space and computational needs. This can also lead to reduced pipeline stalls, which supports critical data to remain in memory, limiting or minimizing stalls and maintaining computational efficiency.
[0221] Embodiments provide for adaptive tiling and optimization methods. This can lead to a real-time adaptation, because the system can adjust to varying conditions, facilitating sustained high performance. This can also lead to tuned or optimized performance, because advanced search algorithms allow precise tuning of tiling parameters, improving performance and resource management.
[0222] Although embodiments above are described primarily with respect to computing the attention mechanism in edge devices, for supporting inference tasks, embodiments are not necessarily limited to such scenarios.
[0223] Accordingly, embodiments of the present disclosure can be adapted for cloud-based environments, to handle large-scale data and intensive computations. In cloud environments, the scale of resources available allows for enhanced parallelism and optimization. In some embodiments, in cloud environments, distributed computing resources and parallel processing can be leveraged to handle larger models and datasets. In some embodiments, efficient data synchronization mechanisms can be integrated to manage distributed memory and facilitate consistency across multiple nodes. In some embodiments, advanced load balancing techniques can be employed to distribute computation tasks effectively across a cloud infrastructure.
[0224] Embodiments can be implemented to support AI training rather than or in addition to supporting AI inference. This may involve adapting the techniques disclosed herein to handle backward passes and gradient computations. For gradient computations used in AI training, the computation pipeline as described above may be modified to include gradient calculations and backpropagation, integrating them (e.g. seamlessly) with the existing attention mechanism. Embodiments may implement optimizations to handle the increased computational load during training, facilitating that resource usage remains efficient. Embodiments may incorporate mechanisms for adaptive learning rates and optimization techniques to enhance training performance.
[0225] Embodiments of the present disclosure can be adapted to a variety of network types, such as mobile networks, e.g. utilizing wireless channels, or specialized communication systems. For mobile networks, embodiments can be adapted to handle network constraints and mobility, optimizing for reduced latency and energy efficiency in mobile scenarios. For specialized networks, embodiments may be adapted to specific requirements thereof, such as for internet-of things (IoT) or low-latency communication systems, for example by adjusting memory management and computation strategies.
[0226] FIG. 10 is a schematic diagram of an electronic device or a computing device 1000 that may perform any or all of operations of the above methods and features explicitly or implicitly described herein, according to different embodiments of the present disclosure. For example, a computer equipped with network function may be configured as an electronic device 1000.
[0227] As shown, the device includes a processor 1010, such as a Central Processing Unit (CPU) or specialized processors such as a Graphics Processing Unit (GPU) or other such processor unit, memory 1020, non-transitory mass storage 1030, I / O interface 1040, network interface 1050, and a transceiver 1060, all of which are communicatively coupled via bi-directional bus 1070. According to certain embodiments, any or all of the depicted elements may be utilized, or only a subset of the elements. Further, the device 1000 may contain multiple instances of certain elements, such as multiple processors, memories, or transceivers. Also, elements of the hardware device may be directly coupled to other elements without the bi-directional bus. Additionally or alternatively to a processor and memory, other electronics, such as integrated circuits, may be employed for performing the required logical operations.
[0228] The memory 1020 may include any type of non`-transitory memory such as static random access memory (SRAM) , dynamic random access memory (DRAM) , synchronous DRAM (SDRAM) , read-only memory (ROM) , any combination of such, or the like. The mass storage element 1030 may include any type of non-transitory storage device, such as a solid state drive, hard disk drive, a magnetic disk drive, an optical disk drive, USB drive, or any computer program product configured to store data and machine executable program code. According to certain embodiments, the memory 1020 or mass storage 1030 may have recorded thereon statements and instructions executable by the processor 1010 for performing any of the aforementioned method operations described above.
[0229] In some embodiments, computing device 1000 may be configured to implement the pipelined execution of transformer-based attention mechanisms. This includes tasks such as matrix multiplications and Softmax computations, as described in reference to one or more embodiments, including FIG. 3A, 3B, 4A, 4B, 5A, 5B, 6A, and 6B. According to some embodiments, memory 1020 may include on-chip cache memory and / or off-chip memory. In some embodiments, mass storage 1030 may refer to off-chip memory, such as DRAM. The one or more of memory 1020 and mass storage 1030 may be used as described in the parallel MAC-VEC execution strategies discussed in FIG. 6A for example.
[0230] The processor 1010 may include one or more cores that have specialized units, such as a MAC unit for matrix multiplication and a VEC unit for vector operations, depending on the implementation. For example, the MAC unit may handle matrix multiplications, such as computing QiKT or PiV, as described in embodiments herein including FIG. 3A, 3B, FIG. 5A, 5B FIG. 6A and 6B. The VEC unit, on the other hand, may execute vector-based operations like Softmax, as described in reference to FIG. 4A, 4B and FIG. 6A and 6B. Intermediate results such as Ci , and Pi may be stored in the on-chip cache memory, supporting memory-aware tiling strategies described in FIG. 3A, 3B, FIG. 5A and 5B and FIG. 6A and 6B. Meanwhile, the off-chip memory (e.g., DRAM) may be used to store larger matrices and final output matrices, Oi, such as those discussed in FIG. 5A and 6A.
[0231] FIG. 11A illustrates an example of an apparatus 1110, according to an embodiment of the present disclosure. The apparatus 1110 may be a communication device or an apparatus implemented in a communication device in one or more embodiments described herein. For example, the apparatus implemented in a communication device may be an integrated circuit, which in some contexts may be known by other colloquial names, such as chip, modem, modem chip, baseband chip, or baseband processor. In some implementations, one or more integrated circuits can be packaged into a system-on-chip, a system-in-package, or a multi-chip module. The apparatus may comprise one or more integrated circuits or comprise one or more integrated circuits and other discrete components. In some implementations, the apparatus 1110 may be similar to or a module in apparatus 1000.
[0232] In an example, the apparatus 1110 may include one or more processors / processor cores 1111, and an interface circuit 1112. The apparatus 1110 may further include a memory 1113. The one or more processors / processor cores 1111 are configured to process signals and execute one or more communication protocols. The memory 1113 is configured to store at least a part of corresponding computer program instructions and / or data. In an example, the one or more processors (or processor cores) 1111 execute the computer program instructions stored in the memory 1113 to implement related operations (for example, inputting, outputting, receiving, and transmitting) in the foregoing method embodiments. In some implementations, the memory 1113 being configured to store the corresponding computer program instructions and / or data may mean that the memory 1113 is configured to store all of the corresponding computer program instructions and / or data for execution by the one or more processors / processor cores 1111. In some implementations, the memory 1113 being configured to store the corresponding computer program instructions and / or data may mean that the memory 1113 is configured to store a part of the corresponding computer program instructions and / or data. For example, the part of the corresponding computer program instructions and / or data include computer program instructions and / or data that need to be currently executed by the one or more processors / processor cores 1111. Thus, the memory 1113 may store different parts of computer program instructions and / or data for a plurality times for the one or more processors (or processor cores) 1111 to perform related operations in the foregoing method embodiments. As a communication interface, the interface circuit 1112 is configured to implement communication with another component. For example, the interface circuit 1112 may communicate a signal with other apparatus / system such as a radio frequency processing apparatus, or processor system. Optionally, to reduce a load of the processor core, a baseband signal processing circuit 1114 may be also disposed to implement processing of at least a part of baseband signals, including signal demodulation, modulation, encoding, decoding, or the like.
[0233] Apparatus 1110 may be processor 1010 or included in or part of the processor 1010 in apparatus 1000. Apparatus 1110 may be or include a baseband chip. In some implementations, the apparatus 1110 may be independently packaged into a chip. In some implementations, the apparatus 1000 includes different types of chips. The apparatus 1110 may be packaged into a processor chip (for example, a SoC chip or an SIP chip) with the different types of chips. In some implementations, the apparatus 1110 may be packaged into a chip with some or all of circuits of a radio frequency processing system that may further included in the apparatus 1000.
[0234] In some embodiments, apparatus 1110 may be configured to handle tasks associated with the pipelined execution of transformer-based attention mechanisms, including matrix multiplications and Softmax computations, as described in one or embodiments, including in reference to FIG. 3A, 3B, 4A, 4B, 5A, 5B, 6A and 6B. In some embodiments, memory 1113 may represent on-chip cache memory and off-chip memory used to manage parallel MAC-VEC execution as described in one or more embodiments herein. In some embodiments, at least one processor 1111 may include at least one core which includes a MAC unit and VEC unit, where the MAC unit can perform matrix multiplication operations, such as computing matrix products (e.g., QiKTK or PiV) as described in one or more embodiments including in FIG. 3A, FIG. 5A, and 6A, while the VEC unit can execute vector-based operations such as Softmax computations, as described in one or more embodiments including in FIG. 4A and 6A. The on-chip cache memory may be used to store intermediate results like Ci, and Pi supporting the memory-aware tiling strategies as discussed in FIG. 3A and FIG. 5A for example. Off-chip memory, such as DRAM, may store larger matrices and final output matrices, Oi as referenced in FIG. 5A and 6A.
[0235] The chip architecture 1110 can also implement memory-aware management techniques, such as the selective overwriting strategy described in FIG. 9A and FIG. 9B, where on-chip memory constraints are managed by overwriting parts of the V or K matrices.
[0236] FIG. 11B illustrates an example apparatus 1130, according to an embodiment of the present disclosure. Apparatus 1130 may include corresponding modules or units configured to implement methods and / or embodiments described herein. In some implementations, the apparatus 1130 includes a processing unit 1132 and a communication unit 1133. Optionally, the apparatus 1130 may further include a storage unit 1131 configured to store apparatus program code (or instructions) and / or data.
[0237] In some embodiments, the apparatus 1130 may be a module, or a circuit or a chip responsible for a communication function in apparatus 1000. In some implementations, apparatus 1130 may be implemented as apparatus 1000, accordingly, the processing unit 1132 is implemented as processor 1010, the communication unit 1133 is implemented as transceiver 1060, and the storage unit 1131 is implemented as memory 1020.
[0238] In some implementations, a function of the apparatus 1130 may be implemented by one or more processors. Specifically, the processor may include a modem chip, or a system on chip SoC chip or an SIP chip that includes a modem core. A function of the communication unit 1133 may be implemented by a transceiver circuit.
[0239] In some implementations, when the apparatus 1130 is a circuit or a chip that is responsible for a communication function, for example, a modem chip, a system on chip SoC chip or an SIP chip that includes a modem core, a function of the processing unit 1132 may be implemented by a circuit system that is in the chip and that includes one or more processors or processor cores. A function of the communication unit 1133 may be implemented by an interface circuit or a data transceiver circuit on the foregoing chip.
[0240] In some embodiments, apparatus 1130 may be designed to handle transformer-based attention mechanisms through a more modular approach, with processing units that include MAC and VEC units, as described in in one or embodiments, including in reference to FIG. 3A, 3B, 4A, 4B, 5A, 5B, 6A and 6B. In some embodiments, storage unit 1131 may include an on-chip cache memory and off-chip memory for implementing parallel MAC-VEC execution as described in one or more embodiments herein. In some embodiments, the processing unit 1132 includes at least one core which includes a MAC unit and VEC unit, where the MAC unit can perform matrix multiplication operations, such as computing matrix products (e.g., QiKTK or PiV) as described in one or more embodiments including in FIG. 3A, FIG. 5A, and 6A, 6B while the VEC unit can execute vector-based operations such as Softmax computations, as described in one or more embodiments including in FIG. 4A, 4B, 6A and 6B. These MAC and VEC units work together to execute the parallel MAC-VEC strategies discussed in embodiments herein including FIG. 6A, 6B and FIG. 7, where matrix multiplications and Softmax operations are performed in parallel to optimize throughput and minimize idle time.
[0241] The on-chip cache memory may be used to store intermediate results like Ci and Pi, supporting the memory-aware tiling strategies as discussed in FIG. 3A and FIG. 5A for example. Off-chip memory, such as DRAM, may store larger matrices and final output matrices, Oi as referenced in FIG. 5A for example.
[0242] In some embodiments, the computing device in FIG. 10 and the apparatuses in FIG. 11A and FIG. 11B are versatile enough to implement the tiling strategies described in FIG. 2 and buffer overwrite strategies, as described in FIG. 9A and FIG. 9B. Additionally, the apparatuses shown in FIG. 10, FIG. 11A, and FIG. 11B can implement the stream-processing and pipelined execution schemes described in FIG. 6A and FIG. 6B. These schemes may enable improved parallel execution of attention mechanisms, using hardware resources like the MAC and VEC units to process different parts of the data stream in parallel.
[0243] FIG. 12A illustrates a method for performing a matrix-based computation in a computing device, according to an embodiment. The computing device may include a MA) unit for performing matrix multiplication, and a VEC unit. In some embodiments, the computing device further includes an on-chip cache memory shared by the MAC unit and the VEC unit) . The computing device may further include an off-chip memory operatively coupled to the on-chip cache memory.
[0244] The method 1200 includes obtaining 1201 (e.g. receiving / producing) a first plurality of tiles, denoted as Qi, which collectively represent a first matrix Q. The method further includes, according to a first set of multiplication operations, multiplying 1202, using the MAC unit, each of the first plurality of tiles (Qi) by a second matrix (K) to produce first intermediate result tiles (Ci) . The method further includes writing 1203 the first intermediate result tiles (Ci) to the on-chip cache memory as they are produced by the first set of multiplication operations. The method further includes obtaining 1204, in turn, each of the first intermediate result tiles (Ci) from the on-chip cache memory and as written to the on-chip cache memory by said writing the first intermediate result tiles and, using the VEC unit and according to a set of softmax operations, producing second intermediate result tiles (Pi) indicative of respective softmaxes of each of the first intermediate result tiles (Ci) (i.e. which represent the softmax calculation results of corresponding tiles Ci) . The method further includes writing 1205 the second intermediate result tiles (Pi) to the on-chip cache memory as they are produced by the set of softmax operations. The method further includes obtaining 1206, in turn, each of the second intermediate result tiles (Pi) from the on-chip cache memory and as written to the on-chip cache memory by said writing the second intermediate result tiles and, using the MAC unit and according to a second set of multiplication operations, multiplying each of the second intermediate result tiles (Pi) by a third matrix (V) to produce output result tiles (Oi) . The method may further include, according to a first parallelization, performing, by the MAC unit, at least one of the first set of multiplication operations, to produce one of the first intermediate result tiles (Ci) , in parallel with at least one of the softmax operations as performed by the VEC unit on another one of the first intermediate result tiles (Ci) . The method may further include, according to a second parallelization, performing, by the MAC unit, at least one of the second set of multiplication operations, on one of the second intermediate result tiles (Pi) , in parallel with at least one of the softmax operations as performed by the VEC unit to produce another one of the second intermediate result tiles (Pi) . The method may allow for increased throughput by overlappingMatMul and Softmax computations. The method may further allow for reduced latency and improved computational efficiency.
[0245] FIG. 12B illustrates another method for performing a matrix-based computation in a computing device, according to an embodiment. The computing device in method 1220 includes a MAC unit and a VEC unit. The method 1220 includes, performing in parallel, a matrix multiplication operation 1221 of a plurality of matrix multiplication operations performed on the MAC unit, and a softmax operation 1222 of a plurality of softmax operations performed on the VEC unit. In some embodiments, each softmax operation is based on an output of a corresponding one of the plurality of matrix multiplication operations. In some embodiments, the plurality of matrix multiplication operations and the plurality of softmax operations interact with one another via inputs and outputs written to, remaining in, and read from an on-chip cache memory of the computing device. In some embodiments, the plurality of matrix multiplication operations include a first subset of matrix multiplication operations, each of which provides an output for use by a corresponding one of the plurality of softmax operations. In some embodiments, the plurality of matrix multiplication operations further include a second subset of matrix multiplication operations, each of which operates based on output of said corresponding one of the plurality of softmax operations or another corresponding one of the plurality of softmax operations.
[0246] In some embodiments, the method further includes subdividing matrices into tiled matrices having a size which is sufficiently small to be held in an on-chip cache memory of the computing device. In some embodiments, the plurality of matrix multiplication operations and the plurality of softmax operations operate on said tiled matrices and produce further corresponding tile matrices which are also sufficiently small to be held in the on-chip cache memory of the computing device.
[0247] In some embodiments, the plurality of matrix multiplication operations involve at least one matrix from matrices Q, K, V of an attention mechanism computation for an artificial intelligence or machine learning application. In some embodiments, the computing device is an edge computing device.
[0248] In some embodiments, the matrix-based computation is a mixed computation involving matrix-based operations and vector-based operations performed in a pipelined manner and parallelized due to concurrent usage of the MAC unit and the VEC unit.
[0249] In the present disclosure, the terms “a” or “an” are defined to mean “at least one” , that is, these terms do not exclude a plural number of items, unless stated otherwise.
[0250] In the present disclosure, terms such as “substantially” , “generally” and “about” , which modify a value, condition or characteristic of a feature of an example embodiment, should be understood to mean that the value, condition or characteristic is defined within tolerances that are acceptable for the proper operation of the example embodiment for its intended application.
[0251] In the present disclosure, unless stated otherwise, the terms “connected” and “coupled” , and derivatives and variants thereof, refer herein to any structural or functional connection or coupling, either direct or indirect, between two or more elements. For example, the connection or coupling between the elements can be acoustical, mechanical, optical, electrical, thermal, logical, or any combinations thereof.
[0252] In the present disclosure, the expression “based on” is intended to mean “based at least partly on” , that is, this expression can mean “based solely on” or “based partially on” , and so should not be interpreted in a limited manner. More particularly, the expression “based on” could also be understood as meaning “depending on” , “representative of” , “indicative of” , “associated with” or similar expressions.
[0253] In the present disclosure, the terms "system" and "network" may be used interchangeably in different embodiments of this application. "At least one" means one or more, and "a plurality of" means two or more. The term "and / or" describes an association relationship of associated objects, and indicates that three relationships may exist. For example, A and / or B may indicate the following three cases: Only A exists, both A and B exist, and only B exists, where A and B may be singular or plural. The character " / " indicates an "or" relationship between associated objects. "At least one of the following items (pieces) " or a similar expression thereof indicates any combination of these items, including a single item (piece) or any combination of a plurality of items (pieces) .
[0254] In the present disclosure, "at least one" means one or more, and "a plurality of" means two or more. "and / or" describes an association relationship of associated objects, and indicates that there may be three relationships. For example, A and / or B may indicate cases includes “only A” , “both A and B” , and “only B”, where A and B may be singular or plural. The character " / " generally indicates that the associated objects are in an OR relationship. "At least one of the following items" or a similar expression thereof refers to any combination of these items, including any combination of a single item or a plurality of items. For example, “at least one of a, b, or c” may represent a, b, c, “a and b” , “a and c” , “b and c” , or “a, b and c”, where a, b, and c may be a single or multiple form.
[0255] It will be appreciated that, although specific embodiments of the technology have been described herein for purposes of illustration, various modifications may be made without departing from the scope of the technology. The specification and drawings are, accordingly, to be regarded simply as an illustration of the invention as defined by the appended claims, and are contemplated to cover any and all modifications, variations, combinations or equivalents that fall within the scope of the present invention. In particular, it is within the scope of the technology to provide a computer program product or program element, or a program storage or memory device such as a magnetic or optical wire, tape or disc, or the like, for storing signals readable by a machine, for controlling the operation of a computer according to the method of the technology and / or to structure some or all of its components in accordance with the system of the technology.
[0256] Acts associated with the method described herein can be implemented as coded instructions in a computer program product. In other words, the computer program product is a computer-readable medium upon which software code is recorded to execute the method when the computer program product is loaded into memory and executed on the microprocessor of the wireless communication device.
[0257] Further, each operation of the method may be executed on any computing device, such as a personal computer, server, PDA, or the like and pursuant to one or more, or a part of one or more, program elements, modules or objects generated from any programming language, such as C++, Java, or the like. In addition, each operation, or a file or object or the like implementing each said operation, may be executed by special purpose hardware or a circuit module designed for that purpose.
[0258] Through the descriptions of the preceding embodiments, the present invention may be implemented by using hardware only or by using software and a necessary universal hardware platform. Based on such understandings, the technical solution of the present invention may be embodied in the form of a software product. The software product may be stored in a non-volatile or non-transitory storage medium, which can be a compact disk read-only memory (CD-ROM) , USB flash disk, or a removable hard disk. The software product includes a number of instructions that enable a computer device (personal computer, server, or network device) to execute the methods provided in the embodiments of the present invention. For example, such an execution may correspond to a simulation of the logical operations as described herein. The software product may additionally or alternatively include a number of instructions that enable a computer device to execute operations for configuring or programming a digital logic apparatus in accordance with embodiments of the present invention.
[0259] Although the present invention has been described with reference to specific features and embodiments thereof, it is evident that various modifications and combinations can be made thereto without departing from the invention. The specification and drawings are, accordingly, to be regarded simply as an illustration of the invention as defined by the appended claims, and are contemplated to cover any and all modifications, variations, combinations or equivalents that fall within the scope of the present invention.
[0260] Embodiments have been described above in conjunctions with aspects of the present invention upon which they can be implemented. Those skilled in the art will appreciate that embodiments may be implemented in conjunction with the aspect with which they are described, but may also be implemented with other embodiments of that aspect. When embodiments are mutually exclusive, or are otherwise incompatible with each other, it will be apparent to those skilled in the art. Some embodiments may be described in relation to one aspect, but may also be applicable to other aspects, as will be apparent to those of skill in the art.
Claims
1.A method for performing a matrix-based computation in a computing device, the computing device including a multiply-accumulate (MAC) unit for performing matrix multiplication, a vector (VEC) unit, on-chip cache memory (shared by the MAC unit and the VEC unit) , and off-chip memory operatively coupled to the on-chip cache memory, the method comprising:obtaining a first plurality of tiles (Qi) which collectively represent a first matrix (Q) ;according to a first set of multiplication operations, multiplying, using the MAC unit, each of the first plurality of tiles (Qi) by a second matrix (K) to produce first intermediate result tiles (Ci) ;writing the first intermediate result tiles (Ci) to the on-chip cache memory as they are produced by the first set of multiplication operations;obtaining, in turn, each of the first intermediate result tiles (Ci) from the on-chip cache memory and as written to the on-chip cache memory by said writing the first intermediate result tiles and, using the VEC unit and according to a set of softmax operations, producing second intermediate result tiles (Pi) indicative of respective softmaxes of each of the first intermediate result tiles (Ci) ;writing the second intermediate result tiles (Pi) to the on-chip cache memory as they are produced by the set of softmax operations;obtaining, in turn, each of the second intermediate result tiles (Pi) from the on-chip cache memory and as written to the on-chip cache memory by said writing the second intermediate result tiles and, using the MAC unit and according to a second set of multiplication operations, multiplying each of the second intermediate result tiles (Pi) by a third matrix (V) to produce output result tiles (Oi) ;wherein one or both of the following hold:according to a first parallelization: at least one of the first set of multiplication operations, performed by the MAC unit to produce one of the first intermediate result tiles (Ci) , is performed in parallel with at least one of the softmax operations as performed by the VEC unit on another one of the first intermediate result tiles (Ci) ; andaccording to a second parallelization: at least one of the second set of multiplication operations, performed by the MAC unit on one of the second intermediate result tiles (Pi) , is performed in parallel with at least one of the softmax operations as performed by the VEC unit to produce another one of the second intermediate result tiles (Pi) .and further wherein one or both of the following hold:as part of the first parallelization: for at least one of the first set of multiplication operations, as soon as feasible following completion of a respective one of the second set of multiplication operations, performing said at least one of the first set of multiplication operations, whether or not one of the softmax operations is currently being performed; andas part of the second parallelization: as soon as feasible following completion of a final one of the softmax operations and when the MAC unit is available for use, performing a final one of the second set of multiplication operations.2.The method of claim 1, wherein the matrix-based computation is part of an attention mechanism computation for an artificial intelligence or machine learning application.3.The method of any one of claims 1 to 2, wherein the computing device is an edge computing device which has limited computational power compared to a data center computing device.4.The method of any one of claims 1 to 3, wherein some or all of: the first matrix, the second matrix, the third matrix, and an output matrix (O) formed from the output result tiles (Oi) are four-dimensional tensors.5.The method of any one of claims 1 to 4, further comprising, in response to insufficient capacity in the on-chip cache memory during one of the softmax operations, one or both of the following:when one of the first set of multiplication operations is being performed concurrently with said one of the softmax operations: halting said one of the first set of multiplication operations; and overwriting portions of the on-chip cache memory, previously allocated for storing components of the second matrix (K) used as input in said one of the first set of multiplication operations, with results of said one of the softmax operations; andwhen one of the second set of multiplication operations is being performed concurrently with said one of the softmax operations: halting said one of the second set of multiplication operations; and overwriting portions of the on-chip cache memory, previously allocated for storing components of the third matrix (V) used as input in said one of the second set of multiplication operations, with results of said one of the softmax operations.6.The method of claim 5, further comprising, following completion of said one of the softmax operations, restarting or resuming said one of the first set of multiplication operations or said one of the second set of multiplication operations, said repeating or resuming comprising reloading data from the off-chip memory to the on-chip cache memory.7.The method of any one of claims 1 to 6, wherein:at least one of the first plurality of tiles (Qi) is a four-dimensional tensor having dimension sizes Bb, Hh, NQ and E;the second matrix (K) is a four-dimensional tensor having dimension sizes B, H, N and E;at least one of the first set of multiplication operations, to produce one of the first intermediate result tiles (Ci) , comprises:selecting a portion (Ki) of the second matrix (K) , the portion (Ki) having dimension sizes Bb, Hh, NK, V and E, wherein NK, V is less than or equal to N and is based at least in part on a criterion of fitting computation results into the on-chip cache memory;dividing the portion (Ki) of the second matrix (K) into a second plurality of tiles (Kij) ;loading said one of the first plurality of tiles (Qi) into the on-chip cache memory;for each one of the second plurality of tiles (Kij) , separately:loading said one of the second plurality of tiles into the on-chip cache memory;computing a matrix product (Cij) of said one of the first plurality of tiles (Qi) times said one of the second plurality of tiles (Kij) ; andstoring the matrix product (Cij) to the on-chip cache memory as a portion of said one of the first intermediate result tiles (Ci) .8.The method of claim 7, wherein the dimension sizes Bb, Hh, NQ and NK, V are defined by an optimization routine which is configured based on hardware parameters of the computing device.9.The method of claim 8, wherein the hardware parameters include one or more of: size of the on-chip cache memory; bandwidth of the on-chip cache memory; size of the off-chip memory; and bandwidth of the off-chip memory.10.The method of any one of claims 1 to 9, wherein:at least one of the set of softmax operations, to produce one of the second intermediate result tiles (Pi) , comprises:dividing a corresponding one of the first intermediate result tiles (Ci) , already held in the on-chip cache memory, into a plurality of sub-tiles (Cij) ;for each one of the plurality of sub-tiles (Cij) , separately:performing a softmax computation on said one of the plurality of sub-tiles (Cij) ; andstoring a result of the softmax computation to the on-chip cache memory as a portion (Pij) of said one of the second intermediate result tiles (Pi) .11.The method of claim 10, wherein the softmax computation includes a plurality of sub-computations, and wherein all of the sub-computations are performed without reading to or writing from the off-chip memory.12.The method of claim 10, wherein each of the plurality of sub-tiles (Cij) has dimension sizes Bb, Hh, 1 and N.13.The method of any one of claims 1 to 12, wherein:at least one of the second set of multiplication operations, to produce one of the output result tiles (Oi) , comprises:dividing one of the second intermediate result tiles (Pi) , already held in the on-chip cache memory, into a second plurality of tiles (Pij) ,selecting a corresponding portion (Vi) of the third matrix (V) ;dividing the portion (Vi) of the third matrix into a third plurality of tiles (Vij) ;wherein a total number (Tc) of the second plurality of tiles equals a total number of the third plurality of tiles;initializing a portion of the on-chip cache memory to hold the output result tile (Oi) ; andfor each one of the third plurality of tiles (Vij) , sequentially in turn:loading said one of the third plurality of tiles (Vij) into the on-chip cache memory;computing a matrix product of a corresponding one of the second plurality of tiles (Pij) times said one of the third plurality of tiles (Vij) to produce a partial product; andadding the partial product to contents of the portion of the on-chip cache memory to thereby additively accumulate the partial products produced over all of the second plurality of tiles in the portion of the on-chip cache memory.14.The method of claim 13, wherein the total number (Tc) equals approximately N / NK, V, where N is a dimension size of said one of the second intermediate result tiles (Pi) and also a dimension size of said one of the portion (Vi) of the third matrix, and NK, V is a dimension size of each one of the second plurality of tiles (Pij) and also a dimension size of each one of the third plurality of tiles (Vij) .15.The method of any one of claims 1 to 14, wherein:the first matrix (Q) , the second matrix (K) and the third matrix (V) are four-dimensional tensors having dimension sizes B, H, N and E;each one of the first plurality of tiles (Qi) is a four-dimensional tensor having dimension sizes Bb, Hh, NQ and E;each one of the first intermediate result tiles (Ci) is a four-dimensional tensor having dimension sizes Bb, Hh, NQ and N;each one of the second intermediate result tiles (Pi) is a four-dimensional tensor having dimension sizes Bb, Hh, NQ and N;each one of the output result tiles (Oi) is a four-dimensional tensor having dimension sizes Bb, Hh, NQ and E;each one of the second matrix (K) , the third matrix (V) , and the second intermediate result tiles (Pi) are divided so as to have a size NK, V along a respective dimension thereof, andthe dimension sizes Bb, Hh, NQ and NK, V are defined by an optimization routine which is configured based on hardware parameters of the computing device.16.The method of claim 15, wherein the hardware parameters include one or more of: size of the on-chip cache memory; bandwidth of the on-chip cache memory; size of the off-chip memory; and bandwidth of the off-chip memory.17.The method of claim 15 or 16, wherein Bb<B, Hh<H, NQ<N and NK, V<N and wherein Bb, Hh, NQ and NK,V specify tiling sizes for subdividing one or more of the first matrix (Q) , the second matrix (K) and the third matrix (V) to facilitate reduction in usage of the off-chip memory.18.A method for performing a matrix-based computation in a computing device, the computing device including a multiply-accumulate (MAC) unit and a vector (VEC) unit, the method comprising: performing in parallel:a matrix multiplication operation of a plurality of matrix multiplication operations performed on the MAC unit; anda softmax operation of a plurality of softmax operations performed on the VEC unit.19.The method of claim 18, wherein each softmax operation is based on an output of a corresponding one of the plurality of matrix multiplication operations.20.The method of claim 18 or 19, wherein the plurality of matrix multiplication operations and the plurality of softmax operations interact with one another via inputs and outputs written to, remaining in, and read from an on-chip cache memory of the computing device.21.The method of any one of claims 18 to 20, wherein the plurality of matrix multiplication operations include: a first subset of matrix multiplication operations, each of which provides an output for use by a corresponding one of the plurality of softmax operations; and a second subset of matrix multiplication operations, each of which operates based on output of said corresponding one of the plurality of softmax operations or another corresponding one of the plurality of softmax operations.22.The method of any one of claims 18 to 21, further comprising subdividing matrices into tiled matrices having a size which is sufficiently small to be held in an on-chip cache memory of the computing device, and wherein the plurality of matrix multiplication operations and the plurality of softmax operations operate on said tiled matrices and produce further corresponding tile matrices which are also sufficiently small to be held in the on-chip cache memory of the computing device.23.The method of any one of claims 18 to 22, wherein the plurality of matrix multiplication operations involve at least one matrix from matrices Q, K, V of an attention mechanism computation for an artificial intelligence or machine learning application.24.The method of any one of claims 18 to 23, wherein the computing device is an edge computing device.25.The method of any one of claims 18 to 24, wherein the matrix-based computation is a mixed computation involving matrix-based operations and vector-based operations performed in a pipelined manner and parallelized due to concurrent usage of the MAC unit and the VEC unit.26.A computer program product comprising a computer readable medium which, when executed on a computer causes the computer to perform the method of any one of claims 1 to 25, the computer comprising the computing device.27.A computer configured to implement the method of any one of claims 1 to 25, the computer comprising the computing device.28.A computing device configured to perform a matrix-based computation, the computing device including a multiply-accumulate (MAC) unit for performing matrix multiplication, a vector (VEC) unit, on-chip cache memory (shared by the MAC unit and the VEC unit) , and off-chip memory operatively coupled to the on-chip cache memory, the computing device configured to:obtain a first plurality of tiles (Qi) which collectively represent a first matrix (Q) ;according to a first set of multiplication operations, multiply, using the MAC unit, each of the first plurality of tiles (Qi) by a second matrix (K) to produce first intermediate result tiles (Ci) ;write the first intermediate result tiles (Ci) to the on-chip cache memory as they are produced by the first set of multiplication operations;obtain, in turn, each of the first intermediate result tiles (Ci) from the on-chip cache memory and as written to the on-chip cache memory by said writing the first intermediate result tiles and, using the VEC unit and according to a set of softmax operations, produce second intermediate result tiles (Pi) indicative of respective softmaxes of each of the first intermediate result tiles (Ci) ;write the second intermediate result tiles (Pi) to the on-chip cache memory as they are produced by the set of softmax operations;obtain, in turn, each of the second intermediate result tiles (Pi) from the on-chip cache memory and as written to the on-chip cache memory by said writing the second intermediate result tiles and, using the MAC unit and according to a second set of multiplication operations, multiply each of the second intermediate result tiles (Pi) by a third matrix (V) to produce output result tiles (Oi) ;wherein one or both of the following hold:according to a first parallelization: at least one of the first set of multiplication operations, performed by the MAC unit to produce one of the first intermediate result tiles (Ci) , is performed in parallel with at least one of the softmax operations as performed by the VEC unit on another one of the first intermediate result tiles (Ci) ; andaccording to a second parallelization: at least one of the second set of multiplication operations, performed by the MAC unit on one of the second intermediate result tiles (Pi) , is performed in parallel with at least one of the softmax operations as performed by the VEC unit to produce another one of the second intermediate result tiles (Pi) .and further wherein one or both of the following hold:as part of the first parallelization: for at least one of the first set of multiplication operations, as soon as feasible following completion of a respective one of the second set of multiplication operations, the computing device is further configured for performing said at least one of the first set of multiplication operations, whether or not one of the softmax operations is currently being performed; andas part of the second parallelization: as soon as feasible following completion of a final one of the softmax operations and when the MAC unit is available for use, the computing device is further configured for performing a final one of the second set of multiplication operations.29.The computing device of claim 28, wherein the matrix-based computation is part of an attention mechanism computation for an artificial intelligence or machine learning application.30.The computing device of any one of claims 28 to 29, wherein the computing device is an edge computing device which has limited computational power compared to a data center computing device.31.The computing device of any one of claims 28 to 30, wherein some or all of: the first matrix, the second matrix, the third matrix, and an output matrix (O) formed from the output result tiles (Oi) are four-dimensional tensors.32.The computing device of any one of claims 28 to 31, further configured for, in response to insufficient capacity in the on-chip cache memory during one of the softmax operations, one or both of the following:when one of the first set of multiplication operations is being performed concurrently with said one of the softmax operations: halting said one of the first set of multiplication operations; and overwriting portions of the on-chip cache memory, previously allocated for storing components of the second matrix (K) used as input in said one of the first set of multiplication operations, with results of said one of the softmax operations; andwhen one of the second set of multiplication operations is being performed concurrently with said one of the softmax operations: halting said one of the second set of multiplication operations; and overwriting portions of the on-chip cache memory, previously allocated for storing components of the third matrix (V) used as input in said one of the second set of multiplication operations, with results of said one of the softmax operations.33.The computing device of claim 32, further configured for, following completion of said one of the softmax operations, restarting or resuming said one of the first set of multiplication operations or said one of the second set of multiplication operations, said repeating or resuming comprising reloading data from the off-chip memory to the on-chip cache memory.34.The computing device of any one of claims 28 to 33, wherein:at least one of the first plurality of tiles (Qi) is a four-dimensional tensor having dimension sizes Bb, Hh, NQ and E;the second matrix (K) is a four-dimensional tensor having dimension sizes B, H, N and E;at least one of the first set of multiplication operations, to produce one of the first intermediate result tiles (Ci) , comprises:selecting a portion (Ki) of the second matrix (K) , the portion (Ki) having dimension sizes Bb, Hh, NK, V and E, wherein NK, V is less than or equal to N and is based at least in part on a criterion of fitting computation results into the on-chip cache memory;dividing the portion (Ki) of the second matrix (K) into a second plurality of tiles (Kij) ;loading said one of the first plurality of tiles (Qi) into the on-chip cache memory;for each one of the second plurality of tiles (Kij) , separately:loading said one of the second plurality of tiles into the on-chip cache memory;computing a matrix product (Cij) of said one of the first plurality of tiles (Qi) times said one of the second plurality of tiles (Kij) ; andstoring the matrix product (Cij) to the on-chip cache memory as a portion of said one of the first intermediate result tiles (Ci) .35.The computing device of claim 34, wherein the dimension sizes Bb, Hh, NQ and NK, V are defined by an optimization routine which is configured based on hardware parameters of the computing device.36.The computing device of claim 35, wherein the hardware parameters include one or more of: size of the on-chip cache memory; bandwidth of the on-chip cache memory; size of the off-chip memory; and bandwidth of the off-chip memory.37.The computing device of any one of claims 28 to 36, wherein:at least one of the set of softmax operations, to produce one of the second intermediate result tiles (Pi) , comprises:dividing a corresponding one of the first intermediate result tiles (Ci) , already held in the on-chip cache memory, into a plurality of sub-tiles (Cij) ;for each one of the plurality of sub-tiles (Cij) , separately:performing a softmax computation on said one of the plurality of sub-tiles (Cij) ; andstoring a result of the softmax computation to the on-chip cache memory as a portion (Pij) of said one of the second intermediate result tiles (Pi) .38.The computing device of claim 37, wherein the softmax computation includes a plurality of sub-computations, and wherein all of the sub-computations are performed without reading to or writing from the off-chip memory.39.The computing device of claim 38, wherein each of the plurality of sub-tiles (Cij) has dimension sizes Bb, Hh, 1 and N.40.The computing device of any one of claims 28 to 39, wherein:at least one of the second set of multiplication operations, to produce one of the output result tiles (Oi) , comprises:dividing one of the second intermediate result tiles (Pi) , already held in the on-chip cache memory, into a second plurality of tiles (Pij) ,selecting a corresponding portion (Vi) of the third matrix (V) ;dividing the portion (Vi) of the third matrix into a third plurality of tiles (Vij) ;wherein a total number (Tc) of the second plurality of tiles equals a total number of the third plurality of tiles;initializing a portion of the on-chip cache memory to hold the output result tile (Oi) ; andfor each one of the third plurality of tiles (Vij) , sequentially in turn:loading said one of the third plurality of tiles (Vij) into the on-chip cache memory;computing a matrix product of a corresponding one of the second plurality of tiles (Pij) times said one of the third plurality of tiles (Vij) to produce a partial product; andadding the partial product to contents of the portion of the on-chip cache memory to thereby additively accumulate the partial products produced over all of the second plurality of tiles in the portion of the on-chip cache memory.41.The computing device of claim 40, wherein the total number (Tc) equals approximately N / NK, V, where N is a dimension size of said one of the second intermediate result tiles (Pi) and also a dimension size of said one of the portion (Vi) of the third matrix, and NK, V is a dimension size of each one of the second plurality of tiles (Pij) and also a dimension size of each one of the third plurality of tiles (Vij) .42.The computing device of any one of claims 28 to 41, wherein:the first matrix (Q) , the second matrix (K) and the third matrix (V) are four-dimensional tensors having dimension sizes B, H, N and E;each one of the first plurality of tiles (Qi) is a four-dimensional tensor having dimension sizes Bb, Hh, NQ and E;each one of the first intermediate result tiles (Ci) is a four-dimensional tensor having dimension sizes Bb, Hh, NQ and N;each one of the second intermediate result tiles (Pi) is a four-dimensional tensor having dimension sizes Bb, Hh, NQ and N;each one of the output result tiles (Oi) is a four-dimensional tensor having dimension sizes Bb, Hh, NQ and E;each one of the second matrix (K) , the third matrix (V) , and the second intermediate result tiles (Pi) are divided so as to have a size NK, V along a respective dimension thereof, andthe dimension sizes Bb, Hh, NQ and NK, V are defined by an optimization routine which is configured based on hardware parameters of the computing device.43.The computing device of claim 42, wherein the hardware parameters include one or more of: size of the on-chip cache memory; bandwidth of the on-chip cache memory; size of the off-chip memory; and bandwidth of the off-chip memory.44.The computing device of claim 42 or 43, wherein Bb<B, Hh<H, NQ<N and NK, V<N and wherein Bb, Hh, NQ and NK, V specify tiling sizes for subdividing one or more of the first matrix (Q) , the second matrix (K) and the third matrix (V) to facilitate reduction in usage of the off-chip memory.45.A computing device configured to perform a matrix-based computation, the computing device including a multiply-accumulate (MAC) unit and a vector (VEC) unit, the computing device configured to perform in parallel:a matrix multiplication operation of a plurality of matrix multiplication operations performed on the MAC unit; anda softmax operation of a plurality of softmax operations performed on the VEC unit.46.The computing device of claim 45, wherein each softmax operation is based on an output of a corresponding one of the plurality of matrix multiplication operations.47.The computing device of claim 45 or 46, wherein the plurality of matrix multiplication operations and the plurality of softmax operations interact with one another via inputs and outputs written to, remaining in, and read from an on-chip cache memory of the computing device.48.The computing device of any one of claims 45 to 47, wherein the plurality of matrix multiplication operations include: a first subset of matrix multiplication operations, each of which provides an output for use by a corresponding one of the plurality of softmax operations; and a second subset of matrix multiplication operations, each of which operates based on output of said corresponding one of the plurality of softmaxoperations or another corresponding one of the plurality of softmax operations.49.The computing device of any one of claims 45 to 48, further comprising subdividing matrices into tiled matrices having a size which is sufficiently small to be held in an on-chip cache memory of the computing device, and wherein the plurality of matrix multiplication operations and the plurality of softmax operations operate on said tiled matrices and produce further corresponding tile matrices which are also sufficiently small to be held in the on-chip cache memory of the computing device.50.The computing device of any one of claims 45 to 49, wherein the plurality of matrix multiplication operations involve at least one matrix from matrices Q, K, V of an attention mechanism computation for an artificial intelligence or machine learning application.51.The computing device of any one of claims 45 to 50, wherein the computing device is an edge computing device.52.The computing device of any one of claims 45 to 51, wherein the matrix-based computation is a mixed computation involving matrix-based operations and vector-based operations performed in a pipelined manner and parallelized due to concurrent usage of the MAC unit and the VEC unit.