Skip to content

Add restrict qualifiers to matrix function calls - #1

Open
ColeStrickler wants to merge 1 commit into
CSL-KU:mainfrom
ColeStrickler:restrict
Open

Add restrict qualifiers to matrix function calls#1
ColeStrickler wants to merge 1 commit into
CSL-KU:mainfrom
ColeStrickler:restrict

Conversation

@ColeStrickler

Copy link
Copy Markdown

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

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