EPFL-LAP / dynamatic

DHLS (Dynamic High-Level Synthesis) compiler based on MLIR
Other
49 stars 14 forks source link

[Speculation] Add a basic Pass that reads from a JSON file #60

Closed asleix closed 7 months ago

asleix commented 8 months ago

Speculative execution involves speculating on the output of a long latency operation or chain of operations, allowing operations that depend on it to begin execution early, without impacting correctness.

The pass HandshakeSpeculation is implemented, which places the Speculation Operations according to the positions specified in an input JSON file. A helper class called SpeculationPlacements holds the placement information and implements the JSON parser.

This pull-request (PR) includes the basic structure and some dummy connections, and will be followed by 1-2 PRs implementing more features. The idea is the following.

PR 1 (this one). The pass will place the units according to an input JSON file, and use simple connections. PR 2. Use the correct control path for connecting Commits and SaveCommits. Still read position from JSON. PR 3. If no JSON is provided, automatically choose the positions for placing the units.

The work for PR2 and PR3 is mostly done and being tested. The split into smaller merges should help reviewing. I will wait for PR1 to be merged to create PR2 and PR3.

The pass can be run with dynamatic-opt input.mlir --handshake-speculation="unit-positions=positions.json"An input JSON should have the following format. This example can be used in the handshake IR of integration-test/fir.

{
  "speculator": {"srcOp": "cmpi0", "dstOp":"fork5"},
  "saves": [
    {"srcOp": "extsi6", "dstOp":"mc_load0"},
    {"srcOp": "extsi7", "dstOp":"mc_load1"}
  ],
  "commits": [
    {"srcOp": "trunci0", "dstOp":"cond_br0"}
  ],
  "saveCommits": [
    {"srcOp": "mux1", "dstOp":"buffer10"}
  ]
}

For PR2, example JSON files will be explicitly added because they will be needed for unit tests of the pass.

Important: A newer version of CIRCT is required for this to work https://github.com/EPFL-LAP/circt/pull/1.

asleix commented 8 months ago

Thanks a lot for the very detailed review!

I have added three commits to address all the comments.

Here is an example of the new JSON format (it's the same example I shared in the previous format).

{
  "speculator": {
    "operation-name": "fork5",
    "operand-idx": 0
  },
  "saves": [
    {
      "operation-name": "mc_load0",
      "operand-idx": 0
    },
    {
      "operation-name": "mc_load1",
      "operand-idx": 0
    }
  ],
  "commits": [
    {
      "operation-name": "cond_br0",
      "operand-idx": 1
    }
  ],
  "save-commits": [
    {
      "operation-name": "buffer10",
      "operand-idx": 0
    }
  ]
}

I think I addressed all the comments. Please tell me if I missed anything.

lucas-rami commented 7 months ago

I have just merged your CIRCT PR on main, so you can now include the new CIRCT commit in this PR :)

asleix commented 7 months ago

I implemented your latest comments and updated the CIRCT branch. I also merged the main branch and checked that the pass worked. And I want to let you know that I have prepared unit tests that I will include in the second PR for this project. Thanks for your quick feedback!