예제 #1
0
void MallocPlus::memory_delete_all(void){
   map <void *, malloc_plus_memory_entry*> memory_ptr_dict_old = memory_ptr_dict;
   map <void *, malloc_plus_memory_entry*>::iterator it;

   for ( it=memory_ptr_dict_old.begin(); it != memory_ptr_dict_old.end(); it++){
      malloc_plus_memory_entry *memory_item = it->second;

      if (DEBUG) printf("MALLOC_PLUS_MEMORY_REMOVE: DEBUG -- removed memory pointer %p name %s\n",memory_item->mem_ptr,memory_item->mem_name);

      if ((memory_item->mem_flags & DEVICE_REGULAR_MEMORY) != 0){
#ifdef HAVE_OPENCL
         ezcl_device_memory_delete(memory_item->mem_ptr);
#endif
      } else {
         free(memory_item->mem_ptr);
      }

      free(memory_item->mem_nelem);
      free(memory_item->mem_name);
      free(memory_item);
   }

   memory_ptr_dict.clear();
   memory_name_dict.clear();
}
예제 #2
0
void *MallocPlus::memory_delete(const char *name){
   list<malloc_plus_memory_entry>::iterator it;

   for ( it=memory_list.begin(); it != memory_list.end(); it++){
      if (DEBUG) printf("Testing it name %s input name %s\n",it->mem_name,name);
      if (! strcmp(name,it->mem_name)) break;
   }
   if (it != memory_list.end()){
      if (DEBUG) printf("MALLOC_PLUS_MEMORY_REMOVE: DEBUG -- removed memory pointer %p\n",it->mem_ptr);
      free(it->mem_name);
      if ((it->mem_flags & DEVICE_REGULAR_MEMORY) != 0){
#ifdef HAVE_OPENCL
         ezcl_device_memory_delete(it->mem_ptr);
#endif
      }
#ifdef HAVE_J7
      else if (it->mem_flags & LOAD_BALANCE_MEMORY) {
         j7->memFree(it->mem_ptr);
      }
#endif
      else {
         free(it->mem_ptr);
      }
      memory_list.erase(it);
   } else {
      if (DEBUG) printf("Warning -- memory named %s not found\n",name);
   }

   return(NULL);
}
예제 #3
0
void *MallocPlus::memory_delete(void *malloc_mem_ptr){
   map <void *, malloc_plus_memory_entry*>::iterator it = memory_ptr_dict.find(malloc_mem_ptr);

   if (it != memory_ptr_dict.end()){
      malloc_plus_memory_entry *memory_item = it->second;

      if (DEBUG) printf("MALLOC_PLUS_MEMORY_REMOVE: DEBUG -- removed memory pointer %p\n",memory_item->mem_ptr);

      if ((memory_item->mem_flags & DEVICE_REGULAR_MEMORY) != 0){
#ifdef HAVE_OPENCL
         //printf("MALLOC_PLUS_MEMORY_REMOVE: DEBUG -- removed memory pointer %p\n",memory_item->mem_ptr);
         ezcl_device_memory_delete(memory_item->mem_ptr);
#endif
      }
#ifdef HAVE_J7
      else if (memory_item->mem_flags & LOAD_BALANCE_MEMORY) {
         j7->memFree(memory_item->mem_ptr);
      }
#endif
      else {
         free(memory_item->mem_ptr);
      }

      memory_ptr_dict.erase(it);
      // Need to delete the entry in the name dictionary. This is done in a separate scope
      // so the iterator "it" is isolated for this use
      {
         map <const char *, malloc_plus_memory_entry*>::iterator it = memory_name_dict.find(memory_item->mem_name);
         memory_name_dict.erase(it);
      }

      free(memory_item->mem_nelem);
      free(memory_item->mem_name);
      free(memory_item);
   } else {
      if (DEBUG) printf("Warning -- memory pointer %p not found\n",malloc_mem_ptr);
   }

   return(NULL);
}
예제 #4
0
void *MallocPlus::memory_replace(void *malloc_mem_ptr_old, void * const malloc_mem_ptr_new){
   list<malloc_plus_memory_entry>::iterator it, it_old=memory_list.end(), it_new=memory_list.end();

   for ( it=memory_list.begin(); it != memory_list.end(); it++){
      if (DEBUG) printf("Testing it ptr %p ptr old %p ptr new %p name %s\n",it->mem_ptr,malloc_mem_ptr_old,malloc_mem_ptr_new,it->mem_name);
      if (malloc_mem_ptr_old == it->mem_ptr) it_old = it;
      if (malloc_mem_ptr_new == it->mem_ptr) it_new = it;
      if (it_new != memory_list.end() && it_old != memory_list.end() ) break;
   }
   if (it != memory_list.end()){
      if (DEBUG) printf("Found it ptr_old %p name %s ptr_new %p name %s\n",it_old->mem_ptr,it_old->mem_name,it_new->mem_ptr,it_new->mem_name);
      if ((it_old->mem_flags & DEVICE_REGULAR_MEMORY) != 0){
#ifdef HAVE_OPENCL
         if (DEBUG) printf("Deleting device memory name %s pointer %p\n",it_old->mem_name,it_old->mem_ptr);
         ezcl_device_memory_delete(it_old->mem_ptr);
#endif
      }
#ifdef HAVE_J7
      else if (it->mem_flags & LOAD_BALANCE_MEMORY) {
         j7->memFree(it_old->mem_ptr);
      }
#endif
      else {
         free(it_old->mem_ptr);
      }
      it_old->mem_ptr      = it_new->mem_ptr;
      it_old->mem_nelem    = it_new->mem_nelem;
      it_old->mem_capacity = it_new->mem_capacity;
      it_old->mem_elsize   = it_new->mem_elsize;
      it_old->mem_flags    = it_new->mem_flags;
      malloc_mem_ptr_old = (void *)malloc_mem_ptr_new;
      free(it_new->mem_name);
      memory_list.erase(it_new);
      return(it_old->mem_ptr);
   } else {
      if (DEBUG) printf("Warning -- memory not found\n");
   }
   return(NULL);
}
예제 #5
0
void *MallocPlus::memory_delete(const char *name){
   map <const char *, malloc_plus_memory_entry*>::iterator it = memory_name_dict.find(name);

   if (it != memory_name_dict.end()){
      malloc_plus_memory_entry *memory_item = it->second;

      if (DEBUG) printf("MALLOC_PLUS_MEMORY_REMOVE: DEBUG -- removed memory pointer %p\n",memory_item->mem_ptr);
      if ((memory_item->mem_flags & DEVICE_REGULAR_MEMORY) != 0){
#ifdef HAVE_OPENCL
         ezcl_device_memory_delete(memory_item->mem_ptr);
#endif
      }
#ifdef HAVE_J7
      else if (memory_item->mem_flags & LOAD_BALANCE_MEMORY) {
         j7->memFree(memory_item->mem_ptr);
      }
#endif
      else {
         free(memory_item->mem_ptr);
      }

      memory_name_dict.erase(it);
      {
         map <void *, malloc_plus_memory_entry*>::iterator it = memory_ptr_dict.find(memory_item->mem_ptr);
         memory_ptr_dict.erase(it);
      }

      free(memory_item->mem_nelem);
      free(memory_item->mem_name);
      free(memory_item);
   } else {
      if (DEBUG) printf("Warning -- memory named %s not found\n",name);
   }

   return(NULL);
}
예제 #6
0
int L7_Free(
      const int *l7_id
      )
{
   /*
    * Purpose
    * =======
    * L7_Free destroys the database associated with the input
    * L7 handle. All memory assoicated with this database
    * is deallocated.
    * 
    * Arguments
    * =========
    * l7_id          (input) const int*
    *                Handle to database to be destroyed.
    * 
    * 
    * Return value
    * ============
    * Value other than L7_OK indicates an error.
    * 
    * Notes:
    * =====
    * It is not necessary to destroy databases once they are not needed.
    * However, a significant amount of memory use can build up if 
    * databases are created throuhout execution. Therefore, the user
    * is strongly encouraged to destroy databases that are no longer
    * needed.
    * 
    */
   
   /*
    * Local variables.
    */
   
   int
     ierr;            /* Error code for return              */
   
#if defined HAVE_MPI
   
   l7_id_database
     *l7_db,          /* Database for the input l7_id.      */
     *prev_l7_db;     /* Previous structure in linked list. */
   
   /*
    * Executable Statements
    */
   
   if (! l7.mpi_initialized){
      return(0);
   }
   
   ierr = MPI_Comm_rank(MPI_COMM_WORLD, &l7.penum);
   L7_ASSERT( ierr == MPI_SUCCESS, "MPI_Comm_rank error", ierr);
 
   if (l7.initialized != 1){
      ierr = -1;
      L7_ASSERT( l7.initialized != 1, "L7 not initialized", ierr);
   }
   
   /*
    *  Get first L7 structure and null out previous structure
    */
   
   l7_db      = l7.first_db;
   prev_l7_db = (l7_id_database *)0;
   
   /*
    * Find the structure to be freed
    */
   
   while (l7_db){
      if (l7_db->l7_id == *l7_id )
         break;
      prev_l7_db = l7_db;
      l7_db = l7_db->next_db;
   }
   
   if (l7_db == NULL){
      ierr = -1;
      L7_ASSERT(l7_db != NULL, "Failed to find database.", ierr);
   }
   
   /*
    * Free all data associated with this id.
    */
   
   if (l7_db->indices_needed)
      free(l7_db->indices_needed);
   
   if (l7_db->recv_from)
      free(l7_db->recv_from);
   
   if (l7_db->recv_counts)
      free(l7_db->recv_counts);
   
   if (l7_db->send_to)
      free(l7_db->send_to);
   
   if (l7_db->send_counts)
      free(l7_db->send_counts);
   
   if (l7_db->indices_global_to_send)
      free(l7_db->indices_global_to_send);
   
   if (l7_db->indices_local_to_send)
      free(l7_db->indices_local_to_send);
   
   if (l7_db->starting_indices)
      free(l7_db->starting_indices);
   
   if (l7_db->mpi_request)
      free(l7_db->mpi_request);
   
   if (l7_db->mpi_status)
      free(l7_db->mpi_status);
   
#ifdef HAVE_OPENCL
   if (l7_db->indices_have)
      free(l7_db->indices_have);

   if (l7_db->dev_indices_have)
      ezcl_device_memory_delete(l7_db->dev_indices_have);
#endif
   
   /*
    * Assign pointers to next, first, and last if needed
    */
   
   if (l7.first_db == l7_db && l7.last_db == l7_db){
      /*
       * Only one database currently stored.
       */
      
      l7.first_db = (l7_id_database *)0;
      l7.last_db  = (l7_id_database *)0;
   }
   else if (l7.first_db == l7_db){
      /*
       * If this id is the first id, reassign first to next
       */
      
      l7.first_db = l7_db->next_db;
   }
   else if (l7.last_db == l7_db){
      /*
       * If this is the last id, reassign last to prev
       */
      
      l7.last_db = prev_l7_db;
      prev_l7_db->next_db = (l7_id_database *)0;
   }
   else {
      /*
       *  if this id is an interior id
       */
      prev_l7_db->next_db = l7_db->next_db;
   }
   
   /*
    * Free the database
    */
   
   free(l7_db);
   
   l7_db = NULL;
   
   /*
    * Decrement number of databases stored
    */
   
   l7.num_dbs--;
   
#endif /* HAVE_MPI */

   ierr = L7_OK;
   
   return(ierr);
   
}
예제 #7
0
void gpu_compact_hash_delete(cl_mem dev_hash, cl_mem dev_hash_header){
      ezcl_device_memory_delete(dev_hash);
      ezcl_device_memory_delete(dev_hash_header);
}
예제 #8
0
파일: hash.c 프로젝트: brtnfld/CLAMR
void gpu_compact_hash_delete(cl_mem dev_hash, cl_mem dev_hash_header){
   ezcl_device_memory_delete(dev_hash);
   ezcl_device_memory_delete(dev_hash_header);
   hash_method = METHOD_UNSET;
}