llvm-c166/offload/test/offloading/HIP/device_api.hip
Sophia Herrmann 49892f2014
[Offload] Add GetErrorName and GetErrorString to LLVMOffloadKernel (#212887)
Continuing the work to cover cuda/hip runtime in LLVMOffloadKernel, this
PR introduces the `GetErrorName` and `GetErrorString` functions for
pretty printing LLVMOffload errors, in a separate `LanguageUtils.cpp`

Additionally moves out helper functions ` convertResult` and
`getQueueFromStream` into the utils file too.

Assisted by GPT-5.5, checked and reviewed manually
2026-08-14 09:13:23 -07:00

45 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
// 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) {
int Count = 0;
if (hipGetDeviceCount(&Count) != hipSuccess)
return 1;
printf("device count: %d\n", Count);
// CHECK: device count: {{[1-9][0-9]*}}
int Device = -1;
if (hipGetDevice(&Device) != hipSuccess)
return 1;
printf("device: %d\n", Device);
// CHECK: device: {{[0-9]+}}
if (hipSetDevice(Device) != hipSuccess)
return 1;
int After = -1;
if (hipGetDevice(&After) != hipSuccess)
return 1;
printf("device after set: %d\n", After);
// CHECK: device after set: {{[0-9]+}}
hipError_t Err = hipSetDevice(-1);
printf("set invalid device: %u\n", Err);
// CHECK: set invalid device: 2
}