Asynchronous copy in c++ when input has been destructed

I want to copy an at::Tensor input with pinned memory with
input.to(at::TensorOptions().device(at::kCUDA, -1), true, false, input.suggest_memory_format());
As it is an asynchronous operation, how to ensure that the storage area of the original input is not released before completion if input will be destructed?

Is the following function safe if input is in pinned memory, and on a different GPU device?.

at::Tensor to_current_device(at::Tensor input) {
  if (input.device() == at::kCPU) return input.cuda();
  if (input.device().index() == at::cuda::current_device()) return input;
  at::TensorOptions options;
  // input.is_pinned()
  return input.to(at::TensorOptions().device(at::kCUDA, -1), input.is_pinned(), 
                  false, // <==
                  input.suggest_memory_format());  
}

input = to_current_device(input);

And also about when copy is true:

at::Tensor to_current_device(at::Tensor input) {
  if (input.device() == at::kCPU) return input.cuda();
  if (input.device().index() == at::cuda::current_device()) return input;
  at::TensorOptions options;
  // input.is_pinned()
  return input.to(at::TensorOptions().device(at::kCUDA, -1), input.is_pinned(), 
                  true,  // <==
                  input.suggest_memory_format());  
                                                   
}

input = to_current_device(input);

Thanks so much if anyone can help.