How to create a PadNode

/// Creates a PadNode with the given \p name and output type \p outTy which
/// pads the given \p input with the explicit pads \p pads according to the
/// padding mode \p mode and with the given value \p value. The padding mode
/// \p mode is one of enumeration values from \ref PaddingMode. For an input
/// with N dimensions (rank N) the \p pads must be a vector with 2*N values
/// with the following format:
/// pads = [pad_before(D1), pad_before(D2), …, pad_before(DN),
/// pad_after (D1), pad_after (D2), …, pad_after (DN)].
/// The mode PaddingMode::CONSTANT pads the input using the constant value
/// \p value and currently is the only mode supported.

  PadNode *createPad(llvm::StringRef name, NodeValue input, TypeRef outTy,
                     unsigned_t mode, llvm::ArrayRef<int> pads, float value);

I am trying to pad a placeholder node that is of dimensions (NHWC) 16X5X5X1 to 16X5X5X4

I am able to create a PadNode and add it to the graph(I crosschecked it by dumping the DAG), but I am hitting a segmentation fault while generating IR.

Am I passing the correct values to /p pads parameter?

                                int pads[] = {0, 0, 0, 0, 0, 0, 0, 3};

                                auto filterOutTy = F->getParent()->uniqueType(ElemKind::FloatTy, filterOutPadDims);
                                auto inputOutTy = F->getParent()->uniqueType(ElemKind::FloatTy, inputOutPadDims);

                                auto *INPUTPAD = F->createPad("pad", nodeValue0, inputOutTy, PaddingMode::CONSTANT, pads, 0.f);

I think it looks reasonable, though I don’t see what inputOutPadDims is. Have you tried running in assert mode, to see if it hits an assertion instead of seg faulting? Or have you tried running in a debugger to see where the seg fault is?

Unhandled node; perhaps the node should have been lowered, or the backend should have specified an IRGen case for this node to a backend-specific Instr.

Hey @jfix ! Thanks for the reply. so I tried compiling with g++ instead of clang, then I hit the above assertion instead of a segfault. :thinking:

I was using a mock backend, and tried to add the padNode in “transformpostlowering” looks like the node should be lowered. Thanks for the Help.

1 Like