Skip to content
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
1 change: 1 addition & 0 deletions python/utils/LinkedLibraryHolder.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "cudaq/Support/TargetConfig.h"
#include "cudaq/host_config.h"
#include <filesystem>
#include <functional>
#include <map>
#include <string>
#include <unordered_map>
Expand Down
3 changes: 2 additions & 1 deletion runtime/common/AnalogRemoteRESTQPU.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ class AnalogRemoteRESTQPU : public BaseRemoteRESTQPU {
std::string strArgs = charArgs;
nlohmann::json j;
std::vector<std::size_t> mapping_reorder_idx;
codes.emplace_back(name, strArgs, std::nullopt, j, mapping_reorder_idx);
codes.emplace_back(name, strArgs, std::nullopt, std::nullopt, j,
mapping_reorder_idx);

if (executionContext) {
executor->setShots(executionContext->shots);
Expand Down
5 changes: 3 additions & 2 deletions runtime/common/BaseRemoteRESTQPU.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
namespace nvqir {
// QIR helper to retrieve the output log.
std::string_view getQirOutputLog();
cudaq::Resources *getResourceCounts();
void setResourceCounts(cudaq::Resources &&);
bool isUsingResourceCounterSimulator();
} // namespace nvqir

Expand Down Expand Up @@ -342,7 +342,8 @@ class BaseRemoteRESTQPU : public QPU {
if (executionContext->name == "resource-count") {
cudaq::ExecutionContext context("resource-count");
context.executionManager = cudaq::getDefaultExecutionManager();
assert(codes.size() == 1 && codes[0].jit);
assert(codes.size() == 1 && codes[0].jit && codes[0].resourceCounts);
nvqir::setResourceCounts(std::move(codes[0].resourceCounts.value()));
cudaq::get_platform().with_execution_context(
context, [&]() { codes[0].jit->run(kernelName); });
return;
Expand Down
5 changes: 2 additions & 3 deletions runtime/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,7 @@ target_include_directories(cudaq-mlir-runtime
${CMAKE_SOURCE_DIR}/runtime)

target_link_libraries(cudaq-mlir-runtime
PUBLIC
nvqir
PRIVATE
CCDialect
QuakeDialect
OptCodeGen
Expand All @@ -149,7 +148,7 @@ target_link_libraries(cudaq-mlir-runtime
MLIRTargetLLVMIRExport
MLIRLLVMCommonConversion
MLIRLLVMToLLVMIRTranslation
PRIVATE
cudaq-common
CUDAQTargetConfigUtil
cudaq-logger
)
Expand Down
20 changes: 9 additions & 11 deletions runtime/common/Compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,6 @@

using namespace mlir;

namespace nvqir {
// QIR helper to retrieve the output log.
std::string_view getQirOutputLog();
cudaq::Resources *getResourceCounts();
bool isUsingResourceCounterSimulator();
} // namespace nvqir

namespace {
/// Conditionally form an output_names JSON object if this was for QIR
nlohmann::json formOutputNames(const std::string &codegenTranslation,
Expand Down Expand Up @@ -359,14 +352,15 @@ std::vector<cudaq::KernelExecution> Compiler::lowerQuakeCodePart2(
// We need to run resource counting preprocessing after the pass pipeline as
// the pre-processing might change the IR structure (may interfere with
// other passes).
std::unique_ptr<Resources> resourceCounts;
if (executionContext && executionContext->name == "resource-count") {
resourceCounts = std::make_unique<Resources>();
// Each pass may run in a separate thread, so we have to make sure to
// grab this reference in this thread
auto resource_counts = nvqir::getResourceCounts();
std::function<void(std::string, size_t, size_t)> f =
[&](std::string gate, size_t nControls, size_t count) {
[&resourceCounts](std::string gate, size_t nControls, size_t count) {
CUDAQ_INFO("Appending: {}", gate);
resource_counts->appendInstruction(gate, nControls, count);
resourceCounts->appendInstruction(gate, nControls, count);
};
cudaq::opt::ResourceCountPreprocessOptions opt{f};
mlir::PassManager pm(moduleOp.getContext());
Expand Down Expand Up @@ -520,7 +514,11 @@ std::vector<cudaq::KernelExecution> Compiler::lowerQuakeCodePart2(
auto optionalJit = jitEngines.size() > iter.index()
? std::optional(jitEngines[iter.index()])
: std::nullopt;
codes.emplace_back(name, codeStr, optionalJit, j, mapping_reorder_idx);
auto optionalResourceCounts = resourceCounts
? std::optional(*resourceCounts.release())
: std::nullopt;
codes.emplace_back(name, codeStr, optionalJit, optionalResourceCounts, j,
mapping_reorder_idx);
}

return codes;
Expand Down
5 changes: 0 additions & 5 deletions runtime/common/Resources.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#pragma once

#include "Trace.h"
#include <ostream>
#include <unordered_map>
#include <vector>
Expand Down Expand Up @@ -48,10 +47,6 @@ class Resources {
bool operator==(const Instruction &other) const;
};

Resources() = default;
Resources(Resources &) = default;
Resources(Resources &&) = default;

/// @brief Return the number of times the given Instruction is
/// used in the current kernel execution
std::size_t count(const Instruction &instruction) const;
Expand Down
16 changes: 10 additions & 6 deletions runtime/common/ServerHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "Future.h"
#include "JIT.h"
#include "Registry.h"
#include "Resources.h"
#include "RuntimeTarget.h"
#include "SampleResult.h"
#include "common/RecordLogParser.h"
Expand All @@ -31,17 +32,20 @@ struct KernelExecution {
std::string name;
std::string code;
std::optional<JitEngine> jit;
std::optional<Resources> resourceCounts;
nlohmann::json output_names;
std::vector<std::size_t> mapping_reorder_idx;
nlohmann::json user_data;
KernelExecution(std::string &n, std::string &c, std::optional<JitEngine> jit,
nlohmann::json &o, std::vector<std::size_t> &m)
: name(n), code(c), jit(jit), output_names(o), mapping_reorder_idx(m) {}
std::optional<Resources> rc, nlohmann::json &o,
std::vector<std::size_t> &m)
: name(n), code(c), jit(jit), resourceCounts(rc), output_names(o),
mapping_reorder_idx(m) {}
KernelExecution(std::string &n, std::string &c, std::optional<JitEngine> jit,
nlohmann::json &o, std::vector<std::size_t> &m,
nlohmann::json &ud)
: name(n), code(c), jit(jit), output_names(o), mapping_reorder_idx(m),
user_data(ud) {}
std::optional<Resources> rc, nlohmann::json &o,
std::vector<std::size_t> &m, nlohmann::json &ud)
: name(n), code(c), jit(jit), resourceCounts(rc), output_names(o),
mapping_reorder_idx(m), user_data(ud) {}
};

/// @brief Responses / Submissions to the Server are modeled via JSON
Expand Down
1 change: 1 addition & 0 deletions runtime/cudaq/algorithms/resource_estimation.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ void switchToResourceCounterSimulator();
void stopUsingResourceCounterSimulator();
void setChoiceFunction(std::function<bool()> choice);
cudaq::Resources *getResourceCounts();
void setResourceCounts(cudaq::Resources &&);
} // namespace nvqir

namespace cudaq {
Expand Down
1 change: 1 addition & 0 deletions runtime/cudaq/platform/default/rest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ target_link_libraries(cudaq-rest-qpu
fmt::fmt-header-only
cudaq
cudaq-platform-default
nvqir
${AWSSDK_LINK_LIBRARIES})

install(TARGETS cudaq-rest-qpu DESTINATION lib)
Expand Down
4 changes: 3 additions & 1 deletion runtime/cudaq/platform/fermioniq/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ target_link_libraries(${LIBRARY_NAME}
cudaq-mlir-runtime
fmt::fmt-header-only
cudaq
cudaq-platform-default)
cudaq-platform-default
nvqir
)

install(TARGETS ${LIBRARY_NAME} DESTINATION lib)

Expand Down
1 change: 1 addition & 0 deletions runtime/cudaq/platform/pasqal/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ target_link_libraries(${LIBRARY_NAME}
fmt::fmt-header-only
cudaq
cudaq-platform-default
nvqir
)

install(TARGETS ${LIBRARY_NAME} DESTINATION lib)
Expand Down
6 changes: 4 additions & 2 deletions runtime/cudaq/platform/quera/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ target_link_libraries(${LIBRARY_NAME}
pthread
cudaq-mlir-runtime
cudaq-logger
cudaq
cudaq-platform-default)
cudaq
cudaq-platform-default
nvqir
)

install(TARGETS ${LIBRARY_NAME} DESTINATION lib)

Expand Down
6 changes: 6 additions & 0 deletions runtime/nvqir/resourcecounter/ResourceCounter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,10 @@ cudaq::Resources *getResourceCounts() {
getResourceCounterSimulator()->flushGateQueue();
return getResourceCounterSimulator()->getResourceCounts();
}

void setResourceCounts(cudaq::Resources &&rc) {
getResourceCounterSimulator()->flushGateQueue();
getResourceCounterSimulator()->setResourceCounts(std::move(rc));
}

} // namespace nvqir
3 changes: 3 additions & 0 deletions runtime/nvqir/resourcecounter/ResourceCounter.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ class ResourceCounter : public nvqir::CircuitSimulatorBase<double> {
}

cudaq::Resources *getResourceCounts() { return &this->resourceCounts; }
void setResourceCounts(cudaq::Resources &&rc) {
this->resourceCounts = std::move(rc);
}

void setChoiceFunction(std::function<bool()> choice) {
assert(choice);
Expand Down
Loading