code: def ensure_cugraph_obj(
      obj, nx_weight_attr=None, matrix_graph_type=None
  ):
      """
      Convert the input obj - if possible - to a cuGraph Graph-type obj (Graph,
      etc.) and return a tuple of (cugraph Graph-type obj, original
      input obj type). If matrix_graph_type is specified, it is used as the
      cugraph Graph-type obj to create when converting from a matrix type.
      """
      # FIXME: importing here to avoid circular import
      from cugraph.structure import Graph
      from cugraph.utilities.nx_factory import convert_from_nx
  
      input_type = type(obj)
      if is_cugraph_graph_type(input_type):
          return (obj, input_type)
  
      elif is_nx_graph_type(input_type):
          return (
              convert_from_nx(obj, weight=nx_weight_attr),
              input_type,
          )
  
      elif (input_type in __cp_matrix_types) or (
          input_type in __sp_matrix_types
      ):
          if matrix_graph_type is None:
              matrix_graph_type = Graph
          elif matrix_graph_type not in [Graph]:
              if not isinstance(matrix_graph_type, Graph):
                  raise TypeError(
                      f"matrix_graph_type must be either a cugraph "
                      f"Graph, got: {matrix_graph_type}"
                  )
          if input_type in (
              __cp_compressed_matrix_types
              + __sp_compressed_matrix_types
          ):
              coo = obj.tocoo(copy=False)
          else:
              coo = obj
  
          if input_type in __cp_matrix_types:
              df = cudf.DataFrame(
                  {
                      "source": cp.ascontiguousarray(coo.row),
                      "destination": cp.ascontiguousarray(coo.col),
                      "weight": cp.ascontiguousarray(coo.data),
                  }
              )
          else:
              df = cudf.DataFrame(
                  {
                      "source": coo.row,
                      "destination": coo.col,
                      "weight": coo.data,
                  }
              )
          # FIXME:
          # * do a quick check that symmetry is stored explicitly in the cupy
          #   data for sym matrices (ie. for each uv, check vu is there)
          # * populate the cugraph graph with directed data and set renumbering
          #   to false in from edge list call.
          if isinstance(matrix_graph_type, Graph):
              G = matrix_graph_type
          else:
              G = matrix_graph_type()
          G.from_cudf_edgelist(df, edge_attr="weight", renumber=True)
  
          return (G, input_type)
  
      else:
          raise TypeError(f"obj of type {input_type} is not supported.")
  
imports: import importlib
  import os
  import shutil
  from numba import cuda
  import cudf
  from cudf.core.column import as_column
  from cuda.cudart import cudaDeviceAttr
  from rmm._cuda.gpu import getDeviceAttribute
label_desc: Use image node_id 6 for calling a global function with example usage: ensure_cugraph_obj(obj, nx_weight_attr, matrix_graph_type) and returns: obj,  input_type, convert_from_nx,  input_type, G,  input_type