This repository has been archived by the owner on Aug 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathsetup.py
201 lines (174 loc) · 8.4 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# Copyright (c) 2014-2016, Intel Corporation All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
from __future__ import print_function
import os
import sys
import types
import distutils.ccompiler
from distutils import sysconfig
from distutils.core import setup
from distutils.extension import Extension
from distutils.ccompiler import CCompiler
from distutils.unixccompiler import UnixCCompiler
from Cython.Distutils import build_ext as build_ext_org
import subprocess
MAJOR = 0
MINOR = 7
REVISION = 1
VERSION = '{0}.{1}.{2}'.format(MAJOR, MINOR, REVISION)
# detect the compiler version
def find_compiler_major():
p = subprocess.Popen(['icpc', '-v'],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
out, err = p.communicate()
if not isinstance(err, str):
err = str(err, 'ascii')
tokens = err.split()
version = tokens[2]
major, minor, revision = version.split('.')
print("detecting compiler version:", version)
return int(major)
# functions to find proper command line arguments
def find_offload_switch():
if find_compiler_major() >= 16:
return '-qoffload=mandatory'
else:
return '-offload=mandatory'
# compiler driver for Intel Composer for C/C++
class IntelCompiler(UnixCCompiler, object):
"""Compiler wrapper for Intel Composer for C/C++"""
def __init__(self, verbose=0, dry_run=0, force=0):
super(self.__class__, self).__init__(verbose, dry_run, force)
print('creating IntelCompiler instance')
def set_executables(self, **args):
# basically, we ignore all the tool chain coming in
super(self.__class__, self).set_executables(compiler='icc',
compiler_so='icc',
compiler_cxx='icpc',
linker_exe='icc',
linker_so='icc -shared')
def library_dir_option(self, dir):
# We have to filter out -L/usr/lib64
if dir == '/usr/lib64':
return ''
else:
return super(self.__class__, self).library_dir_option(dir)
def library_option(self, lib):
# We have to filter out -lpythonX.Y
if lib[0:6] == 'python':
return ''
else:
return super(self.__class__, self).library_option(lib)
def _fix_lib_args(self, libraries, library_dirs, runtime_library_dirs):
# we need to have this method here, to avoid an endless
# recursion in UnixCCompiler._fix_lib_args.
libraries, library_dirs, runtime_library_dirs = \
CCompiler._fix_lib_args(self, libraries, library_dirs,
runtime_library_dirs)
libdir = sysconfig.get_config_var('LIBDIR')
if runtime_library_dirs and (libdir in runtime_library_dirs):
runtime_library_dirs.remove(libdir)
return libraries, library_dirs, runtime_library_dirs
# register Intel Composer for C/C++ as the main compiler for pyMIC
def my_new_compiler(plat=None, compiler=None, verbose=0, dry_run=0, force=0):
compiler = IntelCompiler(verbose, dry_run, force)
return compiler
# override naming of the resulting output files
class build_ext(build_ext_org):
def get_ext_filename(self, ext_name):
filename = build_ext_org.get_ext_filename(self, ext_name)
split = os.path.splitext(filename)
basename = os.path.splitext(split[0])[0]
if basename in ['pymic_libxstream', 'liboffload_array']:
filename = basename + split[1]
return filename
# override compiler construction
print('creating compiler instance for Intel Composer for C/C++')
distutils.ccompiler.new_compiler = my_new_compiler
print('done with customizations')
# define the source of LIBXSTREAM and the pyMIC offload engine
libxstream_src = map(lambda x: 'src/libxstream/src/' + x,
['libxstream.cpp', 'libxstream_alloc.cpp',
'libxstream_argument.cpp', 'libxstream_context.cpp',
'libxstream_event.cpp', 'libxstream_offload.cpp',
'libxstream_stream.cpp', 'libxstream_workitem.cpp',
'libxstream_workqueue.cpp'])
sources = ['src/pymic_libxstream.pyx', 'src/pymic_internal.cc',
'src/pymicimpl_misc.cc']
sources.extend(libxstream_src)
engine_libxstream = Extension('pymic.pymic_libxstream',
sources,
language='c++',
include_dirs=['./src/libxstream/include',
'./include/'],
extra_compile_args=['-fPIC', '-std=c++0x',
'-DPYMIC_USE_XSTREAM=1',
'-DLIBXSTREAM_EXPORTED',
find_offload_switch(),
'-Wall', '-pthread',
'-g', '-O2', '-ansi-alias'],
extra_link_args=['-pthread'])
liboffload_array = Extension('pymic.liboffload_array',
['src/offload_array.c'],
language='c',
include_dirs=['./include/'],
extra_compile_args=['-fPIC', '-mmic',
'-std=c99', '-g', '-O2'],
extra_link_args=['-mmic'])
setup(
name='Python Offload Infrastructure for the '
'Intel(R) Many Integrated Core Architecture',
version=VERSION,
author='Michael Klemm',
author_email='[email protected]',
maintainer='Michael Klemm',
maintainer_email='[email protected]',
url='https://github.com/01org/pyMIC',
description='A Python module to offload computation to the '
'Intel(R) Xeon Phi(tm) coprocessor',
long_description=""
"pyMIC is a Python module to offload computation in a "
"Python program to the Intel Xeon Phi coprocessor. It "
"contains offloadable arrays and device management "
"functions. It supports invocation of native kernels "
"(C/C++, Fortran) and blends in with Numpy's array "
"types for float, complex, and int data types. For "
"more information and downloads please visit pyMIC's "
"Github page: https://github.com/01org/pyMIC. You can "
"find pyMIC's mailinglist at "
"https://lists.01.org/mailman/listinfo/pymic. If you "
"want to report a bug, please send an email to the "
"mailinglist or file an issue at Github.",
platforms=['Linux'],
license='BSD-3',
cmdclass={'build_ext': build_ext},
packages=['pymic'],
ext_modules=[engine_libxstream, liboffload_array],
)