| 200 | } |
| 201 | |
| 202 | void ParallelSplit(OpKernelContext* ctx, |
| 203 | const Eigen::TensorMap< |
| 204 | Eigen::Tensor<const string, 1, 1, long>, |
| 205 | 16, Eigen::MakePointer> input_vec, |
| 206 | const int64 batch_size, const string& delimiter) { |
| 207 | ThreadPool* thread_pool = |
| 208 | ctx->device()->tensorflow_cpu_worker_threads()->workers; |
| 209 | const int64 num_threads = thread_pool->NumThreads() + 1; |
| 210 | |
| 211 | std::vector<int64> num_indices(batch_size); |
| 212 | num_indices[0] = 0; |
| 213 | |
| 214 | std::vector<WorkerInfo> w_array; |
| 215 | for (int i = 0; i < num_threads; i++) { |
| 216 | WorkerInfo w(num_threads, batch_size); |
| 217 | w_array.emplace_back(w); |
| 218 | } |
| 219 | std::vector<std::vector<int64>> id_to_worker(batch_size); |
| 220 | |
| 221 | thread_pool->ParallelForWithWorkerId( |
| 222 | batch_size, |
| 223 | element_cost_, |
| 224 | [&w_array, &id_to_worker, &input_vec, |
| 225 | &delimiter, ctx, this, &num_indices] |
| 226 | (int64 start, int64 end, int64 worker_id){ |
| 227 | int64 position_in_worker = 0; |
| 228 | for (int64 i = start; i < end; ++i) { |
| 229 | std::vector<StringPiece> parts = |
| 230 | skip_empty_ ? |
| 231 | Split(input_vec(i), delimiter, str_util::SkipEmpty()) |
| 232 | : Split(input_vec(i), delimiter, str_util::AllowEmpty()); |
| 233 | int64 n_entries = parts.size(); |
| 234 | id_to_worker[i].emplace_back(worker_id); |
| 235 | id_to_worker[i].emplace_back(w_array[worker_id].counter_for_thread); |
| 236 | id_to_worker[i].emplace_back(w_array[worker_id].output_size); |
| 237 | num_indices[i] = n_entries; |
| 238 | position_in_worker += n_entries; |
| 239 | w_array[worker_id].num_indices_buffer[ |
| 240 | w_array[worker_id].counter_for_thread] = n_entries; |
| 241 | w_array[worker_id].output_size += n_entries; |
| 242 | w_array[worker_id].max_num_entries = |
| 243 | std::max(w_array[worker_id].max_num_entries, n_entries); |
| 244 | w_array[worker_id].tokens_buffer.insert( |
| 245 | w_array[worker_id].tokens_buffer.end(), |
| 246 | std::make_move_iterator(parts.begin()), |
| 247 | std::make_move_iterator(parts.end())); |
| 248 | w_array[worker_id].counter_for_thread++; |
| 249 | } |
| 250 | }); |
| 251 | |
| 252 | int64 output_size = 0; |
| 253 | int64 max_num_entries = 0; |
| 254 | for (int i = 0; i < num_threads; i++) { |
| 255 | output_size += w_array[i].output_size; |
| 256 | max_num_entries = std::max(w_array[i].max_num_entries, max_num_entries); |
| 257 | } |
| 258 | |
| 259 | std::vector<int64> id_to_index(batch_size); |
nothing calls this directly
no test coverage detected