Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Identify and list features of existing extended floating point wrapper types #1451

Closed
Tracked by #1011 ...
jrhemstad opened this issue Feb 28, 2024 · 6 comments
Closed
Tracked by #1011 ...
Assignees

Comments

@jrhemstad
Copy link
Collaborator

jrhemstad commented Feb 28, 2024

@cliffburdick said it best:

CUDA does not have standardized classes/operators available on both host and device to support these operations, so we define it here.

As it happens, there appears to be a lot of projects and people who feel the same:

Things to look into:

  • RAPIDS?
@weinbe2
Copy link

weinbe2 commented Feb 29, 2024

Kokkos has Kokkos::Experimental::half_t and Kokkos::Experimental::bhalf_t, where it'll properly wrap the data types if a given target supports it... and otherwise it's a thin wrapper around float.

It has a few levels of abstraction (as Kokkos does), but the core abstract implementation is here: https://github.com/kokkos/kokkos/blob/master/core/src/impl/Kokkos_Half_FloatingPointWrapper.hpp ; and, as an example, the way it'll picks a proper type for CUDA if a given version/arch supports it is here: https://github.com/kokkos/kokkos/blob/master/core/src/Cuda/Kokkos_Cuda_Half_Impl_Type.hpp

@achirkin
Copy link

achirkin commented Mar 1, 2024

In rapidsai/raft ANN benchmarks, we don't have a wrapper; instead, we have a uint16_t stub for CPU-only builds. Also across raft, the lack of <type_traits> support (i.e. something like std::is_floating_point) has been an annoying issue, which still prevents parts of raft from supporting half.

@jrhemstad
Copy link
Collaborator Author

In rapidsai/raft ANN benchmarks, we don't have a wrapper; instead, we have a uint16_t stub for CPU-only builds. Also across raft, the lack of <type_traits> support (i.e. something like std::is_floating_point) has been an annoying issue, which still prevents parts of raft from supporting half.

Thanks @achirkin, this is really helpful feedback. We've heard a lot of similar things, and so we're working on figuring out how to address all of these problems and more :)

@miscco
Copy link
Collaborator

miscco commented Mar 5, 2024

I bricked my workstation for a few hours so here is a comparison. I tried to be diligent, but it is hard to find every function:

half

API Kokkos MatX CUB pytorch Eigen cutlass
cast_to_half ✔️ ✔️ ✔️ ✔️ ✔️
cast_from_half ✔️ ✔️ ✔️ ✔️ ✔️ ✔️
conversion to float ✔️ ✔️ ✔️ ✔️ ✔️ ✔️
int constructor ✔️ ✔️ ✔️ ✔️ ✔️ ✔️
converting constructor ✔️ ✔️ ✔️ ✔️ ✔️ ✔️
converting assignment ✔️ ✔️
--- --- --- --- --- --- ---
operator+= half ✔️ ✔️ ✔️ ✔️ ✔️ ✔️
operator+= float ✔️ ✔️ ✔️
operator-= half ✔️ ✔️ ✔️ ✔️ ✔️ ✔️
operator-= float ✔️ ✔️ ✔️
operator*= half ✔️ ✔️ ✔️ ✔️ ✔️ ✔️
operator*= float ✔️ ✔️ ✔️
operator/= half ✔️ ✔️ ✔️ ✔️ ✔️ ✔️
operator/= float ✔️ ✔️ ✔️
operator+ half, half ✔️ ✔️ ✔️ ✔️ ✔️ ✔️
operator+ T, half ✔️ ✔️ ✔️
operator- half, half ✔️ ✔️ ✔️ ✔️ ✔️ ✔️
operator- T, half ✔️ ✔️ ✔️
operator* half, half ✔️ ✔️ ✔️ ✔️ ✔️ ✔️
operator* T, half ✔️ ✔️ ✔️
operator/ half, half ✔️ ✔️ ✔️ ✔️ ✔️ ✔️
operator/ T, half ✔️ ✔️ ✔️
unary+ ✔️
unary- ✔️ ✔️
--- --- --- --- --- --- ---
operator== half ✔️ ✔️ ✔️ ✔️ ✔️
operator== float ✔️
operator!= half ✔️ ✔️ ✔️ ✔️ ✔️
operator!= float ✔️
operator< half ✔️ ✔️ ✔️ ✔️ ✔️
operator< float ✔️
operator> half ✔️ ✔️ ✔️ ✔️ ✔️
operator> float ✔️
operator<= half ✔️ ✔️ ✔️ ✔️ ✔️
operator<= float ✔️
operator>= half ✔️ ✔️ ✔️ ✔️ ✔️
operator>= float ✔️
--- --- --- --- --- --- ---
operatorOR ✔️
operator&& ✔️
operator++ ✔️ ✔️ ✔️ ✔️ ✔️
operator++(int) ✔️ ✔️ ✔️ ✔️ ✔️
operator-- ✔️ ✔️ ✔️
operator--(int) ✔️ ✔️ ✔️
--- --- --- --- --- --- ---
abs ✔️ ✔️ ✔️
fmod ✔️ ✔️
fmax ✔️
fmin ✔️
fdim ✔️
exp ✔️ ✔️ ✔️
exp2 ✔️
expm1 ✔️ ✔️
log ✔️ ✔️ ✔️
log1p ✔️ ✔️
log2 ✔️ ✔️ ✔️
log10 ✔️ ✔️ ✔️
pow ✔️ ✔️ ✔️
sqrt ✔️ ✔️ ✔️ ✔️
cbrt ✔️
hypot ✔️
erf ✔️
erfc ✔️
tgamma ✔️
lgamma ✔️
signbit ✔️
fpclassify ✔️
copysign ✔️
isinf ✔️ ✔️ ✔️ ✔️
isnan ✔️ ✔️ ✔️
isfinite ✔️ ✔️ ✔️
isnormal ✔️
ceil ✔️ ✔️ ✔️
floor ✔️ ✔️ ✔️
round ✔️ ✔️ ✔️
trunc ✔️
rint ✔️
sin ✔️ ✔️ ✔️
cos ✔️ ✔️ ✔️
tan ✔️ ✔️ ✔️
asin ✔️ ✔️ ✔️
acos ✔️ ✔️ ✔️
atan ✔️ ✔️ ✔️
atan2 ✔️ ✔️ ✔️
sinh ✔️ ✔️
cosh ✔️ ✔️
tanh ✔️ ✔️ ✔️
asinh ✔️ ✔️
acosh ✔️ ✔️
atanh ✔️ ✔️ ✔️
numeric_limits ✔️ ✔️ ✔️ ✔️ ✔️

@jrhemstad
Copy link
Collaborator Author

jrhemstad commented Mar 5, 2024

Awesome work @miscco. I think the only missing piece is to understand what each of these solutions does for atomic operations. Do they overload things like atomicAdd? Something else?

@cliffburdick was there anything you recall having to add for the matx types that you don't see reflected in the table above?

@jrhemstad jrhemstad changed the title Identify existing extended floating point wrapper types Identify and list features of existing extended floating point wrapper types Mar 5, 2024
@cliffburdick
Copy link

Awesome work @miscco. I think the only missing piece is to understand what each of these solutions does for atomic operations. Do they overload things like atomicAdd? Something else?

@cliffburdick was there anything you recall having to add for the matx types that you don't see reflected in the table above?

Not sure why I didn't see this. I think this is comprehensive, but one of the main issues was also having types that are compatible with their complex counterparts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

No branches or pull requests

5 participants