Skip to content
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

[NFC] Document intrinsic lowering #2543

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

LU-JOHN
Copy link
Contributor

@LU-JOHN LU-JOHN commented Apr 25, 2024

Document how llvm intrinsics are lowered by SPIRV-LLVM-Translator.

Signed-off-by: Lu, John <john.lu@intel.com>
Copy link
Contributor

@MrSidims MrSidims left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this! I'll post extra comments later. There are 2 cases missing:

  1. Just mapping on a SPIR-V instruction from either core spec or extension. Q: do we want to mention this case?
  2. Some emulation done straight in SPIR-V writer, so not intermediate transformation is being done.

General Q: do we want to unify approaches? All of them have pros and cons, for example if we need to do some types adjustments, it's either to do it just during SPIR-V generation as we create module from scratch, on LLVM IR level replacing types is much harder. Also while inserting definitions of intrinsic function overloads is also possible, do we really want to do it in every case as we would need to insert every possible type combination?

Another Q: do we want (and if yes or no - mention it in the document) emulate some intrinsic that are being mapped on OpenCL lib calls or extension instruction in case, if lets say we know, that target device supports only native builtins or doesn't support a particular extension?

@asudarsa
Copy link
Contributor

Thanks so much for adding this @LU-JOHN
High level comment - I think you should add this under the 'docs' directory.

I will add my feedback in a bit.

Thanks

BB);
}

When these ExtInst are reverse translated they are converted to calls:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please document what happens when reverse translation is called with --spirv-target-env=SPV-IR i.e the user requests SPIR-V friendly IR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a little documentation, but this is just duplicating text from the --help option. I do not understand enough to explain why --spirv-target-env=SPV-IR should be used. Perhaps someone else can re-write this seciton.

@@ -0,0 +1,132 @@
The SPIRV-LLVM-Translator will "lower" some LLVM intrinsic calls to another function or implementation
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to document what logic/criteria is used to select between these three options?

Thanks

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added documentation to explain the pros/cons of each approach. The approaches are ordered from best to worst in my opinion.

Signed-off-by: Lu, John <john.lu@intel.com>
Signed-off-by: Lu, John <john.lu@intel.com>
Signed-off-by: Lu, John <john.lu@intel.com>
Signed-off-by: Lu, John <john.lu@intel.com>
@LU-JOHN
Copy link
Contributor Author

LU-JOHN commented May 6, 2024

Thanks for working on this! I'll post extra comments later. There are 2 cases missing:

  1. Just mapping on a SPIR-V instruction from either core spec or extension. Q: do we want to mention this case?
  2. Some emulation done straight in SPIR-V writer, so not intermediate transformation is being done.

General Q: do we want to unify approaches? All of them have pros and cons, for example if we need to do some types adjustments, it's either to do it just during SPIR-V generation as we create module from scratch, on LLVM IR level replacing types is much harder. Also while inserting definitions of intrinsic function overloads is also possible, do we really want to do it in every case as we would need to insert every possible type combination?

Another Q: do we want (and if yes or no - mention it in the document) emulate some intrinsic that are being mapped on OpenCL lib calls or extension instruction in case, if lets say we know, that target device supports only native builtins or doesn't support a particular extension?

Thanks for working on this! I'll post extra comments later. There are 2 cases missing:

  1. Just mapping on a SPIR-V instruction from either core spec or extension. Q: do we want to mention this case?
  2. Some emulation done straight in SPIR-V writer, so not intermediate transformation is being done.

General Q: do we want to unify approaches? All of them have pros and cons, for example if we need to do some types adjustments, it's either to do it just during SPIR-V generation as we create module from scratch, on LLVM IR level replacing types is much harder. Also while inserting definitions of intrinsic function overloads is also possible, do we really want to do it in every case as we would need to insert every possible type combination?

Another Q: do we want (and if yes or no - mention it in the document) emulate some intrinsic that are being mapped on OpenCL lib calls or extension instruction in case, if lets say we know, that target device supports only native builtins or doesn't support a particular extension?

  1. I've documented lowering with an instruction in an extension.
  2. Emulation done in SPIRVWriter.cpp.

I think we do want to simplify the lowering process, but that is a bigger discussion than what this document addresses. I'm only trying to give an overview of what is currently done.

@LU-JOHN
Copy link
Contributor Author

LU-JOHN commented May 6, 2024

Thanks so much for adding this @LU-JOHN High level comment - I think you should add this under the 'docs' directory.

I will add my feedback in a bit.

Thanks

Moved to docs directory.

@LU-JOHN LU-JOHN requested review from MrSidims and asudarsa May 6, 2024 23:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants