-
Notifications
You must be signed in to change notification settings - Fork 527
/
test_caffe_main.hpp
78 lines (58 loc) · 1.7 KB
/
test_caffe_main.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// The main caffe test code. Your test cpp code should include this hpp
// to allow a main function to be compiled into the binary.
#ifndef CAFFE_TEST_TEST_CAFFE_MAIN_HPP_
#define CAFFE_TEST_TEST_CAFFE_MAIN_HPP_
#include <glog/logging.h>
#include <gtest/gtest.h>
#include <cstdio>
#include <cstdlib>
#include "caffe/common.hpp"
using std::cout;
using std::endl;
#ifdef CMAKE_BUILD
#include "caffe_config.h"
#else
#define CUDA_TEST_DEVICE -1
#define CMAKE_SOURCE_DIR "src/"
#define EXAMPLES_SOURCE_DIR "examples/"
#define CMAKE_EXT ""
#endif
int main(int argc, char** argv);
namespace caffe {
template <typename TypeParam>
class MultiDeviceTest : public ::testing::Test {
public:
typedef typename TypeParam::Dtype Dtype;
protected:
MultiDeviceTest() {
Caffe::set_mode(TypeParam::device);
}
virtual ~MultiDeviceTest() {}
};
typedef ::testing::Types<float, double> TestDtypes;
template <typename TypeParam>
struct CPUDevice {
typedef TypeParam Dtype;
static const Caffe::Brew device = Caffe::CPU;
};
template <typename Dtype>
class CPUDeviceTest : public MultiDeviceTest<CPUDevice<Dtype> > {
};
#ifdef CPU_ONLY
typedef ::testing::Types<CPUDevice<float>,
CPUDevice<double> > TestDtypesAndDevices;
#else
template <typename TypeParam>
struct GPUDevice {
typedef TypeParam Dtype;
static const Caffe::Brew device = Caffe::GPU;
};
template <typename Dtype>
class GPUDeviceTest : public MultiDeviceTest<GPUDevice<Dtype> > {
};
typedef ::testing::Types<CPUDevice<float>, CPUDevice<double>,
GPUDevice<float>, GPUDevice<double> >
TestDtypesAndDevices;
#endif
} // namespace caffe
#endif // CAFFE_TEST_TEST_CAFFE_MAIN_HPP_