зеркало из https://github.com/microsoft/caffe.git
common.hpp update
This commit is contained in:
Родитель
36f4cde959
Коммит
298e7a4129
|
@ -4,17 +4,48 @@
|
|||
#include <iostream>
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <cublas_v2.h>
|
||||
#include <glog/logging.h>
|
||||
|
||||
#include "driver_types.h"
|
||||
|
||||
namespace caffeine {
|
||||
using boost::shared_ptr;
|
||||
|
||||
// We will use the boost shared_ptr instead of the new C++11 one mainly
|
||||
// because cuda does not work (at least now) well with C++11 features.
|
||||
using boost::shared_ptr;
|
||||
|
||||
#define CUDA_CHECK(condition) CHECK((condition) == cudaSuccess)
|
||||
#define CUBLAS_CHECK(condition) CHECK((condition) == CUBLAS_STATUS_SUCCESS)
|
||||
|
||||
// A singleton class to hold common caffeine stuff, such as the handler that
|
||||
// caffeine is going to use for cublas.
|
||||
class Caffeine {
|
||||
private:
|
||||
Caffeine() {
|
||||
CUBLAS_CHECK(cublasCreate(&cublas_handle_));
|
||||
};
|
||||
static shared_ptr<Caffeine> singleton_;
|
||||
cublasHandle_t cublas_handle_;
|
||||
public:
|
||||
~Caffeine() {
|
||||
if (!cublas_handle_) {
|
||||
CUBLAS_CHECK(cublasDestroy(cublas_handle_));
|
||||
}
|
||||
}
|
||||
static Caffeine& Get() {
|
||||
if (!singleton_) {
|
||||
singleton_.reset(new Caffeine());
|
||||
}
|
||||
return *singleton_;
|
||||
}
|
||||
|
||||
static cublasHandle_t cublas_handle() {
|
||||
return Get().cublas_handle_;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
static std::ostream nullout(0);
|
||||
|
||||
#define CUDA_CHECK(condition) \
|
||||
CHECK((condition) == cudaSuccess)
|
||||
|
||||
#endif // CAFFEINE_COMMON_HPP_
|
||||
|
|
Загрузка…
Ссылка в новой задаче