Observed issues › catalog/nvhpc-c-function-pointer-kernel-missing
nvc/nvfortran -mp=gpu: compile succeeds but the kernel is missing at run time ("Failed to find device function") for function pointers, static locals, VLAs, long double, type-bound calls
Legality: independently confirmed. One independent reading disputed it; 2 adjudicating readings that weighed both find the program legal and the result required: Both readings misapply the indirect clause. An indirect device invocation is defined as a call through a pointer that refers to the host version of the procedure. Here f is assigned inside the target region from tw and th, which are in declare target, so f refers to the device versions and the call is an ordinary device call. The indirect clause rules do not apply. No restriction is violated, and base-language semantics give the expected result. How this is checked
Affected variants
| Compiler | MI300A gfx942 unified memory (XNACK 1) | MI300A gfx942 copy (XNACK 0) | MI250X gfx90a copy (XNACK 0) | MI300X gfx942 copy (XNACK 0) | MI350X gfx950 copy (XNACK 0) | A100 sm_80 separate memory | A100 sm_80 managed memory |
|---|---|---|---|---|---|---|---|
| AFAR 24.3.0 | correct | correct | unknown not run | correct | correct | n/a | n/a |
| CCE 19.0.0 | correct | correct | unknown not run | unknown not run | unknown not run | n/a | n/a |
| CCE 20.0.2 | correct | correct | unknown not run | unknown not run | unknown not run | n/a | n/a |
| CCE 21.0.3 | correct | correct | unknown not run | unknown not run | unknown not run | n/a | n/a |
| CCE 21.0.4 | correct | correct | unknown not run | unknown not run | unknown not run | n/a | n/a |
| NVHPC 25.11 | n/a | n/a | n/a | n/a | n/a | behaves incorrectly | behaves incorrectly |
| NVHPC 26.9 | n/a | n/a | n/a | n/a | n/a | behaves incorrectly | behaves incorrectly |
| GCC 16.2.0 | correct | correct | correct | correct | correct | correct | n/a |
"behaves incorrectly" / "not supported": this issue, confirmed in up to four environments (another build directory, another node, a repeat). "fails another way": a different failure, not counted as this issue. "unknown": not run there, or the runs disagree.
Messages
| Result | Compiler and GPU | Message |
|---|---|---|
| behaves incorrectly | NVHPC 25.11, A100 separate NVHPC 25.11, A100 managed | showAccelerator Fatal Error: Failed to find device function 'nvkernel_main_F1L19_2'! File was compiled with: -gpu=cc80 Rebuild this file with -gpu=cc80 to use NVIDIA Tesla GPU 0 File: <dir>/nvhpc-c-function-pointer-kernel-missing.c Function: main:12 Line: 19 |
| behaves incorrectly | NVHPC 26.9, A100 separate NVHPC 26.9, A100 managed | showAccelerator Fatal Error: Failed to find device function 'nvkernel_main_F1L22_2'! File was compiled with: -gpu=cc80 Rebuild this file with -gpu=cc80 to use NVIDIA Tesla GPU 0 File: <dir>/nvhpc-c-function-pointer-kernel-missing.c Function: main:12 Line: 22 |
Reproduce
NVHPC 25.11, A100 separate
export LD_LIBRARY_PATH=$NVHPC_25_11/compilers/lib nvc -mp=gpu -gpu=cc80 -gpu=mem:separate -O2 repro.c -o repro OMP_TARGET_OFFLOAD=mandatory ./repro
NVHPC 26.9, A100 separate
export LD_LIBRARY_PATH=$NVHPC_26_9/compilers/lib nvc -mp=gpu -gpu=cc80 -gpu=mem:separate -O2 repro.c -o repro OMP_TARGET_OFFLOAD=mandatory ./repro
AFAR 24.3.0, MI300A unified (runs correctly)
$AFAR/bin/amdclang -fopenmp --offload-arch=gfx942 -fopenmp-version=52 -fopenmp-version=52 -O2 repro.c -o repro HSA_XNACK=1 OMP_TARGET_OFFLOAD=mandatory ./repro
Program (61 lines)
// # Draft finding: omp52-c-w-function-pointer on nvhpc
//
// - compiler: nvhpc
// - toolchain: nvhpc; arch: sm_80; machine: wingtip; memory mode: copy; opt: -O2
// - program: catalog omp52-c-w-function-pointer (c, version 52, sha256 b55bf877e3962528)
// - expected: check=pass (trusted; elision + model)
// - actual: run_error (exit_status: 1; without mandatory: exit_status: 1) [the confirmer's class run_error; the matrix's class of the same run is wrong_answer: a run that fails]
// - observed: the run ends with "Accelerator Fatal Error: Failed to find device function 'nvkernel_main_F1L31_2'! File was compiled with: -gpu=cc80" (NVHPC 25.11 and 26.9, both memory modes): the compile succeeds without generating the target region's kernel; split: the static local, VLA and long double forms are findings of their own
// - verdict: compiler_bug by rule R20-runtime-bug: a legal program fails at run time, deterministically, against an expected value from two or more independent sources with an executed witness, and another toolchain, mode, arch or the elision gives the expected value
// - reason: expected trusted check=pass (elision + model): stored main verdict: elision + model agree; witnesses: afar/gfx942/copy, cce19/gfx942/copy, cce20/gfx942/copy, cce21/gfx942/copy, elision
// - citations: RUL-DERIVED-NEEDS-EXECUTION (rulings.md); RUL-WITNESS-PER-MODE (rulings.md); RUL-SAME-COMPILER-RUNS (rulings.md); RUL-PRESENCE-WITNESS (rulings.md); RUL-METAMORPHIC-OTHER-FAMILY (rulings.md)
// - legality: legal: offload.engine.prerun.check accepts it (rerun: offload.engine.rules with the
// race rule and the restriction checks, and the AFAR clang front end, not under test here); no
// compiler under test, gfortran or gcc is a legality witness
// - witnesses: afar/gfx942/copy, cce19/gfx942/copy, cce20/gfx942/copy, cce21/gfx942/copy, elision
// - withdrawn: none
//
// Generated by compliance.widen (OpenMP 5.2, C11; catalog widening). Do not edit.
// id: omp52-c-w-function-pointer
// primary atom: base.device.function_pointer
// atoms: base.device.function_pointer
// legal: yes
// observable: yes
// ran_on_host: inside the target region of interest
// evidence: construct
// needs: none
// std: c11
// feature: a pointer to a declare target function taken and called in device code
// spec: OpenMP 5.2 §13.8, p.287: a program may rely on a function address in a target region for assignments, comparisons to zero and indirect calls
#include <stdio.h>
#include <stdbool.h>
#include <omp.h>
enum { n = 64 };
#pragma omp declare target
int tw(int x) { return 2 * x + 1; }
int th(int x) { return 3 * x; }
#pragma omp end declare target
int main(void) {
int a[n], b[n], ref[n];
int host_flag = 1;
for (int i = 0; i < n; i++) {
a[i] = i + 1;
b[i] = 0;
ref[i] = (i % 2) ? 2 * (i + 1) + 1 : 3 * (i + 1);
}
#pragma omp target teams distribute parallel for map(to: a) map(from: b) map(tofrom: \
host_flag)
for (int i = 0; i < n; i++) {
int (*f)(int) = (i % 2) ? tw : th;
b[i] = f(a[i]);
if (i == 0) host_flag = omp_is_initial_device();
}
bool ok = true;
for (int i = 0; i < n; i++)
ok = ok && (b[i] == ref[i]);
printf("RESULT ran_on_host=%d check=%s\n", host_flag, ok ? "pass" : "fail");
return 0;
}
Something to add? Dispute its legality · Report it fixed in a newer release · Report a mistake on this page
Expected and observed
Expected
check=pass
Observed where it behaves incorrectly
Accelerator Fatal Error: Failed to find device function 'nvkernel_main_F1L19_2'! File was compiled with: -gpu=cc80 Rebuild this file with -gpu=cc80 to use NVIDIA Tesla GPU 0 File: <dir>/nvhpc-c-function-pointer-kernel-missing.c Function: main:12 Line: 19
What the specification requires
The specification text this program relies on and the compiler is expected to support.
OpenMP 5.2 §13.8 p.287
Evidence
Same compiler, one change
- the two functions called directly instead of through a function pointer: AFAR 24.3.0: correct; CCE 19.0.0: correct; CCE 20.0.2: correct; CCE 21.0.3: correct; CCE 21.0.4: correct; NVHPC 25.11: correct; NVHPC 26.9: correct
Control program
#include <stdio.h> #include <stdbool.h> #include <omp.h> enum { n = 64 }; #pragma omp declare target int tw(int x) { return 2 * x + 1; } int th(int x) { return 3 * x; } #pragma omp end declare target int main(void) { int a[n], b[n], ref[n]; int host_flag = 1; for (int i = 0; i < n; i++) { a[i] = i + 1; b[i] = 0; ref[i] = (i % 2) ? 2 * (i + 1) + 1 : 3 * (i + 1); } #pragma omp target teams distribute parallel for map(to: a) map(from: b) map(tofrom: \ host_flag) for (int i = 0; i < n; i++) { b[i] = (i % 2) ? tw(a[i]) : th(a[i]); if (i == 0) host_flag = omp_is_initial_device(); } bool ok = true; for (int i = 0; i < n; i++) ok = ok && (b[i] == ref[i]); printf("RESULT ran_on_host=%d check=%s\n", host_flag, ok ? "pass" : "fail"); return 0; }
Other compilers run it correctly
AFAR 24.3.0, CCE 19.0.0, CCE 20.0.2, CCE 21.0.3, CCE 21.0.4, GCC 16.2.0