Skip to content

Thread s/d omatcopy for large matrices - #6237

Open
aalquwayfili wants to merge 1 commit into
OpenMathLib:developfrom
aalquwayfili:omatcopy-threads
Open

aalquwayfili wants to merge 1 commit into
OpenMathLib:developfrom
aalquwayfili:omatcopy-threads

Conversation

@aalquwayfili

Copy link
Copy Markdown
Contributor

Follow-up to #6135 for #4902: omatcopy now uses threads for big matrices.

Each thread gets a block of rows (or columns for column-major) through blas_level1_thread, and BLAS_TRANSB_T handles where that block lands in B for the transposed copies.

Two limits: small copies stay on one thread (65536 * GEMM_MULTITHREAD_THRESHOLD, like gemv/ger), and in the transposed copies each thread gets at least 32 rows/columns. Without the second one the threads were fighting over the same cache lines of B, e.g. 8192x32 ColMajor/Trans got 2x slower on 16 threads.

cblas_domatcopy on a 16-core i9-9960X, GB/s, 1 -> 16 threads:

A RowMajor Trans ColMajor Trans
100000x5000 6.6 -> 33.6 6.1 -> 30.6
5000x100000 5.7 -> 30.4 6.5 -> 32.4
4000x10000 6.6 -> 28.2 6.5 -> 27.7

It tops out around 8 threads here (memory bandwidth), and 4000x10000 is actually a bit faster on 8. On the shapes from #4902 it now beats the OpenMP dcopy loop from the issue (about 0.25 s vs 0.32 to 0.35 s), so maybe that one can be closed. I can't compare with MKL though.

Output is bitwise the same as on one thread. I added four 600x500 tests since the existing ones are too small to hit the threaded path.

One side effect: with the pthreads build, calling it inside an OpenMP loop now prints the "Detect OpenMP Loop" warning, like daxpy does.

omatcopy always ran on one thread. Split A into blocks of rows (row-major)
or columns (column-major) with blas_level1_thread and run the kernel on each
block. For the transposed copies BLAS_TRANSB_T moves B by the block width.

Copies below 65536 * GEMM_MULTITHREAD_THRESHOLD elements stay on one thread.
The transposed ones give each thread at least 32 rows or columns, since
narrower bands make the threads write into the same cache lines of B.

Add domatcopy tests that are large enough to use the threaded path.

This branch has not been deployed

No deployments
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