Glow: Separate HAL, temporary state, and compiled functions

Created on 9 Jul 2018  路  1Comment  路  Source: pytorch/glow

This is part of the Backend refactoring in #1227.

The goal is to have the Backend sub-classes represent the hardware abstraction layer. The instances hold no mutable state, and all actions are performed through const virtual functions.

Proposed interface:

class Backend {
  virtual bool transformPreLowering(Function *F, CompilationMode mode) const;
  virtual bool transformPostLowering(Function *F, CompilationMode mode) const;
  virtual bool isOpSupported(Kinded::Kind opKind, ElemKind elementTy) const;
  virtual bool shouldLower(const Node *N) const;
  virtual bool shouldShareBuffers() const;

  /// Compile an IR function, consuming it in the process.
  /// Returns a new object representing the compiled function.
  virtual unique_ptr<CompiledFunction> compileFunction(unique_ptr<IRFunction>) const;
}

class CompiledFunction {
  virtual void execute() =0;
}

Refactoring steps:

  • Change transformPreLowering and friends to be const.
  • Create a CompiledFunction sub-class per backend which holds the result of compiling a function.
  • Move remaining temporary compilation state out of the Backend sub-classes into a locally defined class that only exists during compileFunction().
  • Remove the IRFunction pointer from backend instances and the createBackend() function.

At this stage, the CompiledFunction sub-classes will still reference the original module, and their execute method can modify variables in the module.

Most helpful comment

I believe this is done; Backend is now a pure stateless abstraction layer.

>All comments

I believe this is done; Backend is now a pure stateless abstraction layer.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

georgeokelly picture georgeokelly  路  4Comments

pjaaskel picture pjaaskel  路  4Comments

speryt picture speryt  路  3Comments

rdzhabarov picture rdzhabarov  路  4Comments

qcolombet picture qcolombet  路  5Comments