[Scilab-Dev] How to free unreferenced variable inside SciLab stack

Serge Steer Serge.Steer at inria.fr
Mon May 18 09:37:13 CEST 2009


Vincent Lejeune a écrit :
> Hi,
>
> I use a Scilab_variable_pointer in SciLab stack to hold a custom type.
> The matter is that I have no control over its unallocation by the
> SciLab Stack.
> The pointer actually hold the location of a matrix stored on GPU side.
> But when the pointer is no more referenced, the matrix is still in the
> GPU memory, and this lead to dirty memory leaks.
> I'm trying to do some benchmark over 10 000 computations of a sum of a
> 512*512 matrix. I do this with the SciLab code below :
>
> "timer();for i=1:10000 C=gpuAdd(A,B);end;timer()"
>
> Every time gpuAdd is called, a new matrix is created, but the previous
> matrix is not freed. So I can get up to 10 000 matrix of 250+ ko...
> But when I use the same code with "traditionnal" matrix, I don't have
> any memory leak. I think there is some unallocation work done by the
> scilab stacks, I'd like to know if I can overloard it in some way to
> free Matrix in GPU memory when the pointer is freed in the stack.
>
> Thx for the help !
>
In the current Scilab version (it will change with Scilab6) the regular
variables are stored in a preallocated stack. It is the stack mechanism
which removes the variables out of the stack when it is required. But
there is no free mechanism. So if you store a pointer in a regular
variable, the value of the pointer will be stored in the stack but
Scilab does not know anything about it.

Suppose that the variable A contains such a pointer, il one executes B=A
it will copy the value of the pointer in variable B (the data pointed to
are not copied). Now if one execute A=1, the old A value is replaced in
the stack by the new one without any care of what A was.

So there is now no way to implicitely unallocate pointers stored in
Scilab variables.

In you specific case ( C=gpuAdd(A,B)) it is however possible to free the
pointer on the computed sum after you have made a copy the  pointed
variable value into the regular matrix C.

Serge Steer



More information about the dev mailing list