code: def __init__(self, devdata, threads, shared_mem=0, registers=0):
      if threads > devdata.max_threads:
          raise ValueError("too many threads")
  
      # copied literally from occupancy calculator
      alloc_warps = _int_ceiling(threads / devdata.warp_size)
      alloc_smem = _int_ceiling(
          shared_mem, devdata.smem_alloc_granularity
      )
      if devdata.register_allocation_unit == "warp":
          alloc_regs = alloc_warps * 32 * registers
      elif devdata.register_allocation_unit == "block":
          alloc_regs = _int_ceiling(alloc_warps * 2, 4) * 16 * registers
      else:
          raise ValueError(
              "Improper register allocation unit:"
              + devdata.register_allocation_unit
          )
  
      if alloc_regs > devdata.registers:
          raise ValueError("too many registers")
  
      if alloc_smem > devdata.shared_memory:
          raise ValueError("too much smem")
  
      self.tb_per_mp_limits = [
          (devdata.thread_blocks_per_mp, "device"),
          (_int_floor(devdata.warps_per_mp / alloc_warps), "warps"),
      ]
      if registers > 0:
          self.tb_per_mp_limits.append(
              (_int_floor(devdata.registers / alloc_regs), "regs")
          )
      if shared_mem > 0:
          self.tb_per_mp_limits.append(
              (_int_floor(devdata.shared_memory / alloc_smem), "smem")
          )
  
      self.tb_per_mp, self.limited_by = min(self.tb_per_mp_limits)
  
      self.warps_per_mp = self.tb_per_mp * alloc_warps
      self.occupancy = self.warps_per_mp / devdata.warps_per_mp
  
imports: import pycuda.driver
  import pycuda._driver
  import numpy
  from pycuda.compyte.dtypes import register_dtype, get_or_register_dtype, _fill_dtype_registry, dtype_to_ctype
label_desc: Use image node_id 1 to create a new OccupancyRecord object  with example: obj = OccupancyRecord(devdata, threads, shared_mem, registers)