-
Notifications
You must be signed in to change notification settings - Fork 18.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #165 from BVLC/boost-eigen
MKL/non-MKL Reconciliation Caffe no longer requires MKL. By default it builds without it, relying on atlas and cblas instead. Set the `USE_MKL` var in your Makefile.config accordingly.
- Loading branch information
Showing
21 changed files
with
493 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// Copyright 2013 Rowland Depp | ||
|
||
#ifndef CAFFE_UTIL_MKL_ALTERNATE_H_ | ||
#define CAFFE_UTIL_MKL_ALTERNATE_H_ | ||
|
||
#ifdef USE_MKL | ||
|
||
#include <mkl.h> | ||
|
||
#else // If use MKL, simply include the MKL header | ||
|
||
extern "C" { | ||
#include <cblas.h> | ||
} | ||
#include <math.h> | ||
|
||
// Functions that caffe uses but are not present if MKL is not linked. | ||
|
||
// A simple way to define the vsl unary functions. The operation should | ||
// be in the form e.g. y[i] = sqrt(a[i]) | ||
#define DEFINE_VSL_UNARY_FUNC(name, operation) \ | ||
template<typename Dtype> \ | ||
void v##name(const int n, const Dtype* a, Dtype* y) { \ | ||
CHECK_GT(n, 0); CHECK(a); CHECK(y); \ | ||
for (int i = 0; i < n; ++i) { operation; } \ | ||
} \ | ||
inline void vs##name( \ | ||
const int n, const float* a, float* y) { \ | ||
v##name<float>(n, a, y); \ | ||
} \ | ||
inline void vd##name( \ | ||
const int n, const double* a, double* y) { \ | ||
v##name<double>(n, a, y); \ | ||
} | ||
|
||
DEFINE_VSL_UNARY_FUNC(Sqr, y[i] = a[i] * a[i]); | ||
DEFINE_VSL_UNARY_FUNC(Exp, y[i] = exp(a[i])); | ||
|
||
// A simple way to define the vsl unary functions with singular parameter b. | ||
// The operation should be in the form e.g. y[i] = pow(a[i], b) | ||
#define DEFINE_VSL_UNARY_FUNC_WITH_PARAM(name, operation) \ | ||
template<typename Dtype> \ | ||
void v##name(const int n, const Dtype* a, const Dtype b, Dtype* y) { \ | ||
CHECK_GT(n, 0); CHECK(a); CHECK(y); \ | ||
for (int i = 0; i < n; ++i) { operation; } \ | ||
} \ | ||
inline void vs##name( \ | ||
const int n, const float* a, const float b, float* y) { \ | ||
v##name<float>(n, a, b, y); \ | ||
} \ | ||
inline void vd##name( \ | ||
const int n, const double* a, const float b, double* y) { \ | ||
v##name<double>(n, a, b, y); \ | ||
} | ||
|
||
DEFINE_VSL_UNARY_FUNC_WITH_PARAM(Powx, y[i] = pow(a[i], b)); | ||
|
||
// A simple way to define the vsl binary functions. The operation should | ||
// be in the form e.g. y[i] = a[i] + b[i] | ||
#define DEFINE_VSL_BINARY_FUNC(name, operation) \ | ||
template<typename Dtype> \ | ||
void v##name(const int n, const Dtype* a, const Dtype* b, Dtype* y) { \ | ||
CHECK_GT(n, 0); CHECK(a); CHECK(b); CHECK(y); \ | ||
for (int i = 0; i < n; ++i) { operation; } \ | ||
} \ | ||
inline void vs##name( \ | ||
const int n, const float* a, const float* b, float* y) { \ | ||
v##name<float>(n, a, b, y); \ | ||
} \ | ||
inline void vd##name( \ | ||
const int n, const double* a, const double* b, double* y) { \ | ||
v##name<double>(n, a, b, y); \ | ||
} | ||
|
||
DEFINE_VSL_BINARY_FUNC(Add, y[i] = a[i] + b[i]); | ||
DEFINE_VSL_BINARY_FUNC(Sub, y[i] = a[i] - b[i]); | ||
DEFINE_VSL_BINARY_FUNC(Mul, y[i] = a[i] * b[i]); | ||
DEFINE_VSL_BINARY_FUNC(Div, y[i] = a[i] / b[i]); | ||
|
||
// In addition, MKL comes with an additional function axpby that is not present | ||
// in standard blas. We will simply use a two-step (inefficient, of course) way | ||
// to mimic that. | ||
inline void cblas_saxpby(const int N, const float alpha, const float* X, | ||
const int incX, const float beta, float* Y, | ||
const int incY) { | ||
cblas_sscal(N, beta, Y, incY); | ||
cblas_saxpy(N, alpha, X, incX, Y, incY); | ||
} | ||
inline void cblas_daxpby(const int N, const double alpha, const double* X, | ||
const int incX, const double beta, double* Y, | ||
const int incY) { | ||
cblas_dscal(N, beta, Y, incY); | ||
cblas_daxpy(N, alpha, X, incX, Y, incY); | ||
} | ||
|
||
#endif // USE_MKL | ||
#endif // CAFFE_UTIL_MKL_ALTERNATE_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright 2014 BVLC and contributors. | ||
|
||
#ifndef CAFFE_RNG_CPP_HPP_ | ||
#define CAFFE_RNG_CPP_HPP_ | ||
|
||
#include <boost/random/mersenne_twister.hpp> | ||
#include "caffe/common.hpp" | ||
|
||
namespace caffe { | ||
|
||
typedef boost::mt19937 rng_t; | ||
inline rng_t& caffe_rng() { | ||
Caffe::RNG &generator = Caffe::rng_stream(); | ||
return *(caffe::rng_t*) generator.generator(); | ||
} | ||
|
||
} // namespace caffe | ||
|
||
#endif // CAFFE_RNG_HPP_ |
Oops, something went wrong.