How to free sparse array?

42 views
Skip to first unread message

Alex Shroyer

unread,
Jan 11, 2022, 7:43:50 PMJan 11
to ArrayFire Users
Hi, I'm wondering why the memory seems to not be freed in this example, and how to free memory from a sparse array. Thanks!

// sparse.c
#include <arrayfire.h>
// create sparse array from dense identity array
//! af_release_array of sparse array does not free memory
int main(void)
{
 af_array af,saf;int ndims = 2; dim_t dims[] = {3,3}; size_t a,b,c,d;

 af_identity(&af,ndims,dims,f64);

 af_create_sparse_array_from_dense(&saf,af,AF_STORAGE_CSR);
 af_print_array(saf);

 af_release_array(af);
 af_device_gc();

 af_device_mem_info(&a,&b,&c,&d);
 printf("mem_info: %lu %lu %lu %lu \n",a,b,c,d);

 af_release_array(saf); // runs, but the memory is not released
 af_device_gc();

 af_device_mem_info(&a,&b,&c,&d);
 printf("mem_info: %lu %lu %lu %lu \n",a,b,c,d);

 return 0;
 }

# makefile
LIBS=-lafcpu
LIB_PATHS=-L/opt/arrayfire/lib64
INCLUDES=-I/opt/arrayfire/include
CC=g++  $(COMPILER_OPTIONS)
COMPILER_OPTIONS=-std=c++11 -g

$(target): $(target).c
        $(CC) $(target).c -o $(target) $(INCLUDES)      $(LIBS) $(LIB_PATHS)

# shell
$ make target=sparse && ./sparse
No Name Sparse Array
Storage Format : AF_STORAGE_CSR
[3 3 1 1]
No Name Sparse Array: Values
[3 1 1 1]
    1.0000
    1.0000
    1.0000

No Name Sparse Array: RowIdx
[4 1 1 1]
         0
         1
         2
         3

No Name Sparse Array: ColIdx
[3 1 1 1]
         0
         1
         2

mem_info: 3072 3 3072 3
mem_info: 3072 3 3072 3


Reply all
Reply to author
Forward
0 new messages