Memory management

[Old posts from the commercial version of ArrayFire] Discussion of ArrayFire using CUDA or OpenCL.

Moderator: pavanky

Memory management

Postby Medivh » Sat Sep 06, 2014 9:38 am

Hi,

i would understand and clarify allocation and memory management using arrayfire on C/C++.

According docs "array C = rand(1,10)" as example , generate and allocate a vector on device(default). Writing an complet algoritm, i see a progressive decrease of memory (af::info) but i don't understand if af::info is memory garbage or really device gpu memory.

If the question above is positive, how i can delete variabile C on device or reset the entire memory?

In matlab i haven't those problem because matlab has : clear and reset for device memory erase.
Medivh
 
Posts: 6
Joined: Fri Jul 18, 2014 9:19 am

Re: Memory management

Postby shehzan » Sat Sep 06, 2014 11:09 am

Hi

af::info shows the instantaneous memory used and available on the device.
ArrayFire runs its own garbage collection because we use a custom memory manager. We do not allow explicit deletion of arrays.
Although an array may have gone out of scope, we do not release the memory since we can reuse the same allocated memory for another array without calling (a relatively expensive) cudaMalloc call.
In that sense, you may not see the release memory.
----
Shehzan
Developer
AccelerEyes
User avatar
shehzan
 
Posts: 121
Joined: Tue Feb 12, 2013 7:20 pm

Re: Memory management

Postby Medivh » Sat Sep 06, 2014 5:14 pm

So if an array C (esample 1th post) is gone of scope, i have to reuse that variable C for another array (a kind of override/realloaction) ?

array C = rand(1,10);
.....
....
C out of scope
...
array C = seq(-5,10);
Medivh
 
Posts: 6
Joined: Fri Jul 18, 2014 9:19 am

Re: Memory management

Postby shehzan » Sat Sep 06, 2014 5:55 pm

By C/C++ rules, if C goes out of scope, it cannot be reused.

When I said the memory is resued is valid in the following case:

// Allocate memory for C
// Use C
// C out of scope

// Allocate D
// Use D.

In this case D may be allowed to reuse memory already allocated to C.
Note this is a possibility but not a certainty. There are multiple condition governing such reuse. The memory manger decides whether to reuse or allocate new memory.
----
Shehzan
Developer
AccelerEyes
User avatar
shehzan
 
Posts: 121
Joined: Tue Feb 12, 2013 7:20 pm


Return to [archive-commercial] Programming & Development with ArrayFire

cron