SINGA-148 Race condition between Worker threads and Driver minor bug fix in slice.cc, concate.cc pass cpplint check
Project: http://git-wip-us.apache.org/repos/asf/incubator-singa/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-singa/commit/b00dc32f Tree: http://git-wip-us.apache.org/repos/asf/incubator-singa/tree/b00dc32f Diff: http://git-wip-us.apache.org/repos/asf/incubator-singa/diff/b00dc32f Branch: refs/heads/master Commit: b00dc32fb1562d3b71bc346021d1918059d5e6cc Parents: 77d5c5c Author: WANG Sheng <[email protected]> Authored: Wed Mar 30 15:22:41 2016 +0800 Committer: WANG Sheng <[email protected]> Committed: Wed Mar 30 15:22:41 2016 +0800 ---------------------------------------------------------------------- include/singa/utils/math_blob.h | 2 +- src/neuralnet/connection_layer/concate.cc | 8 ++++---- src/neuralnet/connection_layer/slice.cc | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/b00dc32f/include/singa/utils/math_blob.h ---------------------------------------------------------------------- diff --git a/include/singa/utils/math_blob.h b/include/singa/utils/math_blob.h index 93967b4..55ba44b 100644 --- a/include/singa/utils/math_blob.h +++ b/include/singa/utils/math_blob.h @@ -282,7 +282,7 @@ template<typename Op, typename Dtype> void Map(const Blob<Dtype> & A, const Blob<Dtype> & B, Blob<Dtype> * C) { CHECK_EQ(A.count(), B.count()) << "Blobs must have the same size"; CHECK_EQ(A.count(), C->count()) << "Blobs must have the same size"; - //cpu_e_f<Op>(A.count(), A.cpu_data(), B.cpu_data(), C->mutable_cpu_data()); + // cpu_e_f<Op>(A.count(), A.cpu_data(), B.cpu_data(), C->mutable_cpu_data()); auto context = Singleton<Context>::Instance(); int device = context->device_id(std::this_thread::get_id()); if (device < 0) { http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/b00dc32f/src/neuralnet/connection_layer/concate.cc ---------------------------------------------------------------------- diff --git a/src/neuralnet/connection_layer/concate.cc b/src/neuralnet/connection_layer/concate.cc index 0cdd812..9d3fd0c 100644 --- a/src/neuralnet/connection_layer/concate.cc +++ b/src/neuralnet/connection_layer/concate.cc @@ -60,7 +60,7 @@ void ConcateLayer::ComputeFeature(int flag, const vector<Layer*>& srclayers) { int device = context->device_id(std::this_thread::get_id()); while (concate_offset < data_.count()) { for (size_t i = 0; i < srclayers.size(); ++i) { - if (device == -1) { + if (device < 0) { const float* src = srclayers[i]->data(this).cpu_data() + srclayer_offset; float* dst = data_.mutable_cpu_data() + concate_offset; @@ -72,7 +72,7 @@ void ConcateLayer::ComputeFeature(int flag, const vector<Layer*>& srclayers) { float* dst = data_.mutable_gpu_data() + concate_offset; cudaMemcpy(dst, src, step * sizeof(float), cudaMemcpyDefault); #else - LOG(FATAL) << "GPU is supported"; + LOG(FATAL) << "GPU is not supported"; #endif } concate_offset += step; @@ -94,7 +94,7 @@ void ConcateLayer::ComputeGradient(int flag, const vector<Layer*>& srclayers) { int device = context->device_id(std::this_thread::get_id()); while (concate_offset < grad_.count()) { for (size_t i = 0; i < srclayers.size(); ++i) { - if (device == -1) { + if (device < 0) { const float* src = grad_.cpu_data() + concate_offset; float* dst = srclayers[i]->mutable_grad(this)->mutable_cpu_data() + srclayer_offset; @@ -106,7 +106,7 @@ void ConcateLayer::ComputeGradient(int flag, const vector<Layer*>& srclayers) { + srclayer_offset; cudaMemcpy(dst, src, step * sizeof(float), cudaMemcpyDefault); #else - LOG(FATAL) << "GPU is supported"; + LOG(FATAL) << "GPU is not supported"; #endif } concate_offset += step; http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/b00dc32f/src/neuralnet/connection_layer/slice.cc ---------------------------------------------------------------------- diff --git a/src/neuralnet/connection_layer/slice.cc b/src/neuralnet/connection_layer/slice.cc index efa33a4..3cca3fd 100644 --- a/src/neuralnet/connection_layer/slice.cc +++ b/src/neuralnet/connection_layer/slice.cc @@ -73,7 +73,7 @@ void SliceLayer::ComputeFeature(int flag, const vector<Layer*>& srclayers) { int device = context->device_id(std::this_thread::get_id()); while (srclayer_offset < blob.count()) { for (int i = 0; i < num_slices_; ++i) { - if (device == -1) { + if (device < 0) { const float* src = blob.cpu_data() + srclayer_offset; float* dst = datavec_[i]->mutable_cpu_data() + slice_offset; memcpy(dst, src, step * sizeof(float)); @@ -83,7 +83,7 @@ void SliceLayer::ComputeFeature(int flag, const vector<Layer*>& srclayers) { float* dst = datavec_[i]->mutable_gpu_data() + slice_offset; cudaMemcpy(dst, src, step * sizeof(float), cudaMemcpyDefault); #else - LOG(FATAL) << "GPU is supported"; + LOG(FATAL) << "GPU is not supported"; #endif } srclayer_offset += step; @@ -105,7 +105,7 @@ void SliceLayer::ComputeGradient(int flag, const vector<Layer*>& srclayers) { int device = context->device_id(std::this_thread::get_id()); while (srclayer_offset < blob->count()) { for (int i = 0; i < num_slices_; ++i) { - if (device == -1) { + if (device < 0) { const float* src = gradvec_[i]->cpu_data() + slice_offset; float* dst = blob->mutable_cpu_data() + srclayer_offset; memcpy(dst, src, step * sizeof(float)); @@ -115,7 +115,7 @@ void SliceLayer::ComputeGradient(int flag, const vector<Layer*>& srclayers) { float* dst = blob->mutable_gpu_data() + srclayer_offset; cudaMemcpy(dst, src, step * sizeof(float), cudaMemcpyDefault); #else - LOG(FATAL) << "GPU is supported"; + LOG(FATAL) << "GPU is not supported"; #endif } srclayer_offset += step;
