Skip to content

Commit

Permalink
cleaned up comments, changed function parameter to reference
Browse files Browse the repository at this point in the history
  • Loading branch information
gcatron committed Nov 16, 2018
1 parent 590254f commit 80d92a4
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 18 deletions.
2 changes: 1 addition & 1 deletion include/glow/Backends/BackendUtils.h
Expand Up @@ -38,7 +38,7 @@ getValueOffset(Value *v,
/// Computes offsets and total allocation for Constants, Placeholders, and
/// Activations to build runtime symbol table. Returns RuntimeBundle.
runtime::RuntimeBundle
generateRuntimeBundle(const IRFunction *F, MemoryAllocator *constantAllocator,
generateRuntimeBundle(const IRFunction &F, MemoryAllocator *constantAllocator,
MemoryAllocator *placeholderAllocator,
MemoryAllocator *activationsAllocator);
} // end namespace glow
Expand Down
22 changes: 11 additions & 11 deletions lib/Backends/BackendUtils.cpp
Expand Up @@ -57,22 +57,22 @@ size_t glow::getValueOffset(
}

runtime::RuntimeBundle
glow::generateRuntimeBundle(const IRFunction *F,
glow::generateRuntimeBundle(const IRFunction &F,
MemoryAllocator *constantAllocator,
MemoryAllocator *placeholderAllocator,
MemoryAllocator *activationsAllocator) {
// Handle Constants, Placeholders, and Activations, in that order.
/// Symbol table mapping symbol name to offset for runtime.
// Symbol table mapping symbol name to offset for runtime.
std::unordered_map<std::string, runtime::RuntimeSymbolInfo> symbolTable;
uint64_t constantMaxSize = 0;
uint64_t placeholderMaxSize = 0;
uint64_t activationsMaxSize = 0;

// Compute the offsets for Constants.
if (constantAllocator) {
for (auto &v : F->getGraph()->getParent()->getConstants()) {
assert(isa<WeightVar>(F->getWeightForNode(v)) && "Expected WeightVar");
auto *w = cast<WeightVar>(F->getWeightForNode(v));
for (auto &v : F.getGraph()->getParent()->getConstants()) {
assert(isa<WeightVar>(F.getWeightForNode(v)) && "Expected WeightVar");
auto *w = cast<WeightVar>(F.getWeightForNode(v));
auto numBytes = w->getSizeInBytes();
size_t addr = constantAllocator->allocate(numBytes, v);
runtime::RuntimeSymbolInfo symbol;
Expand All @@ -86,10 +86,10 @@ glow::generateRuntimeBundle(const IRFunction *F,

// Compute the offsets for Placeholders.
if (placeholderAllocator) {
for (auto &v : F->getGraph()->getParent()->getPlaceholders()) {
for (auto &v : F.getGraph()->getParent()->getPlaceholders()) {
// Get the WeightVar for each Placeholder to calculate offsets.
assert(isa<WeightVar>(F->getWeightForNode(v)) && "Expected WeightVar");
auto *w = cast<WeightVar>(F->getWeightForNode(v));
assert(isa<WeightVar>(F.getWeightForNode(v)) && "Expected WeightVar");
auto *w = cast<WeightVar>(F.getWeightForNode(v));
auto numBytes = w->getSizeInBytes();
size_t addr = placeholderAllocator->allocate(numBytes, w);
runtime::RuntimeSymbolInfo symbol;
Expand All @@ -102,7 +102,7 @@ glow::generateRuntimeBundle(const IRFunction *F,
}
// Compute the offsets for Activations.
if (activationsAllocator) {
for (const auto &I : F->getInstrs()) {
for (const auto &I : F.getInstrs()) {
if (auto *A = llvm::dyn_cast<AllocActivationInst>(&I)) {
auto numBytes = I.getSizeInBytes();
size_t addr = activationsAllocator->allocate(numBytes, A);
Expand Down Expand Up @@ -154,6 +154,6 @@ glow::generateRuntimeBundle(const IRFunction *F,
runtime::RuntimeBundle info(constantMaxSize, placeholderMaxSize,
activationsMaxSize);
info.symbolTable = std::move(symbolTable);
info.constants = collectConstants(F, constantMaxSize, info.symbolTable);
info.constants = collectConstants(&F, constantMaxSize, info.symbolTable);
return info;
}
}
5 changes: 2 additions & 3 deletions lib/Backends/CPU/CPUBackend.cpp
Expand Up @@ -118,9 +118,8 @@ CPUBackend::compileIR(std::unique_ptr<IRFunction> IR) const {
MemoryAllocator constantAllocator("ConstantWeights", 0);
MemoryAllocator placeholderAllocator("Placeholders", 0);
MemoryAllocator activationsAllocator("Activations", 0);
runtime::RuntimeBundle runtimeInfo =
generateRuntimeBundle(IR.get(), &constantAllocator, &placeholderAllocator,
&activationsAllocator);
runtime::RuntimeBundle runtimeInfo = generateRuntimeBundle(
*IR, &constantAllocator, &placeholderAllocator, &activationsAllocator);
return llvm::make_unique<CPUFunction>(std::move(JIT), runtimeInfo);
}

Expand Down
4 changes: 2 additions & 2 deletions lib/Backends/Interpreter/Interpreter.cpp
Expand Up @@ -32,8 +32,8 @@ std::unique_ptr<CompiledFunction> Interpreter::compile(Function *F) const {
std::unique_ptr<CompiledFunction>
Interpreter::compileIR(std::unique_ptr<IRFunction> IR) const {
MemoryAllocator constantWeightsAllocator("ConstantWeights", 0);
runtime::RuntimeBundle bundle = generateRuntimeBundle(
IR.get(), &constantWeightsAllocator, nullptr, nullptr);
runtime::RuntimeBundle bundle =
generateRuntimeBundle(*IR, &constantWeightsAllocator, nullptr, nullptr);
return llvm::make_unique<InterpreterFunction>(std::move(IR), bundle);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Backends/OpenCL/OpenCL.cpp
Expand Up @@ -1521,7 +1521,7 @@ std::unique_ptr<CompiledFunction>
OCLBackend::compileIR(std::unique_ptr<IRFunction> IR) const {
MemoryAllocator allocator("GPU", 0xFFFFFFFF);
runtime::RuntimeBundle bundle =
generateRuntimeBundle(IR.get(), &allocator, &allocator, &allocator);
generateRuntimeBundle(*IR, &allocator, &allocator, &allocator);
return llvm::make_unique<OpenCLFunction>(std::move(IR), bundle);
}

Expand Down

0 comments on commit 80d92a4

Please sign in to comment.