NVIDIA / MatX

An efficient C++17 GPU numerical computing library with Python-like syntax

Home Page:https://nvidia.github.io/MatX

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[BUG] Conversion issue with matxBf16 and logical > with float literal

mfzmullen opened this issue · comments

Describe the Bug
When using matxBf16 type in a logical > operation, the compiler (gcc 11.4.0, nvcc from cuda toolkit 12.4.131) complains that:
error: more than one conversion function from "matx::matxBf16" to a built-in type applies:
function "matx::matxHalf::operator float() const [with T=__nv_bfloat16]" (declared at line 99 of /home/mmullen/adl/adldependencies/build/include/matx/core/half.h)
function "matx::matxHalf::operator double() const [with T=__nv_bfloat16]" (declared at line 109 of /home/mmullen/adl/adldependencies/build/include/matx/core/half.h)
static attribute((always_inline)) inline attribute((host)) attribute((device)) auto op(T1 v1, T2 v2) { return v1 > v2; }

To Reproduce
Steps to reproduce the behavior:

  1. Compare a matxBf16 type to a float literal using >
  2. Try to compile

Expected Behavior
Error free compilation and a boolean value.

Code Snippets

  #include <matx.h>
  #include <iostream>
  
  int main([[maybe_unused]] int argc, [[maybe_unused]] char **argv)
  {
      MATX_ENTER_HANDLER();
  
      int npts = 2;
  
      auto t0 = matx::make_tensor<matx::matxBf16>({npts, npts});    
      auto t1 = matx::make_tensor<matx::matxBf16>({npts, npts});    
  
      (t1 = matx::zeros({npts, npts})).run();
      t0(0,0) = 0.25;
      t0(0,1) = 0.5;
      t0(1,0) = 0.75;
      t0(1,1) = 1.0;
  
      matx::IF(t0 > 0.6, t1 = t0).run();
      
      matx::print(t1);
  
      CUDA_CHECK_LAST_ERROR();
      MATX_EXIT_HANDLER();
  }

System Details (please complete the following information):

  • OS: Ubuntu 22.04
  • CUDA version: 12.4
  • g++ version: 11.4.0
  • CUDA Arch: 86-real (also specifying in my CMakeLists.txt)

Additional Context
If I delete the definition on how to cast to double in half.h, it seems to work just fine, or explicitly cast the float literal to a matxBf16 type. It would be nice to not have to explicitly cast all over though.

Thanks for reporting this, @mfzmullen! We'll look into it today.