static void ind_set( int value ) { pgm_cycle = value; if( value ) ind_on(); else ind_off(); }
void CropLayer<Dtype>::crop_copy(const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top, const int* offsets, vector<int> indices, int cur_dim, const Dtype* src_data, Dtype* dest_data, bool is_forward) { if (cur_dim + 1 < top[0]->num_axes()) { // We are not yet at the final dimension, call copy recursively for (int i = 0; i < top[0]->shape(cur_dim); ++i) { indices[cur_dim] = i; crop_copy(bottom, top, offsets, indices, cur_dim+1, src_data, dest_data, is_forward); } } else { // We are at the last dimensions, which is stored continuously in memory // prepare index vector reduced(red) and with offsets(off) std::vector<int> ind_red(cur_dim, 0); std::vector<int> ind_off(cur_dim+1, 0); for (int j = 0; j < cur_dim; ++j) { ind_red[j] = indices[j]; ind_off[j] = indices[j] + offsets[j]; } ind_off[cur_dim] = offsets[cur_dim]; // do the copy if (is_forward) { caffe_copy(top[0]->shape(cur_dim), src_data + bottom[0]->offset(ind_off), dest_data + top[0]->offset(ind_red)); } else { // in the backwards pass the src_data is top_diff // and the dest_data is bottom_diff caffe_copy(top[0]->shape(cur_dim), src_data + top[0]->offset(ind_red), dest_data + bottom[0]->offset(ind_off)); } } }
void CropLayer<Dtype>::crop_copy(const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top, const vector<int>& offsets, const Dtype* src_data, Dtype* dest_data) { int last_dim = top[0]->num_axes() - 1; int copy_count = top[0]->count() / top[0]->shape(last_dim); #ifdef _OPENMP #pragma omp parallel for #endif for (int i = 0; i < copy_count; ++i) { // prepare index vector reduced(red) and with offsets(off) std::vector<int> ind_red(last_dim, 0); std::vector<int> ind_off(last_dim+1, 0); int cur_iteration = i; for (int j = last_dim - 1; j >=0; --j) { int index = cur_iteration % top[0]->shape(j); cur_iteration /= top[0]->shape(j); ind_red[j] = index; ind_off[j] = index + offsets[j]; } ind_off[last_dim] = offsets[last_dim]; // Last dimensions stored continously in memory // do the copy if (is_forward) { caffe_copy(top[0]->shape(last_dim), src_data + bottom[0]->offset(ind_off), dest_data + top[0]->offset(ind_red)); } else { // in the backwards pass the src_data is top_diff // and the dest_data is bottom_diff caffe_copy(top[0]->shape(last_dim), src_data + top[0]->offset(ind_red), dest_data + bottom[0]->offset(ind_off)); } } }
static void ind_init() { ind_off(); IND_PORT_DIR |= _BV( IND_PIN ); }