-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblock.cpp
More file actions
54 lines (46 loc) · 1.26 KB
/
block.cpp
File metadata and controls
54 lines (46 loc) · 1.26 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
#include "block.hpp"
namespace fool{
template<typename Dtype>
Block<Dtype>::Block(const std::vector<int>& shape){
m_capacity = 0;
SyncedBlock(shape);
}
template<typename Dtype>
void Block<Dtype>::SyncedBlock(const std::vector<int>& shape){
m_count = 1;
m_shape.resize(shape.size());
for(unsigned int i = 0; i < shape.size(); ++i){
m_count *= shape[i];
m_shape[i] = shape[i];
}
if(m_count > m_capacity){
m_capacity = m_count;
m_data.reset(new MemoryController(m_capacity * sizeof(Dtype)));
m_diff.reset(new MemoryController(m_capacity * sizeof(Dtype)));
}
}
// static_cast don't adapt to const-ness
template<typename Dtype>
const Dtype* Block<Dtype>::cpu_data(){
return (const Dtype*)(m_data->cpu_data());
}
template<typename Dtype>
Dtype* Block<Dtype>::mutable_cpu_data(){
return static_cast<Dtype*>(m_data->mutable_cpu_data());
}
template<typename Dtype>
const Dtype* Block<Dtype>::cpu_diff(){
return (const Dtype*)(m_diff->cpu_data());
}
template<typename Dtype>
Dtype* Block<Dtype>::mutable_cpu_diff(){
return static_cast<Dtype*>(m_diff->mutable_cpu_data());
}
template<typename Dtype>
void Block<Dtype>::FromModel(const vector<int>& shape){
}
INSTANTIATE_CLASS(Block);
// label information
template class Block<int>;
template class Block<unsigned int>;
}