Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

[MXNET-545] Fix broken cython build #10951

Merged
merged 114 commits into from
May 24, 2019
Merged
Show file tree
Hide file tree
Changes from 100 commits
Commits
Show all changes
114 commits
Select commit Hold shift + click to select a range
9d47eed
Fix broken build with cython 0.28
asitstands May 15, 2018
b3a9784
Fix setup.py to be compatible with cython 0.28
asitstands May 26, 2018
feecd35
Fix broken cython ndarray module
asitstands May 26, 2018
fcc41a0
Revised comments
asitstands May 26, 2018
771a9b6
Replace hard coded library path with one obtained by find_lib_path
asitstands May 26, 2018
df1a291
Add documentation for MXNET_ENABLE_CYTHON and MXNET_ENFORCE_CYTHON
asitstands May 27, 2018
0000950
Add cython build to CI
asitstands Jun 16, 2018
86d1c90
Fix for cython CI
asitstands Jun 16, 2018
f8a7b8c
Adjust python environment for cython CI
asitstands Jun 16, 2018
646ea91
Add make variables to set python executable
asitstands Jun 16, 2018
64057b3
Fix typo
asitstands Jun 16, 2018
5aaa8ad
Fix nnvm include path
asitstands Jun 16, 2018
1f4d53a
Does not use ccache for cython
asitstands Jun 16, 2018
d252bea
Fix issues with the wildcards in the library list in Jenkinsfile
asitstands Jun 16, 2018
cbae43d
Fix issues with the wildcards in the library list in Jenkinsfile (con…
asitstands Jun 16, 2018
be0744a
Fix issues with the wildcards in the library list in Jenkinsfile (con…
asitstands Jun 16, 2018
40ba9de
Intentionally introduce a bug to check that the tests actually runwit…
asitstands Jun 16, 2018
b5b0a54
Remove the intentionally introduced bug
asitstands Jun 16, 2018
c798d38
Update installation doc
asitstands Jun 16, 2018
206e706
Retrigger CI
asitstands Jun 16, 2018
939e9ce
Merge branch 'master' into fix_cython
asitstands Jun 18, 2018
6df4e28
Run cython CI in ubuntu environment instead of CentOS environment
asitstands Jun 19, 2018
741d088
Commit a missed file
asitstands Jun 19, 2018
b32b8a6
Fix a bug in check_cython
asitstands Jun 19, 2018
9a526ec
Refine environments for cython CI
asitstands Jun 19, 2018
17286a4
Restore unrelated changes
asitstands Jun 19, 2018
0d4a2aa
Merge branch 'master' into fix_cython
asitstands Jun 19, 2018
238f40c
Fix a problem occurring when the cython modules for python 2 and 3 ar…
asitstands Jun 19, 2018
7284615
Trigger CI
asitstands Jun 19, 2018
57c3410
Pin the cython version in the CI
asitstands Jun 20, 2018
48039a2
Resolve the confliction with master. Merge branch 'master' into fix_c…
asitstands Jun 22, 2018
96ed71f
Catch up #11320
asitstands Jun 22, 2018
991dd8c
Remove optional arguments unused after #11320
asitstands Jun 23, 2018
d779ec9
Trigger CI
asitstands Jun 23, 2018
5922f88
Trigger CI
asitstands Jun 26, 2018
2fbe3fe
Resolve conflict with master
asitstands Jul 31, 2018
ed1e126
Trigger CI
asitstands Aug 1, 2018
430f38d
Remove unnecessary stype argument from the NDArrayBase constructor
asitstands Aug 2, 2018
e3ad1ca
Revise confusing initialization of `_ndarray_cls`
asitstands Aug 2, 2018
58c2754
Cython CI with CMake
asitstands Aug 3, 2018
d0ef6fe
Add cython build for python3 in CI
asitstands Aug 3, 2018
8140a4d
Fix misplaced cython build in CI
asitstands Aug 3, 2018
5093d83
Adjust CI environments for cython
asitstands Aug 5, 2018
868b170
Merge branch 'master' into fix_cython
asitstands Aug 5, 2018
bf798c9
Fix invalid path for cython generated .so files in cmake build
asitstands Aug 5, 2018
4bca56c
Revert invalid fix
asitstands Aug 5, 2018
e602d88
Revise docs
asitstands Aug 7, 2018
7dd3fa6
Revise check_cython
asitstands Aug 7, 2018
d80fc68
Merge branch 'master' into fix_cython
asitstands Aug 7, 2018
bc838c8
Temporaily use make instead of cmake for debugging
asitstands Aug 7, 2018
8cb0e62
Temporal changes for debugging
asitstands Aug 7, 2018
94f5427
Temporal changes for debugging
asitstands Aug 7, 2018
f6cee03
Temporaily use ctypes instead of cython modules for debugging
asitstands Aug 7, 2018
c505bf0
Temporaily disable ccache for debugging
asitstands Aug 7, 2018
17f6c70
Temporaily use make (DEV = 0) instead of cmake for debugging
asitstands Aug 8, 2018
8ccc5f2
Temporaily disable cudnn for debugging
asitstands Aug 8, 2018
c6d1e49
Merge branch 'master' into fix_cython
asitstands Aug 8, 2018
786b2fd
Restore temporal changes
asitstands Aug 8, 2018
e02cc4f
Temporarily disable coverage report
asitstands Aug 9, 2018
fc6f843
Merge branch 'master' into fix_cython
asitstands Aug 9, 2018
aa64c42
Adapt to Jenkinsfile_utils
asitstands Aug 9, 2018
c90570c
Adapt to Jenkinsfile_utils (cont.)
asitstands Aug 9, 2018
a2bb2e1
Restore unrelated changes
asitstands Aug 9, 2018
d89de2f
Restore temporal changes
asitstands Aug 10, 2018
2297f34
Merge branch 'master' into fix_cython
asitstands Sep 3, 2018
2cc7e85
Merge master
asitstands Sep 25, 2018
2b8628c
Resolve conflict
asitstands Nov 2, 2018
efd5bd2
Merge branch 'master' into fix_cython
asitstands Nov 3, 2018
927ca1a
Resolving conflict
asitstands Nov 5, 2018
d02b89b
Test with the cmake build is removed
asitstands Nov 8, 2018
df89ef3
Resolving conflicts
asitstands Nov 8, 2018
17a702c
Add MXNET_ENABLE_CYTHON=0 to tensorrt test
asitstands Nov 8, 2018
8375dfe
Resolving conflicts
asitstands Nov 8, 2018
d5f6fe6
Fix typo
asitstands Nov 8, 2018
c1480f5
Resolve conflicts
asitstands Nov 13, 2018
fdf344f
Trigger CI
asitstands Nov 13, 2018
7036d9b
Merge branch 'master' into fix_cython
asitstands Nov 21, 2018
e81dba9
Trigger CI
asitstands Nov 21, 2018
92ea420
Merge branch 'master' into fix_cython
asitstands Nov 23, 2018
fcf5986
Adapt to Jenkinsfile refactoring
asitstands Nov 23, 2018
064f56f
Adapt to Jenkinsfile refactoring (cont.)
asitstands Nov 23, 2018
b30ba00
Trigger CI
asitstands Nov 23, 2018
aea2d41
Merge branch 'master' into fix_cython
asitstands Nov 23, 2018
9965e4c
Trigger CI
asitstands Nov 23, 2018
371a8c6
Stash missing cython modules
asitstands Nov 23, 2018
9adca4d
Trigger CI
asitstands Dec 3, 2018
09efb2b
Merge branch 'master' into fix_cython
asitstands Dec 4, 2018
61387bc
Merge branch 'master' into fix_cython
asitstands Dec 5, 2018
10d817c
CMake build of cython modules without unit tests
asitstands Dec 11, 2018
adce15e
Fix typo
asitstands Dec 11, 2018
d7bdf63
Trigger CI
asitstands Dec 12, 2018
83f5a1e
Merge branch 'master' into fix_cython
asitstands Jan 18, 2019
550ae4a
Fix a mistake introduced in merging process
asitstands Jan 18, 2019
2253b76
trigger test
szha Mar 5, 2019
95f42bd
Update Jenkinsfile_utils.groovy
szha Mar 17, 2019
f42fd0a
Trigger CI
asitstands Apr 10, 2019
4ed7657
Merge branch 'fix_cython' of /~https://github.com/asitstands/incubator-…
asitstands Apr 10, 2019
e81093a
Trigger CI
asitstands Apr 10, 2019
9c836bc
Trigger CI
asitstands Apr 13, 2019
4be2da6
Resolving conflicts with master
asitstands Apr 13, 2019
0dce3f9
Merge branch 'master' into fix_cython
asitstands May 3, 2019
ec37d87
Merge branch 'master' into fix_cython
asitstands May 6, 2019
d5de9c4
Trigger tests
asitstands May 6, 2019
11e30ca
Merge branch 'master' into fix_cython
asitstands May 8, 2019
d8c435c
Trigger tests
asitstands May 9, 2019
bc526f2
Merge branch 'master' into fix_cython
asitstands May 9, 2019
25a3dfd
Merge branch 'master' into fix_cython
asitstands May 13, 2019
e300834
Trigger tests
asitstands May 14, 2019
8dbc12f
Trigger tests
asitstands May 14, 2019
10bc51e
Trigger tests
asitstands May 16, 2019
a6005c7
Trigger tests
asitstands May 17, 2019
db80ee7
Trigger tests
asitstands May 18, 2019
a5ad3c0
Merge branch 'master' into fix_cython
asitstands May 22, 2019
1443088
Trigger tests
asitstands May 23, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ mxnet_option(USE_SIGNAL_HANDLER "Print stack traces on segfaults." OFF)
mxnet_option(USE_TENSORRT "Enable infeference optimization with TensorRT." OFF)
mxnet_option(USE_ASAN "Enable Clang/GCC ASAN sanitizers." OFF)
mxnet_option(ENABLE_TESTCOVERAGE "Enable compilation with test coverage metric output" OFF)
mxnet_option(BUILD_CYTHON_MODULES "Build cython modules." OFF)

message(STATUS "CMAKE_CROSSCOMPILING ${CMAKE_CROSSCOMPILING}")
message(STATUS "CMAKE_HOST_SYSTEM_PROCESSOR ${CMAKE_HOST_SYSTEM_PROCESSOR}")
Expand Down Expand Up @@ -806,3 +807,12 @@ endif()
set(LINT_DIRS "include src plugin cpp-package tests")
set(EXCLUDE_PATH "src/operator/contrib/ctc_include")
add_custom_target(mxnet_lint COMMAND ${CMAKE_COMMAND} -DMSVC=${MSVC} -DPYTHON_EXECUTABLE=${PYTHON_EXECUTABLE} -DLINT_DIRS=${LINT_DIRS} -DPROJECT_SOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR} -DPROJECT_NAME=mxnet -DEXCLUDE_PATH=${EXCLUDE_PATH} -P ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/dmlc-core/cmake/lint.cmake)

if(BUILD_CYTHON_MODULES)
include(cmake/BuildCythonModules.cmake)
add_cython_modules(2) # Build cython module for python2 if python2 is found
add_cython_modules(3) # Build cython module for python3 if python3 is found
if((NOT ${PYTHON2_FOUND}) AND (NOT ${PYTHON3_FOUND}))
message(FATAL_ERROR "No python interpreter found to build cython modules")
endif()
endif()
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ doxygen:

# Cython build
cython:
cd python; python setup.py build_ext --inplace --with-cython
cd python; $(PYTHON) setup.py build_ext --inplace --with-cython
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a default value for PYTHON?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the default is just python. It is defined in make/config.mk.


cython2:
cd python; python2 setup.py build_ext --inplace --with-cython
Expand Down
4 changes: 2 additions & 2 deletions ci/Jenkinsfile_utils.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def pack_lib(name, libs, include_gcov_data = false) {
sh returnStatus: true, script: """
set +e
echo "Packing ${libs} into ${name}"
echo ${libs} | sed -e 's/,/ /g' | xargs md5sum
for i in \$(echo ${libs} | sed -e 's/,/ /g'); do md5sum \$i; done
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this the same?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to handle glob patterns in $libs. The names of the shared library files produced by cython depend on the python version and platform. Using glob pattterns is convenient.

return 0
"""
stash includes: libs, name: name
Expand All @@ -86,7 +86,7 @@ def unpack_and_init(name, libs, include_gcov_data = false) {
sh returnStatus: true, script: """
set +e
echo "Unpacked ${libs} from ${name}"
echo ${libs} | sed -e 's/,/ /g' | xargs md5sum
for i in \$(echo ${libs} | sed -e 's/,/ /g'); do md5sum \$i; done
return 0
"""
if (include_gcov_data) {
Expand Down
4 changes: 2 additions & 2 deletions ci/docker/install/ubuntu_python.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ wget -nv https://bootstrap.pypa.io/get-pip.py
python3 get-pip.py
python2 get-pip.py

pip2 install nose cpplint==1.3.0 pylint==1.9.3 'numpy<=1.15.2,>=1.8.2' nose-timer 'requests<2.19.0,>=2.18.4' h5py==2.8.0rc1 scipy==1.0.1 boto3
pip3 install nose cpplint==1.3.0 pylint==2.1.1 'numpy<=1.15.2,>=1.8.2' nose-timer 'requests<2.19.0,>=2.18.4' h5py==2.8.0rc1 scipy==1.0.1 boto3
pip2 install nose cpplint==1.3.0 pylint==1.9.3 'numpy<=1.15.2,>=1.8.2' nose-timer 'requests<2.19.0,>=2.18.4' h5py==2.8.0rc1 scipy==1.0.1 boto3 Cython==0.28.5
pip3 install nose cpplint==1.3.0 pylint==2.1.1 'numpy<=1.15.2,>=1.8.2' nose-timer 'requests<2.19.0,>=2.18.4' h5py==2.8.0rc1 scipy==1.0.1 boto3 Cython==0.28.5
58 changes: 58 additions & 0 deletions ci/docker/runtime_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,26 @@ scala_prepare() {
export MAVEN_OPTS="-Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn"
}

check_cython() {
set -ex
local python_ver=$1
local is_cython_used=$(python${python_ver} <<EOF
import sys
import mxnet as mx
cython_ndarraybase = 'mxnet._cy' + str(sys.version_info.major) + '.ndarray'
print(mx.nd._internal.NDArrayBase.__module__ == cython_ndarraybase)
EOF
)

if [ "${is_cython_used}" != "True" ]; then
echo "ERROR: cython is not used."
return 1
else
echo "NOTE: cython is used."
return 0
fi
}

build_ccache_wrappers() {
set -ex

Expand Down Expand Up @@ -370,6 +390,8 @@ build_ubuntu_cpu_openblas() {
USE_LIBJPEG_TURBO=1 \
USE_SIGNAL_HANDLER=1 \
-j$(nproc)
make cython PYTHON=python2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ccache doesn't work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make cython PYTHON=python3
}

build_ubuntu_cpu_mkl() {
Expand Down Expand Up @@ -682,6 +704,9 @@ build_ubuntu_gpu_cuda91_cudnn7() {
CUDA_ARCH="$CI_CUDA_COMPUTE_CAPABILITIES" \
USE_SIGNAL_HANDLER=1 \
-j$(nproc)

make cython PYTHON=python2
make cython PYTHON=python3
}

build_ubuntu_amalgamation() {
Expand Down Expand Up @@ -749,6 +774,7 @@ build_ubuntu_gpu_cmake() {
-DCMAKE_BUILD_TYPE=Release \
-DCUDA_ARCH_NAME=Manual \
-DCUDA_ARCH_BIN=$CI_CMAKE_CUDA_ARCH_BIN \
-DBUILD_CYTHON_MODULES=1 \
-G Ninja \
/work/mxnet

Expand All @@ -769,12 +795,25 @@ sanity_check() {
nosetests-3.4 tests/tutorials/test_sanity_tutorials.py
}

unittest_ubuntu_python2_cpu_cython() {
set -ex
export PYTHONPATH=./python/
export MXNET_MKLDNN_DEBUG=1
export MXNET_STORAGE_FALLBACK_LOG_VERBOSE=0
export MXNET_ENABLE_CYTHON=1
export MXNET_ENFORCE_CYTHON=1
check_cython 2
nosetests-2.7 $NOSE_COVERAGE_ARGUMENTS $NOSE_TIMER_ARGUMENTS --with-xunit --xunit-file nosetests_unittest.xml --verbose tests/python/unittest
nosetests-2.7 $NOSE_COVERAGE_ARGUMENTS $NOSE_TIMER_ARGUMENTS --with-xunit --xunit-file nosetests_train.xml --verbose tests/python/train
nosetests-2.7 $NOSE_COVERAGE_ARGUMENTS $NOSE_TIMER_ARGUMENTS --with-xunit --xunit-file nosetests_quantization.xml --verbose tests/python/quantization
}

unittest_ubuntu_python2_cpu() {
set -ex
export PYTHONPATH=./python/
export MXNET_MKLDNN_DEBUG=1
export MXNET_STORAGE_FALLBACK_LOG_VERBOSE=0
export MXNET_ENABLE_CYTHON=0
nosetests-2.7 $NOSE_COVERAGE_ARGUMENTS $NOSE_TIMER_ARGUMENTS --with-xunit --xunit-file nosetests_unittest.xml --verbose tests/python/unittest
nosetests-2.7 $NOSE_COVERAGE_ARGUMENTS $NOSE_TIMER_ARGUMENTS --with-xunit --xunit-file nosetests_train.xml --verbose tests/python/train
nosetests-2.7 $NOSE_COVERAGE_ARGUMENTS $NOSE_TIMER_ARGUMENTS --with-xunit --xunit-file nosetests_quantization.xml --verbose tests/python/quantization
Expand All @@ -785,6 +824,7 @@ unittest_ubuntu_python3_cpu() {
export PYTHONPATH=./python/
export MXNET_MKLDNN_DEBUG=1 # Ignored if not present
export MXNET_STORAGE_FALLBACK_LOG_VERBOSE=0
export MXNET_ENABLE_CYTHON=0
nosetests-3.4 $NOSE_COVERAGE_ARGUMENTS $NOSE_TIMER_ARGUMENTS --with-xunit --xunit-file nosetests_unittest.xml --verbose tests/python/unittest
nosetests-3.4 $NOSE_COVERAGE_ARGUMENTS $NOSE_TIMER_ARGUMENTS --with-xunit --xunit-file nosetests_quantization.xml --verbose tests/python/quantization
}
Expand All @@ -794,6 +834,7 @@ unittest_ubuntu_python3_cpu_mkldnn() {
export PYTHONPATH=./python/
export MXNET_MKLDNN_DEBUG=1 # Ignored if not present
export MXNET_STORAGE_FALLBACK_LOG_VERBOSE=0
export MXNET_ENABLE_CYTHON=0
nosetests-3.4 $NOSE_COVERAGE_ARGUMENTS $NOSE_TIMER_ARGUMENTS --with-xunit --xunit-file nosetests_unittest.xml --verbose tests/python/unittest
nosetests-3.4 $NOSE_COVERAGE_ARGUMENTS $NOSE_TIMER_ARGUMENTS --with-xunit --xunit-file nosetests_mkl.xml --verbose tests/python/mkl
}
Expand All @@ -813,6 +854,19 @@ unittest_ubuntu_python3_gpu() {
export MXNET_MKLDNN_DEBUG=1 # Ignored if not present
export MXNET_STORAGE_FALLBACK_LOG_VERBOSE=0
export CUDNN_VERSION=${CUDNN_VERSION:-7.0.3}
export MXNET_ENABLE_CYTHON=0
nosetests-3.4 $NOSE_COVERAGE_ARGUMENTS $NOSE_TIMER_ARGUMENTS --with-xunit --xunit-file nosetests_gpu.xml --verbose tests/python/gpu
}

unittest_ubuntu_python3_gpu_cython() {
set -ex
export PYTHONPATH=./python/
export MXNET_MKLDNN_DEBUG=1 # Ignored if not present
export MXNET_STORAGE_FALLBACK_LOG_VERBOSE=0
export CUDNN_VERSION=${CUDNN_VERSION:-7.0.3}
export MXNET_ENABLE_CYTHON=1
export MXNET_ENFORCE_CYTHON=1
check_cython 3
nosetests-3.4 $NOSE_COVERAGE_ARGUMENTS $NOSE_TIMER_ARGUMENTS --with-xunit --xunit-file nosetests_gpu.xml --verbose tests/python/gpu
}

Expand All @@ -821,6 +875,7 @@ unittest_ubuntu_python3_gpu_nocudnn() {
export PYTHONPATH=./python/
export MXNET_STORAGE_FALLBACK_LOG_VERBOSE=0
export CUDNN_OFF_TEST_ONLY=true
export MXNET_ENABLE_CYTHON=0
nosetests-3.4 $NOSE_COVERAGE_ARGUMENTS $NOSE_TIMER_ARGUMENTS --with-xunit --xunit-file nosetests_gpu.xml --verbose tests/python/gpu
}

Expand All @@ -830,6 +885,7 @@ unittest_ubuntu_tensorrt_gpu() {
export MXNET_STORAGE_FALLBACK_LOG_VERBOSE=0
export LD_LIBRARY_PATH=/work/mxnet/lib:$LD_LIBRARY_PATH
export CUDNN_VERSION=${CUDNN_VERSION:-7.0.3}
export MXNET_ENABLE_CYTHON=0
python tests/python/tensorrt/lenet5_train.py
nosetests-3.4 $NOSE_COVERAGE_ARGUMENTS $NOSE_TIMER_ARGUMENTS --with-xunit --xunit-file nosetests_trt_gpu.xml --verbose --nocapture tests/python/tensorrt/
}
Expand All @@ -842,6 +898,7 @@ unittest_ubuntu_python2_quantization_gpu() {
export MXNET_MKLDNN_DEBUG=1 # Ignored if not present
export MXNET_STORAGE_FALLBACK_LOG_VERBOSE=0
export CUDNN_VERSION=${CUDNN_VERSION:-7.0.3}
export MXNET_ENABLE_CYTHON=0
nosetests-2.7 $NOSE_COVERAGE_ARGUMENTS $NOSE_TIMER_ARGUMENTS --with-xunit --xunit-file nosetests_quantization_gpu.xml --verbose tests/python/quantization_gpu
}

Expand All @@ -853,6 +910,7 @@ unittest_ubuntu_python3_quantization_gpu() {
export MXNET_MKLDNN_DEBUG=1 # Ignored if not present
export MXNET_STORAGE_FALLBACK_LOG_VERBOSE=0
export CUDNN_VERSION=${CUDNN_VERSION:-7.0.3}
export MXNET_ENABLE_CYTHON=0
nosetests-3.4 $NOSE_COVERAGE_ARGUMENTS $NOSE_TIMER_ARGUMENTS --with-xunit --xunit-file nosetests_quantization_gpu.xml --verbose tests/python/quantization_gpu
}

Expand Down
34 changes: 27 additions & 7 deletions ci/jenkins/Jenkins_steps.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,20 @@ utils = load('ci/Jenkinsfile_utils.groovy')

// mxnet libraries
mx_lib = 'lib/libmxnet.so, lib/libmxnet.a, 3rdparty/dmlc-core/libdmlc.a, 3rdparty/tvm/nnvm/lib/libnnvm.a'
mx_lib_cython = 'lib/libmxnet.so, lib/libmxnet.a, 3rdparty/dmlc-core/libdmlc.a, 3rdparty/tvm/nnvm/lib/libnnvm.a, python/mxnet/_cy2/*.so, python/mxnet/_cy3/*.so'

// Python wheels
mx_pip = 'build/*.whl'

// mxnet cmake libraries, in cmake builds we do not produce a libnvvm static library by default.
mx_cmake_lib = 'build/libmxnet.so, build/libmxnet.a, build/3rdparty/dmlc-core/libdmlc.a, build/tests/mxnet_unit_tests, build/3rdparty/openmp/runtime/src/libomp.so'
mx_cmake_lib_cython = 'build/libmxnet.so, build/libmxnet.a, build/3rdparty/dmlc-core/libdmlc.a, build/tests/mxnet_unit_tests, build/3rdparty/openmp/runtime/src/libomp.so, python/mxnet/_cy2/*.so, python/mxnet/_cy3/*.so'
// mxnet cmake libraries, in cmake builds we do not produce a libnvvm static library by default.
mx_cmake_lib_debug = 'build/libmxnet.so, build/libmxnet.a, build/3rdparty/dmlc-core/libdmlc.a, build/tests/mxnet_unit_tests'
mx_cmake_mkldnn_lib = 'build/libmxnet.so, build/libmxnet.a, build/3rdparty/dmlc-core/libdmlc.a, build/tests/mxnet_unit_tests, build/3rdparty/openmp/runtime/src/libomp.so, build/3rdparty/mkldnn/src/libmkldnn.so.0'
mx_mkldnn_lib = 'lib/libmxnet.so, lib/libmxnet.a, lib/libiomp5.so, lib/libmkldnn.so.0, lib/libmklml_intel.so, lib/libsparse_matrix.so, 3rdparty/dmlc-core/libdmlc.a, 3rdparty/tvm/nnvm/lib/libnnvm.a'
mx_tensorrt_lib = 'build/libmxnet.so, lib/libnvonnxparser_runtime.so.0, lib/libnvonnxparser.so.0, lib/libonnx_proto.so, lib/libonnx.so'
mx_lib_cpp_examples = 'lib/libmxnet.so, lib/libmxnet.a, 3rdparty/dmlc-core/libdmlc.a, 3rdparty/tvm/nnvm/lib/libnnvm.a, 3rdparty/ps-lite/build/libps.a, deps/lib/libprotobuf-lite.a, deps/lib/libzmq.a, build/cpp-package/example/*'
mx_lib_cpp_examples = 'lib/libmxnet.so, lib/libmxnet.a, 3rdparty/dmlc-core/libdmlc.a, 3rdparty/tvm/nnvm/lib/libnnvm.a, 3rdparty/ps-lite/build/libps.a, deps/lib/libprotobuf-lite.a, deps/lib/libzmq.a, build/cpp-package/example/*, python/mxnet/_cy2/*.so, python/mxnet/_cy3/*.so'
mx_lib_cpp_examples_cpu = 'build/libmxnet.so, build/cpp-package/example/*'

// Python unittest for CPU
Expand All @@ -46,6 +48,12 @@ def python2_ut(docker_container_name) {
}
}

def python2_ut_cython(docker_container_name) {
timeout(time: max_time, unit: 'MINUTES') {
utils.docker_run(docker_container_name, 'unittest_ubuntu_python2_cpu_cython', false)
}
}

// Python 3
def python3_ut(docker_container_name) {
timeout(time: max_time, unit: 'MINUTES') {
Expand Down Expand Up @@ -89,6 +97,12 @@ def python3_gpu_ut_nocudnn(docker_container_name) {
}
}

def python3_gpu_ut_cython(docker_container_name) {
timeout(time: max_time, unit: 'MINUTES') {
utils.docker_run(docker_container_name, 'unittest_ubuntu_python3_gpu_cython', true)
}
}

//------------------------------------------------------------------------------------------

def compile_unix_cpu_openblas() {
Expand All @@ -98,7 +112,7 @@ def compile_unix_cpu_openblas() {
timeout(time: max_time, unit: 'MINUTES') {
utils.init_git()
utils.docker_run('ubuntu_cpu', 'build_ubuntu_cpu_openblas', false)
utils.pack_lib('cpu', mx_lib, true)
utils.pack_lib('cpu', mx_lib_cython, true)
}
}
}
Expand Down Expand Up @@ -224,7 +238,7 @@ def compile_unix_cmake_gpu() {
timeout(time: max_time, unit: 'MINUTES') {
utils.init_git()
utils.docker_run('ubuntu_gpu', 'build_ubuntu_gpu_cmake', false)
utils.pack_lib('cmake_gpu', mx_cmake_lib, true)
utils.pack_lib('cmake_gpu', mx_cmake_lib_cython, true)
}
}
}
Expand Down Expand Up @@ -546,8 +560,8 @@ def test_unix_python2_cpu() {
node(NODE_LINUX_CPU) {
ws('workspace/ut-python2-cpu') {
try {
utils.unpack_and_init('cpu', mx_lib, true)
python2_ut('ubuntu_cpu')
utils.unpack_and_init('cpu', mx_lib_cython, true)
python2_ut_cython('ubuntu_cpu')
utils.publish_test_coverage()
} finally {
utils.collect_test_results_unix('nosetests_unittest.xml', 'nosetests_python2_cpu_unittest.xml')
Expand Down Expand Up @@ -648,8 +662,14 @@ def test_unix_python3_gpu() {
node(NODE_LINUX_GPU) {
ws('workspace/ut-python3-gpu') {
try {
utils.unpack_and_init('gpu', mx_lib, true)
python3_gpu_ut('ubuntu_gpu')
/*
* CMake build with llvm openmp causes a segmentation fault.
* We can restore this if the issue is addressed (#12160).
*
* utils.unpack_and_init('cmake_gpu', mx_cmake_lib_cython, true)
*/
utils.unpack_and_init('gpu', mx_lib_cython, true)
python3_gpu_ut_cython('ubuntu_gpu')
utils.publish_test_coverage()
} finally {
utils.collect_test_results_unix('nosetests_gpu.xml', 'nosetests_python3_gpu.xml')
Expand Down
38 changes: 38 additions & 0 deletions cmake/BuildCythonModules.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

function(add_cython_modules python_version)
unset(PYTHON_EXECUTABLE CACHE)
set(PYTHONINTERP_FOUND FALSE)
find_package(PythonInterp ${python_version} EXACT)
if(PYTHONINTERP_FOUND)
find_program(CYTHON_EXECUTABLE NAMES cython)
if(CYTHON_EXECUTABLE)
add_custom_command(COMMAND ${CMAKE_COMMAND} POST_BUILD
-E env MXNET_LIBRARY_PATH=${CMAKE_BINARY_DIR}/libmxnet.so
${PYTHON_EXECUTABLE} setup.py build_ext --inplace --with-cython
TARGET mxnet
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/python")
message("-- Cython modules for python${python_version} will be built")
set(PYTHON${python_version}_FOUND 1 PARENT_SCOPE)
else()
message(FATAL_ERROR "-- Cython not found")
endif()
else()
set(PYTHON${python_version}_FOUND 0 PARENT_SCOPE)
endif()
endfunction()
16 changes: 16 additions & 0 deletions docs/faq/env_var.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,22 @@ When USE_PROFILER is enabled in Makefile or CMake, the following environments ca
- If set to '0', profiler records the events of the symbolic operators.
- If set to '1', profiler records the events of all operators.

## Interface between Python and the C API

* MXNET_ENABLE_CYTHON
- Values: 0(false), 1(true) ```(default=1)```
- If set to 0, MXNet uses the ctypes to interface with the C API.
- If set to 1, MXNet tries to use the cython modules for the ndarray and symbol. If it fails, the ctypes is used or an error occurs depending on MXNET_ENFORCE_CYTHON.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool!


* MXNET_ENFORCE_CYTHON
- Values: 0(false) or 1(true) ```(default=0)```
- This has an effect only if MXNET_ENABLE_CYTHON is 1.
- If set to 0, MXNet fallbacks to the ctypes if importing the cython modules fails.
- If set to 1, MXNet raises an error if importing the cython modules fails.

If cython modules are used, `mx.nd._internal.NDArrayBase` must be `mxnet._cy3.ndarray.NDArrayBase` for python 3 or `mxnet._cy2.ndarray.NDArrayBase` for python 2.
If ctypes is used, it must be `mxnet._ctypes.ndarray.NDArrayBase`.

## Other Environment Variables

* MXNET_GPU_WORKER_NSTREAMS
Expand Down
11 changes: 10 additions & 1 deletion docs/install/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -1371,7 +1371,16 @@ then running:
free -m # to verify the swapfile size has been increased
```

**Step 2** Install MXNet Python Bindings
**Step 2** Build cython modules (optional)

```bash
$ pip install Cython
$ make cython # You can set the python executable with `PYTHON` flag, e.g., make cython PYTHON=python3
```
*MXNet* tries to use the cython modules unless the environment variable `MXNET_ENABLE_CYTHON` is set to `0`. If loading the cython modules fails, the default behavior is falling back to ctypes without any warning. To raise an exception at the failure, set the environment variable `MXNET_ENFORCE_CYTHON` to `1`. See [here](/faq/env_var.html) for more details.


**Step 3** Install MXNet Python Bindings

To install Python bindings run the following commands in the MXNet directory:

Expand Down
3 changes: 3 additions & 0 deletions make/config.mk
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ EXTRA_OPERATORS =
# Create C++ interface package
USE_CPP_PACKAGE = 0

# Python executable. Needed for cython target
PYTHON = python

#----------------------------
# plugins
#----------------------------
Expand Down
Loading