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

Addresses comments in runtime feature discovery API #13964

Merged
merged 37 commits into from
Feb 12, 2019
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
ff109f5
Prototype for runtime feature detection
larroy Dec 5, 2018
5ebc7a2
Includes from diamond to quotes
larroy Dec 5, 2018
30f057f
Add CPU feature and BLAS flavour flags
larroy Jan 8, 2019
e9eff40
Add BLAS flavour and CPU SSE and AVX flags
larroy Jan 8, 2019
2e60d23
MXNET_USE_LAPACK
larroy Jan 8, 2019
d913033
Fix C++ linting errors
larroy Jan 8, 2019
939d76c
Expose runtime feature detection in the public C API and in the Pytho…
larroy Jan 9, 2019
80ae05e
Refactor Storage -> FeatureSet
larroy Jan 9, 2019
c6bdb54
Refine documentation
larroy Jan 9, 2019
a27af10
Add failure case
larroy Jan 9, 2019
799a567
Fix pylint
larroy Jan 9, 2019
ba356cf
Address CR comments
larroy Jan 15, 2019
09e68a6
Address CR comments
larroy Jan 23, 2019
acb5982
Merge remote-tracking branch 'upstream/master' into feature_discovery
larroy Jan 23, 2019
ce57e05
Merge remote-tracking branch 'upstream/master' into feature_discovery
larroy Jan 23, 2019
ee462d4
Address CR
larroy Jan 23, 2019
7abd905
Address CR
larroy Jan 23, 2019
81c5d15
Address CR
larroy Jan 23, 2019
4f02a6d
Address CR
larroy Jan 23, 2019
ccff811
remove old files
larroy Jan 23, 2019
23b67d1
Fix unit test
larroy Jan 23, 2019
3758952
Port CMake blas change from #13957
larroy Jan 23, 2019
10e4693
Fix lint
larroy Jan 24, 2019
121e7e9
Merge remote-tracking branch 'upstream/master' into feature_discovery
larroy Jan 25, 2019
9949e0a
mxruntime -> libinfo
larroy Jan 25, 2019
b30faf7
Fix comments
larroy Jan 25, 2019
dfde762
Merge remote-tracking branch 'upstream/master' into feature_discovery…
Feb 10, 2019
6710cdb
restore libinfo.py
Feb 10, 2019
997db3e
Rework API for feature detection / libinfo
Feb 10, 2019
c7a348e
Refine documentation
Feb 11, 2019
3da28d7
Fix lint
Feb 11, 2019
615b051
Fix lint
Feb 11, 2019
d897ef0
Define make_unique only for C++ std < 14
Feb 11, 2019
e3be970
Add memory include
larroy Feb 11, 2019
683f1cc
remove old tests
Feb 11, 2019
8fa05a1
make_unique fiasco
Feb 11, 2019
f6f5356
Fix lint
Feb 11, 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
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -409,12 +409,14 @@ if(USE_OPENMP)
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
add_definitions(-DMXNET_USE_OPENMP=1)
else()
if(OPENMP_FOUND)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
add_definitions(-DMXNET_USE_OPENMP=1)
endif()
endif()
elseif(UNIX AND NOT ANDROID)
Expand Down
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,16 @@ ifeq ($(USE_CUDNN), 1)
LDFLAGS += -lcudnn
endif

ifeq ($(use_blas), open)
CFLAGS += -DMXNET_USE_BLAS_OPEN=1
else ifeq ($(use_blas), atlas)
CFLAGS += -DMXNET_USE_BLAS_ATLAS=1
else ifeq ($(use_blas), mkl)
CFLAGS += -DMXNET_USE_BLAS_MKL=1
else ifeq ($(use_blas), apple)
CFLAGS += -DMXNET_USE_BLAS_APPLE=1
endif

# whether to use F16C instruction set extension for fast fp16 compute on CPU
# if cross compiling you may want to explicitly turn it off if target system does not support it
ifndef USE_F16C
Expand Down
4 changes: 4 additions & 0 deletions cmake/ChooseBlas.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,26 @@ if(BLAS STREQUAL "Atlas" OR BLAS STREQUAL "atlas")
list(APPEND mshadow_LINKER_LIBS ${Atlas_LIBRARIES})
add_definitions(-DMSHADOW_USE_CBLAS=1)
add_definitions(-DMSHADOW_USE_MKL=0)
add_definitions(-DMXNET_USE_BLAS_ATLAS=1)
elseif(BLAS STREQUAL "Open" OR BLAS STREQUAL "open")
find_package(OpenBLAS REQUIRED)
include_directories(SYSTEM ${OpenBLAS_INCLUDE_DIR})
list(APPEND mshadow_LINKER_LIBS ${OpenBLAS_LIB})
add_definitions(-DMSHADOW_USE_CBLAS=1)
add_definitions(-DMSHADOW_USE_MKL=0)
add_definitions(-DMXNET_USE_BLAS_OPEN=1)
elseif(BLAS STREQUAL "MKL" OR BLAS STREQUAL "mkl")
find_package(MKL REQUIRED)
include_directories(SYSTEM ${MKL_INCLUDE_DIR})
list(APPEND mshadow_LINKER_LIBS ${MKL_LIBRARIES})
add_definitions(-DMSHADOW_USE_CBLAS=0)
add_definitions(-DMSHADOW_USE_MKL=1)
add_definitions(-DMXNET_USE_BLAS_MKL=1)
elseif(BLAS STREQUAL "apple")
find_package(Accelerate REQUIRED)
include_directories(SYSTEM ${Accelerate_INCLUDE_DIR})
list(APPEND mshadow_LINKER_LIBS ${Accelerate_LIBRARIES})
add_definitions(-DMSHADOW_USE_MKL=0)
add_definitions(-DMSHADOW_USE_CBLAS=1)
add_definitions(-DMXNET_USE_BLAS_APPLE=1)
endif()
50 changes: 11 additions & 39 deletions include/mxnet/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,47 +25,18 @@
#ifndef MXNET_BASE_H_
#define MXNET_BASE_H_

#include <dmlc/base.h>
#include <dmlc/io.h>
#include <dmlc/type_traits.h>
#include <dmlc/parameter.h>
#include <mshadow/tensor.h>
// nnvm headers for symbolic construction.
#include <nnvm/op.h>
#include <nnvm/tuple.h>
#include <nnvm/symbolic.h>
#include "dmlc/base.h"
#include <string>
#include "dmlc/io.h"
#include "dmlc/type_traits.h"
#include "dmlc/parameter.h"
#include "mshadow/tensor.h"
// nnvm headers for symbolic construction.
#include "nnvm/op.h"
#include "nnvm/tuple.h"
#include "nnvm/symbolic.h"
#include "mxruntime.h"

/*!
*\brief whether to use opencv support
*/
#ifndef MXNET_USE_OPENCV
#define MXNET_USE_OPENCV 1
#endif

/*!
*\brief whether to use cuda support
*/
#ifndef MXNET_USE_CUDA
#define MXNET_USE_CUDA MSHADOW_USE_CUDA
#endif

/*!
*\brief whether to use cudnn library for convolution
*/
#ifndef MXNET_USE_CUDNN
#define MXNET_USE_CUDNN MSHADOW_USE_CUDNN
#endif

/*!
*\brief whether to use cusolver library
*/
#ifndef MXNET_USE_CUSOLVER
#define MXNET_USE_CUSOLVER MSHADOW_USE_CUSOLVER
#endif

/*! \brief Error message for using gpu when MXNET_USE_CUDA==0 */
#define MXNET_GPU_NOT_ENABLED_ERROR "GPU is not enabled"

/*!
* \brief define compatible keywords in g++
Expand Down Expand Up @@ -412,6 +383,7 @@ inline std::ostream& operator<<(std::ostream &out, const Context &ctx) {
#define MXNET_DESCRIBE(...) describe(__VA_ARGS__ "\n\nFrom:" __FILE__ ":" STRINGIZE(__LINE__))
#define ADD_FILELINE "\n\nDefined in " __FILE__ ":L" STRINGIZE(__LINE__)


#if MXNET_USE_MKLDNN == 1
constexpr size_t kMKLDNNAlign = 64;
#endif
Expand Down
19 changes: 19 additions & 0 deletions include/mxnet/c_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,24 @@ MXNET_DLL const char *MXGetLastError();
//-------------------------------------
// Part 0: Global State setups
//-------------------------------------

/*!
* \brief Check if a feature is enabled in the runtime
* \param feature to check mxruntime.h
* \param out set to true if the feature is enabled, false otherwise
* \return 0 when success, -1 when failure happens.
*/
MXNET_DLL int MXRuntimeHasFeature(const mx_uint feature, bool *out);
szha marked this conversation as resolved.
Show resolved Hide resolved


/*!
* \brief Return a list of supported runtime features not enabled inclusive.
* \param size size of the returned array
* \param names ptr to array of strings containing feature names
* \return 0 when success, -1 when failure happens.
*/
MXNET_DLL int MXRuntimeFeatureList(size_t *size, const char ***names);

/*!
* \brief Seed all global random number generators in mxnet.
* \param seed the random number seed.
Expand Down Expand Up @@ -465,6 +483,7 @@ MXNET_DLL int MXGetGPUMemoryInformation64(int dev, uint64_t *free_mem, uint64_t
*/
MXNET_DLL int MXGetVersion(int *out);


//-------------------------------------
// Part 1: NDArray creation and deletion
//-------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions include/mxnet/io.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
#ifndef MXNET_IO_H_
#define MXNET_IO_H_

#include <dmlc/data.h>
#include <dmlc/registry.h>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include "dmlc/data.h"
#include "dmlc/registry.h"
#include "./base.h"
#include "./ndarray.h"

Expand Down
194 changes: 194 additions & 0 deletions include/mxnet/mxruntime.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
/*
szha marked this conversation as resolved.
Show resolved Hide resolved
* 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.
*/

/*!
* Copyright (c) 2018 by Contributors
* \file mxruntime.h
* \brief check MXNet features including compile time support
*/

#pragma once

#include <string>
#include "dmlc/base.h"
#include "mshadow/base.h"

/*!
*\brief whether to use opencv support
*/
#ifndef MXNET_USE_OPENCV
#define MXNET_USE_OPENCV 1
larroy marked this conversation as resolved.
Show resolved Hide resolved
#endif

/*!
*\brief whether to use cuda support
*/
#ifndef MXNET_USE_CUDA
#define MXNET_USE_CUDA MSHADOW_USE_CUDA
#endif

/*!
*\brief whether to use cudnn library for convolution
*/
#ifndef MXNET_USE_CUDNN
#define MXNET_USE_CUDNN MSHADOW_USE_CUDNN
#endif

#ifndef MXNET_USE_NCCL
#define MXNET_USE_NCCL 0
#endif

/*!
*\brief whether to use cusolver library
*/
#ifndef MXNET_USE_CUSOLVER
#define MXNET_USE_CUSOLVER MSHADOW_USE_CUSOLVER
#endif

#ifndef MXNET_ENABLE_CUDA_RTC
#define MXNET_ENABLE_CUDA_RTC 0
#endif

/*! \brief Error message for using gpu when MXNET_USE_CUDA==0 */
#define MXNET_GPU_NOT_ENABLED_ERROR "GPU is not enabled"


#ifndef MXNET_USE_TENSORRT
#define MXNET_USE_TENSORRT 0
#endif


#ifndef MXNET_USE_BLAS_ATLAS
#define MXNET_USE_BLAS_ATLAS 0
#endif

#ifndef MXNET_USE_BLAS_OPEN
#define MXNET_USE_BLAS_OPEN 0
#endif

#ifndef MXNET_USE_BLAS_MKL
#define MXNET_USE_BLAS_MKL 0
#endif

#ifndef MXNET_USE_BLAS_APPLE
#define MXNET_USE_BLAS_APPLE 0
#endif

#ifndef MXNET_USE_LAPACK
#define MXNET_USE_LAPACK 0
#endif

#ifndef MXNET_USE_MKLDNN
#define MXNET_USE_MKLDNN 0
#endif

#ifndef MXNET_USE_OPENMP
#define MXNET_USE_OPENMP 0
#endif

#ifndef MXNET_USE_F16C
#define MXNET_USE_F16C MSHADOW_USE_F16C
#endif

#ifndef MXNET_USE_CAFFE
#define MXNET_USE_CAFFE 0
#endif

#ifndef MXNET_USE_DIST_KVSTORE
#define MXNET_USE_DIST_KVSTORE 0
#endif

#ifndef MXNET_USE_SIGNAL_HANDLER
#define MXNET_USE_SIGNAL_HANDLER 0
#endif



namespace mxnet {
namespace features {
// Check compile flags such as CMakeLists.txt

/// Compile time features
// ATTENTION: When changing this enum, match the strings in mxruntime.cc!!!
larroy marked this conversation as resolved.
Show resolved Hide resolved
enum : uint32_t {
// NVIDIA, CUDA
CUDA = 0,
CUDNN,
NCCL,
CUDA_RTC,
TENSORRT,

// CPU Features / optimizations
CPU_SSE,
CPU_SSE2,
CPU_SSE3,
CPU_SSE4_1,
CPU_SSE4_2,
CPU_SSE4A, // AMD extensions to SSE4
CPU_AVX,
CPU_AVX2,


// Multiprocessing / CPU / System
OPENMP,
SSE,
F16C,
JEMALLOC,

// Math libraries & BLAS
// Flavour of BLAS
BLAS_OPEN,
BLAS_ATLAS,
// Intel(R) Math Kernel Library
BLAS_MKL,
BLAS_APPLE,
// Other math libraries:
// Linear Algebra PACKage
LAPACK,
// Intel(R) Math Kernel Library for Deep Neural Networks
MKLDNN,

// Image processing
OPENCV,

// Misc
CAFFE,
PROFILER,
DIST_KVSTORE,
CXX14,
// Signal handler to print stack traces on exceptions
SIGNAL_HANDLER,
DEBUG,

// size indicator
MAX_FEATURES
};


struct EnumNames {
static const std::vector<std::string> names;
};

/*!
* \return true if the given feature is supported
*/
bool is_enabled(uint32_t feat);

} // namespace features
} // namespace mxnet
2 changes: 1 addition & 1 deletion python/mxnet/gluon/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def _replace_atomic(src, dst):
_MOVEFILE_WRITE_THROUGH = 0x8
_windows_default_flags = _MOVEFILE_WRITE_THROUGH

text_type = unicode if sys.version_info[0] == 2 else str # noqa
text_type = unicode if sys.version_info[0] == 2 else str # pylint: disable=undefined-variable

def _str_to_unicode(x):
"""Handle text decoding. Internal use only"""
Expand Down
Loading