10000 Tweak device abstraction so CPU_ONLY build works by jeffdonahue · Pull Request #803 · BVLC/caffe · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Tweak device abstraction so CPU_ONLY build works #803

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 27, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

8000
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,8 @@ $(LAYER_BUILD_DIR)/%.o: src/$(PROJECT)/layers/%.cpp $(HXX_SRCS) \

$(DEVICE_BUILD_DIR)/%.o: src/$(PROJECT)/devices/%.cpp $(HXX_SRCS) \
| $(DEVICE_BUILD_DIR)
$(CXX) $< $(CXXFLAGS) -c -o $@
$(CXX) $< $(CXXFLAGS) -c -o $@ 2> $@.$(WARNS_EXT) \
|| (cat $@.$(WARNS_EXT); exit 1)
@ echo

$(PROTO_BUILD_DIR)/%.pb.o: $(PROTO_BUILD_DIR)/%.pb.cc $(PROTO_GEN_HEADER) \
Expand Down Expand Up @@ -480,7 +481,8 @@ $(LAYER_BUILD_DIR)/%.cuo: src/$(PROJECT)/layers/%.cu $(HXX_SRCS) \

$(DEVICE_BUILD_DIR)/%.cuo: src/$(PROJECT)/devices/%.cu $(HXX_SRCS) \
| $(DEVICE_BUILD_DIR)
$(CUDA_DIR)/bin/nvcc $(NVCCFLAGS) $(CUDA_ARCH) -c $< -o $@
$(CUDA_DIR)/bin/nvcc $(NVCCFLAGS) $(CUDA_ARCH) -c $< -o $@ 2> $@.$(WARNS_EXT) \
|| (cat $@.$(WARNS_EXT); exit 1)
@ echo

$(UTIL_BUILD_DIR)/%.cuo: src/$(PROJECT)/util/%.cu | $(UTIL_BUILD_DIR)
Expand Down
4 changes: 4 additions & 0 deletions include/caffe/devices/gpu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#ifndef CAFFE_DEVICES_GPU_H_
#define CAFFE_DEVICES_GPU_H_

#ifndef CPU_ONLY

extern "C" {
#include <cblas.h>
}
Expand Down Expand Up @@ -86,4 +88,6 @@ class GPUDevice : public Device<Dtype> {

} // namespace caffe

#endif // CPU_ONLY

#endif // CAFFE_DEVICES_GPU_H_
2 changes: 2 additions & 0 deletions include/caffe/filler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#ifndef CAFFE_FILLER_HPP
#define CAFFE_FILLER_HPP

#include <math.h>

#include <string>

#include "caffe/common.hpp"
Expand Down
7 changes: 7 additions & 0 deletions src/caffe/device_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ Device<Dtype>* DeviceFactory<Dtype>::GetDevice(Caffe::Brew mode) {
case Caffe::CPU:
return cpu_device_;
case Caffe::GPU:
#ifndef CPU_ONLY
return gpu_device_;
#else
NO_GPU;
return static_cast<Device<Dtype>*>(NULL);
#endif
default:
LOG(FATAL) << "Unknown caffe mode.";
return static_cast<Device<Dtype>*>(NULL);
Expand All @@ -35,8 +40,10 @@ Device<Dtype>* DeviceFactory<Dtype>::GetDevice(Caffe::Brew mode) {
template<typename Dtype>
Device<Dtype>* DeviceFactory<Dtype>::cpu_device_ = new CPUDevice<Dtype>();

#ifndef CPU_ONLY
template<typename Dtype>
Device<Dtype>* DeviceFactory<Dtype>::gpu_device_ = new GPUDevice<Dtype>();
#endif

INSTANTIATE_CLASS(DeviceFactory);
template class DeviceFactory<int>;
Expand Down
4 changes: 4 additions & 0 deletions src/caffe/devices/gpu.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright 2014 BVLC and contributors.

#ifndef CPU_ONLY

#include <cublas_v2.h>

#include "caffe/common.hpp"
Expand Down Expand Up @@ -204,3 +206,5 @@ template class GPUDevice<int>;
template class GPUDevice<unsigned int>;

} // namespace caffe

#endif // CPU_ONLY
2 changes: 2 additions & 0 deletions src/caffe/solver.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright 2014 BVLC and contributors.

#include <math.h>

#include <cstdio>

#include <algorithm>
Expand Down
0