Skip to content

Commit

Permalink
Merge pull request BVLC#5 from jdemouth/caffe-0.14-cnmem-fp16
Browse files Browse the repository at this point in the history
Make FP16 blobs support FP32 inputs.
  • Loading branch information
thatguymike committed Nov 2, 2015
2 parents 78ca38b + 0f18d78 commit 1d160aa
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion include/caffe/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
// <float16,float> for Intel
// <float16,float16> for ARM

//#define NATIVE_FP16_SUPPORTED 1
#define NATIVE_FP16_SUPPORTED 1

#if NATIVE_FP16_SUPPORTED
# define CAFFE_FP16_MTYPE float16
Expand Down
19 changes: 16 additions & 3 deletions src/caffe/blob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -593,14 +593,27 @@ void Blob<float16,CAFFE_FP16_MTYPE>::FromProto(const BlobProto& proto, bool resh
CHECK(ShapeEquals(proto)) << "shape mismatch (reshape not set)";
}
// copy data
if (proto.half_data_size() > 0) {
if (proto.data_size() > 0) {
CHECK_EQ(count_, proto.data_size());
float16* data_vec = mutable_cpu_data();
for (int i = 0; i < count_; ++i) {
data_vec[i] = Get<float16>(proto.data(i));
}
} else if (proto.half_data_size() > 0) {
float16* data_vec = mutable_cpu_data();
CHECK_EQ(count_, proto.half_data_size());
for (int i = 0; i < count_; ++i) {
data_vec[i].setx(proto.half_data(i));
}
}
if (proto.half_diff_size() > 0) {
if (proto.diff_size() > 0) {
CHECK_EQ(count_, proto.diff_size());
float16* diff_vec = mutable_cpu_diff();
for (int i = 0; i < count_; ++i) {
diff_vec[i] = Get<float16>(proto.half_diff(i));
}
}
else if (proto.half_diff_size() > 0) {
CHECK_EQ(count_, proto.half_diff_size());
float16* diff_vec = mutable_cpu_diff();
for (int i = 0; i < count_; ++i) {
Expand All @@ -617,7 +630,7 @@ INSTANTIATE_CLASS(Blob);
#if NATIVE_FP16_SUPPORTED
//template class Blob<float16,float16>;
#else
//template class Blob<float16,float>;
template class Blob<float16,float>;
#endif
#endif // CPU_ONLY

Expand Down

0 comments on commit 1d160aa

Please sign in to comment.