Skip to content

[SYSTEMDS-3914] tsmm ooc operation - #2323

Closed
j143 wants to merge 2 commits into
apache:mainfrom
j143:SYSTEMDS-3914-tsmm-out-of-core-operation
Closed

j143 wants to merge 2 commits into
apache:mainfrom
j143:SYSTEMDS-3914-tsmm-out-of-core-operation

Conversation

@j143

@j143 j143 commented Sep 3, 2025 •

Copy link
Copy Markdown
Member

TSMM operation using existing transposeSelfMatrixMultOperations assuming the the number columns <= size of block.

This scenario: a matrix with many rows but few columns <= blocksize (1000) .

Let's walk through an example of a 6x2 matrix X with a block size of 2x2. This matrix is "tall" (it has 3 blocks of rows) and "skinny" (it has only 1 block of columns).

The operation is $C = t(X) \cdot X$. The output C will be a small 2x2 matrix.


The Input Matrix X

First, let's visualize our input matrix. It's a single stream of three blocks: X1, X2, and X3.

$$X = \begin{pmatrix} X_1 \\ X_2 \\ X_3 \end{pmatrix} = \begin{pmatrix} 1 & 2 \\ 3 & 0 \\ \hdashline 4 & 1 \\ 1 & 1 \\ \hdashline 0 & 2 \\ 5 & 1 \end{pmatrix}$$

The algorithm will compute the final result C by summing the tsmm of each individual block:

$$C = (t(X_1) \cdot X_1) + (t(X_2) \cdot X_2) + (t(X_3) \cdot X_3)$$


The Streaming Process

We this stream one block at a time, adding each result to a single accumulator block (resultBlock) that stays in memory.

1. Initialization

An empty 2x2 resultBlock is created. This is our accumulator.

$$ resultBlock = \begin{pmatrix} 0 & 0 \\ 0 & 0 \end{pmatrix}$$

2. Processing the Stream

The while loop begins, processing one block at a time.


Iteration 1: Process X1

  • Map: The code computes $t(X_1) \cdot X_1$.

$$t(X_1) \cdot X_1 = \begin{pmatrix} 1 & 3 \\ 2 & 0 \end{pmatrix} \cdot \begin{pmatrix} 1 & 2 \\ 3 & 0 \end{pmatrix} = \begin{pmatrix} 10 & 2 \\ 2 & 4 \end{pmatrix}$$

  • Reduce: This partial result is added to resultBlock.

$$ resultBlock = \begin{pmatrix} 0 & 0 \\ 0 & 0 \end{pmatrix} + \begin{pmatrix} 10 & 2 \\ 2 & 4 \end{pmatrix} = \begin{pmatrix} 10 & 2 \\ 2 & 4 \end{pmatrix}$$


Iteration 2: Process X2

  • Map: The code computes $t(X_2) \cdot X_2$.

$$t(X_2) \cdot X_2 = \begin{pmatrix} 4 & 1 \\ 1 & 1 \end{pmatrix} \cdot \begin{pmatrix} 4 & 1 \\ 1 & 1 \end{pmatrix} = \begin{pmatrix} 17 & 5 \\ 5 & 2 \end{pmatrix}$$

  • Reduce: This new partial result is added to the current resultBlock.

$$resultBlock = \begin{pmatrix} 10 & 2 \\ 2 & 4 \end{pmatrix} + \begin{pmatrix} 17 & 5 \\ 5 & 2 \end{pmatrix} = \begin{pmatrix} 27 & 7 \\ 7 & 6 \end{pmatrix}$$


Iteration 3: Process X3

  • Map: The code computes $t(X_3) \cdot X_3$.

$$t(X_3) \cdot X_3 = \begin{pmatrix} 0 & 5 \\ 2 & 1 \end{pmatrix} \cdot \begin{pmatrix} 0 & 2 \\ 5 & 1 \end{pmatrix} = \begin{pmatrix} 25 & 5 \\ 5 & 5 \end{pmatrix}$$

  • Reduce: This final partial result is added to the resultBlock.

$$resultBlock = \begin{pmatrix} 27 & 7 \\ 7 & 6 \end{pmatrix} + \begin{pmatrix} 25 & 5 \\ 5 & 5 \end{pmatrix} = \begin{pmatrix} 52 & 12 \\ 12 & 11 \end{pmatrix}$$


Final Result

Once the stream is empty, the loop terminates, and the final resultBlock is sent to the output. This entire process read the massive 6x2 input matrix while only holding one small input block and the small 2x2 result block in memory at any given time.

@codecov

codecov Bot commented Sep 3, 2025 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.17949% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 72.27%. Comparing base (feafd0e) to head (7cd9d18).
⚠️ Report is 8 commits behind head on main.

Files with missing lines Patch % Lines
...s/runtime/instructions/ooc/TSMMOOCInstruction.java 88.88% 4 Missing ⚠️
...c/main/java/org/apache/sysds/hops/AggBinaryOp.java 0.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##               main    #2323   +/-   ##
=========================================
  Coverage     72.26%   72.27%           
- Complexity    46646    46651    +5     
=========================================
  Files          1496     1497    +1     
  Lines        176874   176903   +29     
  Branches      34771    34771           
=========================================
+ Hits         127820   127853   +33     
+ Misses        39405    39402    -3     
+ Partials       9649     9648    -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@j143

j143 commented Sep 4, 2025

Copy link
Copy Markdown
Member Author

Hi @mboehm7 , I've implemented TSMM. Thanks to your note on column <= blocksize, It is a bit straightforward implementation. could you please check once. thanks

@mboehm7

mboehm7 commented Sep 21, 2025

Copy link
Copy Markdown
Contributor

LGTM - thanks for the patch @j143. Overall, this was a good start. During the merge I made the following additional modifications:

  • Changed the TSMM OOC instruction to consume the stream directly but produce a normal non-OOC output because it is a single block anyway
  • Added a validation check so we fail with unsupported operations if the dimensions do not qualify for OOC
  • Generalized the code so it works for both left and right TSMM
  • Eliminated unnecessary warnings (imports, unused variables)
  • Extended the test to cover both dense and sparse

@mboehm7 mboehm7 closed this in 7c504d0 Sep 21, 2025
@github-project-automation github-project-automation Bot moved this from In Progress to Done in SystemDS PR Queue Sep 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants