Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

std::floating_point concept in CUDA for all IEE754 types

I would like to know if CUDA provides a concept similar to std::floating_point but including all IEE754 types including e.g. __half. I provide below a sample code that test that __half template functions do not compile with std::floating_point.

#include <concepts>
#include <iostream>
#include <cuda_fp16.h>

template<std::floating_point T>
__host__ __device__ bool use_floating_point() {
    return True;
}

int main() {
  std::cout << "Is float a floating-point type?" << use_floating_point<float>() << '\n';
  std::cout << "Is __half a floating-point type?" << use_floating_point<__half>() << '\n'; // Compilation error
  return 0;
}

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I think what you are looking for is std::is_iec559, because is_floating_point covers only a limited set of types, while is_iec559, to my understanding is supposed to match any type that implements IEE754.

However, as @Artyer points out in a comment. std::is_iec559<__half> is false.

If you merely need std::is_flaoting_point plus __half, you can write your custom concept

template <typename T>
concept floating_or_half = std::floating_point<T> || std::same_as<T,__half>;


template<floating_or_half T>
bool use_floating_point() {
    return true;
}

Live Demo

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading