| 42 | |
| 43 | template <typename T> |
| 44 | static Graph* Transpose(const string& kind, const TensorShape& in_shape, const Tensor& perm_tensor) { |
| 45 | Graph* g = new Graph(OpRegistry::Global()); |
| 46 | DataType type = DataTypeToEnum<T>::v(); |
| 47 | |
| 48 | const bool isDefault = (kind == "Default"); |
| 49 | string op_name = isDefault ? "Transpose" : "_MklTranspose"; |
| 50 | |
| 51 | // Create inputs |
| 52 | Tensor input1(type, in_shape); |
| 53 | input1.flat<T>().setRandom(); |
| 54 | |
| 55 | Node* input_in0 = test::graph::Constant(g, input1); |
| 56 | Node* input_in1 = test::graph::Constant(g, perm_tensor); |
| 57 | |
| 58 | // Create NodeDef |
| 59 | auto nodeBuilder = NodeBuilder(g->NewName("transpose"), op_name) |
| 60 | .Input(input_in0) |
| 61 | .Input(input_in1); |
| 62 | |
| 63 | isDefault ? nodeBuilder : nodeBuilder.Attr("_kernel", "MklNameChangeOp"); |
| 64 | |
| 65 | TF_CHECK_OK(nodeBuilder.Finalize(g, nullptr)); |
| 66 | |
| 67 | return g; |
| 68 | } |
| 69 | |
| 70 | #define S_TENSOR(size, ...) test::AsTensor<int32>({__VA_ARGS__}, {size}) |
| 71 | |