code: def cuda_kernel_factory(nvrtc_kernel_str, dtypes, kernel_name=None):
      """
      A factory wrapper function to perform some of the boiler-plate involved in
      making cuPy RawKernels type-agnostic.
  
      Until a better method is created, either by RAPIDS or cuPy, this function
      will perform a string search and replace of c-based datatype primitives
      in ``nvrtc_kernel_str`` using a numerical placeholder (eg. {0}, {1}) for
      the dtype in the corresponding index of tuple ``dtypes``.
  
      Note that the extern, function scope, and function name should not be
      included in the kernel string. These will be added by this function and
      the function name will be made unique, based on the given dtypes.
  
      Examples
      --------
  
          The following kernel string with dtypes = [float, double, int]
  
          ({0} *a, {1} *b, {2} *c) {}
  
          Will become
  
          (float *a, double *b, int *c) {}
  
      Parameters
      ----------
  
      nvrtc_kernel_str : string valid nvrtc kernel string without extern, scope,
                         or function name.
      dtypes : tuple of dtypes to search and replace.
      kernel_name : string prefix and function name to use. Note that when
                    this not set (or is set to None), a UUID will
                    be used, which will stop this function from
                    being memoized.
  
      Returns
      -------
  
      kernel_name : string unique function name created for kernel,
      raw_kernel : cupy.RawKernel object ready for use
      """
  
      dtype_strs = get_dtype_strs(dtypes)
  
      for idx, dtype in enumerate(dtypes):
          nvrtc_kernel_str = nvrtc_kernel_str.replace(
              "{%d}" % idx, dtype_strs[idx]
          )
  
      kernel_name = f"""{uuid1()
                        if kernel_name is None
                        else kernel_name}_{
                          "".join(dtype_strs).replace(" ", "_")
                      }"""
  
      nvrtc_kernel_str = "%s\nvoid %s%s" % (
          extern_prefix,
          kernel_name,
          nvrtc_kernel_str,
      )
  
      if logger.should_log_for(logger.level_debug):
          logger.debug(str(nvrtc_kernel_str))
  
      return cp.RawKernel(nvrtc_kernel_str, kernel_name)
  
imports: import cuml.internals.logger
  from uuid import uuid1
  import functools
  from cuml.internals.safe_imports import cpu_only_import
  from cuml.internals.safe_imports import gpu_only_import
label_desc: Use image node_id 3 for calling a global function with example usage: cuda_kernel_factory(nvrtc_kernel_str, dtypes, kernel_name) and returns: cp