Commit bce07606 authored by Mccaskey, Alex's avatar Mccaskey, Alex
Browse files

fixing bug in tests where qjit cache file was empty



Signed-off-by: Mccaskey, Alex's avatarAlex McCaskey <mccaskeyaj@ornl.gov>
parent 5831a7e2
Pipeline #122857 passed with stage
in 15 minutes and 25 seconds
......@@ -136,6 +136,7 @@ class PyObjectiveFunction : public qcor::ObjectiveFunction {
// QJIT compile
// this will be fast if already done, and we just do it once
qjit.jit_compile(src, true);
qjit.write_cache();
}
// Evaluate this ObjectiveFunction at the dictionary of kernel args,
......@@ -196,6 +197,7 @@ class PyKernelFunctor : public qcor::KernelFunctor {
auto src = py_kernel.attr("get_internal_src")().cast<std::string>();
// this will be fast if already done, and we just do it once
qjit.jit_compile(src, true);
qjit.write_cache();
}
// Delegate to QJIT to create a CompositeInstruction representation
......@@ -282,6 +284,7 @@ PYBIND11_MODULE(_pyqcor, m) {
// m.def("createObjectiveFunction", [](const std::string name, ))
py::class_<qcor::QJIT, std::shared_ptr<qcor::QJIT>>(m, "QJIT", "")
.def(py::init<>(), "")
.def("write_cache", &qcor::QJIT::write_cache, "")
.def("jit_compile", &qcor::QJIT::jit_compile, "")
.def(
"internal_python_jit_compile",
......
......@@ -94,6 +94,7 @@ class qjit(object):
# Run the QJIT compile step to store function pointers internally
self._qjit.internal_python_jit_compile(self.src)
self._qjit.write_cache()
return
......
......@@ -47,6 +47,8 @@ class QJIT {
void jit_compile(const std::string &quantum_kernel_src,
const bool add_het_map_kernel_ctor = false);
void write_cache();
template <typename... Args>
void invoke(const std::string &kernel_name, Args... args) {
auto f_ptr = kernel_name_to_f_ptr[kernel_name];
......
......@@ -6,7 +6,6 @@
#include "Accelerator.hpp"
#include "CompositeInstruction.hpp"
#include "xacc.hpp"
#include "Utils.hpp"
#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/DiagnosticOptions.h"
......@@ -51,6 +50,7 @@
#include "qcor_jit.hpp"
#include "qcor_syntax_handler.hpp"
#include "qrt.hpp"
#include "xacc.hpp"
#include "xacc_internal_compiler.hpp"
using namespace llvm;
......@@ -322,16 +322,17 @@ QJIT::QJIT() {
std::string cache_file_contents(
(std::istreambuf_iterator<char>(cache_file)),
std::istreambuf_iterator<char>());
auto cache_json = nlohmann::json::parse(cache_file_contents);
auto jit_cache = cache_json["jit_cache"];
for (auto &element : jit_cache) {
auto key_val = element.get<std::pair<std::size_t, std::string>>();
cached_kernel_codes.insert(key_val);
if (!cache_file_contents.empty()) {
auto cache_json = nlohmann::json::parse(cache_file_contents);
auto jit_cache = cache_json["jit_cache"];
for (auto &element : jit_cache) {
auto key_val = element.get<std::pair<std::size_t, std::string>>();
cached_kernel_codes.insert(key_val);
}
}
}
}
QJIT::~QJIT() {
void QJIT::write_cache() {
std::string cache_file_loc = "@CMAKE_INSTALL_PREFIX@/tmp/qjit_cache.json";
nlohmann::json j;
j["jit_cache"] = cached_kernel_codes;
......@@ -340,6 +341,7 @@ QJIT::~QJIT() {
cache << str;
cache.close();
}
QJIT::~QJIT() { write_cache(); }
void QJIT::jit_compile(const std::string &code,
const bool add_het_map_kernel_ctor) {
......@@ -470,7 +472,7 @@ void QJIT::invoke_with_hetmap(const std::string &kernel_name,
}
std::shared_ptr<xacc::CompositeInstruction> QJIT::extract_composite_with_hetmap(
const std::string kernel_name, xacc::HeterogeneousMap &args ) {
const std::string kernel_name, xacc::HeterogeneousMap &args) {
auto composite =
xacc::getIRProvider("quantum")->createComposite(kernel_name + "_qjit");
auto f_ptr = kernel_name_to_f_ptr_parent_hetmap[kernel_name];
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment