microsoft / nnfusion

A flexible and efficient deep neural network (DNN) compiler that generates high-performance executable from a DNN model description.
MIT License
948 stars 158 forks source link

[BUG] "More than one instance of overloaded function" for half type #469

Closed mzmssg closed 1 year ago

mzmssg commented 1 year ago

🐛 Bug

NNFusion relies on implicit conversion to support half arithmetic operation, which may error out in some cases:

  1. more than one implicit conversion
half a;
half b = sqrt(a);
/*
 error: more than one instance of overloaded function "sqrt" matches the argument list:
            function "std::sqrt(long double)"
            function "std::sqrt(float)"
            argument types are: (__half)
*/
  1. Implicit conversion changes output data type, then the following operator may get unexpected input type
    half a;
    half b = a * normcdf(a); // normcdf returns a float, so * is on half and (unexpected) float
    /*
    error: more than one operator "*" matches these operands:
            built-in operator "arithmetic * arithmetic"
            function "operator*(const __half &, const __half &)"
            operand types are: __half * float
    */
  2. No conversion from/to some type
    int64_t a;
    half b = (half)a;
    /*
    error: more than one constructor applies to convert from "int64_t" to "__half":
            function "__half::__half(float)"
            function "__half::__half(double)"
            function "__half::__half(short)"
            function "__half::__half(unsigned short)"
            function "__half::__half(int)"
            function "__half::__half(unsigned int)"
            function "__half::__half(long long)"
            function "__half::__half(unsigned long long)"
    */

    Expected behavior Use half operator, e.g. sqrt->hsqrt

xiayuqing0622 commented 1 year ago

the second bug is fixed by pr #473 . the first and third ones are fixed by the latest antares.