I'm trying to vectorize the inner `for` of this function:
void SIFTDescriptor::samplePatch(float *vec) { for (int r = 0; r < par.patchSize; ++r) { const int br0 = par.spatialBins * bin0[r]; const float wr0 = w0[r]; const int br1 = par.spatialBins * bin1[r]; const float wr1 = w1[r]; for (int c = 0; c < par.patchSize; ++c) { const float val = mask.at<float>(r,c) * grad.at<float>(r,c); const int bc0 = bin0[c]; const float wc0 = w0[c]*val; const int bc1 = bin1[c]; const float wc1 = w1[c]*val; // ori from atan2 is in range <-pi,pi> so add 2*pi to be surely above zero const float o = float(par.orientationBins)*(ori.at<float>(r,c) + 2*M_PI)/(2*M_PI); int bo0 = (int)o; const float wo1 = o - bo0; bo0 %= par.orientationBins; int bo1 = (bo0+1) % par.orientationBins; const float wo0 = 1.0f - wo1; // add to corresponding 8 vec... if (wr0*wc0>0) { vec[br0+bc0+bo0] += wr0*wc0 * wo0; vec[br0+bc0+bo1] += wr0*wc0 * wo1; } if (wr0*wc1>0) { vec[br0+bc1+bo0] += wr0*wc1 * wo0; vec[br0+bc1+bo1] += wr0*wc1 * wo1; } if (wr1*wc0>0) { vec[br1+bc0+bo0] += wr1*wc0 * wo0; vec[br1+bc0+bo1] += wr1*wc0 * wo1; } if (wr1*wc0>0) { vec[br1+bc1+bo0] += wr1*wc0 * wo0; vec[br1+bc1+bo1] += wr1*wc0 * wo1; } } } }
However, Intel Advisor tells me that there are two Read-After-Write dependencies in:
vec[br0+bc0+bo0] += wr0*wc0 * wo0;
And:
vec[br1+bc0+bo0] += wr1*wc0 * wo0;
How can I solve them? This is the first time that I try to solve such a dependency and I'm struggling a little bit...