I have to repeatedly call a custom function and I notice that the time for each iteration is roughly the same for the first ~100 iterations but suddenly doubles after ~150 iterations going from 3 ms to eventually 10 ms after 200 iterations. I have attached the code below. What could be the reason for this?
for (int i = 0; i < 200; i++) {
std::string filename = std::to_string(i) + ".png";
cv::Mat img = cv::imread(filename, cv::IMREAD_GRAYSCALE);
af::array afimg(2048, 2048, img.data, afHost);
af::array bfimg =
afimg.as(f32);
af::timer::start();
index = bufferInd(0);
buffer(af::span, af::span, index) = bfimg;
bufferReshape(index, af::span) = af::moddims(bfimg, 1, rows * cols);
bufferInd = af::shift(bufferInd, -1, 0, 0, 0);
af::sync();
std::cout << "Reading time: " << af::timer::stop() << " s" << std::endl;
}