1 #ifndef MSHADOW_TENSOR_BASE_H
2 #define MSHADOW_TENSOR_BASE_H
17 #ifndef MSHADOW_STAND_ALONE
18 #define MSHADOW_STAND_ALONE 0
22 #ifndef MSHADOW_ALLOC_PAD
23 #define MSHADOW_ALLOC_PAD true
31 #ifndef MSHADOW_MIN_PAD_RATIO
32 #define MSHADOW_MIN_PAD_RATIO 2
35 #if MSHADOW_STAND_ALONE
36 #define MSHADOW_USE_CBLAS 0
37 #define MSHADOW_USE_MKL 0
38 #define MSHADOW_USE_CUDA 0
42 #ifndef MSHADOW_USE_CBLAS
43 #define MSHADOW_USE_CBLAS 0
46 #ifndef MSHADOW_USE_MKL
47 #define MSHADOW_USE_MKL 1
50 #ifndef MSHADOW_USE_CUDA
51 #define MSHADOW_USE_CUDA 1
54 #ifndef MSHADOW_SINGLE_PRECISION
55 #define MSHADOW_SINGLE_PRECISION 1
58 #ifndef MSHADOW_USE_SSE
59 #define MSHADOW_USE_SSE 1
62 #ifndef MSHADOW_USE_NVML
63 #define MSHADOW_USE_NVML 0
67 #undef MSHADOW_USE_SSE
68 #define MSHADOW_USE_SSE 0
77 #include <mkl_cblas.h>
79 #include <mkl_vsl_functions.h>
92 #ifdef MSHADOW_XINLINE
93 #error "MSHADOW_XINLINE must not be defined"
96 #define MSHADOW_XINLINE inline __attribute__((always_inline)) __device__ __host__
98 #define MSHADOW_XINLINE inline __attribute__((always_inline))
101 #define MSHADOW_CINLINE inline __attribute__((always_inline))
103 #if defined(__GXX_EXPERIMENTAL_CXX0X) || defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L
104 #define MSHADOW_CONSTEXPR constexpr
106 #define MSHADOW_CONSTEXPR const
114 const float kPi = 3.1415926f;
116 #if MSHADOW_SINGLE_PRECISION
262 dst = max( dst, src );
266 return redres == redsrc ? 1.0f: 0.0f;
269 #if MSHADOW_SINGLE_PRECISION
272 MSHADOW_CONSTEXPR
static real_t kInitV = -DBL_MAX;
280 inline void Error(
const char *msg ){
281 fprintf( stderr,
"Error:%s\n",msg );
286 if( !exp )
Error(
"AssertError" );
289 inline void Assert(
bool exp,
const char *msg ){
290 if( !exp )
Error( msg );
294 fprintf( stderr,
"warning:%s\n",msg );
298 #endif // TENSOR_BASE_H
static MSHADOW_XINLINE real_t Map(real_t a)
map a to result using defined operation
Definition: tensor_base.h:236
void Warning(const char *msg)
warning
Definition: tensor_base.h:293
unsigned index_t
type that will be used for index
Definition: tensor_base.h:123
save to saver: =
Definition: tensor_base.h:170
static MSHADOW_CONSTEXPR real_t kAlphaBLAS
helper constant to use BLAS, alpha
Definition: tensor_base.h:202
static MSHADOW_CONSTEXPR real_t kBetaBLAS
helper constant to use BLAS, beta
Definition: tensor_base.h:191
static MSHADOW_XINLINE real_t Map(real_t a, real_t b)
map a, b to result using defined operation
Definition: tensor_base.h:147
static MSHADOW_XINLINE void Reduce(volatile real_t &dst, volatile real_t src)
do reduction into dst
Definition: tensor_base.h:247
static MSHADOW_XINLINE real_t Map(real_t a, real_t b)
map a, b to result using defined operation
Definition: tensor_base.h:140
divide operator
Definition: tensor_base.h:152
static MSHADOW_XINLINE void Save(real_t &a, real_t b)
save b to a using save method
Definition: tensor_base.h:185
static MSHADOW_CONSTEXPR real_t kBetaBLAS
helper constant to use BLAS, beta
Definition: tensor_base.h:178
static MSHADOW_CONSTEXPR real_t kInitV
an intial value of reducer
Definition: tensor_base.h:270
op::right OPType
corresponding binary operator type
Definition: tensor_base.h:180
static MSHADOW_XINLINE void Reduce(volatile real_t &dst, volatile real_t src)
do reduction into dst
Definition: tensor_base.h:260
op::minus OPType
corresponding binary operator type
Definition: tensor_base.h:206
static MSHADOW_XINLINE real_t Map(real_t a, real_t b)
map a, b to result using defined operation
Definition: tensor_base.h:133
identity function that maps a real number to it self
Definition: tensor_base.h:234
op::mul OPType
corresponding binary operator type
Definition: tensor_base.h:215
float real_t
type that will be used for content
Definition: tensor_base.h:118
const unsigned kRandBufferSize
buffer size for each random number generator
Definition: tensor_base.h:112
get rhs
Definition: tensor_base.h:159
static MSHADOW_XINLINE void Save(real_t &a, real_t b)
save b to a using save method
Definition: tensor_base.h:220
minus to saver: -=
Definition: tensor_base.h:196
static MSHADOW_CONSTEXPR real_t kAlphaBLAS
helper constant to use BLAS, alpha
Definition: tensor_base.h:189
multiply to saver: *=
Definition: tensor_base.h:209
const float kPi
pi
Definition: tensor_base.h:114
static MSHADOW_XINLINE real_t Map(real_t a, real_t b)
map a, b to result using defined operation
Definition: tensor_base.h:154
op::plus OPType
corresponding binary operator type
Definition: tensor_base.h:193
static MSHADOW_XINLINE void Save(real_t &a, real_t b)
save b to a using save method
Definition: tensor_base.h:198
static MSHADOW_CONSTEXPR real_t kBetaBLAS
helper constant to use BLAS, beta
Definition: tensor_base.h:204
void Error(const char *msg)
send error message then exit
Definition: tensor_base.h:280
static MSHADOW_XINLINE void Save(real_t &a, real_t b)
save b to a using save method
Definition: tensor_base.h:172
divide to saver: /=
Definition: tensor_base.h:218
static MSHADOW_CONSTEXPR real_t kAlphaBLAS
helper constant to use BLAS, alpha
Definition: tensor_base.h:176
maximum reducer
Definition: tensor_base.h:258
static MSHADOW_XINLINE real_t PartialGrad(real_t redres, real_t redsrc)
calculate gradient of redres with respect to redsrc, redres: reduced result, redsrc: one of reduction...
Definition: tensor_base.h:251
plus operator
Definition: tensor_base.h:138
save to saver: +=
Definition: tensor_base.h:183
sum reducer
Definition: tensor_base.h:245
void Assert(bool exp, const char *msg)
assert a expression is true
Definition: tensor_base.h:289
mul operator
Definition: tensor_base.h:131
static MSHADOW_CONSTEXPR real_t kInitV
an intial value of reducer
Definition: tensor_base.h:255
static MSHADOW_XINLINE real_t PartialGrad(real_t redres, real_t redsrc)
calculate gradient of redres with respect to redsrc, redres: reduced result, redsrc: one of reduction...
Definition: tensor_base.h:265
static MSHADOW_XINLINE real_t Map(real_t a, real_t b)
map a, b to result using defined operation
Definition: tensor_base.h:161
minus operator
Definition: tensor_base.h:145
op::div OPType
corresponding binary operator type
Definition: tensor_base.h:224
static MSHADOW_XINLINE void Save(real_t &a, real_t b)
save b to a using save method
Definition: tensor_base.h:211