Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
d87e6d7
Initial introduction of RaggedIterDomain
naoyam Dec 12, 2025
77c6a07
Merge remote-tracking branch 'origin/main' into raggediterdomain_init…
naoyam Dec 12, 2025
f16fc4d
cleanup
naoyam Dec 12, 2025
23d55f1
fix
naoyam Dec 12, 2025
8392332
fix
naoyam Dec 12, 2025
787dfec
unit test
naoyam Dec 12, 2025
a0b40a3
cleanup
naoyam Dec 12, 2025
dbdd917
Fix IterVisitor
naoyam Dec 12, 2025
cdbd81e
cleanup
naoyam Dec 12, 2025
d4c8d7f
WIP: partition
naoyam Dec 12, 2025
9575a13
Partition expr
naoyam Dec 13, 2025
a054ae0
TensorView::partition
naoyam Dec 13, 2025
69dbe0f
cleanup
naoyam Dec 13, 2025
db3b359
Merge remote-tracking branch 'origin/main' into raggediterdomain_part…
naoyam Dec 13, 2025
2348dde
cleanup
naoyam Dec 13, 2025
7090b9c
WIP: asNested
naoyam Dec 13, 2025
b07e285
cleanup
naoyam Dec 13, 2025
a2c504b
asNested
naoyam Dec 15, 2025
b1d8cf4
warpdim
naoyam Dec 15, 2025
201c148
Make sure RaggedIterDomain is propagated to output tensors
naoyam Dec 17, 2025
9e0b161
Extend ops to be aware with RaggediterDomain
naoyam Dec 17, 2025
60a2dd5
RaggedIterDomain and reduction
naoyam Dec 17, 2025
566d63d
WIP
naoyam Dec 18, 2025
144b206
WIP
naoyam Dec 18, 2025
e2efe75
cleanup
naoyam Dec 18, 2025
0b68d6b
cleanup
naoyam Dec 18, 2025
8a73bb2
cleanup
naoyam Dec 18, 2025
550e0c5
Merge branch 'raggediterdomain_partition' into raggediterdomain-asnested
naoyam Dec 18, 2025
82bd85e
Merge remote-tracking branch 'origin/main' into raggediterdomain-asne…
naoyam Dec 18, 2025
f215f07
Use extents as a parameter
naoyam Dec 18, 2025
5b99432
Merge remote-tracking branch 'origin/main' into raggediterdomain-asne…
naoyam Dec 18, 2025
2dd9287
Merge branch 'raggediterdomain-asnested' into raggediterdomain_clone
naoyam Dec 18, 2025
c3aebec
combine
naoyam Dec 19, 2025
a22bb1f
Add tests
naoyam Dec 19, 2025
f521c38
WIP
naoyam Dec 19, 2025
8d0d9cb
don't hold component ID in RaggedIterDomain
naoyam Dec 19, 2025
67aac1b
Add design doc
naoyam Dec 19, 2025
3a80926
license
naoyam Dec 19, 2025
f75ecb6
Merge branch 'main' into raggediterdomain-asnested
naoyam Jan 7, 2026
8aa854e
feedback
naoyam Jan 7, 2026
72ae14f
fix
naoyam Jan 7, 2026
85d48df
Merge branch 'raggediterdomain-asnested' into raggediterdomain_clone
naoyam Jan 7, 2026
5f86d9c
Merge branch 'main' into raggediterdomain_clone
naoyam Jan 7, 2026
bf5b627
Merge remote-tracking branch 'origin/main' into raggediterdomain_clone
naoyam Jan 7, 2026
bec4c09
Merge remote-tracking branch 'origin/main' into raggediterdomain_clone
naoyam Jan 7, 2026
4d8acab
cleanup
naoyam Jan 9, 2026
3b082ba
cleanup
naoyam Jan 9, 2026
72dbc41
Merge branch 'raggediterdomain_clone' into ragged_combine
naoyam Jan 13, 2026
5002407
expand doc
naoyam Jan 13, 2026
be0e2ea
cleanup
naoyam Jan 13, 2026
05a6201
Merge remote-tracking branch 'origin/main' into ragged_combine
naoyam Jan 16, 2026
d2b5384
format
naoyam Jan 16, 2026
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
1 change: 1 addition & 0 deletions csrc/dispatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ class Val;
f(ScanOp); \
f(Merge); \
f(Partition); \
f(Combine); \
f(Swizzle); \
f(Swizzle2D); \
f(Resize); \
Expand Down
101 changes: 101 additions & 0 deletions csrc/ir/internal_base_nodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,107 @@ std::pair<IterDomain*, RaggedIterDomain*> RaggedIterDomain::partition(
return {component_id, ragged_id};
}

IterDomain* RaggedIterDomain::combine(
IterDomain* component,
RaggedIterDomain* ragged) {
NVF_ERROR(component != nullptr, "combine: component IterDomain is null");
NVF_ERROR(ragged != nullptr, "combine: ragged IterDomain is null");

NVF_ERROR(
!component->isA<RaggedIterDomain>(),
"combine: component must be a regular IterDomain, got RaggedIterDomain: ",
component->toString());

// Validate that component and ragged have compatible properties
NVF_ERROR_EQ(
component->getParallelType(),
ParallelType::Serial,
"Combining parallelized IterDomain not supported: ",
component->toString());

NVF_ERROR_EQ(
ragged->getParallelType(),
ParallelType::Serial,
"Combining parallelized RaggedIterDomain not supported: ",
ragged->toString());

NVF_ERROR_EQ(
component->getIterType(),
IterType::Iteration,
"combine: only IterType::Iteration is supported for component, got ",
component->getIterType(),
" for IterDomain: ",
component->toString());

NVF_ERROR_EQ(
ragged->getIterType(),
IterType::Iteration,
"combine: only IterType::Iteration is supported for ragged, got ",
ragged->getIterType(),
" for RaggedIterDomain: ",
ragged->toString());

// Validate component-ragged pairing when Partition definition is available
// (Option 3 of doc/dev/ragged_iter_domain_combine_design_doc.md).
// Only validate when the RaggedIterDomain has a direct Partition definition.
// After propagation (e.g., set() operations), the definition may be nullptr,
// in which case we trust the user to provide the correct component.
if (ragged->definition() != nullptr &&
ragged->definition()->isA<Partition>()) {
auto* partition = ragged->definition()->as<Partition>();
IterDomain* expected_component = partition->component();

NVF_ERROR(
component == expected_component,
"combine: component mismatch. The provided component does not match ",
"the component from the Partition that created this "
"RaggedIterDomain.\n",
" Provided component: ",
component->toString(),
"\n",
" Expected component: ",
expected_component->toString());
}
// If no Partition definition (after set, in segmented fusion, or external
// input), trust the user and proceed without validation

// The combined extent is the sum of all extents in the ragged dimension
// For a 1D extents tensor [e0, e1, ..., en-1], the total is sum(extents)
TensorView* extents_tv = ragged->extents();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
TensorView* extents_tv = ragged->extents();
TensorView* extents = ragged->extents();

The type already says it. Also, in the context of RaggedIterDomain, extents has to be a TensorView.

NVF_ERROR(extents_tv != nullptr, "combine: ragged extents tensor is null");

// It is still assumed the extents tensor is just 1D
NVF_ERROR_EQ(
std::ranges::distance(
extents_tv->getLogicalDomain() | TensorDomain::kNoReductions),
1,
"Unexpected rank of extent tensor: ",
extents_tv->toString());

auto container = component->container();
auto zero = container->zeroVal(DataType::Index);

// Create a symbolic extent for the combined IterDomain
// This represents the sum of all ragged extents, i.e.,
// sum(extents_tv, {0}). We could use the sum output as the extent
// but we would need to extract the scalar value out of the 0-dim
// tensor. For now, we leave it as a symbolic Val.
Val* combined_extent =
IrBuilder::createInContainer<Val>(container, DataType::Index);

// Create the combined IterDomain with the symbolic extent
IterDomain* combined_id = IterDomainBuilder(zero, combined_extent)
.parallel_type(ParallelType::Serial)
.iter_type(IterType::Iteration)
.build();

// Create the Combine expression linking component + ragged -> combined
IrBuilder::createInContainer<Combine>(
container, combined_id, component, ragged);

return combined_id;
}

TensorDomain::TensorDomain(
IrBuilderPasskey passkey,
std::vector<IterDomain*> logical_domain,
Expand Down
16 changes: 16 additions & 0 deletions csrc/ir/internal_base_nodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,22 @@ class NVF_API RaggedIterDomain : public IterDomain {
IterDomain* in,
TensorView* extents);

//! Combine a component IterDomain with a RaggedIterDomain to flatten
//! This is the inverse of partition, creating a regular IterDomain
//!
//! \param component Component IterDomain (extent = num_components)
//! \param ragged RaggedIterDomain with variable extents per component
//! \return Regular IterDomain with extent = sum of all component extents
//!
//! This operation flattens the ragged structure back into a single dimension.
//! Example: component extent=3, ragged extents=[127, 0, 198]
//! -> output extent = 325 (= 127 + 0 + 198)
//!
//! Note: We use "combine" instead of "merge" to differentiate from the
//! regular IterDomain::merge operation which only works with regular
//! IterDomains.
static IterDomain* combine(IterDomain* component, RaggedIterDomain* ragged);

//! Override cloneWithoutRFactor to preserve RaggedIterDomain type
IterDomain* cloneWithoutRFactor(bool map_with_original = false) override;

Expand Down
27 changes: 27 additions & 0 deletions csrc/ir/internal_nodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2708,6 +2708,33 @@ std::string Partition::toInlineString(int indent_size) const {

NVFUSER_DEFINE_CLONE_AND_CREATE(Partition)

Combine::Combine(
IrBuilderPasskey passkey,
IterDomain* out,
IterDomain* component,
RaggedIterDomain* ragged)
: Expr(passkey) {
addOutput(out);
addInput(component);
addInput(ragged);
}

std::string Combine::toString(int indent_size) const {
std::stringstream ss;
ss << "Combine: ";
ss << "component: " << component()->toString();
ss << " + ragged: " << ragged()->toString();
ss << " -> " << out()->toString();
ss << "\n";
return ss.str();
}

std::string Combine::toInlineString(int indent_size) const {
NVF_CHECK(false, "Combine can not be printed inline");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not? toString seems to be one line.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I actually am not quite sure why, but our convention is that inline printing seems to be only for scalar values. For example, Split::toInlineString isn't supported either. It isn't just whether it can be printed in a single line. It's more like if it can be recursively called.

}

NVFUSER_DEFINE_CLONE_AND_CREATE(Combine)

Swizzle::Swizzle(
IrBuilderPasskey passkey,
IterDomain* out_x,
Expand Down
38 changes: 38 additions & 0 deletions csrc/ir/internal_nodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -1910,6 +1910,44 @@ class NVF_API Partition : public Expr {
}
};

//! Combine a component IterDomain with a RaggedIterDomain to flatten
//! This is the inverse of Partition, merging component and ragged dimensions
//! into a single regular IterDomain
class NVF_API Combine : public Expr {
public:
using Expr::Expr;

Combine(
IrBuilderPasskey,
IterDomain* out,
IterDomain* component,
RaggedIterDomain* ragged);

NVFUSER_DECLARE_CLONE_AND_CREATE

const char* getOpString() const override {
return "Combine";
}

std::string toString(int indent_size = 0) const override;
std::string toInlineString(int indent_size = 0) const override;

//! Output IterDomain (combined/flattened dimension)
IterDomain* out() const {
return output(0)->as<IterDomain>();
}

//! Component dimension input (extent = num_components)
IterDomain* component() const {
return input(0)->as<IterDomain>();
}

//! Ragged dimension input (variable extents per component)
RaggedIterDomain* ragged() const {
return input(1)->as<RaggedIterDomain>();
}
};

class Swizzle : public Expr {
public:
using Expr::Expr;
Expand Down
Loading