ai-techsystems / deepC

vendor independent TinyML deep learning library, compiler and inference framework microcomputers and micro-controllers
https://cainvas.ai-tech.systems/
Apache License 2.0
558 stars 86 forks source link

operator GEMM does not compile with template type int #84

Open srohit0 opened 5 years ago

srohit0 commented 5 years ago

How to Reproduce

Step 1 Change gemm operator in swig/dnnc.api file to add int shown below:

tensor<output> gemm(tensor<input> &a, tensor<input> &b, 
                                       tensor<input> &c, float alpha = 1.0, float beta = 1.0, 
                                       int transA = 0, int transB = 0) {
     Gemm<output, input, input> op("localOpName", alpha, beta, transA, transB);
     return op.compute(a, b, c);
     dtype = {
         "double" : "double",
         "float" : "float",
         "int" : "int"
     }
}

Step 2

cd swig make clean make

Observe compiler errors

/home/dnnc/master/dnnCompiler/include/operators/Gemm.h:139:25: error: invalid operands to binary expression ('float' and 'const Product<Eigen::Map<Eigen::Matrix<int, -1, -1, 1, -1, -1>, 0, Eigen::Stride<0, 0> >, Eigen:: Map<Eigen::Matrix<int, -1, -1, 1, -1, -1>, 0, Eigen::Stride<0, 0> > >') eResult = alpha (eigenMatrixA eigenMatrixB) + beta * eigenMatrixC;


 dnnc_api.cpp:10885:13: note: in instantiation of member function 'dnnc::Gemm<int, int, int>::compute' requested here
                 return op.compute(a, b, c);
                           ^
 /home/dnnc/master/dnnCompiler/packages/eigen-eigen-323c052e1731/Eigen/src/Core/../plugins/CommonCwiseBinaryOps.h: 50:29: note: candidate function template not viable: no known conversion from 'const Product<Eigen::Map<Eigen::       Matrix<int, -1, -1, 1, -1, -1>, 0, Eigen::Stride<0, 0> >, Eigen::Map<Eigen::Matrix<int, -1, -1, 1, -1, -1>, 0,        Eigen::Stride<0, 0> > >' to 'const Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 1, -1, -1> >::StorageBaseType' (aka   'const Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 1, -1, -1> >') for 2nd argument
 EIGEN_MAKE_SCALAR_BINARY_OP(operator*,product)
                             ^
 /home/dnnc/master/dnnCompiler/packages/eigen-eigen-323c052e1731/Eigen/src/Core/util/Macros.h:960:41: note:        expanded from macro 'EIGEN_MAKE_SCALAR_BINARY_OP'
   EIGEN_MAKE_SCALAR_BINARY_OP_ONTHELEFT(METHOD,OPNAME) \
                                         ^
 /home/dnnc/master/dnnCompiler/packages/eigen-eigen-323c052e1731/Eigen/src/Core/util/Macros.h:953:4: note:         expanded from macro 'EIGEN_MAKE_SCALAR_BINARY_OP_ONTHELEFT'
   (METHOD)(const T& scalar, const StorageBaseType& matrix) { \

/home//dnnc/master/dnnCompiler/packages/eigen-eigen-323c052e1731/Eigen/src/Core/../plugins/CommonCwiseBinaryOps.h: 50:29: note: candidate function template not viable: no known conversion from 'const Product<Eigen::Map<Eigen::       Matrix<int, -1, -1, 1, -1, -1>, 0, Eigen::Stride<0, 0> >, Eigen::Map<Eigen::Matrix<int, -1, -1, 1, -1, -1>, 0,        Eigen::Stride<0, 0> > >' to 'const Eigen::MatrixBase<Eigen::Map<Eigen::Matrix<int, -1, -1, 1, -1, -1>, 0, Eigen::     Stride<0, 0> > >::StorageBaseType' (aka 'const Eigen::MatrixBase<Eigen::Map<Eigen::Matrix<int, -1, -1, 1, -1, -1>,    0, Eigen::Stride<0, 0> > >') for 2nd argument
 /home//dnnc/master/dnnCompiler/packages/eigen-eigen-323c052e1731/Eigen/src/Core/util/Macros.h:960:41: note:        expanded from macro 'EIGEN_MAKE_SCALAR_BINARY_OP'
   EIGEN_MAKE_SCALAR_BINARY_OP_ONTHELEFT(METHOD,OPNAME) \
                                         ^
 /home//dnnc/master/dnnCompiler/packages/eigen-eigen-323c052e1731/Eigen/src/Core/util/Macros.h:953:4: note:         expanded from macro 'EIGEN_MAKE_SCALAR_BINARY_OP_ONTHELEFT'
   (METHOD)(const T& scalar, const StorageBaseType& matrix) { \
    ^
 /home//dnnc/master/dnnCompiler/packages/eigen-eigen-323c052e1731/Eigen/src/Core/PermutationMatrix.h:543:1: note:   candidate template ignored: could not match 'MatrixBase<type-parameter-0-0>' against 'float'
 operator*(const MatrixBase<MatrixDerived> &matrix,

...
...

 /home/dnnc/master/dnnCompiler/packages/eigen-eigen-323c052e1731/unsupported/Eigen/CXX11/src/Tensor/TensorUInt128. h:135:35: note: candidate template ignored: could not match 'TensorUInt128<type-parameter-0-0, type-parameter-0-1>'   against 'float'
 TensorUInt128<uint64_t, uint64_t> operator * (const TensorUInt128<HL, LL>& lhs, const TensorUInt128<HR, LR>& rhs)
                                   ^