Skip to content

Commit

Permalink
[SYCLomatic] Add support for handling CU_EVENT_* enum (#2513)
Browse files Browse the repository at this point in the history
  • Loading branch information
the-slow-one authored Nov 29, 2024
1 parent 3ecb185 commit de1cfa3
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
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 @@ -2585,6 +2585,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 @@ -2895,6 +2899,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"));
}
return;
}

bool IsAssigned = false;
const CallExpr *CE = getNodeAsType<CallExpr>(Result, "eventAPICall");
if (!CE) {
Expand Down Expand Up @@ -4263,8 +4277,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;
}

0 comments on commit de1cfa3

Please sign in to comment.