Skip to content

Commit

Permalink
Create a ctypes cython optional compatible package (apache#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
tqchen authored and sergei-mironov committed Aug 8, 2018
1 parent c2b42b8 commit 588fa9b
Show file tree
Hide file tree
Showing 21 changed files with 890 additions and 625 deletions.
10 changes: 7 additions & 3 deletions nnvm/Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export LDFLAGS = -pthread -lm
export CFLAGS = -std=c++11 -Wall -O3 -msse2 -Wno-unknown-pragmas -funroll-loops\
-Iinclude -Idmlc-core/include -I../include -fPIC -L../lib
-Iinclude -Idmlc-core/include -fPIC

# specify tensor path
.PHONY: clean all test lint doc python
.PHONY: clean all test lint doc cython cython3

all: lib/libnnvm.so lib/libnnvm.a cli_test

Expand Down Expand Up @@ -31,9 +31,13 @@ lib/libnnvm.a: $(ALL_DEP)
cli_test: $(ALL_DEP) build/test_main.o
$(CXX) $(CFLAGS) -o $@ $(filter %.o %.a, $^) $(LDFLAGS)

python:
cython:
cd python; python setup.py build_ext --inplace

cython3:
cd python; python3 setup.py build_ext --inplace


lint:
python2 dmlc-core/scripts/lint.py nnvm cpp include src

Expand Down
7 changes: 4 additions & 3 deletions nnvm/python/nnvm/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#!/usr/bin/env python
# coding: utf-8
"""NNVM python API for ease of use and help new framework establish python API. """
from __future__ import absolute_import
from __future__ import absolute_import as _abs

from . import base
from . import _base
from . import symbol as sym
from . import symbol
from ._base import NNVMError

__version__ = base.__version__
__version__ = _base.__version__
5 changes: 3 additions & 2 deletions nnvm/python/nnvm/base.py → nnvm/python/nnvm/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from __future__ import absolute_import

import sys
import os
import ctypes
import numpy as np
from . import libinfo
Expand Down Expand Up @@ -31,7 +32,7 @@ class NNVMError(Exception):
def _load_lib():
"""Load libary by searching possible path."""
lib_path = libinfo.find_lib_path()
lib = ctypes.cdll.LoadLibrary(lib_path[0])
lib = ctypes.CDLL(lib_path[0], ctypes.RTLD_GLOBAL)
# DMatrix functions
lib.NNGetLastError.restype = ctypes.c_char_p
return lib
Expand All @@ -41,13 +42,13 @@ def _load_lib():
# library instance of nnvm
_LIB = _load_lib()


# type definitions
nn_uint = ctypes.c_uint
SymbolCreatorHandle = ctypes.c_void_p
SymbolHandle = ctypes.c_void_p
GraphHandle = ctypes.c_void_p


#----------------------------
# helper function definition
#----------------------------
Expand Down
1 change: 1 addition & 0 deletions nnvm/python/nnvm/_cy2/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This folder is by default empty and will hold DLLs generated by cython.
1 change: 1 addition & 0 deletions nnvm/python/nnvm/_cy2/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Namespace for cython generated modules for python2"""
1 change: 1 addition & 0 deletions nnvm/python/nnvm/_cy3/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This folder is by default empty and will hold DLLs generated by cython.
1 change: 1 addition & 0 deletions nnvm/python/nnvm/_cy3/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Cython generated modules"""
3 changes: 1 addition & 2 deletions nnvm/python/nnvm/attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"""Attribute scoping support for symbolic API."""
from __future__ import absolute_import

from .base import string_types
from ._base import string_types

class AttrScope(object):
"""Attribute manager for scoping.
Expand Down Expand Up @@ -59,4 +59,3 @@ def __exit__(self, ptype, value, trace):
AttrScope.current = self._old_scope

AttrScope.current = AttrScope()

1 change: 1 addition & 0 deletions nnvm/python/nnvm/ctypes/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ctypes specific implementation of certain modules
1 change: 1 addition & 0 deletions nnvm/python/nnvm/ctypes/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
""""ctypes implementation of the Symbol"""
Loading

0 comments on commit 588fa9b

Please sign in to comment.