Skip to content

Commit

Permalink
Fix issue NVIDIA#2541.
Browse files Browse the repository at this point in the history
Workaround for issue NVIDIA#2539.

Signed-off-by: Eric Schweitz <[email protected]>
  • Loading branch information
schweitzpgi committed Jan 24, 2025
1 parent 9490165 commit 57f8c02
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
20 changes: 11 additions & 9 deletions lib/Optimizer/CodeGen/ConvertToQIRAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1815,17 +1815,19 @@ struct QuakeToQIRAPIPrepPass
}

void guaranteeMzIsLabeled(quake::MzOp mz, int &counter, OpBuilder &builder) {
if (!mz.getRegisterNameAttr()) {
// Manufacture a bogus name on demand here.
std::string manuName = std::to_string(counter++);
constexpr std::size_t padSize = 5;
manuName =
std::string(padSize - std::min(padSize, manuName.length()), '0') +
manuName;
mz.setRegisterName("r" + manuName);
} else {
if (mz.getRegisterNameAttr() &&
/* FIXME: issue 2538: the name should never be empty. */
!mz.getRegisterNameAttr().getValue().empty()) {
mz->setAttr(cudaq::opt::MzAssignedNameAttrName, builder.getUnitAttr());
return;
}
// Manufacture a bogus name on demand here.
std::string manuName = std::to_string(counter++);
constexpr std::size_t padSize = 5;
manuName =
std::string(padSize - std::min(padSize, manuName.length()), '0') +
manuName;
mz.setRegisterName("r" + manuName);
}
};

Expand Down
1 change: 1 addition & 0 deletions python/cudaq/kernel/ast_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,7 @@ def isQuantumTy(ty):
ty) or quake.StruqType.isinstance(ty)

areQuantumTypes = [isQuantumTy(ty) for ty in self.argTypes]
f.attributes.__setitem__('cudaq-kernel', UnitAttr.get())
if True not in areQuantumTypes and not self.disableEntryPointTag:
f.attributes.__setitem__('cudaq-entrypoint', UnitAttr.get())

Expand Down
2 changes: 2 additions & 0 deletions runtime/cudaq/builder/kernel_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -887,6 +887,8 @@ void tagEntryPoint(ImplicitLocOpBuilder &builder, ModuleOp &module,
module.walk([&](func::FuncOp function) {
if (function.empty())
return WalkResult::advance();
if (!function->hasAttr(cudaq::kernelAttrName))
function->setAttr(cudaq::kernelAttrName, builder.getUnitAttr());
if (!function->hasAttr(cudaq::entryPointAttrName) &&
!hasAnyQubitTypes(function.getFunctionType()) &&
(symbolName.empty() || function.getSymName().equals(symbolName)))
Expand Down

0 comments on commit 57f8c02

Please sign in to comment.