Skip to content

Commit 5427de1

Browse files
sbryngelsonclaude
andcommitted
Fix Fypp macro syntax and precheck coverage claims
- GPU macros use $: prefix (inline), not @: — matches all 400+ usages in src/ - GPU_PARALLEL, GPU_DATA, GPU_HOST_DATA are block macros using #:call/#:endcall - Add block macro usage example - Fix GPU_ROUTINE args: parallelism='[seq]', not function_name= - Split forbidden patterns into precheck-enforced vs convention-enforced (goto, COMMON, save, stop are not checked by precheck.sh) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 20da91f commit 5427de1

File tree

2 files changed

+34
-16
lines changed

2 files changed

+34
-16
lines changed

.claude/rules/fortran-conventions.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,15 @@ Every Fortran module follows this pattern:
2222
- Constants: descriptive names, not ALL_CAPS
2323

2424
## Forbidden Patterns
25-
These are caught by `./mfc.sh precheck` (source lint step 4/5):
25+
26+
Caught by `./mfc.sh precheck` (source lint step 4/5):
2627
- `dsqrt`, `dexp`, `dlog`, `dble`, `dabs` → use `sqrt`, `exp`, `log`, `real(..., wp)`
2728
- `real(8)`, `real(4)` → use `wp` or `stp` kind parameters
29+
- Raw `!$acc` or `!$omp` directives → use Fypp GPU_* macros from `parallel_macros.fpp`
30+
31+
Enforced by convention/code review (not automated):
2832
- `goto`, `COMMON` blocks, global `save` variables
2933
- `stop`, `error stop` → use `call s_mpi_abort()`
30-
- Raw `!$acc` or `!$omp` directives → use Fypp GPU_* macros from `parallel_macros.fpp`
3134

3235
## Precision Types
3336
- `wp` (working precision): used for computation. Double by default.

.claude/rules/gpu-and-mpi.md

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,36 @@ compiles to either OpenACC or OpenMP target offload depending on the build flag:
2222
- `shared_parallel_macros.fpp` — Shared helpers (collapse, private, reduction generators)
2323

2424
### Key GPU Macros (always use the `GPU_*` prefix)
25-
- `@:GPU_PARALLEL_LOOP(collapse=N, private=[...], reduction=[...], reductionOp='+')`
25+
26+
Inline macros (use `$:` prefix):
27+
- `$:GPU_PARALLEL_LOOP(collapse=N, private=[...], reduction=[...], reductionOp='+')`
2628
Parallel loop over GPU threads. Most common GPU macro.
27-
- `@:END_GPU_PARALLEL_LOOP()` — Required closing for GPU_PARALLEL_LOOP.
28-
- `@:GPU_PARALLEL(code, ...)` — GPU parallel region (wraps code block).
29-
- `@:GPU_LOOP(collapse=N, ...)` — Inner loop within a GPU parallel region.
30-
- `@:GPU_DATA(code, copy=..., create=..., ...)` — Scoped data region.
31-
- `@:GPU_ENTER_DATA(create=[...])` — Allocate device memory (unscoped).
32-
- `@:GPU_EXIT_DATA(delete=[...])` — Free device memory.
33-
- `@:GPU_UPDATE(host=[...])` — Copy device → host (before MPI send).
34-
- `@:GPU_UPDATE(device=[...])` — Copy host → device (after MPI receive).
35-
- `@:GPU_ROUTINE(function_name=..., nohost=True/False)` — Mark routine for device.
36-
- `@:GPU_DECLARE(copyin=[...], link=[...])` — Declare device-resident data.
37-
- `@:GPU_ATOMIC(atomic='update')` — Atomic operation on device.
38-
- `@:GPU_WAIT()` — Synchronization barrier.
39-
- `@:GPU_HOST_DATA(code, use_device_addr=[...])` — Host code with device pointers.
29+
- `$:END_GPU_PARALLEL_LOOP()` — Required closing for GPU_PARALLEL_LOOP.
30+
- `$:GPU_LOOP(collapse=N, ...)` — Inner loop within a GPU parallel region.
31+
- `$:GPU_ENTER_DATA(create=[...])` — Allocate device memory (unscoped).
32+
- `$:GPU_EXIT_DATA(delete=[...])` — Free device memory.
33+
- `$:GPU_UPDATE(host=[...])` — Copy device → host (before MPI send).
34+
- `$:GPU_UPDATE(device=[...])` — Copy host → device (after MPI receive).
35+
- `$:GPU_ROUTINE(parallelism='[seq]')` — Mark routine for device compilation.
36+
- `$:GPU_DECLARE(create=[...])` — Declare device-resident data.
37+
- `$:GPU_ATOMIC(atomic='update')` — Atomic operation on device.
38+
- `$:GPU_WAIT()` — Synchronization barrier.
39+
40+
Block macros (use `#:call`/`#:endcall`):
41+
- `GPU_PARALLEL(...)` — GPU parallel region wrapping a code block.
42+
- `GPU_DATA(copy=..., create=..., ...)` — Scoped data region.
43+
- `GPU_HOST_DATA(use_device_addr=[...])` — Host code with device pointers.
44+
45+
Block macro usage:
46+
```
47+
#:call GPU_PARALLEL(copyin='[var1]', copyout='[var2]')
48+
$:GPU_LOOP(collapse=N)
49+
do k = 0, n; do j = 0, m
50+
! loop body
51+
end do; end do
52+
$:END_GPU_LOOP()
53+
#:endcall GPU_PARALLEL
54+
```
4055

4156
NEVER write raw `!$acc` or `!$omp` directives. Always use `GPU_*` Fypp macros.
4257
The precheck source lint will catch raw directives and fail.

0 commit comments

Comments
 (0)