Matlab and sgesv and segmentation faults

General CULA Dense (LAPACK & BLAS) support and troubleshooting. Use this forum if you are having a general problem or have encountered a bug.

Re: Matlab and sgesv and segmentation faults

Postby Boxed Cylon » Wed Sep 05, 2012 2:28 pm

Just to note that I've upgraded my system to the new SUSE 12.2. (This then required that I compile gcc 4.4, since the 4.7 that came with the new SUSE is not compatible with matlab.) Alas, even though I have a new OS version and a new gcc version, I still get the dreaded "Segmentation fault" when clearing the mex file. Too bad.

On the other hand, I have a snazzy new system!
Boxed Cylon
 
Posts: 48
Joined: Fri Oct 16, 2009 8:57 pm

Re: Matlab and sgesv and segmentation faults

Postby Boxed Cylon » Mon Sep 10, 2012 9:19 pm

A minor breakthrough...

If I run the above gpu_sgesv routine in matlab, and then run the routine below, I can then happily "clear all" or exit matlab without a problem.

The routine below must not be linked to CULA libraries and, as you see, it merely executes a cudaDeviceReset(); at exit. Presumably what is happening is that the CULA libraries get cleared when gpu_sgesv is cleared, but the CUDA libraries are still loaded by this routine. Then this routine gets cleared, the DeviceReset happens, and the CUDA libraries are unloaded. The effect is to allow a clean clearing of matlab routines and variables, or a clean matlab exit.

This suggests that the ordering of how the libraries are unloaded is important, but I am not sure how to arrange that! This is a viable workaround for the issue that has nagged me, in any case.

Code: Select all
#include "mex.h"
#include "cublas.h"
#include "cuda.h"

static int initialized = 0;

/* --------------------------- host code ------------------------------*/


/*  end_cula.cu -
    No input, no output.


  B. Cylon  08/2012
*/

void cleanup(void) {
   mexPrintf("MEX-file is terminating, exiting CUDA/CULA-2 Thread\n");
    cudaDeviceReset();
   mexPrintf("Exited CUDA Thread.\n");
}


void mexFunction( int nlhs, mxArray *plhs[],
                  int nrhs, const mxArray *prhs[])
{
      if (!initialized) {

      fprintf (stderr,"************* Starting CULA Safety Exit *************\n");
       mexAtExit(cleanup);
       initialized = 1;
      fprintf (stderr,"*************  Done!  *************\n");
      }

}
Boxed Cylon
 
Posts: 48
Joined: Fri Oct 16, 2009 8:57 pm

Re: Matlab and sgesv and segmentation faults

Postby john » Fri Oct 12, 2012 12:20 pm

Hi Cylon,
I believe I've cracked this one, but unfortunately I don't have a suitable platform on which to test (namely containing CUDA 5 and Matlab). We did manage to find some resources that were unknowingly allocated within CUBLAS during the course of culaShutdown and then left to leak. This thread managed to demonstrate it very succinctly: LINK This is fixed as of next version, as that thread indicates, so I hope that the next release puts this to rest!
john
Administrator
 
Posts: 587
Joined: Thu Jul 23, 2009 2:31 pm

Re: Matlab and sgesv and segmentation faults

Postby Boxed Cylon » Sat Oct 20, 2012 4:16 am

I had high hopes that CUDA 5.0/CULA R16 would resolve the segmentation faults when clearing the mex file, but alas no such luck.

The workaround given above still works though. And it looks like while "clear all" causes a segmentation fault, an "exit" exits cleanly now, which is an improvement, I think.

I use gcc version 4.4.7 (compiled) and Suse 12.2. Its late now however; perhaps tomorrow will resolve the situation.

In any case, thanks for the updated software!
Boxed Cylon
 
Posts: 48
Joined: Fri Oct 16, 2009 8:57 pm

Previous

Return to CULA Dense Support

Who is online

Users browsing this forum: No registered users and 6 guests

cron