| 45 | |
| 46 | template<typename T> |
| 47 | void SplitOneOutput(Response& batched_response, |
| 48 | int index, int call_num, std::vector<Tensor>& ret) { |
| 49 | Tensor& batched_tensor = batched_response.outputs[index]; |
| 50 | auto batched_tensor_shape = batched_tensor.shape(); |
| 51 | auto batched_flat = batched_tensor.flat<T>(); |
| 52 | size_t current_pos = 0; |
| 53 | |
| 54 | size_t single_output_size = 1; |
| 55 | TensorShape tensor_shape; |
| 56 | for (int j = 1; j < batched_tensor_shape.dims(); ++j) { |
| 57 | tensor_shape.AddDim(batched_tensor_shape.dim_size(j)); |
| 58 | single_output_size *= batched_tensor_shape.dim_size(j); |
| 59 | } |
| 60 | for (int i = 0; i < call_num; ++i) { |
| 61 | Tensor t(batched_tensor.dtype(), tensor_shape); |
| 62 | auto flat = t.flat<T>(); |
| 63 | |
| 64 | memcpy(flat.data(), batched_flat.data() + current_pos, |
| 65 | single_output_size); |
| 66 | current_pos += single_output_size; |
| 67 | ret[i] = t; |
| 68 | } |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | Status BatchCall::BatchRequest() { |