Giter Site home page Giter Site logo

Comments (11)

crtrott avatar crtrott commented on May 25, 2024 4

Just try out what is fastest and do that. Though I hope its the std::numeric_limits solution ;-)

from kokkos-kernels.

mhoemmen avatar mhoemmen commented on May 25, 2024

Kokkos::ArithTraits needs to work on the GPU, so you can't use std::numeric_limits if __CUDA_ARCH__ is defined. It could be that this works now, given how CUDA's constexpr support has been evolving. However, you'll have to try it to be sure.

If std::numeric_limits doesn't work, you could try this:
https://stackoverflow.com/questions/15514286/way-to-get-floating-point-special-values-in-cuda

from kokkos-kernels.

ibaned avatar ibaned commented on May 25, 2024

Actually, this is the code right now, so the CUDA part is already separate:

#ifdef __CUDA_ARCH__
    return CUDART_NAN;
    //return nan (); // this returns 0 ???
#else
    // http://pubs.opengroup.org/onlinepubs/009696899/functions/nan.html
    return strtod ("NAN", (char**) NULL);
#endif // __CUDA_ARCH__

So we only have to worry about the slow host code, which has no GPU restrictions.

from kokkos-kernels.

hcedwar avatar hcedwar commented on May 25, 2024

Suggest the strtod only be called once to initialize a singleton:

#ifdef __CUDA_ARCH__
__device__ inline
double kokkos_kernels_nan_function() // whatever 
{  return CUDART_NAN ; }
#else
inline
double kokkos_kernels_nan_function() // whatever 
{ static double x = strtod("NAN",(char**)NULL); return x ; }
#endif

from kokkos-kernels.

ibaned avatar ibaned commented on May 25, 2024

This is quite similar to what Teuchos does. They also use a singleton, just a different initialization.

Any reason not to use the numeric_limits quiet_NAN to initialize the singleton instead of strtod ?

from kokkos-kernels.

ibaned avatar ibaned commented on May 25, 2024

Actually, std::numeric_limits<double>::quiet_NaN() is constexpr in C++11, so calling it directly might be faster than loading a singleton in that case.

from kokkos-kernels.

ibaned avatar ibaned commented on May 25, 2024

Could someone add me to this repository so I can assign this to myself?

from kokkos-kernels.

crtrott avatar crtrott commented on May 25, 2024

Ah this is Kokkos-Kernels totally overlooked this.

from kokkos-kernels.

mhoemmen avatar mhoemmen commented on May 25, 2024

std::numeric_limits should work. We could even make ArithTraits::nan constexpr in the non-CUDA case (and eventually, even in the CUDA case, since CUDA looks like it's starting to get more constexpr support).

Singletons could be bad if calling this in a thread-parallel context; we would want pthread_once in that case.

from kokkos-kernels.

ibaned avatar ibaned commented on May 25, 2024

trilinos/Trilinos#1490 fixes this in Trilinos, including the addition of a performance test in the affected MiniTensor package to measure the difference.

#36 fixes this in the KokkosKernels develop branch.

They are separate since KokkosKernels is unlikely to promote into Trilinos in the near term, and MiniTensor needs this now.

from kokkos-kernels.

mhoemmen avatar mhoemmen commented on May 25, 2024

I submitted a trilinos/Trilinos#1490 review; thanks!

from kokkos-kernels.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.