-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[mlir][EmitC]Add a Reflection Map to a Class #150572
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
Shouldn't it be "char* getBufferForName" ? (it returns a string) |
|
The map should be declared as a member of the class. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| This would require that the class has fields with attributes and a function named `execute`. | |
| This requires that the class has fields with attributes and a function named `execute`. |
Why is execute a requirement?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I insert the new function before the execute function.
Ideally, we could have some other insertion point but execute func made the most sense since it is always added when we wrap-emitc-func-in-class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this code is repeated, I'd suggest making it a helper function or a lambda. Then the code here can be
if(!hasMap)
addHeader(kMapLibraryHeader);
if(!hasString)
addHeader(kMapLibraryHeader);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| bool hasMap = false; | |
| bool hasString = false; | |
| bool hasMapHdr = false; | |
| bool hasStringHdr = false; |
nit: hasString is pretty common name that usually isn't about the header. Lets just make it completely unambiguous.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you're going to early exit, you might as well put it in the loop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this be a cast<>? If you know it will be of this type (e.g. can't fail) then cast<> is appropriate. Otherwise, I think you still need to check dyn_cast<> for success.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ack, thanks for the pointer!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| std::string indexPath = stringAttr.getValue().str(); | |
| fieldNames.emplace_back(indexPath, fieldOp.getName().str()); | |
| fieldNames.emplace_back(tringAttr.getValue().str(), fieldOp.getName().str()); |
You can avoid a copy here, otherwise you can probably use std::move() to similar effect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of nesting so deeply w/ dyn_cast<>, can you just early exit if the cast fails?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd recommend doing this w/ a string_stream. You can avoid a lot of copies and you can use things like formatv() to make the code easier to read.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For blocks like this, where you're basically spelling out the C++ code, you may want to write that down in a comment, so its easy to see what operations you're doing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we now simply return the full map, I have reduced the amount of c++ code I'm spelling out.
I appreciate the pointer!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the \22 be in the output? I'd expect maybe \", but IDK if that's going to work correctly. It desn't seem right to me at least...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is some weird parsing going on.
I chose to not take it too seriously since it didn't change the output when it came to cpp.
f4512f1 to
94b0c34
Compare
We could:
|
Let's do 1. 2 would mean re-creating the map at every call to that function, which would need to be renamed to indicate that ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we stop in the error case? I'd assume you'd want to return an error code here, instead of continuing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think this would be more readable as a formatv(). IMO, structures like this are harder to read when constructed via stream (e.g. its easier to misread them or miss a detail). WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LLVM style is to omit braces for single statement bodies. I'm not sure if MLIR deviates (I'm fine either way), but we should be consistent, and you have a different convention a few lines above.
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
This reverts commit f2dee0d99bc1fb258b6cef57dc150cb637cc4ab3.
|
[Apologies if I missed some earlier community discussion on this] |
Thanks @aniragil! While there has been some discussion dating back to 2023 on what MLGO would need and resulting in the efforts by @simon-camp to add an upstream supported lowering to EmitC (PR #11754), it isn't clear to me what else is needed. Therefore, I would appreciate to discuss this based on an RFC as suggested by @aniragil. |
The RFC in question is this one. The MLGO usecase was used as one of the motivations, especially since MLGO is in-tree. The additional requirements (for MLGO) were listed high-level, this patch here is for the "ability to bind by name" part. Perhaps we should make that relation to the RFC more clear in this patch description? |
That RFC was specifically about upstreaming the TOSA to EmitC conversions and the reference implementation, both implemented in https://github.com/iml130/mlir-emitc/. It is correct that MLGO use-case was highlighted as a motivation but the specific RFC never got a lot of attraction and was never accepted. I think what Gil is asking for is a separate, more detailed RFC with regards to what is needed and what operations or conversions need to be implemented. It can of course refer to the linked thread and re-use arguments. |
Right, and IIRC there was no explicit RFC signoff process at the time anyway; on that - asking to learn (and make sure we follow the right steps) - is there an explicit signoff now in MLIR, or, like in LLVM, that's ony an escalation when there's disagreements?
We should have one up today. I am concerned with timing here, though, and would love it if we could find a way to make progress in the meantime. I'm assuming there's no objection to other work continuing, like lowering opcodes (that's quite generic), while folks look at the pieces that are more MLGO-specific and covered by the RFC, correct? |
|
As this pass is very use case specific, it could also be moved to the MLGO side of the repo together with a custom opt tool to run it. |
Here is an RFC. |
One way to try and speed things up is to request more EmitC folks in the community for review in addition to @marbre and myself, e.g. @simon-camp, @mgehre-amd, @jacquesguan.
It's eventually up to the reviewers, so best to upload and have concrete discussions per case. For instance, malloc and memcpy were such generic contributions. |
This adds a pass that adds a
getBufferForNamefunction to EmitC classes that enables runtime lookup of field buffers by their string names.This allows us to get the cpp emission: