Skip to content

Segfault segmenting in presence of dangling unary Op chain from inputs #585

@jacobhinkle

Description

@jacobhinkle

I encountered a segfault during segmentation when implementing #449 in SegmentCandidateFinder::forwardInputs() at https://github.com/NVIDIA/Fuser/blob/main/csrc/fusion_segmenter.cpp#L3408. That method tries to build a chain of UnaryOps from inputs, and implicitly assumes that there are uses for each output. This is triggered whenever we must segment (i.e. the complete Fusion cannot be scheduled) and there is a chain of UnaryOps from an input that eventually is unused.

TEST_F(NVFuserTest, FusionDanglingUnaryOp_CUDA) {
  auto fusion = std::make_unique<Fusion>();
  FusionGuard fg(fusion.get());

  // Create a segmented Fusion. We call segment_set here to ensure the whole
  // Fusion cannot be scheduled. This triggers segmentation, so that
  // forwardInputs() is called. The structure of this Fusion is not important;
  // it is only important that it must be segmented.
  auto size = IrBuilder::create<Scalar>(5);
  auto tv0 = full({size}, fusion->zeroVal(), DataType::Int);
  auto tv1 = segment_set(tv0);
  fusion->addOutput(tv1);

  // Now take in an input that has a chain of UnaryOp uses that terminates in a
  // Val with no uses. This triggers a segfault in forwardInputs().
  Val* alpha = IrBuilder::create<Scalar>(DataType::Int);
  fusion->addInput(alpha);
  neg(castOp(DataType::Float, alpha));

  FusionExecutorCache executor_cache(std::move(fusion));

  executor_cache.runFusionWithInputs({11});
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions