Add restrict qualifiers to matrix function calls - #1
Open
ColeStrickler wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
By adding restrict qualifiers to the calls to the matrix multiplication functions the compiler can greatly improve its optimization of the computation.
void matmult_opt0_naive(const float* restrict A,
const float* restrict B,
float* restrict C,
int dimension)
I ran the eval.sh with and without these qualifiers added on a Ryzen 3900x.
With restrict qualifiers
n ws dur
16 3 0.000002 0.000001 0.000001 0.000010 0.000003
32 12 0.000007 0.000003 0.000003 0.000006 0.000004
64 48 0.000091 0.000027 0.000026 0.000050 0.000038
128 192 0.001980 0.000114 0.000109 0.000196 0.000169
256 768 0.016037 0.000607 0.000635 0.001495 0.001442
512 3072 0.363812 0.006123 0.006502 0.012121 0.010977
1024 12288 6.351671 0.047204 0.070970 0.098113 0.095890
2048 49152 48.689588 0.900440 0.587070 1.411933 1.387838
Without restrict qualifiers
16 3 0.000002 0.000001 0.000001 0.000003 0.000001
32 12 0.000020 0.000004 0.000004 0.000021 0.000005
64 48 0.000148 0.000017 0.000017 0.000163 0.000018
128 192 0.001987 0.000126 0.000121 0.001425 0.000154
256 768 0.016817 0.000797 0.000795 0.012233 0.001444
512 3072 0.344755 0.007023 0.008326 0.098995 0.010561
1024 12288 8.198040 0.058190 0.082988 0.804152 0.097722
2048 49152 53.720333 1.276770 0.706351 6.644807 1.370478
Hashes check out. Small difference due to -oFast:
[Hashes for 1024 without qualifier]:
matmult_opt0 8.069329 chsum: -3305.024465
matmult_opt1 0.060602 chsum: -3305.024618
matmult_opt2 0.084965 chsum: -3305.024618
matmult_opt3 0.787418 chsum: -3305.024465
matmult_opt4 0.094848 chsum: -3305.023131
[Hashes for 1024 with qualifier]:
matmult_opt0 6.306643 chsum: -3305.023527
matmult_opt1 0.047218 chsum: -3305.024618
matmult_opt2 0.072593 chsum: -3305.024618
matmult_opt3 0.099318 chsum: -3305.023172
matmult_opt4 0.096280 chsum: -3305.023131