Skip to content

Commit bb3e585

Browse files
authored
[DevTSAN] Do early return if kernel has no data race reports (#19133)
Sync runtime data from device to host will cost a lot of time, so we'd better check if kernel has reports first to avoid unnecessary data sync.
1 parent 6deac70 commit bb3e585

File tree

4 files changed

+19
-10
lines changed

4 files changed

+19
-10
lines changed

unified-runtime/source/loader/layers/sanitizer/tsan/tsan_interceptor.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,17 @@ ur_result_t TsanRuntimeDataWrapper::syncToDevice(ur_queue_handle_t Queue) {
6161
return UR_RESULT_SUCCESS;
6262
}
6363

64+
bool TsanRuntimeDataWrapper::hasReport(ur_queue_handle_t Queue) {
65+
ur_result_t URes = getContext()->urDdiTable.Enqueue.pfnUSMMemcpy(
66+
Queue, true, ur_cast<void *>(&Host), getDevicePtr(),
67+
sizeof(TsanRuntimeData::RecordedReportCount), 0, nullptr, nullptr);
68+
if (URes != UR_RESULT_SUCCESS) {
69+
UR_LOG(ERR, "Failed to sync runtime data to host: {}", URes);
70+
return false;
71+
}
72+
return Host.RecordedReportCount != 0;
73+
}
74+
6475
ur_result_t TsanRuntimeDataWrapper::importLocalArgsInfo(
6576
ur_queue_handle_t Queue, const std::vector<TsanLocalArgsInfo> &LocalArgs) {
6677
assert(!LocalArgs.empty());
@@ -310,6 +321,9 @@ ur_result_t TsanInterceptor::postLaunchKernel(ur_kernel_handle_t Kernel,
310321
// urEventSetCallback
311322
UR_CALL(getContext()->urDdiTable.Queue.pfnFinish(Queue));
312323

324+
if (!LaunchInfo.Data.hasReport(Queue))
325+
return UR_RESULT_SUCCESS;
326+
313327
UR_CALL(LaunchInfo.Data.syncFromDevice(Queue));
314328

315329
for (uptr ReportIndex = 0;

unified-runtime/source/loader/layers/sanitizer/tsan/tsan_interceptor.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ struct TsanRuntimeDataWrapper {
133133

134134
ur_result_t syncToDevice(ur_queue_handle_t Queue);
135135

136+
bool hasReport(ur_queue_handle_t Queue);
137+
136138
ur_result_t
137139
importLocalArgsInfo(ur_queue_handle_t Queue,
138140
const std::vector<TsanLocalArgsInfo> &LocalArgs);

unified-runtime/source/loader/layers/sanitizer/tsan/tsan_libdevice.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ struct TsanLocalArgsInfo {
8282
constexpr uint64_t TSAN_MAX_NUM_REPORTS = 128;
8383

8484
struct TsanRuntimeData {
85+
uint32_t RecordedReportCount = 0;
86+
8587
uintptr_t GlobalShadowOffset = 0;
8688

8789
uintptr_t GlobalShadowOffsetEnd = 0;
@@ -103,8 +105,6 @@ struct TsanRuntimeData {
103105

104106
int Lock = 0;
105107

106-
uint32_t RecordedReportCount = 0;
107-
108108
TsanErrorReport Report[TSAN_MAX_NUM_REPORTS];
109109
};
110110

unified-runtime/source/loader/layers/sanitizer/tsan/tsan_shadow.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -169,19 +169,12 @@ ur_result_t ShadowMemoryGPU::CleanShadow(ur_queue_handle_t Queue, uptr Ptr,
169169
UR_LOG_L(getContext()->logger, DEBUG, "urVirtualMemMap: {} ~ {}",
170170
(void *)MappedPtr, (void *)(MappedPtr + PageSize - 1));
171171

172-
// Initialize to zero
173-
URes = EnqueueUSMSet(Queue, (void *)MappedPtr, (char)0, PageSize);
174-
if (URes != UR_RESULT_SUCCESS) {
175-
UR_LOG_L(getContext()->logger, ERR, "EnqueueUSMBlockingSet(): {}",
176-
URes);
177-
return URes;
178-
}
179-
180172
VirtualMemMaps[MappedPtr] = PhysicalMem;
181173
}
182174
}
183175
}
184176

177+
// Initialize to zero
185178
auto URes = EnqueueUSMSet(Queue, (void *)Begin, (char)0,
186179
Size / kShadowCell * kShadowCnt * kShadowSize);
187180
if (URes != UR_RESULT_SUCCESS) {

0 commit comments

Comments
 (0)