Skip to content

Commit

Permalink
[pauli word] Rework the implementation from front to back.
Browse files Browse the repository at this point in the history
This changes the pauli_word implementation to be compatible
with std::string, use the core character literal support, which
changes the code generation and provides a potential way to
perform optimizations on quake.exp_pauli ops.

This PR also does a complete rewrite of the GKE code. The
rewrite fuses the C++ host entry point argument processing
with the .argsCreator support function. It removes several
special cases that are no longer germane as the surface of
supported C++ argument types has expanded quite a bit. It
is fully backwards compatible with the old argument packing
pointer-free format.  The .argsCreator function remains
highly coupled with the Python implementation and launcher.
C++ should use the streamlined launcher as it has greater
flexibility.

Fixes tests and updates them to use the hybrid launcher where
appropriate. Add new tests.

Signed-off-by: Eric Schweitz <eschweitz@nvidia.com>
  • Loading branch information
schweitzpgi committed Oct 31, 2024
1 parent c7e1f8d commit 3513b78
Show file tree
Hide file tree
Showing 20 changed files with 2,029 additions and 1,468 deletions.
3 changes: 3 additions & 0 deletions include/cudaq/Optimizer/Builder/Factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,9 @@ bool hasSRet(mlir::func::FuncOp funcOp);
mlir::FunctionType toHostSideFuncType(mlir::FunctionType funcTy,
bool addThisPtr, mlir::ModuleOp module);

/// Convert device type, \p ty, to host side type.
mlir::Type convertToHostSideType(mlir::Type ty);

// Return `true` if the given type corresponds to a standard vector type
// according to our convention.
// The convention is a `ptr<struct<ptr<T>, ptr<T>, ptr<T>>>`.
Expand Down
5 changes: 5 additions & 0 deletions include/cudaq/Optimizer/Dialect/CC/CCTypes.td
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,12 @@ def cc_StructType : CCType<"Struct", "struct",
];

let extraClassDeclaration = [{
// O(1)
bool isEmpty() const { return getMembers().empty(); }

// O(n)
std::size_t getNumMembers() const { return getMembers().size(); }

Type getMember(unsigned position) { return getMembers()[position]; }
}];
}
Expand Down
15 changes: 5 additions & 10 deletions lib/Optimizer/Builder/Factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,19 +342,14 @@ Type factory::getSRetElementType(FunctionType funcTy) {
return funcTy.getResult(0);
}

static Type convertToHostSideType(Type ty) {
Type factory::convertToHostSideType(Type ty) {
if (auto memrefTy = dyn_cast<cc::StdvecType>(ty))
return convertToHostSideType(
factory::stlVectorType(memrefTy.getElementType()));
return factory::stlVectorType(
convertToHostSideType(memrefTy.getElementType()));
if (isa<cc::IndirectCallableType>(ty))
return cc::PointerType::get(IntegerType::get(ty.getContext(), 8));
if (auto memrefTy = dyn_cast<cc::CharspanType>(ty)) {
// `pauli_word` is an object with a std::vector in the header files at
// present. This data type *must* be updated if it becomes a std::string
// once again.
return convertToHostSideType(
factory::stlVectorType(IntegerType::get(ty.getContext(), 8)));
}
if (isa<cc::CharspanType>(ty))
return factory::stlStringType(ty.getContext());
auto *ctx = ty.getContext();
if (auto structTy = dyn_cast<cc::StructType>(ty)) {
SmallVector<Type> newMembers;
Expand Down
2 changes: 1 addition & 1 deletion lib/Optimizer/Dialect/CC/CCTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ Type cc::SpanLikeType::getElementType() const {
}

bool isDynamicType(Type ty) {
if (isa<StdvecType>(ty))
if (isa<SpanLikeType>(ty))
return true;
if (auto strTy = dyn_cast<StructType>(ty)) {
for (auto memTy : strTy.getMembers())
Expand Down
5 changes: 4 additions & 1 deletion lib/Optimizer/Transforms/DecompositionPatterns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,14 +362,17 @@ struct ExpPauliDecomposition : public OpRewritePattern<quake::ExpPauliOp> {
auto strAttr = cast<mlir::StringAttr>(attr.value());
optPauliWordStr = strAttr.getValue();
}
} else if (auto lit = addrOp.getDefiningOp<
cudaq::cc::CreateStringLiteralOp>()) {
optPauliWordStr = lit.getStringLiteral();
}
}
}
}

// Assert that we have a constant known pauli word
if (!optPauliWordStr.has_value())
return failure();
return expPauliOp.emitOpError("cannot determine pauli word string");

auto pauliWordStr = optPauliWordStr.value();

Expand Down
Loading

0 comments on commit 3513b78

Please sign in to comment.