This is an automated email from the ASF dual-hosted git repository. cjolivier01 pushed a commit to branch cython in repository https://gitbox.apache.org/repos/asf/incubator-mxnet.git
commit ffde37380a323b746716e09eabe1398801020218 Author: Chris Olivier <cjolivie...@gmail.com> AuthorDate: Wed Mar 14 14:06:31 2018 -0700 [WIP] Test CI build (#10111) * Refreshed branch my_cython * Trigger * lint * Set master on mshadow * Don't need sys/time.h * don't use REQUIRE for find_package() python, cython * Add Windows dll linkage to cython test API * Add python and cython installs * Set openmp commit * Added unit test --- 3rdparty/openmp | 2 +- ci/docker/Dockerfile.build.jetson | 1 + cmake/UseCython.cmake | 6 +++--- mshadow | 2 +- python/mxnet/cython/__init__.py | 29 +++++++++++++++++++++++++++++ src/cython/cpp_api.cc | 5 ++--- src/cython/cpp_api.h | 12 +++++++----- tests/python/unittest/test_cython.py | 18 ++++-------------- 8 files changed, 48 insertions(+), 27 deletions(-) diff --git a/3rdparty/openmp b/3rdparty/openmp index 37c7212..29b515e 160000 --- a/3rdparty/openmp +++ b/3rdparty/openmp @@ -1 +1 @@ -Subproject commit 37c72127e90360a020f351f18d9cccfc30e5145a +Subproject commit 29b515e1e6d26b5b0d32d47d28dcdb4b8a11470d diff --git a/ci/docker/Dockerfile.build.jetson b/ci/docker/Dockerfile.build.jetson index e49b48e..08043d2 100755 --- a/ci/docker/Dockerfile.build.jetson +++ b/ci/docker/Dockerfile.build.jetson @@ -59,6 +59,7 @@ RUN JETPACK_DOWNLOAD_PREFIX=http://developer.download.nvidia.com/devzone/devcent dpkg -i $ARM_CUDNN_DEV_INSTALLER_PACKAGE && \ apt update -y && \ apt install -y unzip cuda-cudart-cross-aarch64-8-0 cuda-cublas-cross-aarch64-8-0 \ + apt install -y python python-dev python3 python3-dev cython cython3 \ cuda-nvml-cross-aarch64-8-0 cuda-nvrtc-cross-aarch64-8-0 cuda-cufft-cross-aarch64-8-0 \ cuda-curand-cross-aarch64-8-0 cuda-cusolver-cross-aarch64-8-0 cuda-cusparse-cross-aarch64-8-0 \ cuda-misc-headers-cross-aarch64-8-0 cuda-npp-cross-aarch64-8-0 libcudnn6 && \ diff --git a/cmake/UseCython.cmake b/cmake/UseCython.cmake index f442d72..1f7749c 100644 --- a/cmake/UseCython.cmake +++ b/cmake/UseCython.cmake @@ -96,10 +96,10 @@ if(NOT python_libs_version) message(STATUS "Looking for python dependencies, version: ${python_libs_version}") endif() -find_package(PythonInterp ${python_libs_version} REQUIRED) +find_package(PythonInterp ${python_libs_version}) if(PYTHONINTERP_FOUND) message(STATUS "Python ${python_libs_version} executable: ${PYTHON_EXECUTABLE}") - find_package(PythonLibs ${python_libs_version} REQUIRED) + find_package(PythonLibs ${python_libs_version}) if(PYTHONLIBS_FOUND) set(PYTHON_DEBUG_LIBRARY ${PYTHON_LIBRARY}) set(PYTHON_DEBUG_LIBRARIES ${PYTHON_DEBUG_LIBRARIES}) @@ -110,7 +110,7 @@ if(PYTHONINTERP_FOUND) list(GET PYTHON_VERSION_LIST 1 PYTHON_VERSION_MINOR) list(GET PYTHON_VERSION_LIST 1 PYTHON_VERSION_PATCH) - find_package(Cython ${python_libs_version} REQUIRED) + find_package(Cython ${python_libs_version}) if(CYTHON_FOUND) set(CYTHON${python_libs_version}_FOUND ${python_libs_version}) message(STATUS " CYTHON${python_libs_version}_FOUND: ${CYTHON${python_libs_version}_FOUND}") diff --git a/mshadow b/mshadow index f5b67f3..b3771de 160000 --- a/mshadow +++ b/mshadow @@ -1 +1 @@ -Subproject commit f5b67f380cb0588be11e6f440f92f013139380ee +Subproject commit b3771de20ed36f90ba7b8436ae4b79ea298a687a diff --git a/python/mxnet/cython/__init__.py b/python/mxnet/cython/__init__.py index 13a8339..4c679dd 100644 --- a/python/mxnet/cython/__init__.py +++ b/python/mxnet/cython/__init__.py @@ -14,3 +14,32 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. + +import importlib +import sys + + +def load_cython(package_name, module_name): + # How to pass something like '.' as package_name? + name = package_name + '.cyX.' + module_name + try: + if sys.version_info >= (3, 0): + if len(package_name) > 0 and package_name[0] != '.': + name = package_name + '.cy3.' + module_name + package_name = None + else: + name = 'cy3.' + module_name + else: + if len(package_name) > 0 and package_name[0] != '.': + name = package_name + '.cy2.' + module_name + package_name = None + else: + name = 'cy2.' + module_name + #print('Attemptiog to load cython module: {}'.format(name)) + the_module = importlib.import_module(name, package=package_name) + #print('Loaded cython module: {}'.format(name)) + return the_module + except: + # No cython found + print('Unable to load cython module: {}'.format(name)) + return None diff --git a/src/cython/cpp_api.cc b/src/cython/cpp_api.cc index 44c8009..f0f8736 100644 --- a/src/cython/cpp_api.cc +++ b/src/cython/cpp_api.cc @@ -18,12 +18,11 @@ */ #include <iostream> #include <cstdarg> -#include <sys/time.h> #include <chrono> -#include "cpp_api.h" +#include "./cpp_api.h" extern "C" int CythonPrintFromCPP(const char *foo) { - if(foo) { + if (foo) { std::cout << foo << std::endl << std::flush; } return 0; diff --git a/src/cython/cpp_api.h b/src/cython/cpp_api.h index 249e33d..89567b1 100644 --- a/src/cython/cpp_api.h +++ b/src/cython/cpp_api.h @@ -19,15 +19,17 @@ #ifndef MXNET_CYTHON_CPP_API_H_ #define MXNET_CYTHON_CPP_API_H_ +#include <mxnet/c_api.h> + /*! \brief Inhibit C++ name-mangling for MXNet functions. */ #ifdef __cplusplus extern "C" { #endif // __cplusplus -int CythonPrintFromCPP(const char *foo); -int Printf(const char *fmt, ...); -int TrivialCPPCall(int var); -uint64_t TimeInMilliseconds(); +MXNET_DLL int CythonPrintFromCPP(const char *foo); +MXNET_DLL int Printf(const char *fmt, ...); +MXNET_DLL int TrivialCPPCall(int var); +MXNET_DLL uint64_t TimeInMilliseconds(); #ifdef __cplusplus } @@ -35,7 +37,7 @@ uint64_t TimeInMilliseconds(); namespace shapes { -class Rectangle { +class MXNET_DLL Rectangle { public: int x0, y0, x1, y1; Rectangle(); diff --git a/tests/python/unittest/test_cython.py b/tests/python/unittest/test_cython.py index 5cb6829..650c670 100644 --- a/tests/python/unittest/test_cython.py +++ b/tests/python/unittest/test_cython.py @@ -20,22 +20,11 @@ from __future__ import print_function import sys -import time from mxnet.base import _LIB +import mxnet.cython as cy -try: - if sys.version_info >= (3, 0): - import mxnet.cython.cy3.mxcython as mxc - import mxnet.ndarray.cy3.ndarray as ndcy - import mxnet.symbol.cy3.symbol as symcy - else: - import mxnet.cython.cy2.mxcython as mxc - import mxnet.ndarray.cy2.ndarray as ndcy - import mxnet.symbol.cy2.symbol as symcy -except: - # No cython found - print('Unable to load cython modules') - exit(1) +mxc = cy.load_cython('mxnet.cython', 'mxcython') +cynd = cy.load_cython('mxnet.ndarray', 'ndarray') def test_basic_cython(): print('ENTER test_basic_cython') @@ -69,6 +58,7 @@ def test_perf(count, make_c_call): msg = " WITH API CALL" print("PYTHON {}: {} items took {} seconds".format(msg, count, float(stop - start)/1000)) + def test_perf_bridge(count, do_cython_call, api_call_count): if do_cython_call == 0: assert api_call_count == 0 # Sanity on input values -- To stop receiving notification emails like this one, please contact cjolivie...@apache.org.