Skip to content

safe-math: nvc/nvcc/clang still contract multiply-adds, and NvidiaCompiler drops all optimisation #3077

Open

Description

@ggorman

safe-math was defined (#1438, 2020) as "drop -ffast-math" (GCC: -fno-unsafe-math-optimizations; nvc:
drop -fast). Two consequences today:

  1. Contraction is unspecified. GCC C99 never contracts; GCC C++ did until dsl: Print double-precision FD weights to 20 digits #3074 (-ffp-contract=off);
    clang defaults to -ffp-contract=on; nvc++ fuses under -O2/-fast; nvcc defaults to --fmad=true.
    test_gradient_equivalence (fp64, safe-math) fails on OpenACC with -fast or -O2 (ratio 1.23) and on
    CUDA by default (1.24), and passes with -Mnofma / --fmad=false. On an RTX 3090 fp64 FMA is worth
    13-14% (OpenACC) and 31-39% (CUDA) of throughput, fp32 nothing, so a blanket "no contraction" is not free
    on GPU.
  2. NvidiaCompiler under safe-math appends nothing in place of -fast, so OpenACC safe-math builds are
    effectively unoptimised: 0.3-0.5 GPts/s vs 9-15 with -fast on the same kernels (3D acoustic, 3090).
    Question for maintainers: should safe-math promise "no contraction" on every backend (at the GPU fp64
    cost), or should contraction be a separate, documented per-compiler setting that tests needing exact
    cancellation opt into? Either way NvidiaCompiler should keep a safe optimisation level.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions