Repository navigation
Expand file tree
/
Copy pathparallel_cpu.hpp
More file actions
66 lines (51 loc) · 1.64 KB
/
Copy pathparallel_cpu.hpp
File metadata and controls
66 lines (51 loc) · 1.64 KB
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
// Copyright 2016 Yahoo Inc.
// Licensed under the terms of the Apache 2.0 license.
// Please see LICENSE file in the project root for terms.
#ifndef CAFFE_PARALLEL_CPU_HPP_
#define CAFFE_PARALLEL_CPU_HPP_
#include <boost/date_time/posix_time/posix_time.hpp>
#include <vector>
#include "caffe/blob.hpp"
#include "caffe/common.hpp"
#include "caffe/internal_thread.hpp"
#include "caffe/layer.hpp"
#include "caffe/parallel.hpp"
#include "caffe/proto/caffe.pb.h"
#include "caffe/solver.hpp"
#include "caffe/syncedmem.hpp"
#include "caffe/util/blocking_queue.hpp"
namespace caffe {
// Params stored in CPU memory.
template<typename Dtype>
class CPUParams : public Params<Dtype> {
public:
CPUParams(shared_ptr<Solver<Dtype> > root_solver, int device);
virtual ~CPUParams();
void configure(Solver<Dtype>* solver) const;
protected:
using Params<Dtype>::size_;
using Params<Dtype>::data_;
using Params<Dtype>::diff_;
};
// Synchronous data parallelism using map-reduce between local CPUs.
template<typename Dtype>
class P2PSyncCPU : public CPUParams<Dtype>, public Solver<Dtype>::Callback {
public:
explicit P2PSyncCPU(shared_ptr<Solver<Dtype> > root_solver,
P2PSyncCPU<Dtype>* parent, const SolverParameter& param);
virtual ~P2PSyncCPU();
inline const shared_ptr<Solver<Dtype> >& solver() const {
return solver_;
}
inline const int GetInitIter() const { return initial_iter_; }
protected:
void on_start();
void on_gradients_ready();
const int initial_iter_;
shared_ptr<Solver<Dtype> > solver_;
using Params<Dtype>::size_;
using Params<Dtype>::data_;
using Params<Dtype>::diff_;
};
} // namespace caffe
#endif