Skip to content

[spirv] Properly handle subspan offset - #5403

Merged
antiagainst merged 6 commits into
iree-org:mainfrom
antiagainst:subspan-offset
Apr 14, 2021
Merged

antiagainst merged 6 commits into
iree-org:mainfrom
antiagainst:subspan-offset

Conversation

@antiagainst

Copy link
Copy Markdown
Member

This commit implements a pass to flatten n-D MemRef
subspan ops to 1-D MemRef ones and folds the byte
offsets on subspan ops to the consumer load/store
ops, in preparation for lowering to SPIR-V.

Addresses #5372

This commit implements a pass to flatten n-D MemRef
subspan ops to 1-D MemRef ones and folds the byte
offsets on subspan ops to the consumer load/store
ops, in preparation for lowering to SPIR-V.
@antiagainst

Copy link
Copy Markdown
Member Author

@benvanik

Copy link
Copy Markdown
Collaborator

fantastic work lei!

@MaheshRavishankar MaheshRavishankar left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Just a few nits.

memref::LoadOp loadOp, ArrayRef<Value> operands,
ConversionPatternRewriter &rewriter) const override {
typename memref::LoadOp::Adaptor adaptor(operands);
assert(isRankZeroOrOneMemRef(adaptor.memref().getType()));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple of points here.

  1. For zero-D memref it is better to check the rank and return failure.
  2. you could have a memref<?xf32, affine_map<(d0)[s0] -> (d0 + s0)>. It is better to handle these as well. linearizeIndices logic must be able to handle this too.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 1. For 2 shouldn't it already be handled by getStridesAndOffset (with strides = [1], offset = s0)?

@MaheshRavishankar

Copy link
Copy Markdown
Collaborator

FYI @asaadaldien this has the makings of the pass to linearize multi-dimensional memrefs to 1D memrefs like we discussed today.

@hanhanW

hanhanW commented Apr 14, 2021 •

Copy link
Copy Markdown
Contributor

I found that this would break using workgroup memory in Linalg on tensors.

To repro: iree-translate --iree-mlir-to-vm-bytecode-module --iree-hal-target-backends=vulkan-spirv third_party/iree/iree/test/e2e/vulkan_specific/gemm.mlir -iree-spirv-use-workgroup-memory -iree-flow-dispatch-linalg-on-tensors -iree-codegen-spirv-experimental-linalg-on-tensors

This also breaks conv test (using workgroup memory). There are 1D and 3D cases in the file. If you want to test it, you will have to comment those conv_1d and conv_3d. (they will be disabled in #5375 , I probably should make another change to make it easier...)

error log: https://gist.githubusercontent.com/hanhanW/55f17473630c32ac3a6f63c6e765311c/raw/07695b6a188aca70db68e22252a59c360579bf42/log

@antiagainst

Copy link
Copy Markdown
Member Author

I found that this would break using workgroup memory in Linalg on tensors.

8c0afe9 should address this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants