def gen_profiler(
    func_attrs: Dict[str, Any], workdir: str, header_files: str, backend_spec
):
    """Generates code for topk profiling.

    Parameters
    ----------
    func_attrs : Dict[str, Any]
        Stores the operation attributes.
    workdir: str
        Target directory for generated C++ source code files
    header_files : str
        Includes the header files for a backend.
    backend_spec : class
        Specifies the backend configurations.

    Returns
    -------
    None
    """
    # If topK is less than 100, disable profiling since our implementation does not need it.
    if func_attrs["topK"] < 100:
        func_attrs["has_profiler"] = False
        return

    op_type = func_attrs["op"]
    file_pairs = []
    index_type = backend_spec.index_type
    prefix = backend_spec.prefix
    dtype = backend_spec.dtype_to_backend_type(func_attrs["inputs"][0]._attrs["dtype"])

    code = PROFILER_TEMPLATE.render(
        header_files=header_files,
        func_signature=FUNC_SIGNATURE.render(
            func_name=func_attrs["name"], index_type=index_type, prefix=prefix
        ),
        kernel=KERNEL_TEMPLATE.render(cub=backend_spec.cub, prefix=prefix),
        dtype=dtype,
    )
    op_name = func_attrs["op"]
    add_profiler(file_pairs, workdir, op_type, op_name, code)
    return file_pairs
Generates code for topk profiling.

    Parameters
    ----------
    func_attrs : Dict[str, Any]
        Stores the operation attributes.
    workdir: str
        Target directory for generated C++ source code files
    header_files : str
        Includes the header files for a backend.
    backend_spec : class
        Specifies the backend configurations.

    Returns
    -------
    None
    
python/aitemplate/backend/common/tensor/topk_common.py