Skip to content

Commit bed950d

Browse files
committed
Create a ctypes cython optional compatible package (apache#11)
1 parent 807400a commit bed950d

File tree

21 files changed

+890
-625
lines changed

21 files changed

+890
-625
lines changed

nnvm/Makefile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
export LDFLAGS = -pthread -lm
22
export CFLAGS = -std=c++11 -Wall -O3 -msse2 -Wno-unknown-pragmas -funroll-loops\
3-
-Iinclude -Idmlc-core/include -I../include -fPIC -L../lib
3+
-Iinclude -Idmlc-core/include -fPIC
44

55
# specify tensor path
6-
.PHONY: clean all test lint doc python
6+
.PHONY: clean all test lint doc cython cython3
77

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

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

34-
python:
34+
cython:
3535
cd python; python setup.py build_ext --inplace
3636

37+
cython3:
38+
cd python; python3 setup.py build_ext --inplace
39+
40+
3741
lint:
3842
python2 dmlc-core/scripts/lint.py nnvm cpp include src
3943

nnvm/python/nnvm/__init__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
#!/usr/bin/env python
22
# coding: utf-8
33
"""NNVM python API for ease of use and help new framework establish python API. """
4-
from __future__ import absolute_import
4+
from __future__ import absolute_import as _abs
55

6-
from . import base
6+
from . import _base
77
from . import symbol as sym
88
from . import symbol
9+
from ._base import NNVMError
910

10-
__version__ = base.__version__
11+
__version__ = _base.__version__

nnvm/python/nnvm/base.py renamed to nnvm/python/nnvm/_base.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from __future__ import absolute_import
55

66
import sys
7+
import os
78
import ctypes
89
import numpy as np
910
from . import libinfo
@@ -31,7 +32,7 @@ class NNVMError(Exception):
3132
def _load_lib():
3233
"""Load libary by searching possible path."""
3334
lib_path = libinfo.find_lib_path()
34-
lib = ctypes.cdll.LoadLibrary(lib_path[0])
35+
lib = ctypes.CDLL(lib_path[0], ctypes.RTLD_GLOBAL)
3536
# DMatrix functions
3637
lib.NNGetLastError.restype = ctypes.c_char_p
3738
return lib
@@ -41,13 +42,13 @@ def _load_lib():
4142
# library instance of nnvm
4243
_LIB = _load_lib()
4344

45+
4446
# type definitions
4547
nn_uint = ctypes.c_uint
4648
SymbolCreatorHandle = ctypes.c_void_p
4749
SymbolHandle = ctypes.c_void_p
4850
GraphHandle = ctypes.c_void_p
4951

50-
5152
#----------------------------
5253
# helper function definition
5354
#----------------------------

nnvm/python/nnvm/_cy2/README

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This folder is by default empty and will hold DLLs generated by cython.

nnvm/python/nnvm/_cy2/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Namespace for cython generated modules for python2"""

nnvm/python/nnvm/_cy3/README

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This folder is by default empty and will hold DLLs generated by cython.

nnvm/python/nnvm/_cy3/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Cython generated modules"""

nnvm/python/nnvm/attribute.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"""Attribute scoping support for symbolic API."""
33
from __future__ import absolute_import
44

5-
from .base import string_types
5+
from ._base import string_types
66

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

6161
AttrScope.current = AttrScope()
62-

nnvm/python/nnvm/ctypes/README

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Ctypes specific implementation of certain modules
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
""""ctypes implementation of the Symbol"""

0 commit comments

Comments
 (0)