Skip to content

Conversation

@asudarsa
Copy link
Contributor

@asudarsa asudarsa commented Mar 28, 2024

It seems we currently allow OCL to SPIR-V translation only for OpenCL C sources. This PR tries to extend this to OpenCL C++ and C++ for OpenCL sources as well.

Thanks

@asudarsa asudarsa requested review from MrSidims and vmaksimo March 28, 2024 12:23
!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 1, i32 2}
!2 = !{i32 4, i32 100000}
!2 = !{i32 7, i32 100000}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test case was actually derived from SYCL source.

@asudarsa
Copy link
Contributor Author

Test fail is not related and an issue has been opened.

Thanks

@asudarsa asudarsa requested a review from svenvh March 28, 2024 20:57
// This is a pre-processing pass, which transform LLVM IR module to a more
// suitable form for the SPIR-V translation: it is specifically designed to
// handle OpenCL C built-in functions and shouldn't be launched for other
// handle OpenCL C/CPP built-in functions and shouldn't be launched for other
Copy link
Contributor

Choose a reason for hiding this comment

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

Out of curiosity, what is the reason for only running this transform for these types of sources?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These are the only OpenCL related sources and this particular module deals with OpenCL sources.

@@ -0,0 +1,24 @@
; RUN: llvm-as %s -o %t.bc
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider adding a comment describing purpose of this test. I think that looking at the filename or file history is not as clear or convenient.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Thanks

// source languages
if (std::get<0>(Src) != spv::SourceLanguageOpenCL_C)
if (std::get<0>(Src) != spv::SourceLanguageOpenCL_C &&
std::get<0>(Src) != spv::SourceLanguageOpenCL_CPP)
Copy link
Contributor

Choose a reason for hiding this comment

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

There is also a SourceLanguageCPP_for_OpenCL. Should this be allowed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. Good catch. Thanks. Added.

Signed-off-by: Sudarsanam, Arvind <[email protected]>
Signed-off-by: Sudarsanam, Arvind <[email protected]>
Copy link
Contributor

@LU-JOHN LU-JOHN left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@svenvh svenvh 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!

// handle OpenCL C built-in functions and shouldn't be launched for other
// source languages
if (std::get<0>(Src) != spv::SourceLanguageOpenCL_C)
// handle OpenCL C/CPP and CPP for OpenCL modules and shouldn't be launched
Copy link
Member

Choose a reason for hiding this comment

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

In comments we can refer to the official language names:

Suggested change
// handle OpenCL C/CPP and CPP for OpenCL modules and shouldn't be launched
// handle OpenCL C/C++ and C++ for OpenCL modules and shouldn't be launched

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in commit
Thanks

if (std::get<0>(Src) != spv::SourceLanguageOpenCL_C)
// This is a pre-processing pass, which transform LLVM IR module to a more
// suitable form for the SPIR-V translation: it is specifically designed to
// handle OpenCL C/CPP and CPP for OpenCL types and shouldn't be launched for
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// handle OpenCL C/CPP and CPP for OpenCL types and shouldn't be launched for
// handle OpenCL C/C++ and C++ for OpenCL types and shouldn't be launched for

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in commit. Thanks

Signed-off-by: Arvind Sudarsanam <[email protected]>
@asudarsa asudarsa merged commit 80dfd86 into KhronosGroup:main Apr 2, 2024
bwlodarcz added a commit to bwlodarcz/SPIRV-LLVM-Translator that referenced this pull request Apr 18, 2024
…onosGroup#2466)"

This reverts commit 80dfd86.
The commit break Translator in cases when user supplied function is named
with the prefix which, after demangling, is the same as OpenCL builtin.
The culprit code is placed in during SPIRWriter OCL pass in
OCLToSPIRVBase::visitCallInst(CallInst &).
Failing name would be for example atomic_fetch_and_sub_uint32_explicit.
MrSidims pushed a commit that referenced this pull request Apr 19, 2024
…)" (#2508)

This reverts commit 80dfd86.
The commit break Translator in cases when user supplied function is named
with the prefix which, after demangling, is the same as OpenCL builtin.
The culprit code is placed in during SPIRWriter OCL pass in
OCLToSPIRVBase::visitCallInst(CallInst &).
Failing name would be for example atomic_fetch_and_sub_uint32_explicit.
maarquitos14 added a commit to maarquitos14/SPIRV-LLVM-Translator that referenced this pull request Feb 27, 2025
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.

3 participants