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

Function SelectDevice

tensorflow/core/common_runtime/eager/execute.cc:226–290  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

224}
225
226Status SelectDevice(EagerOperation* op, const NodeDef& ndef, EagerContext* ctx,
227 Device** device) {
228 std::vector<Device*> final_devices;
229 PrioritizedDeviceTypeVector supported_devs;
230 TF_RETURN_IF_ERROR(SupportedDeviceTypesForNode(
231 ctx->prioritized_device_type_list(), ndef, &supported_devs,
232 &ctx->HostCPU()->parsed_name()));
233 if (supported_devs.empty()) {
234 return errors::NotFound("Could not find valid device for node.\nNode:",
235 FormatNodeDefForError(ndef),
236 "\nAll kernels registered for op ", ndef.op(),
237 " :\n", KernelsRegisteredForOp(ndef.op()));
238 }
239
240 if (DeviceNameUtils::HasSomeDetails(op->GetDeviceName())) {
241 ctx->pflr()->device_set()->FindMatchingDevices(op->GetDeviceName(),
242 &final_devices);
243
244 if (!final_devices.empty()) {
245 final_devices = ColocationGraph::FilterSupportedDevices(
246 final_devices, supported_devs, /*default_device=*/nullptr);
247 }
248
249 if (final_devices.empty() && ctx->AllowSoftPlacement()) {
250 DeviceNameUtils::ParsedName soft_device_name = op->GetDeviceName();
251 soft_device_name.type.clear();
252 soft_device_name.has_type = false;
253 soft_device_name.has_id = false;
254 // TODO(fishx): Soft placement logic picks up another task if the
255 // requested does not exist.
256 ctx->pflr()->device_set()->FindMatchingDevices(soft_device_name,
257 &final_devices);
258 if (!final_devices.empty()) {
259 final_devices = ColocationGraph::FilterSupportedDevices(
260 final_devices, supported_devs, /*default_device=*/nullptr);
261 }
262 }
263 if (final_devices.empty()) {
264 return errors::InvalidArgument(
265 "Could not satisfy device specification '", op->GetDeviceName(),
266 "'. All available devices [",
267 absl::StrJoin(DevicesToString(ctx->pflr()->device_set()->devices()),
268 ", "),
269 "]. Eager operation: ", op->DebugString());
270 }
271 } else {
272 // TODO(fishx): Allow setting default device in eager context.
273 final_devices = ColocationGraph::FilterSupportedDevices(
274 ctx->pflr()->device_set()->devices(), supported_devs,
275 /*default_device=*/nullptr);
276 if (final_devices.empty()) {
277 return errors::InvalidArgument(
278 "No OpKernel registered to suppport this eager operation:",
279 op->DebugString());
280 }
281 }
282
283 VLOG(1) << "Placer place op [" << op->Name()

Callers 1

EagerLocalExecuteFunction · 0.85

Calls 15

NotFoundFunction · 0.85
FormatNodeDefForErrorFunction · 0.85
KernelsRegisteredForOpFunction · 0.85
InvalidArgumentFunction · 0.85
HostCPUMethod · 0.80
FindMatchingDevicesMethod · 0.80
device_setMethod · 0.80
DevicesToStringFunction · 0.70
nameMethod · 0.65
emptyMethod · 0.45
opMethod · 0.45

Tested by

no test coverage detected