-
Notifications
You must be signed in to change notification settings - Fork 209
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix a bug in tensornet backend scratch pad allocation in multi-GPU mo…
…de (#2516) * Fix a bug in default init of scratchpad: it must allocate memory after we've set the device Signed-off-by: Thien Nguyen <thiennguyen@nvidia.com> * Add test Signed-off-by: Thien Nguyen <thiennguyen@nvidia.com> * Add a check to prevent multiple allocate calls Signed-off-by: Thien Nguyen <thiennguyen@nvidia.com> --------- Signed-off-by: Thien Nguyen <thiennguyen@nvidia.com>
- Loading branch information
Showing
4 changed files
with
80 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2022 - 2025 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. * | ||
******************************************************************************/ | ||
#include <cudaq.h> | ||
#include <gtest/gtest.h> | ||
|
||
TEST(TensornetMPITester, checkInit) { | ||
EXPECT_TRUE(cudaq::mpi::is_initialized()); | ||
std::cout << "Rank = " << cudaq::mpi::rank() << "\n"; | ||
} | ||
|
||
TEST(TensornetMPITester, checkSimple) { | ||
constexpr std::size_t numQubits = 50; | ||
auto kernel = []() __qpu__ { | ||
cudaq::qvector q(numQubits); | ||
h(q[0]); | ||
for (int i = 0; i < numQubits - 1; i++) | ||
x<cudaq::ctrl>(q[i], q[i + 1]); | ||
mz(q); | ||
}; | ||
|
||
auto counts = cudaq::sample(100, kernel); | ||
|
||
if (cudaq::mpi::rank() == 0) { | ||
EXPECT_EQ(2, counts.size()); | ||
|
||
for (auto &[bits, count] : counts) { | ||
printf("Observed: %s, %lu\n", bits.data(), count); | ||
EXPECT_EQ(numQubits, bits.size()); | ||
} | ||
} | ||
} | ||
|
||
int main(int argc, char **argv) { | ||
::testing::InitGoogleTest(&argc, argv); | ||
cudaq::mpi::initialize(); | ||
const auto testResult = RUN_ALL_TESTS(); | ||
cudaq::mpi::finalize(); | ||
return testResult; | ||
} |