Clear Filters
Clear Filters

AVX Programming, how to do within C mex file

9 views (last 30 days)
Hi everybody, fma operations or more generally using avx programming may be very usefull on some circonstancies, better accuracy within dot product for example, faster execution of unrolled loop as blas routines do,....
Is it possible to use this approach within C mex file? Is it nessessary to add specific compilation options at mex command?
Any help or hints about this subject will be great. I have not the fixed-point designer toolbox which probably answers to my question. However I don't use any fixed-point arithmetic.
Best regards
Alain

Accepted Answer

Walter Roberson
Walter Roberson on 25 Oct 2023
Moved: Walter Roberson on 26 Oct 2023
  1 Comment
Alain Barraud
Alain Barraud on 25 Oct 2023
Moved: Walter Roberson on 26 Oct 2023
Following your answer AVX.c contains a fma basic test
__m256d veca = _mm256_setr_pd(6.0, 6.0, 6.0, 6.0);
__m256d vecb = _mm256_setr_pd(2.0, 2.0, 2.0, 2.0);
__m256d vecc = _mm256_setr_pd(7.0, 7.0, 7.0, 7.0);
__m256d resultat = _mm256_fmaddsub_pd(veca, vecb, vecc);
double* res = (double*)&resultat;
wihin an appropriate mex gateway with some includes as follows
#include <immintrin.h>
#include <stdio.h>
#include "mex.h"
#include "matrix.h"
mex COMPFLAGS='$COMPFLAGS /arch:AVX2' AVX.c
Building with 'Microsoft Visual C++ 2019 (C)'.
MEX completed successfully.
I obtain the attended results

Sign in to comment.

More Answers (0)

Products


Release

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!