Editor’s introduction
The study evaluates FLAASH, a flexible accelerator designed for sparse high-order tensor contraction. It compares performance across varying levels of sparsity and tensor order, demonstrating over 25x speedup in deep learning tasks by distributing sparse dot products across dedicated engines. The design addresses challenges in control flow and data representation, showing effectiveness in high-sparsity and high-order scenarios.
Introduction
Tensors are ubiquitous in machine learning, with deep learning models commonly using high-order tensors to represent data, neural activations, and parameters. Sparse tensor computations can increase the efficiency of processing large-scale data. Sparsity presents an opportunity to compress data in storage and skip superfluous computations. However, software approaches have limited ability to harness the parallel nature of the arithmetic, and hardware support remains challenging.
Enhancing the efficiency of tensor contraction, an operation that extends matrix multiplication to higher dimensions, could accelerate various types of machine learning. Neural network layers can be replaced with a single tensor contraction or tensor decomposition (decomposition requires many contraction operations when optimizing and evaluating). Additionally, note that tensor contraction can be used directly as a method of machine learning. Currently, these operations are expensive compared to the standard highly-optimized operations on dense tensors of activations and weights.
There is a pressing need to improve hardware support for high-order tensors with unstructured sparsity. Recent advancements have made progress in addressing challenges in tensor contraction in general, but they do not take on this specific problem. focus only on GPU implementations. target sparse convolution operations, and deal with structured sparsity. It is common for existing work to concentrate on only matrices, or on sparse-dense operations. Performance improvements from our work will directly enable and enhance the improvements promised in these approaches (e.g., reducing the parameter count by more than 65% while maintaining classifier performance).
Although structured sparsity can be exploited, imposing structure requirements can limit the ability to achieve high sparsity levels. A method for computing on and storing unstructured sparse data is essential. Unstructured sparsity is more challenging to implement, since it allows no assumptions, while structured sparsity relies on meeting specific conditions. Typically, sparse tensor hardware focuses on matrices, with higher-order tensors requiring reformatting or posing difficulties in memory access patterns and caching. Arbitrary-order hardware therefore offers the greatest flexibility. These requirements are met by, though our approach offers greater flexibility by using modularity to easily support alternative tensor storage formats, scheduling strategies, and caching behavior.
To address these challenges, we introduce FLAASH (FLexible Accelerator Architecture for Sparse High-order tensor contraction), a groundbreaking approach to sparse tensor contraction architecture. Our results demonstrate the significant potential of FLAASH. We evaluate its performance in two categories of benchmarks: synthetic and deep learning.
Sparsity
Sparse tensors have a high proportion of entries that are zeros, with only some small number of non-zero values. When expressed as a percentage, sparsity is the fraction of the total volume (product of all mode lengths) occupied by nonzero values. The number of non-zero values is often abbreviated as NNZ. These zeros obviate the multiplications and accumulations internal to the contraction operation, meaning that sparsity-unaware storage and compute techniques will “waste time” processing zeros that could be skipped. This goal is at the heart of sparsity optimizations: efficiently skipping the zeros in storage and compute.
Sparsity commonly arises in data used for machine learning for many reasons. Sparse matrices may represent momentary observations in discrete time, such as readings from a photodetector that usually does not detect any photons. Sparsity often arises in the storage of graphs using the adjacency matrix format, where each coordinate in a matrix represents a connection between nodes referenced by the row and column. Since many graphs are far from fully-connected, this leads to many zeros representing no connection between those nodes. Also, sparsity is often desirable in neural network weights (and therefore activations) themselves to reduce storage size or inference FLOP count (assuming the inference procedure is sparsity-aware).
In unstructured sparsity, there is potential for significant imbalance in the number of nonzero elements in each fiber. One job may require iterating through 10000 nonzero elements while the next job has only two. This puts strain on the scheduling system, particularly if it cannot predict that these scheduled jobs will take very different amounts of time to complete. This challenge is particularly pressing for GPU-like architectures with a shared instruction pointer across many processing elements since the job that completes early will keep the processing element occupied until the longest-running job in the work group completes. Our architecture instead allows each processing element to operate independently without adding complexity.
Sparse tensors can be stored in memory and on disk in a variety of formats. Compressed sparse fiber (CSF) format is common because it is an extension of the CSR (row) and CSC (column) formats often used for sparse matrices. Storing in CSF format requires performing the following procedure. First, a mode is chosen, and all fibers that go in that direction are enumerated. Next, for each fiber, coordinate-entry pairs are stored in indexed order with all zero elements omitted. Then, these coordinate-entry pairs are stored end-to-end in some way that enables later retrieval of a fiber. Often, the approach is to store the start and end pointers for each fiber in an order that makes traversal easy.
While these patterns are easy for a CPU to parse, a CPU is insufficiently parallel and leaves performance on the table. This means we need a custom architecture to traverse these structures efficiently. We implement hardware traversal of compressed data structures to skip element-wise zero checks or seeking: all pointers are calculated from tensor metadata while tensor in-memory size is dominated by NNZ.
Prior work
Prior work includes software approaches for sparse tensor contractions and also includes hardware accelerators for sparse matrix operations. We believe that our modular hardware accelerator for unstructured high-order sparse tensor contractions is a novel contribution. Our work is similar to, but our approach places a strong focus on the modularity of the architecture, leaving the door open to alternative designs of each component while retaining the overall architecture structure. We made decisions to use particular tensor storage formats, scheduling strategies, and memory setups, since concrete options must be chosen to perform simulations and benchmarks, but in this paper we present a general flexible and modular framework for the construction of sparse tensor contraction accelerator architectures, while presents only a single design.
There is disagreement about the optimal choice of data structure for accessing and storing operands, intermediate results, and the final result of contraction. In particular, many papers on the subject discuss the use of the compressed sparse row/column/fiber (CSR, CSC, CSF) format and a coordinate-keyed dictionary format.
Prior work also shows that sparse tensor contraction can play an important role in machine learning. Tensor contraction is explored in deep learning as a replacement for fully-connected layers, and as novel layers. There is recent work on noticing and promoting sparsity in neural network activation tensors and in transformer activations.
Approach
We present FLAASH: a FLexible Accelerator Architecture for Sparse High-order tensor contraction. This architecture scales well to the available die area, and it efficiently handles sparsity: computation time is dominated by the number of nonzero values rather than the volume of the tensors. The design is modular in that each component communicates through an abstracted interface, allowing support for multiple storage formats, cache-aware job scheduling, and optional scratchpad use.
Finally, our architecture achieves workload balance across processing elements (Sparse Dot Product Engines, or SDPEs), facilitated by the central job queue. Even if one job specifies a fiber that is more dense than average, the other jobs are not held back from dispatch or completion. Our architecture instead allows each SDPE to operate independently without adding complexity. Unlike the GPU latency hiding approach of context switching, our design leverages a surplus of processing elements such that even a high idle fraction can saturate the memory interface.
Overview
The scheduler maintains a queue of jobs and distributes them to SDPEs as they finish each dot product job. When all jobs are complete and the last result is written, the accelerator signals that it has finished the contraction and returns a pointer to the resulting tensor data structure.
Sparse Dot Product Engines
The SDPE design is optimized to be small so that many SDPEs can be tiled in limited die area, and to scale the design to fit the needs of the larger processor design. One SDPE is comprised of two fiber loader units, an intersection & MAC unit, a result storage unit, and a local job queue.
The intersection & MAC unit pulls from these FIFOs to search for locations where nonzero entries of each fiber align. When the index within the fiber is the same for both inputs, a collision occurs. This triggers a multiply-accumulate (MAC) inside the intersection unit, adding to its internal accumulator. If the index from fiber loader unit A is greater than that of B, then the intersection unit discards the current element from the B fiber and pops the next from that FIFO. After advancing one fiber, the index comparison is repeated.
The local job queue serves as a small buffer, giving the central job queue more freedom to distribute one job per cycle, even if multiple SDPEs are able to start work in the same cycle. With a local job queue, each SDPE can receive its next job and start immediately when it finishes the current one.
Each fiber loader unit also presents a flag to the intersection unit indicating that it has finished adding new pairs to its FIFO. When this flag is raised and the queue is empty, the job is done. This triggers sending the accumulator value to the storage unit, which queues until the tensor memory is ready to write the result. This final queue (another FIFO) allows for greater flexibility in the operation of the tensor memory: For example, the job generator could recognize that there is enough room to store all results in SDPE result queues, and signal that the tensor memory should prioritize all read operations before accepting write requests. The memory queue also helps address load imbalance issues, since an SDPE can begin working on its next job immediately, even when the execution time of a job is very short from having few nonzero elements, or even an unexpectedly all-zero fiber.
Note that the interface between a fiber loader unit and memory only returns nonzero tensor elements. This means that the intersection unit is able to cheaply skip ahead while performing the sparse dot product, since seeking does not involve fetching zeros. Even if the tensor memory uses a data format that requires querying the operand tensors repeatedly to find nonzero elements, this inefficiency is hidden from the SDPE execution model, freeing the implementation of the tensor memory to privately maintain any metadata useful to efficiently traversing the data structure.
Job Generation and Dispatch
We did not implement this method since our focus was not on optimizing memory structure or cache utilization, but the architecture provides this flexibility. The tensor memory and the job generator must be in agreement about the storage format of the result tensor. Focusing on the common case where the result is more dense than the operands, our simple solution is to store the result tensor in a dense CSF format that does not require any prediction, balancing, or dynamic allocation. We leave it to the driver software to sparsify the result tensor. This design decision allows more freedom in implementing the job generator: it removes write order dependencies that are required for some sparse storage formats, and it also avoids the dynamic requirements of order-independent COO formats (such as trees and hash tables).
Tensor Memory
The role of the tensor memory unit is to interact with system memory on behalf of the SDPEs, performing the translation from tensor operation to memory access. Recall that tensor contraction requires computing on pairs of fibers, where every fiber of the first tensor must be paired with every fiber of the second. As mentioned in the prior section, this carries caching implications. Furthermore, memory may be virtually segmented into read-only operands and a write-only result. There is plenty of flexibility to implement this unit to efficiently handle caching with the unique needs of any choice of tensor data structure. From an integration perspective, it may be helpful to also implement allocation in this unit, and facilitate the import and export of data if a separate memory is used rather than direct memory access (DMA) to the host memory.
The tensor memory performs allocation of tensors for operands and the result by maintaining an internal division between allocated and free memory. The job generator performs the translation from tensor index to memory pointer, though, which only works because of our choice of data format, which we explicitly chose to lead to the smallest implementation. This means that the SDPEs make memory requests of the tensor memory with direct physical pointers rather than indices. This works well because the CSF format is simple and allows for up-front pointer calculations without dynamic pointer chasing or reallocation. If we had chosen a more complex format like a tree or locality-binned hash table, then the tensor memory would be the only logical place to handle state while traversing the operand structures and assembling the result structure.
This fulfils the adjacency requirement: adjacent elements of a fiber in the contraction mode are also stored physically adjacent in memory. This storage format also allows the tensor memory to preallocate the entire result tensor, which gives the job generator sufficient context to compute the pointer of each result element before the contraction starts. Our implementation preallocates a dense result in CSF format, which can be converted to a sparse representation in one pass. This is suboptimal but simplifies the implementation considerably, and since results tend to be more dense than operands, it is not an invalid assumption.
Input/Output Interface
We envision this accelerator as a small component of a larger processor design, sharing system memory through a DMA interface. The I/O unit would implement this interface. In a discrete design, this unit would house the PCIe connection to the host system. We implemented this portion of the simulator as part of the testbench, since the design of high-speed IO interfaces is out of scope for this project.
Implementation
Tensors are generated randomly, with density as the probability that an individual element will be nonzero. We consider the workloads described by: multi-layer perceptrons from AlexNet and VGG-19, replaced with equivalent tensor contractions. We chose densities to cover a range of empirical results. For example, suggest pruned BERT-base encoders achieve around 3% density, while recurrent neural networks from are below 10%. suggest as low as 6.5% density, and suggests 3% to as low as 0.5% density in transformer activations for some layers.
Machine Learning Workload
The Pytorch and TensorFlow libraries both support dense tensor contraction and sparse matrix contraction, but they do not have functions to perform sparse tensor contraction. An equivalent mathematical operation is to reshape sparse tensors into sparse matrices where the free modes are combined to a single mode. These sparse matrices are then contracted and reshaped to the appropriate dimensions. Note that, for these experiments, only the sparse matrix contraction time is being measured, not the time it takes to reshape.
Conclusion and Future Work
Sparsity in tensors is crucial for efficient ML computations, but providing hardware support is challenging. We demonstrate that FLAASH performs well even in high-sparsity and high-order contexts, providing a significant speedup to machine learning workloads. FLAASH opens up possibilities for a variety of future scheduling, cache, and data structure optimizations. Future work could include comparing different data structures and cache management strategies, and exploring opportunities to decompose dot products into shorter jobs.


