arXiv:2609.06328cs.PLSep 2026

Manuscript Offprint

arXiv:2609.06328

SparseConflicts: Handling Conflicting Data Layouts in Sparse Tensor Contractions

Adhitha Dias, Kirshanthan Sundararajah, Artem Pelenitsyn, Milind Kulkarni

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

ADHITHA DIAS, Purdue University, USA

KIRSHANTHAN SUNDARARAJAH, Virginia Tech, USA

ARTEM PELENITSYN, Purdue University, USA

MILIND KULKARNI, Purdue University, USA

Optimizing sparse tensor computations is challenging due to the use of compressed storage formats, which leads to non-affine loop nests and a vast, complex schedule space. The performance of a given schedule is sensitive to the sparsity pattern of the input tensors, making it difficult to find a single optimal solution. When input tensors in the same tensor contraction have conflicting data layouts in relation to the iteration order, it requires costly—both in time and memory—layout transformation, such as transposition. A promising but under-explored alternative is to generate a schedule that avoids explicit transposition, but this has not been systematically supported in existing compilers.

This paper presents a new code generation strategy that generalizes the intermediate representation of the TACO sparse tensor compiler to generate a single loop nest, circumventing explicit transposition of tensors when the tensors have conflicting data layout iteration orders. We extend TACO's iteration graph to express a search-based strategy for locating elements in tensors with conflicting layouts, and we introduce new intermediate representation nodes to lower these schedules to efficient code. This enables the systematic generation of loops that do not require explicit transposition, thus avoiding the overhead of materializing temporary tensors.

We evaluate our approach on a set of sparse tensor contractions using both real-world and synthetic datasets. Our results demonstrate that for computations with misaligned data layouts, our fused approach achieves up to 2× speedup for some sparsity patterns over the traditional approach of explicitly creating a transposed temporary. We also provide guidelines for when this new scheduling strategy is likely to be beneficial.

CCS Concepts: • Software and its engineering → Source code generation; Domain specific languages.

Additional Key Words and Phrases: Sparse Tensor Algebra, Loop Transformations, Tensor Transposition

1 INTRODUCTION

Sparse tensor computations are key components in many scientific computing areas, including, but not limited to numerical simulations, data analysis, and machine learning applications [Hirato 2003; Hu et al. 2020; Markov 2008; Rahman et al. 2021; Ran et al. 2017, 2020]. Sparse tensors are often represented using compressed storage formats such as Compressed Sparse Row (CSR) or Compressed Sparse Fiber (CSF) to save memory and improve computational efficiency [Chou et al. 2018]. Memory saving comes from storing only the non-zero elements of the tensor along with their indices, while computation efficiency is achieved by not performing operations on zero elements (i.e., x×0=0x \times 0 = 0 and x+0=xx + 0 = x). Using these compressed storage formats makes it challenging to perform tensor operations directly on the compressed data because it requires iteration over the non-zero elements and their indices, which can be complex compared to dense tensor operations [Chou et al. 2018; Kjolstad et al. 2017].

A key challenge in optimizing sparse tensor computations is minimizing the overhead associated with accessing and manipulating compressed data structures. The use of compressed storage

Authors' Contact Information: Adithita Dias, Electrical and Computer Engineering, Purdue University, West Lafayette, IN, USA, kadithita@purdue.edu; Kirshanthan Sundararajah, Computer Science, Virginia Tech, Blacksburg, VA, USA, kirshanthans@vt.edu; Artem Pelenitsyn, Electrical and Computer Engineering, Purdue University, West Lafayette, IN, USA, apelenit@purdue.edu; Milind Kulkarni, Electrical and Computer Engineering, Purdue University, West Lafayette, IN, USA, milind@purdue.edu.

X:2

Adhitha Dias, Kirshanthan Sundararajah, Artem Pelenitsyn, and Milind Kulkarni

formats in sparse tensor computations leads to non-affine loops, where loop bounds and memory accesses depend on metadata arrays. These non-affine loop nests prevent the direct application of classical affine loop nest transformation frameworks. Consequently, determining an optimal execution schedule¹ for sparse computations is significantly more challenging than for their dense counterparts that operate on affine loops. This problem has been extensively studied in the compiler literature [Bik et al. 2022; Bik and Wijshoff 1993; Chou et al. 2018; Deeds et al. 2025; Kjolstad et al. 2017; Shaikhha et al. 2024; Tian et al. 2021; Won et al. 2023a; Ye et al. 2023], with proposed solutions involving techniques such as fusion, tiling, and data layout transformations, etc [Ahrens et al. 2025; Chou et al. 2020; Dias et al. 2022; Kjolstad et al. 2019; Mueller et al. 2020; Senanayake et al. 2020].

The effectiveness of a schedule for non-affine loops is highly sensitive to the sparsity pattern of the input tensors [Won et al. 2023b]. A loop structure that performs well for one pattern may be inefficient for another. Since it is impractical for programmers to manually explore the vast space of possible implementations for every use case, modern sparse tensor compilers provide frameworks that use domain-specific languages (DSLs) to express a wide range of schedules without exposing the complexity of low-level details. This allows the user to select the most performant schedule for a specific problem instance [Kjolstad et al. 2017; Senanayake et al. 2020].

A common scheduling challenge arises when a computation involves tensors with conflicting iteration orders. For example, consider an element-wise matrix product²:

A(i,j)×B(i,j),A(i,j)\times B(i,j),

where tensor AA is stored in a row-major format (CSR) and tensor BB is in a column-major format (CSC). Co-iterating over both tensors is difficult due to their conflicting layouts. Specifically, accessing elements of AA requires iterating over index ii before jj, while accessing elements of BB requires iterating over index jj before ii. This means that AA requires a loop order of ii outer and jj inner, while BB requires jj outer and ii inner. This mismatch in iteration order is our core problem and complicates the generation of loop code. The standard solution is to create a temporary sparse tensor by explicitly transposing one of the inputs to match the other's layout. In this case, converting BB to a row-major format (CSR) to match AA's layout. However, this materialization of a temporary copy incurs time and memory costs, as does the use of alternative structures like hash maps [Dias et al. 2022; Raje et al. 2024].

An alternative to materializing a temporary is to generate a schedule that can handle the conflicting iteration orders directly within the computation. This can be achieved with a search-based strategy that locates corresponding elements in the compressed data structures on the fly. For example, using a search and a conditional to match corresponding i,ji, j coordinates in AA with BB, or vice versa. This approach eliminates the need for a temporary copy of the entire tensor and may use lower-dimensional dense temporaries to store intermediate results.

By eliminating an explicit transposition, we

Figure

Fig. 1. The effect of omitting an explicit transpose step on execution time.

can reduce the overhead of data manipulation, leading to improved performance. This is particularly important for sparse tensors, where the cost of creating temporary tensors can be significant

¹A schedule is a concrete realization of the computation, which encompasses, for instance, a loop structure, parallelization strategies, tiling/blocking, loop fusion, etc.

²We use bold letters, like AA and BB, to denote sparse matrices or tensors. Dense tensors are not bolded.

X:3

compared to the actual computation. Figure 1 illustrates the benefits of a single, fused computation over a separate transpose-then-compute approach.

This search-based mechanism has not been explored systematically as a generic loop generation strategy to eliminate explicit transpositions in sparse tensor computations. Existing sparse tensor compilers, such as TACO [Kjolstad et al. 2017], lack a formal mechanism to implement this strategy because their internal representation is over-constrained and not expressive enough to describe such schedules. In this work, we introduce a more generic representation that extends TACO's iteration graph to support a wider range of schedules, including those that avoid explicit transposition. Our key idea is to introduce a relaxed iteration graph that can express a search-based strategy, which we then lower to a new intermediate representation for code generation. This allows us to systematically generate fused transposition schedules for sparse tensor computations.

The contributions of this paper are as follows:

Relaxed Iteration Graph and IR We generalize the iteration graph of TACO to support conflicting iteration orders to circumvent explicit transposition steps in the computation and enable more flexible scheduling. To this end, we generalize the intermediate representation to a relaxed version, by introducing two new IR nodes, forsome and forsame.

Novel Code Generation Strategy We add support for the new IR nodes in the code generation phase, and adapt the existing code generation capabilities of TACO. We further show how the new IR can be transformed into existing IR constructs in certain scenarios.

Demonstrating Performance for Suitable Tensors We identify two classes of problems where this new code generation strategy can provide substantial speedups.

The rest of the paper is organized as follows. We provide the necessary background in Section 2. We motivate the problem in Section 3. The new compiler design is explained in detail in Section 4. We discuss implementation details in Section 5. Evaluation of our compiler is presented in Section 6. We conclude the paper in Section 8 with a discussion.

References (19)