[jit kernel] support dtype as a cpp template parameter (#16452)

This commit is contained in:
陈一涵
2026-01-08 13:54:33 +08:00
committed by GitHub
parent 41b434a7e6
commit 48b8dcd42e
9 changed files with 91 additions and 28 deletions

View File

@@ -5,6 +5,8 @@ import pathlib
from functools import lru_cache
from typing import TYPE_CHECKING, Any, Callable, List, Tuple, TypeAlias, TypeVar, Union
import torch
if TYPE_CHECKING:
from tvm_ffi import Module
@@ -54,6 +56,14 @@ def make_cpp_args(*args: CPP_TEMPLATE_TYPE) -> CPPArgList:
return "true" if arg else "false"
if isinstance(arg, (int, float)):
return str(arg)
if isinstance(arg, torch.dtype):
if arg == torch.float:
return "float"
if arg == torch.float16:
return "__half"
if arg == torch.bfloat16:
return "nv_bfloat16"
raise TypeError(f"Not implement this arg wrapper yet: {arg}")
raise TypeError(f"Unsupported argument type for cpp template: {type(arg)}")
return CPPArgList(_convert(arg) for arg in args)