-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsetup_conda.py
110 lines (95 loc) · 3.1 KB
/
setup_conda.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
from distutils.core import setup, Extension
import os
from os.path import expanduser, exists, join, realpath, basename, dirname
import sys
def find_path(candidates):
for path in candidates:
if exists(path):
return path
def find_path_with_members(candidates, required_names_we):
"""
Args:
candidates (list): possible directories
required_names_we (list) : candidate directory must contain
filenames in this list (extensions are ignored)
"""
for path in candidates:
if exists(path):
members_we = [basename(p).split('.')[0] for p in os.listdir(path)]
if all(want in members_we for want in required_names_we):
return path
anaconda_dir = '/opt/conda/'
ipp_root = find_path([
expanduser('~/intel/ipp'),
expanduser('/opt/intel/ipp'),
anaconda_dir
])
if ipp_root is None:
raise Exception('Cannot find path to Intel IPP')
else:
ipp_lib_dir = find_path_with_members(
candidates=[
join(ipp_root, 'lib'),
# join(ipp_root, 'lib', 'ia32'),
join(ipp_root, 'lib', 'intel64'),
],
required_names_we=['libippi', 'libipps']
)
if ipp_lib_dir is None:
raise Exception('Cannot find path to Intel IPP')
# Ensure that the image and signal processing lib are in the libdir
ipp = {
'include_dir': join(ipp_root, 'include'),
'lib_dir': ipp_lib_dir,
}
join(ipp_root, 'lib', 'ia32', 'libippi')
# jpeg_turbo_root = '/usr/local/opt/jpeg-turbo'
jpeg_turbo_root = anaconda_dir
if exists(jpeg_turbo_root):
jpeg_turbo = {
# 'lib_dir': join('/usr/local/opt/jpeg-turbo', 'lib'),
# 'include_dir': join('/usr/local/opt/jpeg-turbo', 'include'),
'lib_dir': join(jpeg_turbo_root, 'lib'),
'include_dir': join(jpeg_turbo_root, 'include'),
}
else:
jpeg_turbo_header = find_path([
'/usr/include/jpeglib.h'
])
jpeg_turbo_lib = find_path([
'/usr/lib/x86_64-linux-gnu/libjpeg.so',
'/usr/lib/i386-linux-gnu/libjpeg.so',
])
# We can use the system libjpeg if its version is at least 8
jpeg_version_info = basename(realpath(jpeg_turbo_lib)).split('.')[2:]
jpeg_version_major = int(jpeg_version_info[0])
if jpeg_version_major < 8:
raise Exception('Cannot find LibJpegTurbo')
if jpeg_turbo_header is None or jpeg_turbo_lib is None:
raise Exception('Cannot find LibJpegTurbo')
jpeg_turbo = {
'lib_dir': dirname(jpeg_turbo_lib),
'include_dir': dirname(jpeg_turbo_header),
}
accimage = Extension(
'accimage',
include_dirs=[
jpeg_turbo['include_dir'],
ipp['include_dir']
],
libraries=['jpeg', 'ippi', 'ipps'],
library_dirs=[
jpeg_turbo['lib_dir'],
ipp['lib_dir']
],
sources=[
'accimagemodule.c',
'jpegloader.c',
'imageops.c'
])
setup(name='accimage',
version='0.1',
description='Accelerated image loader and preprocessor for Torch',
author='Marat Dukhan',
author_email='[email protected]',
ext_modules=[accimage])