(Final Submission): 987 mnc sketch implemenation #1000
Conversation
…se matrix example
pdamme
left a comment
There was a problem hiding this comment.
Thanks for this PR, @justaprog, @laakhdher, et al. Adding support for MNC sketches would make a great contribution to sparsity estimation in DAPHNE. Overall, your code is already in a good initial state, the stand-alone implementation of the MNC sketch and related algorithms as described in the paper looks good to me. Nevertheless, there is still substantial work required before we can merge this PR, most importantly, the current MNC implementation needs to be integrated with the rest of the DAPHNE system, such that we can benefit from MNC when running a DaphneDSL script.
Required points: (need to be addressed before we can merge this PR)
- Finish the implementation of the remaining parts of MNC as described in the paper.
- Implement the density map estimator over an MNC sketch (your function
Edm()is currently a stub). - Implement the propagation of the MNC sketch over reorganization ops and elementwise binary ops as described in Section 4.2 of the paper.
- Implement the density map estimator over an MNC sketch (your function
- Integrate your implementation of MNC with the rest of the DAPHNE system.
- Make an MNC sketch an optional data property of a matrix (see the developer docs on adding new data properties).
- Invoke the MNC-based sparsity estimation and MNC sketch propagation during the
InferencePass(implement the necessary MLIR interfaces or traits, see the developer docs on data properties again). - Ensure that the MNC sketch of inputs of the data flow graph can be known. Such inputs could be:
- Matrices read from files (most important).
- MNC sketch as an optional part of the file meta data, plus some way of creating that file meta data automatically.
- MNC sketch creation on-the-fly (optional).
- Matrices created by various source ops (e.g.,
fill()/FillOp,seq()/SeqOp,rand()/RandMatrixOp, … (implement the inference interface for the MNC sketch for those ops). - Matrix literals (
MatrixConstantOp).
- Matrices read from files (most important).
- Please fix the code style issues to make the CI checks pass (see the contribution guidelines).
Optional points: (recommended, but not critical for merging)
- Apply some little code improvements (see my comments on individual code lines).
- Use the helper function
genGivenVals()to shorten the code of your unit test cases. Currently, you initialize CSR matrices by hardcoding the values, colIdxs, and rowOffsets arrays, which leads to long and hard-to-read test code. Instead, you could simply pass the (dense) values array togenGivenVals()and get its representation as aCSRMatrixorDenseMatrix. (For small test matrices, it doesn't hurt if you explicitly write the zeros in the code.) You can take inspiration from many existing unit test cases. - Use the MNC sketch for more accurate, structure-aware sparsity estimation of additional ops, e.g.,
SliceRowOp/SliceColOp,ExtractRowOp/ExtractColOp, etc. - Implement the MNC sketch propagation for additional ops, e.g., elementwise unary ops, etc.
| h.hc.assign(h.n, 0); | ||
|
|
||
| const std::size_t *rowOffsets = A.getRowOffsets(); | ||
| const std::size_t *colIdxs = A.getColIdxs(); |
There was a problem hiding this comment.
Please use A.getColIdxs(0); otherwise, you may run into errors if A is a view into a larger CSRMatrix.
|
|
||
| // --- 3) isDiagonal --- | ||
| // We call a matrix "diagonal" if it is square and every non-zero lies on i == j. | ||
| if(h.m == h.n && nnzEnd > nnzBegin) { |
There was a problem hiding this comment.
You could also skip the check for a diagonal matrix if h.maxHr > 1 (or h.maxHc > 1), because a diagonal matrix can have at most one non-zero per row/column.
| const std::size_t m = hA.m; | ||
| const std::size_t l = hB.n; | ||
|
|
||
| double nnz = 0.0; |
There was a problem hiding this comment.
I recommend not using double for the number of non-zeros, because the number of non-zeros is conceptually an integer (e.g., size_t). Using double could lead to round-off errors (and vastly off numbers when casted to integer) when adding up many small numbers of per-row non-zeros in a large matrix).
This hints also applies to several more such uses of double below.
| } | ||
|
|
||
| // Case 2: Extended count | ||
| else if(!hA.her.empty() || !hB.her.empty()) { |
There was a problem hiding this comment.
As the code in the then-branch uses both the extended histograms of hA and hB, I think it should be && instead of || (in contrast to Algorithm 1 in the paper).
| else if(!hA.her.empty() || !hB.her.empty()) { | ||
|
|
||
| // Exact part | ||
| for(std::size_t j = 0; j < hA.n; ++j) |
There was a problem hiding this comment.
These two loops both iterate over the same range (as hA.n is the same as hB.m). If you fuse these loops, you need to scan hA.hec only once, which should be more efficient.
| std::size_t p = (hA.nnzRows - hA.rowsEq1) * (hB.nnzCols - hB.colsEq1); | ||
|
|
||
| if(p > 0) { | ||
| double dens = Edm(hA.hc, hB.hr, p); |
There was a problem hiding this comment.
Don't forget to subtract the extended histograms from hA.hc and hB.hr as in Algorithm 1 in the paper.
…ch IDs consistently
- Integrated Mncsketch into DaphneIR to support RandMatrixOp, FillOp, SeqOp, MatMulOp, TransposeOp, ReshapeOp, MatrixConstantOp, EwAddOp, EwSubOp, EwMulOp, EwDivOp, ReadOp ops
…dOp and ColBindOp
…periments - Created new result files for matrix multiplication experiments with real data: - run_matmul_only_real_data.txt - run_matmul_self_transpose.txt - Updated run_matmul_w.txt with additional results and improved formatting. - Added new script run_elementwise_mul.sh to execute element-wise multiplication experiments across various datasets. - Modified run_matmul_only_real_data.sh to include additional datasets and improved execution permissions. - Created run_matmul_self_transpose.sh for self-transpose matrix multiplication experiments. - Updated run_write_mnc_md.sh to include more datasets and improved formatting.
Update after final submission
Added a Project Spotlight section to the README to document the Matrix Non-zero Count (MNC) sketch implementation. This includes a breakdown of our key technical contributions (compiler integration, sketch propagation, and extended operations), a code navigation guide for our code files in src/ and test/
Issues?
#987
What?
Based on the paper: Johanna Sommer, Matthias Boehm, Alexandre V. Evfimievski, Berthold Reinwald, Peter J. Haas (2019). "MNC: Structure-Exploiting Sparsity Estimation for Matrix Expressions". SIGMOD '19: Proceedings of the 2019 International Conference on Management of Data.
MNC Sparsity Estimator Project (Large Scale Data Engineering
This section documents the environment and results for the MNC Sparsity Estimator)
All experiments were conducted using a Docker container to ensure a consistent environment for library linking and reproducibility.
data.zip
Hardware: 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz with 16.0 GB RAM.
OS/Software: Windows 11 Home running through WSL (Windows Subsystem for Linux).
System Type: 64-bit operating system, x64-based processor.
2. Metrics
Dataset: We used real matrices from the SuiteSparse Matrix Collection (e.g., gre__115.mtx) instead of synthetic random data to better reflect real-world distributions.
Metrics: We measured Accuracy Error (the difference between the MNC estimate and actual sparsity) and Decision Correctness.
Variance: Because MNC is a probabilistic sketching method, small variations in results between runs are expected and were managed by using mean values for reporting.
3. Key Results
Decision Logic: Our implementation uses a 0.25 density threshold. It correctly triggers SPARSE storage for workloads measured below this value and DENSE for those above.
Reliability: The prototype passed 2,452 unit tests in the DAPHNE Catch2 suite, confirming it integrates safely with the existing system kernels.
This PR contains:
Update after final submission:
Current all tests run:
Update Features
Experiments
G11 (800,800), G14(800,800), G22 (2000,2000), G27 (2000,2000), gre__115 (115,115), gre__185 (185,185),
gre__343 (343,343), gre__512 (512,512), str__200 (363,363), str__400 (363,363), lp_scagr7 (129, 185),
football__115 (115,115), dw256A (512,512), dwt__66 (66,66)