Skip to content

Commit

Permalink
add option to override march=native
Browse files Browse the repository at this point in the history
  • Loading branch information
david-cortes committed Jan 20, 2022
1 parent 00fe8b5 commit a493319
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
15 changes: 15 additions & 0 deletions README.md
Expand Up @@ -39,6 +39,21 @@ The variants implemented here are based on multiple oracle calls (building a ser

**Note: Python 2 is not supported and package will fail to run on Python 2.7**

** *
**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:

```
export CFLAGS="-msse2"
pip install costsensitive
```

or for creating wheels:
```
export CFLAGS="-msse2"
python setup.py bwheel
```
** *


* R:

Expand Down
13 changes: 11 additions & 2 deletions setup.py
Expand Up @@ -22,7 +22,8 @@ def build_extensions(self):
for e in self.extensions:
e.extra_compile_args = ['/O2']
else:
self.add_march_native()
if not self.check_cflags_contain_arch():
self.add_march_native()
self.add_openmp_linkage()

for e in self.extensions:
Expand All @@ -32,6 +33,14 @@ def build_extensions(self):

build_ext.build_extensions(self)

def check_cflags_contain_arch(self):
if "CFLAGS" in os.environ:
arch_list = ["-march", "-mcpu", "-mtune", "-msse", "-msse2", "-msse3", "-mssse3", "-msse4", "-msse4a", "-msse4.1", "-msse4.2", "-mavx", "-mavx2"]
for flag in arch_list:
if flag in os.environ["CFLAGS"]:
return True
return False

def add_march_native(self):
arg_march_native = "-march=native"
arg_mcpu_native = "-mcpu=native"
Expand Down Expand Up @@ -106,7 +115,7 @@ def test_supports_compile_arg(self, comm):
'cython'
],
python_requires = ">=3",
version = '0.1.2.13-2',
version = '0.1.2.13-3',
description = 'Reductions for Cost-Sensitive Multi-Class Classification',
author = 'David Cortes',
author_email = 'david.cortes.rivera@gmail.com',
Expand Down

0 comments on commit a493319

Please sign in to comment.