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

[SYCL-SPIRV] Add SPIR-V variants of TypeSampledImage as clang builtin type #1945

Merged
merged 2 commits into from
Jul 6, 2020

Conversation

Naghasan
Copy link
Contributor

This patch adds SPIR-V sampled image types as derivative of the builtin OpenCL Image types.
For each OpenCL image type, clang defines a Sampled variant and
lowered as a "spirv.SampledImage." llvm opaque type.

The motivation for this patch is to allow a cleaner emulation of sampled image reads for the CUDA backend as it does not support independent image and sampler definition. This change allows to properly implement the __spirv_SampledImage builtin function by having it return a sampled image type (which can then be properly lowered according to its target) rather than void *.

Signed-off-by: Victor Lomuller victor@codeplay.com

…in clang.

This patch adds SPIR-V sampled image types as derivative of the builtin OpenCL Image types.
For each OpenCL image type, clang defines a Sampled<image type> variant and
lowered as a "spirv.SampledImage.<image>" llvm opaque type.

Signed-off-by: Victor Lomuller <victor@codeplay.com>
@Fznamznon
Copy link
Contributor

@erichkeane, @bader , could you please help with review?

erichkeane
erichkeane previously approved these changes Jun 23, 2020
Copy link
Contributor

@erichkeane erichkeane left a comment

Choose a reason for hiding this comment

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

The code itself seems pretty mechanical and thus non controversial to me. That said, someone more familiar with what this is doing should judge/approve based on the solution chosen for the problem (that is, does adding these types fix the issue in the best way).

@Naghasan
Copy link
Contributor Author

A bit more background for this patch: This patch makes the SPIR-V type OpTypeSampledImage (https://www.khronos.org/registry/spir-v/specs/unified1/SPIRV.html#OpTypeSampledImage) accessible in clang, even if the naming follows the OpenCL terminology (I think it makes a bit more sense from an upstreaming point of view).

This allow an accurate expression of OpSampledImage (https://www.khronos.org/registry/spir-v/specs/unified1/SPIRV.html#OpSampledImage) which in turns allow its implementation in a library. OpTypeSampledImage can be mapped into something meaningful for the target whereas void * can't.

@Naghasan
Copy link
Contributor Author

PR #1978 is showing the application for this new type

bader
bader previously approved these changes Jun 27, 2020
@bader
Copy link
Contributor

bader commented Jun 29, 2020

@intel/llvm-reviewers-runtime, @elizabethandrews, @Fznamznon, @premanandrao, ping.

clang/lib/Sema/SemaType.cpp Outdated Show resolved Hide resolved
Fznamznon
Fznamznon previously approved these changes Jun 29, 2020
Signed-off-by: Victor Lomuller <victor@codeplay.com>
@Naghasan Naghasan dismissed stale reviews from Fznamznon, bader, and erichkeane via 96ab694 July 3, 2020 14:23
@@ -0,0 +1,12 @@
// RUN: %clang_cc1 %s -triple x86_64-unknown-linux-gnu -O0 -emit-llvm -o - | FileCheck %s
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 intention to test it with x86 triple?

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-ish, it follows the same patterns as for image.cl. This is just to make the output stable when it comes to running the tests.

@bader bader added the cuda CUDA back-end label Jul 3, 2020
Copy link
Contributor

@s-kanaev s-kanaev left a comment

Choose a reason for hiding this comment

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

Runtime library headers look good to me.

@bader bader requested a review from Fznamznon July 3, 2020 20:08
Copy link
Contributor

@premanandrao premanandrao left a comment

Choose a reason for hiding this comment

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

There are multiple places where the IMAGE_TYPE macro is redefined. This would produce a build warning.

Other than that, looks good to me.

@Naghasan
Copy link
Contributor Author

Naghasan commented Jul 6, 2020

There are multiple places where the IMAGE_TYPE macro is redefined. This would produce a build warning.

OpenCLImageTypes.def undefines it, so no warning

@bader bader requested a review from premanandrao July 6, 2020 09:10
@bader bader merged commit 768f74f into intel:sycl Jul 6, 2020
@Fznamznon
Copy link
Contributor

Fznamznon commented Aug 10, 2021

If I remember correctly, the original idea of using functions with __spirv prefixes and Spirv.* opaque types was inspired by SPIR-V friendly LLVM IR ( https://github.com/KhronosGroup/SPIRV-LLVM-Translator/blob/master/docs/SPIRVRepresentationInLLVM.rst ) which allows to define functions/types in source code that will be correctly mapped to SPIR-V instructions/types by SPIR-V translator tool. SPIR-V friendly LLVM IR doc also defines how to attach additional image info to SampledImage type, see https://github.com/KhronosGroup/SPIRV-LLVM-Translator/blob/master/docs/SPIRVRepresentationInLLVM.rst#optypesampledimage . I wonder what was the reason to use mix of OpenCL and SPIRV friendly types (I mean spirv.SampledImage.image*) instead of full SPIR-V friendly type (spirv.SampledImage._void_*)? Can we actually emit full SPIR-V friendly type?

wenju-he added a commit to wenju-he/llvm that referenced this pull request Jan 11, 2023
bader pushed a commit that referenced this pull request Jan 13, 2023
These types are introduced in #1945

This PR fix following build warnings:
```
[3204/3298] Building CXX object tools/lldb/source/Plugins/TypeSystem/Clang/CMakeFiles/lldbPluginTypeSystemClang.dir/TypeSystemClang.cpp.o
lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp: In member function ‘virtual lldb::Encoding lldb_private::TypeSystemClang::GetEncoding(lldb::opaque_compiler_type_t, uint64_t&)’:
lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp:4829:12: warning: enumeration value ‘SampledOCLImage1dRO’ not handled in switch [-Wswitch]
     switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) {
            ^
lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp:4829:12: warning: enumeration value ‘SampledOCLImage1dArrayRO’ not handled in switch [-Wswitch]
lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp:4829:12: warning: enumeration value ‘SampledOCLImage1dBufferRO’ not handled in switch [-Wswitch]
lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp:4829:12: warning: enumeration value ‘SampledOCLImage2dRO’ not handled in switch [-Wswitch]
lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp:4829:12: warning: enumeration value ‘SampledOCLImage2dArrayRO’ not handled in switch [-Wswitch]
lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp:4829:12: warning: enumeration value ‘SampledOCLImage2dDepthRO’ not handled in switch [-Wswitch]
lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp:4829:12: warning: enumeration value ‘SampledOCLImage2dArrayDepthRO’ not handled in switch [-Wswitch]
lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp:4829:12: warning: enumeration value ‘SampledOCLImage2dMSAARO’ not handled in switch [-Wswitch]
lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp:4829:12: warning: enumeration value ‘SampledOCLImage2dArrayMSAARO’ not handled in switch [-Wswitch]
lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp:4829:12: warning: enumeration value ‘SampledOCLImage2dMSAADepthRO’ not handled in switch [-Wswitch]
lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp:4829:12: warning: enumeration value ‘SampledOCLImage2dArrayMSAADepthRO’ not handled in switch [-Wswitch]
lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp:4829:12: warning: enumeration value ‘SampledOCLImage3dRO’ not handled in switch [-Wswitch]
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cuda CUDA back-end
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants