2015-01-12 13:20:53 -05:00
|
|
|
import os, sys
|
2014-10-14 23:49:18 -04:00
|
|
|
from distutils.command.build_ext import build_ext
|
|
|
|
from setuptools import Extension, setup
|
|
|
|
from distutils.sysconfig import get_python_inc
|
|
|
|
from distutils import sysconfig
|
2015-01-12 13:20:53 -05:00
|
|
|
from imp import find_module
|
|
|
|
from glob import glob
|
2014-10-14 23:49:18 -04:00
|
|
|
|
|
|
|
platform_cflags = {}
|
|
|
|
platform_ldflags = {}
|
|
|
|
platform_libs = {}
|
|
|
|
class build_ext_subclass(build_ext):
|
|
|
|
"""Shamelessly stolen from
|
|
|
|
https://stackoverflow.com/questions/724664
|
|
|
|
"""
|
|
|
|
def build_extensions(self):
|
|
|
|
c = self.compiler.compiler_type
|
|
|
|
if c in platform_cflags.keys():
|
|
|
|
for e in self.extensions:
|
|
|
|
e.extra_compile_args = platform_cflags[c]
|
|
|
|
if c in platform_ldflags.keys():
|
|
|
|
for e in self.extensions:
|
|
|
|
e.extra_link_args = platform_ldflags[c]
|
|
|
|
if c in platform_libs.keys():
|
|
|
|
for e in self.extensions:
|
|
|
|
try:
|
|
|
|
e.libraries += platform_libs[c]
|
|
|
|
except:
|
|
|
|
e.libraries = platform_libs[c]
|
|
|
|
build_ext.build_extensions(self)
|
|
|
|
|
|
|
|
def main():
|
|
|
|
|
2015-01-12 13:20:53 -05:00
|
|
|
def recursive_glob(rootdir='.', suffix=''):
|
|
|
|
return [os.path.join(looproot, filename)
|
|
|
|
for looproot, _, filenames in os.walk(rootdir)
|
|
|
|
for filename in filenames if filename.endswith(suffix)]
|
|
|
|
|
2014-10-14 23:49:18 -04:00
|
|
|
def remove_prefixes(optlist, bad_prefixes):
|
|
|
|
for bad_prefix in bad_prefixes:
|
|
|
|
for i, flag in enumerate(optlist):
|
|
|
|
if flag.startswith(bad_prefix):
|
|
|
|
optlist.pop(i)
|
|
|
|
break
|
|
|
|
return optlist
|
|
|
|
|
|
|
|
cvars = sysconfig.get_config_vars()
|
2014-10-15 04:24:25 -04:00
|
|
|
cvars['OPT'] = "-DNDEBUG -O3 " + str.join(' ', remove_prefixes(cvars['OPT'].split(), ['-g', '-O', '-Wstrict-prototypes', '-DNDEBUG']))
|
|
|
|
cvars["CFLAGS"] = cvars["BASECFLAGS"] + " " + cvars["OPT"]
|
2014-10-16 06:57:38 -04:00
|
|
|
cvars["LDFLAGS"] = '-Wl,--no-as-needed ' + cvars["LDFLAGS"]
|
|
|
|
|
2015-01-12 13:20:53 -05:00
|
|
|
DEFINES = []
|
|
|
|
INCLUDE_DIRS = ['${CMAKE_CURRENT_SOURCE_DIR}/external/boost/include',
|
|
|
|
os.path.join(find_module("numpy")[1], "core", "include"),
|
|
|
|
'${PROJECT_SOURCE_DIR}/include']
|
2015-01-28 17:08:39 -05:00
|
|
|
LIBRARY_DIRS = ['${CMAKE_BINARY_DIR}/lib']
|
2015-01-12 13:20:53 -05:00
|
|
|
|
|
|
|
src = [os.path.join('${CMAKE_CURRENT_SOURCE_DIR}', 'src', sf) for sf in ['_atidlas.cpp']]
|
|
|
|
|
|
|
|
boostsrc = '${CMAKE_CURRENT_SOURCE_DIR}/external/boost/libs/'
|
|
|
|
for s in ['numpy','python','smart_ptr','system','thread']:
|
|
|
|
src = src + [x for x in recursive_glob('${CMAKE_CURRENT_SOURCE_DIR}/external/boost/libs/' + s + '/src/','.cpp') if 'win32' not in x and 'pthread' not in x]
|
|
|
|
# make sure next line succeeds even on Windows
|
|
|
|
src = [f.replace("\\", "/") for f in src]
|
|
|
|
if sys.platform == "win32":
|
|
|
|
src += glob(boostsrc + "/thread/src/win32/*.cpp")
|
|
|
|
src += glob(boostsrc + "/thread/src/tss_null.cpp")
|
|
|
|
else:
|
|
|
|
src += glob(boostsrc + "/thread/src/pthread/*.cpp")
|
|
|
|
src= [f for f in src if not f.endswith("once_atomic.cpp")]
|
|
|
|
|
2014-10-14 23:49:18 -04:00
|
|
|
|
|
|
|
setup(
|
2014-10-15 04:24:25 -04:00
|
|
|
name="pyatidlas",
|
|
|
|
package_dir={ '': '${CMAKE_CURRENT_SOURCE_DIR}' },
|
2014-10-14 23:49:18 -04:00
|
|
|
version=[],
|
|
|
|
description="Auto-tuned input-dependent linear algebra subroutines",
|
|
|
|
author='Philippe Tillet',
|
|
|
|
author_email='ptillet@g.harvard.edu',
|
|
|
|
classifiers=[
|
|
|
|
'Environment :: Console',
|
2014-10-16 06:57:38 -04:00
|
|
|
'Development Status :: 1 - Experimental',
|
2014-10-14 23:49:18 -04:00
|
|
|
'Intended Audience :: Developers',
|
|
|
|
'Intended Audience :: Other Audience',
|
|
|
|
'Intended Audience :: Science/Research',
|
|
|
|
'License :: OSI Approved :: MIT License',
|
|
|
|
'Natural Language :: English',
|
|
|
|
'Programming Language :: C++',
|
|
|
|
'Programming Language :: Python',
|
|
|
|
'Programming Language :: Python :: 2',
|
|
|
|
'Programming Language :: Python :: 2.6',
|
|
|
|
'Programming Language :: Python :: 2.7',
|
|
|
|
'Programming Language :: Python :: 3',
|
|
|
|
'Programming Language :: Python :: 3.2',
|
|
|
|
'Programming Language :: Python :: 3.3',
|
|
|
|
'Programming Language :: Python :: 3.4',
|
|
|
|
'Topic :: Scientific/Engineering',
|
|
|
|
'Topic :: Scientific/Engineering :: Mathematics',
|
|
|
|
'Topic :: Scientific/Engineering :: Physics',
|
|
|
|
'Topic :: Scientific/Engineering :: Machine Learning',
|
|
|
|
],
|
|
|
|
|
2014-10-15 04:24:25 -04:00
|
|
|
packages=["pyatidlas"],
|
|
|
|
ext_package="pyatidlas",
|
2014-10-14 23:49:18 -04:00
|
|
|
ext_modules=[Extension(
|
2015-01-12 13:20:53 -05:00
|
|
|
'_atidlas',src,
|
|
|
|
extra_compile_args= ['-Wno-unused-function', '-Wno-unused-local-typedefs'],
|
|
|
|
extra_link_args=['-Wl,-soname=_atidlas.so'],
|
2014-10-14 23:49:18 -04:00
|
|
|
define_macros=DEFINES,
|
|
|
|
undef_macros=[],
|
|
|
|
include_dirs=INCLUDE_DIRS,
|
2014-10-15 04:24:25 -04:00
|
|
|
library_dirs=LIBRARY_DIRS,
|
2015-01-12 13:20:53 -05:00
|
|
|
libraries=['OpenCL', 'atidlas']
|
2014-10-14 23:49:18 -04:00
|
|
|
)],
|
|
|
|
cmdclass={'build_ext': build_ext_subclass}
|
|
|
|
)
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|