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 QPUD Library Mode Installer Build #1435

Merged
merged 28 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
4a85c98
Experimenting fixes for lib mode for qpud in the installer
1tnguyen Mar 22, 2024
81eafb1
Merge branch 'main' into tnguyen/installer-qpud-lib-mode
1tnguyen Mar 22, 2024
79fe9b0
Add %cpp_std to run commands
1tnguyen Mar 24, 2024
91be627
Use make_copyable_function util
1tnguyen Mar 25, 2024
7e83939
Debug the missing symbol
1tnguyen Mar 25, 2024
be18e22
Revert "Debug the missing symbol"
1tnguyen Mar 25, 2024
d1707af
Try something
1tnguyen Mar 25, 2024
63d6fdb
Trying a fix
1tnguyen Mar 27, 2024
afb5779
Merge branch 'main' into tnguyen/installer-qpud-lib-mode
1tnguyen Mar 27, 2024
c04a393
Remove obsolete code comments
1tnguyen Mar 27, 2024
0a0e5e3
Adds strict C++-17 checks
1tnguyen Apr 1, 2024
22c6016
Merge branch 'main' into tnguyen/installer-qpud-lib-mode
1tnguyen Apr 1, 2024
59aa9d0
Fixes for C++17 and unit tests
1tnguyen Apr 2, 2024
8d2c726
Merge branch 'main' into tnguyen/installer-qpud-lib-mode
1tnguyen Apr 2, 2024
ebe8283
Merge branch 'main' into tnguyen/installer-qpud-lib-mode
1tnguyen Apr 2, 2024
21dc2b0
Remove the workaround for cnot gate in C++17
1tnguyen Apr 2, 2024
5e7bcbf
Debug test issues for installer
1tnguyen Apr 3, 2024
321d034
Fixed issue with args by ref
1tnguyen Apr 3, 2024
9823eee
Revert "Debug test issues for installer"
1tnguyen Apr 3, 2024
be42b61
Merge branch 'main' into tnguyen/installer-qpud-lib-mode
1tnguyen Apr 4, 2024
6782d41
Set seed for test repeatability
1tnguyen Apr 4, 2024
d04c4eb
Merge branch 'main' into tnguyen/installer-qpud-lib-mode
1tnguyen Apr 4, 2024
f249a56
Merge branch 'main' into tnguyen/installer-qpud-lib-mode
1tnguyen Apr 12, 2024
19beb05
Fixes after merge
1tnguyen Apr 12, 2024
ef84840
Fixed a typo: REQURIES -> REQUIRES
1tnguyen Apr 12, 2024
2c76555
Merge branch 'main' into tnguyen/installer-qpud-lib-mode
1tnguyen Apr 16, 2024
4ad7ecd
Address code review
1tnguyen Apr 16, 2024
574dcef
Merge branch 'main' into tnguyen/installer-qpud-lib-mode
1tnguyen Apr 17, 2024
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
5 changes: 4 additions & 1 deletion docker/build/assets.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,10 @@ RUN python3 -m ensurepip --upgrade && python3 -m pip install lit && \
dnf install -y --nobest --setopt=install_weak_deps=False file which
RUN cd /cuda-quantum && source scripts/configure_build.sh && \
"$LLVM_INSTALL_PREFIX/bin/llvm-lit" -v build/test \
--param nvqpp_site_config=build/test/lit.site.cfg.py
--param nvqpp_site_config=build/test/lit.site.cfg.py && \
"$LLVM_INSTALL_PREFIX/bin/llvm-lit" -v build/targettests \
--param nvqpp_site_config=build/targettests/lit.site.cfg.py


# Tests for the Python wheel are run post-installation.
COPY --from=python_build /wheelhouse /cuda_quantum/wheelhouse
14 changes: 6 additions & 8 deletions runtime/common/JIT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include "mlir/ExecutionEngine/ExecutionEngine.h"
#include <cxxabi.h>

#define DEBUG_TYPE "cudaq-qpud"

namespace cudaq {

void invokeWrappedKernel(std::string_view irString,
Expand Down Expand Up @@ -79,14 +81,14 @@ void invokeWrappedKernel(std::string_view irString,
std::string demangledName(demangledPtr);
if (demangledName.rfind(wrappedKernelSymbol, 0) == 0 &&
demangledName.find(templatedTypeName) != std::string::npos) {
llvm::dbgs() << "Found symbol " << func.getName() << " for "
<< wrappedKernelSymbol;
LLVM_DEBUG(llvm::dbgs() << "Found symbol " << func.getName()
<< " for " << wrappedKernelSymbol);
mangledWrapper = func.getName().str();
fixUpLinkage(func);
}
if (demangledName.rfind(funcName, 0) == 0) {
llvm::dbgs() << "Found symbol " << func.getName() << " for "
<< funcName;
LLVM_DEBUG(llvm::dbgs() << "Found symbol " << func.getName()
<< " for " << funcName);
mangledKernel = func.getName().str();
fixUpLinkage(func);
}
Expand All @@ -109,10 +111,6 @@ void invokeWrappedKernel(std::string_view irString,
return std::make_unique<llvm::SectionMemoryManager>();
});
llvm::Triple targetTriple(llvm::Twine(llvmModule->getTargetTriple()));
// IMPORTANT: need to setAutoClaimResponsibilityForObjectSymbols to true to
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The removal of these lines probably means we need to edit the comments in runtime/common/JIT.h, too.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed #1533.

// prevent debug asserts about symbol responsibility.
objectLayer->setAutoClaimResponsibilityForObjectSymbols(true);

return objectLayer;
};

Expand Down
28 changes: 20 additions & 8 deletions runtime/cudaq/algorithms/observe.h
Original file line number Diff line number Diff line change
Expand Up @@ -502,10 +502,16 @@ auto observe_async(const std::size_t qpu_id, QuantumKernel &&kernel, spin_op &H,
H, platform, shots, kernelName, qpu_id);
#else
return details::runObservationAsync(
[&kernel,
args = std::forward_as_tuple(std::forward<Args>(args)...)]() mutable {
std::apply(std::move(kernel), std::move(args));
},
detail::make_copyable_function([&kernel,
args = std::make_tuple(std::forward<Args>(
args)...)]() mutable {
std::apply(
[&kernel](Args &&...args) {
return cudaq::invokeKernel(std::forward<QuantumKernel>(kernel),
std::forward<Args>(args)...);
},
std::move(args));
}),
H, platform, shots, kernelName, qpu_id);
#endif
}
Expand Down Expand Up @@ -535,10 +541,16 @@ auto observe_async(std::size_t shots, std::size_t qpu_id,
H, platform, shots, kernelName, qpu_id);
#else
return details::runObservationAsync(
[&kernel,
args = std::forward_as_tuple(std::forward<Args>(args)...)]() mutable {
std::apply(std::move(kernel), std::move(args));
},
detail::make_copyable_function([&kernel,
args = std::make_tuple(std::forward<Args>(
args)...)]() mutable {
std::apply(
[&kernel](Args &&...args) {
return cudaq::invokeKernel(std::forward<QuantumKernel>(kernel),
std::forward<Args>(args)...);
},
std::move(args));
}),
H, platform, shots, kernelName, qpu_id);
#endif
}
Expand Down
28 changes: 20 additions & 8 deletions runtime/cudaq/algorithms/sample.h
Original file line number Diff line number Diff line change
Expand Up @@ -385,10 +385,16 @@ async_sample_result sample_async(const std::size_t qpu_id,
platform, kernelName, shots, qpu_id);
#else
return details::runSamplingAsync(
[&kernel,
args = std::forward_as_tuple(std::forward<Args>(args)...)]() mutable {
std::apply(std::move(kernel), std::move(args));
},
detail::make_copyable_function([&kernel,
args = std::make_tuple(std::forward<Args>(
args)...)]() mutable {
std::apply(
[&kernel](Args &&...args) {
return cudaq::invokeKernel(std::forward<QuantumKernel>(kernel),
std::forward<Args>(args)...);
},
std::move(args));
}),
platform, kernelName, shots, qpu_id);
#endif
}
Expand Down Expand Up @@ -437,10 +443,16 @@ async_sample_result sample_async(std::size_t shots, std::size_t qpu_id,
platform, kernelName, shots, qpu_id);
#else
return details::runSamplingAsync(
[&kernel,
args = std::forward_as_tuple(std::forward<Args>(args)...)]() mutable {
std::apply(std::move(kernel), std::move(args));
},
detail::make_copyable_function([&kernel,
args = std::make_tuple(std::forward<Args>(
args)...)]() mutable {
std::apply(
[&kernel](Args &&...args) {
return cudaq::invokeKernel(std::forward<QuantumKernel>(kernel),
std::forward<Args>(args)...);
},
std::move(args));
}),
platform, kernelName, shots, qpu_id);
#endif
}
Expand Down
7 changes: 2 additions & 5 deletions targettests/Remote-Sim/args_parsing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@
******************************************************************************/

// REQUIRES: remote-sim
// REQUIRES: c++20
// FIXME: https://github.com/NVIDIA/cuda-quantum/issues/1111

// clang-format off
// RUN: nvq++ --target remote-mqpu --remote-mqpu-auto-launch 1 %s -o %t && %t
// RUN: nvq++ --enable-mlir --target remote-mqpu --remote-mqpu-auto-launch 1 %s -o %t && %t
// RUN: nvq++ %cpp_std --target remote-mqpu --remote-mqpu-auto-launch 1 %s -o %t && %t
// RUN: nvq++ %cpp_std --enable-mlir --target remote-mqpu --remote-mqpu-auto-launch 1 %s -o %t && %t
// clang-format on

#include <cudaq.h>
Expand Down
4 changes: 2 additions & 2 deletions targettests/Remote-Sim/args_synthesis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

// REQUIRES: remote-sim
// clang-format off
// RUN: nvq++ --enable-mlir --target remote-mqpu --remote-mqpu-auto-launch 1 %s -o %t && %t
// RUN: nvq++ --enable-mlir --no-aggressive-early-inline --target remote-mqpu --remote-mqpu-auto-launch 1 %s -o %t && %t
// RUN: nvq++ %cpp_std --enable-mlir --target remote-mqpu --remote-mqpu-auto-launch 1 %s -o %t && %t
// RUN: nvq++ %cpp_std --enable-mlir --no-aggressive-early-inline --target remote-mqpu --remote-mqpu-auto-launch 1 %s -o %t && %t
// clang-format on

// This is a comprehensive set of tests for kernel argument synthesis for remote
Expand Down
14 changes: 10 additions & 4 deletions targettests/Remote-Sim/free_func.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@
******************************************************************************/

// REQUIRES: remote-sim
// REQUIRES: c++20
// FIXME: https://github.com/NVIDIA/cuda-quantum/issues/1111

// clang-format off
// RUN: nvq++ --target remote-mqpu --remote-mqpu-auto-launch 1 %s -o %t && %t
// RUN: nvq++ --enable-mlir --target remote-mqpu --remote-mqpu-auto-launch 1 %s -o %t && %t
// RUN: nvq++ %cpp_std --target remote-mqpu --remote-mqpu-auto-launch 1 %s -o %t && %t
// RUN: nvq++ %cpp_std --enable-mlir --target remote-mqpu --remote-mqpu-auto-launch 1 %s -o %t && %t
// clang-format on

#include <cudaq.h>
Expand All @@ -21,7 +19,11 @@ void ghz(std::size_t N) __qpu__ {
cudaq::qvector q(N);
h(q[0]);
for (int i = 0; i < N - 1; i++) {
#if CUDAQ_USE_STD20
x<cudaq::ctrl>(q[i], q[i + 1]);
#else
cx(q[i], q[i + 1]);
#endif
schweitzpgi marked this conversation as resolved.
Show resolved Hide resolved
}
mz(q);
}
Expand All @@ -30,7 +32,11 @@ void ansatz(double theta) __qpu__ {
cudaq::qvector q(2);
x(q[0]);
ry(theta, q[1]);
#if CUDAQ_USE_STD20
1tnguyen marked this conversation as resolved.
Show resolved Hide resolved
x<cudaq::ctrl>(q[1], q[0]);
#else
cx(q[1], q[0]);
#endif
}

int main() {
Expand Down
10 changes: 6 additions & 4 deletions targettests/Remote-Sim/observe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@
* the terms of the Apache License 2.0 which accompanies this distribution. *
******************************************************************************/

// REQUIRES: c++20
// REQUIRES: remote-sim
// FIXME: https://github.com/NVIDIA/cuda-quantum/issues/1111

// clang-format off
// RUN: nvq++ --target remote-mqpu --remote-mqpu-auto-launch 1 %s -o %t && %t
// RUN: nvq++ --enable-mlir --target remote-mqpu --remote-mqpu-auto-launch 1 %s -o %t && %t
// RUN: nvq++ %cpp_std --target remote-mqpu --remote-mqpu-auto-launch 1 %s -o %t && %t
// RUN: nvq++ %cpp_std --enable-mlir --target remote-mqpu --remote-mqpu-auto-launch 1 %s -o %t && %t
// clang-format on

#include <cudaq.h>
Expand All @@ -26,7 +24,11 @@ struct ansatz {
cudaq::qvector q(2);
x(q[0]);
ry(theta, q[1]);
#if CUDAQ_USE_STD20
1tnguyen marked this conversation as resolved.
Show resolved Hide resolved
x<cudaq::ctrl>(q[1], q[0]);
#else
cx(q[1], q[0]);
#endif
}
};

Expand Down
15 changes: 10 additions & 5 deletions targettests/Remote-Sim/observe_async.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@
******************************************************************************/

// REQUIRES: remote-sim
// REQUIRES: c++20
// FIXME: https://github.com/NVIDIA/cuda-quantum/issues/1111

// clang-format off
// RUN: nvq++ --target remote-mqpu --remote-mqpu-auto-launch 3 %s -o %t && %t
// RUN: nvq++ --enable-mlir --target remote-mqpu --remote-mqpu-auto-launch 3 %s -o %t && %t
// RUN: nvq++ %cpp_std --target remote-mqpu --remote-mqpu-auto-launch 3 %s -o %t && %t
// RUN: nvq++ %cpp_std --enable-mlir --target remote-mqpu --remote-mqpu-auto-launch 3 %s -o %t && %t
// clang-format on

#include <cudaq.h>
Expand All @@ -22,7 +20,7 @@ struct ansatz {
cudaq::qvector q(2);
x(q[0]);
ry(theta, q[1]);
x<cudaq::ctrl>(q[1], q[0]);
cx(q[1], q[0]);
1tnguyen marked this conversation as resolved.
Show resolved Hide resolved
}
};

Expand All @@ -45,5 +43,12 @@ int main() {
printf("Energy is %lf\n", energy);
printf("Gradient is %lf\n", gradient);
assert(std::abs(energy + 1.748794) < 1e-3);
// Shots-based observe async. API
cudaq::set_random_seed(13);
auto energyFutureShots =
cudaq::observe_async(/*shots=*/8192, /*qpu_id=*/0, ansatz{}, h, .59);
const auto energyShots = energyFutureShots.get().expectation();
printf("Energy (shots) is %lf\n", energyShots);
assert(std::abs(energyShots + 1.748794) < 0.1);
return 0;
}
14 changes: 10 additions & 4 deletions targettests/Remote-Sim/sample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@
* the terms of the Apache License 2.0 which accompanies this distribution. *
******************************************************************************/

// REQUIRES: c++20
// REQUIRES: remote-sim
// FIXME: https://github.com/NVIDIA/cuda-quantum/issues/1111

// clang-format off
// RUN: nvq++ --target remote-mqpu --remote-mqpu-auto-launch 1 %s -o %t && %t
// RUN: nvq++ --enable-mlir --target remote-mqpu --remote-mqpu-auto-launch 1 %s -o %t && %t
// RUN: nvq++ %cpp_std --target remote-mqpu --remote-mqpu-auto-launch 1 %s -o %t && %t
// RUN: nvq++ %cpp_std --enable-mlir --target remote-mqpu --remote-mqpu-auto-launch 1 %s -o %t && %t
// clang-format on

#include <cudaq.h>
Expand All @@ -23,7 +21,11 @@ struct ghz {
cudaq::qarray<N> q;
h(q[0]);
for (int i = 0; i < N - 1; i++) {
#if CUDAQ_USE_STD20
x<cudaq::ctrl>(q[i], q[i + 1]);
#else
cx(q[i], q[i + 1]);
#endif
}
mz(q);
}
Expand All @@ -42,7 +44,11 @@ int main() {
cudaq::qvector q(N);
h(q[0]);
for (int i = 0; i < N - 1; i++) {
#if CUDAQ_USE_STD20
x<cudaq::ctrl>(q[i], q[i + 1]);
#else
cx(q[i], q[i + 1]);
#endif
}
mz(q);
};
Expand Down
25 changes: 16 additions & 9 deletions targettests/Remote-Sim/sample_async.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@
******************************************************************************/

// REQUIRES: remote-sim
// REQUIRES: c++20
// FIXME: https://github.com/NVIDIA/cuda-quantum/issues/1111

// clang-format off
// RUN: nvq++ --target remote-mqpu --remote-mqpu-auto-launch 4 %s -o %t && %t
// RUN: nvq++ --enable-mlir --target remote-mqpu --remote-mqpu-auto-launch 4 %s -o %t && %t
// RUN: nvq++ %cpp_std --target remote-mqpu --remote-mqpu-auto-launch 4 %s -o %t && %t
// RUN: nvq++ %cpp_std --enable-mlir --target remote-mqpu --remote-mqpu-auto-launch 4 %s -o %t && %t
// clang-format on

#include <cudaq.h>
Expand All @@ -31,16 +29,25 @@ int main() {
printf("Number of QPUs: %zu\n", num_qpus);
assert(num_qpus == 4);
std::vector<cudaq::async_sample_result> countFutures;
// sample_async API with default shots
for (std::size_t i = 0; i < num_qpus; i++) {
countFutures.emplace_back(cudaq::sample_async(i, simpleX{}, i + 1));
}
// Shots-based sample_async API
std::vector<cudaq::async_sample_result> countFuturesWithShots;
for (std::size_t i = 0; i < num_qpus; i++) {
countFuturesWithShots.emplace_back(
cudaq::sample_async(/*shots=*/1024, /*qpu_id=*/i, simpleX{}, i + 1));
}

for (std::size_t i = 0; i < num_qpus; i++) {
auto counts = countFutures[i].get();
counts.dump();
const std::string expectedBitStr(i + 1, '1');
assert(counts.size() == 1);
assert(counts.begin()->first == expectedBitStr);
for (auto counts :
{countFutures[i].get(), countFuturesWithShots[i].get()}) {
counts.dump();
const std::string expectedBitStr(i + 1, '1');
assert(counts.size() == 1);
assert(counts.begin()->first == expectedBitStr);
}
}
return 0;
}
4 changes: 4 additions & 0 deletions targettests/Target/IQM/for_loop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ struct ghz {
cudaq::qarray<N> q;
h(q[0]);
for (int i = 0; i < N - 1; i++) {
#if CUDAQ_USE_STD20
x<cudaq::ctrl>(q[i], q[i + 1]);
#else
cx(q[i], q[i + 1]);
#endif
}
auto result = mz(q[0]);
}
Expand Down
4 changes: 4 additions & 0 deletions targettests/Target/IQM/z_gate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ template <std::size_t N>
struct kernel_with_z {
auto operator()() __qpu__ {
cudaq::qarray<N> q;
#if CUDAQ_USE_STD20
z<cudaq::ctrl>(q[0], q[1]);
#else
cz(q[0], q[1]);
#endif
auto result = mz(q[0]);
}
};
Expand Down
5 changes: 5 additions & 0 deletions targettests/execution/auto_kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,13 @@ struct ak2 {
cudaq::qarray<3> q;
x(q[0]);
h(q[1]);
#if CUDAQ_USE_STD20
x<cudaq::ctrl>(q[1], q[2]);
x<cudaq::ctrl>(q[0], q[1]);
#else
cx(q[1], q[2]);
cx(q[0], q[1]);
#endif
h(q[0]);
x(q[1]);
y(q[2]);
Expand Down
Loading
Loading