-
Notifications
You must be signed in to change notification settings - Fork 698
Allow Compilation without Collecting Constants #2246
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,6 +43,10 @@ class Backend { | |
/// Generate code for input function \param F. | ||
virtual std::unique_ptr<CompiledFunction> compile(Function *F) const = 0; | ||
|
||
/// Generate code for input function \param F but do not collect constants. | ||
virtual std::unique_ptr<CompiledFunction> | ||
compileWithoutConstants(Function *F) const = 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. where is it invoked? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently nowhere but it will be called from the Provisioner. |
||
|
||
/// Save the bundle for \p F for a later standalone execution | ||
/// in \p outputDir. Make \p networkName the function name for | ||
/// the entry point of the network and prepend all generated | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -99,14 +99,21 @@ CPUBackend::createIRGen(IRFunction *IR, | |
|
||
std::unique_ptr<CompiledFunction> | ||
CPUBackend::compileIR(std::unique_ptr<IRFunction> IR) const { | ||
auto function = compileIRWithoutConstants(IR.get()); | ||
static_cast<CPUFunction *>(function.get())->collectConstants(IR.get()); | ||
return function; | ||
} | ||
|
||
std::unique_ptr<CompiledFunction> | ||
CPUBackend::compileIRWithoutConstants(IRFunction *IR) const { | ||
AllocationsInfo allocationsInfo; | ||
std::unique_ptr<LLVMIRGen> irgen = createIRGen(IR.get(), allocationsInfo); | ||
std::unique_ptr<LLVMIRGen> irgen = createIRGen(IR, allocationsInfo); | ||
irgen->initTargetMachine(target.empty() ? "" : target.getValue(), | ||
llvm::CodeModel::Model::Large); | ||
irgen->initCodeGen(); | ||
// Perform the address assignment for activations and WeightVars. | ||
|
||
allocateJITMemory(IR.get(), irgen->getAllocationsInfo()); | ||
allocateJITMemory(IR, irgen->getAllocationsInfo()); | ||
// Create the jitmain function to be invoked by JIT. | ||
emitJitMain(*irgen); | ||
// Emit the code for the body of the entry function. | ||
|
@@ -128,6 +135,12 @@ std::unique_ptr<CompiledFunction> CPUBackend::compile(Function *F) const { | |
return compileIR(std::move(IR)); | ||
} | ||
|
||
std::unique_ptr<CompiledFunction> | ||
CPUBackend::compileWithoutConstants(Function *F) const { | ||
auto IR = generateAndOptimizeIR(F, shouldShareBuffers()); | ||
return compileIRWithoutConstants(IR.get()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did we come to a conclusion about how There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we decided to make expose collect constants as a method on each compiled function, and keep the bundle_ private. We call collectConstants in CompileIR where we still have the IR. |
||
} | ||
|
||
void CPUBackend::save(Function *F, llvm::StringRef outputDir, | ||
llvm::StringRef networkName) const { | ||
std::string tgt = target.empty() ? "" : target.getValue(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,8 +45,14 @@ class CPUBackend : public BackendUsingGlowIR { | |
std::unique_ptr<CompiledFunction> | ||
compileIR(std::unique_ptr<IRFunction> IR) const override; | ||
|
||
std::unique_ptr<CompiledFunction> | ||
compileIRWithoutConstants(IRFunction *IR) const; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. vertical space b/w top level declarations. |
||
|
||
std::unique_ptr<CompiledFunction> compile(Function *F) const override; | ||
|
||
std::unique_ptr<CompiledFunction> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. vertical space b/w top level declarations. |
||
compileWithoutConstants(Function *F) const override; | ||
|
||
void save(Function *F, llvm::StringRef outputDir, | ||
llvm::StringRef networkName) const override; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,8 +29,22 @@ std::unique_ptr<CompiledFunction> Interpreter::compile(Function *F) const { | |
return compileIR(std::move(IR)); | ||
} | ||
|
||
std::unique_ptr<CompiledFunction> | ||
Interpreter::compileWithoutConstants(Function *F) const { | ||
auto IR = generateAndOptimizeIR(F, shouldShareBuffers()); | ||
return compileIRWithoutConstants(std::move(IR)); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Blank line between definitions. |
||
|
||
std::unique_ptr<CompiledFunction> | ||
Interpreter::compileIR(std::unique_ptr<IRFunction> IR) const { | ||
auto function = compileIRWithoutConstants(std::move(IR)); | ||
auto IFunction = static_cast<InterpreterFunction *>(function.get()); | ||
IFunction->collectConstants(IFunction->getIR()); | ||
return function; | ||
} | ||
|
||
std::unique_ptr<CompiledFunction> | ||
Interpreter::compileIRWithoutConstants(std::unique_ptr<IRFunction> IR) const { | ||
MemoryAllocator constantWeightsAllocator("ConstantWeights", 0); | ||
MemoryAllocator placeholderWeightsAllocator("PlaceholderWeights", 0); | ||
MemoryAllocator activationsAllocator("Activations", 0); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,8 +37,14 @@ class Interpreter final : public BackendUsingGlowIR { | |
std::unique_ptr<CompiledFunction> | ||
compileIR(std::unique_ptr<IRFunction> IR) const override; | ||
|
||
std::unique_ptr<CompiledFunction> | ||
compileIRWithoutConstants(std::unique_ptr<IRFunction> IR) const; | ||
|
||
std::unique_ptr<CompiledFunction> compile(Function *F) const override; | ||
|
||
std::unique_ptr<CompiledFunction> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. More blank lines plz :) |
||
compileWithoutConstants(Function *F) const override; | ||
|
||
bool isOpSupported(Kinded::Kind opKind, ElemKind elementTy) const override; | ||
|
||
bool shouldLower(const Node *N) const override; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,6 +62,10 @@ class InterpreterFunction final : public CompiledFunction { | |
|
||
/// Does any needed initialization work for the Backend, creates tensors from | ||
/// constants. | ||
|
||
/// Collects constants for runtime. | ||
void collectConstants(IRFunction *F); | ||
|
||
void setupRuns() override; | ||
|
||
/// Per run setup, adds references for tensors from \p ctx to | ||
|
@@ -76,6 +80,8 @@ class InterpreterFunction final : public CompiledFunction { | |
void tearDownRuns() override; | ||
|
||
void execute() override; | ||
/// Get reference to IR function. | ||
IRFunction *getIR() { return F_.get(); } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As above, I think adding a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The challenge here is the CPUFunction, it doesn't keep the IR around so it would still need it passed in. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is a good point. Which makes me wonder, how could we even use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, the device manager will have a reference to the module so that is where it can collect constants from. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looking at collectConstants, does it even need to take an IRFunction? It looks like it pulls all the constants from the Module via |
||
///@} | ||
|
||
private: | ||
|
Uh oh!
There was an error while loading. Please reload this page.