onnx-mlir icon indicating copy to clipboard operation
onnx-mlir copied to clipboard

Last use of GetRef is associated with Strings

Open AlexandreEichenberger opened this issue 1 year ago • 1 comments

Here is the last use of KrnlGetRefOp (created via the Krill Builder getRef().

ONNXToKrnl...CategoryMapper.cpp

Value loadElement(Value memref, ValueRange loopInd, Type elementType,
      int64_t rank, KrnlBuilder &createKrnl) const {
    Value inputElem;
    TypeSwitch<Type>(elementType)
        .Case<IntegerType>(
            [&](IntegerType) { inputElem = createKrnl.load(memref, loopInd); })
        .Case<krnl::StringType>([&](krnl::StringType stringType) {
          MathBuilder createMath(createKrnl);
          Value zero = createMath.constant(
              createMath.getBuilder().getIntegerType(64), 0);
          ArrayRef<int64_t> shape =
              memref.getType().cast<ShapedType>().getShape();
          SmallVector<int64_t, 4> newShape;
          for (uint64_t i = 0; i < shape.size(); i++)
            newShape.emplace_back(
                (shape[i] == ShapedType::kDynamic) ? 1 : shape[i]);
          auto memRefType = MemRefType::get(
              newShape, krnl::StringType::get(elementType.getContext()));


          // Sole use of krnl.getRef.
          Value stringMemRef = createKrnl.getRef(memRefType, memref, zero);


          inputElem = createKrnl.load(stringMemRef, loopInd);
        })
        .Default([&](Type type) {
          llvm::errs() << "type: " << type << "\n";
          llvm_unreachable("Unexpected elementType");
        });

    return inputElem;
  }

Anyone familiar with string handling know if there is an other way than using getRefs?

@chentong319 @tungld @imaihal @negiyas ?

Context: this op is creating some migration issue for @philass . We used to need the getRef a lot for our own handling of buffer management, but this was ripped out once we started using the mlir approach per Tong's suggestion.

AlexandreEichenberger avatar Nov 08 '23 18:11 AlexandreEichenberger