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-23 02:03 +0800

1import logging 

2 

3import torch 

4import triton 

5 

6from flag_gems.runtime import torch_device_fn 

7 

8from .ones import ones_kernel 

9 

10logger = logging.getLogger( 

11 f'flag_gems.runtime.backend._mthreads.ops.{__name__.split(".")[-1]}' 

12) 

13 

14 

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