Skip to content

Commit

Permalink
more options for march=native
Browse files Browse the repository at this point in the history
  • Loading branch information
david-cortes committed May 21, 2022
1 parent 3e84dd4 commit f87572f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,17 @@ brew install libomp
And then reinstall this package: `pip install --force-reinstall hpfrec`.

** *
**IMPORTANT:** the setup script will try to add compilation flag `-march=native`. This instructs the compiler to tune the package for the CPU in which it is being installed, but the result might not be usable in other computers. If building a binary wheel of this package or putting it into a docker image which will be used in different machines, this can be overriden by manually supplying compilation `CFLAGS` as an environment variable with something related to architecture. For maximum compatibility (but slowest speed), assuming `x86-64` computers, it's possible to do something like this:
**IMPORTANT:** the setup script will try to add compilation flag `-march=native`. This instructs the compiler to tune the package for the CPU in which it is being installed (by e.g. using AVX instructions if available), but the result might not be usable in other computers. If building a binary wheel of this package or putting it into a docker image which will be used in different machines, this can be overriden either by (a) defining an environment variable `DONT_SET_MARCH=1`, or by (b) manually supplying compilation `CFLAGS` as an environment variable with something related to architecture. For maximum compatibility (but slowest speed), it's possible to do something like this:

```
export CFLAGS="-msse2"
export DONT_SET_MARCH=1
pip install hpfrec
```

or for creating wheels:
or, for forcing a maximum-compatibility x86-64 binary:
```
export CFLAGS="-msse2"
python setup.py bwheel
export CFLAGS="-march=x86-64"
pip install hpfrec
```
** *

Expand Down
5 changes: 4 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def build_extensions(self):
for e in self.extensions:
e.extra_compile_args += ['/openmp', '/O2', '/fp:fast']
else:
if not self.check_cflags_contain_arch():
if not self.check_for_variable_dont_set_march() and not self.check_cflags_contain_arch():
self.add_march_native()
self.add_openmp_linkage()
self.add_no_math_errno()
Expand All @@ -43,6 +43,9 @@ def check_cflags_contain_arch(self):
return True
return False

def check_for_variable_dont_set_march(self):
return "DONT_SET_MARCH" in os.environ

def add_march_native(self):
arg_march_native = "-march=native"
arg_mcpu_native = "-mcpu=native"
Expand Down

0 comments on commit f87572f

Please sign in to comment.