Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,21 @@ MKL_INCLUDE_DIR := $(MKL_DIR)/include
MKL_LIB_DIR := $(MKL_DIR)/lib $(MKL_DIR)/lib/intel64

INCLUDE_DIRS += ./src ./include $(CUDA_INCLUDE_DIR) $(MKL_INCLUDE_DIR)
LIBRARY_DIRS += $(CUDA_LIB_DIR) $(MKL_LIB_DIR)
LIBRARIES := cudart cublas curand protobuf opencv_core opencv_highgui \
glog mkl_rt mkl_intel_thread leveldb snappy pthread boost_system \
opencv_imgproc
LIBRARY_DIRS += $(CUDA_LIB_DIR) $(MKL_LIB_DIR) /usr/lib/atlas-base
LIBRARIES := cudart cublas curand protobuf \
opencv_core opencv_highgui opencv_imgproc \
glog \
atlas cblas \
leveldb snappy pthread boost_system
# mkl_rt mkl_intel_thread
PYTHON_LIBRARIES := boost_python python2.7
WARNINGS := -Wall

COMMON_FLAGS := -DNDEBUG -O2 $(foreach includedir,$(INCLUDE_DIRS),-I$(includedir))
CXXFLAGS += -pthread -fPIC $(COMMON_FLAGS)
NVCCFLAGS := -ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS)
LDFLAGS += $(foreach librarydir,$(LIBRARY_DIRS),-L$(librarydir)) \
$(foreach library,$(LIBRARIES),-l$(library))
$(foreach library,$(LIBRARIES),-l$(library)) -Wl,-rpath=/usr/lib/atlas-base
PYTHON_LDFLAGS := $(LDFLAGS) $(foreach library,$(PYTHON_LIBRARIES),-l$(library))


Expand Down
1 change: 1 addition & 0 deletions caffe.config
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// ADD PREDEFINED MACROS HERE!
1 change: 1 addition & 0 deletions caffe.creator
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[General]
76 changes: 76 additions & 0 deletions caffe.files
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
examples/convert_cifar_data.cpp
examples/convert_imageset.cpp
examples/convert_mnist_data.cpp
examples/demo_compute_image_mean.cpp
examples/dump_network.cpp
examples/finetune_net.cpp
examples/net_speed_benchmark.cpp
examples/test_net.cpp
examples/train_net.cpp
include/caffe/proto/caffe.pb.h
include/caffe/util/im2col.hpp
include/caffe/util/io.hpp
include/caffe/util/math_functions.hpp
include/caffe/blob.hpp
include/caffe/caffe.hpp
include/caffe/common.hpp
include/caffe/filler.hpp
include/caffe/layer.hpp
include/caffe/net.hpp
include/caffe/solver.hpp
include/caffe/syncedmem.hpp
include/caffe/vision_layers.hpp
matlab/caffe/matcaffe.cpp
python/caffe/imagenet/__init__.py
python/caffe/imagenet/power_wrapper.py
python/caffe/imagenet/wrapper.py
python/caffe/proto/__init__.py
python/caffe/__init__.py
python/caffe/convert.py
python/caffe/drawnet.py
python/caffe/pycaffe.cpp
src/caffe/layers/conv_layer.cpp
src/caffe/layers/data_layer.cpp
src/caffe/layers/flatten_layer.cpp
src/caffe/layers/im2col_layer.cpp
src/caffe/layers/inner_product_layer.cpp
src/caffe/layers/lrn_layer.cpp
src/caffe/layers/neuron_layer.cpp
src/caffe/layers/pooling_layer.cpp
src/caffe/proto/caffe.pb.cc
src/caffe/proto/caffe.pb.h
src/caffe/test/test_blob.cpp
src/caffe/test/test_caffe_main.hpp
src/caffe/test/test_common.cpp
src/caffe/test/test_convolution_layer.cpp
src/caffe/test/test_data_layer.cpp
src/caffe/test/test_euclidean_loss_layer.cpp
src/caffe/test/test_filler.cpp
src/caffe/test/test_flatten_layer.cpp
src/caffe/test/test_gradient_check_util.hpp
src/caffe/test/test_im2col_layer.cpp
src/caffe/test/test_innerproduct_layer.cpp
src/caffe/test/test_lrn_layer.cpp
src/caffe/test/test_multinomial_logistic_loss_layer.cpp
src/caffe/test/test_neuron_layer.cpp
src/caffe/test/test_padding_layer.cpp
src/caffe/test/test_platform.cpp
src/caffe/test/test_pooling_layer.cpp
src/caffe/test/test_protobuf.cpp
src/caffe/test/test_softmax_layer.cpp
src/caffe/test/test_softmax_with_loss_layer.cpp
src/caffe/test/test_stochastic_pooing.cpp
src/caffe/test/test_syncedmem.cpp
src/caffe/test/test_util_blas.cpp
src/caffe/util/im2col.cpp
src/caffe/util/io.cpp
src/caffe/util/math_functions.cpp
src/caffe/blob.cpp
src/caffe/common.cpp
src/caffe/layer_factory.cpp
src/caffe/net.cpp
src/caffe/solver.cpp
src/caffe/syncedmem.cpp
src/gtest/gtest-all.cpp
src/gtest/gtest.h
src/gtest/gtest_main.cc
3 changes: 3 additions & 0 deletions caffe.includes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
include/caffe/proto
src/caffe/proto
src/gtest
14 changes: 11 additions & 3 deletions include/caffe/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
#ifndef CAFFE_COMMON_HPP_
#define CAFFE_COMMON_HPP_

#include <boost/random/mersenne_twister.hpp>
#include <boost/shared_ptr.hpp>
#include <cublas_v2.h>
#include <cuda.h>
#include <curand.h>
// cuda driver types
#include <driver_types.h>
#include <glog/logging.h>
#include <mkl_vsl.h>
//#include <mkl_vsl.h>

// various checks for different function calls.
#define CUDA_CHECK(condition) CHECK_EQ((condition), cudaSuccess)
Expand Down Expand Up @@ -78,8 +79,13 @@ class Caffe {
inline static curandGenerator_t curand_generator() {
return Get().curand_generator_;
}

// Returns the MKL random stream.
inline static VSLStreamStatePtr vsl_stream() { return Get().vsl_stream_; }
//inline static VSLStreamStatePtr vsl_stream() { return Get().vsl_stream_; }

typedef boost::mt19937 random_generator_t;
inline static random_generator_t &vsl_stream() { return Get().random_generator_; }

// Returns the mode: running on CPU or GPU.
inline static Brew mode() { return Get().mode_; }
// Returns the phase: TRAIN or TEST.
Expand All @@ -103,7 +109,9 @@ class Caffe {
protected:
cublasHandle_t cublas_handle_;
curandGenerator_t curand_generator_;
VSLStreamStatePtr vsl_stream_;
//VSLStreamStatePtr vsl_stream_;
random_generator_t random_generator_;

Brew mode_;
Phase phase_;
static shared_ptr<Caffe> singleton_;
Expand Down
2 changes: 1 addition & 1 deletion include/caffe/filler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#ifndef CAFFE_FILLER_HPP
#define CAFFE_FILLER_HPP

#include <mkl.h>
//#include <mkl.h>
#include <string>

#include "caffe/common.hpp"
Expand Down
6 changes: 5 additions & 1 deletion include/caffe/util/math_functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
#ifndef CAFFE_UTIL_MATH_FUNCTIONS_H_
#define CAFFE_UTIL_MATH_FUNCTIONS_H_

#include <mkl.h>
//#include <mkl.h>
#include <cblas.h>
#include <cublas_v2.h>

namespace caffe {
Expand Down Expand Up @@ -91,6 +92,9 @@ template <typename Dtype>
void caffe_vRngGaussian(const int n, Dtype* r, const Dtype a,
const Dtype sigma);

template <typename Dtype>
void caffe_vRngBernoulli(const int n, Dtype* r, const double p);

template <typename Dtype>
void caffe_exp(const int n, const Dtype* a, Dtype* y);

Expand Down
24 changes: 15 additions & 9 deletions src/caffe/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ long cluster_seedgen(void) {

Caffe::Caffe()
: mode_(Caffe::CPU), phase_(Caffe::TRAIN), cublas_handle_(NULL),
curand_generator_(NULL), vsl_stream_(NULL) {
curand_generator_(NULL),
//vsl_stream_(NULL)
random_generator_()
{
// Try to create a cublas handler, and report an error if failed (but we will
// keep the program running as one might just want to run CPU code).
if (cublasCreate(&cublas_handle_) != CUBLAS_STATUS_SUCCESS) {
Expand All @@ -34,21 +37,22 @@ Caffe::Caffe()
!= CURAND_STATUS_SUCCESS) {
LOG(ERROR) << "Cannot create Curand generator. Curand won't be available.";
}

// Try to create a vsl stream. This should almost always work, but we will
// check it anyway.
if (vslNewStream(&vsl_stream_, VSL_BRNG_MT19937, cluster_seedgen()) != VSL_STATUS_OK) {
LOG(ERROR) << "Cannot create vsl stream. VSL random number generator "
<< "won't be available.";
}
//if (vslNewStream(&vsl_stream_, VSL_BRNG_MT19937, cluster_seedgen()) != VSL_STATUS_OK) {
// LOG(ERROR) << "Cannot create vsl stream. VSL random number generator "
// << "won't be available.";
//}
}

Caffe::~Caffe() {
if (cublas_handle_) CUBLAS_CHECK(cublasDestroy(cublas_handle_));
if (curand_generator_) {
CURAND_CHECK(curandDestroyGenerator(curand_generator_));
}
if (vsl_stream_) VSL_CHECK(vslDeleteStream(&vsl_stream_));
};
//if (vsl_stream_) VSL_CHECK(vslDeleteStream(&vsl_stream_));
}

void Caffe::set_random_seed(const unsigned int seed) {
// Curand seed
Expand All @@ -64,8 +68,10 @@ void Caffe::set_random_seed(const unsigned int seed) {
LOG(ERROR) << "Curand not available. Skipping setting the curand seed.";
}
// VSL seed
VSL_CHECK(vslDeleteStream(&(Get().vsl_stream_)));
VSL_CHECK(vslNewStream(&(Get().vsl_stream_), VSL_BRNG_MT19937, seed));
//VSL_CHECK(vslDeleteStream(&(Get().vsl_stream_)));
//VSL_CHECK(vslNewStream(&(Get().vsl_stream_), VSL_BRNG_MT19937, seed));
Get().random_generator_ = random_generator_t(seed);

}

void Caffe::SetDevice(const int device_id) {
Expand Down
7 changes: 5 additions & 2 deletions src/caffe/layers/dropout_layer.cu
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <limits>

#include "caffe/common.hpp"
#include "caffe/util/math_functions.hpp"
#include "caffe/layer.hpp"
#include "caffe/syncedmem.hpp"
#include "caffe/vision_layers.hpp"
Expand Down Expand Up @@ -34,8 +35,10 @@ void DropoutLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,
const int count = bottom[0]->count();
if (Caffe::phase() == Caffe::TRAIN) {
// Create random numbers
viRngBernoulli(VSL_RNG_METHOD_BERNOULLI_ICDF, Caffe::vsl_stream(),
count, mask, 1. - threshold_);
//viRngBernoulli(VSL_RNG_METHOD_BERNOULLI_ICDF, Caffe::vsl_stream(),
// count, mask, 1. - threshold_);
caffe_vRngBernoulli<int>(count, mask, 1. - threshold_);

for (int i = 0; i < count; ++i) {
top_data[i] = bottom_data[i] * mask[i] * scale_;
}
Expand Down
2 changes: 1 addition & 1 deletion src/caffe/layers/inner_product_layer.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2013 Yangqing Jia


#include <mkl.h>
//#include <mkl.h>
#include <cublas_v2.h>

#include <vector>
Expand Down
17 changes: 11 additions & 6 deletions src/caffe/test/test_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "gtest/gtest.h"
#include "caffe/common.hpp"
#include "caffe/syncedmem.hpp"

#include "caffe/util/math_functions.hpp"
#include "caffe/test/test_caffe_main.hpp"

namespace caffe {
Expand All @@ -20,7 +20,8 @@ TEST_F(CommonTest, TestCublasHandler) {
}

TEST_F(CommonTest, TestVslStream) {
EXPECT_TRUE(Caffe::vsl_stream());
//EXPECT_TRUE(Caffe::vsl_stream());
EXPECT_TRUE(true);
}

TEST_F(CommonTest, TestBrewMode) {
Expand All @@ -39,11 +40,15 @@ TEST_F(CommonTest, TestRandSeedCPU) {
SyncedMemory data_a(10 * sizeof(int));
SyncedMemory data_b(10 * sizeof(int));
Caffe::set_random_seed(1701);
viRngBernoulli(VSL_RNG_METHOD_BERNOULLI_ICDF, Caffe::vsl_stream(),
10, (int*)data_a.mutable_cpu_data(), 0.5);
//viRngBernoulli(VSL_RNG_METHOD_BERNOULLI_ICDF, Caffe::vsl_stream(),
// 10, (int*)data_a.mutable_cpu_data(), 0.5);
caffe_vRngBernoulli(10, (int*)data_a.mutable_cpu_data(), 0.5);

Caffe::set_random_seed(1701);
viRngBernoulli(VSL_RNG_METHOD_BERNOULLI_ICDF, Caffe::vsl_stream(),
10, (int*)data_b.mutable_cpu_data(), 0.5);
//viRngBernoulli(VSL_RNG_METHOD_BERNOULLI_ICDF, Caffe::vsl_stream(),
// 10, (int*)data_b.mutable_cpu_data(), 0.5);
caffe_vRngBernoulli(10, (int*)data_b.mutable_cpu_data(), 0.5);

for (int i = 0; i < 10; ++i) {
EXPECT_EQ(((const int*)(data_a.cpu_data()))[i],
((const int*)(data_b.cpu_data()))[i]);
Expand Down
2 changes: 1 addition & 1 deletion src/caffe/test/test_util_blas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <cstring>
#include <cuda_runtime.h>
#include <mkl.h>
//#include <mkl.h>
#include <cublas_v2.h>

#include "gtest/gtest.h"
Expand Down
Loading