     }
     else
     {
+      // reset the last CUDA error
+      cudaGetLastError();
+
       std::cout << "  failed to allocate " << n << " bytes of memory (fallback failed)" << std::endl;
       result = 0;
     }

  }
  else
  {
    // attempt to allocate pinned host memory
    void *h_ptr = 0;
    if(cudaMallocHost(&h_ptr, n) == cudaSuccess)

      }
      else
      {
        // reset the last CUDA error
        cudaGetLastError();

        // attempt to deallocate buffer
        std::cout << "  failed to map host memory into device address space (fallback failed)" << std::endl;
        cudaError_t error = cudaFreeHost(h_ptr);
