Skip to content

Commit

Permalink
[runtime] Build runtime bundle with only Function (no IR) (pytorch#2611)
Browse files Browse the repository at this point in the history
  • Loading branch information
bertmaher authored Mar 29, 2019
1 parent 0e92a7d commit c5d2d7a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
6 changes: 6 additions & 0 deletions include/glow/Backends/BackendUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,11 @@ generateRuntimeBundle(const IRFunction &F, MemoryAllocator &constantAllocator,
MemoryAllocator &placeholderAllocator,
MemoryAllocator &activationsAllocator);

/// Build a runtime symbol table from a Function. Computes Constant and
/// Placeholder sizes, but not Activations, since Functions are unserialized.
/// Only use this method to generate bundles for backends that do not use
/// Glow's IR.
runtime::RuntimeBundle generateRuntimeBundle(const Function *F);

} // end namespace glow
#endif // GLOW_BACKENDS_BACKENDUTILS_H
33 changes: 33 additions & 0 deletions lib/Backends/BackendUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,39 @@ runtime::RuntimeBundle::getSymbolInfo(const Named *v) const {
return it->second;
}

runtime::RuntimeBundle glow::generateRuntimeBundle(const Function *F) {
std::unordered_map<std::string, runtime::RuntimeSymbolInfo> symbolTable;

MemoryAllocator constants("constants", 0);
MemoryAllocator placeholders("placeholders", 0);

// Allocate constants.
for (auto const *V : F->getParent()->getConstants()) {
auto size = V->getType()->getSizeInBytes();
auto offset = constants.allocate(size, V);
runtime::RuntimeSymbolInfo symbol;
symbol.offset = offset;
symbol.size = size;
symbol.type = *V->getType();
symbolTable.emplace(V->getName(), symbol);
}

// Allocate placeholders.
for (auto const *V : F->getParent()->getPlaceholders()) {
auto size = V->getType()->getSizeInBytes();
auto offset = placeholders.allocate(size, V);
runtime::RuntimeSymbolInfo symbol;
symbol.offset = offset;
symbol.size = size;
symbol.type = *V->getType();
symbolTable.emplace(V->getName(), symbol);
}

return runtime::RuntimeBundle(symbolTable, constants.getMaxMemoryUsage(),
placeholders.getMaxMemoryUsage(),
/*activationsMaxSize*/ 0);
}

runtime::RuntimeBundle
glow::generateRuntimeBundle(const IRFunction &F,
MemoryAllocator &constantAllocator,
Expand Down

0 comments on commit c5d2d7a

Please sign in to comment.