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

[CUDA][HIP] file-scope device variable not allowed with trivial ctor #72261

Closed
yxsamliu opened this issue Nov 14, 2023 · 3 comments · Fixed by #72394 or #73140
Closed

[CUDA][HIP] file-scope device variable not allowed with trivial ctor #72261

yxsamliu opened this issue Nov 14, 2023 · 3 comments · Fixed by #72394 or #73140
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" cuda

Comments

@yxsamliu
Copy link
Collaborator

`struct A {
A() {}
~A() {}
int x;
};

device A x;`

the above code is allowed with nvcc but not cuda-clang.

https://godbolt.org/z/jjMG3zTd3

https://godbolt.org/z/74Ed1WvGn

nvcc allows it not because it makes the ctor A::A() implicitly host device (this can be seen by defining A x in device function), but because it does not check host/device availability for file-scope device var.

I think it makes sense to make trivial ctor/dtor implicitly host device.

@Artem-B

@Artem-B
Copy link
Member

Artem-B commented Nov 14, 2023

I think it makes sense to make trivial ctor/dtor implicitly host device.
SGTM.

yxsamliu added a commit to yxsamliu/llvm-project that referenced this issue Nov 16, 2023
Make trivial ctor/dtor implicitly host device functions
so that they can be used to initialize file-scope
device variables to match nvcc behavior.

Fixes: llvm#72261

Fixes: SWDEV-432412
yxsamliu added a commit that referenced this issue Nov 16, 2023
Make trivial ctor/dtor implicitly host device functions so that they can
be used to initialize file-scope
device variables to match nvcc behavior.

Fixes: #72261

Fixes: SWDEV-432412
@EugeneZelenko EugeneZelenko added the clang:frontend Language frontend issues, e.g. anything involving "Sema" label Nov 16, 2023
@llvmbot
Copy link
Collaborator

llvmbot commented Nov 16, 2023

@llvm/issue-subscribers-clang-frontend

Author: Yaxun (Sam) Liu (yxsamliu)

`struct A { A() {} ~A() {} int x; };

device A x;`

the above code is allowed with nvcc but not cuda-clang.

https://godbolt.org/z/jjMG3zTd3

https://godbolt.org/z/74Ed1WvGn

nvcc allows it not because it makes the ctor A::A() implicitly host device (this can be seen by defining A x in device function), but because it does not check host/device availability for file-scope device var.

I think it makes sense to make trivial ctor/dtor implicitly host device.

@Artem-B

@Artem-B
Copy link
Member

Artem-B commented Nov 19, 2023

@yxsamliu The patch is causing compilation issues: #72394 (comment)

sr-tream pushed a commit to sr-tream/llvm-project that referenced this issue Nov 20, 2023
Make trivial ctor/dtor implicitly host device functions so that they can
be used to initialize file-scope
device variables to match nvcc behavior.

Fixes: llvm#72261

Fixes: SWDEV-432412
zahiraam pushed a commit to zahiraam/llvm-project that referenced this issue Nov 20, 2023
Make trivial ctor/dtor implicitly host device functions so that they can
be used to initialize file-scope
device variables to match nvcc behavior.

Fixes: llvm#72261

Fixes: SWDEV-432412
yxsamliu added a commit to yxsamliu/llvm-project that referenced this issue Nov 23, 2023
Treat ctor/dtor in device var init as host device function
so that they can be used to initialize file-scope
device variables to match nvcc behavior. If they are non-trivial
they will be diagnosed.

We cannot add implicit host device attrs to non-trivial
ctor/dtor since determining whether they are non-trivial
needs to know whether they have a trivial body and all their
member and base classes' ctor/dtor have trivial body, which
is affected by where their bodies are defined or instantiated.

Fixes: llvm#72261

Fixes: SWDEV-432412
searlmc1 pushed a commit to ROCm/llvm-project that referenced this issue Nov 27, 2023
Make trivial ctor/dtor implicitly host device functions
so that they can be used to initialize file-scope
device variables to match nvcc behavior.

Fixes: llvm#72261

Fixes: SWDEV-432412

cherry-pick of: llvm#72394

Change-Id: Ieac37f8fa35e035a84bae9c5d29c6f5acab6a766
yxsamliu added a commit that referenced this issue Dec 1, 2023
Treat ctor/dtor in device var init as host device function
so that they can be used to initialize file-scope
device variables to match nvcc behavior. If they are non-trivial
they will be diagnosed.

We cannot add implicit host device attrs to non-trivial
ctor/dtor since determining whether they are non-trivial
needs to know whether they have a trivial body and all their
member and base classes' ctor/dtor have trivial body, which
is affected by where their bodies are defined or instantiated.

Fixes: #72261

Fixes: SWDEV-432412
rocm-ci pushed a commit to ROCm/llvm-project that referenced this issue Dec 15, 2023
Make trivial ctor/dtor implicitly host device functions
so that they can be used to initialize file-scope
device variables to match nvcc behavior.

Fixes: llvm#72261

Fixes: SWDEV-432412

cherry-pick of: llvm#72394

[CUDA][HIP] ignore implicit host/device attr for override

When deciding whether a previous function declaration is an
overload or override, implicit host/device attrs should
not be considered.

This fixes the failure for the following code:

`template <typename T>
class C {
    explicit C() {};
};

template <> C<int>::C() {};
`

The issue was introduced by llvm#72394

sine the template specialization is treated as overload
due to implicit host/device attrs are considered for
overload/override differentiation.

cherry-pick of llvm#72815

Change-Id: Ie896cc0e4d5d82d5af48e08a996a3b392285d9ee
rocm-ci pushed a commit to ROCm/llvm-project that referenced this issue Dec 15, 2023
Treat ctor/dtor in device var init as host device function
so that they can be used to initialize file-scope
device variables to match nvcc behavior. If they are non-trivial
they will be diagnosed.

We cannot add implicit host device attrs to non-trivial
ctor/dtor since determining whether they are non-trivial
needs to know whether they have a trivial body and all their
member and base classes' ctor/dtor have trivial body, which
is affected by where their bodies are defined or instantiated.

Revert "[CUDA][HIP] make trivial ctor/dtor host device"

This reverts commit 876f99a.

Fixes: llvm#72261

Fixes: SWDEV-432412

Fixes: SWDEV-433956
Change-Id: I711db63a2166ce77dea06aad5d04cae10d96ce24
searlmc1 pushed a commit to ROCm/llvm-project that referenced this issue Dec 19, 2023
Treat ctor/dtor in device var init as host device function
so that they can be used to initialize file-scope
device variables to match nvcc behavior. If they are non-trivial
they will be diagnosed.

We cannot add implicit host device attrs to non-trivial
ctor/dtor since determining whether they are non-trivial
needs to know whether they have a trivial body and all their
member and base classes' ctor/dtor have trivial body, which
is affected by where their bodies are defined or instantiated.

Fixes: llvm#72261

Fixes: SWDEV-432412
Change-Id: Iac807ee37d235c73d66fcf9c4416b928a1afe832
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" cuda
Projects
None yet
4 participants