Skip to content
This repository was archived by the owner on Aug 5, 2022. It is now read-only.

Commit 12c7e5e

Browse files
guomingzGerrit Code Review
authored andcommitted
Merge "Optimization of swap function for YOLO-V2 eval_detection."
2 parents e099133 + 6bb8218 commit 12c7e5e

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/caffe/layers/eval_detection_layer.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -356,11 +356,19 @@ namespace caffe {
356356

357357
Dtype* swap_data = swap.mutable_cpu_data();
358358
int index = 0;
359-
for (int b = 0; b < bottom[0]->num(); ++b) {
360-
for (int h = 0; h < bottom[0]->height(); ++h) {
361-
for (int w = 0; w < bottom[0]->width(); ++w) {
362-
for (int c = 0; c < bottom[0]->channels(); ++c) {
363-
swap_data[index++] = bottom[0]->data_at(b, c, h, w);
359+
360+
int n_value = bottom[0]->num();
361+
int h_value = bottom[0]->height();
362+
int w_value = bottom[0]->width();
363+
int c_value = bottom[0]->channels();
364+
const Dtype* input_data = bottom[0]->cpu_data();
365+
366+
for (int b = 0; b < n_value; ++b) {
367+
for (int h = 0; h < h_value; ++h) {
368+
for (int w = 0; w < w_value; ++w) {
369+
for (int c = 0; c < c_value; ++c) {
370+
//swap_data[index++] = bottom[0]->data_at(b, c, h, w); //"index" is Not safe for OpenMP
371+
swap_data[index++] = input_data[((b * c_value + c) * h_value + h) * w_value + w];
364372
}
365373
}
366374
}

0 commit comments

Comments
 (0)