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

Translate LLVM-IR zero-length arrays to 1-length arrays in SPIR-V #2743

Merged
merged 6 commits into from
Oct 8, 2024

Conversation

lbushi25
Copy link
Contributor

@lbushi25 lbushi25 commented Oct 7, 2024

The LLVM-IR type of zero-length array does not seem to have a mapping into SPIR-V type, rather it outputs an error since the obvious choice of zero-length array is not valid in SPIR-V. This, for example, prohibits us from using unbounded arrays in SYCL device kernels because they are typically represented in LLVM-IR through zero-length arrays. This PR attempts to introduce a workaround to this by lowering a zero-length array in LLVM-IR to a 1-length array in SPIR-V.

@CLAassistant
Copy link

CLAassistant commented Oct 7, 2024

CLA assistant check
All committers have signed the CLA.

@lbushi25 lbushi25 marked this pull request as ready for review October 7, 2024 16:26
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.

Unconditionally generating non-conformant SPIR-V seems not right. The suggestion in #417 was to hide such functionality behind an option (or perhaps we should consider a SPIR-V extension?).

@lbushi25
Copy link
Contributor Author

lbushi25 commented Oct 7, 2024

Unconditionally generating non-conformant SPIR-V seems not right. The suggestion in #417 was to hide such functionality behind an option (or perhaps we should consider a SPIR-V extension?).

Why would this be non-conformant SPIR-V?
I'm not generating arrays of size zero. I'm instead modifying the lowering of LLVM IR arrays of zero-length to SPIR-V arrays of length 1 which are, at least to the best of my knowledge, valid in SPIR-V.

@svenvh
Copy link
Member

svenvh commented Oct 8, 2024

Why would this be non-conformant SPIR-V? I'm not generating arrays of size zero. I'm instead modifying the lowering of LLVM IR arrays of zero-length to SPIR-V arrays of length 1 which are, at least to the best of my knowledge, valid in SPIR-V.

My apologies, I completely misread your initial description. Lowering to a SPIR-V array of length 1 is of course valid SPIR-V.

lib/SPIRV/SPIRVWriter.cpp Show resolved Hide resolved
lib/SPIRV/SPIRVWriter.cpp Show resolved Hide resolved
@MrSidims MrSidims merged commit 38db490 into KhronosGroup:main Oct 8, 2024
9 checks passed
AlexeySachkov pushed a commit to intel/llvm that referenced this pull request Oct 11, 2024
…rray of length 1 (#15663)

Cherry-pick of
KhronosGroup/SPIRV-LLVM-Translator#2743.

The LLVM-IR type of zero-length array does not seem to have a mapping
into SPIR-V type, rather it outputs an error since the obvious choice of
zero-length array is not valid in SPIR-V. This, for example, prohibits
us from using unbounded arrays in SYCL device kernels because they are
typically represented in LLVM-IR through zero-length arrays. This PR
introduces a workaround to this by lowering a zero-length array in
LLVM-IR to a 1-length array in SPIR-V.
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.

4 participants