iree: Failed to legalize operation 'stream.cmd.dispatch'

For IR provided here

with

iree-compile uncased_transpose_repro.mlir --iree-hal-target-backends="rocm" --iree-rocm-target-chip=gfx942 -o dump.vmfb

OR

iree-compile uncased_transpose_repro.mlir --iree-hal-target-backends=llvm-cpu -o dump.vmfb

We get the following error

uncased_transpose_repro.mlir:92:11: error: failed to legalize operation 'stream.cmd.dispatch' that was explicitly marked illegal
    %88 = torch.operator "onnx.Transpose"(%87) {torch.onnx.perm = [0 : si64, 2 : si64, 1 : si64, 3 : si64]} : (!torch.vtensor<[?,?,?,?],f32>) -> !torch.vtensor<[?,?,?,?],f32> 
          ^
cased_MM.mlir:92:11: note: see current operation: "stream.cmd.dispatch"(%17, %18, %5, %6, %106, %108, %78, %80, %82, %84, <<UNKNOWN SSA VALUE>>, <<UNKNOWN SSA VALUE>>, %66, %42, %7, %7, %66, %42) <{entry_points = [@torch_jit$async_dispatch_10::@embedded_elf_x86_64::@torch_jit$async_dispatch_10_transpose_Dx12xDx64_f32], operandSegmentSizes = array<i32: 4, 6, 2, 2, 2, 2>, resource_accesses = [1 : i32, 2 : i32]}> : (index, index, index, index, i32, i32, i32, i32, i32, i32, !stream.resource<transient>, !stream.resource<external>, index, index, index, index, index, index) -> ()

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 20 (18 by maintainers)

Commits related to this issue

Most upvoted comments

That’s good. I’m getting the new error for rocm mentioned in the above link.

For llvm-cpu, I am still getting the cmd.stream.dispatch error for all four test cases besides the transpose one, so I’d like to keep this issue open for CPU.

@zjgarvey with the recent gist https://gist.github.com/zjgarvey/1bf521f50d3928596c2198bf734eb973 is the failure

 iree/compiler/src/iree/compiler/Dialect/VM/Target/Bytecode/ArchiveWriter.cpp:390: std::optional<ZIPFileRef> mlir::iree_compiler::IREE::VM::appendZIPFileToStream(std::string, uint64_t, uint64_t, std::function<LogicalResult (llvm::raw_ostream &)>, llvm::raw_ostream &): Assertion `fileRef.totalLength == fileLength && "declared length mismatch"' failed.

As mentioned in a previous issue that is to do with the wrong way of elliding variables in the repros?

That might be tricky becuase tensors in the inner computation are also getting converted e.g

  %18 = flow.dispatch.region -> (tensor<?x768xf32>{%16}) {
    %38 = affine.apply affine_map<()[s0, s1] -> (s0 * s1)>()[%0, %1]
    %39 = tensor.empty(%38) : tensor<?x768xf32>
    %40 = linalg.generic {indexing_maps = [affine_map<(d0, d1) -> (d0)>, affine_map<(d0, d1) -> (d0, d1)>], iterator_types = ["parallel", "parallel"]} ins(%collapsed : tensor<?xi64>) outs(%39 : tensor<?x768xf32>) {
    ^bb0(%in: i64, %out: f32):
      %41 = arith.index_cast %in : i64 to index
      %42 = linalg.index 1 : index
      %extracted = tensor.extract %cst_3[%41, %42] : tensor<30522x768xf32>
      linalg.yield %extracted : f32
    } -> tensor<?x768xf32>
    flow.return %40 : tensor<?x768xf32>
  }

becomes

  %18 = flow.dispatch.region -> (tensor<?x768xf32>{%17}) {
  %41 = affine.apply affine_map<()[s0, s1] -> (s0 * s1)>()[%0, %1]
  %42 = tensor.empty(%41) : tensor<?x768xf32>
  %43 = linalg.generic {indexing_maps = [affine_map<(d0, d1) -> (d0)>, affine_map<(d0, d1) -> (d0, d1)>], iterator_types = ["parallel", "parallel"]} ins(%16 : tensor<?xi64>) outs(%42 : tensor<?x768xf32>) {
  ^bb0(%in: i64, %out: f32):
    %44 = arith.index_cast %in : i64 to index
    %45 = linalg.index 1 : index
    %46 = flow.tensor.load %cst_3[%44, %45] : tensor<30522x768xf32>
    linalg.yield %46 : f32
  } -> tensor<?x768xf32>
  flow.return %43 : tensor<?x768xf32>
}

Edit: I see that the guard that should prevent this from happening just needs updating, I can do that.