forked from bpartridge/PyPhi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 58ce8c0
Showing
9 changed files
with
2,090 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
|
||
PY_VER = 2.7.3 | ||
SRC = $(shell readlink -f python) | ||
MIC_PY_HOME = $(SRC)/_install | ||
MIC_PY_PATH = $(MIC_PY_HOME)/lib/python2.7 | ||
CTYPES = $(SRC)/Modules/_ctypes | ||
NP_UTILS = numpy/numpyxc.py numpy/setup.cfg numpy/site.cfg | ||
|
||
all: numpyxc | ||
|
||
install: | ||
@echo "To install, copy $(MIC_PY_HOME) where it can be accessed from the MIC card." | ||
$(error) | ||
|
||
python.tgz: | ||
wget http://www.python.org/ftp/python/$(PY_VER)/Python-$(PY_VER).tgz -O $@ | ||
|
||
$(SRC): python.tgz | ||
mkdir -p $@ | ||
tar -xf $< -C $@ --strip-components=1 | ||
|
||
$(SRC)/hostpython: | $(SRC) | ||
# TODO: fail if patched | ||
cd $< && ./configure && make | ||
cd $< && mv python hostpython && mv Parser/pgen Parser/hostpgen && make distclean | ||
|
||
xcompile.patch: | ||
wget http://randomsplat.com/wp-content/uploads/2012/10/Python-$(PY_VER)-xcompile.patch -O $@ | ||
|
||
$(SRC)/patched: xcompile.patch $(SRC)/hostpython | ||
cd $(SRC) && patch -p1 < ../$< | ||
touch $@ | ||
|
||
$(SRC)/Makefile: $(SRC)/patched $(CTYPES)/.git | ||
# Must have unicode UCS4 to be compatible with Numpy on modern Linux systems | ||
cd $(SRC) && ./configure CC="icc -mmic" CXX="icpc -mmic" --host=x86_64 --without-gcc --enable-unicode=ucs4 | ||
|
||
$(CTYPES)/.git: | $(SRC) | ||
mv $(CTYPES) $(CTYPES).orig | ||
git clone https://github.com/bpartridge/xeon_phi_ctypes.git $(CTYPES) | ||
|
||
$(MIC_PY_HOME): $(SRC)/Makefile $(SRC)/patched $(CTYPES)/.git | ||
sed -e "s/-OPT:Olimit=0//g" -i.backup $(SRC)/Makefile | ||
cd $(SRC) && make HOSTPYTHON=./hostpython HOSTPGEN=./Parser/hostpgen \ | ||
CROSS_COMPILE=k1om- CROSS_COMPILE_TARGET=yes HOSTARCH=x86_64 BUILDARCH=x86_64-linux-gnu \ | ||
EXTRA_CFLAGS="-fp-model precise -shared -fPIC" LDFLAGS="" | ||
mkdir -p $(MIC_PY_HOME) | ||
cd $(SRC) && make install HOSTPYTHON=./hostpython CROSS_COMPILE_TARGET=yes prefix=$(MIC_PY_HOME) | ||
|
||
micclean: miccleanobjs | ||
rm $(SRC)/Makefile | ||
|
||
miccleanobjs: | ||
rm -rvf $(SRC)/**/*.o | ||
rm -rf $(SRC)/build | ||
rm -rf $(MIC_PY_HOME) | ||
|
||
numpy.tgz: | ||
wget http://downloads.sourceforge.net/project/numpy/NumPy/1.8.0/numpy-1.8.0.tar.gz -O $@ | ||
|
||
numpy: numpy.tgz | ||
mkdir $@ | ||
tar -xf $< -C $@ --strip-components=1 | ||
|
||
numpyclean: numpy | ||
rm -rf numpy/build | ||
rm -rvf numpy/**/*.o | ||
|
||
numpyxc: numpy | $(MIC_PY_HOME) $(NP_UTILS) | ||
# build_clib forces config.h to be created; it needs to be modified before extensions are built | ||
cd numpy && PYTHONXCPREFIX=$(MIC_PY_HOME) python numpyxc.py build_clib | ||
sed '/INTRIN/ d' -i numpy/build/*/numpy/core/include/numpy/config.h | ||
cd numpy && PYTHONXCPREFIX=$(MIC_PY_HOME) python numpyxc.py build | ||
cd numpy && PYTHONXCPREFIX=$(MIC_PY_HOME) python numpyxc.py install --prefix=$(MIC_PY_HOME) | ||
|
||
nose: | ||
pip install --install-option="--prefix=$(MIC_PY_HOME)" nose | ||
|
||
scipy.tgz: | ||
wget http://downloads.sourceforge.net/project/scipy/scipy/0.13.2/scipy-0.13.2.tar.gz -O $@ | ||
|
||
scipy: scipy.tgz | ||
mkdir $@ | ||
tar -xf $< -C $@ --strip-components=1 | ||
|
||
scipyclean: scipy | ||
rm -rf scipy/build | ||
rm -rvf scipy/**/*.o | ||
|
||
scipyxc: scipy | $(MIC_PY_HOME) $(NP_UTILS) | ||
cp $(NP_UTILS) scipy/ | ||
cd scipy && PYTHONXCPREFIX=$(MIC_PY_HOME) python numpyxc.py install --prefix=$(MIC_PY_HOME) | ||
|
||
.PHONY: all micclean miccleanobjs numpyxc nose |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# PyPhi | ||
## Python for Scientific Computing on Intel's Xeon Phi MIC Platform | ||
|
||
*Compiled by Brenton Partridge, Harvard University* | ||
*All utilities released under Creative Commons CC-BY.* | ||
|
||
This repository contains tools for cross-compiling a Python interpreter | ||
and the Numpy and Scipy libraries for an Intel Xeon Phi coprocessor, | ||
allowing you to run Python code using those libraries as a native | ||
executable on the coprocessor. | ||
|
||
Based on [Emilio Castillo Villar's work](http://software.intel.com/en-us/forums/topic/392736) to cross-compile Python. | ||
|
||
Numpy was never designed to be cross-compiled for anything, much less | ||
a system without a compiler of its own, so much effort was placed into | ||
re-engineering it to use the "MIC" architecture and the relevant Intel MKL | ||
libraries. Internal testing code for Numpy and Scipy also works. | ||
|
||
After downloading the Makefile into a folder and running `make`, | ||
that folder will then contain `python/_install` which will be the | ||
`$PYTHONHOME` whose `bin/python` can be executed on the Phi. | ||
See `mic_task.sh` for a usage example. | ||
|
||
## REQUIREMENTS | ||
|
||
- 64-bit Intel system for compiling. | ||
|
||
- Recent Python installed on that system; | ||
tested with the Anaconda distribution. | ||
|
||
- Intel Composer XE 2013 SP1 installed with MKL and MPI support in | ||
`/opt/intel/composer_xe_2013_sp1/`. | ||
|
||
- A Xeon Phi coprocessor for testing (not needed for compilation itself.) | ||
|
||
## TODO | ||
|
||
- Currently, SSE instructions are disabled for Numpy, since they are | ||
very different on the Phi. This would require a native porting effort | ||
for such files as `einsum.c.src`. | ||
|
||
- MPI such as mpi4py. | ||
|
||
- Pip/setuptools for non-native python packages. | ||
|
||
- A generic modified version of Pip for native python packages. | ||
|
||
## References | ||
|
||
- http://software.intel.com/en-us/forums/topic/392736 | ||
|
||
- http://randomsplat.com/id5-cross-compiling-python-for-embedded-linux.html | ||
|
||
- http://www.nersc.gov/users/computational-systems/testbeds/babbage/#toc-anchor-12 | ||
|
||
- http://www.scipy.org/scipylib/building/linux.html#any-distribution-with-intel-c-compiler-and-mkl | ||
|
||
- http://thread.gmane.org/gmane.comp.python.scientific.user/32036/focus=32037 | ||
|
||
- http://whatschrisdoing.com/blog/2009/10/16/cross-compiling-python-extensions/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
get_micfile | ||
echo $MIC_LD_LIBRARY_PATH > $HOME/MIC_LD_LIBRARY_PATH | ||
ssh `head -n1 micfile.$PBS_JOBID` < $HOME/mic_task.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import sys | ||
print 'sys.maxunicode:', sys.maxunicode | ||
|
||
import numpy as np | ||
|
||
np.seterr(all='ignore') | ||
print "errors:", np.geterr() | ||
|
||
# print 'NumPy version:', np.__version__ | ||
print np.random.test(verbose=3) | ||
# print np.linalg.test() | ||
|
||
print np.log(np.arange(5)) | ||
|
||
import scipy.stats | ||
|
||
print scipy.stats.test(verbose=3) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/bin/sh | ||
#Designed to run on a MIC card | ||
|
||
ulimit -s unlimited | ||
export LD_LIBRARY_PATH=`cat $HOME/MIC_LD_LIBRARY_PATH` | ||
export PYTHONHOME=$HOME/mic/python/_install | ||
export PYTHONPATH=$PYTHONHOME/lib/python2.7:$PYTHONHOME/lib/python2.7/site-packages | ||
export PATH=$PYTHONHOME/bin:$PATH | ||
echo "Number of cores:" `grep -c ^processor /proc/cpuinfo` | ||
# which python | ||
# python -V | ||
# python -m test.test_math | ||
# python -m test.test_ctypes | ||
# echo $PYTHONPATH | ||
# python -c "import sys; print 'sys.maxunicode', sys.maxunicode" | ||
# python -c "import numpy; print 'NumPy version:', numpy.__version__;" | ||
python mic_task.py | ||
# export NPHOME=$PYTHONHOME/lib/python2.7/site-packages/numpy | ||
# python $NPHOME/core/tests/test_arrayprint.py |
Oops, something went wrong.