Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH Reuse TopK buffers #110

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions sklearn_numba_dpex/common/kernels.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,41 @@ def elementwise_ops(data):


@lru_cache
def make_initialize_to_zeros_kernel(shape, work_group_size, dtype):
def make_fill_kernel(fill_value, shape, work_group_size, dtype):
n_items = math.prod(shape)
global_size = math.ceil(n_items / work_group_size) * work_group_size
zero = dtype(0.0)
fill_value = dtype(fill_value)

@dpex.kernel
def initialize_to_zeros_kernel(data):
def fill_kernel(data):
item_idx = dpex.get_global_id(zero_idx)

if item_idx >= n_items:
return

data[item_idx] = zero
data[item_idx] = fill_value

def initialize_to_zeros(data):
def fill(data):
data = dpt.reshape(data, (-1,))
initialize_to_zeros_kernel[global_size, work_group_size](data)
fill_kernel[global_size, work_group_size](data)

return fill


@lru_cache
def make_range_kernel(n_items, work_group_size):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe range => arange to match the numpy function name?

Otherwise one can get confused with the "range" name from SYCL terminology.

global_size = math.ceil(n_items / work_group_size) * work_group_size

@dpex.kernel
def range_kernel(data):
item_idx = dpex.get_global_id(zero_idx)

if item_idx >= n_items:
return

data[item_idx] = item_idx

return initialize_to_zeros
return range_kernel[global_size, work_group_size]


@lru_cache
Expand Down
Loading