Skip to content

Commit

Permalink
Merge branch 'main' into ch-vector.result
Browse files Browse the repository at this point in the history
  • Loading branch information
schweitzpgi authored Oct 1, 2024
2 parents e2ef0bb + ba1341c commit 4f243cb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/Frontend/nvqpp/ConvertExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1260,6 +1260,17 @@ bool QuakeBridgeVisitor::VisitCallExpr(clang::CallExpr *x) {
return pushValue(builder.create<cc::ComputePtrOp>(
loc, elePtrTy, vecPtr, ValueRange{negativeOneIndex}));
}
if (funcName.equals("data"))
if (auto memberCall = dyn_cast<clang::CXXMemberCallExpr>(x))
if (memberCall->getImplicitObjectArgument()) {
[[maybe_unused]] auto calleeTy = popType();
assert(isa<FunctionType>(calleeTy));
// data() returns a pointer to a sequence of elements.
auto eleTy = cast<cc::SpanLikeType>(svec.getType()).getElementType();
auto eleArrTy = cc::PointerType::get(cc::ArrayType::get(eleTy));
return pushValue(
builder.create<cc::StdvecDataOp>(loc, eleArrTy, svec));
}

TODO_loc(loc, "unhandled std::vector member function, " + funcName);
}
Expand Down
18 changes: 18 additions & 0 deletions test/AST-Quake/vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,21 @@ struct simple_float_rotation {
}
};

struct difficult_symphony {
auto operator()(std::vector<float> theta) __qpu__ {
float *firstData = theta.data();
cudaq::qvector q(1);
rx(firstData[0], q[0]);
mz(q);
}
};

// clang-format off
// CHECK-LABEL: func.func @__nvqpp__mlirgen__difficult_symphony(
// CHECK-SAME: %[[VAL_0:.*]]: !cc.stdvec<f32>{{.*}}) attributes {"cudaq-entrypoint", "cudaq-kernel"} {
// CHECK: %[[VAL_1:.*]] = cc.stdvec_data %[[VAL_0]] : (!cc.stdvec<f32>) -> !cc.ptr<!cc.array<f32 x ?>>
// clang-format on

int main() {
std::vector<double> vec_args = {0.63};

Expand All @@ -63,6 +78,9 @@ int main() {
printf("Observed: %s, %lu\n", bits.c_str(), count);
}

auto bob_counts = cudaq::sample(difficult_symphony{}, float_args);
bob_counts.dump();

// can get <ZZ...Z> from counts too
printf("Exp: %lf\n", float_counts.expectation());
return 0;
Expand Down

0 comments on commit 4f243cb

Please sign in to comment.