code: def _convolve(
      in1,
      in2,
      use_convolve,
      swapped_inputs,
      mode,
  ):
      val = _valfrommode(mode)
  
      # Promote inputs
      promType = cp.promote_types(in1.dtype, in2.dtype)
      in1 = in1.astype(promType)
      in2 = in2.astype(promType)
  
      # Create empty array to hold number of aout dimensions
      out_dimens = np.empty(in1.ndim, int)
      if val == VALID:
          for i in range(in1.ndim):
              out_dimens[i] = (
                  max(in1.shape[i], in2.shape[i])
                  - min(in1.shape[i], in2.shape[i])
                  + 1
              )
              if out_dimens[i] < 0:
                  raise Exception(
                      "no part of the output is valid, use option 1 (same) or 2 \
                       (full) for third argument"
                  )
      elif val == SAME:
          for i in range(in1.ndim):
              if not swapped_inputs:
                  out_dimens[i] = in1.shape[i]  # Per scipy docs
              else:
                  out_dimens[i] = min(in1.shape[i], in2.shape[i])
      elif val == FULL:
          for i in range(in1.ndim):
              out_dimens[i] = in1.shape[i] + in2.shape[i] - 1
      else:
          raise Exception(
              "mode must be 0 (valid), 1 (same), or 2 (full)"
          )
  
      # Create empty array out on GPU
      out = cp.empty(out_dimens.tolist(), in1.dtype)
  
      out = _convolve_gpu(
          in1,
          out,
          in2,
          val,
          use_convolve,
          swapped_inputs,
      )
  
      return out
  
imports: import cupy
  import numpy
  from ..utils._caches import _cupy_kernel_cache
  from ..utils.helper_tools import _get_function, _get_tpb_bpg, _print_atts
  from .convolution_utils import CIRCULAR, FULL, PAD, REFLECT, SAME, VALID, _bvalfromboundary, _iDivUp, _valfrommode
label_desc: Use image node_id 5 for calling a global function with example usage: _convolve(in1, in2, use_convolve, swapped_inputs, mode) and returns: out