Skip to content

Commit 1b22544

Browse files
authored
[SYCL][PI][CUDA][HIP] Fix bugs that can cause events not to be waited on (#8374)
Fixes two bug in CUDA PI and HIP PI that can cause waiting for events to do nothing: - The first one is an off-by-one error when checking if an event needs to be waited on - The second one is `last_sync_compute_streams_` / `last_sync_transfer_streams_` to a new value before checking the streams which can read these variables, expecting the old values. Both of these are synchronization related and therefore hard to test for.
1 parent 84fe658 commit 1b22544

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

sycl/plugins/cuda/pi_cuda.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ struct _pi_queue {
476476
if (stream_token == std::numeric_limits<pi_uint32>::max()) {
477477
return false;
478478
}
479-
return last_sync_compute_streams_ >= stream_token;
479+
return last_sync_compute_streams_ > stream_token;
480480
}
481481

482482
bool can_reuse_stream(pi_uint32 stream_token) {
@@ -567,9 +567,6 @@ struct _pi_queue {
567567
unsigned int end = num_compute_streams_ < size
568568
? num_compute_streams_
569569
: compute_stream_idx_.load();
570-
if (ResetUsed) {
571-
last_sync_compute_streams_ = end;
572-
}
573570
if (end - start >= size) {
574571
sync_compute(0, size);
575572
} else {
@@ -582,6 +579,9 @@ struct _pi_queue {
582579
sync_compute(0, end);
583580
}
584581
}
582+
if (ResetUsed) {
583+
last_sync_compute_streams_ = end;
584+
}
585585
}
586586
{
587587
unsigned int size = static_cast<unsigned int>(transfer_streams_.size());
@@ -591,9 +591,6 @@ struct _pi_queue {
591591
unsigned int end = num_transfer_streams_ < size
592592
? num_transfer_streams_
593593
: transfer_stream_idx_.load();
594-
if (ResetUsed) {
595-
last_sync_transfer_streams_ = end;
596-
}
597594
if (end - start >= size) {
598595
sync_transfer(0, size);
599596
} else {
@@ -606,6 +603,9 @@ struct _pi_queue {
606603
sync_transfer(0, end);
607604
}
608605
}
606+
if (ResetUsed) {
607+
last_sync_transfer_streams_ = end;
608+
}
609609
}
610610
}
611611
}

sycl/plugins/hip/pi_hip.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ struct _pi_queue {
457457
if (stream_token == std::numeric_limits<pi_uint32>::max()) {
458458
return false;
459459
}
460-
return last_sync_compute_streams_ >= stream_token;
460+
return last_sync_compute_streams_ > stream_token;
461461
}
462462

463463
bool can_reuse_stream(pi_uint32 stream_token) {
@@ -548,9 +548,6 @@ struct _pi_queue {
548548
unsigned int end = num_compute_streams_ < size
549549
? num_compute_streams_
550550
: compute_stream_idx_.load();
551-
if (ResetUsed) {
552-
last_sync_compute_streams_ = end;
553-
}
554551
if (end - start >= size) {
555552
sync_compute(0, size);
556553
} else {
@@ -563,6 +560,9 @@ struct _pi_queue {
563560
sync_compute(0, end);
564561
}
565562
}
563+
if (ResetUsed) {
564+
last_sync_compute_streams_ = end;
565+
}
566566
}
567567
{
568568
unsigned int size = static_cast<unsigned int>(transfer_streams_.size());
@@ -572,9 +572,6 @@ struct _pi_queue {
572572
unsigned int end = num_transfer_streams_ < size
573573
? num_transfer_streams_
574574
: transfer_stream_idx_.load();
575-
if (ResetUsed) {
576-
last_sync_transfer_streams_ = end;
577-
}
578575
if (end - start >= size) {
579576
sync_transfer(0, size);
580577
} else {
@@ -587,6 +584,9 @@ struct _pi_queue {
587584
sync_transfer(0, end);
588585
}
589586
}
587+
if (ResetUsed) {
588+
last_sync_transfer_streams_ = end;
589+
}
590590
}
591591
}
592592
}

0 commit comments

Comments
 (0)