This is an archive of the discontinued LLVM Phabricator instance.

[MLIR:Python] Make DenseElementsAttr.get() only request a buffer format if no explicit type was provided.
ClosedPublic

Authored by phawkins on Jul 13 2023, 8:30 AM.

Details

Summary

Not every NumPy type (e.g., the ml_dtypes.bfloat16 NumPy extension type) has a type in the Python buffer protocol, so exporting such a buffer with PyBUF_FORMAT may fail.

However, we don't care about the self-reported type of a buffer if the user provides an explicit type. In the case that an explicit type is provided, don't request the format from the buffer protocol, which allows arrays whose element types are unknown to the buffer protocol to be passed.

Diff Detail

Event Timeline

phawkins created this revision.Jul 13 2023, 8:30 AM
Herald added a project: Restricted Project. · View Herald Transcript
phawkins requested review of this revision.Jul 13 2023, 8:30 AM
ftynse accepted this revision.Jul 13 2023, 10:50 AM
This revision is now accepted and ready to land.Jul 13 2023, 10:50 AM
jpienaar accepted this revision.Jul 13 2023, 10:57 AM

Thanks!

Hold off merging for a minute.

mlir/lib/Bindings/Python/IRAttributes.cpp
701–703

Hold off a second before merging, I realized there's a bug here.

phawkins updated this revision to Diff 540146.Jul 13 2023, 11:55 AM

Fixed bug where we didn't correctly error on all failing cases.

This should be ready to merge now, I think.