dmlc / HalideIR

Symbolic Expression and Statement Module for new DSLs
Other
205 stars 59 forks source link

It seems size_t different from uint64_t on macOS (64 bit) #17

Closed clouds56 closed 6 years ago

clouds56 commented 6 years ago

When compiling latest tvm, it failed on topi.cc.o

FAILED: CMakeFiles/tvm_topi.dir/topi/src/topi.cc.o 
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++  -DDMLC_USE_FOPEN64=0 -DGLFW_DLL -DTVM_CUDA_RUNTIME=0 -DTVM_LLVM_VERSION=50 -DTVM_METAL_RUNTIME=1 -DTVM_OPENCL_RUNTIME=1 -DTVM_OPENGL_RUNTIME=1 -Dtvm_topi_EXPORTS -I../include -I../HalideIR/src -I../dlpack/include -I../topi/include -I/usr/local/opt/llvm/include -I../dmlc-core/include -isystem /usr/local/include -O3 -Wall -fPIC -std=c++11 -fPIC   -DLLVM_BUILD_GLOBAL_ISEL -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -MD -MT CMakeFiles/tvm_topi.dir/topi/src/topi.cc.o -MF CMakeFiles/tvm_topi.dir/topi/src/topi.cc.o.d -o CMakeFiles/tvm_topi.dir/topi/src/topi.cc.o -c ../topi/src/topi.cc
In file included from ../topi/src/topi.cc:12:
In file included from ../topi/include/topi/broadcast.h:11:
../topi/include/topi/detail/broadcast.h:58:10: warning: explicitly assigning value of variable of type 'int' to itself [-Wself-assign]
  for (i = i; i <= max_size; ++i) {
       ~ ^ ~
In file included from ../topi/src/topi.cc:31:
In file included from ../topi/include/topi/cuda/dense.h:14:
In file included from ../topi/include/topi/contrib/cublas.h:10:
../topi/include/topi/detail/extern.h:113:5: error: call to 'make_const' is ambiguous
    make_const(Int(32), buf->shape.size()),
    ^~~~~~~~~~
../HalideIR/src/ir/IROperator.h:81:13: note: candidate function
EXPORT Expr make_const(Type t, int64_t val);
            ^
../HalideIR/src/ir/IROperator.h:82:13: note: candidate function
EXPORT Expr make_const(Type t, uint64_t val);
            ^
../HalideIR/src/ir/IROperator.h:83:13: note: candidate function
EXPORT Expr make_const(Type t, double val);
            ^
../HalideIR/src/ir/IROperator.h:84:13: note: candidate function
inline Expr make_const(Type t, int32_t val)   {return make_const(t, (int64_t)val);}
            ^
../HalideIR/src/ir/IROperator.h:85:13: note: candidate function
inline Expr make_const(Type t, uint32_t val)  {return make_const(t, (uint64_t)val);}
            ^
../HalideIR/src/ir/IROperator.h:86:13: note: candidate function
inline Expr make_const(Type t, int16_t val)   {return make_const(t, (int64_t)val);}
            ^
../HalideIR/src/ir/IROperator.h:87:13: note: candidate function
inline Expr make_const(Type t, uint16_t val)  {return make_const(t, (uint64_t)val);}
            ^
../HalideIR/src/ir/IROperator.h:88:13: note: candidate function
inline Expr make_const(Type t, int8_t val)    {return make_const(t, (int64_t)val);}
            ^
../HalideIR/src/ir/IROperator.h:89:13: note: candidate function
inline Expr make_const(Type t, uint8_t val)   {return make_const(t, (uint64_t)val);}
            ^
../HalideIR/src/ir/IROperator.h:90:13: note: candidate function
inline Expr make_const(Type t, bool val)      {return make_const(t, (uint64_t)val);}
            ^
../HalideIR/src/ir/IROperator.h:91:13: note: candidate function
inline Expr make_const(Type t, float val)     {return make_const(t, (double)val);}
            ^
1 warning and 1 error generated.

the return type of buf->shape.size() is size_t, which seems different from uint64_t on my clang of Xcode.

it's defined in stddef.h (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/9.0.0/include/stddef.h:54)

#if defined(__need_size_t)
#if !defined(_SIZE_T) || __has_feature(modules)
/* Always define size_t when modules are available. */
#if !__has_feature(modules)
#define _SIZE_T
#endif
typedef __SIZE_TYPE__ size_t;
#endif
#undef __need_size_t
#endif /*defined(__need_size_t) */

According to this answar and the reference, the definition of size_t is implementation depended.

I added inline Expr make_const(Type t, size_t val) {return make_const(t, (uint64_t)val);}, and it works, while I don't think it's a solution, since some system may have size_t and uint64_t the same.

Why don't we use template here?