Takes in a list of nets. They usually represent your whole execution graph. This function will insert cross device copy functions to all nets, and resolve inter-net external inputs dependencies. This method will insert Copy funcitons if external inputs of a net is produced on differ
(nets, blob_to_device_init=None)
| 2597 | |
| 2598 | |
| 2599 | def InjectDeviceCopiesAmongNets(nets, blob_to_device_init=None): |
| 2600 | """ |
| 2601 | Takes in a list of nets. They usually represent your whole execution graph. |
| 2602 | This function will insert cross device copy functions to all nets, and resolve |
| 2603 | inter-net external inputs dependencies. This method will insert Copy funcitons if |
| 2604 | external inputs of a net is produced on different device than it is required. |
| 2605 | Inputs: |
| 2606 | nets: a list of nets |
| 2607 | Outputs: |
| 2608 | new_nets: a list of new nets with device difference solved. |
| 2609 | |
| 2610 | Some notes from wyiming: |
| 2611 | 1. You MUST pass nets in execution order. e.g. [train_init, train] |
| 2612 | """ |
| 2613 | assert isinstance(nets, list), \ |
| 2614 | "nets {} should be a list of nets.".format(str(nets)) |
| 2615 | assert all(isinstance(net, Net) for net in nets), \ |
| 2616 | "nets {} should be a list of nets.".format(str(nets)) |
| 2617 | # A holistic blob to device mapping. |
| 2618 | blob_to_device = blob_to_device_init or {} |
| 2619 | blob_remap = {} |
| 2620 | new_nets = [] |
| 2621 | |
| 2622 | for net in nets: |
| 2623 | new_net, blob_to_device = InjectCrossDeviceCopies( |
| 2624 | net, |
| 2625 | blob_to_device=blob_to_device, |
| 2626 | blob_remap=blob_remap, |
| 2627 | ) |
| 2628 | new_nets.append(new_net) |
| 2629 | |
| 2630 | return new_nets, blob_to_device |
| 2631 | |
| 2632 | |
| 2633 | def InjectDeviceCopiesAmongNetsWithoutB2D(nets, blob_to_device_init=None): |
no test coverage detected
searching dependent graphs…