4

I'm trying to run a Visual Studio cpp project created by a friend of mine. I'm trying to run the file without VS. But I'm getting a list of errors, all in the same format:

inlining failed in call to always_inline '__m256d _mm256_broadcast_sd(const double*)': target specific option mismatch|

It runs correctly in VS with release mode and breaks when run in debug mode.

The includes are as follows:

#include "stdafx.h"
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <vector>
# include <omp.h>
#include <chrono>
#include <fstream>
#include <algorithm>

#include <immintrin.h>

using namespace std::chrono;
using namespace std;

and the error is called from here:

double zero = 0;
__m256d acc = _mm256_broadcast_sd(&zero);

Update:

I'm using the this command to run it: g++ -std=c++0x multip.cpp -o multip, is there an additional parameter to add -mavx to the compiler invocation?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
S.Dan
  • 1,826
  • 5
  • 28
  • 55
  • 1
    Side note NOT solving your issue: You can use _mm256_setzero_pd() – Guillaume Gris Jul 07 '17 at 06:05
  • Related: [The Effect of Architecture When Using SSE / AVX Intrinisics](//stackoverflow.com/q/55747789) explains how GCC/clang differ from MSVC/ICC: GCC/clang require you to enable extensions that you use intrinsics for. They'll never emit an SSE4.1 instruction without `-msse4.1` even from intrinsics. – Peter Cordes Sep 27 '19 at 00:13

1 Answers1

15

"Target specific option mismatch" means that you're missing a feature flag from your GCC invocation. You probably need to add -mavx to your compiler invocation.

If you're intending to run this on your computer only, -march=native will turn on all the feature flags that your own machine supports.

zneak
  • 134,922
  • 42
  • 253
  • 328
  • `g++ -std=c++0x multip.cpp -o multip` this is what I used, and It should be able to run on anybody's machine. – S.Dan Jul 07 '17 at 05:08
  • 2
    @SachiDangalla This [broadcast instruction](https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=mm256_broadcast_sd&expand=489) requires CPU that supports [AVX instruction set](https://en.wikipedia.org/wiki/Advanced_Vector_Extensions). It will not run on anybody's machine, but only on those where this instruction is supported. – Ivan Aksamentov - Drop Jul 07 '17 at 05:10
  • So in a machine with AVX instructions, the code is run correctly in VS but not in command line. Is there an additional parameter to be used? – S.Dan Jul 07 '17 at 05:30
  • @SachiDangalla, you need to be more specific about the error that you get. – zneak Jul 07 '17 at 15:09
  • 1
    @SachiDangalla: Visual Studio lets you use intrinsics for instruction sets that haven't been enabled for the compiler to use. This is not the case in GCC or clang. If you ran MSVC's compiler from the command line, it would work the same as from inside VS... And BTW, I highly recommend using `-march=native` or `-march=haswell` or instead of *just* `-mavx`, to set tuning options appropriate for a modern CPU as well as enable AVX + AVX2 + FMA + popcnt + BMI1/2 + etc. etc. Or `-march=znver1` for Ryzen. – Peter Cordes Feb 12 '19 at 16:38