def gen_profiler(func_attrs, workdir, profiler_filename, shape_template):
    """Codegen for conv3d profiler."""
    op_type = func_attrs["op"]
    op_instance = func_attrs["op_instance"]

    # shape func
    shape_func = shape_template.render(
        indent="  ",
        dtype="int64_t ",
        div="/",
        x_dim0="batch",
        x_dim1="in_d",
        x_dim2="in_h",
        x_dim3="in_w",
        x_dim4="in_ch",
        w_dim0="out_ch",
        w_dim1="kernel_d",
        w_dim2="kernel_h",
        w_dim3="kernel_w",
        stride_d="stride_d",
        stride_h="stride_h",
        stride_w="stride_w",
        dilate_d="dilation_d",
        dilate_h="dilation_h",
        dilate_w="dilation_w",
        pad_d="pad_d",
        pad_h="pad_h",
        pad_w="pad_w",
    )

    backend_spec = CUDASpec()
    dtype = backend_spec.dtype_to_lib_type(func_attrs["inputs"][0]._attrs["dtype"])
    instance_name_base = "DeviceConvFwdInstance"
    exec_program = EXEC_TEMPLATE.render(
        indent="  ",
        is_profiler=True,
        instance=instance_name_base,
        dtype=dtype,
    )

    function_name = "conv"
    instances = []
    benchmark_instances = []
    for instance_idx, (op_name, op) in enumerate(op_instance.items()):
        config = common.emit_instance(op)
        config_name = common.extract_config_name(config)
        instance_name = f"{instance_name_base}_{instance_idx}"
        conv_op = f"conv_op_{instance_idx}"
        instance = INSTANCE_TEMPLATE.render(
            config_name=config_name,
            name=instance_name,
            config=config,
        )
        benchmark_instance = BENCHMARK_INSTANCE_TEMPLATE.render(
            indent="  ",
            instance_name=instance_name,
            conv_op=conv_op,
            conv_op_name=op_name,
            func_name=f"benchmark_{function_name}",
            ni="NI",
            di="DI",
            hi="HI",
            wi="WI",
            ci="CI",
            co="CO",
            kd="KD",
            kh="KH",
            kw="KW",
            no="NO",
            do="DO",
            ho="HO",
            wo="WO",
            stride_d="stride_d",
            stride_h="stride_h",
            stride_w="stride_w",
            dilation_d="dilation_d",
            dilation_h="dilation_h",
            dilation_w="dilation_w",
            pad_d="pad_d",
            pad_h="pad_h",
            pad_w="pad_w",
        )
        instances.append(instance)
        benchmark_instances.append(benchmark_instance)

    op_func = SRC_TEMPLATE.render(
        is_profiler=True,
        instances="\n".join(instances),
        instance_name_base=instance_name_base,
        function_name=function_name,
        shape_function="",
        exec_paths=exec_program,
    )
    func_call = FUNC_CALL_TEMPLATE.render(
        indent="  ",
        is_profiler=True,
        func_name=function_name,
        in_ptr="x.device_data()",
        weight_ptr="w.device_data()",
        out_ptr="y.device_data()",
        p_batch="&NI",
        p_out_ch="&CO",
        p_in_ch="&CI",
        p_kernel_d="&KD",
        p_kernel_h="&KH",
        p_kernel_w="&KW",
        p_in_d="&DI",
        p_in_h="&HI",
        p_in_w="&WI",
        p_out_batch="&NO",
        p_out_d="&DO",
        p_out_h="&HO",
        p_out_w="&WO",
        stride_d="stride_d",
        stride_h="stride_h",
        stride_w="stride_w",
        dilation_d="dilation_d",
        dilation_h="dilation_h",
        dilation_w="dilation_w",
        pad_d="pad_d",
        pad_h="pad_h",
        pad_w="pad_w",
    )
    code = PROFILER_TEMPLATE.render(
        op_func=op_func,
        shape_func=shape_func,
        instance_name_base=instance_name_base,
        function_name=function_name,
        func_call=func_call,
        benchmark_instances="\n".join(benchmark_instances),
    )

    # FIXME: remove file_pairs once we have make -j ready for building
    # an entire graph
    file_pairs = []
    common.add_profiler(file_pairs, workdir, op_type, profiler_filename, code)
    # build
    return common.build_profiler(file_pairs)
Codegen for conv3d profiler.
python/aitemplate/backend/cuda/conv3d/conv3d.py