Skip to content
Merged
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
8 changes: 3 additions & 5 deletions csrc/contiguity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,8 +441,7 @@ NonDivisibleSplitDependencies::NonDivisibleSplitDependencies(
for (auto transform : transforms) {
auto inp_ids = ir_utils::filterByType<IterDomain>(transform->inputs());
for (auto inp_id : inp_ids) {
if (std::find(alloc_domain.begin(), alloc_domain.end(), inp_id) !=
alloc_domain.end()) {
if (std::ranges::find(alloc_domain, inp_id) != alloc_domain.end()) {
// This generally shouldn't happen as there shouldn't be
// transformations before the allocation ids, but in case for some
// reason we eventually do have cases like that, we should reset the
Expand All @@ -453,7 +452,7 @@ NonDivisibleSplitDependencies::NonDivisibleSplitDependencies(
}

bool inputs_non_divisible =
std::any_of(inp_ids.begin(), inp_ids.end(), [this](IterDomain* inp_id) {
std::ranges::any_of(inp_ids, [this](IterDomain* inp_id) {
return depends_on_non_divisible_split.find(inp_id) !=
depends_on_non_divisible_split.end();
});
Expand Down Expand Up @@ -575,8 +574,7 @@ void ContigIDs::build(const std::vector<IterDomain*>& ids) {
alloc_domain_id->toString());
// Index of merged reductions can always be coalesced, so considering
// reduction as true contiguity.
if (alloc_contiguity.value_or(true) &&
alloc_domain_id->getIterType() != IterType::GatherScatter) {
if (alloc_contiguity.value_or(true)) {
contig_ids_.emplace(alloc_domain_id);
is_contig_alloc_.at(alloc_domain_id) = true;
within_contig_ids_[alloc_domain_id] = std::unordered_set<IterDomain*>();
Expand Down
6 changes: 2 additions & 4 deletions csrc/device_lower/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1815,11 +1815,9 @@ void validateAndConvertIterDomainGrouping(Fusion* fusion) {
// Remember if a grouped ID is found
is_grouped = true;

// Grouping only makes sense for the normal iteration or gather scatter
// type
// Grouping only makes sense for the normal iteration type
NVF_CHECK(
id->getIterType() == IterType::Iteration ||
id->getIterType() == IterType::GatherScatter,
id->getIterType() == IterType::Iteration,
"Invalid use of ParallelType::Group.",
" Grouping of ",
id->getIterType(),
Expand Down
10 changes: 0 additions & 10 deletions csrc/fusion_segmenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1474,16 +1474,6 @@ void eraseInputDistinctRootDomains(Fusion* fusion) {
compare_result.dom1_has_unreachable_ids;

if (has_disjoint_loop_logical) {
// NOTE: This is only the case for scatter outputs, for which loop and
// logical are disjoint. Consequently, the loop domain cannot be replayed.
// Since this scatter output is a fusion input to this segment, its loop
// domain is immaterial now and we can skip replaying it.
NVF_ERROR(
std::ranges::any_of(
tv->getLogicalDomain(),
[](IterDomain* id) { return id->isGatherScatter(); }),
"Disjoint loop and logical are only permitted for scatter outputs, ",
tv->domain()->toString(0, false));
NVF_ERROR(
!isSharded(tv),
"Sharding is not permitted when loop domain is disjoint from logical "
Expand Down
13 changes: 5 additions & 8 deletions csrc/id_model/contiguity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ ContigIDGroups::ContigIDGroups(

auto alloc_contiguity = alloc_contiguity_.at(index_domain_i);

if (alloc_contiguity &&
index_domain->getIterType() != IterType::GatherScatter) {
if (alloc_contiguity) {
contig_ids_.emplace(graph_.toGroup(index_domain));
}
}
Expand All @@ -64,15 +63,15 @@ ContigIDGroups::ContigIDGroups(
const auto outputs = direction == Direction::Forward
? graph_.outputGroups(eg)
: graph_.inputGroups(eg);
if (std::any_of(inputs.begin(), inputs.end(), [&](const ValGroup& inp) {
if (std::ranges::any_of(inputs, [&](const ValGroup& inp) {
return resize_deps_.count(inp) > 0;
})) {
for (const auto& out : outputs) {
resize_deps_.insert(out);
}
}

if (std::any_of(inputs.begin(), inputs.end(), [&](const ValGroup& inp) {
if (std::ranges::any_of(inputs, [&](const ValGroup& inp) {
return non_divisible_deps_.count(inp) > 0;
})) {
for (const auto& out : outputs) {
Expand Down Expand Up @@ -169,10 +168,8 @@ void ContigIDGroups::handle(Split* split, Direction direction) {
if (direction == Direction::Forward) {
const auto& divisible_splits = GpuLower::current()->divisibleSplitSet();
const ExprGroup& split_group = graph_.toGroup(split);
bool divisible = std::any_of(
divisible_splits.begin(),
divisible_splits.end(),
[&](Split* divisible_split) -> bool {
bool divisible = std::ranges::any_of(
divisible_splits, [&](Split* divisible_split) -> bool {
return split_group->has(divisible_split);
});
if (!divisible) {
Expand Down
12 changes: 2 additions & 10 deletions csrc/ir/internal_base_nodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,12 +398,6 @@ IterDomain* IterDomain::merge(
inner->getIterType() == IterType::Iteration)) {
iter_type = IterType::Iteration;
}

if ((outer->isBroadcast() || inner->isBroadcast()) &&
(outer->getIterType() == IterType::GatherScatter ||
inner->getIterType() == IterType::GatherScatter)) {
iter_type = IterType::GatherScatter;
}
}

Val* expanded_extent = nullptr;
Expand Down Expand Up @@ -700,10 +694,8 @@ void IterDomain::parallelize(ParallelType t) {

if (t == ParallelType::Group) {
NVF_CHECK(
getIterType() == IterType::Iteration ||
getIterType() == IterType::GatherScatter,
"Grouping IterDomain of non Iteration / GatherScatter type is not "
"allowed. ",
getIterType() == IterType::Iteration,
"Grouping IterDomain of non Iteration type is not allowed. ",
getIterType());
}

Expand Down
4 changes: 0 additions & 4 deletions csrc/ir/internal_base_nodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,6 @@ class NVF_API IterDomain : public Val {
return getIterType() == IterType::Symbolic;
}

bool isGatherScatter() const {
return getIterType() == IterType::GatherScatter;
}

bool isStride() const {
return getIterType() == IterType::Stride;
}
Expand Down
16 changes: 2 additions & 14 deletions csrc/ops/indexing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,7 @@ TensorView* gather(TensorView* inp, int64_t dim, TensorView* index) {
std::vector<IterDomain*> out_domain;
out_domain.reserve(idx_domain.size());
for (auto idx_domain_ptr : idx_domain) {
out_domain.push_back(
IterDomainBuilder(idx_domain_ptr)
.iter_type(
idx_domain_ptr->getIterType() == IterType::Iteration
? IterType::GatherScatter
: idx_domain_ptr->getIterType())
.build());
out_domain.push_back(idx_domain_ptr->cloneWithoutRFactor());
}

TensorView* out_tensor = IrBuilder::create<TensorView>(
Expand Down Expand Up @@ -254,13 +248,7 @@ TensorView* scatter(
// The shape of output tensor is same as self tensor.
std::vector<IterDomain*> out_logical;
for (const auto i : arange(self_dom.size())) {
out_logical.push_back(
IterDomainBuilder(self_dom[i])
.iter_type(
self_dom[i]->getIterType() == IterType::Iteration
? IterType::GatherScatter
: self_dom[i]->getIterType())
.build());
out_logical.push_back(self_dom[i]->cloneWithoutRFactor());
}

// Create the loop domain based on the logical domain of the index
Expand Down
9 changes: 3 additions & 6 deletions csrc/ops/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ IterType promoteIterType(IterType type1, IterType type2) {
// Iteration: Default
// Reduction: Should not appear here
// Broadcast: Propagated only if type1 and type2 are Broadcast
// GatherScatter: Converted to Iteration
// Stride: Shold not appear here
// VectorComponent: Converted to Iteration

Expand All @@ -164,11 +163,11 @@ IterType promoteIterType(IterType type1, IterType type2) {
"Invalid IterType: ",
type2);

// Do not propagate GatherScatter and VectorComponent
if (type1 == IterType::VectorComponent || type1 == IterType::GatherScatter) {
// Do not propagate VectorComponent
if (type1 == IterType::VectorComponent) {
type1 = IterType::Iteration;
}
if (type2 == IterType::VectorComponent || type2 == IterType::GatherScatter) {
if (type2 == IterType::VectorComponent) {
type2 = IterType::Iteration;
}

Expand Down Expand Up @@ -408,8 +407,6 @@ IterDomain* newOutputIterDomain(
extent_val = promoteSize(extent_val, id->extent());
if (iter_type.has_value()) {
iter_type = promoteIterType(iter_type.value(), id->getIterType());
} else if (id->isGatherScatter()) {
iter_type = IterType::Iteration;
} else {
iter_type = id->getIterType();
}
Expand Down
3 changes: 2 additions & 1 deletion csrc/runtime/fusion_executor_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// clang-format on
#pragma once

#include <cstdint>
#include <mutex>
#include <type_traits>
#include <unordered_map>
Expand All @@ -28,7 +29,7 @@ class ExactLogicalDomainMap;
class Fusion;
class FusionKernelRuntime;
class KernelArgumentHolder;
enum class PrimDataType;
enum class PrimDataType : std::uint8_t;

//! [ Note -- Post-definition cache implementation ]
//!
Expand Down
3 changes: 2 additions & 1 deletion csrc/runtime/fusion_kernel_runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// clang-format on
#pragma once

#include <cstdint>
#include <mutex>
#include <vector>

Expand All @@ -23,7 +24,7 @@
namespace nvfuser {

class HeuristicParamsList;
enum class PrimDataType;
enum class PrimDataType : std::uint8_t;
class Fusion;
class Val;

Expand Down
33 changes: 14 additions & 19 deletions csrc/type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,26 @@ StructType globalTensorMetaData(

StructType::FieldInfo logical_size_field;
logical_size_field.name = "logical_size";
logical_size_field.type = std::make_shared<DataType>(
ArrayType{std::make_shared<DataType>(DataType::Index), dim});
logical_size_field.type = std::make_shared<DataType>(ArrayType{
.type = std::make_shared<DataType>(DataType::Index), .size = dim});
logical_size_field.used_in_kernel = true;

StructType::FieldInfo logical_stride_field;
logical_stride_field.name = "logical_stride";
logical_stride_field.type = std::make_shared<DataType>(
ArrayType{std::make_shared<DataType>(DataType::Index), dim});
logical_stride_field.type = std::make_shared<DataType>(ArrayType{
.type = std::make_shared<DataType>(DataType::Index), .size = dim});
logical_stride_field.used_in_kernel = false;

StructType::FieldInfo alloc_size_field;
alloc_size_field.name = "alloc_size";
alloc_size_field.type = std::make_shared<DataType>(
ArrayType{std::make_shared<DataType>(DataType::Index), alloc_dim});
alloc_size_field.type = std::make_shared<DataType>(ArrayType{
.type = std::make_shared<DataType>(DataType::Index), .size = alloc_dim});
alloc_size_field.used_in_kernel = false;

StructType::FieldInfo alloc_stride_field;
alloc_stride_field.name = "alloc_stride";
alloc_stride_field.type = std::make_shared<DataType>(
ArrayType{std::make_shared<DataType>(DataType::Index), alloc_dim});
alloc_stride_field.type = std::make_shared<DataType>(ArrayType{
.type = std::make_shared<DataType>(DataType::Index), .size = alloc_dim});
alloc_stride_field.used_in_kernel = true;

return StructType::make<TensorMetaData>(
Expand Down Expand Up @@ -884,8 +884,6 @@ static const char* iter_type2string(IterType t) {
return "b";
case IterType::Stride:
return "s";
case IterType::GatherScatter:
return "n";
case IterType::VectorComponent:
return "v";
case IterType::Symbolic:
Expand Down Expand Up @@ -1393,7 +1391,6 @@ at::ScalarType data_type_to_aten(const DataType& data_type) {
return at::ScalarType::Float8_e8m0fnu;
#if NVF_TORCH_VERSION_NO_LESS(2, 8, 0)
case DataType::Float4_e2m1fn_x2:
return at::ScalarType::Float4_e2m1fn_x2;
case DataType::Float4_e2m1fn:
return at::ScalarType::Float4_e2m1fn_x2;
#endif
Expand Down Expand Up @@ -1434,9 +1431,7 @@ at::ScalarType data_type_to_aten(const DataType& data_type) {
// there is no direct mapping, we use some data type as a proxy.
// If there is a data type with the same size, we use that
const int64_t size_bit = dataTypeSizeBit(data_type);
if (size_bit == 8) {
return at::ScalarType::Byte;
} else if (size_bit == 16) {
if (size_bit == 16) {
return at::ScalarType::UInt16;
} else if (size_bit == 32) {
return at::ScalarType::UInt32;
Expand Down Expand Up @@ -1465,7 +1460,7 @@ at::ScalarType data_type_to_aten(

AdjustLastDim getLastDimAdjustment(const DataType& dtype) {
if (dtype == DataType::Index) {
return AdjustLastDim{1, 1};
return AdjustLastDim{.numerator = 1, .denominator = 1};
}
const int64_t scalar_type_bit =
(int64_t)c10::elementSize(data_type_to_aten(dtype)) * 8;
Expand All @@ -1475,7 +1470,8 @@ AdjustLastDim getLastDimAdjustment(const DataType& dtype) {
// at_size * 4 / 3 is the size of the last dimension of the corresponding
// TensorView.
const int64_t gcd = std::gcd(scalar_type_bit, dtype_bit);
return AdjustLastDim{scalar_type_bit / gcd, dtype_bit / gcd};
return AdjustLastDim{
.numerator = scalar_type_bit / gcd, .denominator = dtype_bit / gcd};
}

std::ostream& operator<<(std::ostream& out, const ValType vtype) {
Expand Down Expand Up @@ -1823,9 +1819,8 @@ int max_digits10(DataType dtype) {
} else if (dtype == DataType::Float8_e4m3fn) {
return 3;
} else if (
dtype == DataType::Float8_e5m2 || dtype == DataType::Float8_e8m0fnu) {
return 2;
} else if (dtype == DataType::Float4_e2m1fn) {
dtype == DataType::Float8_e5m2 || dtype == DataType::Float8_e8m0fnu ||
dtype == DataType::Float4_e2m1fn) {
return 2;
} else {
NVF_CHECK(
Expand Down
Loading
Loading