| 211 | |
| 212 | template <typename T> |
| 213 | static Graph* FusedMatMul(const string& kind, int m, int k, int n, |
| 214 | bool transpose_a, bool transpose_b, const string& activation = "") { |
| 215 | Graph* g = new Graph(OpRegistry::Global()); |
| 216 | DataType type = DataTypeToEnum<T>::v(); |
| 217 | |
| 218 | std::vector<string> fused_ops{"BiasAdd"}; |
| 219 | |
| 220 | if(activation != "" && activation != "null"){ |
| 221 | fused_ops.push_back(activation); |
| 222 | } |
| 223 | |
| 224 | const bool isDefault = (kind == "Default"); |
| 225 | string op_name = isDefault ? "_FusedMatMul" : "_MklFusedMatMul"; |
| 226 | |
| 227 | int num_args = 1; |
| 228 | Tensor in0(type, transpose_a ? TensorShape({k, m}) : TensorShape({m, k})); |
| 229 | in0.flat<T>().setRandom(); |
| 230 | Tensor in1(type, transpose_b ? TensorShape({n, k}) : TensorShape({k, n})); |
| 231 | in1.flat<T>().setRandom(); |
| 232 | Tensor bias(type, TensorShape({transpose_b ? k : n})); |
| 233 | bias.flat<T>().setRandom(); |
| 234 | |
| 235 | Node* input_in0 = test::graph::Constant(g, in0); |
| 236 | Node* input_in1 = test::graph::Constant(g, in1); |
| 237 | Node* input_bias = test::graph::Constant(g, bias, absl::StrCat("arg", 1)); |
| 238 | |
| 239 | Node* not_mkl_shape = |
| 240 | test::graph::Constant(g, GetMklMetaTensor(), "not_mkl"); |
| 241 | |
| 242 | std::vector<NodeBuilder::NodeOut> args; |
| 243 | std::vector<NodeBuilder::NodeOut> args_not_mkl; |
| 244 | args.push_back(input_bias); |
| 245 | args_not_mkl.push_back(not_mkl_shape); |
| 246 | |
| 247 | auto nodeBuilder = NodeBuilder(g->NewName("fused_matmul"), op_name) |
| 248 | .Input(input_in0) |
| 249 | .Input(input_in1) |
| 250 | .Input(args) |
| 251 | .Attr("T", type) |
| 252 | .Attr("num_args", num_args) |
| 253 | .Attr("fused_ops", fused_ops) |
| 254 | .Attr("transpose_a", transpose_a) |
| 255 | .Attr("transpose_b", transpose_b); |
| 256 | |
| 257 | isDefault ? nodeBuilder : nodeBuilder.Attr("_kernel", "MklLayoutDependentOp") |
| 258 | .Input(not_mkl_shape) |
| 259 | .Input(not_mkl_shape) |
| 260 | .Input(args_not_mkl); |
| 261 | |
| 262 | TF_CHECK_OK(nodeBuilder.Finalize(g, nullptr)); |
| 263 | |
| 264 | return g; |
| 265 | } |
| 266 | |
| 267 | #define BM_FusedMatMul_Base(kind, ACT, M, K, N, TA, TB, T, DEVICE, NTH) \ |
| 268 | static void BM_FusedMatMul##_##kind##_##ACT##_##M##_##K##_##N##_##TA##_##TB##_##T##_##DEVICE##_##NTH( \ |
nothing calls this directly
no test coverage detected