From 5106fbeb5dcf3d18adf734598ee7918f4ba48c80 Mon Sep 17 00:00:00 2001 From: Vipul Cariappa Date: Wed, 5 Nov 2025 09:38:56 +0100 Subject: [PATCH] add `IsCUDAFunction` & `AdaptCUDAFunction` --- clingwrapper/src/clingwrapper.cxx | 31 ++++++++++++++++++++++++++++++- clingwrapper/src/cpp_cppyy.h | 4 ++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/clingwrapper/src/clingwrapper.cxx b/clingwrapper/src/clingwrapper.cxx index 6df99240..e3895eed 100644 --- a/clingwrapper/src/clingwrapper.cxx +++ b/clingwrapper/src/clingwrapper.cxx @@ -1105,9 +1105,13 @@ bool Cppyy::IsNamespace(TCppScope_t scope) return Cpp::IsNamespace(scope) || Cpp::GetGlobalScope() == scope; } +bool Cppyy::IsCUDAFunction(TCppScope_t scope) +{ + return Cpp::IsCUDAFunction(scope); +} + bool Cppyy::IsClass(TCppScope_t scope) { - // Test if this scope represents a namespace. return Cpp::IsClass(scope); } // @@ -1851,6 +1855,31 @@ Cppyy::TCppScope_t Cppyy::WrapLambdaFromVariable(TCppScope_t var) { return var; } +void Cppyy::AdaptCUDAFunction(TCppScope_t fn) { + std::string fn_name = Cpp::GetQualifiedCompleteName(fn); + std::string signature = Cppyy::GetMethodSignature(fn, true); + + std::ostringstream call; + call << "("; + for (size_t i = 0, n = Cppyy::GetMethodNumArgs(fn); i < n; i++) { + call << Cppyy::GetMethodArgName(fn, i); + if (i != n - 1) + call << ", "; + } + call << ")"; + + std::ostringstream code; + static int i = 0; + code + << "template \n" + << "auto " << fn_name << signature << "{" << " return " << fn_name << "<<<_X, _Y>>>" << call.str() << "; }\n"; + Cppyy::Compile(code.str().c_str()); + // if (Cppyy::Compile(code.str().c_str())) { + // TCppScope_t res = Cpp::GetNamed(fn_name, Cpp::GetScope("__cppjit_internal_wrap_g")); + // if (res) return res; + // } + // return fn; +} Cppyy::TCppScope_t Cppyy::AdaptFunctionForLambdaReturn(TCppScope_t fn) { std::string fn_name = Cpp::GetQualifiedCompleteName(fn); std::string signature = Cppyy::GetMethodSignature(fn, true); diff --git a/clingwrapper/src/cpp_cppyy.h b/clingwrapper/src/cpp_cppyy.h index 80acf04f..4180762b 100644 --- a/clingwrapper/src/cpp_cppyy.h +++ b/clingwrapper/src/cpp_cppyy.h @@ -203,6 +203,8 @@ namespace Cppyy { RPY_EXPORTED bool IsNamespace(TCppScope_t scope); RPY_EXPORTED + bool IsCUDAFunction(TCppScope_t scope); + RPY_EXPORTED bool IsClass(TCppScope_t scope); RPY_EXPORTED bool IsTemplate(TCppScope_t scope); @@ -363,6 +365,8 @@ namespace Cppyy { RPY_EXPORTED TCppScope_t WrapLambdaFromVariable(TCppScope_t var); RPY_EXPORTED + void AdaptCUDAFunction(TCppScope_t fn); + RPY_EXPORTED TCppScope_t AdaptFunctionForLambdaReturn(TCppScope_t fn); RPY_EXPORTED TCppType_t GetDatamemberType(TCppScope_t data);