Skip to content

[SYCL] Change adress space for global variables #2534

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 6 commits into from
Sep 30, 2020

Conversation

fadeeval
Copy link
Contributor

@fadeeval fadeeval commented Sep 24, 2020

GlobalVariables shouldn't have private address space.
This PR change usage of private address space to global for global variables.
Private address space maps to Function StorageClass in llvm-spirv translator, but global declarations shouldn't have Function Storage Class due to SPIRV spec (https://www.khronos.org/registry/spir-v/specs/unified1/SPIRV.html).

Signed-off-by: Aleksander Fadeev [email protected]

Signed-off-by: Aleksander Fadeev <[email protected]>
Signed-off-by: Aleksander Fadeev <[email protected]>
@fadeeval fadeeval marked this pull request as ready for review September 24, 2020 14:11
@premanandrao
Copy link
Contributor

Looks like you are only changing the address space for string literals. Is that correct? PR title seems to be more general.

@fadeeval
Copy link
Contributor Author

The getStringLiteralAddressSpace() function is not being used for string literal only.

@fadeeval
Copy link
Contributor Author

But maybe I didn't write description exactly correct, now it should be more understandable.

@@ -4012,7 +4012,7 @@ LangAS CodeGenModule::getStringLiteralAddressSpace() const {
// const char *getLiteral() n{
// return "AB";
// }
return LangAS::opencl_private;
return LangAS::opencl_global;
Copy link
Contributor

Choose a reason for hiding this comment

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

To me, opencl_constant looks like a right value to return. Could you explain why we use opencl_global here?

Copy link
Contributor

@keryell keryell Sep 24, 2020

Choose a reason for hiding this comment

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

There are too many constraints on OpenCL constant address space: limited memory capacity, pointers that cannot be cast to generic address space...
So even it seems like the obvious answer, it causes a lot of trouble.
But since you are asking: there is obviously a missing comment explaining the motivation in the code... :-(
Actually any question in a PR means at least 1 lacking comment in the code. ;-)

Copy link
Contributor

Choose a reason for hiding this comment

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

In this case though, there is a comment just above the differences that says:
```
// If we keep a literal string in constant address space, the following code
// becomes illegal:
//
// const char *getLiteral() n{
// return "AB";
// }

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes but it does not explains why it becomes illegal.
The more comments, the happier I am. :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is a addressspacecast to generic address space in IR, but adressspacecast from constant to generic forbitten because of constant address space is not part of generic address space. @keryell, should I write it in source code comments?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes please, add a lot of comments useful to understand the big picture. Thanks.

@elizabethandrews
Copy link
Contributor

elizabethandrews commented Sep 24, 2020

The getStringLiteralAddressSpace() function is not being used for string literal only.

Can you add tests for all the cases you're trying to support? The current test modifications only show address space change for string literals.

I took a quick look at the code to see where getStringLiteralAddressSpace() is called and the only other place I saw it called is createUnnamedGlobalFrom() I'm not familiar with this API (so please correct me if I am mistaken) but this does not look like the place to 'change address space of global variables' like the PR title suggests. This looks like code to handle cases like the integer array here - https://godbolt.org/z/nqzqx8. (Note the global this creates).

Edit: Corrected Godbolt link.

@elizabethandrews
Copy link
Contributor

The getStringLiteralAddressSpace() function is not being used for string literal only.

Can you add tests for all the cases you're trying to support? The current test modifications only show address space change for string literals.

I took a quick look at the code to see where getStringLiteralAddressSpace() is called and the only other place I saw it called is createUnnamedGlobalFrom() I'm not familiar with this API (so please correct me if I am mistaken) but this does not look like the place to 'change address space of global variables' like the PR title suggests. This looks like code to handle cases like the integer array here - https://godbolt.org/z/nqzqx8. (Note the global this creates).

Edit: Corrected Godbolt link.

Is this the case you're trying to handle when you say global variables? I think I may have misunderstood what you meant by 'global variables'. In any case, please add a test.

@fadeeval
Copy link
Contributor Author

@elizabethandrews, I am not sure that it is needed to add tests because the fixed tests already show that I wanted to do.
Arrays and static variables (as well as literal strings) are declared as global in LLVM IR, so in SPIRV it may be a problem, that this PR should fix.

@premanandrao
Copy link
Contributor

@elizabethandrews, I am not sure that it is needed to add tests because the fixed tests already show that I wanted to do.
Arrays and static variables (as well as literal strings) are declared as global in LLVM IR, so in SPIRV it may be a problem, that this PR should fix.

Please add a test that checks this for file-scope statics, static data members, and templated versions of both. I think these will be helpful.

@bader bader changed the title Change adress space for global variables [SYCL] Change adress space for global variables Sep 28, 2020
Signed-off-by: Aleksander Fadeev <[email protected]>
Signed-off-by: Aleksander Fadeev <[email protected]>
@Fznamznon Fznamznon requested a review from asavonic September 29, 2020 11:49
@bader bader merged commit eac16d8 into intel:sycl Sep 30, 2020
alexbatashev pushed a commit to alexbatashev/llvm that referenced this pull request Oct 5, 2020
…_wrapper

* upstream/sycl: (1021 commits)
  [SYCL] Enable async_work_group_copy for scalar and vector bool types (intel#2582)
  [SYCL] Fix element type in handler::copy (intel#2590)
  [NFC][SYCL] Remove unnecessary if condition (intel#2585)
  [SYCL][NFC] Fix SYCL lit test execution on a system w/o GPU (intel#2584)
  [SYCL] Add error handling for non-uniform work group size case (intel#2569)
  [SYCL][ESIMD] Preserve undef initializer for globals in ESIMDLowerVecArg pass (intel#2555)
  [SYCL] Make Level-Zero events visible on the host (intel#2576)
  [Driver][SYCL][NFC] Add help information for -Wno-sycl-strict (intel#2570)
  [SYCL] Relax test to work in Win32 environment. (intel#2580)
  [SYCL] Emit suppressed warnings from SYCL headers (intel#2575)
  [SYCL][NFC] Cover more classes with ABI tests (intel#2577)
  [SYCL][ESIMD] Update ESIMD tests and add raw send support. (intel#2482)
  [SYCL] Make ESIMD on-device tests require linux,gpu,opencl. (intel#2560)
  [SYCL] Release commands with no dependencies after they're enqueued (intel#2492)
  [SYCL] Add multi-device and multi-platform support for SYCL_DEVICE_ALLOWLIST  (intel#2483)
  [SYCL] Try to enqueue host command depencies (intel#2561)
  [SYCL][ESIMD][NFC] Align namespace name with the spec guidelines (intel#2573)
  [SYCL][NFC] Add class layout ABI tests for memory objects (intel#2559)
  [SYCL] Change adress space for global variables (intel#2534)
  [NFC][SYCL] Fix comment. (intel#2541)
  ...
kbenzie added a commit to kbenzie/intel-llvm that referenced this pull request Feb 17, 2025
…global

[DeviceMSAN] Fix gpu crashed on device global variable
Chenyang-L pushed a commit that referenced this pull request Feb 18, 2025
[DeviceMSAN] Fix gpu crashed on device global variable
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