Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SYCLomatic] Resolve explicit typecasting of first argument in cuMemHostGetDevicePointer call #2526

Open
wants to merge 5 commits into
base: SYCLomatic
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions clang/lib/DPCT/RuleInfra/CallExprRewriterCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,35 @@ inline std::function<std::string(const CallExpr *C)> getDerefedType(size_t Idx)
};
}

inline std::function<std::string(const CallExpr *C)>
getReplacedTypeNameForDerefExpr(size_t Idx) {
return [=](const CallExpr *C) -> std::string {
if (Idx >= C->getNumArgs())
return "";

const auto *ArgExpr = C->getArg(Idx);
QualType ArgExprType = ArgExpr->getType();

if (auto *CSCE =
dyn_cast<ExplicitCastExpr>(ArgExpr->IgnoreImplicitAsWritten()))
ArgExprType = CSCE->getTypeAsWritten();

while (const auto *ET = dyn_cast<ElaboratedType>(ArgExprType)) {
ArgExprType = ET->getNamedType();
if (const auto *TDT = dyn_cast<TypedefType>(ArgExprType)) {
if (isRedeclInCUDAHeader(TDT))
break;
ArgExprType = TDT->getDecl()->getUnderlyingType();
}
}

ArgExprType = DerefQualType(ArgExprType);
return ArgExprType.isNull()
? ""
: DpctGlobalInfo::getReplacedTypeName(ArgExprType);
};
}

inline std::function<std::string(const CallExpr *)> getTemplateArg(size_t Idx) {
return [=](const CallExpr *C) -> std::string {
std::string TemplateArgStr = "";
Expand Down
3 changes: 2 additions & 1 deletion clang/lib/DPCT/RulesLang/APINamesMemory.inc
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@ ASSIGNABLE_FACTORY(ASSIGN_FACTORY_ENTRY("cudaHostGetDevicePointer",

ASSIGNABLE_FACTORY(ASSIGN_FACTORY_ENTRY("cuMemHostGetDevicePointer_v2",
DEREF(makeCallArgCreatorWithCall(0)),
CAST(getDerefedType(0), ARG(1))))
CAST(getReplacedTypeNameForDerefExpr(0),
ARG(1))))

ASSIGNABLE_FACTORY(CONDITIONAL_FACTORY_ENTRY(
checkIsUSM(),
Expand Down
4 changes: 4 additions & 0 deletions clang/test/dpct/USM-restricted.cu
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,10 @@ void foo() {
// CHECK: MY_SAFE_CALL(DPCT_CHECK_ERROR(*D_ptr = (dpct::device_ptr)h_A));
MY_SAFE_CALL(cuMemHostGetDevicePointer(D_ptr, h_A, 0));

unsigned long long addr;
// CHECK: *(dpct::device_ptr *)&addr = (dpct::device_ptr)h_A;
cuMemHostGetDevicePointer((CUdeviceptr *)&addr, h_A, 0);

cudaHostRegister(h_A, size, 0);
// CHECK: errorCode = 0;
errorCode = cudaHostRegister(h_A, size, 0);
Expand Down