Coverage for src/flag_gems/runtime/backend/_tsingmicro/ops/zeros_like.py: 0%
19 statements
« prev ^ index » next coverage.py v7.6.9, created at 2026-06-10 07:09 +0800
« prev ^ index » next coverage.py v7.6.9, created at 2026-06-10 07:09 +0800
1import logging
3import torch
4import triton
6from flag_gems.runtime import torch_device_fn
8from .zeros import zeros_kernel
10TOTAL_CORE_NUM = torch_device_fn.get_device_properties().multi_processor_count
13logger = logging.getLogger("flag_gems").getChild(__name__.lstrip("."))
16def zeros_like(
17 x, *, dtype=None, layout=None, device=None, pin_memory=None, memory_format=None
18):
19 logger.debug("GEMS_TSINGMICRO ZEROS_LIKE")
20 if device is None:
21 device = x.device
22 if dtype is None:
23 dtype = x.dtype
24 out = torch.empty_like(x, device=device, dtype=dtype)
25 N = x.numel()
26 grid_fn = lambda meta: (min(triton.cdiv(N, meta["BLOCK_SIZE"]), TOTAL_CORE_NUM),)
27 with torch_device_fn.device(x.device):
28 zeros_kernel[grid_fn](out, N)
29 return out