code: def convert_to_cupy(
      data: Any,
      dtype: np.dtype | None = None,
      wrap_sequence: bool = False,
      safe: bool = False,
  ) -> Any:
      """
      Utility to convert the input data to a cupy array. If passing a dictionary, list or tuple,
      recursively check every item and convert it to cupy array.
  
      Args:
          data: input data can be PyTorch Tensor, numpy array, cupy array, list, dictionary, int, float, bool, str, etc.
              Tensor, numpy array, cupy array, float, int, bool are converted to cupy arrays,
              for dictionary, list or tuple, convert every item to a numpy array if applicable.
          dtype: target data type when converting to Cupy array, tt must be an argument of `numpy.dtype`,
              for more details: https://docs.cupy.dev/en/stable/reference/generated/cupy.array.html.
          wrap_sequence: if `False`, then lists will recursively call this function.
              E.g., `[1, 2]` -> `[array(1), array(2)]`. If `True`, then `[1, 2]` -> `array([1, 2])`.
          safe: if `True`, then do safe dtype convert when intensity overflow. default to `False`.
              E.g., `[256, -12]` -> `[array(0), array(244)]`. If `True`, then `[256, -12]` -> `[array(255), array(0)]`.
      """
      if safe:
          data = safe_dtype_range(data, dtype)
      # direct calls
      if isinstance(data, torch.Tensor) and data.device.type == "cuda":
          # This is needed because of https://github.com/cupy/cupy/issues/7874#issuecomment-1727511030
          if data.dtype == torch.bool:
              data = data.detach().to(torch.uint8)
              if dtype is None:
                  dtype = bool  # type: ignore
          data = cp.asarray(data, dtype)
      elif isinstance(
          data, (cp_ndarray, np.ndarray, torch.Tensor, float, int, bool)
      ):
          data = cp.asarray(data, dtype)
      elif isinstance(data, list):
          list_ret = [convert_to_cupy(i, dtype) for i in data]
          return cp.asarray(list_ret) if wrap_sequence else list_ret
      elif isinstance(data, tuple):
          tuple_ret = tuple(convert_to_cupy(i, dtype) for i in data)
          return cp.asarray(tuple_ret) if wrap_sequence else tuple_ret
      elif isinstance(data, dict):
          return {k: convert_to_cupy(v, dtype) for k, v in data.items()}
      # make it contiguous
      if not isinstance(data, cp.ndarray):
          raise ValueError(
              f"The input data type [{type(data)}] cannot be converted into cupy arrays!"
          )
  
      if data.ndim > 0:
          data = cp.ascontiguousarray(data)
      return data
  
imports: from __future__ import annotations
  import re
  from collections.abc import Sequence
  from typing import Any
  import numpy
  import torch
  import monai
  from monai.config.type_definitions import DtypeLike, NdarrayTensor
  from monai.utils import optional_import
label_desc: Use image node_id 9 for calling a global function with example usage: convert_to_cupy(data, dtype, wrap_sequence, safe) and returns: data, unknown, unknown, unknown