cutile-python icon indicating copy to clipboard operation
cutile-python copied to clipboard

[FEA]: Require ct.count for statistical kernels

Open ZhangZhiPku opened this issue 1 month ago • 0 comments

Is this a new feature, an improvement, or a change to existing functionality?

New Feature

How would you describe the priority of this feature request?

low

Please provide a clear description of problem this feature solves

require ct.count function in some statistical method, example:

import torch
import cuda.tile as ct

@ct.function
def tile_histogram(
    data: ct.Tile, bins: ct.Tile,
    min: float, bin_size: float, num_bins: int
) -> ct.Tile:
    data = data - min
    data = ct.floor(data / bin_size)
    data = ct.clip(data, 0, num_bins)
    # ct.count(data, bins):
    # goes through each value v in data
    # interprets v as a bin index
    # increments bins[v] by 1
    # returns the updated bins
    bins = ct.count(data, bins)
    return bins
    
@ct.kernel
def device_histogram(
    x: ct.Array, y:ct.Array, tile_size: ct.Constant, 
    min: float, bin_size: float, num_bins: int
):
    block_idx = ct.bid(0)
    loop = x.shape[0] // tile_size
    
    bins = ct.zeros(shape=(tile_size, ), dtype=ct.int32)
    for idx in range(loop):
        tile = ct.load(x, (idx, ), (tile_size, 0))
        bins = tile_histogram(tile, bins, min, bin_size, num_bins)
    
    ct.atomic_add(y, (0, ), bins)

Feature Description

provide a tile op: count

ct.count(data, bins):

  1. goes through each value v in data
  2. interprets v as a bin index
  3. increments bins[v] by 1
  4. returns the updated bins

by the way, ct.clip is missing too.

Describe your ideal solution

provide a tile op: count

ct.count(data, bins):

  1. goes through each value v in data
  2. interprets v as a bin index
  3. increments bins[v] by 1
  4. returns the updated bins

by the way, ct.clip is missing too.

Describe any alternatives you have considered

No response

Additional context

No response

Contributing Guidelines

  • [x] I agree to follow cuTile Python's contributing guidelines
  • [x] I have searched the open feature requests and have found no duplicates for this feature request

ZhangZhiPku avatar Dec 19 '25 07:12 ZhangZhiPku