2

Since version 6, clang has supported a __fp16 type. I would like to use it, but I need to support other compilers (both clang-based and non-clang-based) as well as older versions of clang, so I need a reliable way to detect support. Unfortunately, I don't see anything in clang's documentation about how to detect it (using __has_feature, __has_extension, etc.).

Since clang's version number macros are unreliable, the best solution I have right now is to use __has_warning("-Wpragma-pack") (the -Wpragma-pack warning was also added in clang 6). I'm hoping that there is a fp16 feature/extension/whatever I can check instead which just isn't documented where I'm looking, but obviously open to other ideas.

So, does anyone know of a better way to detect __fp16 support?

nemequ
  • 15,543
  • 38
  • 58
  • 1
    Although I couldn't find anything to really help you, an alternative could be `_Float16` which is defined in the C standard and works in GCC too (not sure about MSVC but probably works there too, and it also isn't supported for g++ unfortunately). – mediocrevegetable1 Feb 01 '21 at 06:25
  • 1
    Also, https://stackoverflow.com/questions/60626480/c-support-of-float16?noredirect=1&lq=1 a comment on this post says you can enable `__fp16` on GCC and G++ with `-mfp16-format`, though I tried it and it doesn't work for me (maybe I have an outdated version). – mediocrevegetable1 Feb 01 '21 at 06:36
  • Yep, I'm using _Float16 and __fp16 whenever available, and I also have a fairly portable implementation (based on https://gist.github.com/rygorous/2156668) in progress. I'm just trying to nail down the right conditions in the preprocessor. Those are all I have right now, but I also want to look into what some AI libraries provide; IIRC Tensorflow and NVidia have some support… just not sure if that will be usable for my project or not yet. – nemequ Feb 01 '21 at 06:49
  • Ah, I see, that makes sense. Unfortunately, I still have nothing to help regarding your specific question, but I'll try to keep looking. I checked the link, the structs seem pretty in-line with how floating points actually work, an interesting concept.r – mediocrevegetable1 Feb 01 '21 at 06:54

0 Answers0