Skip to content

Commit d52d669

Browse files
committed
Fix post-rebase errors, including:
-device-abstracted version of MVN -new memset/memcpy wrappers (set_void and copy_void) -fixing MKL switching logic
1 parent e30ba4d commit d52d669

24 files changed

+150
-292
lines changed

include/caffe/common_layers.hpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,16 +120,12 @@ class MVNLayer : public Layer<Dtype> {
120120
virtual inline int ExactNumBottomBlobs() const { return 1; }
121121
virtual inline int ExactNumTopBlobs() const { return 1; }
122122

123-
protected:
124-
virtual Dtype Forward_cpu(const vector<Blob<Dtype>*>& bottom,
125-
vector<Blob<Dtype>*>* top);
126-
virtual Dtype Forward_gpu(const vector<Blob<Dtype>*>& bottom,
123+
virtual Dtype Forward(const vector<Blob<Dtype>*>& bottom,
127124
vector<Blob<Dtype>*>* top);
128-
virtual void Backward_cpu(const vector<Blob<Dtype>*>& top,
125+
virtual void Backward(const vector<Blob<Dtype>*>& top,
129126
const vector<bool>& propagate_down, vector<Blob<Dtype>*>* bottom);
130-
virtual void Backward_gpu(const vector<Blob<Dtype>*>& top,
131-
const vector<bool>& propagate_down, vector<Blob<Dtype>*>* bottom);
132127

128+
protected:
133129
Blob<Dtype> mean_, variance_, temp_;
134130

135131
// sum_multiplier is just used to carry out sum using blas

include/caffe/device.hpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
1-
// Copyright 2014 BVLC and contributors.
2-
31
#ifndef CAFFE_DEVICE_H_
42
#define CAFFE_DEVICE_H_
53

6-
extern "C" {
7-
#include <cblas.h>
8-
}
9-
104
#include "caffe/common.hpp"
5+
#include "caffe/util/mkl_alternate.hpp"
116

127
namespace caffe {
138

@@ -34,10 +29,18 @@ class Device {
3429
/* NOLINT_NEXT_LINE(build/include_what_you_use) */
3530
virtual void copy(const int N, const Dtype *X, Dtype *Y) { NOT_IMPLEMENTED; }
3631

32+
virtual inline void copy_void(const size_t N, const void *X, void* Y) {
33+
NOT_IMPLEMENTED;
34+
}
35+
3736
virtual void set(const int N, const Dtype alpha, Dtype *X) {
3837
NOT_IMPLEMENTED;
3938
}
4039

40+
virtual inline void set_void(const size_t N, const int alpha, void *X) {
41+
NOT_IMPLEMENTED;
42+
}
43+
4144
virtual void add_scalar(const int N, const Dtype alpha, Dtype *X) {
4245
NOT_IMPLEMENTED;
4346
}

include/caffe/devices/cpu.hpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
// Copyright 2014 BVLC and contributors.
2-
31
#ifndef CAFFE_DEVICES_CPU_H_
42
#define CAFFE_DEVICES_CPU_H_
53

6-
extern "C" {
7-
#include <cblas.h>
8-
}
4+
#include "caffe/util/mkl_alternate.hpp"
95

106
#include "caffe/device.hpp"
117

@@ -34,8 +30,18 @@ class CPUDevice : public Device<Dtype> {
3430
/* NOLINT_NEXT_LINE(build/include_what_you_use) */
3531
virtual void copy(const int N, const Dtype *X, Dtype *Y);
3632

33+
virtual inline void copy_void(const size_t N, const void *X, void* Y) {
34+
if (X != Y) {
35+
memcpy(Y, X, N); // NOLINT(caffe/alt_fn)
36+
}
37+
}
38+
3739
virtual void set(const int N, const Dtype alpha, Dtype *X);
3840

41+
virtual inline void set_void(const size_t N, const int alpha, void *X) {
42+
memset(X, alpha, N); // NOLINT(caffe/alt_fn)
43+
}
44+
3945
virtual void add_scalar(const int N, const Dtype alpha, Dtype *X);
4046

4147
virtual void scal(const int N, const Dtype alpha, Dtype *X);

include/caffe/devices/gpu.hpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
// Copyright 2014 BVLC and contributors.
2-
31
#ifndef CAFFE_DEVICES_GPU_H_
42
#define CAFFE_DEVICES_GPU_H_
53

64
#ifndef CPU_ONLY
75

8-
extern "C" {
9-
#include <cblas.h>
10-
}
6+
#include "caffe/util/mkl_alternate.hpp"
117

128
#include "caffe/device.hpp"
139

@@ -36,8 +32,19 @@ class GPUDevice : public Device<Dtype> {
3632
/* NOLINT_NEXT_LINE(build/include_what_you_use) */
3733
virtual void copy(const int N, const Dtype *X, Dtype *Y);
3834

35+
virtual inline void copy_void(const size_t N, const void *X, void* Y) {
36+
if (X != Y) {
37+
// NOLINT_NEXT_LINE(caffe/alt_fn)
38+
CUDA_CHECK(cudaMemcpy(Y, X, N, cudaMemcpyDefault));
39+
}
40+
}
41+
3942
virtual void set(const int N, const Dtype alpha, Dtype *X);
4043

44+
virtual inline void set_void(const size_t N, const int alpha, void *X) {
45+
CUDA_CHECK(cudaMemset(X, alpha, N)); // NOLINT(caffe/alt_fn)
46+
}
47+
4148
virtual void add_scalar(const int N, const Dtype alpha, Dtype *X);
4249

4350
virtual void scal(const int N, const Dtype alpha, Dtype *X);

include/caffe/filler.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#include "caffe/device.hpp"
1515
#include "caffe/proto/caffe.pb.h"
1616
#include "caffe/syncedmem.hpp"
17-
#include "caffe/util/math_functions.hpp"
1817

1918
namespace caffe {
2019

include/caffe/layer.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
#include "caffe/blob.hpp"
88
#include "caffe/common.hpp"
9-
#include "caffe/proto/caffe.pb.h"
109
#include "caffe/device.hpp"
10+
#include "caffe/proto/caffe.pb.h"
1111
#include "caffe/util/device_alternate.hpp"
1212

1313
namespace caffe {

include/caffe/util/rng.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ inline rng_t* caffe_rng() {
1717
return static_cast<caffe::rng_t*>(Caffe::rng_stream().generator());
1818
}
1919

20+
inline unsigned int caffe_rng_rand() {
21+
return (*caffe_rng())();
22+
}
23+
2024
// Fisher–Yates algorithm
2125
template <class RandomAccessIterator, class RandomGenerator>
2226
inline void shuffle(RandomAccessIterator begin, RandomAccessIterator end,

scripts/cpp_lint.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1561,10 +1561,10 @@ def CheckForMultilineCommentsAndStrings(filename, clean_lines, linenum, error):
15611561

15621562

15631563
caffe_alt_function_list = (
1564-
('memset', ['caffe_set', 'caffe_memset']),
1565-
('cudaMemset', ['caffe_gpu_set', 'caffe_gpu_memset']),
1566-
('memcpy', ['caffe_copy', 'caffe_memcpy']),
1567-
('cudaMemcpy', ['caffe_copy', 'caffe_gpu_memcpy']),
1564+
('memset', ['set', 'set_void']),
1565+
('cudaMemset', ['set', 'set_void']),
1566+
('memcpy', ['copy', 'copy_void']),
1567+
('cudaMemcpy', ['copy', 'copy_void']),
15681568
)
15691569

15701570

src/caffe/device_factory.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// Copyright 2014 BVLC and contributors.
2-
31
#include "caffe/common.hpp"
42
#include "caffe/device.hpp"
53
#include "caffe/devices/cpu.hpp"

src/caffe/devices/cpu.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
1-
// Copyright 2014 BVLC and contributors.
2-
3-
extern "C" {
4-
#include <cblas.h>
5-
}
6-
71
#include <boost/math/special_functions/next.hpp>
82
#include <boost/random.hpp>
93

10-
#include <limits>
11-
#include <cmath>
124
#include <algorithm>
5+
#include <cmath>
6+
#include <limits>
137

148
#include "caffe/common.hpp"
159
#include "caffe/devices/cpu.hpp"
@@ -137,13 +131,13 @@ void CPUDevice<unsigned int>::axpby(const int N, const unsigned int alpha,
137131

138132
template<typename Dtype>
139133
void CPUDevice<Dtype>::copy(const int N, const Dtype *X, Dtype *Y) {
140-
memcpy(Y, X, sizeof(Dtype) * N);
134+
memcpy(Y, X, sizeof(Dtype) * N); // NOLINT(caffe/alt_fn)
141135
}
142136

143137
template<typename Dtype>
144138
void CPUDevice<Dtype>::set(const int N, const Dtype alpha, Dtype *X) {
145139
if (alpha == 0) {
146-
memset(X, 0, sizeof(Dtype) * N);
140+
memset(X, 0, sizeof(Dtype) * N); // NOLINT(caffe/alt_fn)
147141
return;
148142
}
149143
std::fill_n(X, N, alpha);

0 commit comments

Comments
 (0)