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] Add support for kernel name types templated using enums. #1675

Merged
merged 14 commits into from
May 18, 2020

Conversation

elizabethandrews
Copy link
Contributor

Forward declaration of enum used as template parameter for kernel name type is now emitted in integration header.

Enumerators in name type is also replaced with their underlying integer value since the enum definition is not visible in integration header..

E.g. For following application/user code:

 enum class device : int {
     cpu,
     gpu
 };

 template<device DeviceType>
 class dummy_functor { };

The following is generated in integration header:

// Forward declaration of enum:
enum class device : int;
// Forward declaration of templated kernel function types: 
template <device DeviceType> class dummy_functor;
//Specializations of KernelInfo for kernel function types: 
template <> struct KernelInfo<dummy_functor<(device)1>> {..} 

Signed-off-by: Elizabeth Andrews [email protected]

@elizabethandrews
Copy link
Contributor Author

@premanandrao I've added a test for anonymous namespaces. I'm waiting on your response about enums in SYCL headers, before removing the 'in cl namespace' check. Thanks!

@elizabethandrews
Copy link
Contributor Author

@premanandrao I've added a test for anonymous namespaces. I'm waiting on your response about enums in SYCL headers, before removing the 'in cl namespace' check. Thanks!

I took another look at the integration header and the includes here are defines.hpp and kernel_desc.hpp. As far as I can tell the only namespaces visible in integration header are therefore 'cl' and anything declared in cstddef (which is included in kernel_desc.hpp). Given that information do you still think we should remove the 'enum defined in cl namespace' check? Removing this check would result in a lot of unnecessary forward declarations in the integration header - since most sycl programs use the enums defined in SYCL headers.

clang/lib/Sema/SemaSYCL.cpp Outdated Show resolved Hide resolved
clang/test/CodeGenSYCL/int_header1.cpp Outdated Show resolved Hide resolved
@Fznamznon Fznamznon changed the title Add support for kernel name types templated using enums. [SYCL] Add support for kernel name types templated using enums. May 12, 2020
@premanandrao
Copy link
Contributor

@premanandrao I've added a test for anonymous namespaces. I'm waiting on your response about enums in SYCL headers, before removing the 'in cl namespace' check. Thanks!

I took another look at the integration header and the includes here are defines.hpp and kernel_desc.hpp. As far as I can tell the only namespaces visible in integration header are therefore 'cl' and anything declared in cstddef (which is included in kernel_desc.hpp). Given that information do you still think we should remove the 'enum defined in cl namespace' check?

I don't think this is right. <kernel_desc.hpp> includes many other header files and a lot of other symbols including enums are visible. Perhaps you were looking at the minimal version in the test directories?

Removing this check would result in a lot of unnecessary forward declarations in the integration header - since most sycl programs use the enums defined in SYCL headers.

But the forward declarations are only for the cases where they are used as kernel name types.

clang/lib/Sema/SemaSYCL.cpp Outdated Show resolved Hide resolved
clang/lib/Sema/SemaSYCL.cpp Show resolved Hide resolved
clang/lib/Sema/SemaSYCL.cpp Outdated Show resolved Hide resolved
clang/lib/Sema/SemaSYCL.cpp Outdated Show resolved Hide resolved
@elizabethandrews
Copy link
Contributor Author

But the forward declarations are only for the cases where they are used as kernel name types.

Oh right. Yes that's true. Got confused for a second. I'll remove the check.

@elizabethandrews
Copy link
Contributor Author

I'm having some trouble with emitting the global scope specifiers. I can emit it for template arguments by getting Argument type for each argument and creating fullyQualifiedType

  QualType T = Arg.getAsType();
  QualType FullyQualifiedType = TypeName::getFullyQualifiedType(T, Ctx, true);
  ArgOS << FullyQualifiedType.getAsString(TypePolicy);

But I'm not sure what to do about template name. Currently I'm emitting it using printQualifiedName but this does not emit global scope specifier. Would someone know how I can go about this?

@erichkeane
Copy link
Contributor

pecifiers. I can emit it for template arguments by getting Argument type for each argument an

What do you mean by "global scope specifier". Do you mean the scope resolution operator? (::)?

@elizabethandrews
Copy link
Contributor Author

elizabethandrews commented May 13, 2020

pecifiers. I can emit it for template arguments by getting Argument type for each argument an

What do you mean by "global scope specifier". Do you mean the scope resolution operator? (::)?

Yes. That is what I meant. After my patch,

     template <> struct KernelInfo<::nm1::KernelName3< ::nm1::nm2::KernelName0>>

has become

      template <> struct KernelInfo<nm1::KernelName3<nm1::nm2::KernelName0>>

5d22a8e was done a while ago to start the search for namespaces from global namespace

@erichkeane
Copy link
Contributor

pecifiers. I can emit it for template arguments by getting Argument type for each argument an

What do you mean by "global scope specifier". Do you mean the scope resolution operator? (::)?

Yes. That is what I meant. After my patch,

     template <> struct KernelInfo<::nm1::KernelName3< ::nm1::nm2::KernelName0>>

has become

      template <> struct KernelInfo<nm1::KernelName3<nm1::nm2::KernelName0>>

5d22a8e was done a while ago to start the search for namespaces from global namespace

I have no idea how that worked (or why 'suppress typedefs' did it...).

I haven't looked closely into the printer, but I think @premanandrao has. Prem, can you take a look?

@premanandrao
Copy link
Contributor

pecifiers. I can emit it for template arguments by getting Argument type for each argument an

What do you mean by "global scope specifier". Do you mean the scope resolution operator? (::)?

Yes. That is what I meant. After my patch,

     template <> struct KernelInfo<::nm1::KernelName3< ::nm1::nm2::KernelName0>>

has become

      template <> struct KernelInfo<nm1::KernelName3<nm1::nm2::KernelName0>>

5d22a8e was done a while ago to start the search for namespaces from global namespace

I have no idea how that worked (or why 'suppress typedefs' did it...).

I haven't looked closely into the printer, but I think @premanandrao has. Prem, can you take a look?

Yes, I will take a look.

 Removed check for CL namespace.
 Emit scope resolution operator for global namespace.
 Added test when underlying type is not fixed.

Signed-off-by: Elizabeth Andrews <[email protected]>
…o fixed underlying type

Signed-off-by: Elizabeth Andrews <[email protected]>
clang/include/clang/AST/Decl.h Show resolved Hide resolved
clang/lib/AST/Decl.cpp Outdated Show resolved Hide resolved
clang/lib/Sema/SemaSYCL.cpp Outdated Show resolved Hide resolved
clang/lib/Sema/SemaSYCL.cpp Outdated Show resolved Hide resolved
clang/lib/Sema/SemaSYCL.cpp Outdated Show resolved Hide resolved

for (unsigned I = 0; I < Args.size(); I++) {
const TemplateArgument &Arg = Args[I];
if (Arg.getKind() == TemplateArgument::ArgKind::Pack) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems a lot like a few of the other places we emit arguments based on their kind. Is there a way to dispatch the body of much of this instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maaaaybe. But I think the function body is not similar enough to make this efficient. Both functions are looping over arguments to emit 'something' but what is being emitted is different.

clang/lib/Sema/SemaSYCL.cpp Outdated Show resolved Hide resolved
  Minor refactoring when emitting scope resolution operator.
  Added tests got unscoped enum.
  Added comment syntax for bool argument.

Signed-off-by: Elizabeth Andrews <[email protected]>
Signed-off-by: Elizabeth Andrews <[email protected]>
clang/lib/Sema/SemaSYCL.cpp Outdated Show resolved Hide resolved
clang/lib/Sema/SemaSYCL.cpp Outdated Show resolved Hide resolved
clang/lib/Sema/SemaSYCL.cpp Outdated Show resolved Hide resolved
Signed-off-by: Elizabeth Andrews <[email protected]>
Signed-off-by: Elizabeth Andrews <[email protected]>
Signed-off-by: Elizabeth Andrews <[email protected]>
erichkeane
erichkeane previously approved these changes May 14, 2020
clang/lib/AST/Decl.cpp Show resolved Hide resolved
@elizabethandrews
Copy link
Contributor Author

Thanks for the review everyone!

Fznamznon
Fznamznon previously approved these changes May 15, 2020
clang/lib/AST/Decl.cpp Outdated Show resolved Hide resolved
@bader
Copy link
Contributor

bader commented May 15, 2020

http://ci.llvm.intel.com:8010/#/builders/37/builds/859/steps/15/logs/FAIL__SYCL-Unit__CudaInteropGetNativeTests_interop - this failure seems to be unrelated to the patch.
This patch changes SYCL compiler, which has no effect on unittests.

Also fixed handling of template argument type - enum type. The prior
patch handled only enum values, not the type itself.

Signed-off-by: Elizabeth Andrews <[email protected]>
Signed-off-by: Elizabeth Andrews <[email protected]>
Changed 'check' function to return true on error.
Changed diagnostic message.

Signed-off-by: Elizabeth Andrews <[email protected]>
erichkeane
erichkeane previously approved these changes May 17, 2020
Comment on lines +34 to +35
// expected-error@+2 {{kernel name is invalid. Unscoped enum requires fixed underlying type}}
template <unscoped_enum_no_type_set EnumType>
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be great if this diagnostic will also point to concrete single_task/parallel_for kernel invocation call which caused this error. See

// expected-error@+4 {{kernel needs to have a globally-visible name}}
for example.

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 because kernel location is set differently when kernel is defined using a lambda vs a functor. I just tested kernelname-enum.cpp using lambdas instead of functors and the diagnostic is generated at the point of kernel invocation like this example above. Since this is an existing issue with all diagnostics emitted when kernel is defined using functors, I'd like to work on this as a separate issue if that is alright with you.

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay. We need to capture this problem somehow.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok. I'll file a bug and assign it to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

clang/test/SemaSYCL/kernelname-enum.cpp Show resolved Hide resolved
Signed-off-by: Elizabeth Andrews <[email protected]>
@bader bader merged commit e7020a1 into intel:sycl May 18, 2020
alexbatashev pushed a commit to alexbatashev/llvm that referenced this pull request May 20, 2020
* sycl: (65 commits)
  [SYCL] Host task implementation (intel#1471)
  [SYCL] Update getting dependencies documentation (intel#1699)
  [SYCL] Fix types and transparent functors recognition in reduction (intel#1709)
  [SYCL][Doc] Get started guide clean-up (intel#1697)
  Add --spirv-fp-contract={on|off|fast} option (intel#509)
  [SYCL][Doc] Fix tbb target path in Get Started Guide. (intel#1695)
  [SYCL] Add support for kernel name types templated using enums. (intel#1675)
  [Driver][SYCL] Make -std=c++17 the default for DPC++ (intel#1662)
  AllocaInst should store Align instead of MaybeAlign.
  [X86] Replace selectScalarSSELoad ComplexPattern with PatFrags to handle the 3 types of loads we currently match.
  Harden IR and bitcode parsers against infinite size types.
  Revert "[nfc] test commit"
  [nfc] test commit
  Expose IRGen API to add the default IR attributes to a function definition.
  The release notes for ObjCBreakBeforeNestedBlockParam was placed between the release note for IndentCaseBlocks and its example code
  [VectorCombine] forward walk through instructions to improve chaining of transforms
  [PhaseOrdering] add vector reduction tests; NFC
  [InstCombine] Clean up alignment handling (NFC)
  [ARM] Patterns for VQSHRN
  [VectorCombine] add reduction-like patterns; NFC
  ...
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.

7 participants