Bug - arrayfire error with cudaMalloc

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

Moderator: pavanky

Bug - arrayfire error with cudaMalloc

Postby kues » Sun Nov 03, 2013 8:59 pm

Dear all,

I have had a persistent af::exception error with a large piece of code that I am writing. The code segment below has been stripped down to the bare minimum that reproduces the error. I have removed the error handling code to improve readability.
The code that is provided iterates to i = 13 and then throws the following error:
"src/gena/gi_mem.cpp:533: CUDA runtime error: invalid device pointer (17)
terminate called after throwing an instance of 'af::exception'"

Removing (1) cudaMalloc and the associated array h_data or (2) removing temp_data prevents the problem from occurring. The error is not dependent on the value of maxlist.
I'm running CUDA 5.5 on a Centos 5 Linux distro. The error has appeared in both ArrayFire 1.9 and 2.0.

Any ideas on whether this is a problem with my code or with ArrayFire would be much appreciated.

Best,
Kingsley

Code: Select all
int main(int argc, char ** argv)
{

    float *dev_volt;
    int maxlist = 200;
   
        for( int i = 0; i != 100; i++){

            cout << i << endl;

           cudaMalloc( (void**)&dev_volt, maxlist*sizeof(*dev_volt) );

            array h_data( 1, maxlist, dev_volt, afDevice );
            array temp_data = constant( 0, 1, 10 );
            for( int x = 0; x < 5*maxlist; x++ )
                    temp_data( seq(0,4 ) ) = temp_data( seq( 5,9 ) );

            cudaFree( dev_volt );

    }
   

    return 0;
}
kues
 
Posts: 2
Joined: Sun Nov 03, 2013 6:42 pm

Re: Bug - arrayfire error with cudaMalloc

Postby pavanky » Tue Nov 05, 2013 11:54 am

Hi Kingsley,

Using cudaMalloc and cudaFree seems to be clashing with our memory manager. Would it be possible for you to use array::alloc<float>() and array::free instead ? This seems to work without issues.
We will be investigating the failure on our end as well.

Let me know if you need anything else from our end.
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: Bug - arrayfire error with cudaMalloc

Postby pavanky » Tue Nov 05, 2013 12:51 pm

Hi Kingsley,

Sorry about noticing this earlier. The problem is the following:

Once you give arrayfire access to a pointer, we take full control of the pointer (including the part where we free it). Our memory manager unlocks the memory when the variable is out of scope and frees the memory only when necessary.

In your particular code, cudaFree was already freeing the memory, causing our memory manager to free deallocated space and hence raising the exception.

In short, do not use cudaFree at the end of the loop and arrayfire will take care of freeing the resources for you.
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: Bug - arrayfire error with cudaMalloc

Postby kues » Tue Nov 05, 2013 1:39 pm

Thanks for help and quick replies.

Cheers,
Kingsley
kues
 
Posts: 2
Joined: Sun Nov 03, 2013 6:42 pm


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

cron