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

Commit 80a850d

Browse files
leezucjolivier01haojin2
authored
Backport 3rdparty/openmp fixes (#17193)
* Upgrade 3rdparty/openmp to release_90 version (#17012) Fixes #10856 * Fix omp assert issue (#17039) * Disable OpenMP offloading support for 3rdparty/openmp (#17098) * Disable OpenMP offloading support for 3rdparty/openmp OpenMP offloading was introduced some time during the past two years and is enabled by default. With upgrading 3rdparty/openmp in #17012 it was made part of the MXNet CMake build. But we don't use OpenMP offloading and the Cuda target in the llvm OpenMP Offloading build is broken in our setting. * Update CMake on CI * Fix reshape interoperability test (#17155) * fix reshape interoperability test * fix for scipy import Co-authored-by: Chris Olivier <[email protected]> Co-authored-by: Hao Jin <[email protected]>
1 parent 0c6f49f commit 80a850d

17 files changed

+109
-44
lines changed

3rdparty/openmp

Submodule openmp updated 578 files

CMakeLists.txt

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.0.2)
1+
cmake_minimum_required(VERSION 3.13)
22

33
# workaround to store CMAKE_CROSSCOMPILING because is getting reset by the project command
44
if(CMAKE_CROSSCOMPILING)
@@ -240,7 +240,7 @@ if(USE_TENSORRT)
240240
endif()
241241

242242
# please note that when you enable this, you might run into an linker not being able to work properly due to large code injection.
243-
# you can find more information here https://github.com/apache/incubator-mxnet/issues/15971
243+
# you can find more information here https://github.com/apache/incubator-mxnet/issues/15971
244244
if(ENABLE_TESTCOVERAGE)
245245
message(STATUS "Compiling with test coverage support enabled. This will result in additional files being written to your source directory!")
246246
find_program( GCOV_PATH gcov )
@@ -436,18 +436,24 @@ endif()
436436

437437
# ---[ OpenMP
438438
if(USE_OPENMP)
439+
440+
function(load_omp)
441+
# Intel/llvm OpenMP: https://github.com/llvm-mirror/openmp
442+
set(OPENMP_STANDALONE_BUILD TRUE)
443+
set(LIBOMP_ENABLE_SHARED TRUE)
444+
set(CMAKE_BUILD_TYPE Release)
445+
set(OPENMP_ENABLE_LIBOMPTARGET OFF CACHE BOOL "LLVM OpenMP offloading support") # Requires CMP0077 CMake 3.13
446+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/openmp)
447+
endfunction()
448+
439449
find_package(OpenMP REQUIRED)
440450
# This should build on Windows, but there's some problem and I don't have a Windows box, so
441451
# could a Windows user please fix?
442452
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/openmp/CMakeLists.txt
443453
AND SYSTEM_ARCHITECTURE STREQUAL "x86_64"
444454
AND NOT MSVC
445455
AND NOT CMAKE_CROSSCOMPILING)
446-
447-
# Intel/llvm OpenMP: https://github.com/llvm-mirror/openmp
448-
set(OPENMP_STANDALONE_BUILD TRUE)
449-
set(LIBOMP_ENABLE_SHARED TRUE)
450-
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/openmp)
456+
load_omp()
451457
list(REMOVE_ITEM mxnet_LINKER_LIBS iomp5)
452458
list(APPEND mxnet_LINKER_LIBS omp)
453459
if(UNIX)

ci/build_windows.py

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
33

44
# Licensed to the Apache Software Foundation (ASF) under one
@@ -28,7 +28,9 @@
2828
import platform
2929
import shutil
3030
import sys
31+
import tempfile
3132
import time
33+
import zipfile
3234
from distutils.dir_util import copy_tree
3335
from enum import Enum
3436
from subprocess import check_call
@@ -147,22 +149,33 @@ def windows_build(args):
147149
mxnet_root = get_mxnet_root()
148150
logging.info("Found MXNet root: {}".format(mxnet_root))
149151

150-
with remember_cwd():
151-
os.chdir(path)
152-
cmd = "\"{}\" && cmake -G \"NMake Makefiles JOM\" {} {}".format(args.vcvars,
153-
CMAKE_FLAGS[args.flavour],
154-
mxnet_root)
155-
logging.info("Generating project with CMake:\n{}".format(cmd))
156-
check_call(cmd, shell=True)
157-
158-
cmd = "\"{}\" && jom".format(args.vcvars)
159-
logging.info("Building with jom:\n{}".format(cmd))
160-
161-
t0 = int(time.time())
162-
check_call(cmd, shell=True)
163-
164-
logging.info("Build flavour: {} complete in directory: \"{}\"".format(args.flavour, os.path.abspath(path)))
165-
logging.info("Build took {}".format(datetime.timedelta(seconds=int(time.time() - t0))))
152+
url = 'https://github.com/Kitware/CMake/releases/download/v3.16.1/cmake-3.16.1-win64-x64.zip'
153+
with tempfile.TemporaryDirectory() as tmpdir:
154+
cmake_file_path = download_file(url, tmpdir)
155+
with zipfile.ZipFile(cmake_file_path, 'r') as zip_ref:
156+
# Create $tmpdir\cmake-3.16.1-win64-x64\bin\cmake.exe
157+
zip_ref.extractall(tmpdir)
158+
159+
with remember_cwd():
160+
os.chdir(path)
161+
cmd = "\"{}\" && {} -G \"NMake Makefiles JOM\" {} {}".format(
162+
args.vcvars,
163+
os.path.join(tmpdir, 'cmake-3.16.1-win64-x64', 'bin', 'cmake.exe'),
164+
CMAKE_FLAGS[args.flavour], mxnet_root)
165+
logging.info("Generating project with CMake:\n{}".format(cmd))
166+
check_call(cmd, shell=True)
167+
168+
cmd = "\"{}\" && jom".format(args.vcvars)
169+
logging.info("Building with jom:\n{}".format(cmd))
170+
171+
t0 = int(time.time())
172+
check_call(cmd, shell=True)
173+
174+
logging.info(
175+
"Build flavour: {} complete in directory: \"{}\"".format(
176+
args.flavour, os.path.abspath(path)))
177+
logging.info("Build took {}".format(
178+
datetime.timedelta(seconds=int(time.time() - t0))))
166179
windows_package(args)
167180

168181

@@ -262,4 +275,3 @@ def main():
262275

263276
if __name__ == '__main__':
264277
sys.exit(main())
265-

ci/docker/Dockerfile.build.android_armv7

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#
1919
# Dockerfile to build MXNet for Android ARMv7
2020

21-
FROM mxnetcipinned/dockcross-base:11262018
21+
FROM dockcross/base
2222
MAINTAINER Pedro Larroy "[email protected]"
2323

2424
# The cross-compiling emulator

ci/docker/Dockerfile.build.android_armv8

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#
1919
# Dockerfile to build MXNet for Android ARM64/ARMv8
2020

21-
FROM mxnetcipinned/dockcross-base:11262018
21+
FROM dockcross/base
2222
MAINTAINER Pedro Larroy "[email protected]"
2323

2424
RUN apt-get update && apt-get install -y \
@@ -82,4 +82,4 @@ RUN /work/ubuntu_adduser.sh
8282

8383
COPY runtime_functions.sh /work/
8484

85-
WORKDIR /work/build
85+
WORKDIR /work/build

ci/docker/Dockerfile.build.armv6

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#
1919
# Dockerfile to build MXNet for ARMv6
2020

21-
FROM mxnetcipinned/dockcross-linux-armv6:11262018
21+
FROM dockcross/linux-armv6
2222

2323
ENV ARCH armv6l
2424
ENV HOSTCC gcc

ci/docker/Dockerfile.build.armv7

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#
1919
# Dockerfile to build MXNet for Android ARMv7
2020

21-
FROM mxnetcipinned/dockcross-linux-armv7:11262018
21+
FROM dockcross/linux-armv7
2222

2323
ENV ARCH armv7l
2424
ENV HOSTCC gcc

ci/docker/Dockerfile.build.armv8

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#
1919
# Dockerfile to build MXNet for ARM64/ARMv8
2020

21-
FROM mxnetcipinned/dockcross-linux-arm64:11262018
21+
FROM dockcross/linux-arm64
2222

2323
ENV ARCH aarch64
2424
ENV HOSTCC gcc

ci/docker/Dockerfile.build.jetson

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
FROM nvidia/cuda:9.0-cudnn7-devel as cudabuilder
2424

25-
FROM mxnetcipinned/dockcross-linux-arm64:11262018
25+
FROM dockcross/linux-arm64
2626

2727
ENV ARCH aarch64
2828
ENV HOSTCC gcc

ci/docker/install/requirements

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ h5py==2.8.0rc1
2626
mock==2.0.0
2727
nose==1.3.7
2828
nose-timer==0.7.3
29-
numpy>1.16.0,<2.0.0
29+
numpy>1.16.0,<1.18.0
3030
pylint==2.3.1; python_version >= '3.0'
3131
requests<2.19.0,>=2.18.4
32-
scipy==1.0.1
32+
scipy==1.2.1
3333
six==1.11.0

ci/docker/install/ubuntu_core.sh

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,10 @@ apt-get install -y \
5353
ln -s /usr/lib/x86_64-linux-gnu/libturbojpeg.so.0.1.0 /usr/lib/x86_64-linux-gnu/libturbojpeg.so
5454

5555

56-
# Note: we specify an exact cmake version to work around a cmake 3.10 CUDA 10 issue.
57-
# Reference: https://github.com/clab/dynet/issues/1457
56+
# CMake 3.13.2+ is required
5857
mkdir /opt/cmake && cd /opt/cmake
59-
wget -nv https://cmake.org/files/v3.12/cmake-3.12.4-Linux-x86_64.sh
60-
sh cmake-3.12.4-Linux-x86_64.sh --prefix=/opt/cmake --skip-license
58+
wget -nv https://cmake.org/files/v3.13/cmake-3.13.5-Linux-x86_64.sh
59+
sh cmake-3.13.5-Linux-x86_64.sh --prefix=/opt/cmake --skip-license
6160
ln -s /opt/cmake/bin/cmake /usr/local/bin/cmake
62-
rm cmake-3.12.4-Linux-x86_64.sh
61+
rm cmake-3.13.5-Linux-x86_64.sh
6362
cmake --version

ci/util.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,15 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18-
import os
1918
import contextlib
2019
import logging
2120
import logging.config
21+
import os
22+
import subprocess
2223
import sys
2324

25+
import requests
26+
2427

2528
def get_mxnet_root() -> str:
2629
curpath = os.path.abspath(os.path.dirname(__file__))
@@ -130,3 +133,31 @@ def config_logging():
130133
# or sensitive information
131134
logging.getLogger("botocore").setLevel(logging.WARNING)
132135
logging.getLogger("requests").setLevel(logging.WARNING)
136+
137+
138+
# Takes url and downloads it to the dest_path directory on Windows.
139+
def download_file(url, dest_path):
140+
file_name = url.split('/')[-1]
141+
full_path = "{}\\{}".format(dest_path, file_name)
142+
logging.info("Downloading: {}".format(full_path))
143+
r = requests.get(url, stream=True)
144+
if r.status_code == 404:
145+
return r.status_code
146+
elif r.status_code != 200:
147+
logging.error("{} returned status code {}".format(url, r.status_code))
148+
with open(full_path, 'wb') as f:
149+
for chunk in r.iter_content(chunk_size=1024):
150+
if chunk: # filter out keep-alive new chunks
151+
f.write(chunk)
152+
return full_path
153+
154+
155+
# Takes arguments and runs command on host. Shell is disabled by default.
156+
def run_command(args, shell=False):
157+
try:
158+
logging.info("Issuing command: {}".format(args))
159+
res = subprocess.check_output(args, shell=shell, timeout=1800).decode("utf-8").replace("\r\n", "")
160+
logging.info("Output: {}".format(res))
161+
except subprocess.CalledProcessError as e:
162+
raise RuntimeError("command '{}' return with error (code {}): {}".format(e.cmd, e.returncode, e.output))
163+
return res

src/engine/openmp.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ OpenMP *OpenMP::Get() {
4141
OpenMP::OpenMP()
4242
: omp_num_threads_set_in_environment_(is_env_set("OMP_NUM_THREADS")) {
4343
#ifdef _OPENMP
44+
initialize_process();
4445
const int max = dmlc::GetEnv("MXNET_OMP_MAX_THREADS", INT_MIN);
4546
if (max != INT_MIN) {
4647
omp_thread_max_ = max;
@@ -61,6 +62,12 @@ OpenMP::OpenMP()
6162
#endif
6263
}
6364

65+
void OpenMP:: initialize_process() {
66+
#ifdef _OPENMP
67+
omp_get_num_procs(); // will force OpenMP to be initialized
68+
#endif
69+
}
70+
6471
void OpenMP::on_start_worker_thread(bool use_omp) {
6572
#ifdef _OPENMP
6673
if (!omp_num_threads_set_in_environment_) {

src/engine/openmp.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,13 @@ class OpenMP {
7474
*/
7575
void on_start_worker_thread(bool use_omp);
7676

77+
/*!
78+
* \brief Initialize a new process to use omp (after a fork,
79+
* in case you're starting threads in the atfork() that may interfere
80+
* with the initialization. Can serialize the init with this first.
81+
*/
82+
void initialize_process();
83+
7784
/*!
7885
* \brief Get the OpenMP object's singleton pointer
7986
* \return Singleton OpenMP object pointer

src/initialize.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ void LibraryInitializer::atfork_child() {
209209
#if MXNET_USE_OPENCV && !__APPLE__
210210
cv::setNumThreads(mp_cv_num_threads_);
211211
#endif // MXNET_USE_OPENCV
212+
engine::OpenMP::Get()->initialize_process();
212213
engine::OpenMP::Get()->set_thread_max(1);
213214
engine::OpenMP::Get()->set_enabled(false);
214215
Engine::Get()->Start();
@@ -218,6 +219,7 @@ void LibraryInitializer::atfork_child() {
218219

219220
void LibraryInitializer::install_pthread_atfork_handlers() {
220221
#ifndef _WIN32
222+
engine::OpenMP::Get()->initialize_process(); // force omp to set its atfork handler first
221223
pthread_atfork(pthread_atfork_prepare, pthread_atfork_parent, pthread_atfork_child);
222224
#endif
223225
}

tests/python/unittest/test_metric.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import mxnet as mx
1919
import numpy as np
2020
import scipy
21+
from scipy.stats import pearsonr
2122
import json
2223
import math
2324
from common import with_seed
@@ -267,7 +268,7 @@ def test_pearsonr():
267268
pred1 = mx.nd.array([[0.3, 0.7], [0, 1.], [0.4, 0.6]])
268269
label1 = mx.nd.array([[1, 0], [0, 1], [0, 1]])
269270
pearsonr_expected_np = np.corrcoef(pred1.asnumpy().ravel(), label1.asnumpy().ravel())[0, 1]
270-
pearsonr_expected_scipy, _ = scipy.stats.pearsonr(pred1.asnumpy().ravel(), label1.asnumpy().ravel())
271+
pearsonr_expected_scipy, _ = pearsonr(pred1.asnumpy().ravel(), label1.asnumpy().ravel())
271272
macro_pr = mx.metric.create('pearsonr', average='macro')
272273
micro_pr = mx.metric.create('pearsonr', average='micro')
273274

@@ -289,7 +290,7 @@ def test_pearsonr():
289290
label12 = mx.nd.array([[1, 0], [0, 1], [0, 1], [1, 0], [0, 1], [0, 1]])
290291

291292
pearsonr_expected_np = np.corrcoef(pred12.asnumpy().ravel(), label12.asnumpy().ravel())[0, 1]
292-
pearsonr_expected_scipy, _ = scipy.stats.pearsonr(pred12.asnumpy().ravel(), label12.asnumpy().ravel())
293+
pearsonr_expected_scipy, _ = pearsonr(pred12.asnumpy().ravel(), label12.asnumpy().ravel())
293294

294295
macro_pr.reset()
295296
micro_pr.update([label2], [pred2])

tests/python/unittest/test_numpy_interoperability.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ def _add_workload_reshape():
576576
# OpArgMngr.add_workload('reshape', b, (2, 2), order='F') # Items are not equal with order='F'
577577

578578
a = np.array(_np.ones((0, 2)))
579-
OpArgMngr.add_workload('reshape', a, -1, 2)
579+
OpArgMngr.add_workload('reshape', a, (-1, 2))
580580

581581

582582
def _add_workload_rint(array_pool):

0 commit comments

Comments
 (0)