Skip to content

feat[cartesian]: Introduce default compiler flags#2520

Merged
FlorianDeconinck merged 4 commits intoGridTools:mainfrom
FlorianDeconinck:feature/default_compiler_flags
Mar 11, 2026
Merged

feat[cartesian]: Introduce default compiler flags#2520
FlorianDeconinck merged 4 commits intoGridTools:mainfrom
FlorianDeconinck:feature/default_compiler_flags

Conversation

@FlorianDeconinck
Copy link
Contributor

Description

Continuing an ongoing effort to support a wider range of in-use compilers (clang/icx) we introduce a system to detect the C++ compiler and adapt the openmp and compilation flags loaded by default.

We use setuptools to detect the compiler which is future-proofed (3.14) as well as a solution for older python (3.8+).

In order to get a closer match with default Fortran numerics at -O0 we drop all FMA at this optimization level.

Configuration still listens to the GT4PY_* environment variable in priority.

Requirements

  • All fixes and/or new features come with corresponding tests.
  • Important design decisions have been documented in the appropriate ADR inside the docs/development/ADRs/ folder.

If this PR contains code authored by new contributors please make sure:

  • The PR contains an updated version of the AUTHORS.md file adding the names of all the new contributors.

Copy link
Contributor

@romanc romanc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One small suggestion inline. Looks good otherwise.

I'll update the pending ADR on GT4PY_CARTESIAN_ENABLE_OPENMP in PR #2512 to include automatic compiler detection.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Writing the ADR, I came across this default. I think we should we change the default to False for apple-clang now that we can detect compilers because we won't compile with the necessary OpenMP flags.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch - done.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new dataclass member still needs to be assigned as default, or am I missing something here?

_enable_open_mp = os.environ.get("GT4PY_CARTESIAN_ENABLE_OPENMP", _compiler_infos.enable_openmp)

Freeze dataclass and centralize defaults
@FlorianDeconinck FlorianDeconinck requested a review from romanc March 11, 2026 11:02
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new dataclass member still needs to be assigned as default, or am I missing something here?

_enable_open_mp = os.environ.get("GT4PY_CARTESIAN_ENABLE_OPENMP", _compiler_infos.enable_openmp)

@FlorianDeconinck
Copy link
Contributor Author

You are not missing something, I quite literally did not write half the code -_-

@FlorianDeconinck FlorianDeconinck requested a review from romanc March 11, 2026 12:56
Copy link
Contributor

@romanc romanc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good now. The only question that popped up is if we should notify the user which compiler we detected (and how to possibly set another one, e.g. by setting the CXX / CC env variables).

@FlorianDeconinck
Copy link
Contributor Author

Looking good now. The only question that popped up is if we should notify the user which compiler we detected (and how to possibly set another one, e.g. by setting the CXX / CC env variables).

I thought about it - but we are already pretty verbose with NDSL and I was careful not to bury more verbosity... Arguably, it would be good to have a way to dump the entire "config" of GT4Py, including defaults flags

@romanc
Copy link
Contributor

romanc commented Mar 11, 2026

Looking good now. The only question that popped up is if we should notify the user which compiler we detected (and how to possibly set another one, e.g. by setting the CXX / CC env variables).

I thought about it - but we are already pretty verbose with NDSL and I was careful not to bury more verbosity... Arguably, it would be good to have a way to dump the entire "config" of GT4Py, including defaults flags

Sounds good - I agree, we can pick this up later in a bigger context.

@FlorianDeconinck FlorianDeconinck merged commit 194871d into GridTools:main Mar 11, 2026
19 checks passed
romanc added a commit that referenced this pull request Mar 12, 2026
…onfiguration out of `config.py` (#2524)

## Description

We introduced a bad behavior by forcing FMA deactivation in `-O0` in
#2520 by passing a flag to `nvcc` that isn't readable.

While fixing the above we also moved the entire configuration of GPU
device code & execution to the `compiler.py` flag to centralize and
clean up the central `config.py`.

Everything remains functionally the same: environment variable have
precedence on defaults and the entire GPU stack is setup out of
CUDA_ROOT & `cupy` device.

E.g.:
- Split environment variables for GPU source code compile flags off CXX
flags
- Move GPU compiler configuration out in `compiler.py`
- Force FMA (`-fmad=false`) off for `-O0`

:warning: I didn't had a unit test because the real system test would
require a "fresh" load of gt4py with a different env (`-O0` in
`GT4PY_COMPILE_OPT_LEVEL`) - which is beyond the scope of `pytest`

---------

Co-authored-by: Roman Cattaneo <romanc@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants