| 243 | } |
| 244 | |
| 245 | Status GraphView::Initialize(const Graph* g) { |
| 246 | CHECK(node_offsets_ == nullptr); |
| 247 | const int num_nodes = g->num_node_ids(); |
| 248 | num_nodes_ = num_nodes; |
| 249 | size_t total_bytes = 0; |
| 250 | for (const Node* n : g->nodes()) { |
| 251 | if (n->out_edges().size() > kint32max) { |
| 252 | return errors::InvalidArgument( |
| 253 | "The executor cannot handle nodes with more than ", kint32max, |
| 254 | " output edges. Node ", n->name(), " had ", n->out_edges().size(), |
| 255 | " output edges."); |
| 256 | } |
| 257 | total_bytes += NodeItemBytes(n); |
| 258 | } |
| 259 | |
| 260 | node_offsets_ = new uint32[num_nodes]; |
| 261 | for (int i = 0; i < num_nodes; i++) { |
| 262 | node_offsets_[i] = kuint32max; |
| 263 | } |
| 264 | |
| 265 | space_ = new char[total_bytes]; // NodeItem objects are allocated here |
| 266 | char* ptr = space_; |
| 267 | for (const Node* n : g->nodes()) { |
| 268 | ptr = InitializeNode(ptr, n); |
| 269 | } |
| 270 | CHECK_EQ(ptr, space_ + total_bytes); |
| 271 | return Status::OK(); |
| 272 | } |
| 273 | |
| 274 | namespace { |
| 275 | // If a Node has been marked to use a ScopedAllocator x for output i, then |