void Blob<Dtype>::scale_data(Dtype scale_factor) { Dtype* data; if (!data_) { return; } switch (data_->head()) { case SyncedMemory::SYNCED_PRV: case SyncedMemory::HEAD_AT_PRV: data = mutable_prv_data(); caffe_scal(prv_data_count(), scale_factor, data); break; case SyncedMemory::HEAD_AT_CPU: data = mutable_cpu_data(); caffe_scal(count_, scale_factor, data); return; case SyncedMemory::HEAD_AT_GPU: case SyncedMemory::SYNCED: #ifndef CPU_ONLY data = mutable_gpu_data(); caffe_gpu_scal(count_, scale_factor, data); return; #else NO_GPU; #endif case SyncedMemory::UNINITIALIZED: return; default: LOG(FATAL) << "Unknown SyncedMemory head state: " << data_->head(); } }
void Blob<Dtype>::update(){ switch(data_->head()){ case SyncedMemory::SyncedHead::HEAD_AT_CPU: dragon_axpy(count_, Dtype(-1), cpu_diff(), mutable_cpu_data()); break; case SyncedMemory::SyncedHead::HEAD_AT_GPU: case SyncedMemory::SyncedHead::SYNCED: #ifndef CPU_ONLY dragon_gpu_axpy<Dtype>(count_, Dtype(-1), gpu_diff(), mutable_gpu_data()); #endif break; default: // UNINITIALIZED JUST DO NOTHING ; } }
void Blob<Dtype>::scale_data(Dtype scale_factor) { Dtype* data; if (!data_) { return; } switch (data_->head()) { case SyncedMemory::HEAD_AT_CPU: { data = mutable_cpu_data(); caffe_scal(count_, scale_factor, data); return; } case SyncedMemory::HEAD_AT_GPU: case SyncedMemory::SYNCED: { #ifndef CPU_ONLY data = mutable_gpu_data(); if (device_->backend() == Backend::BACKEND_CUDA) { #ifdef USE_CUDA caffe_gpu_scal(count_, scale_factor, data); #endif } else { #ifdef USE_GREENTEA greentea_gpu_scal(device_->id(), count_, scale_factor, (cl_mem) data, 0); #endif } return; #else NO_GPU; #endif } case SyncedMemory::UNINITIALIZED: return; default: LOG(FATAL)<< "Unknown SyncedMemory head state: " << data_->head(); } }