Files
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

77 lines
2.2 KiB
C

// RUN: %libomptarget-compile-run-and-check-generic
#include <omp.h>
#include <stdio.h>
#include <string.h>
int test_omp_device_uid(int device_num) {
const char *device_uid = omp_get_uid_from_device(device_num);
if (device_uid == NULL) {
printf("FAIL for device %d: omp_get_uid_from_device returned NULL\n",
device_num);
return 0;
}
int device_num_from_uid = omp_get_device_from_uid(device_uid);
if (device_num_from_uid != device_num) {
printf(
"FAIL for device %d: omp_get_device_from_uid returned %d (UID: %s)\n",
device_num, device_num_from_uid, device_uid);
return 0;
}
if (device_num == omp_get_initial_device())
return 1;
int success = 1;
// Note that the following code may be executed on the host if the host is the
// device
#pragma omp target map(tofrom : success) device(device_num)
{
int device_num = omp_get_device_num();
// omp_get_uid_from_device() in the device runtime is a dummy function
// returning NULL
const char *device_uid = omp_get_uid_from_device(device_num);
// omp_get_device_from_uid() in the device runtime is a dummy function
// returning omp_invalid_device.
int device_num_from_uid = omp_get_device_from_uid(device_uid);
// Depending on whether we're executing on the device or the host, we either
// got NULL as the device UID or the correct device UID. Consequently,
// omp_get_device_from_uid() either returned omp_invalid_device or the
// correct device number (aka omp_get_initial_device()).
if (device_uid ? device_num_from_uid != device_num
: device_num_from_uid != omp_invalid_device) {
printf("FAIL for device %d (target): omp_get_device_from_uid returned %d "
"(UID: %s)\n",
device_num, device_num_from_uid, device_uid);
success = 0;
}
}
return success;
}
int main() {
int num_devices = omp_get_num_devices();
int num_failed = 0;
// (also test initial device aka num_devices)
for (int i = 0; i < num_devices + 1; i++) {
if (!test_omp_device_uid(i)) {
printf("FAIL for device %d\n", i);
num_failed++;
}
}
if (num_failed) {
printf("FAIL\n");
return 1;
}
printf("PASS\n");
return 0;
}
// CHECK: PASS