Ich bin eine seltsame Fehler für den folgenden Code erhalten:_mm_fmadd_pd Programm empfangene Signal SIGILL, Illegal instruction
#include <assert.h>
#include <stdio.h>
#include <immintrin.h>
inline static double myfma(double x,double y, double z) {
double r; // result
__m128d xx, yy, zz,rr;
xx = _mm_set_sd(x);// xx[0]=x, xx[1]=undefined
yy = _mm_set_sd(y);// yy[0]=y, yy[1]=undefined
zz = _mm_set_sd(z);// zz[0]=z, zz[1]=undefined
r = _mm_cvtsd_f64(_mm_fmadd_pd(xx,yy,zz));
return r;
}
void testfma() {
double x, y, z, res;
x = 1.0;
y = 2.0;
z = 3.0;
res = myfma(x,y,z);
printf("test: res = x*y + z \n");
printf(" x: %g\n", x);
printf(" y: %g\n", y);
printf(" z: %g\n", z);
assert(res == 5.0);
}
int main() {
testfma();
return 0;
}
Kompilieren des Codes wie:
g++ test.cpp -o a.out -std=c++11 -mavx2 -mfma -march=native -g
, wenn ich starten Sie die ausführbare ich immer bin Nachricht:
Illegal instruction (core dumped)
mit gDB, um weitere Informationen zu erhalten:
gdb ./a.out
(gdb) r
(gdb) r
Starting program: ....
Program received signal SIGILL, Illegal instruction.
0x000000000040067d in _mm_fmadd_pd(double __vector(2), double __vector(2), double __vector(2)) (__C=..., __B=..., __A=...)
at /usr/lib/gcc/x86_64-linux-gnu/5/include/fmaintrin.h:42
42 (__v2df)__C);
jedoch bei der Verwendung von valgrind wie folgt:
valgrind ./a.out
==9825== Memcheck, a memory error detector
==9825== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==9825== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright
info
==9825== Command: ./helios.x
==9825==
test: res = x*y + z
x: 1
y: 2
z: 3
res: 5
==9825==
==9825== HEAP SUMMARY:
==9825== in use at exit: 0 bytes in 0 blocks
==9825== total heap usage: 1 allocs, 1 frees, 1,024 bytes allocated
==9825==
==9825== All heap blocks were freed -- no leaks are possible
==9825==
==9825== For counts of detected and suppressed errors, rerun with: -v
==9825== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
Das Programm scheint zu funktionieren. Was ich hier vermisse? Wie kann ich _mm_fmadd_pd auf eine robuste Weise verwenden? Ist es möglich, dass das Beispiel funktioniert, unabhängig davon, ob es in einem Intel- oder AMD-Prozessor läuft? ist es möglich, es mit g ++ oder icpc kompilieren zu lassen?
Sind Sie sicher, dass Ihre CPU über FMA verfügt? Versuchen Sie auch, mit '-g' zu kompilieren, so dass Sie beim Absturz in gdb sehen können, was gerade passiert ... –
Mit der -g-Flag erhalte ich den Fehler: (gdb) r Startprogramm: .... .. Programm empfangen Signal SIGILL, Illegal Anweisung. 0x000000000040067d in _mm_fmadd_pd (doppelt __vector (2), doppelt __vector (2), doppelt __vector (2)) (__C = ..., __B = ..., __A = ...) unter/usr/lib/gcc /x86_64-linux-gnu/5/include/fmaintrin.h:42 42 (__v2df) __ C); –