Commit 9a54cc72 authored by Mccaskey, Alex's avatar Mccaskey, Alex
Browse files

fixing bug #60 - qjit cache now set to home/.qjit

parent 36909d4f
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -253,6 +253,7 @@ class TestKernelJIT(unittest.TestCase):
        self.assertEqual(comp.nInstructions(), 5)   

    def test_for_loop_enumerate(self):
        set_qpu('qpp')
        @qjit
        def ansatz(q: qreg, x: List[float], exp_args: List[FermionOperator]):
            X(q[0])
+0 −1
Original line number Diff line number Diff line


configure_file(qcor_jit.in.cpp
               ${CMAKE_BINARY_DIR}/runtime/jit/qcor_jit.cpp)

+2 −0
Original line number Diff line number Diff line
@@ -30,6 +30,8 @@ class QJIT {
    return (status == 0) ? res.get() : std::string(name);
  };

  std::string qjit_cache_path = "";

 protected:
  std::map<std::string, std::uint64_t> kernel_name_to_f_ptr;
  std::map<std::string, std::uint64_t> kernel_name_to_f_ptr_hetmap;
+8 −7
Original line number Diff line number Diff line
@@ -60,6 +60,7 @@ using namespace llvm::orc;
#include <sys/stat.h>

namespace qcor {

using namespace clang;

class LexerHelper {
@@ -312,12 +313,12 @@ class LLVMJIT {

QJIT::QJIT() {
  // if tmp directory doesnt exist create it
  std::string tmp_dir = "@CMAKE_INSTALL_PREFIX@/tmp";
  if (!xacc::directoryExists(tmp_dir)) {
    auto status = mkdir(tmp_dir.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
  qjit_cache_path = std::string(std::getenv("HOME")) + "/.qjit";
  if (!xacc::directoryExists(qjit_cache_path)) {
    auto status = mkdir(qjit_cache_path.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
  }

  std::string cache_file_loc = "@CMAKE_INSTALL_PREFIX@/tmp/qjit_cache.json";
  std::string cache_file_loc = qjit_cache_path+"/qjit_cache.json";
  if (!xacc::fileExists(cache_file_loc)) {
    // if it doesn't exist, create it
    std::ofstream cache(cache_file_loc);
@@ -338,7 +339,7 @@ QJIT::QJIT() {
  }
}
void QJIT::write_cache() {
  std::string cache_file_loc = "@CMAKE_INSTALL_PREFIX@/tmp/qjit_cache.json";
  std::string cache_file_loc = qjit_cache_path + "/qjit_cache.json";
  nlohmann::json j;
  j["jit_cache"] = cached_kernel_codes;
  auto str = j.dump();
@@ -388,7 +389,7 @@ void QJIT::jit_compile(const std::string &code,
    // correspoding Module bc file name and load it
    auto module_bitcode_file_name = cached_kernel_codes[hash];
    std::string full_path =
        "@CMAKE_INSTALL_PREFIX@/tmp/" + module_bitcode_file_name;
        qjit_cache_path+"/" + module_bitcode_file_name;

    // Load the bitcode file as Module
    SMDiagnostic error;
@@ -411,7 +412,7 @@ void QJIT::jit_compile(const std::string &code,
    std::stringstream file_name_ss;
    file_name_ss << "__qjit_m_" << module.get() << ".bc";
    std::error_code ec;
    ToolOutputFile result("@CMAKE_INSTALL_PREFIX@/tmp/" + file_name_ss.str(),
    ToolOutputFile result(qjit_cache_path+"/" + file_name_ss.str(),
                          ec, sys::fs::F_None);
    WriteBitcodeToFile(*module, result.os());
    result.keep();
+4 −4
Original line number Diff line number Diff line
@@ -58,13 +58,13 @@ def main(argv=None):
        exit(0)

    if '-clear-jit-cache' in sys.argv[1:]:
        files = glob.glob('@CMAKE_INSTALL_PREFIX@/tmp/*.bc')
        files = glob.glob(os.getenv('HOME') + '/.qjit/*.bc')
        for f in files:
            print("removing ", f)
            os.remove(f)
        if os.path.exists('@CMAKE_INSTALL_PREFIX@/tmp/qjit_cache.json'):
            os.remove('@CMAKE_INSTALL_PREFIX@/tmp/qjit_cache.json')
            print('removing @CMAKE_INSTALL_PREFIX@/tmp/qjit_cache.json')
        if os.path.exists(os.getenv('HOME') + '/.qjit/qjit_cache.json'):
            os.remove(os.getenv('HOME') + '/.qjit/qjit_cache.json')
            print('removing {}/.qjit/qjit_cache.json'.format(os.getenv('HOME')))
        exit(0)

    if '--verbose' in sys.argv[1:]:
Loading