Files
TheRock/compiler/amd-llvm/mlir/test/Dialect/SparseTensor/pre_rewriting.mlir
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

102 lines
5.0 KiB
MLIR

// RUN: mlir-opt %s -pre-sparsification-rewrite | FileCheck %s
#SparseVector = #sparse_tensor.encoding<{
map = (d0) -> (d0 : compressed)
}>
#SortedCOO = #sparse_tensor.encoding<{
map = (d0, d1) -> (d0 : compressed(nonunique), d1 : singleton)
}>
#DCSR = #sparse_tensor.encoding<{
map = (d0, d1) -> (d0 : compressed, d1 : compressed)
}>
#Slice = #sparse_tensor.encoding<{
map = (d0 : #sparse_tensor<slice(?, 1, 1)>, d1 : #sparse_tensor<slice(?, 3, 1)>) -> (d0 : compressed(nonunique), d1 : singleton)
}>
#sel_trait = {
indexing_maps = [
affine_map<(i,j) -> (i,j)>, // C (in)
affine_map<(i,j) -> (i,j)>, // L (in)
affine_map<(i,j) -> (i,j)>, // R (in)
affine_map<(i,j) -> (i,j)> // X (out)
],
iterator_types = ["parallel", "parallel"]
}
// CHECK-LABEL: func @sparse_nop_cast(
// CHECK-SAME: %[[A:.*]]: tensor<?xf32, #sparse{{[0-9]*}}>)
// CHECK: return %[[A]] : tensor<?xf32, #sparse{{[0-9]*}}>
func.func @sparse_nop_cast(%a : tensor<?xf32, #SparseVector>) -> tensor<?xf32, #SparseVector> {
%0 = tensor.cast %a : tensor<?xf32, #SparseVector> to tensor<?xf32, #SparseVector>
%1 = tensor.cast %0 : tensor<?xf32, #SparseVector> to tensor<?xf32, #SparseVector>
%2 = tensor.cast %1 : tensor<?xf32, #SparseVector> to tensor<?xf32, #SparseVector>
return %2 : tensor<?xf32, #SparseVector>
}
// CHECK-LABEL: func @sparse_repair_cast(
// CHECK-SAME: %[[A:.*]]: tensor<?xf32>)
// CHECK: %[[C:.*]] = sparse_tensor.convert %[[A]] : tensor<?xf32> to tensor<?xf32, #sparse{{[0-9]*}}>
// CHECK: return %[[C]] : tensor<?xf32, #sparse{{[0-9]*}}>
func.func @sparse_repair_cast(%a : tensor<?xf32>) -> tensor<?xf32, #SparseVector> {
%0 = tensor.cast %a : tensor<?xf32> to tensor<?xf32, #SparseVector>
return %0 : tensor<?xf32, #SparseVector>
}
// CHECK-LABEL: func @sparse_fuse_slice(
// CHECK-SAME: %[[A:.*]]: tensor<2x3xi64, #sparse{{[0-9]*}}>)
// CHECK: %[[E:.*]] = tensor.extract_slice %[[A]][1, 0] [1, 3] [1, 1] : tensor<2x3xi64, #sparse{{[0-9]*}}> to tensor<1x3xi64, #sparse{{[0-9]*}}>
// CHECK: %[[C:.*]] = sparse_tensor.convert %[[E]] : tensor<1x3xi64, #sparse{{[0-9]*}}> to tensor<1x3xi64, #sparse{{[0-9]*}}>
// CHECK: return %[[C]] : tensor<1x3xi64, #sparse{{[0-9]*}}>
func.func @sparse_fuse_slice(%a : tensor<2x3xi64, #SortedCOO>) -> tensor<1x3xi64, #SortedCOO> {
%extracted_slice = tensor.extract_slice %a[1, 0] [1, 3] [1, 1] : tensor<2x3xi64, #SortedCOO> to tensor<1x3xi64>
%cast = tensor.cast %extracted_slice : tensor<1x3xi64> to tensor<1x3xi64, #Slice>
%0 = sparse_tensor.convert %cast : tensor<1x3xi64, #Slice> to tensor<1x3xi64, #SortedCOO>
return %0 : tensor<1x3xi64, #SortedCOO>
}
// CHECK-LABEL: func.func @sparse_select(
// CHECK-SAME: %[[VAL_0:.*]]: tensor<4x4xi1>,
// CHECK-SAME: %[[VAL_1:.*]]: tensor<4x4xf64, #sparse{{[0-9]*}}>,
// CHECK-SAME: %[[VAL_2:.*]]: tensor<4x4xf64, #sparse{{[0-9]*}}>) -> tensor<4x4xf64, #sparse{{[0-9]*}}> {
// CHECK-DAG: %[[VAL_3:.*]] = arith.constant 0.000000e+00 : f64
// CHECK-DAG: %[[VAL_4:.*]] = tensor.empty() : tensor<4x4xf64, #sparse{{[0-9]*}}>
// CHECK-NEXT: %[[VAL_5:.*]] = linalg.generic {indexing_maps = [#map, #map, #map, #map], iterator_types = ["parallel", "parallel"]}
// CHECK-SAME: ins(%[[VAL_0]], %[[VAL_1]], %[[VAL_2]]
// CHECK-NEXT: ^bb0(%[[VAL_6:.*]]: i1, %[[VAL_7:.*]]: f64, %[[VAL_8:.*]]: f64, %[[VAL_9:.*]]: f64):
// CHECK-NEXT: %[[VAL_10:.*]] = sparse_tensor.binary %[[VAL_7]], %[[VAL_8]] : f64, f64 to f64
// CHECK-NEXT: overlap = {
// CHECK-NEXT: ^bb0(%[[VAL_11:.*]]: f64, %[[VAL_12:.*]]: f64):
// CHECK-NEXT: %[[VAL_13:.*]] = arith.select %[[VAL_6]], %[[VAL_11]], %[[VAL_12]] : f64
// CHECK-NEXT: sparse_tensor.yield %[[VAL_13]] : f64
// CHECK-NEXT: }
// CHECK-NEXT: left = {
// CHECK-NEXT: ^bb0(%[[VAL_14:.*]]: f64):
// CHECK-NEXT: %[[VAL_15:.*]] = arith.select %[[VAL_6]], %[[VAL_14]], %[[VAL_3]] : f64
// CHECK-NEXT: sparse_tensor.yield %[[VAL_15]] : f64
// CHECK-NEXT: }
// CHECK-NEXT: right = {
// CHECK-NEXT: ^bb0(%[[VAL_16:.*]]: f64):
// CHECK-NEXT: %[[VAL_17:.*]] = arith.select %[[VAL_6]], %[[VAL_3]], %[[VAL_16]] : f64
// CHECK-NEXT: sparse_tensor.yield %[[VAL_17]] : f64
// CHECK-NEXT: }
// CHECK-NEXT: linalg.yield %[[VAL_10]] : f64
// CHECK-NEXT: } -> tensor<4x4xf64, #sparse{{[0-9]*}}>
// CHECK-NEXT: return %[[VAL_18:.*]] : tensor<4x4xf64, #sparse{{[0-9]*}}>
// CHECK-NEXT: }
func.func @sparse_select(%cond: tensor<4x4xi1>,
%arga: tensor<4x4xf64, #DCSR>,
%argb: tensor<4x4xf64, #DCSR>) -> tensor<4x4xf64, #DCSR> {
%xv = tensor.empty() : tensor<4x4xf64, #DCSR>
%0 = linalg.generic #sel_trait
ins(%cond, %arga, %argb: tensor<4x4xi1>, tensor<4x4xf64, #DCSR>, tensor<4x4xf64, #DCSR>)
outs(%xv: tensor<4x4xf64, #DCSR>) {
^bb(%c: i1, %a: f64, %b: f64, %x: f64):
%1 = arith.select %c, %a, %b : f64
linalg.yield %1 : f64
} -> tensor<4x4xf64, #DCSR>
return %0 : tensor<4x4xf64, #DCSR>
}