MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / Compute

Method Compute

tensorflow/core/kernels/mkl_batch_matmul_op.cc:65–209  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

63 virtual ~BatchMatMulMkl() {}
64
65 void Compute(OpKernelContext* ctx) override {
66 const Tensor& lhs = ctx->input(0);
67 const Tensor& rhs = ctx->input(1);
68
69 if (fuse_mul_) {
70 const Tensor& scale = ctx->input(2);
71 OP_REQUIRES(ctx, scale.NumElements() == 1,
72 errors::InvalidArgument("scale Tensor must be a scalar"));
73 alpha_ = static_cast<float>(scale.flat<Scalar>()(0));
74 beta_ = 0.0f;
75 }
76
77 if (!v2_bcast) {
78 // Using V1, so check to make sure lhs and rhs dimensions are correct and
79 // no broadcasting is needed.
80 OP_REQUIRES(ctx, lhs.dims() == rhs.dims(),
81 errors::InvalidArgument("lhs and rhs has different ndims: ",
82 lhs.shape().DebugString(), " vs. ",
83 rhs.shape().DebugString()));
84 const int ndims = lhs.dims();
85 OP_REQUIRES(
86 ctx, ndims >= 2,
87 errors::InvalidArgument("lhs and rhs ndims must be >= 2: ", ndims));
88 for (int i = 0; i < ndims - 2; ++i) {
89 OP_REQUIRES(ctx, lhs.dim_size(i) == rhs.dim_size(i),
90 errors::InvalidArgument(
91 "lhs.dim(", i, ") and rhs.dim(", i,
92 ") must be the same: ", lhs.shape().DebugString(),
93 " vs ", rhs.shape().DebugString()));
94 }
95 } else {
96 OP_REQUIRES(
97 ctx, lhs.dims() >= 2,
98 errors::InvalidArgument("In[0] ndims must be >= 2: ", lhs.dims()));
99 OP_REQUIRES(
100 ctx, rhs.dims() >= 2,
101 errors::InvalidArgument("In[1] ndims must be >= 2: ", rhs.dims()));
102 }
103
104 // lhs and rhs can have different dimensions
105 const auto ndims_lhs = lhs.dims();
106 const auto ndims_rhs = rhs.dims();
107
108 // Get broadcast info
109 MatMulBCast bcast(lhs.shape().dim_sizes(), rhs.shape().dim_sizes());
110 OP_REQUIRES(
111 ctx, bcast.IsValid(),
112 errors::InvalidArgument(
113 "In[0] and In[1] must have compatible batch dimensions: ",
114 lhs.shape().DebugString(), " vs. ", rhs.shape().DebugString()));
115
116 TensorShape out_shape = bcast.output_batch_shape();
117
118 auto lhs_rows = lhs.dim_size(ndims_lhs - 2);
119 auto lhs_cols = lhs.dim_size(ndims_lhs - 1);
120 auto rhs_rows = rhs.dim_size(ndims_rhs - 2);
121 auto rhs_cols = rhs.dim_size(ndims_rhs - 1);
122

Callers

nothing calls this directly

Calls 15

InvalidArgumentFunction · 0.85
GetFunction · 0.85
CreateStreamFunction · 0.85
allocate_outputMethod · 0.80
SetUsrMemMethod · 0.80
CheckReorderToOpMemMethod · 0.80
GetEngineMethod · 0.80
fFunction · 0.50
inputMethod · 0.45
NumElementsMethod · 0.45
dimsMethod · 0.45
DebugStringMethod · 0.45

Tested by

no test coverage detected