Skip to content

Conversation

@StoeckOverflow
Copy link
Contributor

This Draft PR introduces a basic recompilation pipeline designed to support recompilation during the execution of loops. The implemented functionality includes:

  1. Recompile Kernel: A C++ kernel that accepts MLIR code as a string, along with variadic inputs and outputs, and recompiles it.
  2. Recompile Pass: A new pass that extracts the loop body of ForOps, feeding it as input to the Recompile Kernel. This allows the loop to be recompiled dynamically at each iteration.

Key Features

  1. Dynamic Loop Recompilation:

    • The Recompile Pass wraps around ForOp loop bodies, triggering recompilation of the loop during execution.
    • Recompilation happens on a per-iteration basis as a proof-of-concept.
  2. Extensible Recompilation Control:

    • Future iterations will allow for configurable recompilation conditions (e.g., recompiling after n iterations or under specific runtime conditions).
    • Potential to customize the PassManager for the RecompileOp to utilize either the full pass pipeline or a subset of it.
  3. Testing:

    • A RecompileOp Kernel Test validates the core functionality of the C++ Recompile Kernel.
    • A script-level test ensures the overall pipeline works end-to-end, testing integration between MLIR and the dynamic recompilation mechanism.

Known Issues

There is currently an issue with the invocation of the recompilation kernel that needs to be resolved. Specifically:

  • Error:
loc("-":5:10): error: 'daphne.cast' op using value defined outside the region
Failed to parse source string.
loc("-":5:10): error: 'daphne.cast' op using value defined outside the region
Failed to parse source string.
[error]: Execution error: The kernel-function _decRef__Structure failed during runtime with the following message [ DataObjectFactory::destroy() must not be called with nullptr ]
   | Source file -> "/home/dominic/daphne/test/api/cli/recompilation/recompilation_for_test_1.daphne":5:14
   | 
 5 | P = (X + Y)*2 + 1e-6;
   |               ^~~
  • Investigation Path:
    This issue appears to be related to how arguments are forwarded to the kernel. A deeper analysis of the LLVM code generated by the program may provide insights into the root cause and potential solutions.

Areas for Further Development

This PR serves as a foundation for exploring the following enhancements:

  1. Recompilation Invocation Logic: Implementing heuristics to decide when recompilation is necessary.
  2. Partial vs. Full Pass Pipeline Execution: Determining whether the PassManager for the RecompileOp should execute the entire pass pipeline or only specific passes.

Additionally:

  • Improve Script-Level Tests: The current script-level tests, while sufficient to verify basic functionality, produce NaN results. Developing more robust and precise tests can better validate the pipeline and help identify edge cases or hidden issues.

Tests and Validation

  1. C++ Recompile Kernel Test:

    • Verifies the Recompile Kernel processes MLIR strings correctly with the given inputs and outputs.
  2. Pipeline Integration Test:

    • Validates the end-to-end functionality of the recompilation pipeline through script-level tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant