'Return occupancy of a function.
:param func: kernel for which occupancy is calculated
:param blocksize: block size the kernel is intended to be launched with
:param memsize: per-block dynamic shared memory usage intended, in bytes'

def get_active_blocks_per_multiprocessor(self, func, blocksize, memsize, flags=None):

    retval = c_int()
    if (not flags):
        driver.cuOccupancyMaxActiveBlocksPerMultiprocessor(byref(retval), func.handle, blocksize, memsize)
    else:
        driver.cuOccupancyMaxActiveBlocksPerMultiprocessorWithFlags(byref(retval), func.handle, blocksize, memsize, flags)
    return retval.value
