daphne-project / daphne-project/daphne

Towards a very initial integration of computational storage features

Open
#656 26 comments 0 reactions 0 assignees View on GitHub
Discussion
Dominant language
C++
Stars
81
Forks
83
PR merge metrics
No merged PRs in 30d

Description

@niclashedam and I have recently discussed how we could approach an *initial integration* of some first computational storage features into DAPHNE. *The focus is on where to add/change what in the DAPHNE code base.* For now, it's really just about an initial integration, there may be better ways to achieve it and we can surely refine and extend it in the future. Here is a summary:

### Idea/goals
- a C/C++ kernel that pushes certain pre-defined sequences/DAGs of operations down to computational storage
- should support an arbitrary number of inputs (matrices/frames/scalars) and outputs
- should be generic w.r.t. the concrete DAG of ops to push down, multiple such DAG/functions could be registered, they should be selected by an additional parameter
- should be usable from DaphneDSL
- question: how can we achieve this in DAPHNE?

### Disclaimer
- the goal is to give some pointers to (most of) the decisive points in the code base
- most of the following steps should be copy-paste-adapt of existing code snippets, at some points there will also be some additional work
- overall, I hope this will be helpful to get started

### Suggested steps
- **add new DaphneIR (MLIR) operation (say, `CompStorageOp`)**
- see `src/ir/daphneir/DaphneOps.td`
- this is where all DaphneIR operations (that the DAPHNE compiler can reason about) are defined in [MLIR’s Operation Definition Specification](https://mlir.llvm.org/docs/DefiningDialects/Operations/)
- the new op should have variadic arguments and results, such that it can replace any DAG of operations
- furthermore, the op should get the information for which function registered in computational storage it should execute (could be just an integer code or string name, to begin with)
- take inspiration from `VectorizedPipelineOp` and `DistributedPipelineOp`, probably the most similar ones to your needs
- **add a new compiler pass that can replace a DAG of operations by a `CompStorageOp`**
- new pass
- take inspiration from existing lowering passes in `src/compiler/lowering/`
- e.g., `RewriteSqlOpPass` is a relatively simple pass that replaces certain ops by other ops
- for the identification of the operation DAGs, take inspiration from the [canonicalize methods](https://mlir.llvm.org/docs/Canonicalization/) in `src/ir/daphneir/DaphneDialect.cpp`
- idea: to match A(B(C), D)
- check if the given op is an A-op
- if so
- check if the first operand is a B-op, and if so, if its operand is a C-op
- check if the second operand is a D-op
- if that all holds, replace the A-op by your `CompStorageOp` (no need to erase any operations, they will be clearer away automatically later, if not needed elsewhere)
- add pass to pass pipeline
- the pass pipeline is defined in `src/compiler/execution/DaphneIrExecutor.cpp`
- just before the vectorization pass (`createVectorizeComputationsPass`) could be a good place for the beginning (the integration with vectorization can be discussed later)
- add config flags for turning the pass on/off and for printing the IR after the pass for debugging (optional)
- several passes have such flags, take inspiration from, e.g., the vectorization pass
- relevant for the config
- definition: `src/parser/config/JsonParams.h`, `src/parser/config/ConfigParser.cpp`, `src/api/cli/DaphneUserConfig.h`, `UserConfig.json`
- CLI args: `src/api/internal/daphne_internal.cpp`
- usage (add the pass if flag in on, print the IR afterwards if flag is on): `src/compiler/execution/DaphneIrExecutor.cpp`
- [partly documented](https://daphne-eu.github.io/daphne/Config/)
- **lowering `CompStorageOp` to a kernel call**
- see `src/compiler/lowering/RewriteToCallKernelOpPass.cpp`
- domain-specific DaphneIR ops are lowered to DaphneIR’s `CallKernelOp`, which still has the same arguments and results, but gets the name of the C function to call as the first argument, plus the `DaphneContext` as the last argument
- those C functions can be found in `build/src/runtime/local/kernels/kernels.cpp` (generated as part of the DAPHNE build process)
- you need to make sure that your kernel get pre-compiled, too (see below)
- support your new `CompStorageOp` in `getNumODSOperands()` and `getODSOperandInfo()`, such that the pass knows how to correctly handle the variadic arguments of the op
- supporting variadic results could require some extra work
- either try it with just a single result first
- or take inspiration from `DistributedPipelineKernelReplacement`
- **kernel for `CompStorageOp`**
- write the kernel
- interface/boilerplate
- writing a kernel is [mostly documented](https://daphne-eu.github.io/daphne/development/ImplementBuiltinKernel/)
- take inspiration from vectorized pipeline kernel: `src/runtime/local/kernels/VectorizedPipeline.h`
- contents
- your specific code to offload the computation to computational storage
- register the kernel for pre-compilation
- see `src/runtime/local/kernels/kernels.json`
- take inspiration from `VectorizedPipeline`-kernel
- this file contains the interfaces etc. of all kernels we want to pre-compile such that we can use them from the JIT-compiled DaphneDSL script
- compilation chain
- maybe you need to adapt the C++ compilation chain to link with any libs you require
- see, e.g., `src/runtime/local/kernels/CMakeLists.txt`

Contributor guide

Open the contributing guide

Research direction

Start with src/ir/daphneir/DaphneOps.td and the VectorizedPipelineOp or DistributedPipelineOp definitions, then inspect the lowering passes under src/compiler/lowering/ and the pipeline in src/compiler/execution/DaphneIrExecutor.cpp. Review RewriteToCallKernelOpPass.cpp, src/runtime/local/kernels/VectorizedPipeline.h, kernels.json, and CMakeLists.txt; done means a registered computational-storage operation can be selected from DaphneDSL, lowered to a callable precompiled kernel, and tested through the compiler pipeline.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
backend-api-design, compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.