openvdb icon indicating copy to clipboard operation
openvdb copied to clipboard

[BUG] code that uses openvdb-12.0.0 cannot be compiled with hipcc

Open t1nux opened this issue 10 months ago • 2 comments

Environment

Operating System: (Arch Linux) Version: (openvdb-12.0.0) Other: (compiler: hipcc)

Describe the bug

While using openvdb-12.0.0, when using #include <openvdb/openvdb.h> in code and compiling it with hipcc (ROCM), I get this error:

In file included from test.cpp:1:
In file included from /usr/include/openvdb/openvdb.h:8:
/usr/include/openvdb/Types.h:701:19: error: use of overloaded operator '+' is ambiguous (with operand types 'const math::half' (aka 'const __half') and 'const float')
  701 |         *op = *ip + s;
      |               ~~~ ^ ~
/usr/include/openvdb/Types.h:701:19: note: built-in candidate operator+(float, float)
/usr/include/openvdb/Types.h:701:19: note: built-in candidate operator+(double, float)
/usr/include/openvdb/Types.h:701:19: note: built-in candidate operator+(long double, float)
/usr/include/openvdb/Types.h:701:19: note: built-in candidate operator+(int, float)
/usr/include/openvdb/Types.h:701:19: note: built-in candidate operator+(long, float)
/usr/include/openvdb/Types.h:701:19: note: built-in candidate operator+(long long, float)
/usr/include/openvdb/Types.h:701:19: note: built-in candidate operator+(unsigned int, float)
/usr/include/openvdb/Types.h:701:19: note: built-in candidate operator+(unsigned long, float)
/usr/include/openvdb/Types.h:701:19: note: built-in candidate operator+(unsigned long long, float)
1 error generated when compiling for gfx1100.
failed to execute:/opt/rocm/lib/llvm/bin/clang++  -isystem "/opt/rocm/include" --offload-arch=gfx1100 -O3  -c -x hip test.cpp -o "test.o" -std=c++17

To Reproduce

Steps to reproduce the behavior:

  1. Install openvdb-12.0.0
  2. Add #include <openvdb/openvdb.h>
  3. Compile with hipcc
  4. See error.

Expected behavior

No error.

Additional context

  • Compiling with g++ and openvdb-12.0.0 works.
  • Compiling with hipcc and openvdb-11.0.0 works.

t1nux avatar Feb 24 '25 11:02 t1nux

BTW, a minimal example would be

#include <openvdb/openvdb.h>
int main(){return 0;}

which can be compiled using

  • g++ -c test.cpp -o test.o -I/usr/include (works)
  • hipcc -c test.cpp -o test.o -I/usr/include (doesn't work)

For now, I'm using this patch to get rid of the issue:

--- /usr/include/openvdb/Types.h	2025-04-08 22:19:11.139457511 +0200
+++ /usr/include/openvdb/Types.h_orig	2025-04-08 22:14:19.330065304 +0200
@@ -689,6 +689,7 @@
 class PartialCreate {};
 
 
+#ifndef __HIPCC__
 // For half compilation
 namespace math {
 template<>
@@ -706,6 +707,7 @@
 }
 } // namespace math
   //
+#endif // __HIPCC__
 
 } // namespace OPENVDB_VERSION_NAME
 } // namespace openvdb

t1nux avatar Apr 08 '25 20:04 t1nux

Facing same problem here with Clang-20. No overload exists for operator+ with half float ser-defined types. Related to that is which seems to be the missing piece https://github.com/AcademySoftwareFoundation/openvdb/pull/2011

Either the type must be manually promoted or use the defined operator for half with float which is operator+=.

template<>
inline auto cwiseAdd(const math::Vec3<math::half>& v, const float s)
{
    math::Vec3<math::half> out;
    const math::half* ip = v.asPointer();
    math::half* op       = out.asPointer();
    for(unsigned i = 0; i < 3; ++i, ++op, ++ip)
    {
        OPENVDB_NO_TYPE_CONVERSION_WARNING_BEGIN
-        *op = *ip + s;
+        *op = *ip;
+        *op += s; // rely on operator+=(float) in half implementation
        OPENVDB_NO_TYPE_CONVERSION_WARNING_END
    }
    return out;
}

FabienPean-Virtonomy avatar Sep 08 '25 13:09 FabienPean-Virtonomy