Matrix multiplication is used in a wide variety of computational tasks, for example, image, text, and software code generation, in conjunction with machine learning (ML) models, such as neural networks (NNs). Graphics processing units (GPUs) with tensor cores are examples of hardware that excel at performing matrix multiplication quickly.
However, hardware-optimized solutions are configured for particular data types (e.g., data formats) with the data values in a particular layout to maximize throughput. If data is submitted to a hardware-optimized solution in a different layout and/or a different format, the processing is delayed while the format is converted and/or the layout is shifted to an accepted layout. This situation may arise with some degree of regularity, when storage limitations for large matrices or latency limitations drive developers to use a data format with fewer bit fields than the data type accepted by a hardware-optimized matrix multiplication solution, or upstream software writes data in a different layout.
The disclosed examples are described in detail below with reference to the accompanying drawing figures listed below. The following summary is provided to illustrate some examples disclosed herein. It following, in the sequence, a reference frame of a reference frame set is not meant, however, to limit all examples to any particular configuration or sequence of operations.
Example solutions for multi-stage 8-bit floating point (FP8) matrix multiplication with format conversion, that benefit computation efficiency of matrix multiplication operations by a processor, include: copying data values in FP8 format from global memory to shared memory; loading thread block tiles of FP8 data values from the shared memory into a set of registers; converting each of the multiple FP8 data values in the set of registers to 16-bit floating point (FP16) data values; submitting the FP16 data values to the tensor core; and performing, with the tensor core, matrix multiply accumulate (MMA) computations.
The disclosed examples are described in detail below with reference to the accompanying drawing figures listed below:
Corresponding reference characters indicate corresponding parts throughout the drawings. Any of the drawings may be combined into a single embodiment.
The various examples will be described in detail with reference to the accompanying drawings. Wherever preferable, the same reference numbers will be used throughout the drawings to refer to the same or like parts. References made throughout this disclosure relating to specific examples and implementations are provided solely for illustrative purposes but, unless indicated to the contrary, are not meant to limit all examples.
Example solutions for multi-stage 8-bit floating point (FP8) matrix multiplication with format conversion, that benefit computation efficiency of matrix multiplication operations by a processor, include: copying data values in FP8 format from global memory to shared memory; loading thread block tiles of FP8 data values from the shared memory into a set of registers; converting each of the multiple FP8 data values in the set of registers to 16-bit floating point (FP16) format data values; submitting the FP16 data values to the tensor core; and performing, with the tensor core, matrix multiply accumulate (MMA) computations.
Aspects of the disclosure benefit the operations of computing devices, for example, by increasing the speed of matrix multiplications, reducing the memory required, and reducing electrical consumption. The speed of matrix multiplications is increased at least by converting each of multiple FP8 data values in the set of registers to FP16 data values. Performing the conversion in registers prior to submission to the tensor core increases speed, compared with conversion before storing data values to shared memory. Memory capacity and bandwidth reduction is achieved by enabling the use of FP8 data values in global memory and shared memory, shifting the traditional memory/speed trade-off, and reducing the size of any neural network (NN) or other machine learning (ML) component that is using the MMA computations. Electrical power consumption is reduced at least by the use of less memory and fewer processing cycles.
In general, GPUs are able to process multiple pieces of data simultaneously, rendering them useful for ML, video editing, and gaming applications. Multiple different types of memories are used with GPUs, including global memory, shared memory, and registers. These may be referred to, respectively, as a first memory, a second memory, and a third memory. Global memory tends to be the slowest, but is also typically the largest storage space. Shared memory is often faster than global memory, but more limited in size. Registers are faster still, although typically tightly limited in capacity.
Tensor core 140 expects FP16 data values in a particular layout. However, of the matrices to be multiplied, matrix A 111 and matrix B 112, at least one has stored FP8 data values, in order to save memory space. In some examples, matrix A 111 is in FP16 format and matrix B 112 is in FP8 format. Format conversion is required when tensor core does not support FP8 matrix multiplication natively or these two matrices have different data formats.
To increase the speed of the matrix multiplication, an MMA acceleration 132 performs FP8 to FP16 format conversion within a set of registers 106 and arranges the layout of the data values pulled from matrix A 111 and matrix B 112 into the layout expected by tensor core 140. Performing the format conversion in set of registers 106, and rearranging the layout and submitting data values from matrix A 111 and matrix B 112 in the order expected by MMA (e.g., as warp tiles) permits the MMA process in tensor core 140 to execute without bottlenecks. This significantly increased the speed of the matrix multiplication stage of producing output product 150.
Matrix multiplication is the major operation type when running ML models in GPUs or other hardware accelerators. Transformer-based workloads that generate text or software code operate using a technique known as auto-regressive generation. During generation, one new token is produced in each model forward step. A model forward step has multiple matrix multiplication operations that individually may have low computing intensity in the token-by-token generation stage. A primary speed bottleneck for these operations is loading model weights from global memory 108 to shared memory 130 or set of registers 106.
GPU 104 produces output product 150 by executing a task 110 using task logic 120 (e.g., a software program that performs task 110 to produce output product 150). Task logic 120 contains an ML model 122, which may include an NN. Performing task 110 requires multiplying matrix A 111 and matrix B 112 to compute a matrix C 113. Task logic 120 and data for task 110 are stored in a global memory 108, which may comprise high bandwidth memory (HBM), such as second generation high bandwidth memory (HBM2) or third generation high bandwidth memory (HBM3). In some examples, global memory 108 is not located within the same integrated circuit (IC) package as tensor core 140.
To save space in global memory 108, matrix A 111 or matrix B 112, or both, is in FP8 format. Because FP8 format requires only 8 bits, whereas FP16 format requires 16 bits, and other floating point formats require 32 or 64 bits, the use of FP8 may be preferable when the required numerical precision and range of values permits. Storing data in the lower precision (e.g., FP8 format) also saves data loading cost between global memory 108 and shared memory 130. Unfortunately, some GPUs do not support FP8 in MMA. Converting data values from FP8 to FP16 format prior to storage in shared memory 130 may prevents the use of some optimized asynchronous copy operations provided by common GPUs, and may also limit data loading parallelism. In some examples, shared memory 130 is located within the same IC package as tensor core 140, and is a faster memory type than global memory 108.
Data values (e.g., data values 402a-402d of
Tensor core 140 performs MMA on the submitted data values to compute MMA results 144. In some examples, MMA results 144 are in FP32, and tensor core 140 performs accumulation in FP32 as part of the MMA process. MMA results 144 are returned to set of registers 106 (or a different set of registers, in some examples) and optionally converted back to FP16 or FP8 format. MMA results 144 are then copied back to shared memory 130 and then copied back to global memory 108 as data values for matrix C 113.
In some examples, moving data values between global memory 108 and shared memory 130 uses an asynchronous copy operation. Asynchronous copying (async copy) transfers data between memory locations under the control of hardware enabling software on the GPU to proceed concurrently with other work while the copy completes. Use of asynchronous copy operations permits further a speed increase by aspects of the disclosure. The use of FP8 versus FP16 further speeds copy time between global memory 108 and shared memory 130, because fewer bits are transferred.
Data values (e.g., data values 404a and 404b) are submitted to tensor core 140, and are held in set of registers 106 while MMA logic 408 performs an MMA process (e.g., MMA calculations) on them. This produces MMA results 144 inside set of registers 106 as FP32 data values. Tensor core 140 is able to read and write directly from/to set of registers 106. A data value 414a and a data value 414b are shown. In some examples, the data values in set of registers 106 are then converted to FP16 or FP8 format, and copied to shared memory 130 and then some may be copied to global memory 108. In some examples, asynchronous copy is used for the move to global memory 108.
Data movement from global memory 108 to shared memory 130 (matrix to thread block tile), from shared memory 130 to a register file (thread block tile to warp tile) in set of registers 106, and from the register file to tensor core 140 for computation (warp tile to thread tile) is illustrated.
Each thread block computes its part of the GEMM output by iteratively loading blocks of matrix data from the input matrices and computing an accumulated matrix product. The thread block tile structure is further partitioned into warps (groups of threads that execute together). Warps provide organization for the GEMM computation.
A thread block tile 504 is illustrated, along with the subsequent stage, a warp tile 506. Thread block tile 504 and warp tile 506 are described in further detail in relation to
In stage 804, data values are loaded from shared memory 130 to set of registers 106. In stage 806, data values are submitted to tensor core 140 for MMA calculations. As illustrated, stages 802, 804, and 806 occur concurrently with data progressing through the stages. As shown, data values in thread block tile 201 pass from stage 802, then stage 804, then stage 806 first, followed by data values in thread block tile 202. Some data from thread block tiles 202, 203 and 204 may still be in stage 802 when data from thread block tile 201, that has already passed through stages 802 and 804, is already in stage 806.
The illustrated section is shown to be in main loop body 808, which repeats (after initial pipeline fill), until pipeline purge, when the matrix multiplication is complete. A wait period 810 is shown after data loading for thread block tile 201 have completed, while data values from thread block tile 202 are during loading. As indicated by the shading, all blocks illustrated in stage 806 are from thread block tile 201, and all blocks illustrated in stage 804 are from thread block tile 201, except the final one. The final block illustrated in stage 804 is from thread block tile 202.
Operation 910 copies the first thread block tile (e.g., thread block tile 201). This is followed by four load operations for data values from the first thread block tile: load operation 912a, load operation 912b, load operation 912c, and load operation 912d. After loading, data values may be converted. Data values loaded in load operation 912a are converted in conversion operation 914a, and submitted to tensor core 140 for MMA calculations 916a.
This scheme permits different data values to be in different processes of pipeline 900 concurrently. For example, a set of data values passes through load operation 912c, a conversion operation 914c, and MMA calculations 916c. Another set of data values passes through load operation 912d, a conversion operation 914d, and MMA calculations 916d.
Operation 920 copies the second thread block tile (e.g., thread block tile 202). A set of data values from the second thread block tile passes through a load operation 922a, a conversion operation 924a, and MMA calculations 926a. Another set of data values passes through a load operation 922b, a conversion operation 924b, and MMA calculations 926b. Another set of data values passes through a load operation 922c, a conversion operation 924c, and MMA calculations 926c. Another set of data values passes through a load operation 922d, a conversion operation 924d, and MMA calculations 926d.
Steady state 904 exists from when data values are sent to tensor core 140, until no more data values are being sent to tensor core 140. In some embodiments, the FP8 to FP16 format conversion occurs simultaneously with MMA calculations 916a-d and 926a-d. In some examples, there are 7 stages of parallel operations in flight concurrently in pipeline 900.
Following steady state 904, during flush pipeline stage 906 the data values may be copied to shared memory 130 may remain in the registers with accumulation.
One row of data values in memory representation grids 1008 and 1030 is read in each phase. A counter of the reading phases is indicated to the right side of memory representation grid 1030. When reading from or writing to global memory 108 each thread needs to handle continuous values. When reading from or writing to shared memory 130, the threads in a warp need to only read one 4-byte data from any bank in a phase.
A register 1102 of set of registers 106 is shown holding four FP8 data values, an FP8 data value E0, an FP8 data value E1, an FP8 data value E2, and an FP8 data value E3. Because each register of set of registers 106 is 32 bits (in some examples), when data is in FP8 format, a single register stores four FP8 data values. In some examples, tensor core 140 has a layout requirement that is different than the pattern shown for memory representation grid 1106.
After conversion, each register contains two FP16 data values. Thirty-two bits may be occupied as either {8 bits, 8 bits, 8 bits, 8 bits} or {16 bits, 16 bits}. Register 1102 had held all four FP8 data values E0-E3. After conversion (and permutation/shifting), register 1202 holds FP16 data values H0 and H1, and register 1204 holds FP16 data values H2 and H3. In some examples, dual MMA cores compute odd and even columns of memory representation grid 1206.
In operation 1304, architecture 100 generates matrix A 111 and matrix B 112 for multiplication in global memory 108. Operation 1306 performs matrix multiplication of matrix A 111 and matrix B, specifically MMA, to compute matrix C 113, using operations 1308-1330. Operation 1308 copies data values (e.g., data values 402a and 402b) in FP8 format from global memory 108 to shared memory 130. In some examples, copying the data values in FP8 format data from global memory 108 to shared memory 130 comprises performing an asynchronous copy operation.
Operation 1310 loads thread block tiles of FP8 data values (e.g., three thread block tiles, such as thread block tiles 201-203) from shared memory 130 into set of registers 106. In some examples, each register of set of registers 106 comprises a 32-bit register. In some examples, loading the thread block tiles of FP8 data values from shared memory 130 into set of registers 106 comprises loading four data values in the FP8 format data from shared memory 130 FP8 into a single register of set of registers 106. During steady state operations, loading the thread block tiles of FP8 data values from the shared memory 130 into set of registers 106 occurs while performing MMA computations on prior converted data values.
Operation 1312 converts each of the multiple FP8 data values in set of registers 106 to FP16 data values prior to submitting the data values to tensor core 140. Operation 1314 shifts (permutes) data positions of the FP16 data values to a layout accepted by tensor core 142, also prior to submitting the data values to tensor core 140. In some examples, operations 1312 and 1314 are performed simultaneously, so that shifting data positions of the FP16 data values to the layout accepted by tensor core 140 occurs concurrently with converting each of the multiple FP8 data values to FP16 data values.
Operation 1316 submits the FP16 data values to tensor core 140, and in operation 1318, tensor core 140 performs MMA computations using the FP16 data values. After performing the MMA computations, tensor core 140 returns MMA results 144 (e.g., the results of the MMA computations) in operation 1320. In some examples, MMA results 144 comprise FP32 data values. Operation 1322 copies MMA results 144 into set of registers 106.
Optional operation 1324 converts MMA results 144 in set of registers 106 from FP32 format to FP16 format or FP8 format. Operation 1326 copies MMA results 144 from set of registers 106 into shared memory 130. Operation 1328 stores MMA results 144 to global memory 108. Decision operation 1330 determines whether the matrix multiplication of operation 1306 is complete. If not, flowchart 1300 returns to operation 1308 to continuing to copy data values from global memory 108 to the shared memory 130, load data values into set of registers 106, convert data value format, and submit data values to the tensor core, until MMA computations for matrices in global memory 108 are complete.
Otherwise, operation 1332 finishes computational task 110 to generate an output (output product 150), for example by generating an image, generating text, or generating software code using the MMA computations.
Operation 1404 includes loading thread block tiles of the first floating point data values from the shared memory into a set of registers. Operation 1406 includes converting the first floating point data values in the set of registers to second floating point data values in a second floating point format. Operation 1408 includes submitting the second floating point data values to a tensor core. Operation 1410 includes performing, with the tensor core, MMA computations. Operation 1412 includes generating an output using the MMA computations.
An example system comprises: a processor; and a computer-readable medium storing instructions that are operative upon execution by the processor to: copy data values in a first floating point format from global memory to shared memory; load thread block tiles of the first floating point data values from the shared memory into a set of registers; convert the first floating point data values in the set of registers to second floating point data values in a second floating point format; submit the second floating point data values to a tensor core; perform, with the tensor core, MMA computations; and generate an output using the MMA computations.
An example method comprises: asynchronously copying data values in a first floating point format from global memory to shared memory; loading thread block tiles of the first floating point data values from the shared memory into a set of registers; converting the first floating point data values in the set of registers to second floating point data values in a second floating point format; submitting the second floating point data values to a tensor core; performing, with the tensor core, MMA computations; and generating an output using the MMA computations.
One or more example computer storage devices has computer-executable instructions stored thereon, which, on execution by a computer, cause the computer to perform operations comprising: copying data values in a first floating point format from global memory to shared memory; loading thread block tiles of the first floating point data values from the shared memory into a set of registers while performing matrix multiply accumulate (MMA) computations on prior converted data values; converting the first floating point data values in the set of registers to second floating point data values in a second floating point format; submitting the second floating point data values to a tensor core; performing, with the tensor core, MMA computations; and generating an output using the MMA computations.
Alternatively, or in addition to the other examples described herein, examples include any combination of the following:
While the aspects of the disclosure have been described in terms of various examples with their associated operations, a person skilled in the art would appreciate that a combination of operations from any number of different examples is also within scope of the aspects of the disclosure.
Neither should computing device 1500 be interpreted as having any dependency or requirement relating to any one or combination of components/modules illustrated. The examples disclosed herein may be described in the general context of computer code or machine-useable instructions, including computer-executable instructions such as program components, being executed by a computer or other machine, such as a personal data assistant or other handheld device. Generally, program components including routines, programs, objects, components, data structures, and the like, refer to code that performs particular tasks, or implement particular abstract data types. The disclosed examples may be practiced in a variety of system configurations, including personal computers, laptops, smart phones, mobile tablets, hand-held devices, consumer electronics, specialty computing devices, etc. The disclosed examples may also be practiced in distributed computing environments when tasks are performed by remote-processing devices that are linked through a communications network.
Computing device 1500 includes a bus 1510 that directly or indirectly couples the following devices: computer storage memory 1512, one or more processors 1514, one or more presentation components 1516, input/output (I/O) ports 1518, I/O components 1520, a power supply 1522, and a network component 1524. While computing device 1500 is depicted as a seemingly single device, multiple computing devices 1500 may work together and share the depicted device resources. For example, memory 1512 may be distributed across multiple devices, and processor(s) 1514 may be housed with different devices.
Bus 1510 represents what may be one or more busses (such as an address bus, data bus, or a combination thereof). Although the various blocks of
In some examples, memory 1512 includes computer storage media. Memory 1512 may include any quantity of memory associated with or accessible by the computing device 1500. Memory 1512 may be internal to the computing device 1500 (as shown in
Processor(s) 1514 may include any quantity of processing units that read data from various entities, such as memory 1512 or I/O components 1520. Specifically, processor(s) 1514 are programmed to execute computer-executable instructions for implementing aspects of the disclosure. The instructions may be performed by the processor, by multiple processors within the computing device 1500, or by a processor external to the client computing device 1500. In some examples, the processor(s) 1514 are programmed to execute instructions such as those illustrated in the flow charts discussed below and depicted in the accompanying drawings. Moreover, in some examples, the processor(s) 1514 represent an implementation of analog techniques to perform the operations described herein. For example, the operations may be performed by an analog client computing device 1500 and/or a digital client computing device 1500. Presentation component(s) 1516 present data indications to a user or other device. Exemplary presentation components include a display device, speaker, printing component, vibrating component, etc. One skilled in the art will understand and appreciate that computer data may be presented in a number of ways, such as visually in a graphical user interface (GUI), audibly through speakers, wirelessly between computing devices 1500, across a wired connection, or in other ways. I/O ports 1518 allow computing device 1500 to be logically coupled to other devices including I/O components 1520, some of which may be built in. Example I/O components 1520 include, for example but without limitation, a microphone, joystick, game pad, satellite dish, scanner, printer, wireless device, etc.
Computing device 1500 may operate in a networked environment via the network component 1524 using logical connections to one or more remote computers. In some examples, the network component 1524 includes a network interface card and/or computer-executable instructions (e.g., a driver) for operating the network interface card. Communication between the computing device 1500 and other devices may occur using any protocol or mechanism over any wired or wireless connection. In some examples, network component 1524 is operable to communicate data over public, private, or hybrid (public and private) using a transfer protocol, between devices wirelessly using short range communication technologies (e.g., near-field communication (NFC), Bluetooth™ branded communications, or the like), or a combination thereof. Network component 1524 communicates over wireless communication link 1526 and/or a wired communication link 1526a to a remote resource 1528 (e.g., a cloud resource) across network 1530. Various different examples of communication links 1526 and 1526a include a wireless connection, a wired connection, and/or a dedicated link, and in some examples, at least a portion is routed through the internet.
Although described in connection with an example computing device 1500, examples of the disclosure are capable of implementation with numerous other general-purpose or special-purpose computing system environments, configurations, or devices. Examples of well-known computing systems, environments, and/or configurations that may be suitable for use with aspects of the disclosure include, but are not limited to, smart phones, mobile tablets, mobile computing devices, personal computers, server computers, hand-held or laptop devices, multiprocessor systems, gaming consoles, microprocessor-based systems, set top boxes, programmable consumer electronics, mobile telephones, mobile computing and/or communication devices in wearable or accessory form factors (e.g., watches, glasses, headsets, or earphones), network PCs, minicomputers, mainframe computers, distributed computing environments that include any of the above systems or devices, virtual reality (VR) devices, augmented reality (AR) devices, mixed reality devices, holographic device, and the like. Such systems or devices may accept input from the user in any way, including from input devices such as a keyboard or pointing device, via gesture input, proximity input (such as by hovering), and/or via voice input.
Examples of the disclosure may be described in the general context of computer-executable instructions, such as program modules, executed by one or more computers or other devices in software, firmware, hardware, or a combination thereof. The computer-executable instructions may be organized into one or more computer-executable components or modules. Generally, program modules include, but are not limited to, routines, programs, objects, components, and data structures that perform particular tasks or implement particular abstract data types. Aspects of the disclosure may be implemented with any number and organization of such components or modules. For example, aspects of the disclosure are not limited to the specific computer-executable instructions or the specific components or modules illustrated in the figures and described herein. Other examples of the disclosure may include different computer-executable instructions or components having more or less functionality than illustrated and described herein. In examples involving a general-purpose computer, aspects of the disclosure transform the general-purpose computer into a special-purpose computing device when configured to execute the instructions described herein.
By way of example and not limitation, computer readable media comprise computer storage media and communication media. Computer storage media include volatile and nonvolatile, removable and non-removable memory implemented in any method or technology for storage of information such as computer readable instructions, data structures, program modules, or the like. Computer storage media are tangible and mutually exclusive to communication media. Computer storage media are implemented in hardware and exclude carrier waves and propagated signals. Computer storage media for purposes of this disclosure are not signals per se. Exemplary computer storage media include hard disks, flash drives, solid-state memory, phase change random-access memory (PRAM), static random-access memory (SRAM), dynamic random-access memory (DRAM), other types of random-access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disks (DVD) or other optical storage, magnetic cassettes, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other non-transmission medium that may be used to store information for access by a computing device. In contrast, communication media typically embody computer readable instructions, data structures, program modules, or the like in a modulated data signal such as a carrier wave or other transport mechanism and include any information delivery media.
The order of execution or performance of the operations in examples of the disclosure illustrated and described herein is not essential, and may be performed in different sequential manners in various examples. For example, it is contemplated that executing or performing a particular operation before, contemporaneously with, or after another operation is within the scope of aspects of the disclosure. When introducing elements of aspects of the disclosure or the examples thereof, the articles “a,” “an,” “the,” and “said” are intended to mean that there are one or more of the elements. The terms “comprising,” “including,” and “having” are intended to be inclusive and mean that there may be additional elements other than the listed elements. The term “exemplary” is intended to mean “an example of” The phrase “one or more of the following: A, B, and C” means “at least one of A and/or at least one of B and/or at least one of C.”
Having described aspects of the disclosure in detail, it will be apparent that modifications and variations are possible without departing from the scope of aspects of the disclosure as defined in the appended claims. As various changes could be made in the above constructions, products, and methods without departing from the scope of aspects of the disclosure, it is intended that all matter contained in the above description and shown in the accompanying drawings shall be interpreted as illustrative and not in a limiting sense.
This application claims the benefit of U.S. Provisional Patent Application Ser. No. 63/374,125 filed on Aug. 31, 2022 and entitled “Multi-Stage 8-Bit Floating Point Matrix Multiplication with Format Conversion”, which is hereby incorporated by reference in its entirety for all intents and purposes.
Number | Date | Country | |
---|---|---|---|
63374125 | Aug 2022 | US |