MCPcopy Create free account
hub / github.com/NVIDIA/cuda-quantum / jitCode

Function jitCode

runtime/cudaq/builder/kernel_builder.cpp:947–1125  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

945}
946
947std::tuple<bool, ExecutionEngine *>
948jitCode(ImplicitLocOpBuilder &builder, ExecutionEngine *jit,
949 std::unordered_map<ExecutionEngine *, std::size_t> &jitHash,
950 std::string kernelName, std::vector<std::string> extraLibPaths,
951 StateVectorStorage &stateVectorStorage) {
952
953 // Start of by getting the current ModuleOp
954 auto *block = builder.getBlock();
955 auto *context = builder.getContext();
956 auto *function = block->getParentOp();
957 auto currentModule = function->getParentOfType<ModuleOp>();
958
959 // Create a unique hash from that ModuleOp
960 auto hash = llvm::hash_code{0};
961 currentModule.walk([&hash](Operation *op) {
962 hash = llvm::hash_combine(hash, OperationEquivalence::computeHash(op));
963 });
964 auto moduleHash = static_cast<size_t>(hash);
965
966 if (jit) {
967 // Have we added more instructions since the last time we jit the code? If
968 // so, we need to delete this JIT engine and create a new one.
969 if (moduleHash == jitHash[jit])
970 return std::make_tuple(false, jit);
971 else {
972 // need to redo the jit, remove the old one
973 jitHash.erase(jit);
974 }
975 }
976
977 CUDAQ_INFO("kernel_builder running jitCode.");
978
979 auto module = currentModule.clone();
980 auto ctx = module.getContext();
981 SmallVector<mlir::NamedAttribute> names;
982 names.emplace_back(mlir::StringAttr::get(ctx, kernelName),
983 mlir::StringAttr::get(ctx, "BuilderKernel.EntryPoint"));
984 auto mapAttr = mlir::DictionaryAttr::get(ctx, names);
985 module->setAttr(cudaq::runtime::mangledNameMap, mapAttr);
986
987 // Tag as an entrypoint if it is one
988 tagEntryPoint(builder, module, StringRef{});
989
990 {
991 PassManager pm(context);
992 pm.addInstrumentation(std::make_unique<cudaq::TracePassInstrumentation>());
993 pm.addNestedPass<func::FuncOp>(cudaq::opt::createUnwindLowering());
994 cudaq::opt::addAggressiveInlining(pm);
995 pm.addPass(createCanonicalizerPass());
996 pm.addPass(cudaq::opt::createApplySpecialization());
997 pm.addNestedPass<func::FuncOp>(cudaq::opt::createClassicalMemToReg());
998 pm.addNestedPass<func::FuncOp>(createCanonicalizerPass());
999 pm.addPass(cudaq::opt::createExpandMeasurementsPass());
1000 pm.addNestedPass<func::FuncOp>(cudaq::opt::createLoopNormalize());
1001 pm.addNestedPass<func::FuncOp>(cudaq::opt::createLoopUnroll());
1002 pm.addNestedPass<func::FuncOp>(createCanonicalizerPass());
1003 pm.addNestedPass<func::FuncOp>(cudaq::opt::createQuakeAddDeallocs());
1004 pm.addNestedPass<func::FuncOp>(cudaq::opt::createQuakeAddMetadata());

Callers 2

jitCodeMethod · 0.85
jitAndInvokeMethod · 0.85

Calls 15

tagEntryPointFunction · 0.85
createClassicalMemToRegFunction · 0.85
getEnvBoolFunction · 0.85
getContextMethod · 0.80
walkMethod · 0.80
eraseMethod · 0.80
emplace_backMethod · 0.80
releaseMethod · 0.80
lookupMethod · 0.80
nameFunction · 0.70
getFunction · 0.50
createFunction · 0.50

Tested by

no test coverage detected