Convert Python arguments to C++ template argument strings. Example: make_cpp_args(16, torch.float16) -> ["16", "fp16_t"]
(
*args: MLLM_KERNEL_TEMPLATE_TYPE,
)
| 144 | |
| 145 | |
| 146 | def make_cpp_args( |
| 147 | *args: MLLM_KERNEL_TEMPLATE_TYPE, |
| 148 | ) -> _MLLMKernelTemplateArgListGenerator: |
| 149 | """ |
| 150 | Convert Python arguments to C++ template argument strings. |
| 151 | |
| 152 | Example: |
| 153 | make_cpp_args(16, torch.float16) -> ["16", "fp16_t"] |
| 154 | """ |
| 155 | |
| 156 | def _convert(arg: MLLM_KERNEL_TEMPLATE_TYPE) -> str: |
| 157 | if isinstance(arg, bool): |
| 158 | return "true" if arg else "false" |
| 159 | if isinstance(arg, (int, float)): |
| 160 | return str(arg) |
| 161 | if isinstance(arg, torch.dtype): |
| 162 | return MLLM_KERNEL_TEMPLATE_DTYPE_MAP[arg] |
| 163 | raise TypeError( |
| 164 | f"Unsupported argument type for mllm kernel template: {type(arg)}" |
| 165 | ) |
| 166 | |
| 167 | return _MLLMKernelTemplateArgListGenerator(_convert(arg) for arg in args) |
| 168 | |
| 169 | |
| 170 | # Path constants |
no test coverage detected