Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dlib
Commits
a602126b
Commit
a602126b
authored
Jan 17, 2018
by
Davis King
Browse files
Made picking of the number of compile threads more robust.
parent
d984a1f4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
3 deletions
+16
-3
setup.py
setup.py
+16
-3
No files found.
setup.py
View file @
a602126b
...
...
@@ -34,7 +34,7 @@ import platform
import
subprocess
import
multiprocessing
from
distutils
import
log
from
math
import
ceil
from
math
import
ceil
,
floor
from
setuptools
import
setup
,
Extension
from
setuptools.command.build_ext
import
build_ext
...
...
@@ -137,8 +137,7 @@ class CMakeBuild(build_ext):
else
:
cmake_args
+=
[
'-DCMAKE_BUILD_TYPE='
+
cfg
]
# Do a parallel build
num_cores
=
int
(
ceil
(
multiprocessing
.
cpu_count
()
/
2.0
))
build_args
+=
[
'--'
,
'-j'
+
str
(
num_cores
)]
build_args
+=
[
'--'
,
'-j'
+
str
(
num_available_cpu_cores
(
4
))]
build_folder
=
os
.
path
.
abspath
(
self
.
build_temp
)
...
...
@@ -152,6 +151,20 @@ class CMakeBuild(build_ext):
print
(
"Invoking CMake build: '{}'"
.
format
([
'cmake'
,
'--build'
,
'.'
]
+
build_args
))
subprocess
.
check_call
([
'cmake'
,
'--build'
,
'.'
]
+
build_args
,
cwd
=
build_folder
)
def
num_available_cpu_cores
(
ram_per_build_process_in_gb
):
try
:
mem_bytes
=
os
.
sysconf
(
'SC_PAGE_SIZE'
)
*
os
.
sysconf
(
'SC_PHYS_PAGES'
)
mem_gib
=
mem_bytes
/
(
1024.
**
3
)
# Assume hyperthreading so divide by 2
num_cores
=
int
(
ceil
(
multiprocessing
.
cpu_count
()
/
2.0
))
# Require 4gb of ram per build thread.
mem_cores
=
int
(
floor
(
mem_gib
/
float
(
ram_per_build_process_in_gb
)
+
0.5
));
# We are limited either by RAM or CPU cores. So pick the limiting amount
# and return that.
return
max
(
min
(
num_cores
,
mem_cores
),
1
)
except
ValueError
:
return
2
# just assume 2 if we can't get the os to tell us the right answer.
from
setuptools.command.test
import
test
as
TestCommand
class
PyTest
(
TestCommand
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment