configuring tensorflow to compile without avx2 support

2,143 views
Skip to first unread message

Tarun Khanna

unread,
Jul 6, 2018, 5:55:34 PM7/6/18
to TensorFlow Developers
I need to build tensorflow for a linux based platform. I followed the instructions here to build and run the python version of the library. However, when I run it complains that tensorflow was compiled with avx2 but the current hardware doesn't support it. So, I tried building it without the --config=opt option to the configure script. I am able to run tensorflow with that configuration however I get the warning that SSE4.1 SSE4.2 AVX  are available on the CPU and tensorflow was compiled to not use them.

How do I configure and build tensorflow so it's compiled only without the avx2 instructions?

Thanks.

George Sterpu

unread,
Jul 6, 2018, 6:24:45 PM7/6/18
to Tarun Khanna, TensorFlow Developers
Hi Tarun,
Can you try adding:
export CC_OPT_FLAGS="-march=haswell"
before your bazel build command ?

--
You received this message because you are subscribed to the Google Groups "TensorFlow Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to developers+unsubscribe@tensorflow.org.
Visit this group at https://groups.google.com/a/tensorflow.org/group/developers/.
To view this discussion on the web visit https://groups.google.com/a/tensorflow.org/d/msgid/developers/bd6a9a05-2d55-41b8-9557-3b8c77500497%40tensorflow.org.

Robison, Clayne B

unread,
Jul 6, 2018, 6:30:25 PM7/6/18
to george...@gmail.com, Tarun Khanna, TensorFlow Developers, Robison, Clayne B

-march=haswell will give you avx and avx2 instructions. Depending on your gcc version, you need either -march=ivybridge or -march=corei7-avx. I believe you can also add -mno-avx2 or something like that

Clayne

 

From: George Sterpu <george...@gmail.com>
Sent: Friday, July 6, 2018 3:25 PM
To: Tarun Khanna <tarun...@gmail.com>
Cc: TensorFlow Developers <devel...@tensorflow.org>
Subject: Re: configuring tensorflow to compile without avx2 support

 

Hi Tarun,

Can you try adding:

export CC_OPT_FLAGS="-march=haswell"

before your bazel build command ?

On 6 July 2018 at 23:55, Tarun Khanna <tarun...@gmail.com> wrote:

I need to build tensorflow for a linux based platform. I followed the instructions here to build and run the python version of the library. However, when I run it complains that tensorflow was compiled with avx2 but the current hardware doesn't support it. So, I tried building it without the --config=opt option to the configure script. I am able to run tensorflow with that configuration however I get the warning that SSE4.1 SSE4.2 AVX  are available on the CPU and tensorflow was compiled to not use them.

 

How do I configure and build tensorflow so it's compiled only without the avx2 instructions?

 

Thanks.

--

You received this message because you are subscribed to the Google Groups "TensorFlow Developers" group.

To unsubscribe from this group and stop receiving emails from it, send an email to developers+...@tensorflow.org.

 

--

You received this message because you are subscribed to the Google Groups "TensorFlow Developers" group.

To unsubscribe from this group and stop receiving emails from it, send an email to developers+...@tensorflow.org.

Tarun Khanna

unread,
Jul 6, 2018, 9:47:50 PM7/6/18
to Robison, Clayne B, george...@gmail.com, TensorFlow Developers
Thanks, I'll try those out. It takes a while to build. Is there a way to figure what option is set before it finishes building?

Lakshay Garg

unread,
Jul 6, 2018, 11:55:17 PM7/6/18
to tarun...@gmail.com, devel...@tensorflow.org
On Fri, 6 Jul 2018 at 14:55, Tarun Khanna <tarun...@gmail.com> wrote:
​[SNIP]
How do I configure and build tensorflow so it's compiled only without the avx2 instructions?
​​
You can compile with -march=native. This will enable only the instructions which are supported by the hardware you are compiling on. Also, I have a few binaries over at https://github.com/lakshayg/tensorflow-build if you would like to use pre-built binaries.

Lakshay

Lakshay Garg

unread,
Jul 7, 2018, 12:00:42 AM7/7/18
to tarun...@gmail.com, devel...@tensorflow.org
On Fri, 6 Jul 2018 at 14:55, Tarun Khanna <tarun...@gmail.com> wrote:
​[SNIP]
How do I configure and build tensorflow so it's compiled only without the avx2 instructions?
​​

Jason Zaman

unread,
Jul 7, 2018, 1:29:07 AM7/7/18
to Lakshay Garg, devel...@tensorflow.org, tarun...@gmail.com
Hey,
I assume you are building on a different machine than you are going to be running on. In which case run this on the destination machine to find out what flags are the most optimal for it. 

gcc -march=core2 -E -v - </dev/null 2>&1 | grep cc1

Then when you build use the flags it spits out. Pass them when ./configure asks which flags to optimize.

Also -mno-avx2 will make sure it doesn't use any avx2 instructions. But you should use the above command to find all the flags for the most optimal results. Just make sure you check the march=native on the right machine. If you are going to be deploying on many different machines, you can run that command on all and then use only the flags common to all machines. 

There is also some documentation on the gentoo wiki about which cflags are safe on some common generations.

-- Jason

--
You received this message because you are subscribed to the Google Groups "TensorFlow Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to developers+...@tensorflow.org.
Visit this group at https://groups.google.com/a/tensorflow.org/group/developers/.

--
You received this message because you are subscribed to the Google Groups "TensorFlow Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to developers+...@tensorflow.org.
Visit this group at https://groups.google.com/a/tensorflow.org/group/developers/.

George Sterpu

unread,
Jul 7, 2018, 3:27:51 AM7/7/18
to TensorFlow Developers, Tarun Khanna
Sorry for the mistake in my first reply, please take Clayne's advice.

On 7 July 2018 at 07:28, Jason Zaman <ja...@perfinion.com> wrote:
Hey,
I assume you are building on a different machine than you are going to be running on. In which case run this on the destination machine to find out what flags are the most optimal for it. 

gcc -march=core2 -E -v - </dev/null 2>&1 | grep cc1

Then when you build use the flags it spits out. Pass them when ./configure asks which flags to optimize.

Also -mno-avx2 will make sure it doesn't use any avx2 instructions. But you should use the above command to find all the flags for the most optimal results. Just make sure you check the march=native on the right machine. If you are going to be deploying on many different machines, you can run that command on all and then use only the flags common to all machines. 

There is also some documentation on the gentoo wiki about which cflags are safe on some common generations.

-- Jason
On Sat, Jul 7, 2018, 12:00 Lakshay Garg <laks...@outlook.in> wrote:
On Fri, 6 Jul 2018 at 14:55, Tarun Khanna <tarun...@gmail.com> wrote:
​[SNIP]
How do I configure and build tensorflow so it's compiled only without the avx2 instructions?
​​
You can compile with -march=native. This will enable only the instructions which are supported by the hardware you are compiling on. Also, I have a few binaries over at https://github.com/lakshayg/tensorflow-build if you would like to use pre-built binaries.

Lakshay

--
You received this message because you are subscribed to the Google Groups "TensorFlow Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to developers+unsubscribe@tensorflow.org.
On Jul 7, 2018 12:00, "Lakshay Garg" <laks...@outlook.in> wrote:
On Fri, 6 Jul 2018 at 14:55, Tarun Khanna <tarun...@gmail.com> wrote:
​[SNIP]
How do I configure and build tensorflow so it's compiled only without the avx2 instructions?
​​
You can compile with -march=native. This will enable only the instructions which are supported by the hardware you are compiling on. Also, I have a few binaries over at https://github.com/lakshayg/tensorflow-build if you would like to use pre-built binaries.

Lakshay

--
You received this message because you are subscribed to the Google Groups "TensorFlow Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to developers+unsubscribe@tensorflow.org.

--
You received this message because you are subscribed to the Google Groups "TensorFlow Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to developers+unsubscribe@tensorflow.org.

Tarun Khanna

unread,
Jul 7, 2018, 9:13:59 AM7/7/18
to Jason Zaman, Lakshay Garg, devel...@tensorflow.org
Jason,

Thank you. That's very helpful. I'll try it out.

Robison, Clayne B

unread,
Jul 9, 2018, 9:39:00 AM7/9/18
to Tarun Khanna, george...@gmail.com, TensorFlow Developers
The default is what gets set at the end of ./configure which is -march=native


Clayne

Tarun Khanna

unread,
Jul 9, 2018, 9:52:57 AM7/9/18
to ja...@perfinion.com, laks...@outlook.in, devel...@tensorflow.org
Unfortunately, gcc isn't installed on the machine where the library will be run. lscpu shows that it's a sandybridge cpu though. However, when I try -march=sandybridge for the configure script, the build step complains that sandybridge is an invalid option for -march=. I configured it without --config=opt and was able to run tensorflow. It did spit out warnings that I'm not using the AVX/SSE etc optimizations. So, now I'm building with -march=core2 -mavx -msse4.1 -msse4.2 -mpclmul -mpopcnt -maes -mno-avx2. I'll report back how that goes.

# lscpu         
Architecture:          x86_64                                   
CPU op-mode(s):        32-bit, 64-bit                           
Byte Order:            Little Endian                            
CPU(s):                8                                        
On-line CPU(s) list:   0-7                                      
Thread(s) per core:    2                                        
Core(s) per socket:    4                                        
Socket(s):             1                                        
NUMA node(s):          1                                        
Vendor ID:             GenuineIntel                             
CPU family:            6                                        
Model:                 42                                       
Stepping:              7                                        
CPU MHz:               3401.000                                 
BogoMIPS:              6784.77                                  
Virtualization:        VT-x                                     
L1d cache:             32K                                      
L1i cache:             32K                                      
L2 cache:              256K                                     
L3 cache:              8192K                                    
NUMA node0 CPU(s):     0-7                                      
#               
Tarun


Tarun Khanna

unread,
Jul 11, 2018, 9:27:51 AM7/11/18
to Robison, Clayne B, George Sterpu, TensorFlow Developers
After playing around with different options. The one that works well is this one. -march=core2 -mavx -msse4.1 -msse4.2 -mpclmul -mpopcnt -maes -mno-avx2.

Tarun


Konrád Lőrinczi

unread,
Nov 4, 2019, 12:02:06 PM11/4/19
to TensorFlow Developers, clayne.b...@intel.com, george...@gmail.com, tarun...@gmail.com
How to build tensorflow without AVX?

The base build command is this:
bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package

Where do I need to place the  -march=core2 -mavx -msse4.1 -msse4.2 -mpclmul -mpopcnt -maes -mno-avx2 compiler options?



Thanks,
Konrad


2018. július 11., szerda 15:27:51 UTC+2 időpontban Tarun Khanna a következőt írta:
After playing around with different options. The one that works well is this one. -march=core2 -mavx -msse4.1 -msse4.2 -mpclmul -mpopcnt -maes -mno-avx2.

Tarun



On Mon, Jul 9, 2018 at 9:39 AM Robison, Clayne B <clayne....@intel.com> wrote:
The default is what gets set at the end of ./configure which is -march=native


Clayne

On Jul 6, 2018, at 6:47 PM, Tarun Khanna <tarun...@gmail.com> wrote:

Thanks, I'll try those out. It takes a while to build. Is there a way to figure what option is set before it finishes building?

On Fri, Jul 6, 2018, 6:30 PM Robison, Clayne B <clayne....@intel.com> wrote:

-march=haswell will give you avx and avx2 instructions. Depending on your gcc version, you need either -march=ivybridge or -march=corei7-avx. I believe you can also add -mno-avx2 or something like that

Clayne

 

From: George Sterpu <george...@gmail.com>
Sent: Friday, July 6, 2018 3:25 PM
To: Tarun Khanna <tarun...@gmail.com>
Cc: TensorFlow Developers <devel...@tensorflow.org>
Subject: Re: configuring tensorflow to compile without avx2 support

 

Hi Tarun,

Can you try adding:

export CC_OPT_FLAGS="-march=haswell"

before your bazel build command ?

On 6 July 2018 at 23:55, Tarun Khanna <tarun...@gmail.com> wrote:

I need to build tensorflow for a linux based platform. I followed the instructions here to build and run the python version of the library. However, when I run it complains that tensorflow was compiled with avx2 but the current hardware doesn't support it. So, I tried building it without the --config=opt option to the configure script. I am able to run tensorflow with that configuration however I get the warning that SSE4.1 SSE4.2 AVX  are available on the CPU and tensorflow was compiled to not use them.

 

How do I configure and build tensorflow so it's compiled only without the avx2 instructions?

 

Thanks.

--

You received this message because you are subscribed to the Google Groups "TensorFlow Developers" group.

To unsubscribe from this group and stop receiving emails from it, send an email to deve...@tensorflow.org.

--
You received this message because you are subscribed to the Google Groups "TensorFlow Developers" group.

To unsubscribe from this group and stop receiving emails from it, send an email to deve...@tensorflow.org.

Martin Wicke

unread,
Nov 4, 2019, 12:14:03 PM11/4/19
to Konrád Lőrinczi, TensorFlow Developers, clayne.b...@intel.com, george...@gmail.com, tarun...@gmail.com
You should be asked about it when you run configure.

To unsubscribe from this group and stop receiving emails from it, send an email to developers+...@tensorflow.org.
To view this discussion on the web visit https://groups.google.com/a/tensorflow.org/d/msgid/developers/5fef428d-6563-4410-9cc6-0f41aa257d08%40tensorflow.org.

Konrád Lőrinczi

unread,
Nov 4, 2019, 12:25:18 PM11/4/19
to TensorFlow Developers
Configure doesn't ask about AVX

Günhan Gülsoy

unread,
Nov 4, 2019, 12:30:45 PM11/4/19
to Konrád Lőrinczi, TensorFlow Developers
It asks about the default cpu optimizations to use when you run configure.
And if you do not enter anything, by default it compiles with -march=native when you to --config=opt.

You can simply remove `--config=opt` from your command line. Or you can enter -mavx or -msse4 when asked when running `./configure`

On Mon, Nov 4, 2019 at 9:25 AM Konrád Lőrinczi <klor...@gmail.com> wrote:
Configure doesn't ask about AVX

--
You received this message because you are subscribed to the Google Groups "TensorFlow Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to developers+...@tensorflow.org.

Konrád Lőrinczi

unread,
Nov 5, 2019, 2:37:11 AM11/5/19
to TensorFlow Developers, klor...@gmail.com
Thanks, I found the place, where I need to enter the options in when running `./configure`.



2019. november 4., hétfő 18:30:45 UTC+1 időpontban Günhan Gülsoy a következőt írta:
It asks about the default cpu optimizations to use when you run configure.
And if you do not enter anything, by default it compiles with -march=native when you to --config=opt.

You can simply remove `--config=opt` from your command line. Or you can enter -mavx or -msse4 when asked when running `./configure`

On Mon, Nov 4, 2019 at 9:25 AM Konrád Lőrinczi <klor...@gmail.com> wrote:
Configure doesn't ask about AVX

--
You received this message because you are subscribed to the Google Groups "TensorFlow Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to devel...@tensorflow.org.

Konrád Lőrinczi

unread,
Nov 6, 2019, 9:30:03 AM11/6/19
to TensorFlow Developers, klor...@gmail.com
Could you help me how to fix the compile error in following thread?


Compile error, when building tensorflow v1.14.0 without avx2 support

Thanks in advance!



2019. november 4., hétfő 18:30:45 UTC+1 időpontban Günhan Gülsoy a következőt írta:
It asks about the default cpu optimizations to use when you run configure.
And if you do not enter anything, by default it compiles with -march=native when you to --config=opt.

You can simply remove `--config=opt` from your command line. Or you can enter -mavx or -msse4 when asked when running `./configure`

On Mon, Nov 4, 2019 at 9:25 AM Konrád Lőrinczi <klor...@gmail.com> wrote:
Configure doesn't ask about AVX

--
You received this message because you are subscribed to the Google Groups "TensorFlow Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to devel...@tensorflow.org.
Reply all
Reply to author
Forward
0 new messages