-
Notifications
You must be signed in to change notification settings - Fork 701
Allow Compilation without Collecting Constants #2246
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; | ||
|
||
|
|
||
| /// 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()); | ||
|
||
| } | ||
|
|
||
| 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; | ||
|
||
|
|
||
| std::unique_ptr<CompiledFunction> compile(Function *F) const override; | ||
|
|
||
| std::unique_ptr<CompiledFunction> | ||
|
||
| 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)); | ||
| } | ||
|
||
|
|
||
| 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> | ||
|
||
| 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(); } | ||
|
||
| ///@} | ||
|
|
||
| private: | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.