forked from NVIDIA/cuda-quantum
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJIT.h
More file actions
59 lines (50 loc) · 2 KB
/
JIT.h
File metadata and controls
59 lines (50 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/****************************************************************-*- C++ -*-****
* Copyright (c) 2022 - 2026 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. *
******************************************************************************/
#pragma once
#include <cstddef>
#include <cstdint>
#include <functional>
#include <memory>
#include <string>
namespace llvm {
class StringRef;
namespace orc {
class LLJIT;
}
} // namespace llvm
namespace mlir {
class ExecutionEngine;
class ModuleOp;
} // namespace mlir
namespace cudaq {
/// Util to create a wrapped kernel defined by LLVM IR with serialized
/// arguments.
// Note: We don't use `mlir::ExecutionEngine` to skip unnecessary
// `packFunctionArguments` (slow for raw LLVM IR containing many functions from
// included headers).
std::tuple<std::unique_ptr<llvm::orc::LLJIT>, std::function<void()>>
createWrappedKernel(std::string_view llvmIr, const std::string &kernelName,
void *args, std::uint64_t argsSize);
/// JitEngine is a type-erased class that is wrapping an mlir::ExecutionEngine
/// without introducing any link time dependency on MLIR for the client of the
/// class. Memory management for of the mlir::ExecutionEngine is handled
/// internally.
class JitEngine {
public:
JitEngine(std::unique_ptr<mlir::ExecutionEngine>);
void run(const std::string &kernelName) const;
void (*lookupRawNameOrFail(const std::string &kernelName) const)();
std::size_t getKey() const;
private:
class Impl;
std::shared_ptr<Impl> impl;
};
/// Lower ModuleOp to QIR/LLVM IR and create a JIT execution engine.
JitEngine createQIRJITEngine(mlir::ModuleOp &moduleOp,
llvm::StringRef convertTo);
} // namespace cudaq