explicit BlocksparseConvOp()

in src/blocksparse_conv_op.cc [193:265]


  explicit BlocksparseConvOp(OpKernelConstruction* ctx) : OpKernel(ctx) {

    OP_REQUIRES_OK(ctx, ctx->GetAttr("mode",      &mode_     ));
    OP_REQUIRES_OK(ctx, ctx->GetAttr("C",         &C_        ));
    OP_REQUIRES_OK(ctx, ctx->GetAttr("K",         &K_        ));
    OP_REQUIRES_OK(ctx, ctx->GetAttr("DHW",       &DHW_      ));
    OP_REQUIRES_OK(ctx, ctx->GetAttr("MPQ",       &MPQ_      ));
    OP_REQUIRES_OK(ctx, ctx->GetAttr("dimF",      &dimF_     ));
    OP_REQUIRES_OK(ctx, ctx->GetAttr("trs",       &trs_      ));
    OP_REQUIRES_OK(ctx, ctx->GetAttr("magic_trs", &magic_trs_));
    OP_REQUIRES_OK(ctx, ctx->GetAttr("shift_trs", &shift_trs_));
    OP_REQUIRES_OK(ctx, ctx->GetAttr("debug",     &debug_    ));

    cdhw_ = C_ * DHW_[0] * DHW_[1] * DHW_[2];
    kmpq_ = K_ * MPQ_[0] * MPQ_[1] * MPQ_[2];
    zero_ = 0;
    size_f_ = 1;
    for (std::vector<int32>::iterator it = dimF_.begin() ; it != dimF_.end(); ++it)
      size_f_ *= *it;

    const char* dtypeA;
    if (mode_ == 2)
      dtypeA = std::is_same<AT, float>::value ? "E32" : "E16";
    else
      dtypeA = std::is_same<AT, float>::value ? "F32" : "F16";
    const char* dtypeB = std::is_same<BT, float>::value ? "I32" : "I16";
    const char* dtypeC = std::is_same<CT, float>::value ? "O32" : "O16";
    const char* overlap = "";
    const char* op;
    int depth;

    if (mode_  == 0)
    {
      bool overlapK;
      OP_REQUIRES_OK(ctx, ctx->GetAttr(  "fshare",  &share_  ));
      OP_REQUIRES_OK(ctx, ctx->GetAttr("overlapK",  &overlapK));
      op       = "fprop";
      depth    = 16;
      threads_ = 64;
      if (overlapK)
      {
        overlap = "_overlapK";
        zero_   = kmpq_ * sizeof(CT);
      }
    }
    else if (mode_  == 1)
    {
      bool overlapC;
      OP_REQUIRES_OK(ctx, ctx->GetAttr(  "bshare", &share_  ));
      OP_REQUIRES_OK(ctx, ctx->GetAttr("overlapC", &overlapC));
      op       = "bprop";
      depth    = 16;
      threads_ = 64;
      if (overlapC)
      {
        overlap = "_overlapC";
        zero_   = cdhw_ * sizeof(CT);
      }
    }
    else //if (mode_  == 2)
    {
      op       = "updat";
      depth    = 32;
      zero_    = size_f_ * sizeof(CT);
      threads_ = 128;
      share_   = 0;
      overlap  = "";
    }
    char kernel_name[64];
    sprintf(kernel_name, "conv_blocksparse_32x32x%d_%s_%s_%s_%s%s", depth, op, dtypeA, dtypeB, dtypeC, overlap);
    kernel_name_ = kernel_name;
    kernel_ = 0;
  }