This is an archive of the discontinued LLVM Phabricator instance.

[mlir] Support big endian in DenseElementsAttr
ClosedPublic

Authored by imaihal on Apr 13 2020, 8:08 PM.

Details

Summary

This std::copy_n copies 8 byte data (APInt raw data) by 1 byte from the
beginning of char array. This is no problem in little endian, but the
data is not copied correctly in big endian because the data should be
copied from the end of the char array.

  • Example of 4 byte data (such as float32)

Little endian (First 4 bytes):
Address | 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08
Data | 0xcd 0xcc 0x8c 0x3f 0x00 0x00 0x00 0x00

Big endian (Last 4 bytes):
Address | 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08
Data | 0x00 0x00 0x00 0x00 0x3f 0x8c 0xcc 0xcd

In general, when it copies N(N<8) byte data in big endian, the start
address should be incremented by (8 - N) bytes.
The original code has no problem when it includes 8 byte data(such as
double) even in big endian.

Diff Detail

Event Timeline

imaihal created this revision.Apr 13 2020, 8:08 PM
Herald added a project: Restricted Project. · View Herald Transcript

Thanks for the patch!

mlir/lib/IR/Attributes.cpp
586–587

Can you extract this to a static helper above this function and add comments as to what is going on?

rriddle requested changes to this revision.Apr 14 2020, 10:21 AM
This revision now requires changes to proceed.Apr 14 2020, 10:21 AM
imaihal updated this revision to Diff 258054.Apr 16 2020, 7:49 AM

[mlir] Create a static helper and add comments

imaihal marked 2 inline comments as done.Apr 16 2020, 4:18 PM
imaihal added inline comments.
mlir/lib/IR/Attributes.cpp
586–587

Thanks for the review. I added a static helper and comments. Does this meet your request?

imaihal marked an inline comment as done.Apr 16 2020, 4:19 PM

Is there any way you can add a test for this?

mlir/lib/IR/Attributes.cpp
586–587

Can you add in the reinterpret_cast and the copy_n to the static helper?

ro added a subscriber: ro.Apr 21 2020, 12:58 AM

FWIW, a rebased version of this patch (it needed llvm/Support/Endian.h, among others) fixed the vast majority of mlir failures I'd been
seeing on sparcv9-sun-solaris2.11.

rriddle accepted this revision.Apr 21 2020, 2:07 AM

LGTM after resolving the other comments.

This revision is now accepted and ready to land.Apr 21 2020, 2:07 AM
imaihal updated this revision to Diff 260660.Apr 28 2020, 8:54 AM

[mlir] Added copy_n() in static helper

imaihal marked an inline comment as done.Apr 28 2020, 9:15 AM
In D78076#1993928, @ro wrote:

FWIW, a rebased version of this patch (it needed llvm/Support/Endian.h, among others) fixed the vast majority of mlir failures I'd been
seeing on sparcv9-sun-solaris2.11.

Rebased version solved the failures. Thanks!

Is there any way you can add a test for this?

Many MLIR test such as "mlir/IR/attributes.mlir" fail on big-endian system, but they are fixed by using this patch.
Should I add additional test for this patch?

Is there any way you can add a test for this?

Many MLIR test such as "mlir/IR/attributes.mlir" fail on big-endian system, but they are fixed by using this patch.
Should I add additional test for this patch?

If the tests already fail and get fixed, +1 on just submitting.

rriddle accepted this revision.Apr 28 2020, 10:29 AM

Pre-merge check fails, but I'm not sure why this happens. Could you tell me how to resolve this? (I'm new about Phabricator and archanist. Excuse me if this is basic question)

I see following error in build log.

Getting dependencies of 260660
Base revision is 9b16ece6ca288d976f61bf81c3986ffcaffe0f72
git reset, git cleanup...
Analyzing D78076
Applying diff 260660 for revision D78076...
Traceback (most recent call last):
  File "/mnt/disks/ssd0/agent/workspace/amd64_debian_testing_clang8/llvm-premerge-checks/scripts/phabtalk/apply_patch2.py", line 311, in <module>
    patcher.run()
  File "/mnt/disks/ssd0/agent/workspace/amd64_debian_testing_clang8/llvm-premerge-checks/scripts/phabtalk/apply_patch2.py", line 108, in run
    self._apply_diff(self.diff_id, revision_id)
  File "/mnt/disks/ssd0/agent/workspace/amd64_debian_testing_clang8/llvm-premerge-checks/scripts/phabtalk/apply_patch2.py", line 224, in _apply_diff
    raise Exception('Applying patch failed:\n{}'.format(proc.stdout + proc.stderr))
Exception: Applying patch failed:
error: patch failed: mlir/lib/IR/Attributes.cpp:524
error: mlir/lib/IR/Attributes.cpp: patch does not apply
ro added a comment.Apr 30 2020, 1:14 AM

Pre-merge check fails, but I'm not sure why this happens. Could you tell me how to resolve this? (I'm new about Phabricator and archanist. Excuse me if this is basic question)

I see following error in build log.

[...]

> Exception: Applying patch failed:
> error: patch failed: mlir/lib/IR/Attributes.cpp:524
> error: mlir/lib/IR/Attributes.cpp: patch does not apply

It's exactly as the error says: your patch doesn't apply cleanly to current master. I noticed the problem myself when trying to re-test
the revised version on Solaris/SPARC:

  • For one, the patch is an incremental one on top of your original patch. This won't work: you need to upload a full patch instead.
  • Even so, the original patch doesn't apply any longer, but needs to be rebased.

In short: create a complete patch that applies cleanly to current master and upload that. You should be fine then. At least my Solaris testing
after manually doing the same suggests so.

In D78076#2012022, @ro wrote:

In short: create a complete patch that applies cleanly to current master and upload that. You should be fine then. At least my Solaris testing
after manually doing the same suggests so.

I merged my modification into one commit and rebased it on top of master. Now the tests all passed. Thanks for your help!

@rriddle Is this patch ready for commit? If so, could you help to commit this? I think I don't have write access to the repository.

ro added a comment.May 4 2020, 3:53 AM

This is exactly the version I arrived at myself and tested successfully on sparcv9-sun-solaris2.11. Not only does it fix most mlir failures on
that target, but one in particular that would cause ninja check-all to hang until the test is killed manually.

This revision was automatically updated to reflect the committed changes.