| 298 | } |
| 299 | |
| 300 | void Compute(OpKernelContext* context) override { |
| 301 | OpInputList indices_list_in; |
| 302 | OP_REQUIRES_OK(context, context->input_list("indices", &indices_list_in)); |
| 303 | OpInputList values_list_in; |
| 304 | OP_REQUIRES_OK(context, context->input_list("values", &values_list_in)); |
| 305 | OpInputList shapes_list_in; |
| 306 | OP_REQUIRES_OK(context, context->input_list("shapes", &shapes_list_in)); |
| 307 | OpInputList dense_list_in; |
| 308 | OP_REQUIRES_OK(context, |
| 309 | context->input_list("dense_inputs", &dense_list_in)); |
| 310 | |
| 311 | ValidateInput(context, indices_list_in, values_list_in, shapes_list_in, |
| 312 | dense_list_in); |
| 313 | |
| 314 | std::vector<std::unique_ptr<ColumnInterface<InternalType>>> columns = |
| 315 | GenerateColumnsFromInput(indices_list_in, values_list_in, |
| 316 | shapes_list_in, dense_list_in); |
| 317 | |
| 318 | typename CrossTraits<HASHED_OUTPUT, InternalType>::Crosser crosser( |
| 319 | columns, num_buckets_, hash_key_); |
| 320 | Tensor* indices_out; |
| 321 | Tensor* values_out; |
| 322 | Tensor* shape_out; |
| 323 | const int64 batch_size = CalculateBatchSize(shapes_list_in, dense_list_in); |
| 324 | std::vector<int64> output_start_indices(batch_size); |
| 325 | CreateOutputTensors(columns, batch_size, context, &indices_out, &values_out, |
| 326 | &shape_out, &output_start_indices); |
| 327 | |
| 328 | typename CrossTraits<HASHED_OUTPUT, InternalType>::Updater updater( |
| 329 | output_start_indices, indices_out, values_out); |
| 330 | auto do_work = [&columns, crosser, updater](int64 begin, int64 end) { |
| 331 | for (int b = begin; b < end; b++) { |
| 332 | ProductIterator<InternalType> product_iterator(columns, b); |
| 333 | int64 cross_count = 0; |
| 334 | while (product_iterator.HasNext()) { |
| 335 | const auto permutation = product_iterator.Next(); |
| 336 | updater.Update(b, cross_count, crosser.Generate(b, permutation)); |
| 337 | cross_count++; |
| 338 | } |
| 339 | } |
| 340 | }; |
| 341 | |
| 342 | auto* worker_threads = context->device()->tensorflow_cpu_worker_threads(); |
| 343 | // TODO(zakaria): optimize kCostPerUnit |
| 344 | const int kCostPerUnit = 5000 * indices_list_in.size(); |
| 345 | Shard(worker_threads->num_threads, worker_threads->workers, batch_size, |
| 346 | kCostPerUnit, do_work); |
| 347 | } |
| 348 | |
| 349 | private: |
| 350 | // Validates input tensors. |
nothing calls this directly
no test coverage detected