solvingPuzzles
solvingPuzzles

Reputation: 8889

ArrayFire out of memory doing convolution on NVIDIA Fermi?

I'm trying to use ArrayFire to perform a convolution on a 9000x9000 pixel 3-channel image, which is ~75MB. My GPU is an NVIDIA GTX480 with 1536MB of RAM. I would expect ArrayFire to use 75MB for the input image and roughly 75MB for the output image. However, ArrayFire runs for a while and eventually says that it's out of memory:

Memory Usage: 1325 MB free (1536 MB total) //printed before calling convolutionTest()
warning: device memory is low //printed in convolutionTest()
src/gena/gi_mem.cpp:349: error: tried to allocate 309mb (45mb free / 1536mb total) //exception

When performing a convolution on a 75mb image on a GPU with 1536MB of memory, ArrayFire runs out of memory. Why does this happen, and what can I do about it?


Code:

#include <stdio.h>
#include <arrayfire.h>
using namespace af;

static const float h_sobel[] = {-2.0, -1.0,  0.0,
                                -1.0,  0.0,  1.0,
                                0.0,  1.0,  2.0}; // 3x3 sobel weights

static void convolutionTest() {
    array sobel_k = array(3, 3, h_sobel);
    array img_gray = loadimage("9k_x_9k.png", false); // 'false' makes it a 1 channel grayscale [0-255]
    array img_convolved = convolve(img_gray, sobel_k); // should I preallocate the output space?
}

int main(int argc, char** argv) {
    try {
        info();
        convolutionTest();
    } catch (af::exception& e) {
        fprintf(stderr, "%s\n", e.what()); //prints src/gena/gi_mem.cpp:349: error: tried to allocate 309mb (45mb free / 1536mb total)
    }
    return 0;
}

System configuration and notes:

Upvotes: 0

Views: 617

Answers (1)

Pavan Yalamanchili
Pavan Yalamanchili

Reputation: 12109

This is a bug in loadImage function. It is loading in all three channels causing it to use up more memory than necessary. AccelerEyes will fix it before the next nightly, and report back soon.

Upvotes: 2

Related Questions