Coverage for src/flag_gems/runtime/backend/_metax/ops/ones_like.py: 0%

18 statements  

« prev     ^ index     » next       coverage.py v7.6.9, created at 2026-03-10 02:30 +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("flag_gems." + __name__) 

11 

12 

13def ones_like( 

14 x, *, dtype=None, layout=None, device=None, pin_memory=None, memory_format=None 

15): 

16 logger.debug("METAX GEMS ONES_LIKE") 

17 if device is None: 

18 device = x.device 

19 if dtype is None: 

20 dtype = x.dtype 

21 out = torch.empty_like(x, device=device, dtype=dtype) 

22 N = x.numel() 

23 grid_fn = lambda meta: (triton.cdiv(N, meta["BLOCK_SIZE"]),) 

24 with torch_device_fn.device(x.device): 

25 ones_kernel[grid_fn](out, N, BLOCK_SIZE=1024) 

26 return out