Skip to content

Commit 7e52cd5

Browse files
author
the-slow-one
authored
[SYCLomatic] Fix casting bug while migrating cuEventElapsedTime arguments (#2688)
Signed-off-by: Deepak Raj H R <deepak.raj.h.r@intel.com>
1 parent 2da52e5 commit 7e52cd5

2 files changed

Lines changed: 26 additions & 6 deletions

File tree

clang/lib/DPCT/RulesLang/RulesLang.cpp

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3557,8 +3557,6 @@ void EventAPICallRule::handleEventElapsedTime(bool IsAssigned) {
35573557
if(DpctGlobalInfo::getEnablepProfilingFlag()) {
35583558
// Option '--enable-profiling' is enabled
35593559
auto StmtStrArg0 = getStmtSpelling(TimeElapsedCE->getArg(0));
3560-
auto StmtStrArg1 = getStmtSpelling(TimeElapsedCE->getArg(1));
3561-
auto StmtStrArg2 = getStmtSpelling(TimeElapsedCE->getArg(2));
35623560

35633561
std::ostringstream Repl;
35643562
std::string Assginee = "*(" + StmtStrArg0 + ")";
@@ -3567,10 +3565,27 @@ void EventAPICallRule::handleEventElapsedTime(bool IsAssigned) {
35673565
Assginee = getStmtSpelling(UO->getSubExpr());
35683566
}
35693567

3570-
auto StartTimeStr = StmtStrArg1 + "->get_profiling_info<"
3571-
"sycl::info::event_profiling::command_start>()";
3572-
auto StopTimeStr = StmtStrArg2 + "->get_profiling_info<"
3573-
"sycl::info::event_profiling::command_end>()";
3568+
const auto *StartArg = TimeElapsedCE->getArg(1)->IgnoreImpCasts();
3569+
const auto *EndArg = TimeElapsedCE->getArg(2)->IgnoreImpCasts();
3570+
3571+
ExprAnalysis EAForStartArg(StartArg);
3572+
ExprAnalysis EAForEndArg(EndArg);
3573+
3574+
auto StartArgRepl = EAForStartArg.getReplacedString();
3575+
auto EndArgRepl = EAForEndArg.getReplacedString();
3576+
3577+
if (isa<CStyleCastExpr>(StartArg) || isa<CXXReinterpretCastExpr>(StartArg))
3578+
StartArgRepl = "(" + StartArgRepl + ")";
3579+
3580+
if (isa<CStyleCastExpr>(EndArg) || isa<CXXReinterpretCastExpr>(EndArg))
3581+
EndArgRepl = "(" + EndArgRepl + ")";
3582+
3583+
auto StartTimeStr = StartArgRepl +
3584+
"->get_profiling_info<"
3585+
"sycl::info::event_profiling::command_start>()";
3586+
auto StopTimeStr = EndArgRepl +
3587+
"->get_profiling_info<"
3588+
"sycl::info::event_profiling::command_end>()";
35743589

35753590
Repl << Assginee << " = ("
35763591
<< StopTimeStr << " - " << StartTimeStr << ") / 1000000.0f";

clang/test/dpct/driver-stream-and-event-enable-profiling.cu

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,8 @@ std::vector<cudaEvent_t> cuda_gpu_benchmark_stop_times;
6060
void foo(int idx) {
6161
cudaEventRecord(cuda_gpu_benchmark_stop_times[idx], 0);
6262
}
63+
64+
void test_with_cast(float timeTaken, unsigned long long start, unsigned long long end) {
65+
// CHECK: timeTaken = ((reinterpret_cast<dpct::event_ptr>(end))->get_profiling_info<sycl::info::event_profiling::command_end>() - ((dpct::event_ptr)start)->get_profiling_info<sycl::info::event_profiling::command_start>()) / 1000000.0f;
66+
cuEventElapsedTime(&timeTaken, (CUevent)start, reinterpret_cast<CUevent>(end));
67+
}

0 commit comments

Comments
 (0)