コード例 #1
0
ファイル: blob.cpp プロジェクト: dieface/caffe
Dtype Blob<Dtype>::asum_diff() const {
  if (!diff_) {
    return 0;
  }
  switch (diff_->head()) {
    case SyncedMemory::HEAD_AT_CPU:
      return caffe_cpu_asum(count_, cpu_diff());
    case SyncedMemory::HEAD_AT_GPU:
    case SyncedMemory::SYNCED: {
#ifndef CPU_ONLY
      if (device_->backend() == Backend::BACKEND_CUDA) {
#ifdef USE_CUDA
        Dtype asum;
        caffe_gpu_asum(count_, gpu_diff(), &asum);
        return asum;
#endif
      } else {
#ifdef USE_GREENTEA
        Dtype asum;
        greentea_gpu_asum(device_->id(), count_, (cl_mem) gpu_diff(), 0,
                          &asum);
        return asum;
#endif
      }
#else
      NO_GPU;
#endif
    }
    case SyncedMemory::UNINITIALIZED:
      return 0;
    default:
      LOG(FATAL)<< "Unknown SyncedMemory head state: " << diff_->head();
    }
  return 0;
}
コード例 #2
0
ファイル: blob.cpp プロジェクト: MaoXu/jade
Dtype Blob<Dtype>::sumsq_diff() const {
  Dtype sumsq;
  const Dtype* diff;
  if (!diff_) { return 0; }
  switch (diff_->head()) {
  case SyncedMemory::HEAD_AT_CPU:
    diff = cpu_diff();
    sumsq = caffe_cpu_dot(count_, diff, diff);
    break;
  case SyncedMemory::HEAD_AT_GPU:
  case SyncedMemory::SYNCED:
#ifndef CPU_ONLY
    diff = gpu_diff();
    caffe_gpu_dot(count_, diff, diff, &sumsq);
    break;
#else
    NO_GPU;
#endif
  case SyncedMemory::UNINITIALIZED:
    return 0;
  default:
    LOG(FATAL) << "Unknown SyncedMemory head state: " << data_->head();
  }
  return sumsq;
}
コード例 #3
0
ファイル: blob.cpp プロジェクト: azrael417/caffe
Dtype Blob<Dtype>::asum_diff() const {
  if (!diff_) { return 0; }
  switch (diff_->head()) {
  case SyncedMemory::SYNCED_PRV:
  case SyncedMemory::HEAD_AT_PRV:
    return caffe_cpu_asum( prv_diff_count(), prv_diff());
  case SyncedMemory::HEAD_AT_CPU:
    return caffe_cpu_asum(count_, cpu_diff());
  case SyncedMemory::HEAD_AT_GPU:
  case SyncedMemory::SYNCED:
#ifndef CPU_ONLY
  {
    Dtype asum;
    caffe_gpu_asum(count_, gpu_diff(), &asum);
    return asum;
  }
#else
    NO_GPU;
#endif
  case SyncedMemory::UNINITIALIZED:
    return 0;
  default:
    LOG(FATAL) << "Unknown SyncedMemory head state: " << diff_->head();
  }
  return 0;
}
コード例 #4
0
ファイル: blob.cpp プロジェクト: qianxinchun/Dragon
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
		;
	}
}
コード例 #5
0
ファイル: blob.cpp プロジェクト: dieface/caffe
Dtype Blob<Dtype>::sumsq_diff() const {
  Dtype sumsq;
  const Dtype* diff;
  if (!diff_) {
    return 0;
  }
  switch (diff_->head()) {
    case SyncedMemory::HEAD_AT_CPU: {
      diff = cpu_diff();
      sumsq = caffe_cpu_dot(count_, diff, diff);
      break;
    }
    case SyncedMemory::HEAD_AT_GPU:
    case SyncedMemory::SYNCED: {
#ifndef CPU_ONLY
      diff = gpu_diff();
      if (device_->backend() == Backend::BACKEND_CUDA) {
#ifdef USE_CUDA
        caffe_gpu_dot(count_, diff, diff, &sumsq);
#endif
      } else {
#ifdef USE_GREENTEA
        greentea_gpu_dot(device_->id(), count_, (cl_mem) diff, 0,
                         (cl_mem) diff, 0, &sumsq);
#endif
      }
#else
      NO_GPU;
#endif
      break;
    }
    case SyncedMemory::UNINITIALIZED:
      return 0;
    default:
      LOG(FATAL)<< "Unknown SyncedMemory head state: " << data_->head();
    }
  return sumsq;
}