Coverage for src/flag_gems/runtime/backend/_mthreads/ops/ones_like.py: 0%
18 statements
« prev ^ index » next coverage.py v7.6.9, created at 2026-03-24 15:40 +0800
« prev ^ index » next coverage.py v7.6.9, created at 2026-03-24 15:40 +0800
1import logging
3import torch
4import triton
6from flag_gems.runtime import torch_device_fn
8from .ones import ones_kernel
10logger = logging.getLogger(
11 f'flag_gems.runtime.backend._mthreads.ops.{__name__.split(".")[-1]}'
12)
15def ones_like(
16 x, *, dtype=None, layout=None, device=None, pin_memory=None, memory_format=None
17):
18 logger.debug("GEMS_MTHREADS ONES_LIKE")
19 if device is None:
20 device = x.device
21 if dtype is None:
22 dtype = x.dtype
23 out = torch.empty_like(x, device=device, dtype=dtype)
24 N = x.numel()
25 grid_fn = lambda meta: (triton.cdiv(N, meta["BLOCK_SIZE"]),)
26 with torch_device_fn.device(x.device):
27 ones_kernel[grid_fn](out, N, BLOCK_SIZE=1024)
28 return out