alpaka: Some `alpaka::math::MathStdLib` functions trigger `[-Werror,-Wdouble-promotion]` when not called with `double`

Using alpaka::math::MathStdLib functions sin and cos with an aruments of a different precision than float (e.g. float), and probably other triggers the following clang (Main/14) warning:

~alpaka/include/alpaka/math/sin/Traits.hpp:37:32:
error: implicit conversion increases floating-point precision: 'const float' to 'double' [-Werror,-Wdouble-promotion]
                    return sin(arg);
                           ~~~ ^~~

This is because, e.g., sin is not overloaded for different precisions. For float sinf should be used. (sinl for long double although this may not be supported by alpaka anyway.)

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 28 (28 by maintainers)

Most upvoted comments

If you have your own types, outside of alpaka, why would you want to use alpaka::math:: on them? Would you not have your own sqrt in your namespace and call that via sqrt(varOfMyType) (or by qualified name)?

Templates. You might want to write an alpaka device side function that you can call on float, double, MyBigNumber, MyComplex, __half or bfloat16.

I found it myself now. I thought you where talking about the implementations XXXStdLib implementations, to which my comment before applied. You seem to be referring to the ADL fallback for types other than the ones handled by the backends. So for example if you implement your own complex number:

MyComplex<float> c;
alpaka::math::sqrt(acc, c);

You can use the alpaka functions and they will try to find an implementation of sqrt in the namespace of MyComplex via ADL. If you end up in this fallback, then you seem to not implement the ConceptMathXXXs.