Skip to content

Add tests for evaluation of expressions in directive arguments #122

Open
Ryanpadrone wants to merge 3 commits intoOpenACCUserGroup:masterfrom
Ryanpadrone:exprEval
Open

Add tests for evaluation of expressions in directive arguments #122
Ryanpadrone wants to merge 3 commits intoOpenACCUserGroup:masterfrom
Ryanpadrone:exprEval

Conversation

@Ryanpadrone
Copy link
Copy Markdown

Feature Under Test

OpenACC 3.4 (Feb 2026), Section 2.1
Clarified user-visible behavior of evaluation of expressions in directive arguments.

This clarification states that expressions appearing in directive arguments (e.g., num_gangs(expr), if(expr), async(expr), array section bounds, etc.):
•May be evaluated in any order
•May be evaluated more than once
•May possibly not be evaluated at all (if the implementation determines they are not needed)
•Must not have user-visible behavior that depends on side effects from those evaluations
A conforming program must not rely on side effects (e.g., ++i global state updates) occurring during evaluation of directive argument expressions.

Files

•acc_expr_eval_directive_args.c
•acc_expr_eval_directive_args.cpp
•acc_expr_eval_directive_args.F90
Each file contains 3 tests

Test Design

T1–Pure Expression in Directive Arguments
uses nontrivial but side-effect-free expressions inside directive arguments:
•if((cond == 1) && ((n / 2) > 0))
•num_gangs(foo_pure(...))
•vector_length((n % 128) + 1) (C/C++)
•async(MOD(...)) (Fortran)
Purpose: Validates that directive arguments may contain arbitrary expressions and still produce correct program behavior.

T2-Elidable Expression in update ... if_present

Executes:
#pragma acc update device(a[0:size_maybe_elided(n)]) if_present
where a is intentionally not present on the device.

The section length expression calls a function with a side effect (size_maybe_elided), but the test:
•Does not assert how many times it is called
•Only checks that host data remains unchanged
•Ensures no runtime failure occurs
Purpose: Validates that directive argument expressions may be elided and that user-visible behavior remains correct.

T3–Side-Effecting Expressions in Directive Arguments

Uses side-effecting expressions inside directive arguments:
C/C++:

num_gangs(foo_pure(i++))
num_workers(bar_pure(i++))
async(((i + 1) % 3) + 1)

Fortran:

num_gangs(foo_pure(sidefx_inc(tmp)))
async(MOD(sidefx_inc(tmp + 2), 3) + 1)

The program does not rely on the final value of the side-effect variable. Only numeric correctness of c[i] = a[i] + b[i] is verified
Purpose: Confirms that correctness does not depend on evaluation order or count of side-effecting directive argument expressions.

Compilers:

•NVC 25.11 PASS
•GCC 15.2.0 PASS
•CCE 18.0.0 PASS

Notes:

When compiling with GCC, the C and C++ tests showed
warning: using ‘vector_length (32)’, ignoring runtime setting
This warning indicates that GCC'c OpenACC implementation may treat vector_length(...) as a compile-time or implementation-defined setting rather than honoring it dynamically at runtime.

Importantly:
•The test does not depend on the runtime scheduling behavior of vector_length
•The test only verifies numerical correctness of the kernel computation
•The program executes successfully and returns 0
So this warning does not indicate a failure of section 2.1 behavior and does not affect correctness.

@ajarmusch ajarmusch changed the title Add V&V tests for evaluation of expressions in directive arguments (OpenACC 3.4 §2.1) Add tests for evaluation of expressions in directive arguments Feb 26, 2026
@ajarmusch ajarmusch added the v3.4 label Feb 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants