'Attempt allocation by calling *allocator*.  If a out-of-memory error
is raised, the pending deallocations are flushed and the allocation
is retried.  If it fails in the second attempt, the error is reraised.'

def _attempt_allocation(self, allocator):

    try:
        allocator()
    except CudaAPIError as e:
        if (e.code == enums.CUDA_ERROR_OUT_OF_MEMORY):
            self.deallocations.clear()
            allocator()
        else:
            raise
