-
Notifications
You must be signed in to change notification settings - Fork 348
Expand file tree
/
Copy pathqpu.cpp
More file actions
45 lines (41 loc) · 2.13 KB
/
qpu.cpp
File metadata and controls
45 lines (41 loc) · 2.13 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
/*******************************************************************************
* 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. *
******************************************************************************/
#include "qpu.h"
#include "mlir/IR/BuiltinOps.h"
LLVM_INSTANTIATE_REGISTRY(cudaq::ModuleLauncher::RegistryType)
cudaq::KernelThunkResultType
cudaq::QPU::launchModule(const std::string &name, mlir::ModuleOp module,
const std::vector<void *> &rawArgs,
mlir::Type resultTy) {
auto launcher = registry::get<ModuleLauncher>("default");
if (!launcher)
throw std::runtime_error(
"No ModuleLauncher registered with name 'default'. This may be a "
"result of attempting to use `launchModule` outside Python.");
ScopedTraceWithContext(cudaq::TIMING_LAUNCH, "QPU::launchModule", name);
auto compiled =
launcher->compileModule(name, module, rawArgs, resultTy, true);
return compiled.execute(rawArgs);
}
void *cudaq::QPU::specializeModule(
const std::string &name, mlir::ModuleOp module,
const std::vector<void *> &rawArgs, mlir::Type resultTy,
std::optional<cudaq::JitEngine> &cachedEngine, bool isEntryPoint) {
auto launcher = registry::get<ModuleLauncher>("default");
if (!launcher)
throw std::runtime_error(
"No ModuleLauncher registered with name 'default'. This may be a "
"result of attempting to use `specializeModule` outside Python.");
ScopedTraceWithContext(cudaq::TIMING_LAUNCH, "QPU::specializeModule", name);
auto compiled =
launcher->compileModule(name, module, rawArgs, resultTy, isEntryPoint);
if (cachedEngine)
throw std::runtime_error("cache must not be populated");
cachedEngine = compiled.getEngine();
return reinterpret_cast<void *>(compiled.getEntryPoint());
}