Skip to content

Commit

Permalink
Make python package install more easily
Browse files Browse the repository at this point in the history
  • Loading branch information
tqchen committed Sep 29, 2015
1 parent cdeb822 commit 2358618
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 42 deletions.
11 changes: 9 additions & 2 deletions doc/env_var.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ Environment Variables
MXNet have several settings that can be changed via environment variable.
Usually you do not need to change these settings, but they are listed here for reference.

* MXNET_GPU_WORKER_NTHREADS (default=1 when number of cpu<8, otherwise 2)
* MXNET_GPU_WORKER_NTHREADS (default=1)
- Maximum number of threads that do the computation job on each GPU.
* MXNET_GPU_COPY_NTHREADS (default=1)
- Maximum number of threads that do memory copy job on each GPU.
* MXNET_CPU_WORKER_NTHREADS (default=1)
- Maximum number of threads that do the CPU computation job.
* MXNET_EXEC_ENABLE_INPLACE (default=true)
* MXNET_CPU_PRIORITY_NTHREADS (default=4)
- Number of threads given to prioritized CPU jobs.
* MXNET_EXEC_ENABLE_INPLACE (default=true)
- Whether to enable inplace optimization in symbolic execution.
* MXNET_EXEC_MATCH_RANGE (default=10)
- The rough matching scale in symbolic execution memory allocator.
Expand All @@ -20,3 +22,8 @@ Usually you do not need to change these settings, but they are listed here for r
- NaiveEngine: very simple engine that use master thread to do computation.
- ThreadedEngine: a threaded engine that uses global thread pool to schedule jobs.
- ThreadedEnginePerDevice: a threaded engine that allocates thread per GPU.
* MXNET_KVSTORE_REDUCTION_NTHREADS (default=4)
- Number of threads used for summing of big arrays.
* MXNET_KVSTORE_BIGARRAY_BOUND (default=1e6)
- The minimum size of "big array".
- When the array size is bigger than this threshold, MXNET_KVSTORE_REDUCTION_NTHREADS threads will be used for reduction.
3 changes: 3 additions & 0 deletions python/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dist
*.egg-info
build
9 changes: 9 additions & 0 deletions python/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
MXNet Python Package
====================
MXNet is a deep learning framework designed for both *efficiency* and *flexibility*.
It allows you to mix the flavours of deep learning programs together to maximize the efficiency and your productivity.


Installation
------------
To install, check [Build Instruction](http://mxnet.readthedocs.org/en/latest/build.html)
2 changes: 1 addition & 1 deletion python/mxnet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@
from . import callback
from . import misc

__version__ = "0.1.0"
__version__ = base.__version__
36 changes: 4 additions & 32 deletions python/mxnet/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
""" ctypes library of mxnet and helper functions """
from __future__ import absolute_import

import os
import sys
import ctypes
import platform
import numpy as np
import atexit
from . import libinfo

__all__ = ['MXNetError']
#----------------------------
Expand All @@ -30,43 +29,16 @@ class MXNetError(Exception):
"""Error that will be throwed by all mxnet functions"""
pass


def find_lib_path():
"""Find MXNet dynamic library files.
Returns
-------
lib_path : list(string)
List of all found path to the libraries
"""
curr_path = os.path.dirname(os.path.abspath(os.path.expanduser(__file__)))
api_path = os.path.join(curr_path, '../../lib/')
dll_path = [curr_path, api_path]
if os.name == 'nt':
if platform.architecture()[0] == '64bit':
dll_path.append(os.path.join(api_path, '../windows/x64/Release/'))
else:
dll_path.append(os.path.join(api_path, '../windows/Release/'))
if os.name == 'nt':
dll_path = [os.path.join(p, 'mxnet.dll') for p in dll_path]
else:
dll_path = [os.path.join(p, 'libmxnet.so') for p in dll_path]
lib_path = [p for p in dll_path if os.path.exists(p) and os.path.isfile(p)]
if len(lib_path) == 0:
raise MXNetError('Cannot find find the files.\n' +
'List of candidates:\n' + str('\n'.join(dll_path)))
return lib_path


def _load_lib():
"""Load libary by searching possible path."""
lib_path = find_lib_path()
lib_path = libinfo.find_lib_path()
lib = ctypes.cdll.LoadLibrary(lib_path[0])
# DMatrix functions
lib.MXGetLastError.restype = ctypes.c_char_p
return lib


# version number
__version__ = libinfo.__version__
# library instance of mxnet
_LIB = _load_lib()

Expand Down
35 changes: 35 additions & 0 deletions python/mxnet/libinfo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# coding: utf-8
"""Information about mxnet."""
from __future__ import absolute_import
import os
import platform

def find_lib_path():
"""Find MXNet dynamic library files.
Returns
-------
lib_path : list(string)
List of all found path to the libraries
"""
curr_path = os.path.dirname(os.path.abspath(os.path.expanduser(__file__)))
api_path = os.path.join(curr_path, '../../lib/')
dll_path = [curr_path, api_path]
if os.name == 'nt':
if platform.architecture()[0] == '64bit':
dll_path.append(os.path.join(api_path, '../../windows/x64/Release/'))
else:
dll_path.append(os.path.join(api_path, '../../windows/Release/'))
if os.name == 'nt':
dll_path = [os.path.join(p, 'mxnet.dll') for p in dll_path]
else:
dll_path = [os.path.join(p, 'libmxnet.so') for p in dll_path]
lib_path = [p for p in dll_path if os.path.exists(p) and os.path.isfile(p)]
if len(lib_path) == 0:
raise RuntimeError('Cannot find find the files.\n' +
'List of candidates:\n' + str('\n'.join(dll_path)))
return lib_path


# current version
__version__ = "0.5.0"
21 changes: 14 additions & 7 deletions python/setup.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
"""Setup script for mxnet."""
# pylint: disable=invalid-name, exec-used
"""Setup mxnet package."""
from __future__ import absolute_import
import sys
import os
from setuptools import setup
sys.path.insert(0, '.')
import mxnet

LIB_PATH = mxnet.base.find_lib_path()
# We can not import `mxnet.info.py` in setup.py directly since mxnet/__init__.py
# Will be invoked which introduces dependences
CURRENT_DIR = os.path.dirname(__file__)
libinfo_py = os.path.join(CURRENT_DIR, 'mxnet/libinfo.py')
libinfo = {'__file__': libinfo_py}
exec(compile(open(libinfo_py, "rb").read(), libinfo_py, 'exec'), libinfo, libinfo)

LIB_PATH = libinfo['find_lib_path']()
__version__ = libinfo['__version__']

setup(name='mxnet',
version=mxnet.__version__,
description=mxnet.__doc__,
version=__version__,
description=open(os.path.join(CURRENT_DIR, 'README.md')).read(),
install_requires=[
'numpy',
],
Expand Down

0 comments on commit 2358618

Please sign in to comment.