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

[cuda.cooperative] Add inclusive_scan to cuda.cooperative #3162

Open
wants to merge 2 commits 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
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,26 @@
#
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

from cuda.cooperative.experimental.block._block_merge_sort import merge_sort_keys
from cuda.cooperative.experimental.block._block_load_store import load
from cuda.cooperative.experimental.block._block_load_store import store
from cuda.cooperative.experimental.block._block_reduce import reduce
from cuda.cooperative.experimental.block._block_reduce import sum
from cuda.cooperative.experimental.block._block_scan import exclusive_sum
from cuda.cooperative.experimental.block._block_scan import inclusive_sum
from cuda.cooperative.experimental.block._block_merge_sort import merge_sort_keys
from cuda.cooperative.experimental.block._block_radix_sort import radix_sort_keys
from cuda.cooperative.experimental.block._block_radix_sort import (
radix_sort_keys_descending,
)
from cuda.cooperative.experimental.block._block_load_store import load
from cuda.cooperative.experimental.block._block_load_store import store

__all__ = [
"merge_sort_keys",
"load",
"store",
"reduce",
"sum",
"exclusive_sum",
"inclusive_sum",
"merge_sort_keys",
"radix_sort_keys",
"radix_sort_keys_descending",
"load",
"store",
]
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,43 @@ def exclusive_sum(dtype, threads_in_block, items_per_thread, prefix_op=None):
temp_storage_bytes=specialization.get_temp_storage_bytes(),
algorithm=specialization,
)

def inclusive_sum(dtype, threads_in_block, items_per_thread, prefix_op=None):
template = Algorithm(
"BlockScan",
"InclusiveSum",
"block_scan",
["cub/block/block_scan.cuh"],
[TemplateParameter("T"), TemplateParameter("BLOCK_DIM_X")],
[
[
Pointer(numba.uint8),
DependentArray(Dependency("T"), Dependency("ITEMS_PER_THREAD")),
DependentArray(Dependency("T"), Dependency("ITEMS_PER_THREAD")),
DependentOperator(
Dependency("T"), [Dependency("T")], Dependency("PrefixOp")
),
],
[
Pointer(numba.uint8),
DependentArray(Dependency("T"), Dependency("ITEMS_PER_THREAD")),
DependentArray(Dependency("T"), Dependency("ITEMS_PER_THREAD")),
],
],
)
specialization = template.specialize(
{
"T": dtype,
"BLOCK_DIM_X": threads_in_block,
"ITEMS_PER_THREAD": items_per_thread,
"PrefixOp": prefix_op,
}
)
return Invocable(
temp_files=[
make_binary_tempfile(ltoir, ".ltoir")
for ltoir in specialization.get_lto_ir()
],
temp_storage_bytes=specialization.get_temp_storage_bytes(),
algorithm=specialization,
)