11 #include <dmlc/type_traits.h>
12 #include <dmlc/parameter.h>
13 #include <mshadow/tensor.h>
19 #ifndef MXNET_USE_OPENCV
20 #define MXNET_USE_OPENCV 1
26 #ifndef MXNET_USE_CUDA
27 #define MXNET_USE_CUDA MSHADOW_USE_CUDA
33 #ifndef MXNET_USE_CUDNN
34 #define MXNET_USE_CUDNN MSHADOW_USE_CUDNN
38 #define MXNET_GPU_NOT_ENABLED_ERROR "GPU is not enabled"
44 #if DMLC_USE_CXX11 && defined(__GNUC__) && !defined(__clang_version__)
45 #if __GNUC__ == 4 && __GNUC_MINOR__ < 8
46 #error "Currently we need g++ 4.8 or higher to fully support c++11 features"
57 #define MXNET_API __declspec(dllexport)
59 #define MXNET_API __declspec(dllimport)
68 #ifndef MXNET_PREDICT_ONLY
69 #define MXNET_PREDICT_ONLY 0
82 typedef mshadow::default_real_t
real_t;
131 return !(*
this == b);
137 inline void Save(dmlc::Stream *strm)
const {
146 inline bool Load(dmlc::Stream *strm) {
148 if (strm->Read(&
dev_id,
sizeof(int32_t)) !=
sizeof(int32_t))
return false;
191 template<
typename xpu>
193 return static_cast<mshadow::Stream<xpu>*
>(
stream);
231 namespace parameter {
233 class FieldEntry<mxnet::
TShape>
234 :
public FieldEntryBase<FieldEntry<mxnet::TShape>, mxnet::TShape> {
236 FieldEntry() : enforce_nonzero_(false), expect_ndim_(0) {}
238 typedef FieldEntryBase<FieldEntry<mxnet::TShape>,
mxnet::TShape> Parent;
240 virtual void Check(
void *head)
const {
243 if (expect_ndim_ != 0 && v.ndim() != expect_ndim_) {
244 std::ostringstream os;
245 os <<
"value " << v <<
"for Parameter " << this->key_
246 <<
" has wrong dimensions, expected dimension=" << expect_ndim_;
247 throw dmlc::ParamError(os.str());
249 if (enforce_nonzero_) {
252 std::ostringstream os;
253 os <<
"value " << v <<
"for Parameter " << this->key_
254 <<
" is invalid, the input shape must be nonzero in all dimensions";
255 throw dmlc::ParamError(os.str());
260 inline FieldEntry<mxnet::TShape> &enforce_nonzero() {
261 this->enforce_nonzero_ =
true;
271 bool enforce_nonzero_;
278 #endif // MXNET_BASE_H_
mshadow::TShape TShape
dynamic shape type
Definition: base.h:85
static const int32_t kMaxDevID
the maximal device index
Definition: base.h:154
mshadow::Stream< xpu > * get_stream() const
get mshadow stream from Context
Definition: base.h:192
bool Load(dmlc::Stream *strm)
load the content from binary stream
Definition: base.h:146
mshadow::default_real_t real_t
data type that will be used to store ndarray
Definition: base.h:82
bool operator<(const Context &b) const
Comparator, used to enable Context as std::map key.
mshadow::TBlob TBlob
storage container type
Definition: base.h:87
int dev_mask() const
Get corresponding device mask.
Definition: base.h:107
static const int32_t kMaxDevType
the maximal device type
Definition: base.h:152
execution time context. The information needed in runtime for actual execution.
Definition: base.h:181
static Context Create(DeviceType dev_type, int32_t dev_id)
Create a new context.
DeviceType dev_type
the device type we run the op on
Definition: base.h:98
static Context CPUPinned(int32_t dev_id)
int32_t dev_id
device id we are going to run it on
Definition: base.h:100
void * stream
the stream of the device, can be NULL or Stream<gpu>* in GPU mode
Definition: base.h:185
void Save(dmlc::Stream *strm) const
save the content into binary stream
Definition: base.h:137
mshadow::gpu gpu
mxnet gpu
Definition: base.h:78
DeviceType
Type of device.
Definition: base.h:92
mshadow::cpu cpu
mxnet cpu
Definition: base.h:76
Context()
default constructor
Definition: base.h:102
bool operator!=(const Context &b) const
check if current context not equals another one
Definition: base.h:130
mshadow::index_t index_t
index type usually use unsigned
Definition: base.h:80
static Context GPU(int32_t dev_id)
Context information about the execution enviroment.
Definition: base.h:90
bool operator==(const Context &b) const
check if current context equals another one
Definition: base.h:122