mirror of
https://github.com/clang-retro/llvm.git
synced 2026-11-28 21:29:24 -08: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>
41 lines
1.2 KiB
Plaintext
41 lines
1.2 KiB
Plaintext
// 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
|
|
|
|
// UNSUPPORTED: aarch64-unknown-linux-gnu
|
|
// UNSUPPORTED: x86_64-unknown-linux-gnu
|
|
// UNSUPPORTED: nvptx64-nvidia-cuda-LTO
|
|
// UNSUPPORTED: amdgcn-amd-amdhsa-LTO
|
|
// UNSUPPORTED: amdgpu-amd-amdhsa-LTO
|
|
// UNSUPPORTED: intelgpu
|
|
|
|
#include <stdio.h>
|
|
|
|
int main(int argc, char **argv) {
|
|
hipDeviceProp_t Prop = {};
|
|
hipError_t Err = hipGetDeviceProperties(&Prop, 0);
|
|
if (Err != hipSuccess) {
|
|
printf("hipGetDeviceProperties failed: %u\n", Err);
|
|
return 1;
|
|
}
|
|
|
|
printf("Device name: %s\n", Prop.name);
|
|
// CHECK: Device name:
|
|
printf("Total global memory: %zu\n", Prop.totalGlobalMem);
|
|
// CHECK: Total global memory:
|
|
printf("Multiprocessors: %i\n", Prop.multiProcessorCount);
|
|
// CHECK: Multiprocessors:
|
|
printf("Warp size: %i\n", Prop.warpSize);
|
|
// CHECK: Warp size:
|
|
|
|
if (!Prop.name[0] || !Prop.totalGlobalMem || !Prop.multiProcessorCount ||
|
|
!Prop.warpSize)
|
|
return 1;
|
|
|
|
printf("Device properties are populated.\n");
|
|
// CHECK: Device properties are populated.
|
|
}
|