void BasePrefetchingDataLayer<Ftype, Btype>::InternalThreadEntryN(size_t thread_id) {
#ifndef CPU_ONLY
  const bool use_gpu_transform = this->is_gpu_transform();
#endif
  static thread_local bool iter0 = this->phase_ == TRAIN;
  if (iter0 && this->net_inititialized_flag_ != nullptr) {
    this->net_inititialized_flag_->wait();
  } else {  // nothing to wait -> initialize and start pumping
    std::lock_guard<std::mutex> lock(mutex_in_);
    InitializePrefetch();
    start_reading();
    iter0 = false;
  }
  try {
    while (!must_stop(thread_id)) {
      const size_t qid = this->queue_id(thread_id);
#ifndef CPU_ONLY
      shared_ptr<Batch<Ftype>> batch = prefetches_free_[qid]->pop();

      CHECK_EQ((size_t) -1, batch->id());
      load_batch(batch.get(), thread_id, qid);
      if (Caffe::mode() == Caffe::GPU) {
        if (!use_gpu_transform) {
          batch->data_.async_gpu_push();
        }
        if (this->output_labels_) {
          batch->label_.async_gpu_push();
        }
        CUDA_CHECK(cudaStreamSynchronize(Caffe::th_stream_aux(Caffe::STREAM_ID_ASYNC_PUSH)));
      }

      prefetches_full_[qid]->push(batch);
#else
      shared_ptr<Batch<Ftype>> batch = prefetches_free_[qid]->pop();
      load_batch(batch.get(), thread_id, qid);
      prefetches_full_[qid]->push(batch);
#endif

      if (iter0) {
        if (this->net_iteration0_flag_ != nullptr) {
          this->net_iteration0_flag_->wait();
        }
        std::lock_guard<std::mutex> lock(mutex_out_);
        if (this->net_inititialized_flag_ != nullptr) {
          this->net_inititialized_flag_ = nullptr;  // no wait on the second round
          InitializePrefetch();
          start_reading();
        }
        if (this->auto_mode_) {
          break;
        }  // manual otherwise, thus keep rolling
        iter0 = false;
      }
    }
  } catch (boost::thread_interrupted&) {
  }
}
예제 #2
0
void BasePrefetchingDataLayer<Dtype>::InternalThreadEntry() {
#ifndef CPU_ONLY
  cudaStream_t stream;
  if (Caffe::mode() == Caffe::GPU) {
    CUDA_CHECK(cudaStreamCreateWithFlags(&stream, cudaStreamNonBlocking));
  }
#endif

  try {
    while (!must_stop()) {
      Batch<Dtype>* batch = prefetch_free_.pop();
      load_batch(batch);
#ifndef CPU_ONLY
      if (Caffe::mode() == Caffe::GPU) {
        batch->data_.data().get()->async_gpu_push(stream);
        CUDA_CHECK(cudaStreamSynchronize(stream));
      }
#endif
      prefetch_full_.push(batch);
    }
  } catch (boost::thread_interrupted&) {
    // Interrupted exception is expected on shutdown
  }
#ifndef CPU_ONLY
  if (Caffe::mode() == Caffe::GPU) {
    CUDA_CHECK(cudaStreamDestroy(stream));
  }
#endif
}
예제 #3
0
void BasePrefetchingDataLayer<Dtype>::InternalThreadEntry() {
#ifndef CPU_ONLY
  cudaStream_t stream;//创建CUDA stream,非阻塞类型
  if (Caffe::mode() == Caffe::GPU) {
    CUDA_CHECK(cudaStreamCreateWithFlags(&stream, cudaStreamNonBlocking));
  }
#endif

  try {
    while (!must_stop()) { //循环载入批量数据
      Batch<Dtype>* batch = prefetch_free_.pop();//拿到一个空闲batch
      load_batch(batch);//载入批量数据
#ifndef CPU_ONLY
      if (Caffe::mode() == Caffe::GPU) {
        batch->data_.data().get()->async_gpu_push(stream);
        if (this->output_labels_) {
          batch->label_.data().get()->async_gpu_push(stream);
        }
        CUDA_CHECK(cudaStreamSynchronize(stream));//同步到GPU
      }
#endif
      prefetch_full_.push(batch);//加入到带负载的Batch队列中
    }
  } catch (boost::thread_interrupted&) {//捕获异常,退出while循环
    // Interrupted exception is expected on shutdown
  }
#ifndef CPU_ONLY
  if (Caffe::mode() == Caffe::GPU) {
    CUDA_CHECK(cudaStreamDestroy(stream));//销毁CUDA stream
  }
#endif
}
void TransformingFastHDF5InputLayer<Dtype>::InternalThreadEntry() {
  try {
    while (!must_stop()) {
      Batch* batch = prefetch_free_.pop();
      load_batch(batch);
      prefetch_full_.push(batch);
    }
  } catch (boost::thread_interrupted&) {
    // Interrupted exception is expected on shutdown
  }
}
예제 #5
0
void change_batch() {

	if (! loaded_batch && ! inited_batch)
		load_batch ();

	if (! loaded_batch && ! inited_batch ) {
		init_batch ();
		return;
	}

	big_menu (0);
	big_menu (1);
	inited_batch = saved_batch = 0, loaded_batch = 1;
	big_menu (0);

}
예제 #6
0
void run_sas() {

	register i;
	struct wordb word;
	union  word W_0;


	if (! loaded_sas)
		if (! pt_load (&word.left, &word.right, 0x3E010l, &word.tag, 1)) {
			if ((word.left & 0xFFFFF000l) != 0x03B3E000l)
				load_sas ();
			else
				loaded_sas = 1;
		} else
			load_sas ();

	if (! loaded_batch) {
		if (is_name)
			load_batch ();
		else
			change_batch ();
	}

	if (! loaded_batch)
		return ;

	if (stopped == 0) /* Процессор работает */
		if (! ask_are_you_shure (" Процессор работает !") )
			return ;
	stop ();
	stopped = 4;
	/* Запись в память параметров для САС */
	for (i = 0; i < 10; i++)
		pt_store (batch_w[i].l[1], batch_w[i].l[0], 0x3E000l + i, 0, 1);
	zero ();
	/* Установка регистра РКП */
	pt_sendl (0x0183E010l, BCMD);
	/* Установка регистра РК (РК := РКП) */
	pt_send (04, BBUTTON1);
	memcpy (W_0.c, CAC_Name, 8);
	/* Имя САС.tst ==> в 0 слово */
	pt_store (W_0.l[1], W_0.l[0], 0x0l, 0, 1);
	pt_store (W_0.l[1], W_0.l[0], 0x36l, 0, 1);
	run ();

}
예제 #7
0
파일: util.c 프로젝트: warlck/proj3_starter
// Perform the classification (this calls into the functions from cnn.c
double run_classification(int* samples, int n, double** keep_output) {
  fprintf(stderr, "Making network...\n");
  network_t* net = load_cnn_snapshot();

  fprintf(stderr, "Loading batches...\n");


  for (int i = 0; i < n; i++) {
    int batch = samples[i]/10000;
    if (batches[batch] == NULL) {
      batches[batch] = load_batch(batch);
    }
  }

  vol_t** input = (vol_t**)malloc(sizeof(vol_t*)*n);
  double* output = (double*)malloc(sizeof(double)*n);


  for (int i = 0; i < n; i++) {
    input[i] = batches[samples[i]/10000][samples[i]%10000];
  }

  fprintf(stderr, "Running classification...\n");
  uint64_t start_time = timestamp_us(); 
  net_classify_cats(net, input, output, n);
  uint64_t end_time = timestamp_us();

  for (int i = 0; i < n; i++) {
    samples[i] = (output[i] > 0.5) ? 0 : -1;
  }

  double dt = (double)(end_time-start_time) / 1000.0;
  fprintf(stderr, "TIME: %lf ms\n", dt);

  free_network(net);
  free(input);

  if (keep_output == NULL)
    free(output);
  else
    *keep_output = output;

  return dt;
}