Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
f9def57
Add clipping to slice output extent expressions
jacobhinkle Jun 6, 2023
15587bd
Merge branch 'main' into slice_clip
jacobhinkle Jun 6, 2023
2c4af30
Add where to ExpressionEvaluator, handle negative in slice
jacobhinkle Jun 7, 2023
2b4ef9a
Merge remote-tracking branch 'origin/main' into slice_clip
jacobhinkle Sep 11, 2023
5dcf2c8
Support Set,Where, bool ops in NaiveValueMachine
jacobhinkle Sep 11, 2023
7432adb
Silence clang-tidy in test_resize.cpp
jacobhinkle Sep 11, 2023
d96ee2e
Merge remote-tracking branch 'origin/main' into slice_clip
jacobhinkle Sep 14, 2023
9856d93
Add simplifying comparison operators
jacobhinkle Sep 14, 2023
8544650
Clean up normalized slice start/stop expressions
jacobhinkle Sep 14, 2023
eee9ff2
Fix wrong ostream in preseg ir dump
jacobhinkle Sep 14, 2023
efcb203
Remove debug print
jacobhinkle Sep 14, 2023
bf0a4b6
Handle NE in runBinaryOp
jacobhinkle Sep 14, 2023
121a3b9
Fix simplified comparison ops
jacobhinkle Sep 14, 2023
93f3737
Use maybeCastExpr in resize
jacobhinkle Sep 14, 2023
ec315a1
Update doc comment on slice op
jacobhinkle Sep 14, 2023
98f3519
Add input range test
jacobhinkle Sep 14, 2023
b557e38
Reformat test
jacobhinkle Sep 14, 2023
5b06adc
Merge branch 'main' into slice_clip
jacobhinkle Sep 18, 2023
72493d2
Simplify clipping exprs, clean up op
jacobhinkle Sep 26, 2023
553e63d
Merge remote-tracking branch 'origin/main' into slice_clip
jacobhinkle Sep 26, 2023
a9d9e58
Simplify maybe cast exprs
jacobhinkle Sep 26, 2023
90f9616
Remove unneeded change to nodes.cpp
jacobhinkle Sep 26, 2023
ca3a674
Restore check for trivial slice
jacobhinkle Sep 26, 2023
2fd5c23
Use SimplifyingIrBuilder
jacobhinkle Sep 26, 2023
2bc4748
Cast extent first
jacobhinkle Sep 26, 2023
2f714a8
Merge branch 'main' into slice_clip
jacobhinkle Sep 26, 2023
2331989
Adding a reshape example (#944)
naoyam Sep 26, 2023
74eb074
Remove manual refs and add FEC test
jacobhinkle Sep 26, 2023
d7a4b56
Change check for invalid extents to be >= 0
jacobhinkle Sep 26, 2023
87dae14
Use same set of slice cases for all three tests
jacobhinkle Sep 26, 2023
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
10 changes: 8 additions & 2 deletions csrc/ops/alias.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -691,12 +691,18 @@ TensorView* slice(TensorView* inp, const std::vector<Slice>& ranges) {
out_root_id = inp_root_id->cloneWithoutRFactor();
out_rf_id = out_root_id;
} else {
// Clip the start and stop values to the extent of the input
auto clipped_start =
SimplifyingIrBuilder::minExpr(inp_root_id->extent(), range.start);
auto clipped_stop =
SimplifyingIrBuilder::minExpr(inp_root_id->extent(), range.stop);

out_root_id =
IterDomainBuilder(inp_root_id).is_rfactor_domain(true).build();
out_rf_id = IterDomain::resize(
out_root_id,
SimplifyingIrBuilder::negExpr(range.start),
sub(range.stop, inp_root_id->extent()),
SimplifyingIrBuilder::negExpr(clipped_start),
sub(clipped_stop, inp_root_id->extent()),
true);
needs_real_slicing = true;
}
Expand Down
57 changes: 57 additions & 0 deletions test/test_resize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1122,6 +1122,63 @@ TEST_F(NVFuserTest, FusionResizeSlice5_CUDA) {
testValidate(&fusion, cg_outputs, aten_inputs, {t2, t4}, __LINE__, __FILE__);
}

// Slice with end beyond size of input. This should clip to input, not pad.
TEST_F(NVFuserTest, FusionResizeSlice6_CUDA) {
Fusion fusion;
FusionGuard fg(&fusion);

std::vector<int64_t> shape({9});

// concrete shapes to avoid dynamic Fusion
auto tv0 = makeConcreteTensor(shape);
fusion.addInput(tv0);

auto tv1 = slice(tv0, {{fusion.zeroVal(), IrBuilder::create<Int>(11)}});
fusion.addOutput(tv1);

auto options = at::TensorOptions().dtype(at::kFloat).device(at::kCUDA, 0);

auto t0 = at::randn(shape, options);
std::vector<c10::IValue> aten_inputs({t0});

FusionExecutor fe;
fe.compileFusion(&fusion, aten_inputs);
auto cg_outputs = fe.runFusion(aten_inputs);

auto ref = t0.index({at::indexing::Slice(0, 11)});

testValidate(&fusion, cg_outputs, aten_inputs, {ref}, __LINE__, __FILE__);
}

// Slice with start beyond size of input. This should produce zero-size tensor.
TEST_F(NVFuserTest, FusionResizeSlice7_CUDA) {
Fusion fusion;
FusionGuard fg(&fusion);

std::vector<int64_t> shape({9});

// concrete shapes to avoid dynamic Fusion
auto tv0 = makeConcreteTensor(shape);
fusion.addInput(tv0);

auto tv1 =
slice(tv0, {{IrBuilder::create<Int>(11), IrBuilder::create<Int>(13)}});
fusion.addOutput(tv1);

auto options = at::TensorOptions().dtype(at::kFloat).device(at::kCUDA, 0);

auto t0 = at::randn(shape, options);
std::vector<c10::IValue> aten_inputs({t0});

FusionExecutor fe;
fe.compileFusion(&fusion, aten_inputs);
auto cg_outputs = fe.runFusion(aten_inputs);

auto ref = t0.index({at::indexing::Slice(11, 13)});

testValidate(&fusion, cg_outputs, aten_inputs, {ref}, __LINE__, __FILE__);
}

// Auto scheduled version of Slice1
TEST_F(NVFuserTest, FusionResizeSliceScheduler1_CUDA) {
auto fusion_ptr = std::make_unique<Fusion>();
Expand Down