diff --git a/packages/cuda/lista.cu b/packages/cuda/lista.cu index 4f4bb6131..2ca772b85 100644 --- a/packages/cuda/lista.cu +++ b/packages/cuda/lista.cu @@ -1237,6 +1237,7 @@ int Cuda_Eval(predicate **inpfacts, int ninpf, predicate **inprules, int ninpr, cols1 = qposf->num_columns; rows1 = cargar(qname, qposf->num_rows, cols1, 1, qposf->address_host_table, &dop1, 0); } + if(rows1 > 0) /*Query consideration*/ { consulta(query + 1, qsize, qname, &tmprule); @@ -1275,9 +1276,9 @@ int Cuda_Eval(predicate **inpfacts, int ninpf, predicate **inprules, int ninpr, } //free(hres); - cout << "Elapsed = " << time << endl; - cout << "Size = " << res_rows << endl; - cout << "Iterations = " << itr << endl; + //cout << "Elapsed = " << time << endl; + //cout << "Size = " << res_rows << endl; + //cout << "Iterations = " << itr << endl; clear_memory(); *result = hres; diff --git a/packages/cuda/memory.cu b/packages/cuda/memory.cu index 413562396..66c319ae6 100644 --- a/packages/cuda/memory.cu +++ b/packages/cuda/memory.cu @@ -53,6 +53,7 @@ list::iterator buscarpornombre(int name, int itr, int *totalrows, int * { int x = 1, sum = 0; memnode temp; + temp.name = name; temp.iteration = itr; pair::iterator, list::iterator> rec = equal_range(GPUmem.begin(), GPUmem.end(), temp, compareiteration); @@ -104,14 +105,14 @@ int buscarpornombrecpu(int name, int itr, int *totalrows) return x; } -void limpiar() +void limpiar(const char s[]) { list::iterator ini; memnode temp; if(GPUmem.size() == 0) { - cerr << "Not enough GPU memory: have " << avmem << endl; + cerr << s << ": not enough GPU memory: have " << avmem << endl; exit(1); } @@ -182,12 +183,18 @@ void liberar(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) - limpiar(); + limpiar("not enough memory"); while(cudaMalloc(ptr, size) == cudaErrorMemoryAllocation) - limpiar(); + limpiar("error in memory allocation"); + if (! *ptr ) + exit(0); + // cerr << *ptr << " " << size; avmem -= size; // cout << " " << avmem << endl; @@ -235,6 +242,11 @@ int numrows(int name, int itr) 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 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; list::iterator i; memnode fact; + if(is_fact) { i = buscarhecho(GPUmem.begin(), GPUmem.end(), name); @@ -464,12 +477,16 @@ void clear_memory() { list::iterator ini; list::iterator fin; - ini = GPUmem.begin(); + ini = GPUmem.begin(); fin = GPUmem.end(); while(ini != fin) { - cudaFree(ini->dev_address); - ini++; + if (ini->isrule) { + cudaFree(ini->dev_address); + ini = GPUmem.erase(ini); + } else { + ini++; + } } ini = CPUmem.begin(); fin = CPUmem.end(); @@ -478,6 +495,5 @@ void clear_memory() free(ini->dev_address); ini++; } - GPUmem.clear(); CPUmem.clear(); } diff --git a/packages/cuda/memory.h b/packages/cuda/memory.h index 1a573c5d9..9cc08e331 100644 --- a/packages/cuda/memory.h +++ b/packages/cuda/memory.h @@ -11,7 +11,7 @@ using namespace std; void calcular_mem(int); void liberar(int*, int); -void limpiar(); +void limpiar(const char []); void limpiartodo(int*, int*); int cargar(int, int, int, int, int*, int**, int); int cargafinal(int, int, int**); diff --git a/packages/cuda/treeb.cu b/packages/cuda/treeb.cu index 8a30c8fd4..d81883b2a 100755 --- a/packages/cuda/treeb.cu +++ b/packages/cuda/treeb.cu @@ -839,7 +839,7 @@ int join(int *p1, int *p2, int rLen, int sLen, int of1, int of2, list: } catch(std::bad_alloc &e) { - limpiar(); + limpiar("inclusive scan in join"); } } //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: } catch(std::bad_alloc &e) { - limpiar(); + limpiar("inclusive scan in join"); } } diff --git a/packages/cuda/union2.cu b/packages/cuda/union2.cu index 213a1619b..b3fcb07cf 100644 --- a/packages/cuda/union2.cu +++ b/packages/cuda/union2.cu @@ -102,7 +102,7 @@ int unir(int *res, int rows, int tipo, int **ret) } catch(std::bad_alloc &e) { - limpiar(); + limpiar("sort/unique in unir"); } } nrows = thrust::distance(pt, re); @@ -140,7 +140,7 @@ int unir(int *res, int rows, int tipo, int **ret) } catch(std::bad_alloc &e) { - limpiar(); + limpiar("sort/unique in unir"); } } nrows = thrust::distance(pt2, re2); @@ -179,7 +179,7 @@ int unir(int *res, int rows, int tipo, int **ret) } catch(std::bad_alloc &e) { - limpiar(); + limpiar("sort/unique in unir"); } } nrows = thrust::distance(pt3, re3);