Skip to content

Commit f8df2bd

Browse files
authored
Merge branch 'main' into use-zstd-layers
2 parents 373f608 + 25a4edd commit f8df2bd

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

lib/Frontend/nvqpp/ConvertDecl.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,8 +536,28 @@ bool QuakeBridgeVisitor::VisitFunctionDecl(clang::FunctionDecl *x) {
536536
auto typeFromStack = peelPointerFromFunction(popType());
537537
if (auto f = module.lookupSymbol<func::FuncOp>(kernSym)) {
538538
auto fTy = f.getFunctionType();
539-
assert(typeFromStack == fTy);
540539
auto fSym = f.getSymNameAttr();
540+
if (typeFromStack != fTy) {
541+
// This may be a call to an entry-point kernel. Determine if that is the
542+
// case, and convert this to a direct call. Otherwise, this an calling
543+
// convention violation.
544+
bool found = false;
545+
for (auto pair : namesMap)
546+
if (pair.second == kernName) {
547+
if (auto f = module.lookupSymbol<func::FuncOp>(pair.first)) {
548+
fTy = f.getFunctionType();
549+
fSym = f.getSymNameAttr();
550+
found = true;
551+
}
552+
break;
553+
}
554+
if (!found) {
555+
reportClangError(
556+
x, mangler,
557+
"invalid call from kernel: calling convention violation");
558+
return false;
559+
}
560+
}
541561
return pushValue(builder.create<func::ConstantOp>(loc, fTy, fSym));
542562
}
543563
auto [funcOp, alreadyAdded] = getOrAddFunc(loc, kernName, typeFromStack);
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2025 NVIDIA Corporation & Affiliates. *
3+
* All rights reserved. *
4+
* *
5+
* This source code and the accompanying materials are made available under *
6+
* the terms of the Apache License 2.0 which accompanies this distribution. *
7+
******************************************************************************/
8+
9+
// RUN: cudaq-quake %cpp_std %s | cudaq-opt | FileCheck %s
10+
11+
#include "cudaq.h"
12+
13+
__qpu__ uint64_t otherKernel(std::vector<cudaq::measure_result> &x);
14+
15+
__qpu__ uint64_t test_entry_point() {
16+
cudaq::qvector q(5);
17+
auto results = cudaq::mz(q);
18+
return otherKernel(results);
19+
}
20+
21+
// CHECK-LABEL: func.func @__nvqpp__mlirgen__function_test_entry_point.
22+
// CHECK-SAME: () -> i64 attributes {"cudaq-entrypoint", "cudaq-kernel", no_this} {
23+
// CHECK: %[[VAL_3:.*]] = call @__nvqpp__mlirgen__function_otherKernel.{{.*}}(%{{.*}}) : (!cc.stdvec<i1>) -> i64

0 commit comments

Comments
 (0)