mirror of
https://github.com/siemens-mobile-hacks/llvm-c166.git
synced 2026-11-25 21:45:57 +00:00
CUDA and HIP offloading currently assumes that the source language also implies the device backend: CUDA maps to NVPTX/CUDA and HIP maps to AMDGPU/HSA. That is too restrictive for the LLVM offload path, where the language frontend and the device backend can be separate choices. Using `-foffload-via-llvm` we can split the kernel language from backend assumptions. When enabled, the driver suppresses the vendor runtime/header paths, injects the LLVM-provided generic GPU device headers and language runtime headers, and links the LLVM CUDA/HIP runtime libraries from #211694 instead. It also provides tests for #211694 since they require the frontend to run. Assisted by GPT-5.5, checked and reviewed manually Co-authored-by: Johannes Doerfert <jdoerfert.llvm@gmail.com> Co-authored-by: Jonas Greifenhain <cadivus@daverkomp.de>
39 lines
1.1 KiB
Text
39 lines
1.1 KiB
Text
// clang-format off
|
|
// RUN: %clang++ %flags -foffload-via-llvm --offload-arch=native %s -o %t
|
|
// RUN: %t | %fcheck-generic
|
|
// RUN: %clang++ %flags -foffload-via-llvm --offload-arch=native %s -o %t -fopenmp
|
|
// RUN: %t | %fcheck-generic
|
|
// clang-format on
|
|
|
|
// REQUIRES: gpu
|
|
// UNSUPPORTED: nvptx64-nvidia-cuda-LTO
|
|
// UNSUPPORTED: amdgcn-amd-amdhsa-LTO
|
|
// UNSUPPORTED: amdgpu-amd-amdhsa-LTO
|
|
// UNSUPPORTED: intelgpu
|
|
|
|
#include <stdio.h>
|
|
|
|
__global__ void square(int *Dst, short Q, int *Src, short P) {
|
|
*Dst = (Src[0] + Src[1]) * (Q + P);
|
|
Src[0] = Q;
|
|
Src[1] = P;
|
|
}
|
|
|
|
int main(int argc, char **argv) {
|
|
int DevNo = 0;
|
|
int *Src, *Ptr;
|
|
cudaMalloc(&Ptr, 4);
|
|
cudaMalloc(&Src, 8);
|
|
|
|
int I = 7;
|
|
int HostSrc[2] = {-2, 8};
|
|
cudaMemcpy(Ptr, &I, sizeof(int), cudaMemcpyHostToDevice);
|
|
cudaMemcpy(Src, &HostSrc[0], 2 * sizeof(int), cudaMemcpyHostToDevice);
|
|
square<<<1, 1>>>(Ptr, 3, Src, 4);
|
|
cudaMemcpy(&I, Ptr, sizeof(int), cudaMemcpyDeviceToHost);
|
|
cudaMemcpy(&HostSrc[0], Src, 2 * sizeof(int), cudaMemcpyDeviceToHost);
|
|
printf("I: %i\n", I);
|
|
// CHECK: I: 42
|
|
printf("Src: %i, %i\n", HostSrc[0], HostSrc[1]);
|
|
// CHECK: Src: 3, 4
|
|
}
|