I’ve updated my comments and printouts to hopefully show the problem more clearly. Someone from NVIDIA pointed out that the sparse matrix elements must be in ascending row order. However, I’m still getting incorrect results if I do that. Below is the full output of my current reproduction code.

Notice that the first case works fine, with only one element. The second one, in ascending order, fails. The third one is descending order, but it gives the correct result for some unknown reason. And the fourth and fifth both fail, whether or not I’m using ascending or descending order.

sparse matrix a:

(1, 1): 1

values: 1

row_indices: 1

col_indices: 1

shape: 3, 3

dense matrix b:

1 2 3

4 5 6

7 8 9

values: 1 4 7 2 5 8 3 6 9

shape: 3, 3

result dense matrix c = a * b =

0 0 0

4 5 6

0 0 0

values: 0 4 0 0 5 0 0 6 0

shape: 3, 3

sparse matrix a:

(1, 1): 1

(0, 0): 1

values: 1 1

row_indices: 1 0

col_indices: 1 0

shape: 3, 3

dense matrix b:

1 2 3

4 5 6

7 8 9

values: 1 4 7 2 5 8 3 6 9

shape: 3, 3

result dense matrix c = a * b =

1 2 3

4 5 6

0 0 0

values: 1 4 0 2 5 0 3 6 0

shape: 3, 3

sparse matrix a:

(0, 0): 1

(1, 1): 1

values: 1 1

row_indices: 0 1

col_indices: 0 1

shape: 3, 3

dense matrix b:

1 2 3

4 5 6

7 8 9

values: 1 4 7 2 5 8 3 6 9

shape: 3, 3

result dense matrix c = a * b =

2 4 6

0 0 0

0 0 0

values: 2 0 0 4 0 0 6 0 0

shape: 3, 3

sparse matrix a:

(2, 2): 1

(1, 1): 1

(0, 0): 1

values: 1 1 1

row_indices: 2 1 0

col_indices: 2 1 0

shape: 3, 3

dense matrix b:

1 2 3

4 5 6

7 8 9

values: 1 4 7 2 5 8 3 6 9

shape: 3, 3

result dense matrix c = a * b =

2 4 6

0 0 0

7 8 9

values: 2 0 7 4 0 8 6 0 9

shape: 3, 3

sparse matrix a:

(0, 0): 1

(1, 1): 1

(2, 2): 1

values: 1 1 1

row_indices: 0 1 2

col_indices: 0 1 2

shape: 3, 3

dense matrix b:

1 2 3

4 5 6

7 8 9

values: 1 4 7 2 5 8 3 6 9

shape: 3, 3

result dense matrix c = a * b =

3 6 9

0 0 0

0 0 0

values: 3 0 0 6 0 0 9 0 0

shape: 3, 3

sparse matrix a:

(0, 0): 1

(0, 1): 1

(0, 2): 1

(1, 0): 1

(1, 1): 1

(1, 2): 1

(2, 0): 1

(2, 1): 1

(2, 2): 1

values: 1 1 1 1 1 1 1 1 1

row_indices: 0 0 0 1 1 1 2 2 2

col_indices: 0 1 2 0 1 2 0 1 2

shape: 3, 3

dense matrix b:

1 2 3

4 5 6

7 8 9

values: 1 4 7 2 5 8 3 6 9

shape: 3, 3

result dense matrix c = a * b =

18 27 36

0 0 0

0 0 0

values: 18 0 0 27 0 0 36 0 0

shape: 3, 3