Can I use only CPU memory?

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

Moderator: pavanky

Can I use only CPU memory?

Postby rm9 » Fri Jan 31, 2014 1:19 pm

Hi,

I have a few operations that I would like to do with the array class on the cpu memory (because they are large matrices and I don't care that it will be slower).
Is there anyway to tell the array class to use only the cpu and to free the gpu memory?

Thanks.
rm9
 
Posts: 54
Joined: Thu Jan 30, 2014 5:44 am

Re: Can I use only CPU memory?

Postby shehzan » Fri Jan 31, 2014 1:29 pm

Hi

Unfortunately, the array class is not designed to be used on the CPU.
The best alternative is to use the Host function to copy the data from GPU to CPU and then do your processing.
You can read more about the host function here: http://www.accelereyes.com/arrayfire/c/ ... __host.htm
----
Shehzan
Developer
AccelerEyes
User avatar
shehzan
 
Posts: 121
Joined: Tue Feb 12, 2013 7:20 pm

Re: Can I use only CPU memory?

Postby rm9 » Fri Jan 31, 2014 1:31 pm

So I can use host to get a pointer to the data on cpu memory, and then how do I free the gpu memory?
Thanks.
rm9
 
Posts: 54
Joined: Thu Jan 30, 2014 5:44 am

Re: Can I use only CPU memory?

Postby pavanky » Fri Jan 31, 2014 1:34 pm

Just to add what Shehzan said, you can use the CPU if you are using OpenCL with ArrayFire.

For example you can do something like this.

Code: Select all

// code here on gpu

// code here on cpu
{
 af::deviceset(cpu_device_number);
 // Large memory operations
 af::deviceset(0); // go back to GPU
}



We are trying to improve ArrayFire to make switching between devices (and especially CPU fall back) much easier in the future versions.
The problem with the current version (even with OpenCL) is that there will be a memory copy done when creating the array class from host pointer. So please keep that in mind.
Pavan Yalamanchili,
ArrayFire
--
~ If it is not broken, you have not tried hard enough ~
User avatar
pavanky
Site Admin
 
Posts: 1123
Joined: Mon Mar 15, 2010 7:39 pm
Location: Atlanta, GA

Re: Can I use only CPU memory?

Postby pavanky » Fri Jan 31, 2014 1:35 pm

Hi Ran,

The GPU memory is managed by our memory manager. You do not need to worry about freeing memory explicitly. All memory is unlocked when a variable goes out of scope.
Pavan Yalamanchili,
ArrayFire
--
~ If it is not broken, you have not tried hard enough ~
User avatar
pavanky
Site Admin
 
Posts: 1123
Joined: Mon Mar 15, 2010 7:39 pm
Location: Atlanta, GA

Re: Can I use only CPU memory?

Postby rm9 » Fri Jan 31, 2014 1:37 pm

So just to make sure, I can do something like this:
Code: Select all
{
array data = ....
// code that runs on gpu

// save data on cpu memory
host_data_ = data.host();
}
// GPU memory is cleared here?
rm9
 
Posts: 54
Joined: Thu Jan 30, 2014 5:44 am

Re: Can I use only CPU memory?

Postby rm9 » Fri Jan 31, 2014 1:37 pm

So just to make sure, I can do something like this:
Code: Select all
{
array data = ....
// code that runs on gpu

// save data on cpu memory
host_data_ = data.host();
}
// GPU memory is cleared here?
rm9
 
Posts: 54
Joined: Thu Jan 30, 2014 5:44 am

Re: Can I use only CPU memory?

Postby pavanky » Fri Jan 31, 2014 1:38 pm

The GPU memory is unlocked to be used further by ArrayFire. It is not "free"d to be used by a different application. af::info() will not show it as free memory, but in the backend, the memory is available to be utilized by another array.
Pavan Yalamanchili,
ArrayFire
--
~ If it is not broken, you have not tried hard enough ~
User avatar
pavanky
Site Admin
 
Posts: 1123
Joined: Mon Mar 15, 2010 7:39 pm
Location: Atlanta, GA

Re: Can I use only CPU memory?

Postby rm9 » Fri Jan 31, 2014 1:39 pm

I understand, that's the same for me. :)
Thanks!
rm9
 
Posts: 54
Joined: Thu Jan 30, 2014 5:44 am


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

cron