[clang] [llvm] [Offload][CUDA] Allow CUDA kernels to use LLVM/Offload (PR #94549)

Artem Belevich via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 7 15:13:36 PDT 2024


================
@@ -0,0 +1,31 @@
+/*===------ LLVM/Offload helpers for kernel languages (CUDA/HIP) -*- c++ -*-===
+ *
+ * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+ * See https://llvm.org/LICENSE.txt for license information.
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+ *
+ *===-----------------------------------------------------------------------===
+ */
+
+#include <stdlib.h>
+
+#define __host__ __attribute__((host))
+#define __device__ __attribute__((device))
+#define __global__ __attribute__((global))
+#define __shared__ __attribute__((shared))
+#define __constant__ __attribute__((constant))
+#define __managed__ __attribute__((managed))
+
+extern "C" {
+
+typedef struct dim3 {
+  dim3() {}
+  dim3(unsigned x) : x(x) {}
+  unsigned x = 0, y = 0, z = 0;
+} dim3;
+
+// TODO: For some reason the CUDA device compilation requires this declaration
+// to be present but it should not.
----------------
Artem-B wrote:

It's not clear what "it should not" refers to. Do you mean that CUDA compilation should not require this declaration? Or that the declaration should not be present, ever?

The thing is that we need the correct signature for the function. It's easy enough to construct manually, when it only uses built-in types, but in case of more complicated types, especially those that are provided by CUDA headers, we can not do it by ourselves. So, we do need to rely on the front end to give it to us.


https://github.com/llvm/llvm-project/pull/94549


More information about the llvm-commits mailing list