Make a program with specified number of stages and "width" ops per stage.
| 122 | |
| 123 | // Make a program with specified number of stages and "width" ops per stage. |
| 124 | GraphDef CreateGraphDef(int num_stages, int width, int tensor_size, |
| 125 | bool use_multiple_devices, const Cluster* cluster) { |
| 126 | CHECK_GE(cluster->devices.size(), width); |
| 127 | |
| 128 | using namespace ::tensorflow::ops; // NOLINT(build/namespaces) |
| 129 | |
| 130 | Scope s = Scope::NewRootScope(); |
| 131 | |
| 132 | // x is from the feed. |
| 133 | Output x = Const(s.WithOpName("x"), 0.0f, {tensor_size, 1}); |
| 134 | |
| 135 | // Create stages. |
| 136 | std::vector<Output> last_stage; |
| 137 | last_stage.push_back(x); |
| 138 | for (int i = 0; i < num_stages; i++) { |
| 139 | std::vector<Output> this_stage; |
| 140 | for (int j = 0; j < width; j++) { |
| 141 | Output combine = AddN( |
| 142 | s.WithDevice(cluster->devices[use_multiple_devices ? j : 0].name()), |
| 143 | last_stage); |
| 144 | this_stage.push_back(combine); |
| 145 | } |
| 146 | last_stage = this_stage; |
| 147 | } |
| 148 | |
| 149 | // Create output. |
| 150 | /* Output y =*/AddN(s.WithOpName("y"), last_stage); |
| 151 | |
| 152 | GraphDef def; |
| 153 | TF_CHECK_OK(s.ToGraphDef(&def)); |
| 154 | return def; |
| 155 | } |
| 156 | |
| 157 | string DebugString(const Tensor& x, const Tensor& y, int tensor_size) { |
| 158 | CHECK_EQ(x.NumElements(), tensor_size); |
no test coverage detected