This is an archive of the discontinued LLVM Phabricator instance.

Adds CastSliceOp to the vector ops dialect.
AbandonedPublic

Authored by andydavis1 on Jan 17 2020, 9:10 AM.

Details

Summary

The cast_slices vector operation type casts slices from a 'source' vector to
slices of a 'result' vector, where there is a one-to-one mapping between source
vector and result vector slices (specified by the 'source_sizes' and 'result_sizes' arguments).

Diff Detail

Event Timeline

andydavis1 created this revision.Jan 17 2020, 9:10 AM
Herald added a project: Restricted Project. · View Herald Transcript
aartbik requested changes to this revision.Jan 17 2020, 9:18 AM
aartbik added inline comments.
mlir/include/mlir/Dialect/VectorOps/VectorOps.td
951

I would like to see a bit more documentation of this operation in terms of ranks and sizes of the arrays, like we do for the other sliced operations (so, like "n-D" with restrictions on n array sizes for the input arguments and output).

This revision now requires changes to proceed.Jan 17 2020, 9:18 AM

Please fix the description, BEGIN_PUBLIC/END_PUBLIC don't make sense. The summary should also have a [mlir] tag.

rriddle added inline comments.Jan 17 2020, 9:30 AM
mlir/lib/Dialect/VectorOps/VectorOps.cpp
1651

Cache the end iterator here and above.

mlir/test/Dialect/VectorOps/ops.mlir
248

Seems to be missing a newline here?

Unit tests: pass. 61909 tests passed, 0 failed and 782 were skipped.

clang-tidy: unknown.

clang-format: fail. Please format your changes with clang-format by running git-clang-format HEAD^ or applying this patch.

Build artifacts: diff.json, clang-format.patch, CMakeCache.txt, console-log.txt, test-results.xml

andydavis1 marked 2 inline comments as done.

Addressing comments.

addressing comments

Unit tests: pass. 61909 tests passed, 0 failed and 782 were skipped.

clang-tidy: unknown.

clang-format: pass.

Build artifacts: diff.json, clang-format.patch, CMakeCache.txt, console-log.txt, test-results.xml

mehdi_amini retitled this revision from BEGIN_PUBLIC Adds CastSliceOp to the vector ops dialect. to Adds CastSliceOp to the vector ops dialect..Jan 17 2020, 10:12 PM
mehdi_amini edited the summary of this revision. (Show Details)
nicolasvasilache requested changes to this revision.Jan 20 2020, 7:34 PM
nicolasvasilache added inline comments.
mlir/include/mlir/Dialect/VectorOps/VectorOps.td
964

I find the semantics harder to grasp than it could, I think.
I think the issue is that the usage you have for "cast_slices" leaks into the semantics of the op and I don't think it is warranted.

%1 = vector.cast_slices %0, [1, 1, 3, 12], [3, 12]
      : vector<4x1x3x12xf32> to vector<12x12xf32>

I can think of different ways of specifying this that I would find more natural but first I'd like to understand why you need these attributes in this form and where ambiguity appears that makes it impossible to derive them automatically.

In particular I view this as conflating 2 unrelated things: (1) a reshape that does not move and (2) a multiplicity.
See how (1) is represented in linalg.reshape with affine maps.

It would be great if we could uniformize things (if is makes sense).
Note that this may be an indication that you need 2 ops to express what you want.

Marking as "request changes" until the discussion is resolved.

This revision now requires changes to proceed.Jan 20 2020, 7:34 PM
andydavis1 marked an inline comment as done.Jan 21 2020, 7:10 AM
andydavis1 added inline comments.
mlir/include/mlir/Dialect/VectorOps/VectorOps.td
964

This operation specifies a cast from one vector type to another. I intentionally did not use affine maps (or even the less expressive permutation of dimensions to reshape), so that this operation was even more restricted to its purpose. Its purpose is express a trivial cast between slices of the source/result vectors. Because these aggegate vectors will eventually need to be decomposed to hardware vectors, whats important is that the slices of these vectors have trivial casts that can be canonicalized away.

As an analogy. Think of a reshape operation which starts with the linear address, and de-linearizes this into the source (resp result) vector shape, by using the source (resp result) strides. Instead of source/result permutation of dims, the cast_slices operation specifies the source/result decomposition of slices and further restricts the operation in the following simple ways:

  1. source/result must generate the same number slices so there is a 1-to-1 relationship between a source slice and its associated result slice.
  2. each source/result slice pair must be trivial castable to each other
andydavis1 requested review of this revision.Jan 21 2020, 7:12 AM
andydavis1 abandoned this revision.Jan 22 2020, 1:03 PM

We sync'ed offline and the intuition is that there is a more idiomatic way involving just a "natural" vector.cast that works on both vector and tuple<vector<>,...>