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] Add support for handling CU_EVENT_* enum #2513

Merged
merged 5 commits into from
Nov 29, 2024
Merged
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
4 changes: 2 additions & 2 deletions clang/lib/DPCT/Diagnostics/Diagnostics.inc
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ DEF_WARNING(TIME_MEASUREMENT_FOUND, 1012, MEDIUM_LEVEL, "Detected kernel executi
DEF_COMMENT(TIME_MEASUREMENT_FOUND, 1012, MEDIUM_LEVEL, "Detected kernel execution time measurement pattern and generated an initial code for time measurements in SYCL. You can change the way time is measured depending on your goals.")
DEF_WARNING(ROUNDING_MODE_UNSUPPORTED, 1013, MEDIUM_LEVEL, "The rounding mode could not be specified and the generated code may have different accuracy than the original code. Verify the correctness. SYCL math built-in function rounding mode is aligned with OpenCL C 1.2 standard.")
DEF_COMMENT(ROUNDING_MODE_UNSUPPORTED, 1013, MEDIUM_LEVEL, "The rounding mode could not be specified and the generated code may have different accuracy than the original code. Verify the correctness. SYCL math built-in function rounding mode is aligned with OpenCL C 1.2 standard.")
DEF_WARNING(STREAM_FLAG_PRIORITY_NOT_SUPPORTED, 1014, MEDIUM_LEVEL, "The flag and priority options are not supported for SYCL queues. The output parameter(s) are set to 0.")
DEF_COMMENT(STREAM_FLAG_PRIORITY_NOT_SUPPORTED, 1014, MEDIUM_LEVEL, "The flag and priority options are not supported for SYCL queues. The output parameter(s) are set to 0.")
DEF_WARNING(UNSUPPORTED_FEATURE_IN_SYCL, 1014, MEDIUM_LEVEL, "The %0 %1 not supported for SYCL %2. The output parameter(s) %1 set to 0.")
DEF_COMMENT(UNSUPPORTED_FEATURE_IN_SYCL, 1014, MEDIUM_LEVEL, "The {0} {1} not supported for SYCL {2}. The output parameter(s) {1} set to 0.")
DEF_WARNING(PRINTF_FUNC_MIGRATION_WARNING, 1015, LOW_LEVEL, "Output needs adjustment.")
DEF_COMMENT(PRINTF_FUNC_MIGRATION_WARNING, 1015, LOW_LEVEL, "Output needs adjustment.")
DEF_WARNING(NOT_SUPPORTED_PARAMETERS_VALUE, 1016, LOW_LEVEL, "deprecated")
Expand Down
18 changes: 16 additions & 2 deletions clang/lib/DPCT/RulesLang/RulesLang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2569,6 +2569,10 @@ void EventAPICallRule::registerMatcher(MatchFinder &MF) {
unless(parentStmt())))
.bind("eventAPICallUsed"),
this);
MF.addMatcher(declRefExpr(to(enumConstantDecl(hasType(
enumDecl(hasName("CUevent_flags_enum"))))))
.bind("eventEnum"),
this);
}

bool isEqualOperator(const Stmt *S) {
Expand Down Expand Up @@ -2879,6 +2883,16 @@ bool EventAPICallRule::isEventElapsedTimeFollowed(const CallExpr *Expr) {
}

void EventAPICallRule::runRule(const MatchFinder::MatchResult &Result) {
if (auto *DRE = getNodeAsType<DeclRefExpr>(Result, "eventEnum")) {
if (auto *EC = dyn_cast<EnumConstantDecl>(DRE->getDecl())) {
std::string EName = EC->getName().str();
report(DRE->getBeginLoc(), Diagnostics::UNSUPPORTED_FEATURE_IN_SYCL,
false, EName, "is", "event");
emplaceTransformation(new ReplaceStmt(DRE, "0"));
}
ziranzha marked this conversation as resolved.
Show resolved Hide resolved
return;
}

bool IsAssigned = false;
const CallExpr *CE = getNodeAsType<CallExpr>(Result, "eventAPICall");
if (!CE) {
Expand Down Expand Up @@ -4247,8 +4261,8 @@ void StreamAPICallRule::runRule(const MatchFinder::MatchResult &Result) {
emplaceTransformation(new ReplaceStmt(CE, ReplStr));
} else if (FuncName == "cudaStreamGetFlags" ||
FuncName == "cudaStreamGetPriority") {
report(CE->getBeginLoc(), Diagnostics::STREAM_FLAG_PRIORITY_NOT_SUPPORTED,
false);
report(CE->getBeginLoc(), Diagnostics::UNSUPPORTED_FEATURE_IN_SYCL, false,
"flag and priority options", "are", "queues");
auto StmtStr1 = getStmtSpelling(CE->getArg(1));
std::string ReplStr{"*("};
ReplStr += StmtStr1;
Expand Down
17 changes: 17 additions & 0 deletions clang/test/dpct/driver-stream-and-event.cu
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,20 @@ void test_cuEventRecord_crash(CUevent hEvent, CUstream hStream)
// CHECK: int result = DPCT_CHECK_ERROR(*(dpct::event_ptr)hEvent = ((dpct::queue_ptr)hStream)->ext_oneapi_submit_barrier());
CUresult result = cuEventRecord((CUevent)hEvent, (CUstream)hStream);
}

unsigned getEventFlags(bool enabledSyncBlock) {
// CHECK: /*
// CHECK-NEXT: DPCT1014:{{[0-9]+}}: The CU_EVENT_DISABLE_TIMING is not supported for SYCL event. The output parameter(s) is set to 0.
// CHECK-NEXT: */
// CHECK-NEXT: unsigned flags = 0;
unsigned flags = CU_EVENT_DISABLE_TIMING;

if (enabledSyncBlock)
// CHECK: /*
// CHECK-NEXT: DPCT1014:{{[0-9]+}}: The CU_EVENT_BLOCKING_SYNC is not supported for SYCL event. The output parameter(s) is set to 0.
// CHECK-NEXT: */
// CHECK-NEXT: flags |= 0;
flags |= CU_EVENT_BLOCKING_SYNC;

return flags;
}