Placer爲C++類,聲明在頭文件:tensorflow-r1.14\tensorflow\core\common_runtime\placer.h。
看註釋就知道此類的功能了。
// A placement algorithm that assigns the nodes of the given Graph to
// devices the given DeviceSet, respecting the following constraints:
//
// 1. Existing device assignments remain unchanged.
// 2. Requested (partial or complete) device specifications given by device name
// for each node are granted.
// 3. Nodes connected by edges of a reference type are colocated on
// the same device.
// 4. Given nodes "A" and "B", if node "B" has a colocation group
// "@loc:A", nodes "A" and "B" will be colocated on the same device.
//
// The implementation builds a constraint graph with the same set of
// nodes, and edges that represent colocation constraints between
// nodes. Each connected component in the resulting constraint graph
// is then assigned to a set of valid devices.
//
// Run() will finally assign the device to each node given the list of
// possible devices.
//
// TODO(mrry): "Soft" constraints, such as "place node 'x' as close as
// possible to node 'y' while respecting the other constraints"?
// TODO(mrry): Create a common interface for this and the other
// placement algorithms so that they may be injected into the graph
// builder.
class Placer {
public:
// Creates an instance of the Placer algorithm for the given
// Graph "graph" (nodes in which may or may not be assigned) on the
// given DeviceSet "devices".
// "function_name" should be set to the name of the function whose body is
// represented by "graph". If "graph" is not representing a function body,
// "function_name" should be empty.
//
// If non-null, default_device is used where possible as a placement for nodes
// which do not have a device specified, ahead of other devices which would
// otherwise be higher priority.
//
// The "graph", "devices", and "default_device" pointer arguments are borrowed
// by this Placer, and must outlive it.