more cuda checking

This commit is contained in:
Vítor Santos Costa 2013-10-12 01:11:21 +01:00
parent 36087849f0
commit 0dc78f106b
5 changed files with 35 additions and 18 deletions

View File

@ -1237,6 +1237,7 @@ int Cuda_Eval(predicate **inpfacts, int ninpf, predicate **inprules, int ninpr,
cols1 = qposf->num_columns; cols1 = qposf->num_columns;
rows1 = cargar(qname, qposf->num_rows, cols1, 1, qposf->address_host_table, &dop1, 0); rows1 = cargar(qname, qposf->num_rows, cols1, 1, qposf->address_host_table, &dop1, 0);
} }
if(rows1 > 0) /*Query consideration*/ if(rows1 > 0) /*Query consideration*/
{ {
consulta(query + 1, qsize, qname, &tmprule); consulta(query + 1, qsize, qname, &tmprule);
@ -1275,9 +1276,9 @@ int Cuda_Eval(predicate **inpfacts, int ninpf, predicate **inprules, int ninpr,
} }
//free(hres); //free(hres);
cout << "Elapsed = " << time << endl; //cout << "Elapsed = " << time << endl;
cout << "Size = " << res_rows << endl; //cout << "Size = " << res_rows << endl;
cout << "Iterations = " << itr << endl; //cout << "Iterations = " << itr << endl;
clear_memory(); clear_memory();
*result = hres; *result = hres;

View File

@ -53,6 +53,7 @@ list<memnode>::iterator buscarpornombre(int name, int itr, int *totalrows, int *
{ {
int x = 1, sum = 0; int x = 1, sum = 0;
memnode temp; memnode temp;
temp.name = name; temp.name = name;
temp.iteration = itr; temp.iteration = itr;
pair<list<memnode>::iterator, list<memnode>::iterator> rec = equal_range(GPUmem.begin(), GPUmem.end(), temp, compareiteration); pair<list<memnode>::iterator, list<memnode>::iterator> rec = equal_range(GPUmem.begin(), GPUmem.end(), temp, compareiteration);
@ -104,14 +105,14 @@ int buscarpornombrecpu(int name, int itr, int *totalrows)
return x; return x;
} }
void limpiar() void limpiar(const char s[])
{ {
list<memnode>::iterator ini; list<memnode>::iterator ini;
memnode temp; memnode temp;
if(GPUmem.size() == 0) if(GPUmem.size() == 0)
{ {
cerr << "Not enough GPU memory: have " << avmem << endl; cerr << s << ": not enough GPU memory: have " << avmem << endl;
exit(1); exit(1);
} }
@ -182,12 +183,18 @@ void liberar(int *ptr, int size)
void reservar(int **ptr, int size) void reservar(int **ptr, int size)
{ {
// cout << "R " << avmem << " " << size //size_t free, total;
//cudaMemGetInfo( &free, &total );
// cerr << "R " << free << " " << size << endl;
while(avmem < size) while(avmem < size)
limpiar(); limpiar("not enough memory");
while(cudaMalloc(ptr, size) == cudaErrorMemoryAllocation) while(cudaMalloc(ptr, size) == cudaErrorMemoryAllocation)
limpiar(); limpiar("error in memory allocation");
if (! *ptr )
exit(0);
// cerr << *ptr << " " << size;
avmem -= size; avmem -= size;
// cout << " " << avmem << endl; // cout << " " << avmem << endl;
@ -235,6 +242,11 @@ int numrows(int name, int itr)
return sum; return sum;
} }
extern "C" void * YAP_IntToAtom(int);
extern "C" char * YAP_AtomName(void *);
int cargar(int name, int num_rows, int num_columns, int is_fact, int *address_host_table, int **ptr, int itr) int cargar(int name, int num_rows, int num_columns, int is_fact, int *address_host_table, int **ptr, int itr)
{ {
int numgpu, numcpu, totalrows = 0; int numgpu, numcpu, totalrows = 0;
@ -242,6 +254,7 @@ int cargar(int name, int num_rows, int num_columns, int is_fact, int *address_ho
int size, itrant; int size, itrant;
list<memnode>::iterator i; list<memnode>::iterator i;
memnode fact; memnode fact;
if(is_fact) if(is_fact)
{ {
i = buscarhecho(GPUmem.begin(), GPUmem.end(), name); i = buscarhecho(GPUmem.begin(), GPUmem.end(), name);
@ -464,12 +477,16 @@ void clear_memory()
{ {
list<memnode>::iterator ini; list<memnode>::iterator ini;
list<memnode>::iterator fin; list<memnode>::iterator fin;
ini = GPUmem.begin(); ini = GPUmem.begin();
fin = GPUmem.end(); fin = GPUmem.end();
while(ini != fin) while(ini != fin)
{ {
cudaFree(ini->dev_address); if (ini->isrule) {
ini++; cudaFree(ini->dev_address);
ini = GPUmem.erase(ini);
} else {
ini++;
}
} }
ini = CPUmem.begin(); ini = CPUmem.begin();
fin = CPUmem.end(); fin = CPUmem.end();
@ -478,6 +495,5 @@ void clear_memory()
free(ini->dev_address); free(ini->dev_address);
ini++; ini++;
} }
GPUmem.clear();
CPUmem.clear(); CPUmem.clear();
} }

View File

@ -11,7 +11,7 @@ using namespace std;
void calcular_mem(int); void calcular_mem(int);
void liberar(int*, int); void liberar(int*, int);
void limpiar(); void limpiar(const char []);
void limpiartodo(int*, int*); void limpiartodo(int*, int*);
int cargar(int, int, int, int, int*, int**, int); int cargar(int, int, int, int, int*, int**, int);
int cargafinal(int, int, int**); int cargafinal(int, int, int**);

View File

@ -839,7 +839,7 @@ int join(int *p1, int *p2, int rLen, int sLen, int of1, int of2, list<rulenode>:
} }
catch(std::bad_alloc &e) catch(std::bad_alloc &e)
{ {
limpiar(); limpiar("inclusive scan in join");
} }
} }
//thrust::inclusive_scan(res + 1, res + newLen, res + 1); //thrust::inclusive_scan(res + 1, res + newLen, res + 1);
@ -1021,7 +1021,7 @@ int join(int *p1, int *p2, int rLen, int sLen, int of1, int of2, list<rulenode>:
} }
catch(std::bad_alloc &e) catch(std::bad_alloc &e)
{ {
limpiar(); limpiar("inclusive scan in join");
} }
} }

View File

@ -102,7 +102,7 @@ int unir(int *res, int rows, int tipo, int **ret)
} }
catch(std::bad_alloc &e) catch(std::bad_alloc &e)
{ {
limpiar(); limpiar("sort/unique in unir");
} }
} }
nrows = thrust::distance(pt, re); nrows = thrust::distance(pt, re);
@ -140,7 +140,7 @@ int unir(int *res, int rows, int tipo, int **ret)
} }
catch(std::bad_alloc &e) catch(std::bad_alloc &e)
{ {
limpiar(); limpiar("sort/unique in unir");
} }
} }
nrows = thrust::distance(pt2, re2); nrows = thrust::distance(pt2, re2);
@ -179,7 +179,7 @@ int unir(int *res, int rows, int tipo, int **ret)
} }
catch(std::bad_alloc &e) catch(std::bad_alloc &e)
{ {
limpiar(); limpiar("sort/unique in unir");
} }
} }
nrows = thrust::distance(pt3, re3); nrows = thrust::distance(pt3, re3);