Skip to content

Commit 3a6c8de

Browse files
[UR][DeviceSanitizer] Do not print error log for unsupported feature in urProgramBuildExp. (#18022)
Co-authored-by: Wu Yingcong <yingcong.wu@intel.com>
1 parent 27dbd12 commit 3a6c8de

File tree

6 files changed

+72
-29
lines changed

6 files changed

+72
-29
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// REQUIRES: linux, cpu || (gpu && level_zero)
2+
// RUN: %{build} %device_asan_flags -o %t.out
3+
// RUN: %{run} %t.out 2>&1 | FileCheck %s
4+
5+
#include <sycl/detail/core.hpp>
6+
7+
void test() {
8+
sycl::queue Q;
9+
sycl::buffer<int> A{1};
10+
Q.submit([&](sycl::handler &h) {
11+
sycl::accessor A_acc(A, h);
12+
13+
h.single_task([=]() { A_acc[0] = 88; });
14+
});
15+
}
16+
17+
// CHECK-NOT: <SANITIZER>[ERROR]: Printing build log for program
18+
19+
int main() {
20+
test();
21+
return 0;
22+
}

unified-runtime/source/loader/layers/sanitizer/asan/asan_ddi.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ __urdlllocal ur_result_t UR_APICALL urProgramBuild(
325325
auto UrRes = pfnProgramBuild(hContext, hProgram, pOptions);
326326
if (UrRes != UR_RESULT_SUCCESS) {
327327
auto Devices = GetDevices(hContext);
328-
PrintUrBuildLog(hProgram, Devices.data(), Devices.size());
328+
PrintUrBuildLogIfError(UrRes, hProgram, Devices.data(), Devices.size());
329329
return UrRes;
330330
}
331331

@@ -355,7 +355,7 @@ __urdlllocal ur_result_t UR_APICALL urProgramBuildExp(
355355

356356
auto UrRes = pfnBuildExp(hProgram, numDevices, phDevices, pOptions);
357357
if (UrRes != UR_RESULT_SUCCESS) {
358-
PrintUrBuildLog(hProgram, phDevices, numDevices);
358+
PrintUrBuildLogIfError(UrRes, hProgram, phDevices, numDevices);
359359
return UrRes;
360360
}
361361

@@ -388,7 +388,7 @@ __urdlllocal ur_result_t UR_APICALL urProgramLink(
388388
auto UrRes = pfnProgramLink(hContext, count, phPrograms, pOptions, phProgram);
389389
if (UrRes != UR_RESULT_SUCCESS) {
390390
auto Devices = GetDevices(hContext);
391-
PrintUrBuildLog(*phProgram, Devices.data(), Devices.size());
391+
PrintUrBuildLogIfError(UrRes, *phProgram, Devices.data(), Devices.size());
392392
return UrRes;
393393
}
394394

@@ -426,7 +426,7 @@ ur_result_t UR_APICALL urProgramLinkExp(
426426
auto UrRes = pfnProgramLinkExp(hContext, numDevices, phDevices, count,
427427
phPrograms, pOptions, phProgram);
428428
if (UrRes != UR_RESULT_SUCCESS) {
429-
PrintUrBuildLog(*phProgram, phDevices, numDevices);
429+
PrintUrBuildLogIfError(UrRes, *phProgram, phDevices, numDevices);
430430
return UrRes;
431431
}
432432

unified-runtime/source/loader/layers/sanitizer/msan/msan_ddi.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ ur_result_t urProgramBuild(
268268
auto UrRes = pfnProgramBuild(hContext, hProgram, pOptions);
269269
if (UrRes != UR_RESULT_SUCCESS) {
270270
auto Devices = GetDevices(hContext);
271-
PrintUrBuildLog(hProgram, Devices.data(), Devices.size());
271+
PrintUrBuildLogIfError(UrRes, hProgram, Devices.data(), Devices.size());
272272
return UrRes;
273273
}
274274

@@ -294,7 +294,7 @@ ur_result_t urProgramBuildExp(
294294

295295
auto UrRes = pfnBuildExp(hProgram, numDevices, phDevices, pOptions);
296296
if (UrRes != UR_RESULT_SUCCESS) {
297-
PrintUrBuildLog(hProgram, phDevices, numDevices);
297+
PrintUrBuildLogIfError(UrRes, hProgram, phDevices, numDevices);
298298
return UrRes;
299299
}
300300

@@ -323,7 +323,7 @@ ur_result_t urProgramLink(
323323
auto UrRes = pfnProgramLink(hContext, count, phPrograms, pOptions, phProgram);
324324
if (UrRes != UR_RESULT_SUCCESS) {
325325
auto Devices = GetDevices(hContext);
326-
PrintUrBuildLog(*phProgram, Devices.data(), Devices.size());
326+
PrintUrBuildLogIfError(UrRes, *phProgram, Devices.data(), Devices.size());
327327
return UrRes;
328328
}
329329

@@ -357,7 +357,7 @@ ur_result_t urProgramLinkExp(
357357
auto UrRes = pfnProgramLinkExp(hContext, numDevices, phDevices, count,
358358
phPrograms, pOptions, phProgram);
359359
if (UrRes != UR_RESULT_SUCCESS) {
360-
PrintUrBuildLog(*phProgram, phDevices, numDevices);
360+
PrintUrBuildLogIfError(UrRes, *phProgram, phDevices, numDevices);
361361
return UrRes;
362362
}
363363

unified-runtime/source/loader/layers/sanitizer/sanitizer_common/sanitizer_utils.cpp

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -256,34 +256,38 @@ ur_result_t EnqueueUSMBlockingSet(ur_queue_handle_t Queue, void *Ptr,
256256
Queue, Ptr, 1, &Value, Size, NumEvents, EventWaitList, OutEvent);
257257
}
258258

259-
void PrintUrBuildLog(ur_program_handle_t hProgram,
260-
ur_device_handle_t *phDevices, size_t numDevices) {
259+
void PrintUrBuildLogIfError(ur_result_t Result, ur_program_handle_t Program,
260+
ur_device_handle_t *Devices, size_t NumDevices) {
261+
if (Result == UR_RESULT_SUCCESS ||
262+
Result == UR_RESULT_ERROR_UNSUPPORTED_FEATURE)
263+
return;
264+
261265
getContext()->logger.error("Printing build log for program {}",
262-
(void *)hProgram);
263-
for (size_t i = 0; i < numDevices; i++) {
266+
(void *)Program);
267+
for (size_t I = 0; I < NumDevices; I++) {
264268
std::vector<char> LogBuf;
265269
size_t LogSize = 0;
266-
auto hDevice = phDevices[i];
270+
auto Device = Devices[I];
267271

268272
auto UrRes = getContext()->urDdiTable.Program.pfnGetBuildInfo(
269-
hProgram, hDevice, UR_PROGRAM_BUILD_INFO_LOG, 0, nullptr, &LogSize);
273+
Program, Device, UR_PROGRAM_BUILD_INFO_LOG, 0, nullptr, &LogSize);
270274
if (UrRes != UR_RESULT_SUCCESS) {
271275
getContext()->logger.error("For device {}: failed to get build log size.",
272-
(void *)hDevice);
276+
(void *)Device);
273277
continue;
274278
}
275279

276280
LogBuf.resize(LogSize);
277281
UrRes = getContext()->urDdiTable.Program.pfnGetBuildInfo(
278-
hProgram, hDevice, UR_PROGRAM_BUILD_INFO_LOG, LogSize, LogBuf.data(),
282+
Program, Device, UR_PROGRAM_BUILD_INFO_LOG, LogSize, LogBuf.data(),
279283
nullptr);
280284
if (UrRes != UR_RESULT_SUCCESS) {
281285
getContext()->logger.error("For device {}: failed to get build log.",
282-
(void *)hDevice);
286+
(void *)Device);
283287
continue;
284288
}
285289

286-
getContext()->logger.error("For device {}:\n{}", (void *)hDevice,
290+
getContext()->logger.error("For device {}:\n{}", (void *)Device,
287291
LogBuf.data());
288292
}
289293
}

unified-runtime/source/loader/layers/sanitizer/sanitizer_common/sanitizer_utils.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ EnqueueUSMBlockingSet(ur_queue_handle_t Queue, void *Ptr, char Value,
6565
const ur_event_handle_t *EventWaitList = nullptr,
6666
ur_event_handle_t *OutEvent = nullptr);
6767

68-
void PrintUrBuildLog(ur_program_handle_t hProgram,
69-
ur_device_handle_t *phDevices, size_t numDevices);
68+
void PrintUrBuildLogIfError(ur_result_t Result, ur_program_handle_t Program,
69+
ur_device_handle_t *Devices, size_t NumDevices);
7070

7171
} // namespace ur_sanitizer_layer

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

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,13 @@ ur_result_t urProgramBuild(
140140
const char *pOptions) {
141141
getContext()->logger.debug("==== urProgramBuild");
142142

143-
UR_CALL(
144-
getContext()->urDdiTable.Program.pfnBuild(hContext, hProgram, pOptions));
143+
auto UrRes =
144+
getContext()->urDdiTable.Program.pfnBuild(hContext, hProgram, pOptions);
145+
if (UrRes != UR_RESULT_SUCCESS) {
146+
auto Devices = GetDevices(hContext);
147+
PrintUrBuildLogIfError(UrRes, hProgram, Devices.data(), Devices.size());
148+
return UrRes;
149+
}
145150

146151
UR_CALL(getTsanInterceptor()->registerProgram(hProgram));
147152

@@ -163,9 +168,13 @@ ur_result_t urProgramLink(
163168
ur_program_handle_t *phProgram) {
164169
getContext()->logger.debug("==== urProgramLink");
165170

166-
UR_CALL(getContext()->urDdiTable.Program.pfnLink(hContext, count, phPrograms,
167-
pOptions, phProgram));
168-
171+
auto UrRes = getContext()->urDdiTable.Program.pfnLink(
172+
hContext, count, phPrograms, pOptions, phProgram);
173+
if (UrRes != UR_RESULT_SUCCESS) {
174+
auto Devices = GetDevices(hContext);
175+
PrintUrBuildLogIfError(UrRes, *phProgram, Devices.data(), Devices.size());
176+
return UrRes;
177+
}
169178
UR_CALL(getTsanInterceptor()->registerProgram(*phProgram));
170179

171180
return UR_RESULT_SUCCESS;
@@ -184,8 +193,12 @@ ur_result_t urProgramBuildExp(
184193
const char *pOptions) {
185194
getContext()->logger.debug("==== urProgramBuildExp");
186195

187-
UR_CALL(getContext()->urDdiTable.ProgramExp.pfnBuildExp(hProgram, numDevices,
188-
phDevices, pOptions));
196+
auto UrRes = getContext()->urDdiTable.ProgramExp.pfnBuildExp(
197+
hProgram, numDevices, phDevices, pOptions);
198+
if (UrRes != UR_RESULT_SUCCESS) {
199+
PrintUrBuildLogIfError(UrRes, hProgram, phDevices, numDevices);
200+
return UrRes;
201+
}
189202
UR_CALL(getTsanInterceptor()->registerProgram(hProgram));
190203

191204
return UR_RESULT_SUCCESS;
@@ -209,8 +222,12 @@ ur_result_t urProgramLinkExp(
209222
ur_program_handle_t *phProgram) {
210223
getContext()->logger.debug("==== urProgramLinkExp");
211224

212-
UR_CALL(getContext()->urDdiTable.ProgramExp.pfnLinkExp(
213-
hContext, numDevices, phDevices, count, phPrograms, pOptions, phProgram));
225+
auto UrRes = getContext()->urDdiTable.ProgramExp.pfnLinkExp(
226+
hContext, numDevices, phDevices, count, phPrograms, pOptions, phProgram);
227+
if (UrRes != UR_RESULT_SUCCESS) {
228+
PrintUrBuildLogIfError(UrRes, *phProgram, phDevices, numDevices);
229+
return UrRes;
230+
}
214231

215232
UR_CALL(getTsanInterceptor()->registerProgram(*phProgram));
216233

0 commit comments

Comments
 (0)