Suppose I have
template <bool UsesFastMath> void foo(float* data, size_t length);
and I want to compile one instantiation with -ffast-math
(--use-fast-math
for nvcc), and the other instantiation without it.
This can be achieved by instantiating each of the variants in a separate translation unit, and compiling each of them with a different command-line - with and without the switch.
My question is whether it's possible to indicate to popular compilers (*) to apply or not apply -ffast-math
for individual functions - so that I'll be able to have my instantiations in the same translation unit.
Notes:
- If the answer is "no", bonus points for explaining why not.
- This is not the same questions as this one, which is about turning fast-math on and off at runtime. I'm much more modest...
(*) by popular compilers I mean any of: gcc, clang, msvc icc, nvcc (for GPU kernel code) about which you have that information.
nvcc
: No. Compilation flags are applied on a per-compilation-unit basis. No equivalent function attributes exist to apply this on a per-function basis. If you want different flags applied, stick the code into different compilation units (you can include the source code from the same file, if you desire). For tight local control, various CUDA device intrinsics (or worst case, some inline assembly) can provide much of what you need. – Kaufman