| 338 | } |
| 339 | |
| 340 | void XlaLocalLaunchBase::Compute(OpKernelContext* ctx) { |
| 341 | VLOG(1) << "XlaLocalLaunchOpBase::Compute " |
| 342 | << Canonicalize(function_.name(), AttrSlice(&function_.attr())); |
| 343 | |
| 344 | xla::LocalClient* client; |
| 345 | const XlaCompiler::CompilationResult* kernel; |
| 346 | xla::LocalExecutable* executable; |
| 347 | std::map<int, OptionalTensor> variables; |
| 348 | |
| 349 | { |
| 350 | Status s = CompileToLocalExecutable( |
| 351 | ctx, function_, platform_info_, resources_, constants_, /*async=*/false, |
| 352 | /*lazy=*/false, &client, &variables, &kernel, &executable); |
| 353 | if (!s.ok() && (platform_info_.device_type().type_string() == DEVICE_CPU || |
| 354 | platform_info_.device_type().type_string() == DEVICE_GPU)) { |
| 355 | // Suggest auto jit if the failure was with GPU or CPU. |
| 356 | errors::AppendToMessage(&s, |
| 357 | xla::status_macros::kPossibleAutoJitAlternative); |
| 358 | } |
| 359 | |
| 360 | OP_REQUIRES_OK(ctx, s); |
| 361 | } |
| 362 | |
| 363 | se::Stream* stream = |
| 364 | ctx->op_device_context() ? ctx->op_device_context()->stream() : nullptr; |
| 365 | |
| 366 | VLOG(1) << "Executing XLA Computation..."; |
| 367 | |
| 368 | std::shared_ptr<se::DeviceMemoryAllocator> allocator_ptr = |
| 369 | GetAllocator(ctx, platform_info_); |
| 370 | se::DeviceMemoryAllocator* allocator = allocator_ptr.get(); |
| 371 | XlaComputationLaunchContext launch_context( |
| 372 | client, allocator, |
| 373 | /*allocate_xla_tensors=*/platform_info_.is_on_xla_device(), |
| 374 | platform_info_.UseMultipleStreams()); |
| 375 | launch_context.PopulateInputs(ctx, kernel, variables, |
| 376 | /*missing_ctx_input_prefix=*/0); |
| 377 | |
| 378 | // Execute the computation. |
| 379 | VLOG(2) << "Executing computation."; |
| 380 | xla::ExecutableRunOptions run_options; |
| 381 | run_options.set_stream(stream); |
| 382 | run_options.set_allocator(allocator); |
| 383 | run_options.set_intra_op_thread_pool(&ctx->eigen_cpu_device()); |
| 384 | run_options.set_rng_seed(GetXLARandomSeed()); |
| 385 | xla::ThenExecuteFunction then_execute; |
| 386 | if (ctx->op_device_context()) { |
| 387 | then_execute = [&](se::Stream* stream, std::function<void()> fn) { |
| 388 | Status status = ctx->op_device_context()->ThenExecute( |
| 389 | static_cast<Device*>(ctx->device()), stream, std::move(fn)); |
| 390 | if (!status.ok()) { |
| 391 | // This should never happen. |
| 392 | LOG(ERROR) << "ThenExecute failed " << status; |
| 393 | } |
| 394 | }; |
| 395 | run_options.set_then_execute_function(&then_execute); |
| 396 | } |
| 397 | Env* env = Env::Default(); |
nothing calls this directly
no test coverage detected