Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #344 - add support for std::uint8_t kernel argument #356

Merged
merged 3 commits into from
Jul 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/Frontend/nvqpp/ConvertType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,8 @@ bool QuakeBridgeVisitor::VisitElaboratedType(clang::ElaboratedType *t) {
return pushType(builder.getI64Type());
if (matchTypeName("std", "_Bit_reference", name, /*toEnd=*/true))
return pushType(builder.getI1Type());
if (matchTypeName("std", "uint8_t", name, /*toEnd=*/true))
return pushType(builder.getI8Type());
if (matchTypeName("std", "function", name)) {
// Note: technically this is a wrapper around a Callable and not exactly a
// lambda. (Callables are a generalization of closures, functions,
Expand Down
7 changes: 7 additions & 0 deletions lib/Optimizer/Transforms/QuakeSynthesizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,13 @@ void QuakeSynthesizer::runOnOperation() {
return builder.create<arith::ConstantIntOp>(
builder.getUnknownLoc(), *concrete, 1);
});
} else if (type == builder.getIntegerType(8)) {
synthesizeRuntimeArgument<std::uint8_t>(
builder, argument, args, offset, sizeof(std::uint8_t),
[](OpBuilder &builder, std::uint8_t *concrete) {
return builder.create<arith::ConstantIntOp>(
builder.getUnknownLoc(), *concrete, 8);
});
} else if (type == builder.getIntegerType(32)) {
synthesizeRuntimeArgument<int>(
builder, argument, args, offset, sizeof(int),
Expand Down
32 changes: 32 additions & 0 deletions test/NVQPP/test-int8_t.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*******************************************************************************
* Copyright (c) 2022 - 2023 NVIDIA Corporation & Affiliates. *
* All rights reserved. *
* *
* This source code and the accompanying materials are made available under *
* the terms of the Apache License 2.0 which accompanies this distribution. *
******************************************************************************/

// RUN: nvq++ -v %s -o %basename_t.x --target quantinuum --emulate && ./%basename_t.x | FileCheck %s

#include <cudaq.h>
#include <iostream>

struct variable_qreg {
__qpu__ void operator()(std::uint8_t value) {
cudaq::qreg qubits(value);
mz(qubits);
}
};

int main() {
for (auto i = 1; i < 5; ++i) {
auto result = cudaq::sample(1000, variable_qreg{}, i);
std::cout << result.most_probable() << '\n';
}
return 0;
}

// CHECK: 0
// CHECK: 00
// CHECK: 000
// CHECK: 0000
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
******************************************************************************/

// RUN: nvq++ -v %s -o %basename_t.x --target quantinuum --emulate && ./%basename_t.x | FileCheck %s
// XFAIL: *

#include <cudaq.h>
#include <iostream>
Expand Down
Loading