I have an AVX optimized app which I do not need to make compatible with non AVX CPUs. However, I would like to display a clean error dialog on these older CPUs, rather than having the app crashing, as that causes customer confusion.
In my main()
I create the QApplication
instance (I'm using the Qt framework), then test for AVX using gcc __builtin_cpu_supports ("avx")
. If it fails, I display an error dialog. This proved to work on non-AVX CPUs on a simple test app.
However, our (large) application crashes before displaying the dialog box on non AVX CPUs.
I have suspected:
Problem is, I have no non-AVX system at work for debugging and I would prefer avoiding purchasing one if possible.
You could create a (non-optimised) wrapper program that performs the feature test, then either exits with a friendly message or execs your application.
The QApplication
constructor is allowed to modify the passed arguments, so you'll need to take a copy (or not use any Qt in the path that goes through to exec()
).
Something like (from my head):
int main(int argc, char **argv)
{
if (__builtin_cpu_supports ("avx")) {
execv("/the/real/program", argv);
perror("exec");
exit 1;
} else {
QApplication app(argc, argv);
QDialog d;
d.show();
return 1;
}
}
VMWare can fake the CPUID of the guest OS, and you could just turn off all AVX bits.
However, this is just lying to the application : it won't cause the app to break into the debugger if it still executes that AVX instruction.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.