MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / ComputeAsync

Method ComputeAsync

tensorflow/core/kernels/function_ops.cc:310–416  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

308}
309
310void RemoteCallOp::ComputeAsync(OpKernelContext* ctx, DoneCallback done) {
311 FunctionLibraryRuntime* lib = ctx->function_library();
312 OP_REQUIRES_ASYNC(ctx, lib != nullptr,
313 errors::Internal("No function library is provided."), done);
314
315 const string& source_device = lib->device()->name();
316 const Tensor* target;
317 OP_REQUIRES_OK_ASYNC(ctx, ctx->input("target", &target), done);
318 string target_device;
319 OP_REQUIRES_OK_ASYNC(
320 ctx,
321 DeviceNameUtils::CanonicalizeDeviceName(target->scalar<tstring>()(),
322 source_device, &target_device),
323 done);
324
325 AttrValueMap attr_values = func_.attr();
326
327 FunctionLibraryRuntime::InstantiateOptions instantiate_opts;
328 // TODO(b/141576771): Propagate ctxt's ConfigProto into opts.config_proto.
329 instantiate_opts.target = target_device;
330
331 FunctionTarget function_target = {target_device, lib};
332
333 FunctionLibraryRuntime::Handle handle;
334 {
335 mutex_lock l(mu_);
336 auto cached_entry = handle_cache_.find(function_target);
337 if (cached_entry != handle_cache_.end()) {
338 handle = cached_entry->second;
339 } else {
340 VLOG(1) << "Instantiating " << func_.name() << " on " << target_device;
341 profiler::TraceMe activity(
342 [&] {
343 return strings::StrCat("RemoteCall: Instantiate: ", func_.name(),
344 " on ", target_device);
345 },
346 profiler::TraceMeLevel::kInfo);
347 OP_REQUIRES_OK_ASYNC(
348 ctx,
349 lib->Instantiate(func_.name(), AttrSlice(&attr_values),
350 instantiate_opts, &handle),
351 done);
352 auto insert_result = handle_cache_.insert({function_target, handle});
353 CHECK(insert_result.second) << "Insert unsuccessful.";
354 VLOG(1) << "Instantiated " << func_.name() << " on " << target_device
355 << ", resulting in handle: " << handle << " flr: " << lib;
356 }
357 }
358
359 OpInputList arguments;
360 OP_REQUIRES_OK_ASYNC(ctx, ctx->input_list("args", &arguments), done);
361
362 FunctionLibraryRuntime::Options opts;
363 opts.runner = ctx->runner();
364 opts.source_device = source_device;
365 if (opts.source_device != target_device) {
366 opts.remote_execution = true;
367 }

Callers

nothing calls this directly

Calls 15

InternalFunction · 0.85
AttrSliceClass · 0.85
DataTypeAlwaysOnHostFunction · 0.85
attrMethod · 0.80
set_on_hostMethod · 0.80
nameMethod · 0.65
StrCatFunction · 0.50
function_libraryMethod · 0.45
deviceMethod · 0.45
inputMethod · 0.45
findMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected