531 lines · plain
1// RUN: mlir-opt %s -split-input-file -verify-diagnostics2 3// expected-error@+1 {{expected '(' in dimension-specifier list}}4#a = #sparse_tensor.encoding<{map = []}>5func.func private @scalar(%arg0: tensor<f64, #a>) -> ()6 7// -----8 9// expected-error@+1 {{expected '->'}}10#a = #sparse_tensor.encoding<{map = ()}>11func.func private @scalar(%arg0: tensor<f64, #a>) -> ()12 13// -----14 15// expected-error@+1 {{expected ')' in dimension-specifier list}}16#a = #sparse_tensor.encoding<{map = (d0 -> d0)}>17func.func private @scalar(%arg0: tensor<f64, #a>) -> ()18 19// -----20 21// expected-error@+1 {{expected '(' in dimension-specifier list}}22#a = #sparse_tensor.encoding<{map = d0 -> d0}>23func.func private @scalar(%arg0: tensor<f64, #a>) -> ()24 25// -----26 27// expected-error@+1 {{expected '(' in level-specifier list}}28#a = #sparse_tensor.encoding<{map = (d0) -> d0}>29func.func private @scalar(%arg0: tensor<f64, #a>) -> ()30 31// -----32 33// expected-error@+1 {{expected ':'}}34#a = #sparse_tensor.encoding<{map = (d0) -> (d0)}>35func.func private @scalar(%arg0: tensor<f64, #a>) -> ()36 37// -----38 39// expected-error@+1 {{expected valid level format (e.g. dense, compressed or singleton)}}40#a = #sparse_tensor.encoding<{map = (d0) -> (d0:)}>41func.func private @scalar(%arg0: tensor<f64, #a>) -> ()42 43// -----44 45// expected-error@+1 {{expected valid level format (e.g. dense, compressed or singleton)}}46#a = #sparse_tensor.encoding<{map = (d0) -> (d0 : (compressed))}>47func.func private @scalar(%arg0: tensor<f64, #a>) -> ()48 49// -----50 51// expected-error@+2 {{dimension-rank mismatch between encoding and tensor shape: 2 != 1}}52#a = #sparse_tensor.encoding<{map = (d0, d1) -> (d0 : dense, d1 : compressed)}>53func.func private @tensor_dimlevel_size_mismatch(%arg0: tensor<8xi32, #a>) -> ()54 55// -----56 57// expected-error@+1 {{Batch lvlType can only be leading levels}}58#a = #sparse_tensor.encoding<{map = (d0, d1, d2) -> (d0 : batch, d1 : compressed, d2: batch)}>59func.func private @non_leading_batch(%arg0: tensor<?x?x?i32, #a>) -> ()60 61// -----62 63// expected-error@+1 {{use of undeclared identifier}}64#a = #sparse_tensor.encoding<{map = (d0) -> (d0 : dense, d1 : compressed)}>65func.func private @tensor_sizes_mismatch(%arg0: tensor<8xi32, #a>) -> ()66 67// -----68 69// expected-error@+1 {{failed to infer lvlToDim from dimToLvl}}70#a = #sparse_tensor.encoding<{map = (d0, d1) -> (d0 : dense)}>71func.func private @tensor_sizes_mismatch(%arg0: tensor<8xi32, #a>) -> ()72 73// -----74 75// expected-error@+1 {{expected bare identifier}}76#a = #sparse_tensor.encoding<{map = (1)}>77func.func private @tensor_type_mismatch(%arg0: tensor<8xi32, #a>) -> ()78 79// -----80 81// expected-error@+1 {{unexpected key: nap}}82#a = #sparse_tensor.encoding<{nap = (d0) -> (d0 : dense)}>83func.func private @tensor_type_mismatch(%arg0: tensor<8xi32, #a>) -> ()84 85// -----86 87// expected-error@+1 {{expected '(' in dimension-specifier list}}88#a = #sparse_tensor.encoding<{map = -> (d0 : dense)}>89func.func private @tensor_type_mismatch(%arg0: tensor<8xi32, #a>) -> ()90 91// -----92 93// expected-error@+1 {{unknown level format: strange}}94#a = #sparse_tensor.encoding<{map = (d0) -> (d0 : strange)}>95func.func private @tensor_value_mismatch(%arg0: tensor<8xi32, #a>) -> ()96 97// -----98 99// expected-error@+1 {{expected valid level format (e.g. dense, compressed or singleton)}}100#a = #sparse_tensor.encoding<{map = (d0) -> (d0 : "wrong")}>101func.func private @tensor_dimtolvl_mismatch(%arg0: tensor<8xi32, #a>) -> ()102 103// -----104 105// expected-error@+1 {{expected valid level property (e.g. nonordered, nonunique or high)}}106#a = #sparse_tensor.encoding<{map = (d0) -> (d0 : compressed("wrong"))}>107func.func private @tensor_dimtolvl_mismatch(%arg0: tensor<8xi32, #a>) -> ()108 109// -----110// expected-error@+1 {{expected ')' in level-specifier list}}111#a = #sparse_tensor.encoding<{map = (d0) -> (d0 : compressed[high])}>112func.func private @tensor_dimtolvl_mismatch(%arg0: tensor<8xi32, #a>) -> ()113 114// -----115 116// expected-error@+1 {{unknown level property: wrong}}117#a = #sparse_tensor.encoding<{map = (d0) -> (d0 : compressed(wrong))}>118func.func private @tensor_dimtolvl_mismatch(%arg0: tensor<8xi32, #a>) -> ()119 120// -----121 122// expected-error@+1 {{use of undeclared identifier}}123#a = #sparse_tensor.encoding<{map = (d0) -> (d0 : compressed, dense)}>124func.func private @tensor_dimtolvl_mismatch(%arg0: tensor<8xi32, #a>) -> ()125 126// -----127 128// expected-error@+1 {{failed to infer lvlToDim from dimToLvl}}129#a = #sparse_tensor.encoding<{map = (d0, d1) -> (d0 : dense, d0 : compressed)}>130func.func private @tensor_no_permutation(%arg0: tensor<16x32xf32, #a>) -> ()131 132// -----133 134// expected-error@+1 {{unexpected character}}135#a = #sparse_tensor.encoding<{map = (d0, d1) -> (d0 : compressed; d1 : dense)}>136func.func private @tensor_dimtolvl_mismatch(%arg0: tensor<16x32xi32, #a>) -> ()137 138// -----139 140// expected-error@+1 {{expected attribute value}}141#a = #sparse_tensor.encoding<{map = (d0: d1) -> (d0 : compressed, d1 : dense)}>142func.func private @tensor_dimtolvl_mismatch(%arg0: tensor<16x32xi32, #a>) -> ()143 144// -----145 146// expected-error@+1 {{expected ':'}}147#a = #sparse_tensor.encoding<{map = (d0, d1) -> (d0 = compressed, d1 = dense)}>148func.func private @tensor_dimtolvl_mismatch(%arg0: tensor<16x32xi32, #a>) -> ()149 150// -----151 152// expected-error@+1 {{expected attribute value}}153#a = #sparse_tensor.encoding<{map = (d0 : compressed, d1 : compressed)}>154func.func private @tensor_dimtolvl_mismatch(%arg0: tensor<16x32xi32, #a>) -> ()155 156// -----157 158// expected-error@+1 {{use of undeclared identifier}}159#a = #sparse_tensor.encoding<{map = (d0 = compressed, d1 = compressed)}>160func.func private @tensor_dimtolvl_mismatch(%arg0: tensor<16x32xi32, #a>) -> ()161 162// -----163 164// expected-error@+1 {{use of undeclared identifier}}165#a = #sparse_tensor.encoding<{map = (d0 = l0, d1 = l1) {l0, l1} -> (l0 = d0 : dense, l1 = d1 : compressed)}>166func.func private @tensor_dimtolvl_mismatch(%arg0: tensor<16x32xi32, #a>) -> ()167 168// -----169 170// expected-error@+1 {{expected '='}}171#a = #sparse_tensor.encoding<{map = {l0, l1} (d0 = l0, d1 = l1) -> (l0 : d0 = dense, l1 : d1 = compressed)}>172func.func private @tensor_dimtolvl_mismatch(%arg0: tensor<16x32xi32, #a>) -> ()173 174// -----175// expected-error@+1 {{use of undeclared identifier 'd0'}}176#a = #sparse_tensor.encoding<{map = {l0, l1} (d0 = l0, d1 = l1) -> (d0 : l0 = dense, d1 : l1 = compressed)}>177func.func private @tensor_dimtolvl_mismatch(%arg0: tensor<16x32xi32, #a>) -> ()178 179// -----180// expected-error@+1 {{use of undeclared identifier 'd0'}}181#a = #sparse_tensor.encoding<{map = {l0, l1} (d0 = l0, d1 = l1) -> (d0 : dense, d1 : compressed)}>182func.func private @tensor_dimtolvl_mismatch(%arg0: tensor<16x32xi32, #a>) -> ()183 184// -----185// expected-error@+1 {{expected '='}}186#a = #sparse_tensor.encoding<{map = {l0, l1} (d0 = l0, d1 = l1) -> (l0 : dense, l1 : compressed)}>187func.func private @tensor_dimtolvl_mismatch(%arg0: tensor<16x32xi32, #a>) -> ()188 189// -----190// expected-error@+1 {{use of undeclared identifier}}191#a = #sparse_tensor.encoding<{map = {l0, l1} (d0 = l0, d1 = l1) -> (l0 = dense, l1 = compressed)}>192func.func private @tensor_dimtolvl_mismatch(%arg0: tensor<16x32xi32, #a>) -> ()193 194// -----195// expected-error@+1 {{use of undeclared identifier 'd0'}}196#a = #sparse_tensor.encoding<{map = {l0, l1} (d0 = l0, d1 = l1) -> (d0 = l0 : dense, d1 = l1 : compressed)}>197func.func private @tensor_dimtolvl_mismatch(%arg0: tensor<16x32xi32, #a>) -> ()198 199// -----200 201#a = #sparse_tensor.encoding<{posWidth = "x"}> // expected-error {{expected an integral position bitwidth}}202func.func private @tensor_no_int_ptr(%arg0: tensor<16x32xf32, #a>) -> ()203 204// -----205 206#a = #sparse_tensor.encoding<{posWidth = 42}> // expected-error {{unexpected position bitwidth: 42}}207func.func private @tensor_invalid_int_ptr(%arg0: tensor<16x32xf32, #a>) -> ()208 209// -----210 211#a = #sparse_tensor.encoding<{crdWidth = "not really"}> // expected-error {{expected an integral index bitwidth}}212func.func private @tensor_no_int_index(%arg0: tensor<16x32xf32, #a>) -> ()213 214// -----215 216#a = #sparse_tensor.encoding<{crdWidth = 128}> // expected-error {{unexpected coordinate bitwidth: 128}}217func.func private @tensor_invalid_int_index(%arg0: tensor<16x32xf32, #a>) -> ()218 219// -----220 221#a = #sparse_tensor.encoding<{key = 1}> // expected-error {{unexpected key: key}}222func.func private @tensor_invalid_key(%arg0: tensor<16x32xf32, #a>) -> ()223 224// -----225 226#CSR_SLICE = #sparse_tensor.encoding<{227 map = (d0 : #sparse_tensor<slice(-1, ?, 1)>, d1 : #sparse_tensor<slice(?, 4, 2)>) -> (d0 : dense, d1 : compressed)// expected-error{{expect positive value or ? for slice offset/size/stride}}228}>229func.func private @sparse_slice(tensor<?x?xf64, #CSR_SLICE>)230 231// -----232 233// expected-error@+2 {{Level-rank mismatch between forward-declarations and specifiers. Declared 3 level-variables; but got 2 level-specifiers.}}234#TooManyLvlDecl = #sparse_tensor.encoding<{235 map = {l0, l1, l2} (d0, d1) -> (l0 = d0 : dense, l1 = d1 : compressed)236}>237func.func private @too_many_lvl_decl(%arg0: tensor<?x?xf64, #TooManyLvlDecl>) {238 return239}240 241// -----242 243// expected-error@+1{{expected all singleton lvlTypes stored in the same memory layout (SoA vs AoS).}}244#COO_SoA = #sparse_tensor.encoding<{245 map = (d0, d1, d2) -> (d0 : compressed(nonunique), d1 : singleton(soa, nonunique), d2 : singleton)246}>247func.func private @sparse_coo(tensor<?x?xf32, #COO_SoA>)248 249// -----250 251// expected-error@+1{{SoA is only applicable to singleton lvlTypes.}}252#COO_SoA = #sparse_tensor.encoding<{253 map = (d0, d1) -> (d0 : compressed(nonunique, soa), d1 : singleton(soa))254}>255func.func private @sparse_coo(tensor<?x?xf32, #COO_SoA>)256 257// -----258 259// expected-error@+2 {{use of undeclared identifier 'l1'}}260#TooFewLvlDecl = #sparse_tensor.encoding<{261 map = {l0} (d0, d1) -> (l0 = d0 : dense, l1 = d1 : compressed)262}>263func.func private @too_few_lvl_decl(%arg0: tensor<?x?xf64, #TooFewLvlDecl>) {264 return265}266 267// -----268 269// expected-error@+2 {{Level-variable ordering mismatch. The variable 'l0' was forward-declared as the 1st level; but is bound by the 0th specification.}}270#WrongOrderLvlDecl = #sparse_tensor.encoding<{271 map = {l1, l0} (d0, d1) -> (l0 = d0 : dense, l1 = d1 : compressed)272}>273func.func private @wrong_order_lvl_decl(%arg0: tensor<?x?xf64, #WrongOrderLvlDecl>) {274 return275}276 277// -----278 279// expected-error@+1 {{failed to infer lvlToDim from dimToLvl}}280#BSR = #sparse_tensor.encoding<{281 map = ( i, j ) ->282 ( i floordiv 2 : dense,283 j floordiv 3 : compressed,284 i : dense,285 j mod 3 : dense286 )287}>288func.func private @BSR(%arg0: tensor<?x?xf64, #BSR>) {289 return290}291 292// -----293 294// expected-error@+1 {{failed to infer lvlToDim from dimToLvl}}295#BSR = #sparse_tensor.encoding<{296 map = ( i, j ) ->297 ( i : dense,298 j floordiv 3 : compressed,299 i floordiv 3 : dense,300 j mod 3 : dense301 )302}>303func.func private @BSR(%arg0: tensor<?x?xf64, #BSR>) {304 return305}306 307// -----308 309// expected-error@+1 {{failed to infer lvlToDim from dimToLvl}}310#BSR = #sparse_tensor.encoding<{311 map = ( i, j ) ->312 ( i floordiv -3 : dense,313 j floordiv -3 : compressed,314 i mod 3 : dense,315 j mod 3 : dense316 )317}>318func.func private @BSR(%arg0: tensor<?x?xf64, #BSR>) {319 return320}321 322// -----323 324// expected-error@+1 {{expected lvlToDim to be an inverse of dimToLvl}}325#BSR_explicit = #sparse_tensor.encoding<{326 map =327 {il, jl, ii, jj}328 ( i = il * 3 + ii,329 j = jl * 2 + jj330 ) ->331 ( il = i floordiv 2 : dense,332 jl = j floordiv 3 : compressed,333 ii = i mod 2 : dense,334 jj = j mod 3 : dense335 )336}>337func.func private @BSR_explicit(%arg0: tensor<?x?xf64, #BSR_explicit>) {338 return339}340 341// -----342 343// expected-error@+6 {{expected structured size to be >= 0}}344#NOutOfM = #sparse_tensor.encoding<{345 map = ( i, j, k ) ->346 ( i : dense,347 k floordiv 4 : dense,348 j : dense,349 k mod 4 : structured[-2, 4]350 )351}>352func.func private @NOutOfM(%arg0: tensor<?x?x?xf64, #NOutOfM>) {353 return354}355 356// -----357 358// expected-error@+6 {{expected n <= m in n_out_of_m}}359#NOutOfM = #sparse_tensor.encoding<{360 map = ( i, j, k ) ->361 ( i : dense,362 k floordiv 4 : dense,363 j : dense,364 k mod 4 : structured[5, 4]365 )366}>367func.func private @NOutOfM(%arg0: tensor<?x?x?xf64, #NOutOfM>) {368 return369}370 371// -----372 373// expected-error@+1 {{expected all dense lvlTypes before a n_out_of_m level}}374#NOutOfM = #sparse_tensor.encoding<{375 map = ( i, j, k ) ->376 ( i : dense,377 k floordiv 4 : compressed,378 j : dense,379 k mod 4 : structured[2, 4]380 )381}>382func.func private @NOutOfM(%arg0: tensor<?x?x?xf64, #NOutOfM>) {383 return384}385 386// -----387 388// expected-error@+1 {{expected n_out_of_m to be the last level type}}389#NOutOfM = #sparse_tensor.encoding<{390 map = ( i, j, k ) ->391 ( i : dense,392 k floordiv 4 : structured[2, 4],393 j : dense,394 k mod 4 : compressed395 )396}>397func.func private @NOutOfM(%arg0: tensor<?x?x?xf64, #NOutOfM>) {398 return399}400 401// -----402 403// expected-error@+1 {{expected 1xm block structure for n_out_of_m level}}404#NOutOfM = #sparse_tensor.encoding<{405 map = ( i, j, k ) ->406 ( i : dense,407 k floordiv 2 : dense,408 j : dense,409 k mod 4 : structured[2, 4]410 )411}>412func.func private @NOutOfM(%arg0: tensor<?x?x?xf64, #NOutOfM>) {413 return414}415 416// -----417 418// expected-error@+1 {{expected coeffiencts of Affine expressions to be equal to m of n_out_of_m level}}419#NOutOfM = #sparse_tensor.encoding<{420 map = ( i, j, k ) ->421 ( i : dense,422 k floordiv 2 : dense,423 j : dense,424 k mod 2 : structured[2, 4]425 )426}>427func.func private @NOutOfM(%arg0: tensor<?x?x?xf64, #NOutOfM>) {428 return429}430 431// -----432 433// expected-error@+1 {{expected only one blocked level with the same coefficients}}434#NOutOfM = #sparse_tensor.encoding<{435 map = ( i, j, k ) ->436 ( i floordiv 2 : dense,437 i mod 2 : dense,438 j : dense,439 k floordiv 4 : dense,440 k mod 4 : structured[2, 4]441 )442}>443func.func private @NOutOfM(%arg0: tensor<?x?x?xf64, #NOutOfM>) {444 return445}446 447// -----448 449#CSR_ExpType = #sparse_tensor.encoding<{450 map = (d0, d1) -> (d0 : dense, d1 : compressed),451 posWidth = 32,452 crdWidth = 32,453 explicitVal = 1 : i32,454 implicitVal = 0.0 : f32455}>456 457// expected-error@+1 {{explicit value type mismatch between encoding and tensor element type: 'i32' != 'f32'}}458func.func private @sparse_csr(tensor<?x?xf32, #CSR_ExpType>)459 460// -----461 462#CSR_ImpType = #sparse_tensor.encoding<{463 map = (d0, d1) -> (d0 : dense, d1 : compressed),464 posWidth = 32,465 crdWidth = 32,466 explicitVal = 1 : i32,467 implicitVal = 0.0 : f32468}>469 470// expected-error@+1 {{implicit value type mismatch between encoding and tensor element type: 'f32' != 'i32'}}471func.func private @sparse_csr(tensor<?x?xi32, #CSR_ImpType>)472 473// -----474 475// expected-error@+1 {{expected a numeric value for explicitVal}}476#CSR_ExpType = #sparse_tensor.encoding<{477 map = (d0, d1) -> (d0 : dense, d1 : compressed),478 posWidth = 32,479 crdWidth = 32,480 explicitVal = "str"481}>482func.func private @sparse_csr(tensor<?x?xi32, #CSR_ExpType>)483 484// -----485 486// expected-error@+1 {{expected a numeric value for implicitVal}}487#CSR_ImpType = #sparse_tensor.encoding<{488 map = (d0, d1) -> (d0 : dense, d1 : compressed),489 posWidth = 32,490 crdWidth = 32,491 implicitVal = "str"492}>493func.func private @sparse_csr(tensor<?x?xi32, #CSR_ImpType>)494 495// -----496 497#CSR_ImpVal = #sparse_tensor.encoding<{498 map = (d0, d1) -> (d0 : dense, d1 : compressed),499 posWidth = 32,500 crdWidth = 32,501 implicitVal = 1 : i32502}>503 504// expected-error@+1 {{implicit value must be zero}}505func.func private @sparse_csr(tensor<?x?xi32, #CSR_ImpVal>)506 507// -----508 509#CSR_ImpVal = #sparse_tensor.encoding<{510 map = (d0, d1) -> (d0 : dense, d1 : compressed),511 posWidth = 32,512 crdWidth = 32,513 implicitVal = 1.0 : f32514}>515 516// expected-error@+1 {{implicit value must be zero}}517func.func private @sparse_csr(tensor<?x?xf32, #CSR_ImpVal>)518 519// -----520 521#CSR_OnlyOnes = #sparse_tensor.encoding<{522 map = (d0, d1) -> (d0 : dense, d1 : compressed),523 posWidth = 64,524 crdWidth = 64,525 explicitVal = #complex.number<:f32 1.0, 0.0>,526 implicitVal = #complex.number<:f32 1.0, 0.0>527}>528 529// expected-error@+1 {{implicit value must be zero}}530func.func private @sparse_csr(tensor<?x?xcomplex<f32>, #CSR_OnlyOnes>)531