Skip to content

Commit

Permalink
Merge pull request #41 from primitiv/feature/store-default-object
Browse files Browse the repository at this point in the history
Store default objects in python
  • Loading branch information
Yusuke Oda authored Jul 20, 2018
2 parents 04de17a + f0d616b commit aebd0fb
Show file tree
Hide file tree
Showing 13 changed files with 153 additions and 25 deletions.
20 changes: 14 additions & 6 deletions .travis/debian.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ docker run --name travis-ci -v $TRAVIS_BUILD_DIR:/primitiv-python -td debian:sta

# install
docker exec travis-ci bash -c "apt update"
docker exec travis-ci bash -c "apt install -y git build-essential cmake python3-dev python3-pip python3-numpy"
docker exec travis-ci bash -c "apt install -y build-essential cmake python3-dev python3-pip python3-numpy"
docker exec travis-ci bash -c "pip3 install cython scikit-build"

# TODO(vbkaisetsu):
Expand All @@ -17,14 +17,20 @@ docker exec travis-ci bash -c "pip3 install cython scikit-build"
# For more details, see: http://eigen.tuxfamily.org/bz/show_bug.cgi?id=1392

# install Eigen
docker exec travis-ci bash -c "apt install -y mercurial"
docker exec travis-ci bash -c "hg clone https://bitbucket.org/eigen/eigen"
docker exec travis-ci bash -c "apt install -y wget"
docker exec travis-ci bash -c "wget http://bitbucket.org/eigen/eigen/get/3.3.4.tar.bz2 -O ./eigen.tar.bz2"
docker exec travis-ci bash -c "mkdir ./eigen"
docker exec travis-ci bash -c "tar xf ./eigen.tar.bz2 -C ./eigen --strip-components 1"
docker exec travis-ci bash -c "mkdir ./eigen/build"
docker exec travis-ci bash -c "cd ./eigen/build && cmake .."
docker exec travis-ci bash -c "cd ./eigen/build && make && make install"

# install OpenCL environment
docker exec travis-ci bash -c "apt install -y opencl-headers libclblas-dev pkg-config libhwloc-dev libltdl-dev ocl-icd-dev ocl-icd-opencl-dev clang-3.8 llvm-3.8-dev libclang-3.8-dev libz-dev"
docker exec travis-ci bash -c "apt install -y opencl-headers git pkg-config libhwloc-dev libltdl-dev ocl-icd-dev ocl-icd-opencl-dev clang-3.8 llvm-3.8-dev libclang-3.8-dev libz-dev"
docker exec travis-ci bash -c "wget https://github.com/CNugteren/CLBlast/archive/1.2.0.tar.gz -O ./clblast.tar.gz"
docker exec travis-ci bash -c "mkdir ./clblast"
docker exec travis-ci bash -c "tar xf ./clblast.tar.gz -C ./clblast --strip-components 1"
docker exec travis-ci bash -c "cd ./clblast && cmake . && make && make install"
# pocl 0.13 does not contain mem_fence() function that is used by primitiv.
# We build the latest pocl instead of using distribution's package.
# See: https://github.com/pocl/pocl/issues/294
Expand All @@ -34,7 +40,8 @@ docker exec travis-ci bash -c "cd ./pocl && make && make install"

if [ "${WITH_CORE_LIBRARY}" = "yes" ]; then
# script
docker exec travis-ci bash -c "cd /primitiv-python && ./setup.py build --enable-eigen --enable-opencl"
docker exec travis-ci bash -c "cd /primitiv-python && ./setup.py build --enable-eigen --enable-opencl -- -DCMAKE_VERBOSE_MAKEFILE=ON"
docker exec travis-ci bash -c "cd /primitiv-python && ./setup.py build_ext -i --enable-eigen --enable-opencl -- -DCMAKE_VERBOSE_MAKEFILE=ON"
docker exec travis-ci bash -c "cd /primitiv-python && ./setup.py test --enable-eigen --enable-opencl"

# test installing by "pip install"
Expand All @@ -54,13 +61,14 @@ if [ "${WITH_CORE_LIBRARY}" = "yes" ]; then
docker exec travis-ci bash -c "pip3 uninstall -y primitiv"
else
# install core library
docker exec travis-ci bash -c "cd /primitiv-python/primitiv-core && cmake . -DPRIMITIV_USE_EIGEN=ON -DPRIMITIV_USE_OPENCL=ON"
docker exec travis-ci bash -c "cd /primitiv-python/primitiv-core && cmake . -DPRIMITIV_USE_EIGEN=ON -DPRIMITIV_USE_OPENCL=ON -DCMAKE_VERBOSE_MAKEFILE=ON"
docker exec travis-ci bash -c "cd /primitiv-python/primitiv-core && make"
docker exec travis-ci bash -c "cd /primitiv-python/primitiv-core && make install"
docker exec travis-ci bash -c "ldconfig"

# script
docker exec travis-ci bash -c "cd /primitiv-python && ./setup.py build --enable-eigen --enable-opencl --no-build-core-library"
docker exec travis-ci bash -c "cd /primitiv-python && ./setup.py build_ext -i --enable-eigen --enable-opencl --no-build-core-library"
docker exec travis-ci bash -c "cd /primitiv-python && ./setup.py test --enable-eigen --enable-opencl --no-build-core-library"

# test installing by "./setup.py install"
Expand Down
8 changes: 5 additions & 3 deletions .travis/fedora.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ docker run --name travis-ci -v $TRAVIS_BUILD_DIR:/primitiv-python -td fedora:lat

# install
docker exec travis-ci bash -c "dnf update -y"
docker exec travis-ci bash -c "dnf install -y git rpm-build gcc-c++ cmake python3-devel python3-numpy eigen3-devel"
docker exec travis-ci bash -c "dnf install -y rpm-build gcc-c++ cmake make python3-devel python3-numpy eigen3-devel"
docker exec travis-ci bash -c "pip3 install cython scikit-build"

# NOTE(vbkaisetsu):
Expand All @@ -34,7 +34,8 @@ if [ "${WITH_CORE_LIBRARY}" = "yes" ]; then
# script
# docker exec travis-ci bash -c "cd /primitiv-python && ./setup.py build --enable-eigen --enable-opencl"
# docker exec travis-ci bash -c "cd /primitiv-python && ./setup.py test --enable-eigen --enable-opencl"
docker exec travis-ci bash -c "cd /primitiv-python && ./setup.py build --enable-eigen"
docker exec travis-ci bash -c "cd /primitiv-python && ./setup.py build --enable-eigen -- -DCMAKE_VERBOSE_MAKEFILE=ON"
docker exec travis-ci bash -c "cd /primitiv-python && ./setup.py build_ext -i --enable-eigen -- -DCMAKE_VERBOSE_MAKEFILE=ON"
docker exec travis-ci bash -c "cd /primitiv-python && ./setup.py test --enable-eigen"

# test installing by "pip install"
Expand All @@ -53,14 +54,15 @@ if [ "${WITH_CORE_LIBRARY}" = "yes" ]; then
else
# install core library
# docker exec travis-ci bash -c "cd /primitiv-python/primitiv-core && cmake . -DPRIMITIV_USE_EIGEN=ON -DPRIMITIV_USE_OPENCL=ON"
docker exec travis-ci bash -c "cd /primitiv-python/primitiv-core && cmake . -DPRIMITIV_USE_EIGEN=ON"
docker exec travis-ci bash -c "cd /primitiv-python/primitiv-core && cmake . -DPRIMITIV_USE_EIGEN=ON -DCMAKE_VERBOSE_MAKEFILE=ON"
docker exec travis-ci bash -c "cd /primitiv-python/primitiv-core && make"
docker exec travis-ci bash -c "cd /primitiv-python/primitiv-core && make install"

# script
# docker exec travis-ci bash -c "cd /primitiv-python && ./setup.py build --enable-eigen --enable-opencl --no-build-core-library"
# docker exec travis-ci bash -c "export LD_LIBRARY_PATH=/usr/local/lib && cd /primitiv-python && ./setup.py test --enable-eigen --enable-opencl --no-build-core-library"
docker exec travis-ci bash -c "cd /primitiv-python && ./setup.py build --enable-eigen --no-build-core-library"
docker exec travis-ci bash -c "cd /primitiv-python && ./setup.py build_ext -i --enable-eigen --no-build-core-library"
docker exec travis-ci bash -c "export LD_LIBRARY_PATH=/usr/local/lib && cd /primitiv-python && ./setup.py test --enable-eigen --no-build-core-library"

# test installing by "./setup.py install"
Expand Down
6 changes: 4 additions & 2 deletions .travis/osx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ mkdir work
if [ "${WITH_CORE_LIBRARY}" = "yes" ]; then
# script
git submodule update --init
./setup.py build --enable-eigen
./setup.py build --enable-eigen -- -DCMAKE_VERBOSE_MAKEFILE=ON
./setup.py build_ext -i --enable-eigen -- -DCMAKE_VERBOSE_MAKEFILE=ON
./setup.py test --enable-eigen

# test installing by "pip install"
Expand All @@ -40,11 +41,12 @@ if [ "${WITH_CORE_LIBRARY}" = "yes" ]; then
pip3 uninstall -y primitiv
else
pushd primitiv-core
cmake . -DPRIMITIV_USE_EIGEN=ON
cmake . -DPRIMITIV_USE_EIGEN=ON -DCMAKE_VERBOSE_MAKEFILE=ON
make
make install
popd
./setup.py build --enable-eigen --no-build-core-library
./setup.py build_ext -i --enable-eigen --no-build-core-library
./setup.py test --enable-eigen --no-build-core-library

# test installing by "./setup.py install"
Expand Down
14 changes: 10 additions & 4 deletions .travis/ubuntu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@ docker run --name travis-ci -v $TRAVIS_BUILD_DIR:/primitiv-python -td ubuntu:rol

# install
docker exec travis-ci bash -c "apt update"
docker exec travis-ci bash -c "apt install -y git build-essential cmake python3-dev python3-pip python3-numpy libeigen3-dev"
docker exec travis-ci bash -c "apt install -y build-essential cmake python3-dev python3-pip python3-numpy libeigen3-dev"
docker exec travis-ci bash -c "pip3 install cython scikit-build"

# install OpenCL environment
docker exec travis-ci bash -c "apt install -y opencl-headers libclblas-dev pkg-config libhwloc-dev libltdl-dev ocl-icd-dev ocl-icd-opencl-dev clang-3.8 llvm-3.8-dev libclang-3.8-dev libz-dev"
docker exec travis-ci bash -c "apt install -y opencl-headers git wget pkg-config libhwloc-dev libltdl-dev ocl-icd-dev ocl-icd-opencl-dev clang llvm-dev libclang-dev libz-dev"
docker exec travis-ci bash -c "wget https://github.com/CNugteren/CLBlast/archive/1.2.0.tar.gz -O ./clblast.tar.gz"
docker exec travis-ci bash -c "mkdir ./clblast"
docker exec travis-ci bash -c "tar xf ./clblast.tar.gz -C ./clblast --strip-components 1"
docker exec travis-ci bash -c "cd ./clblast && cmake . && make && make install"
# pocl 0.13 does not contain mem_fence() function that is used by primitiv.
# We build the latest pocl instead of using distribution's package.
# See: https://github.com/pocl/pocl/issues/294
Expand All @@ -21,7 +25,8 @@ docker exec travis-ci bash -c "cd ./pocl && make && make install"

if [ "${WITH_CORE_LIBRARY}" = "yes" ]; then
# script
docker exec travis-ci bash -c "cd /primitiv-python && ./setup.py build --enable-eigen --enable-opencl"
docker exec travis-ci bash -c "cd /primitiv-python && ./setup.py build --enable-eigen --enable-opencl -- -DCMAKE_VERBOSE_MAKEFILE=ON"
docker exec travis-ci bash -c "cd /primitiv-python && ./setup.py build_ext -i --enable-eigen --enable-opencl -- -DCMAKE_VERBOSE_MAKEFILE=ON"
docker exec travis-ci bash -c "cd /primitiv-python && ./setup.py test --enable-eigen --enable-opencl"

# test installing by "pip install"
Expand All @@ -41,13 +46,14 @@ if [ "${WITH_CORE_LIBRARY}" = "yes" ]; then
docker exec travis-ci bash -c "pip3 uninstall -y primitiv"
else
# install core library
docker exec travis-ci bash -c "cd /primitiv-python/primitiv-core && cmake . -DPRIMITIV_USE_EIGEN=ON -DPRIMITIV_USE_OPENCL=ON"
docker exec travis-ci bash -c "cd /primitiv-python/primitiv-core && cmake . -DPRIMITIV_USE_EIGEN=ON -DPRIMITIV_USE_OPENCL=ON -DCMAKE_VERBOSE_MAKEFILE=ON"
docker exec travis-ci bash -c "cd /primitiv-python/primitiv-core && make"
docker exec travis-ci bash -c "cd /primitiv-python/primitiv-core && make install"
docker exec travis-ci bash -c "ldconfig"

# script
docker exec travis-ci bash -c "cd /primitiv-python && ./setup.py build --enable-eigen --enable-opencl --no-build-core-library"
docker exec travis-ci bash -c "cd /primitiv-python && ./setup.py build_ext -i --enable-eigen --enable-opencl --no-build-core-library"
docker exec travis-ci bash -c "cd /primitiv-python && ./setup.py test --enable-eigen --enable-opencl --no-build-core-library"

# test installing by "./setup.py install"
Expand Down
2 changes: 1 addition & 1 deletion primitiv-core
Submodule primitiv-core updated 101 files
2 changes: 0 additions & 2 deletions primitiv/_device.pxd
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
cdef extern from "primitiv/device.h":
cdef cppclass CppDevice "primitiv::Device":
@staticmethod
void set_default(CppDevice &dev) except +
void dump_description() except +


Expand Down
17 changes: 16 additions & 1 deletion primitiv/_device.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ from weakref import WeakValueDictionary
# It means that users can not compare instances by using "is" operator.
cdef object py_primitiv_device_weak_dict = WeakValueDictionary()

cdef object py_primitiv_default_device = None


cdef class Device:
"""Interface of the Tensor provider.
Expand All @@ -24,7 +26,20 @@ cdef class Device:
:type device: primitiv.Device
"""
CppDevice.set_default(device.wrapped[0])
global py_primitiv_default_device
py_primitiv_default_device = device

@staticmethod
def get_default():
"""Retrieves the current default device.
:return: The current default device
:rtype: primitiv.Device
"""
if py_primitiv_default_device is None:
raise RuntimeError("Default object is null.")
return py_primitiv_default_device

def dump_description(self):
"""Prints device description to stderr.
Expand Down
Loading

0 comments on commit aebd0fb

Please sign in to comment.