This is an archive of the discontinued LLVM Phabricator instance.

[MLIR][python bindings] Add support for DenseElementsAttr of IndexType
ClosedPublic

Authored by makslevental on May 2 2023, 1:52 PM.

Diff Detail

Event Timeline

makslevental created this revision.May 2 2023, 1:52 PM
Herald added a project: Restricted Project. · View Herald Transcript
makslevental published this revision for review.May 2 2023, 2:44 PM
rkayaith added inline comments.
mlir/lib/Bindings/Python/IRAttributes.cpp
714
makslevental added inline comments.May 2 2023, 3:54 PM
mlir/lib/Bindings/Python/IRAttributes.cpp
714

I guess this is really what you're pointing at? https://github.com/llvm/llvm-project/blob/a4bdb27538c3bc5b757976e47d663e63880451e3/mlir/include/mlir/IR/BuiltinTypes.td#L307

static constexpr unsigned kInternalStorageBitWidth = 64;

Seems like that one should be kInternalStorageBitWidth = sizeof(uintptr_t) too? But maybe I'm missing something.

makslevental added inline comments.May 2 2023, 4:00 PM
mlir/lib/Bindings/Python/IRAttributes.cpp
714

You can't edit inline comments? Weird...

Anyway I was going to edit/add that this is all about host arch rather than target so maybe being mindful of sizeof(uintptr_t) > 64 is moot (are there 128bit architectures on the horizon?).

rkayaith added inline comments.May 2 2023, 4:10 PM
mlir/lib/Bindings/Python/IRAttributes.cpp
714

this is all about host arch rather than target so maybe being mindful of sizeof(uintptr_t) > 64 is moot (are there 128bit architectures on the horizon?).

yea that'd be my guess as well. but also.. CHERI kind of :)

use uint64_t instead of uintptr_t

since dense<-1> : tensor<index> is allowed, use int64_t

makslevental marked 2 inline comments as done.May 3 2023, 10:34 AM

remove accidentally included cstdint

update python test

rkayaith accepted this revision.May 3 2023, 11:10 AM
rkayaith added inline comments.
mlir/lib/Bindings/Python/IRAttributes.cpp
714

A static_assert that IndexType::kInternalStorageBitWidth == 64 would be nice to explain where int64_t comes from

mlir/test/python/ir/array_attributes.py
374

np.int64 seems like the right type here (though I'm not actually sure what happens when the wrong type gets passed in, maybe it works somehow)

379

I know the other tests here don't, but you could avoid the escaping by using CHECK{LITERAL}: https://llvm.org/docs/CommandGuide/FileCheck.html#directive-modifiers

This revision is now accepted and ready to land.May 3 2023, 11:10 AM

add comment and using np.int64 on input array

makslevental marked an inline comment as done.May 3 2023, 2:47 PM
makslevental added inline comments.
mlir/lib/Bindings/Python/IRAttributes.cpp
714

Can't do that without adding something like mlirIndexTypeGetStorageWidth to C API; comment will have to do.

mlir/test/python/ir/array_attributes.py
379

Leaving as is for this test but definitely will use in the future.

makslevental marked an inline comment as done.May 3 2023, 2:47 PM