Skip to content

[FEA]: Require ct.count for statistical kernels #36

@ZhangZhiPku

Description

@ZhangZhiPku

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

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions