5

I'm trying to enable AVX2 code-generation via CMake on my Visual Studio 2013 projects and so far, I'm out of luck.

Things I've tried are:

  1. Set CMAKE_CXX_FLAGS_* to include /arch:AVX2 like so: SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /arch:AVX2")
  2. Set target properties like so: SET_TARGET_PROPERTIES("myproject" PROPERTIES COMPILE_FLAGS "/arch:AVX2"). I also tried replacing COMPILE_FLAGS with COMPILE_DEFINITIONS, COMPILE_FEATURES (fails to generate project) and COMPILE_OPTIONS.

Each time I try generating the projects, I would make sure to delete the CMake cache so that it doesn't get in the way of generating the project files.

What am I missing? Any help to shed light on this would be much appreciated. Thanks for your time.

Vite Falcon
  • 6,575
  • 3
  • 30
  • 48
  • Are you sure it's not working? Most of these should work as you've written them (`COMPILE_FEATURES` and `COMPILE_DEFINITIONS` are the wrong choices). I'd be inclined to choose `COMPILE_OPTIONS` as the most appropriate, but I'd set it by doing `target_compile_options(myproject PRIVATE /arch:AVX2)` or if your project is cross-platform: `target_compile_options(myproject PRIVATE $<$:/arch:AVX2>)` – Fraser Jun 10 '15 at 08:14
  • Thanks @Fraser for taking the time to look into this. I tried both of your suggestions. The first one adds the option '/arch:AVX2' to the additional compiler options, but the second got mangled (probably my fault). VS UI doesn't show that AVX2 is enabled though. Also, if I manually enable AVX2 it doesn't show up as a compiler flag (nor mentioned in the *.vcproj file for some odd reason). Not sure if this is a bug. – Vite Falcon Jun 10 '15 at 08:33
  • 1
    It should appear as a flag if you hit "apply". Apart from that, I also don't see the dropdown choice being selected when applied by CMake, but it should still work - it's being applied to the command. This works correctly for MSVC 2015 (i.e. the dropdown option is correctly filled in if CMake adds the option). – Fraser Jun 10 '15 at 12:58
  • How do you make sure that AVX2 is not used? Do you see it from assembly? Do you have some special test case? Do you see AVX (1) enabled? – zam Jun 11 '15 at 09:38
  • @Fraser: You're right. It does get work but isn't reflected in the UI. There's a good performance difference compared to without the flags in place. – Vite Falcon Jun 11 '15 at 20:40

0 Answers0