19     if(allocatedBuffers.empty())
 
   24         for(std::set<const void*>::const_iterator it=allocatedBuffers.begin(); it!=allocatedBuffers.end(); ++it)
 
   25             cudaFree(
const_cast<void*
>(*it));
 
   30     std::stringstream message;
 
   32     message<<
"Unfreed Device memory:";
 
   34     for(std::set<const void*>::const_iterator it=allocatedBuffers.begin(); it!=allocatedBuffers.end(); ++it)
 
   37     std::cerr<<message.str()<<
"\n";
 
   45     if(allocatedBuffers.count(pointer)==0)
 
   48     allocatedBuffers.erase(pointer);
 
   62         if(cudaPeekAtLastError() != cudaSuccess)
 
   64             std::stringstream message;
 
   66                 "Failure detected in " 
   67                 "CUDA::DeviceMemoryManager::freeMemoryUnregistered before the " 
   68                 "call to cudaFree:\n";
 
   69             message << cudaGetErrorString(cudaPeekAtLastError()) << 
"\n";
 
   71             std::cerr << message.str();
 
   83     cudaPointerAttributes attributes;
 
   84     cudaPointerGetAttributes(&attributes, ptr);
 
   86     switch(cudaGetLastError())
 
   91         case cudaErrorInvalidDevice:
 
   95         case cudaErrorInvalidValue:
 
  102     return attributes.memoryType == cudaMemoryTypeDevice;
 
  113 void* DeviceMemoryManager::allocateMemoryInternal(
const std::size_t bufferSize)
 
  118     void* 
const pointer = allocateMemoryInternalUnregistered(bufferSize);
 
  120     #ifdef OPENMPCD_DEBUG 
  121         if(allocatedBuffers.count(pointer) != 0)
 
  125                 "cudaMalloc succeeded, but yielded a used address.");
 
  129     allocatedBuffers.insert(pointer);
 
  134 void* DeviceMemoryManager::allocateMemoryInternalUnregistered(
 
  135     const std::size_t bufferSize)
 
  141     const cudaError_t result = cudaMalloc(&pointer, bufferSize);
 
  143     if(result!=cudaSuccess)
 
  145         std::stringstream message;
 
  146         message<<
"cudaMalloc failed when trying to allocate ";
 
  147         message<<bufferSize<<
" bytes. Error code: "<<result;
 
  148         message<<
". Error message: "<<cudaGetErrorString(result);
 
  155     #ifdef OPENMPCD_DEBUG 
  159                 MemoryManagementException,
 
  160                 "cudaMalloc succeeded, but yielded NULL pointer.");