1

I have a af::array variable which is 3000000*3:

int main()
{
    // inputArray is the pointer which fills tempArray

    af::array tempArray = af::array(af::dim4(3000000,3),inputArray);

    tempArray(tempArray < 0) = 0;


}

the problem is that, I want to delete this array so that my memory gets released, it fills my dedicated GPU memory. How should I do it?

Before using this variable enter image description here

after using this variable: enter image description here

1 Answers1

1

It's important to understand that ArrayFire uses a garbage collector. This means that even when you release the memory, the memory on the GPU won't be released but marked as reusable and later used when needed by you (ArrayFire) library.

Allocating memory is expensive that's why software designers strive to use custom allocation systems that reuse and allocate memory in bulk.

To manually return memory to garbage collector use either af::freeV2() or af::deviceGC().

Marcin Poloczek
  • 923
  • 6
  • 21
  • 1
    To add to what @Marcin suggested, even without an explicit garbage collection request, GC is also automatically triggered when there is memory pressure i.e. there are usable allocations but none fit the new allocation criteria etc. For of majority of the use-cases, automatic garbage collection should be able to take care of efficiently reusing memory for similar allocations in a given program. – pradeep Aug 23 '21 at 08:05