sheep94lion opened a new issue #15333: Compile error for custom operators in C
URL: https://github.com/apache/incubator-mxnet/issues/15333
 
 
   ## Description
   I define a custom operator under src/operator/contrib/
   I met compiling errors saying:
   In file included from 
/home/yizhao/Code/mxnet-dev/3rdparty/dmlc-core/include```
   /dmlc/registry.h:14:0,
                    from include/mxnet/operator_util.h:37,
                    from src/operator/contrib/./rpn_inv_normalize_op-inl.h:4,
                    from src/operator/contrib/rpn_inv_normalize_op.cc:1:
   /home/yizhao/Code/mxnet-dev/3rdparty/dmlc-core/include/dmlc/./parameter.h: 
In instantiation of ‘void dmlc::parameter::FieldEntryBase<TEntry, 
DType>::Set(void*, const string&) const [with TEntry = 
dmlc::parameter::FieldEntry<float*>; DType = float*; std::string = 
std::basic_string<char>]’:
   src/operator/contrib/rpn_inv_normalize_op.cc:20:1:   required from here
   
/home/yizhao/Code/mxnet-dev/3rdparty/dmlc-core/include/dmlc/./parameter.h:558:8:
 error: cannot bind ‘std::basic_istream<char>’ lvalue to 
‘std::basic_istream<char>&&’
        is >> this->Get(head);
           ^
   In file included from /usr/include/c++/4.8/sstream:38:0,
                    from 
/home/yizhao/Code/mxnet-dev/3rdparty/dmlc-core/include/dmlc/./logging.h:20,
                    from 
/home/yizhao/Code/mxnet-dev/3rdparty/dmlc-core/include/dmlc/registry.h:13,
                    from include/mxnet/operator_util.h:37,
                    from src/operator/contrib/./rpn_inv_normalize_op-inl.h:4,
                    from src/operator/contrib/rpn_inv_normalize_op.cc:1:
   /usr/include/c++/4.8/istream:872:5: error:   initializing argument 1 of 
‘std::basic_istream<_CharT, _Traits>& 
std::operator>>(std::basic_istream<_CharT, _Traits>&&, _Tp&) [with _CharT = 
char; _Traits = std::char_traits<char>; _Tp = float*]’
        operator>>(basic_istream<_CharT, _Traits>&& __is, _Tp& __x)
        ^
   make: *** [Makefile:532: build/src/operator/contrib/rpn_inv_normalize_op.o] 
Error 1
   ```
   I explored the related source files mentioned in the error message but it is 
hard to locate the problem in my code.
   I follow the tutorial from 
https://mxnet.incubator.apache.org/versions/master/faq/add_op_in_backend.html.
   
   My codes are as following:
   rpn_inv_normalize_op-inl.h
   
   ```
   #ifndef MXNET_OPERATOR_CONTRIB_RPN_INV_NORMALIZE_OP_INL_H_
   #define MXNET_OPERATOR_CONTRIB_RPN_INV_NORMALIZE_OP_INL_H_
   
   #include <mxnet/operator_util.h>
   #include <vector>
   #include "../mshadow_op.h"
   #include "../mxnet_op.h"
   #include "../operator_common.h"
   #include "../elemwise_op_common.h"
   #include "../tensor/init_op.h"
   
   namespace mxnet {
       namespace op {
           struct RpnInvNormalizeParam: public 
dmlc::Parameter<RpnInvNormalizeParam> {
               int num_anchors;
               float *bbox_mean, *bbox_std;
               DMLC_DECLARE_PARAMETER(RpnInvNormalizeParam) {
                   DMLC_DECLARE_FIELD(num_anchors)
                       .describe("Num of anchors.");
                   DMLC_DECLARE_FIELD(bbox_mean)
                       .describe("Bbox mean.");
                   DMLC_DECLARE_FIELD(bbox_std)
                       .describe("Bbox std.");
               }
           };
   
           inline bool RpnInvNormalizeOpShape(const nnvm::NodeAttrs& attrs,
                                              mxnet::ShapeVector* in_attrs,
                                              mxnet::ShapeVector* out_attrs) {
               return true;
           }
   
           inline bool RpnInvNormalizeOpType(const nnvm::NodeAttrs& attrs,
                                             std::vector<int>* in_attrs,
                                             std::vector<int>* out_attrs) {
               return true;
           }
   
           template<typename xpu>
           void RpnInvNormalizeOpForward(const nnvm::NodeAttrs& attrs,
                                         const OpContext& ctx,
                                         const std::vector<TBlob>& inputs,
                                         const std::vector<OpReqType>& req,
                                         const std::vector<TBlob>& outputs) {
               mshadow::Stream<xpu> *s = ctx.get_stream<xpu>();
               const TBlob& in_data = inputs[0];
               const TBlob& out_data = outputs[0];
               const RpnInvNormalizeParam& param = 
nnvm::get<RpnInvNormalizeParam>(attrs.parsed);
               using namespace mxnet_op;
               MSHADOW_TYPE_SWITCH(out_data.type_flag_, DType, {
                   index_t i1, i2, i3, i4;
                   mshadow::Tensor<xpu, 4, DType> in_ts = in_data.get<xpu, 4, 
DType>(s);
                   mshadow::Tensor<xpu, 4, DType> out_ts = out_data.get<xpu, 4, 
DType>(s);
                   for (i1 = 0; i1 < out_ts.size(0); i1++) {
                       for (i2 = 0; i2 < out_ts.size(1); i2++) {
                           for (i3 = 0; i3 < out_ts.size(2); i3++) {
                               for (i4 = 0; i4 < out_ts.size(3); i4++) {
                                   float std = param.bbox_std[i2 % 4];
                                   float mean = param.bbox_mean[i2 % 4];
                                   KERNEL_ASSIGN(out_ts[i1][i2][i3][i4], 
req[0], in_ts[i1][i2][i3][i4] * std + mean);
                               }
                           }
                       }
                   }
               });
           }
       }
   }
   
   #endif
   ```
   ## Environment info (Required)
   
   ```
   What to do:
   1. Download the diagnosis script from 
https://raw.githubusercontent.com/apache/incubator-mxnet/master/tools/diagnose.py
   2. Run the script using `python diagnose.py` and paste its output here.
   
   ```
   
   Package used (Python/R/Scala/Julia):
   (I'm using ...)
   
   For Scala user, please provide:
   1. Java version: (`java -version`)
   2. Maven version: (`mvn -version`)
   3. Scala runtime if applicable: (`scala -version`)
   
   For R user, please provide R `sessionInfo()`:
   
   ## Build info (Required if built from source)
   
   Compiler (gcc/clang/mingw/visual studio):
   
   MXNet commit hash:
   (Paste the output of `git rev-parse HEAD` here.)
   
   Build config:
   (Paste the content of config.mk, or the build command.)
   
   ## Error Message:
   (Paste the complete error message, including stack trace.)
   
   ## Minimum reproducible example
   (If you are using your own code, please provide a short script that 
reproduces the error. Otherwise, please provide link to the existing example.)
   
   ## Steps to reproduce
   (Paste the commands you ran that produced the error.)
   
   1.
   2.
   
   ## What have you tried to solve it?
   
   1.
   2.
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to