Skip to content
This repository has been archived by the owner on Mar 21, 2024. It is now read-only.

add a float16_t data type for half-float support #91

Closed
jaredhoberock opened this issue May 7, 2012 · 2 comments
Closed

add a float16_t data type for half-float support #91

jaredhoberock opened this issue May 7, 2012 · 2 comments
Labels
thrust type: enhancement New feature or request.

Comments

@jaredhoberock
Copy link
Contributor

The half-float [1] type would interoperate with standard 32-bit and 64-bit floats. Also, to avoid redundant conversions the arithmetic operators should yield a float32_t result. This behavior is consistent with the use of half-floats as a compressed storage format.

This enhancement would likely depend on issue NVIDIA/libcudacxx#216 .

class float16_t
{
unsigned short s;

public:

// constructors
host device
float16_t()
: s(float32_t()) {}

host device
float16_t(const float32_t& f)
: s(__float2half_rn(f)) {}

// arithmetic
host device
float32_t operator+(const float16_t& f) const
{
// note: return a float
return static_cast<float32_t>(*this) + static_cast<float32_t>(f);
}

// cast to float
host device
operator float32_t(void) const
{
return __half2float(s);
}
};

[1] http://en.wikipedia.org/wiki/Half_precision_floating-point_format

Forwarded from http://code.google.com/p/thrust/issues/detail?id=259

@marcinz
Copy link

marcinz commented Oct 7, 2020

Just a note, I was looking for complex<__half> support today. I guess this would be a logical continuation of adding float16_t.

@jrhemstad
Copy link
Collaborator

We will be adding extended floating point types to libcu++ in the near future. NVIDIA/cccl#1011

@jrhemstad jrhemstad closed this as not planned Won't fix, can't repro, duplicate, stale Mar 6, 2023
@github-project-automation github-project-automation bot moved this to Done in CCCL Mar 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
thrust type: enhancement New feature or request.
Projects
Archived in project
Development

No branches or pull requests

3 participants