code: def solve_pkt_with_cg(
      pkt_spmv,
      b,
      precon=None,
      x=None,
      tol=1e-7,
      max_iterations=None,
      debug=False,
      pagelocked_allocator=None,
  ):
      if x is None:
          x = gpuarray.zeros(
              pkt_spmv.shape[0],
              dtype=pkt_spmv.dtype,
              allocator=b.allocator,
          )
      else:
          x = pkt_spmv.permute(x)
  
      if pagelocked_allocator is None:
          pagelocked_allocator = drv.pagelocked_empty
  
      cg = CGStateContainer(
          pkt_spmv, precon, pagelocked_allocator=pagelocked_allocator
      )
  
      cg.reset(pkt_spmv.permute(b), x)
  
      it_count = [0]
      res_count = [0]
  
      def debug_callback(what, it_number, x, resid, d, delta):
          if what == "it":
              it_count[0] += 1
          elif what == "it+residual":
              res_count[0] += 1
              it_count[0] += 1
  
      result = cg.run(
          max_iterations, tol, debug_callback=debug_callback
      )
  
      return pkt_spmv.unpermute(result), it_count[0], res_count[0]
  
file_path: pycuda/pycuda/sparse/cg.py
imports: from __future__ import division
  from __future__ import absolute_import
  from pycuda.sparse.inner import AsyncInnerProduct
  from pytools import memoize_method
  import pycuda.driver
  import pycuda.gpuarray
  import numpy
label_desc: Use image node_id 1 for calling a global function with example usage: solve_pkt_with_cg(pkt_spmv, b, precon, x, tol, max_iterations, debug, pagelocked_allocator) and returns: pkt_spmv,  it_count,  res_count