[clang] [CUDA][HIP] Exclude external variables from constant promotion. (PR #73549)

2023-12-18 Thread Levon Ter-Grigoryan via cfe-commits

PatriosTheGreat wrote:

FYI

https://github.com/llvm/llvm-project/pull/73549
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [CUDA][HIP] Exclude external variables from constant promotion. (PR #73549)

2023-12-18 Thread Levon Ter-Grigoryan via cfe-commits


@@ -104,3 +106,14 @@ void fun() {
   (void) b;
   (void) var_host_only;
 }
+
+extern __global__ void external_func();
+extern void* const external_dep[] = {
+  (void*)(external_func)
+};
+extern void* const external_arr[] = {};
+
+void* host_fun() {
+  (void) external_dep;
+  (void) external_arr;
+}

PatriosTheGreat wrote:

This case is checked by flag "-implicit-check-not=external_" at the line 6, so 
we can check that external is not mentioned anywhere at the device code.

https://github.com/llvm/llvm-project/pull/73549
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [CUDA][HIP] Exclude external variables from constant promotion. (PR #73549)

2023-12-18 Thread Levon Ter-Grigoryan via cfe-commits

https://github.com/PatriosTheGreat deleted 
https://github.com/llvm/llvm-project/pull/73549
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [CUDA][HIP] Exclude external variables from constant promotion. (PR #73549)

2023-12-18 Thread Levon Ter-Grigoryan via cfe-commits


@@ -104,3 +106,14 @@ void fun() {
   (void) b;
   (void) var_host_only;
 }
+
+extern __global__ void external_func();
+extern void* const external_dep[] = {
+  (void*)(external_func)
+};
+extern void* const external_arr[] = {};
+
+void* host_fun() {
+  (void) external_dep;
+  (void) external_arr;
+}

PatriosTheGreat wrote:

This case is checked by flag "-implicit-check-not=external_" at the line 6, so 
we can check that external is not mentioned anywhere at the device code.

https://github.com/llvm/llvm-project/pull/73549
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [CUDA][HIP] Exclude external variables from constant promotion. (PR #73549)

2023-12-20 Thread Levon Ter-Grigoryan via cfe-commits

https://github.com/PatriosTheGreat updated 
https://github.com/llvm/llvm-project/pull/73549

>From 1c24a6774f08c9943cce1a2eee96a6a92b11fd02 Mon Sep 17 00:00:00 2001
From: Levon Ter-Grigoryan 
Date: Mon, 27 Nov 2023 18:09:22 +0100
Subject: [PATCH] [CUDA][HIP] Exclude external variables from constant
 promotion.

Promoting __constant__ to external variables includes them to PTX which then 
leads to nvlinker failure.
See changes at device-use-host-var test.
Befor this change those variables was included to PTX without definition.
---
 clang/lib/Sema/SemaCUDA.cpp   |  1 +
 clang/test/CodeGenCUDA/device-use-host-var.cu | 13 +
 2 files changed, 14 insertions(+)

diff --git a/clang/lib/Sema/SemaCUDA.cpp b/clang/lib/Sema/SemaCUDA.cpp
index 6a66ecf6f94c178..d744f9a8c5109f8 100644
--- a/clang/lib/Sema/SemaCUDA.cpp
+++ b/clang/lib/Sema/SemaCUDA.cpp
@@ -792,6 +792,7 @@ void Sema::MaybeAddCUDAConstantAttr(VarDecl *VD) {
   (VD->isFileVarDecl() || VD->isStaticDataMember()) &&
   !IsDependentVar(VD) &&
   ((VD->isConstexpr() || VD->getType().isConstQualified()) &&
+   VD->getStorageClass() != SC_Extern &&
HasAllowedCUDADeviceStaticInitializer(*this, VD,
  CICK_DeviceOrConstant))) {
 VD->addAttr(CUDAConstantAttr::CreateImplicit(getASTContext()));
diff --git a/clang/test/CodeGenCUDA/device-use-host-var.cu 
b/clang/test/CodeGenCUDA/device-use-host-var.cu
index 64de57e41b4b9f5..65aac2b7eca891c 100644
--- a/clang/test/CodeGenCUDA/device-use-host-var.cu
+++ b/clang/test/CodeGenCUDA/device-use-host-var.cu
@@ -2,6 +2,8 @@
 // RUN:   -fcuda-is-device -emit-llvm -o - -x hip %s | FileCheck %s
 // RUN: %clang_cc1 -std=c++14 -triple amdgcn-amd-amdhsa \
 // RUN:   -fcuda-is-device -emit-llvm -o - -x hip %s | FileCheck 
-check-prefix=NEG %s
+// RUN: %clang_cc1 -std=c++14 -triple nvptx64-nvidia-cuda  \
+// RUN:   -fcuda-is-device -emit-llvm -o - -x hip %s | FileCheck 
-check-prefix=NEG -implicit-check-not=external_ %s
 
 #include "Inputs/cuda.h"
 
@@ -104,3 +106,14 @@ void fun() {
   (void) b;
   (void) var_host_only;
 }
+
+extern __global__ void external_func();
+extern void* const external_dep[] = {
+  (void*)(external_func)
+};
+extern void* const external_arr[] = {};
+
+void* host_fun() {
+  (void) external_dep;
+  (void) external_arr;
+}

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [CUDA][HIP] Exclude external variables from constant promotion. (PR #73549)

2023-11-27 Thread Levon Ter-Grigoryan via cfe-commits

https://github.com/PatriosTheGreat created 
https://github.com/llvm/llvm-project/pull/73549

Promoting __constant__ to external variables includes them to PTX which then 
leads to nvlinker failure.
See changes at device-use-host-var test.
Befor this change those variables was included to PTX without definition.

>From a1a50db9bd14467ca4463ec05affc381ab0ea1aa Mon Sep 17 00:00:00 2001
From: Levon Ter-Grigoryan 
Date: Mon, 27 Nov 2023 18:09:22 +0100
Subject: [PATCH] [CUDA][HIP] Exclude external variables from constant
 promotion.

Promoting __constant__ to external variables includes them to PTX which then 
leads to nvlinker failure.
See changes at device-use-host-var test.
Befor this change those variables was included to PTX without definition.
---
 clang/lib/Sema/SemaCUDA.cpp   |  1 +
 clang/test/CodeGenCUDA/device-use-host-var.cu | 16 
 2 files changed, 17 insertions(+)

diff --git a/clang/lib/Sema/SemaCUDA.cpp b/clang/lib/Sema/SemaCUDA.cpp
index 318174f7be8fa95..f9d72e571e7b98b 100644
--- a/clang/lib/Sema/SemaCUDA.cpp
+++ b/clang/lib/Sema/SemaCUDA.cpp
@@ -783,6 +783,7 @@ void Sema::MaybeAddCUDAConstantAttr(VarDecl *VD) {
   (VD->isFileVarDecl() || VD->isStaticDataMember()) &&
   !IsDependentVar(VD) &&
   ((VD->isConstexpr() || VD->getType().isConstQualified()) &&
+   VD->getStorageClass() != SC_Extern &&
HasAllowedCUDADeviceStaticInitializer(*this, VD,
  CICK_DeviceOrConstant))) {
 VD->addAttr(CUDAConstantAttr::CreateImplicit(getASTContext()));
diff --git a/clang/test/CodeGenCUDA/device-use-host-var.cu 
b/clang/test/CodeGenCUDA/device-use-host-var.cu
index 64de57e41b4b9f5..807a485f4c14972 100644
--- a/clang/test/CodeGenCUDA/device-use-host-var.cu
+++ b/clang/test/CodeGenCUDA/device-use-host-var.cu
@@ -2,6 +2,8 @@
 // RUN:   -fcuda-is-device -emit-llvm -o - -x hip %s | FileCheck %s
 // RUN: %clang_cc1 -std=c++14 -triple amdgcn-amd-amdhsa \
 // RUN:   -fcuda-is-device -emit-llvm -o - -x hip %s | FileCheck 
-check-prefix=NEG %s
+// RUN: %clang_cc1 -std=c++14 -triple nvptx64-nvidia-cuda \
+// RUN:   -fcuda-is-device -emit-llvm -o - -x hip %s | FileCheck 
-check-prefix=NEG %s
 
 #include "Inputs/cuda.h"
 
@@ -104,3 +106,17 @@ void fun() {
   (void) b;
   (void) var_host_only;
 }
+
+// NEG-NOT: external_func
+extern __global__ void external_func();
+// NEG-NOT: @external_dep
+extern void* const external_dep[] = {
+  (void*)(external_func)
+};
+// NEG-NOT: @external_arr
+extern void* const external_arr[] = {};
+
+void* host_fun() {
+  (void) external_dep;
+  (void) external_arr;
+}

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [CUDA][HIP] Exclude external variables from constant promotion. (PR #73549)

2023-11-30 Thread Levon Ter-Grigoryan via cfe-commits


@@ -104,3 +106,17 @@ void fun() {
   (void) b;
   (void) var_host_only;
 }
+
+// NEG-NOT: external_func
+extern __global__ void external_func();
+// NEG-NOT: @external_dep
+extern void* const external_dep[] = {
+  (void*)(external_func)
+};
+// NEG-NOT: @external_arr

PatriosTheGreat wrote:

Not sure I got it correctly, but AFAIU in this test we are checking only the 
device code.
So with the current patch an external global variable should not be included to 
the device code (only to the host code) if it's not used in any device 
functions at the current compilation unit. If it's actually used 
Though if this variable is used at the device function than it should be 
manually marked as __constant__ variable. I can add this test case as well if 
it's needed.


https://github.com/llvm/llvm-project/pull/73549
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [CUDA][HIP] Exclude external variables from constant promotion. (PR #73549)

2023-11-30 Thread Levon Ter-Grigoryan via cfe-commits

https://github.com/PatriosTheGreat updated 
https://github.com/llvm/llvm-project/pull/73549

>From 0259038bcb4297a89c700ea2a21b80e7a22480db Mon Sep 17 00:00:00 2001
From: Levon Ter-Grigoryan 
Date: Mon, 27 Nov 2023 18:09:22 +0100
Subject: [PATCH] [CUDA][HIP] Exclude external variables from constant
 promotion.

Promoting __constant__ to external variables includes them to PTX which then 
leads to nvlinker failure.
See changes at device-use-host-var test.
Befor this change those variables was included to PTX without definition.
---
 clang/lib/Sema/SemaCUDA.cpp   |  1 +
 clang/test/CodeGenCUDA/device-use-host-var.cu | 13 +
 2 files changed, 14 insertions(+)

diff --git a/clang/lib/Sema/SemaCUDA.cpp b/clang/lib/Sema/SemaCUDA.cpp
index 318174f7be8fa95..f9d72e571e7b98b 100644
--- a/clang/lib/Sema/SemaCUDA.cpp
+++ b/clang/lib/Sema/SemaCUDA.cpp
@@ -783,6 +783,7 @@ void Sema::MaybeAddCUDAConstantAttr(VarDecl *VD) {
   (VD->isFileVarDecl() || VD->isStaticDataMember()) &&
   !IsDependentVar(VD) &&
   ((VD->isConstexpr() || VD->getType().isConstQualified()) &&
+   VD->getStorageClass() != SC_Extern &&
HasAllowedCUDADeviceStaticInitializer(*this, VD,
  CICK_DeviceOrConstant))) {
 VD->addAttr(CUDAConstantAttr::CreateImplicit(getASTContext()));
diff --git a/clang/test/CodeGenCUDA/device-use-host-var.cu 
b/clang/test/CodeGenCUDA/device-use-host-var.cu
index 64de57e41b4b9f5..65aac2b7eca891c 100644
--- a/clang/test/CodeGenCUDA/device-use-host-var.cu
+++ b/clang/test/CodeGenCUDA/device-use-host-var.cu
@@ -2,6 +2,8 @@
 // RUN:   -fcuda-is-device -emit-llvm -o - -x hip %s | FileCheck %s
 // RUN: %clang_cc1 -std=c++14 -triple amdgcn-amd-amdhsa \
 // RUN:   -fcuda-is-device -emit-llvm -o - -x hip %s | FileCheck 
-check-prefix=NEG %s
+// RUN: %clang_cc1 -std=c++14 -triple nvptx64-nvidia-cuda  \
+// RUN:   -fcuda-is-device -emit-llvm -o - -x hip %s | FileCheck 
-check-prefix=NEG -implicit-check-not=external_ %s
 
 #include "Inputs/cuda.h"
 
@@ -104,3 +106,14 @@ void fun() {
   (void) b;
   (void) var_host_only;
 }
+
+extern __global__ void external_func();
+extern void* const external_dep[] = {
+  (void*)(external_func)
+};
+extern void* const external_arr[] = {};
+
+void* host_fun() {
+  (void) external_dep;
+  (void) external_arr;
+}

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [CUDA][HIP] Exclude external variables from constant promotion. (PR #73549)

2023-11-30 Thread Levon Ter-Grigoryan via cfe-commits


@@ -104,3 +106,17 @@ void fun() {
   (void) b;
   (void) var_host_only;
 }
+
+// NEG-NOT: external_func
+extern __global__ void external_func();
+// NEG-NOT: @external_dep
+extern void* const external_dep[] = {
+  (void*)(external_func)
+};
+// NEG-NOT: @external_arr

PatriosTheGreat wrote:

Ah, sorry misunderstood original comment.
Changed test code to use implicit-check, thanks for the reference

https://github.com/llvm/llvm-project/pull/73549
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits