486 lines · plain
1// RUN: mlir-opt -transform-interpreter -canonicalize -split-input-file -verify-diagnostics %s | FileCheck %s2 3// expected-remark @below {{attr associated to "test.id" = 42 : i32}}4module attributes { test.dlti = #dlti.map<"test.id" = 42 : i32> } {5 func.func private @f()6}7 8module attributes {transform.with_named_sequence} {9 transform.named_sequence @__transform_main(%arg: !transform.any_op) {10 %funcs = transform.structured.match ops{["func.func"]} in %arg : (!transform.any_op) -> !transform.any_op11 %module = transform.get_parent_op %funcs : (!transform.any_op) -> !transform.any_op12 %param = transform.dlti.query ["test.id"] at %module : (!transform.any_op) -> !transform.any_param13 transform.debug.emit_param_as_remark %param, "attr associated to \"test.id\" =" at %module : !transform.any_param, !transform.any_op14 transform.yield15 }16}17 18// -----19 20// expected-remark @below {{i32 present in set : unit}}21module attributes { test.dlti = #dlti.map<i32 = unit> } {22 func.func private @f()23}24 25module attributes {transform.with_named_sequence} {26 transform.named_sequence @__transform_main(%arg: !transform.any_op) {27 %funcs = transform.structured.match ops{["func.func"]} in %arg : (!transform.any_op) -> !transform.any_op28 %module = transform.get_parent_op %funcs : (!transform.any_op) -> !transform.any_op29 %param = transform.dlti.query [i32] at %module : (!transform.any_op) -> !transform.any_param30 transform.debug.emit_param_as_remark %param, "i32 present in set :" at %module : !transform.any_param, !transform.any_op31 transform.yield32 }33}34 35// -----36 37// expected-remark @below {{attr associated to i32's "width_in_bits" = 32 : i32}}38module attributes { test.dlti = #dlti.map<i32 = #dlti.map<"width_in_bits" = 32 : i32>> } {39 func.func private @f()40}41 42module attributes {transform.with_named_sequence} {43 transform.named_sequence @__transform_main(%arg: !transform.any_op) {44 %funcs = transform.structured.match ops{["func.func"]} in %arg : (!transform.any_op) -> !transform.any_op45 %module = transform.get_parent_op %funcs : (!transform.any_op) -> !transform.any_op46 %param = transform.dlti.query [i32,"width_in_bits"] at %module : (!transform.any_op) -> !transform.any_param47 transform.debug.emit_param_as_remark %param, "attr associated to i32's \"width_in_bits\" =" at %module : !transform.any_param, !transform.any_op48 transform.yield49 }50}51 52// -----53 54// expected-remark @below {{width in bits of i32 = 32 : i64}}55// expected-remark @below {{width in bits of f64 = 64 : i64}}56module attributes { test.dlti = #dlti.map<"width_in_bits" = #dlti.map<i32 = 32, f64 = 64>> } {57 func.func private @f()58}59 60module attributes {transform.with_named_sequence} {61 transform.named_sequence @__transform_main(%arg: !transform.any_op) {62 %funcs = transform.structured.match ops{["func.func"]} in %arg : (!transform.any_op) -> !transform.any_op63 %module = transform.get_parent_op %funcs : (!transform.any_op) -> !transform.any_op64 %i32bits = transform.dlti.query ["width_in_bits",i32] at %module : (!transform.any_op) -> !transform.any_param65 %f64bits = transform.dlti.query ["width_in_bits",f64] at %module : (!transform.any_op) -> !transform.any_param66 transform.debug.emit_param_as_remark %i32bits, "width in bits of i32 =" at %module : !transform.any_param, !transform.any_op67 transform.debug.emit_param_as_remark %f64bits, "width in bits of f64 =" at %module : !transform.any_param, !transform.any_op68 transform.yield69 }70}71 72// -----73 74// expected-remark @below {{attr associated to "test.id" = 42 : i32}}75module attributes { test.dlti = #dlti.dl_spec<"test.id" = 42 : i32> } {76 func.func private @f()77}78 79module attributes {transform.with_named_sequence} {80 transform.named_sequence @__transform_main(%arg: !transform.any_op) {81 %funcs = transform.structured.match ops{["func.func"]} in %arg : (!transform.any_op) -> !transform.any_op82 %module = transform.get_parent_op %funcs : (!transform.any_op) -> !transform.any_op83 %param = transform.dlti.query ["test.id"] at %module : (!transform.any_op) -> !transform.any_param84 transform.debug.emit_param_as_remark %param, "attr associated to \"test.id\" =" at %module : !transform.any_param, !transform.any_op85 transform.yield86 }87}88 89// -----90 91module attributes { test.dlti = #dlti.dl_spec<"test.id" = 42 : i32> } {92 // expected-remark @below {{attr associated to "test.id" = 24 : i32}}93 func.func private @f() attributes { test.dlti = #dlti.dl_spec<"test.id" = 24 : i32>}94}95 96module attributes {transform.with_named_sequence} {97 transform.named_sequence @__transform_main(%arg: !transform.any_op) {98 %funcs = transform.structured.match ops{["func.func"]} in %arg : (!transform.any_op) -> !transform.any_op99 %param = transform.dlti.query ["test.id"] at %funcs : (!transform.any_op) -> !transform.any_param100 transform.debug.emit_param_as_remark %param, "attr associated to \"test.id\" =" at %funcs : !transform.any_param, !transform.any_op101 transform.yield102 }103}104 105// -----106 107// expected-remark @below {{attr associated to "test.id" = 42 : i32}}108module attributes { test.dlti = #dlti.dl_spec<"test.id" = 42 : i32> } {109 func.func private @f() attributes { test.dlti = #dlti.dl_spec<"test.id" = 24 : i32> }110}111 112module attributes {transform.with_named_sequence} {113 transform.named_sequence @__transform_main(%arg: !transform.any_op) {114 %funcs = transform.structured.match ops{["func.func"]} in %arg : (!transform.any_op) -> !transform.any_op115 %module = transform.get_parent_op %funcs : (!transform.any_op) -> !transform.any_op116 %param = transform.dlti.query ["test.id"] at %module : (!transform.any_op) -> !transform.any_param117 transform.debug.emit_param_as_remark %param, "attr associated to \"test.id\" =" at %module : !transform.any_param, !transform.any_op118 transform.yield119 }120}121 122// -----123 124module attributes { test.dlti = #dlti.dl_spec<"test.id" = 42 : i32> } {125 func.func @matmul_tensors(126 %arg0: tensor<?x?xf32>, %arg1: tensor<?x?xf32>, %arg2: tensor<?x?xf32>)127 -> tensor<?x?xf32> {128 // expected-remark @below {{associated attr 42 : i32}}129 %0 = linalg.matmul ins(%arg0, %arg1: tensor<?x?xf32>, tensor<?x?xf32>)130 outs(%arg2: tensor<?x?xf32>)131 -> tensor<?x?xf32>132 return %0 : tensor<?x?xf32>133 }134}135 136module attributes {transform.with_named_sequence} {137 transform.named_sequence @__transform_main(%arg: !transform.any_op) {138 %matmul = transform.structured.match ops{["linalg.matmul"]} in %arg : (!transform.any_op) -> !transform.any_op139 %param = transform.dlti.query ["test.id"] at %matmul : (!transform.any_op) -> !transform.any_param140 transform.debug.emit_param_as_remark %param, "associated attr" at %matmul : !transform.any_param, !transform.any_op141 transform.yield142 }143}144 145// -----146 147module attributes { test.dlti = #dlti.dl_spec<"test.id" = 42 : i32> } {148 func.func @matmul_tensors(149 %arg0: tensor<?x?xf32>, %arg1: tensor<?x?xf32>, %arg2: tensor<?x?xf32>)150 -> tensor<?x?xf32> attributes {test.dlti = #dlti.dl_spec<"test.id" = 24 : i32> } {151 // expected-remark @below {{associated attr 24 : i32}}152 %0 = linalg.matmul ins(%arg0, %arg1: tensor<?x?xf32>, tensor<?x?xf32>)153 outs(%arg2: tensor<?x?xf32>)154 -> tensor<?x?xf32>155 return %0 : tensor<?x?xf32>156 }157}158 159module attributes {transform.with_named_sequence} {160 transform.named_sequence @__transform_main(%arg: !transform.any_op) {161 %matmul = transform.structured.match ops{["linalg.matmul"]} in %arg : (!transform.any_op) -> !transform.any_op162 %param = transform.dlti.query ["test.id"] at %matmul : (!transform.any_op) -> !transform.any_param163 transform.debug.emit_param_as_remark %param, "associated attr" at %matmul : !transform.any_param, !transform.any_op164 transform.yield165 }166}167 168// -----169 170// expected-remark @below {{associated attr 42 : i32}}171module attributes { test.dlti =172 #dlti.target_system_spec<"CPU" =173 #dlti.target_device_spec<"test.id" = 42 : i32>> } {174 func.func private @f()175}176 177module attributes {transform.with_named_sequence} {178 transform.named_sequence @__transform_main(%arg: !transform.any_op) {179 %func = transform.structured.match ops{["func.func"]} in %arg : (!transform.any_op) -> !transform.any_op180 %module = transform.get_parent_op %func : (!transform.any_op) -> !transform.any_op181 %param = transform.dlti.query ["CPU","test.id"] at %module : (!transform.any_op) -> !transform.any_param182 transform.debug.emit_param_as_remark %param, "associated attr" at %module : !transform.any_param, !transform.any_op183 transform.yield184 }185}186 187// -----188 189module attributes { test.dlti = #dlti.target_system_spec<"CPU" = #dlti.target_device_spec<"test.id" = 42 : i32>,190 "GPU" = #dlti.target_device_spec<"test.id" = 43 : i32>> } {191 // expected-remark @below {{associated attr 43 : i32}}192 func.func private @f()193}194 195module attributes {transform.with_named_sequence} {196 transform.named_sequence @__transform_main(%arg: !transform.any_op) {197 %func = transform.structured.match ops{["func.func"]} in %arg : (!transform.any_op) -> !transform.any_op198 %param = transform.dlti.query ["GPU","test.id"] at %func : (!transform.any_op) -> !transform.any_param199 transform.debug.emit_param_as_remark %param, "associated attr" at %func : !transform.any_param, !transform.any_op200 transform.yield201 }202}203 204// -----205 206module attributes { test.dlti = #dlti.target_system_spec<"CPU" = #dlti.target_device_spec<"test.id" = 42 : i32>,207 "GPU" = #dlti.target_device_spec<"test.id" = 43 : i32>> } {208 // expected-remark @below {{associated attr 24 : i32}}209 func.func private @f() attributes { test.dlti = #dlti.target_system_spec<"CPU" = #dlti.target_device_spec<"test.id" = 24 : i32>> }210}211 212module attributes {transform.with_named_sequence} {213 transform.named_sequence @__transform_main(%arg: !transform.any_op) {214 %func = transform.structured.match ops{["func.func"]} in %arg : (!transform.any_op) -> !transform.any_op215 %param = transform.dlti.query ["CPU","test.id"] at %func : (!transform.any_op) -> !transform.any_param216 transform.debug.emit_param_as_remark %param, "associated attr" at %func : !transform.any_param, !transform.any_op217 transform.yield218 }219}220 221// -----222 223module attributes { test.dlti = #dlti.target_system_spec<224 "CPU" = #dlti.target_device_spec<225 "cache::L1::size_in_bytes" = 65536 : i32,226 "cache::L1d::size_in_bytes" = 32768 : i32>> } {227 // expected-remark @below {{L1::size_in_bytes 65536 : i32}}228 // expected-remark @below {{L1d::size_in_bytes 32768 : i32}}229 func.func private @f()230}231 232module attributes {transform.with_named_sequence} {233 transform.named_sequence @__transform_main(%arg: !transform.any_op) {234 %func = transform.structured.match ops{["func.func"]} in %arg : (!transform.any_op) -> !transform.any_op235 %l1_size = transform.dlti.query ["CPU","cache::L1::size_in_bytes"] at %func : (!transform.any_op) -> !transform.param<i32>236 %l1d_size = transform.dlti.query ["CPU","cache::L1d::size_in_bytes"] at %func : (!transform.any_op) -> !transform.param<i32>237 transform.debug.emit_param_as_remark %l1_size, "L1::size_in_bytes" at %func : !transform.param<i32>, !transform.any_op238 transform.debug.emit_param_as_remark %l1d_size, "L1d::size_in_bytes" at %func : !transform.param<i32>, !transform.any_op239 transform.yield240 }241}242 243// -----244 245#l1_size = #dlti.map<"size_in_bytes" = 65536 : i32>246#l1d_size = #dlti.map<"size_in_bytes" = 32768 : i32>247module attributes { test.dlti =248 #dlti.target_system_spec<"CPU" =249 #dlti.target_device_spec<"cache" =250 #dlti.map<"L1" = #l1_size,251 "L1d" = #l1d_size >>> } {252 // expected-remark @below {{L1::size_in_bytes 65536 : i32}}253 // expected-remark @below {{L1d::size_in_bytes 32768 : i32}}254 func.func private @f()255}256 257module attributes {transform.with_named_sequence} {258 transform.named_sequence @__transform_main(%arg: !transform.any_op) {259 %func = transform.structured.match ops{["func.func"]} in %arg : (!transform.any_op) -> !transform.any_op260 %l1_size = transform.dlti.query ["CPU","cache","L1","size_in_bytes"] at %func : (!transform.any_op) -> !transform.param<i32>261 %l1d_size = transform.dlti.query ["CPU","cache","L1d","size_in_bytes"] at %func : (!transform.any_op) -> !transform.param<i32>262 transform.debug.emit_param_as_remark %l1_size, "L1::size_in_bytes" at %func : !transform.param<i32>, !transform.any_op263 transform.debug.emit_param_as_remark %l1d_size, "L1d::size_in_bytes" at %func : !transform.param<i32>, !transform.any_op264 transform.yield265 }266}267 268// -----269 270module attributes { test.dlti = #dlti.target_system_spec<271 "CPU" = #dlti.target_device_spec<"inner_most_tile_size" = 42 : i32>> } {272 // CHECK-LABEL: func @matmul_tensors273 func.func @matmul_tensors(274 %arg0: tensor<?x?xf32>, %arg1: tensor<?x?xf32>, %arg2: tensor<?x?xf32>)275 -> tensor<?x?xf32> {276 // CHECK: scf.for {{.*}} to {{.*}} step {{.*}}42277 // CHECK: tensor.extract_slice278 // CHECK: linalg.matmul279 // CHECK: tensor.insert_slice280 // CHECK: scf.yield281 %0 = linalg.matmul ins(%arg0, %arg1: tensor<?x?xf32>, tensor<?x?xf32>)282 outs(%arg2: tensor<?x?xf32>)283 -> tensor<?x?xf32>284 // CHECK: return285 return %0 : tensor<?x?xf32>286 }287}288 289// Demonstrates obtaining transform op parameters from DLTI attributes and directly putting them to use.290module attributes {transform.with_named_sequence} {291 transform.named_sequence @__transform_main(%arg: !transform.any_op) {292 %matmul = transform.structured.match ops{["linalg.matmul"]} in %arg : (!transform.any_op) -> !transform.any_op293 %tile_size = transform.dlti.query ["CPU","inner_most_tile_size"] at %matmul : (!transform.any_op) -> !transform.param<i32>294 transform.structured.tile_using_for %matmul tile_sizes [%tile_size] : (!transform.any_op, !transform.param<i32>) -> (!transform.any_op, !transform.any_op)295 transform.yield296 }297}298 299// -----300 301// expected-note @below {{key "NPU" has no DLTI-mapping per attr: #dlti.target_system_spec}}302module attributes { test.dlti = #dlti.target_system_spec<303 "CPU" = #dlti.target_device_spec<"test.id" = 42 : i32>,304 "GPU" = #dlti.target_device_spec<"test.id" = 43 : i32>> } {305 // expected-error @below {{target op of failed DLTI query}}306 func.func private @f()307}308 309module attributes {transform.with_named_sequence} {310 transform.named_sequence @__transform_main(%arg: !transform.any_op) {311 %func = transform.structured.match ops{["func.func"]} in %arg : (!transform.any_op) -> !transform.any_op312 // expected-error @below {{'transform.dlti.query' op failed to apply}}313 %param = transform.dlti.query ["NPU","test.id"] at %func : (!transform.any_op) -> !transform.any_param314 transform.yield315 }316}317 318// -----319 320// expected-note @below {{key "unspecified" has no DLTI-mapping per attr: #dlti.target_device_spec}}321module attributes { test.dlti = #dlti.target_system_spec<322 "CPU" = #dlti.target_device_spec<"test.id" = 42 : i32>,323 "GPU" = #dlti.target_device_spec<"test.id" = 43 : i32>> } {324 // expected-error @below {{target op of failed DLTI query}}325 func.func private @f()326}327 328module attributes {transform.with_named_sequence} {329 transform.named_sequence @__transform_main(%arg: !transform.any_op) {330 %func = transform.structured.match ops{["func.func"]} in %arg : (!transform.any_op) -> !transform.any_op331 // expected-error @below {{'transform.dlti.query' op failed to apply}}332 %param = transform.dlti.query ["CPU","unspecified"] at %func : (!transform.any_op) -> !transform.any_param333 transform.yield334 }335}336 337// -----338 339// expected-note @below {{key "test.id" has no DLTI-mapping per attr: #dlti.target_system_spec}}340module attributes { test.dlti = #dlti.target_system_spec<341 "CPU" = #dlti.target_device_spec<"test.id" = 42 : i32>,342 "GPU" = #dlti.target_device_spec<"test.id" = 43 : i32>> } {343 // expected-error @below {{target op of failed DLTI query}}344 func.func private @f()345}346 347module attributes {transform.with_named_sequence} {348 transform.named_sequence @__transform_main(%arg: !transform.any_op) {349 %func = transform.structured.match ops{["func.func"]} in %arg : (!transform.any_op) -> !transform.any_op350 // expected-error @below {{'transform.dlti.query' op failed to apply}}351 %param = transform.dlti.query ["test.id"] at %func : (!transform.any_op) -> !transform.any_param352 transform.yield353 }354}355 356// -----357 358// expected-note @below {{key "CPU" has no DLTI-mapping per attr: #dlti.dl_spec}}359module attributes { test.dlti = #dlti.dl_spec<"test.id" = 42 : i32> } {360 // expected-error @below {{target op of failed DLTI query}}361 func.func private @f()362}363 364module attributes {transform.with_named_sequence} {365 transform.named_sequence @__transform_main(%arg: !transform.any_op) {366 %func = transform.structured.match ops{["func.func"]} in %arg : (!transform.any_op) -> !transform.any_op367 // expected-error @below {{'transform.dlti.query' op failed to apply}}368 %param = transform.dlti.query ["CPU","test.id"] at %func : (!transform.any_op) -> !transform.any_param369 transform.yield370 }371}372 373// -----374 375// expected-note @below {{got non-DLTI-queryable attribute upon looking up keys ["CPU"]}}376module attributes { test.dlti = #dlti.dl_spec<"CPU" = 42 : i32> } {377 // expected-error @below {{target op of failed DLTI query}}378 func.func private @f()379}380 381module attributes {transform.with_named_sequence} {382 transform.named_sequence @__transform_main(%arg: !transform.any_op) {383 %func = transform.structured.match ops{["func.func"]} in %arg : (!transform.any_op) -> !transform.any_op384 // expected-error @below {{'transform.dlti.query' op failed to apply}}385 %param = transform.dlti.query ["CPU","test.id"] at %func : (!transform.any_op) -> !transform.any_param386 transform.yield387 }388}389 390// -----391 392// expected-note @below {{got non-DLTI-queryable attribute upon looking up keys [i32]}}393module attributes { test.dlti = #dlti.dl_spec<i32 = 32 : i32> } {394 // expected-error @below {{target op of failed DLTI query}}395 func.func private @f()396}397 398module attributes {transform.with_named_sequence} {399 transform.named_sequence @__transform_main(%arg: !transform.any_op) {400 %func = transform.structured.match ops{["func.func"]} in %arg : (!transform.any_op) -> !transform.any_op401 // expected-error @below {{'transform.dlti.query' op failed to apply}}402 %param = transform.dlti.query [i32,"width_in_bits"] at %func : (!transform.any_op) -> !transform.any_param403 transform.yield404 }405}406 407// -----408 409module {410 // expected-error @below {{target op of failed DLTI query}}411 // expected-note @below {{no DLTI-queryable attrs on target op or any of its ancestors}}412 func.func private @f()413}414 415module attributes {transform.with_named_sequence} {416 transform.named_sequence @__transform_main(%arg: !transform.any_op) {417 %func = transform.structured.match ops{["func.func"]} in %arg : (!transform.any_op) -> !transform.any_op418 // expected-error @below {{'transform.dlti.query' op failed to apply}}419 %param = transform.dlti.query ["CPU","test.id"] at %func : (!transform.any_op) -> !transform.any_param420 transform.yield421 }422}423 424// -----425 426// expected-note @below {{key i64 has no DLTI-mapping per attr: #dlti.map<i32 = 32 : i64>}}427module attributes { test.dlti = #dlti.map<"width_in_bits" = #dlti.map<i32 = 32>>} {428 // expected-error @below {{target op of failed DLTI query}}429 func.func private @f()430}431 432module attributes {transform.with_named_sequence} {433 transform.named_sequence @__transform_main(%arg: !transform.any_op) {434 %func = transform.structured.match ops{["func.func"]} in %arg : (!transform.any_op) -> !transform.any_op435 // expected-error @below {{'transform.dlti.query' op failed to apply}}436 %param = transform.dlti.query ["width_in_bits",i64] at %func : (!transform.any_op) -> !transform.any_param437 transform.yield438 }439}440 441// -----442 443module attributes { test.dlti = #dlti.dl_spec<"test.id" = 42 : i32>} {444 func.func private @f()445}446 447module attributes {transform.with_named_sequence} {448 transform.named_sequence @__transform_main(%arg: !transform.any_op) {449 %funcs = transform.structured.match ops{["func.func"]} in %arg : (!transform.any_op) -> !transform.any_op450 // expected-error @below {{'transform.dlti.query' keys of wrong type: only StringAttr and TypeAttr are allowed}}451 %param = transform.dlti.query [1] at %funcs : (!transform.any_op) -> !transform.param<i64>452 transform.yield453 }454}455 456// -----457 458module attributes { test.dlti = #dlti.map<#dlti.dl_entry<"test.id", 42 : i32>>} {459 // expected-error @below {{target op of failed DLTI query}}460 // expected-note @below {{no keys provided to attempt query with}}461 func.func private @f()462}463 464module attributes {transform.with_named_sequence} {465 transform.named_sequence @__transform_main(%arg: !transform.any_op) {466 %func = transform.structured.match ops{["func.func"]} in %arg : (!transform.any_op) -> !transform.any_op467 // expected-error @below {{'transform.dlti.query' op failed to apply}}468 %param = transform.dlti.query [] at %func : (!transform.any_op) -> !transform.any_param469 transform.yield470 }471}472 473// -----474 475module attributes { test.dlti = #dlti.dl_spec<#dlti.dl_entry<"test.id", 42 : i32>>} {476 func.func private @f()477}478 479module attributes {transform.with_named_sequence} {480 transform.named_sequence @__transform_main(%arg: !transform.any_op) {481 %funcs = transform.structured.match ops{["func.func"]} in %arg : (!transform.any_op) -> !transform.any_op482 // expected-error @below {{expected the type of the parameter attribute ('i32') to match the parameter type ('i64')}}483 %param = transform.dlti.query ["test.id"] at %funcs : (!transform.any_op) -> !transform.param<i64>484 transform.yield485 }486}