| 402 | } // namespace |
| 403 | |
| 404 | Status GraphView::SetAllocAttrs(const Graph* g, const Device* device) { |
| 405 | Status s; |
| 406 | DeviceNameUtils::ParsedName local_dev_name = device->parsed_name(); |
| 407 | |
| 408 | std::vector<const Node*> scoped_allocator_instances; |
| 409 | for (const Node* n : g->nodes()) { |
| 410 | NodeItem* item = node(n->id()); |
| 411 | AllocatorAttributes* attrs = item->output_attr_base(); |
| 412 | if (IsScopedAllocator(n)) { |
| 413 | scoped_allocator_instances.push_back(n); |
| 414 | } |
| 415 | |
| 416 | // Examine the out edges of each node looking for special use |
| 417 | // cases that may affect memory allocation attributes. |
| 418 | for (const auto& e : n->out_edges()) { |
| 419 | if (!e->IsControlEdge()) { |
| 420 | AllocatorAttributes attr; |
| 421 | s = InferAllocAttr(n, e->dst(), local_dev_name, &attr); |
| 422 | if (!s.ok()) return s; |
| 423 | if (attr.value != 0 || attr.scope_id != 0) { |
| 424 | attrs[e->src_output()].Merge(attr); |
| 425 | } |
| 426 | } |
| 427 | } |
| 428 | |
| 429 | for (int out = 0; out < n->num_outputs(); out++) { |
| 430 | const OpKernel* op_kernel = item->kernel; |
| 431 | DCHECK_LT(out, op_kernel->output_memory_types().size()); |
| 432 | bool on_host = op_kernel->output_memory_types()[out] == HOST_MEMORY; |
| 433 | if (on_host) { |
| 434 | AllocatorAttributes h; |
| 435 | h.set_on_host(on_host); |
| 436 | attrs[out].Merge(h); |
| 437 | } |
| 438 | } |
| 439 | } |
| 440 | SetScopedAllocatorAttrs(scoped_allocator_instances); |
| 441 | return s; |
| 442 | } |
| 443 | |
| 444 | } // namespace tensorflow |
| 445 |
no test coverage detected