def gen_function(func_attrs, template_path, shape_eval_template, shape_save_template):
    """

    Parameters
    ----------
    func_attrs : [type]
        [description]
    template_path : [type]
        [description]
    shape_eval_template : [type]
        [description]
    shape_save_template : [type]
        [description]

    Returns
    -------
    [type]
        [description]
    """
    func_name = func_attrs["name"]
    backend_spec = CUDASpec()
    elem_input_type = backend_spec.dtype_to_backend_type(
        func_attrs["inputs"][0]._attrs["dtype"]
    )
    elem_input_type2 = None
    if elem_input_type == "half":
        elem_input_type2 = "half2"
    elif elem_input_type == "float":
        elem_input_type2 = "float2"
    elif elem_input_type == "bfloat16":
        elem_input_type2 = "bfloat16_2"
    else:
        raise NotImplementedError(f"unsupported {elem_input_type=}")
    ndim = func_attrs["ndim"]
    xshape = ["*x_dim%d" % i for i in range(ndim)]
    shape_eval_func = shape_eval_template.render(
        indent="  ", dtype="int64_t ", shape=xshape, out_dim="out_dim"
    )
    yshape = ["*y_dim%d" % i for i in range(ndim - 1)]
    shape_save_func = shape_save_template.render(
        indent="  ", shape=yshape, last_dim="*y_dim%d" % (ndim - 1)
    )
    shape_func = shape_eval_func + shape_save_func
    exec_paths = EXEC_TEMPLATE.render(
        elem_input_type=elem_input_type,
        elem_input_type2=elem_input_type2,
        ndim=func_attrs["ndim"],
        indent="  ",
    )
    return SRC_TEMPLATE.render(
        function_name=func_name,
        elem_input_type=elem_input_type,
        shape_function=shape_func,
        exec_paths=exec_paths,
        ndim=func_attrs["ndim"],
    )


    Parameters
    ----------
    func_attrs : [type]
        [description]
    template_path : [type]
        [description]
    shape_eval_template : [type]
        [description]
    shape_save_template : [type]
        [description]

    Returns
    -------
    [type]
        [description]
    
python/aitemplate/backend/cuda/padding/pad_last_dim.py