This is an archive of the discontinued LLVM Phabricator instance.

[mlir][Linalg] Add tensor support to Linalg EDSC Builders
ClosedPublic

Authored by nicolasvasilache on Jan 16 2020, 12:26 PM.

Details

Summary

This diff extends the Linalg EDSC builders so we can easily create mixed
tensor/buffer linalg.generic ops. This is expected to be useful for
HLO -> Linalg lowering.

The StructuredIndexed struct is made to derive from ValueHandle and can
now capture a type + indexing expressions. This is used to represent return
tensors.

Pointwise unary and binary builders are extended to allow both output buffers
and return tensors. This has implications on the number of region arguments.

Diff Detail

Event Timeline

Unit tests: pass. 61930 tests passed, 0 failed and 783 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

Unit tests: pass. 61930 tests passed, 0 failed and 783 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

hanchung added inline comments.Jan 16 2020, 7:41 PM
mlir/include/mlir/Dialect/Linalg/EDSC/Builders.h
363

s/depth_multiplier/depthMultiplier

Same to others below.

mlir/lib/Dialect/Linalg/EDSC/Builders.cpp
51

Please fix it.

82

Please fix it

134–137

Do we also check if all types in resultTensorTypes are RankedTensorType?

144

Do we need to update maxPos with resultTensorTypes?

229

If this is a unary operation, why do we pass two input to the function?
I was expecting something like makeGenericLinalgOp(iterTypes, {I}, {}, resultTensorTypes, fun);
In addition, is there a test for this path?

mlir/test/EDSC/builder-api-test.cpp
910

Remove one "/" in the beginning?

959

nit: add comment for function argument, /*resultTensorTypes=*/{}

I'm not sure I understand what happens to the Op operands that are supposed to be tensors in individual linalg_ constructors. The comment says outputs should not contain tensors, but in individual constructors there's no generic outputs, and some StructuredIndexed *must* be passed in.

Nit: typo in the commit description "identity identity"

mlir/include/mlir/Dialect/Linalg/EDSC/Builders.h
186

There are no arguments called inputs and outputs here and below. I can suggest the formulation "StructuredIndexed for inputs may wrap a buffer or a tensor, those for outputs may wrap only buffers". Same below.

I'd drop the "TODO", it's the same as above.

195–197

It's not clear what happens to O, which I presume is the output, if you want tensor outputs.

mlir/lib/Dialect/Linalg/EDSC/Builders.cpp
235

Let's clean this semicolon :)

292

Please add a string with description to the assert

293

You can do something like

ArrayRef<StructuredIndexed> all(allIndexed)
bool isResultBuffer = C.getType().isa<MemRefType>();
auto inputs = all.drop_back(isResultBuffer);
auto outputs = all.take_back(isResultBuffer)

or even

ArrayRef<StructuredIndexed> all({A({m, k}), B({k, n}), C({m, n})});
340

Same as above

nicolasvasilache edited the summary of this revision. (Show Details)Jan 21 2020, 9:38 AM
nicolasvasilache marked 2 inline comments as done.
nicolasvasilache edited the summary of this revision. (Show Details)

Refocus on extending EDSC to tensors for pointwise ops.

nicolasvasilache marked an inline comment as done.Jan 21 2020, 9:45 AM

Thanks for your comments, I was a bit too ambitious with the generalization and missed some things.
I refocused on extending StructuredIndexed and limit this first diff to pointwise ops only.

Unit tests: pass. 62017 tests passed, 0 failed and 783 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

nicolasvasilache marked 21 inline comments as done.Jan 21 2020, 9:54 AM
nicolasvasilache added inline comments.
mlir/include/mlir/Dialect/Linalg/EDSC/Builders.h
186

Done by virtue of refocusing the diff.

195–197

Done by virtue of refocusing the diff.

mlir/lib/Dialect/Linalg/EDSC/Builders.cpp
134–137

That is done by the verifier of linalg.generic.

144

Good point, I refocused the diff though so I don't need it anymore.

229

There was not and this was a mistake.
Now there is, thanks for surfacing!

292

obsolete, I'll revisit in a later diff, thanks!

293

obsolete, I'll revisit in a later diff, thanks!

340

obsolete, I'll revisit in a later diff, thanks!

mlir/test/EDSC/builder-api-test.cpp
910

obsolete, I'll revisit in a later diff, thanks!

959

obsolete, I'll revisit in a later diff, thanks!

nicolasvasilache marked 11 inline comments as done.Jan 21 2020, 9:54 AM

Unit tests: pass. 61930 tests passed, 0 failed and 783 were skipped.

clang-tidy: unknown.

clang-format: pass.

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

This revision is now accepted and ready to land.Jan 21 2020, 11:05 AM
This revision was automatically updated to reflect the committed changes.

This was reverted due to an improper update.
See https://reviews.llvm.org/D73149 for the proper version.