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:
- ArrayFire 1.9
- Ubuntu 10.04
- CUDA 5.0
- NVIDIA GTX480 (Fermi) GPU, which has 1536MB of RAM
helloworld
and other ArrayFire examples work properly- ArrayFire's convolution has no trouble with a smaller image (e.g. 512x512 pixels)