builds a graph containing a sequence of conv2d operations. Args: device: String, the device to run on. input_shape: Shape of the input tensor. perm: A list of ints with the same length as input tensor's dimension. datatype: numpy data type of the input tensor. num_iters: numbe
(device, input_shape, perm, datatype, num_iters)
| 32 | |
| 33 | |
| 34 | def build_graph(device, input_shape, perm, datatype, num_iters): |
| 35 | """builds a graph containing a sequence of conv2d operations. |
| 36 | |
| 37 | Args: |
| 38 | device: String, the device to run on. |
| 39 | input_shape: Shape of the input tensor. |
| 40 | perm: A list of ints with the same length as input tensor's dimension. |
| 41 | datatype: numpy data type of the input tensor. |
| 42 | num_iters: number of iterations to run transpose. |
| 43 | |
| 44 | Returns: |
| 45 | An array of tensors to run() |
| 46 | """ |
| 47 | with ops.device("/%s:0" % device): |
| 48 | total_size = np.prod(input_shape) |
| 49 | inp = np.arange(1, total_size + 1, dtype=datatype).reshape(input_shape) |
| 50 | t = constant_op.constant(inp, shape=input_shape) |
| 51 | |
| 52 | outputs = [] |
| 53 | transpose_op = array_ops.transpose(t, perm) |
| 54 | outputs.append(transpose_op) |
| 55 | for _ in range(1, num_iters): |
| 56 | with ops.control_dependencies([transpose_op]): |
| 57 | transpose_op = array_ops.transpose(t, perm) |
| 58 | outputs.append(transpose_op) |
| 59 | return control_flow_ops.group(*outputs) |
| 60 | |
| 61 | |
| 62 | class TransposeBenchmark(test.Benchmark): |
no test coverage detected