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] Enable OpenCL diagnostics for sampler in SYCL mode #167

Merged
merged 3 commits into from
Jun 12, 2019

Conversation

bader
Copy link
Contributor

@bader bader commented May 24, 2019

Selectively enabled a few OpenCL diagnostics for sampler type as some
diagnostics trigger on SYCL use cases.

For instance, OpenCL kernel in SYCL mode initializes lambda captures with
the kernel argument values. This initialization code for sampler emits
errors because OpenCL disallows sampler on the right hand side of the
binary operators - these are supposed to be used only by built-in
functions.

Another potential issue is the lambda object itself -
captured sampler is a member of the lambda object and OpenCL doesn't
allow composite types with samplers. SPIR-V produced from SYCL should be
okay as lambda object can be removed by standard LLVM transformation
passes.

@Fznamznon
Copy link
Contributor

I think if we are going to remove OpTypeSampler usages, we should also remove it from clang tests.

@bader
Copy link
Contributor Author

bader commented May 26, 2019

I think if we are going to remove OpTypeSampler usages, we should also remove it from clang tests.

Thanks for reminding about this.
I've added one come commit to update the clang tests.

@bader bader changed the title [WIP][SYCL] Switch SPIR-V types to OpenCL types [SYCL] Switch SPIR-V types to OpenCL types May 27, 2019
@bader
Copy link
Contributor Author

bader commented May 28, 2019

This PR is superseded by #171.

@bader bader closed this May 28, 2019
@Fznamznon
Copy link
Contributor

Note: in #171 diagnostics aren't enabled.

@bader
Copy link
Contributor Author

bader commented May 29, 2019

Okay. I'll re-open this PR.
I'll rebase it after we merge #171.

@bader bader reopened this May 29, 2019
@bader bader changed the title [SYCL] Switch SPIR-V types to OpenCL types [WIP][SYCL] Switch SPIR-V types to OpenCL types May 29, 2019
@bader bader changed the title [WIP][SYCL] Switch SPIR-V types to OpenCL types [SYCL] Enable OpenCL diagnostics for sampler in SYCL mode May 31, 2019
@bader bader requested a review from Fznamznon May 31, 2019 10:59
@@ -6347,6 +6347,26 @@ NamedDecl *Sema::ActOnVariableDeclarator(
return nullptr;
}

if (R->isSamplerT()) {
Copy link
Contributor

@Fznamznon Fznamznon May 31, 2019

Choose a reason for hiding this comment

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

Shouldn't we guard this code under if (getLangOpts().SYCLIsDevice || getLangOpts().OpenCL) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sampler type is enabled only for OpenCL and SYCL modes, so if R->isSamplerT() returns true, we know that getLangOpts().SYCLIsDevice || getLangOpts().OpenCL is also true.
There might be some other environments which might be interested in enabling this data type, so if they what to disable this diagnostics they will have to extend the condition.

Copy link
Contributor

Choose a reason for hiding this comment

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

But this code already was under if (getLangOpts().OpenCL), maybe this if could help to understand this code in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@AnastasiaStulova asked for applying changes like this as removing redundant checks should speed-up compilation.

@@ -6347,6 +6347,26 @@ NamedDecl *Sema::ActOnVariableDeclarator(
return nullptr;
}

if (R->isSamplerT()) {
// OpenCL v1.2 s6.9.b p4:
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment looks stange. We implement some OpenCL restrictions but not only for OpenCL.

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. Any suggestions?

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually I can't find any restrictions for sampler in SYCL spec. I think we can leave comment describes that SYCL re-uses OpenCL types so these restrictions applied for SYCL too but it's not necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

NOTE: the restriction is enabled for all languages, which allows sampler type. I don't think explicitly mentioning SYCL here is good idea.

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay. So, why we are explicitly mentioning OpenCL here?

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 is the place where the behavior of this type is defined.

@@ -5634,6 +5634,9 @@ void InitializationSequence::InitializeFrom(Sema &S,
bool allowObjCWritebackConversion = S.getLangOpts().ObjCAutoRefCount &&
Entity.isParameterKind();

if (TryOCLSamplerInitialization(S, *this, DestType, Initializer))
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, could you please clarify: why do you need this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To enable sampler initialization diagnostics in SYCL mode.

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, I didn't see why it can't work on old place. I will expand hidden code next time.
Looks like we need also move TryOCLZeroOpaqueTypeInitialization if we want enable diagnostics for event in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Event type diagnostics should be enabled separately.

@@ -2322,7 +2322,7 @@ QualType Sema::BuildArrayType(QualType T, ArrayType::ArraySizeModifier ASM,
// OpenCL v2.0 s6.12.5 - Arrays of blocks are not supported.
// OpenCL v2.0 s6.16.13.1 - Arrays of pipe type are not supported.
// OpenCL v2.0 s6.9.b - Arrays of image/sampler type are not supported.
if (getLangOpts().OpenCL) {
if (getLangOpts().OpenCL || getLangOpts().SYCLIsDevice) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Following the logic:

Sampler type is enabled only for OpenCL and SYCL modes, so if R->isSamplerT() returns true, we know that getLangOpts().SYCLIsDevice || getLangOpts().OpenCL is also true.

Can't we remove getLangOpts checks?

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 don't think so.
Blocks are not OpenCL specific types.

bader added 3 commits June 7, 2019 16:15
Removed comments are redundant and complicate maintenance.

Signed-off-by: Alexey Bader <alexey.bader@intel.com>
Signed-off-by: Alexey Bader <alexey.bader@intel.com>
Selectively enabled a few OpenCL diagnostics for sampler type as some
diagnostics trigger on SYCL use cases.

For instance, OpenCL kernel in SYCL mode initializes lambda captures with
the kernel argument values. This initialization code for sampler emits
errors because OpenCL disallows sampler on the right hand side of the
binary operators - these are supposed to be used only by built-in
functions.

Another potential issue is the lambda object itself -
captured sampler is a member of the lambda object and OpenCL doesn't
allow composite types with samplers. SPIR-V produced from SYCL should be
okay as lambda object can be removed by standard LLVM transformation
passes.

Signed-off-by: Alexey Bader <alexey.bader@intel.com>
@bader bader merged commit eb735ee into intel:sycl Jun 12, 2019
@bader bader deleted the sampler-experiment branch June 21, 2019 12:25
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