This is an archive of the discontinued LLVM Phabricator instance.

[mlir] Add MemRefTypeBuilder and refactor some MemRefType::get().
ClosedPublic

Authored by timshen on Jan 23 2020, 2:19 PM.

Details

Summary

The refactored MemRefType::get() calls all intend to clone from another
memref type, with some modifications. In fact, some calls dropped memory space
during the cloning. Migrate them to the cloning API so that nothing gets
dropped if they are not explicitly listed.

It's close to NFC but not quite, as it helps with propagating memory spaces in
some places.

Diff Detail

Event Timeline

timshen created this revision.Jan 23 2020, 2:19 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 23 2020, 2:19 PM

I personally love the API with chainable calls but we should really get @rriddle 's buyin on this.
I would change the return by reference to just return a new type by value: Types (and recently Values) are small value-type wrappers around a pointer, we should use value semantics everywhere.
Also, if @rriddle agrees to go this way, can we hide MemRef::get and friends from the public API and advertise this as the way to go?

timshen added a comment.EditedJan 23 2020, 2:42 PM

I personally love the API with chainable calls but we should really get @rriddle 's buyin on this.

FWIW I'm open to any API designs that allow implicit propagation of fields like memory space (and alignment in my next patches).

I would change the return by reference to just return a new type by value: Types (and recently Values) are small value-type wrappers around a pointer, we should use value semantics everywhere.

Which function specifically were you talking about?

Also, if @rriddle agrees to go this way, can we hide MemRef::get and friends from the public API and advertise this as the way to go?

My understanding is that ::get and ::getChecked is somewhat generic w.r.t. the contrats with TypeBase, and they might be hard to get off from.

I also won't advertise too much for the MemRefTypeBuilder style API, in my personal preference of designated initializer style "named parameters":

class MemRefType {
  struct BuildOptions {
    ArrayRef<AffineMap> affineMaps;
    unsigned memorySpace;
  };
  static MemRefType::get(ArrayRef<int64_t> shape, Type elementType, BuildOptions);
};

MemRefType::get(shape, elementType, { .memorySpace = 3 });

But we will have to wait for MSVC 2019.

Unit tests: fail. 62143 tests passed, 8 failed and 811 were skipped.

failed: MLIR.Transforms/memref-normalize.mlir
failed: libc++.std/language_support/cmp/cmp_partialord/partialord.pass.cpp
failed: libc++.std/language_support/cmp/cmp_strongeq/cmp.strongeq.pass.cpp
failed: libc++.std/language_support/cmp/cmp_strongord/strongord.pass.cpp
failed: libc++.std/language_support/cmp/cmp_weakeq/cmp.weakeq.pass.cpp
failed: libc++.std/language_support/cmp/cmp_weakord/weakord.pass.cpp
failed: libc++.std/thread/thread_mutex/thread_mutex_requirements/thread_sharedtimedmutex_requirements/thread_sharedtimedmutex_class/try_lock.pass.cpp
failed: libc++.std/thread/thread_mutex/thread_mutex_requirements/thread_timedmutex_requirements/thread_timedmutex_class/try_lock_for.pass.cpp

clang-tidy: pass.

clang-format: pass.

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

Pre-merge checks is in beta. Report issue. Please join beta or enable it for your project.

ftynse requested changes to this revision.Jan 24 2020, 1:13 AM

Thanks, I like the simplification.

Note there's one broken test (clang ones are irrelevant).

mlir/include/mlir/IR/StandardTypes.h
488

Could you please add documentation to this class? Especially as it captures (through ArrayRef) references to data that must be kept live at least as long as this object.

492

Nit: we tend to put private members after public

mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
618

Drop {} inside setAffineMaps (and also addTypes), ArrayRef<T> is implicitly constructible from T.

619

Suggestion: since you are adding a helper class already, can you integrate makeStidedLinearLayoutMap into it directly as MemRefTypeBuilder::setLinearLayoutMap?

This revision now requires changes to proceed.Jan 24 2020, 1:13 AM
rriddle added inline comments.Jan 26 2020, 2:28 AM
mlir/include/mlir/IR/StandardTypes.h
488

I'm generally a bit apprehensive about these types of builders(as it doesn't really align with the rest of the type infra), but in this case it seems to have some value in the simplification it brings. A few comments:

  • I would prefer to move this class inside of MemRefType and out of the global mlir namespace.

(i.e. MemRefTypeBuilder -> MemRefType::Builder)

  • This is missing quite a bit of documentation.
490

nit: Structure classes with public members first and private last:

public:
...

private:
...

timshen updated this revision to Diff 241008.Jan 28 2020, 2:54 PM

Address comments.

timshen updated this revision to Diff 241009.Jan 28 2020, 2:56 PM

Update comments.

timshen marked 6 inline comments as done.Jan 28 2020, 2:59 PM
timshen added inline comments.
mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
619

This is tricky, because it requires storing an AffineMap in the builder. However, StandarTypes.h doesn't see the full definition of AffineMap.

Unit tests: fail. 62145 tests passed, 6 failed and 811 were skipped.

failed: MLIR.Transforms/memref-normalize.mlir
failed: libc++.std/language_support/cmp/cmp_partialord/partialord.pass.cpp
failed: libc++.std/language_support/cmp/cmp_strongeq/cmp.strongeq.pass.cpp
failed: libc++.std/language_support/cmp/cmp_strongord/strongord.pass.cpp
failed: libc++.std/language_support/cmp/cmp_weakeq/cmp.weakeq.pass.cpp
failed: libc++.std/language_support/cmp/cmp_weakord/weakord.pass.cpp

clang-tidy: pass.

clang-format: pass.

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

Pre-merge checks is in beta. Report issue. Please join beta or enable it for your project.

Unit tests: fail. 62145 tests passed, 6 failed and 811 were skipped.

failed: MLIR.Transforms/memref-normalize.mlir
failed: libc++.std/language_support/cmp/cmp_partialord/partialord.pass.cpp
failed: libc++.std/language_support/cmp/cmp_strongeq/cmp.strongeq.pass.cpp
failed: libc++.std/language_support/cmp/cmp_strongord/strongord.pass.cpp
failed: libc++.std/language_support/cmp/cmp_weakeq/cmp.weakeq.pass.cpp
failed: libc++.std/language_support/cmp/cmp_weakord/weakord.pass.cpp

clang-tidy: pass.

clang-format: pass.

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

Pre-merge checks is in beta. Report issue. Please join beta or enable it for your project.

ftynse accepted this revision.Jan 29 2020, 12:44 AM
ftynse added inline comments.
mlir/include/mlir/IR/StandardTypes.h
393

Nit: use /// for class/function comments

rriddle accepted this revision.Jan 29 2020, 4:53 PM

LGTM after fixing the function/class comments to use ///

This revision is now accepted and ready to land.Jan 29 2020, 4:53 PM
timshen updated this revision to Diff 241585.Jan 30 2020, 2:44 PM

Update comments and fix the memref-normalize failure.

timshen updated this revision to Diff 241592.Jan 30 2020, 2:52 PM

Update one of the callsites to not use auto.

Unit tests: fail. 62353 tests passed, 2 failed and 839 were skipped.

failed: libc++.std/containers/sequences/array/array_creation/to_array.fail.cpp
failed: libc++.std/thread/thread_mutex/thread_mutex_requirements/thread_mutex_requirements_mutex/thread_mutex_class/try_lock.pass.cpp

clang-tidy: pass.

clang-format: pass.

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

Pre-merge checks is in beta. Report issue. Please join beta or enable it for your project.

Unit tests: fail. 62354 tests passed, 1 failed and 839 were skipped.

failed: libc++.std/containers/sequences/array/array_creation/to_array.fail.cpp

clang-tidy: pass.

clang-format: pass.

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

Pre-merge checks is in beta. Report issue. Please join beta or enable it for your project.

This revision was automatically updated to reflect the committed changes.