Skip to content

[SYCL] Save user specified names in lambda object #5772

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

Merged
merged 2 commits into from
Mar 11, 2022

Conversation

elizabethandrews
Copy link
Contributor

This patch retains user specified names for lambda captures in
lambda object. As a result, the name of openCL kernel arguments
generated for SYCL kernel specified as a lamdba, now includes the
user names in kernel argument name (matches current behavior for
SYCL kernel specified as a functor object).

Signed-off-by: Elizabeth Andrews elizabeth.andrews@intel.com

This patch retains user specified names for lambda captures in
lambda object. As a result, the name of openCL kernel arguments
generated for SYCL kernel specified as a lamdba, now includes the
user names in kernel argument name (matches current behavior for
SYCL kernel specified as a functor object).

Signed-off-by: Elizabeth Andrews <elizabeth.andrews@intel.com>
@elizabethandrews elizabethandrews requested a review from a team as a code owner March 10, 2022 01:44
@elizabethandrews
Copy link
Contributor Author

I am also working on a patch to upstream this support to LLVM project. I'm hoping to put up that patch for review this week. I will share the link here once I put it up. I'm not sure if they will accept the change since there is no strong justification for this other than "it improves SYCL".

Since there is some urgency for this patch for DPCPP, I am hoping to get the ball rolling here in the meantime.

Signed-off-by: Elizabeth Andrews <elizabeth.andrews@intel.com>
@elizabethandrews elizabethandrews requested a review from a team as a code owner March 10, 2022 19:00
@elizabethandrews
Copy link
Contributor Author

I don't have the environment to test CUDA fails. The failures however seem to be due to IR changes because of name change. I've fixed what I saw in failing tests, but could not verify fix locally. Hopefully I've caught all the issues.

Copy link
Contributor

@alexbatashev alexbatashev left a comment

Choose a reason for hiding this comment

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

Runtime LGTM

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.

LGTM

Copy link
Contributor

@keryell keryell left a comment

Choose a reason for hiding this comment

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

Cool feature for the debug!

@elizabethandrews
Copy link
Contributor Author

@bader I don't believe the failures are a result of this patch. This is the 3rd run with the same code (first run had missed a few CUDA tests which I now fixed by changing tests, second run had one flaky test which longer fails) and this is third run which has new fails which did not show up in previous runs

@bader bader merged commit af29982 into intel:sycl Mar 11, 2022
@keryell
Copy link
Contributor

keryell commented Mar 12, 2022

Just rethinking last night about it, what happens it you have a non qualified name which appears twice, so you have a name conflict?
For example you capture a::c and b::c, with c are USM pointers defined in 2 different namespaces or 2 accessors defined in 2 different nested structs inside the submit around the lambda?

@elizabethandrews
Copy link
Contributor Author

elizabethandrews commented Mar 14, 2022

Just rethinking last night about it, what happens it you have a non qualified name which appears twice, so you have a name conflict? For example you capture a::c and b::c, with c are USM pointers defined in 2 different namespaces or 2 accessors defined in 2 different nested structs inside the submit around the lambda?

I believe you will have the same name. This isn't new behavior though. Accessors defined in nested structs already had name retained in kernel lambda object. For example -

Code:

struct AccessorNested {
  int A, B;
  sycl::accessor<char, 1, sycl::access::mode::read> AccField;
};

struct AccessorOuter {
  sycl::accessor<char, 1, sycl::access::mode::read> AccField;
  AccessorNested obj;
  int C;
};

int main() {
  AccessorOuter Object;
  myQueue.submit([&](sycl::handler &h) {
    h.single_task<class kernel>(
        [=] {
          Object.use();
        });
  });
  return 0;
}

AST for kernel parameters -

|-ParmVarDecl 0xa127378 <<invalid sloc>> <invalid sloc> used _arg_AccField '__global char *'
  | |-SYCLAccessorReadonlyAttr 0xa1273e0 <<invalid sloc>> Implicit
  | `-SYCLAccessorPtrAttr 0xa127438 <<invalid sloc>> Implicit
  |-ParmVarDecl 0xa127470 <<invalid sloc>> <invalid sloc> used _arg_AccField 'sycl::range<1>'
  |-ParmVarDecl 0xa1274e8 <<invalid sloc>> <invalid sloc> used _arg_AccField 'sycl::range<1>'
  |-ParmVarDecl 0xa127560 <<invalid sloc>> <invalid sloc> used _arg_AccField 'sycl::id<1>'
  |-ParmVarDecl 0xa127dc0 <<invalid sloc>> <invalid sloc> used _arg_A 'int'
  |-ParmVarDecl 0xa127e78 <<invalid sloc>> <invalid sloc> used _arg_B 'int'
  |-ParmVarDecl 0xa127f30 <<invalid sloc>> <invalid sloc> used _arg_AccField '__global char *'
  | |-SYCLAccessorReadonlyAttr 0xa127f98 <<invalid sloc>> Implicit
  | `-SYCLAccessorPtrAttr 0xa127ff0 <<invalid sloc>> Implicit
  |-ParmVarDecl 0xa128028 <<invalid sloc>> <invalid sloc> used _arg_AccField 'sycl::range<1>'
  |-ParmVarDecl 0xa1280a0 <<invalid sloc>> <invalid sloc> used _arg_AccField 'sycl::range<1>'
  |-ParmVarDecl 0xa128118 <<invalid sloc>> <invalid sloc> used _arg_AccField 'sycl::id<1>'
  |-ParmVarDecl 0xa128420 <<invalid sloc>> <invalid sloc> used _arg_C 'int'

This is existing behavior though. Variable names nested in some class were available prior to this patch as well. Only names of direct captures were missing - since clang didn't save these in lambda object. This patch just added that. There might be value in using qualified names instead.

@againull
Copy link
Contributor

againull commented Apr 7, 2022

@elizabethandrews I am not sure I fully understand this PR but I have a question.

Value names are discarded by default for release build of the Clang (no assertions), please see:
https://clang.llvm.org/docs/UsersManual.html#controlling-value-names-in-llvm-ir

And to disable this behaviour the following option can be used:
-fno-discard-value-names

If we want to preserve value names for DPCPP then shouldn't we enforce -fno-discard-value-names in driver if -fsycl is used?

@elizabethandrews
Copy link
Contributor Author

@elizabethandrews I am not sure I fully understand this PR but I have a question.

Value names are discarded by default for release build of the Clang (no assertions), please see: https://clang.llvm.org/docs/UsersManual.html#controlling-value-names-in-llvm-ir

And to disable this behaviour the following option can be used: -fno-discard-value-names

If we want to preserve value names for DPCPP then shouldn't we enforce -fno-discard-value-names in driver if -fsycl is used?

@againull this PR wasn't about preserving names for llvm::values. This PR preserves names when generating an openCL kernel (from SYCL kernel). We were not saving user-specified names in some cases resulting in generic names in LLVM IR for openCL kernel arguments, irrespective of options used.

@keryell
Copy link
Contributor

keryell commented Apr 7, 2022

Would it make sense to save a fully qualified mangled name then instead of the short one?

@elizabethandrews
Copy link
Contributor Author

Would it make sense to save a fully qualified mangled name then instead of the short one?

From a functional perspective I don't think it makes a difference since same names don't seem to bother backend. Name generated in IR will be unique. For debugging purposes, if we have names which repeat within a kernel maybe fully qualified names helps? I'm not sure if it will make the IR verbose though.

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