@@ -201,11 +201,118 @@ ur_result_t urProgramLink(
201201 PrintUrBuildLogIfError (UrRes, *phProgram, Devices.data (), Devices.size ());
202202 return UrRes;
203203 }
204+ UR_CALL (getTsanInterceptor ()->insertProgram (*phProgram));
204205 UR_CALL (getTsanInterceptor ()->registerProgram (*phProgram));
205206
206207 return UR_RESULT_SUCCESS;
207208}
208209
210+ // /////////////////////////////////////////////////////////////////////////////
211+ // / @brief Intercept function for urProgramCreateWithIL
212+ __urdlllocal ur_result_t UR_APICALL urProgramCreateWithIL (
213+ // / [in] handle of the context instance
214+ ur_context_handle_t hContext,
215+ // / [in] pointer to IL binary.
216+ const void *pIL,
217+ // / [in] length of `pIL` in bytes.
218+ size_t length,
219+ // / [in][optional] pointer to program creation properties.
220+ const ur_program_properties_t *pProperties,
221+ // / [out] pointer to handle of program object created.
222+ ur_program_handle_t *phProgram) {
223+ UR_LOG_L (getContext ()->logger , DEBUG, " ==== urProgramCreateWithIL" );
224+
225+ UR_CALL (getContext ()->urDdiTable .Program .pfnCreateWithIL (
226+ hContext, pIL, length, pProperties, phProgram));
227+ UR_CALL (getTsanInterceptor ()->insertProgram (*phProgram));
228+
229+ return UR_RESULT_SUCCESS;
230+ }
231+
232+ // /////////////////////////////////////////////////////////////////////////////
233+ // / @brief Intercept function for urProgramCreateWithBinary
234+ __urdlllocal ur_result_t UR_APICALL urProgramCreateWithBinary (
235+ // / [in] handle of the context instance
236+ ur_context_handle_t hContext,
237+ // / [in] number of devices
238+ uint32_t numDevices,
239+ // / [in][range(0, numDevices)] a pointer to a list of device handles.
240+ // / The binaries are loaded for devices specified in this list.
241+ ur_device_handle_t *phDevices,
242+ // / [in][range(0, numDevices)] array of sizes of program binaries specified
243+ // / by `pBinaries` (in bytes).
244+ size_t *pLengths,
245+ // / [in][range(0, numDevices)] pointer to program binaries to be loaded
246+ // / for devices specified by `phDevices`.
247+ const uint8_t **ppBinaries,
248+ // / [in][optional] pointer to program creation properties.
249+ const ur_program_properties_t *pProperties,
250+ // / [out] pointer to handle of Program object created.
251+ ur_program_handle_t *phProgram) {
252+ UR_LOG_L (getContext ()->logger , DEBUG, " ==== urProgramCreateWithBinary" );
253+
254+ UR_CALL (getContext ()->urDdiTable .Program .pfnCreateWithBinary (
255+ hContext, numDevices, phDevices, pLengths, ppBinaries, pProperties,
256+ phProgram));
257+ UR_CALL (getTsanInterceptor ()->insertProgram (*phProgram));
258+
259+ return UR_RESULT_SUCCESS;
260+ }
261+
262+ // /////////////////////////////////////////////////////////////////////////////
263+ // / @brief Intercept function for urProgramCreateWithNativeHandle
264+ __urdlllocal ur_result_t UR_APICALL urProgramCreateWithNativeHandle (
265+ // / [in][nocheck] the native handle of the program.
266+ ur_native_handle_t hNativeProgram,
267+ // / [in] handle of the context instance
268+ ur_context_handle_t hContext,
269+ // / [in][optional] pointer to native program properties struct.
270+ const ur_program_native_properties_t *pProperties,
271+ // / [out] pointer to the handle of the program object created.
272+ ur_program_handle_t *phProgram) {
273+ UR_LOG_L (getContext ()->logger , DEBUG, " ==== urProgramCreateWithNativeHandle" );
274+
275+ UR_CALL (getContext ()->urDdiTable .Program .pfnCreateWithNativeHandle (
276+ hNativeProgram, hContext, pProperties, phProgram));
277+ UR_CALL (getTsanInterceptor ()->insertProgram (*phProgram));
278+
279+ return UR_RESULT_SUCCESS;
280+ }
281+
282+ // /////////////////////////////////////////////////////////////////////////////
283+ // / @brief Intercept function for urProgramRetain
284+ __urdlllocal ur_result_t UR_APICALL urProgramRetain (
285+ ur_program_handle_t
286+ // / [in][retain] handle for the Program to retain
287+ hProgram) {
288+ UR_LOG_L (getContext ()->logger , DEBUG, " ==== urProgramRetain" );
289+
290+ UR_CALL (getContext ()->urDdiTable .Program .pfnRetain (hProgram));
291+
292+ auto &ProgramInfo = getTsanInterceptor ()->getProgramInfo (hProgram);
293+ ProgramInfo.RefCount ++;
294+
295+ return UR_RESULT_SUCCESS;
296+ }
297+
298+ // /////////////////////////////////////////////////////////////////////////////
299+ // / @brief Intercept function for urProgramRelease
300+ ur_result_t UR_APICALL urProgramRelease (
301+ // / [in][release] handle for the Program to release
302+ ur_program_handle_t hProgram) {
303+ UR_LOG_L (getContext ()->logger , DEBUG, " ==== urProgramRelease" );
304+
305+ UR_CALL (getContext ()->urDdiTable .Program .pfnRelease (hProgram));
306+
307+ auto &ProgramInfo = getTsanInterceptor ()->getProgramInfo (hProgram);
308+ if (--ProgramInfo.RefCount == 0 ) {
309+ UR_CALL (getTsanInterceptor ()->unregisterProgram (hProgram));
310+ UR_CALL (getTsanInterceptor ()->eraseProgram (hProgram));
311+ }
312+
313+ return UR_RESULT_SUCCESS;
314+ }
315+
209316// /////////////////////////////////////////////////////////////////////////////
210317// / @brief Intercept function for urProgramBuildExp
211318ur_result_t urProgramBuildExp (
@@ -255,6 +362,7 @@ ur_result_t urProgramLinkExp(
255362 return UrRes;
256363 }
257364
365+ UR_CALL (getTsanInterceptor ()->insertProgram (*phProgram));
258366 UR_CALL (getTsanInterceptor ()->registerProgram (*phProgram));
259367
260368 return UR_RESULT_SUCCESS;
@@ -1157,6 +1265,18 @@ __urdlllocal ur_result_t UR_APICALL urUSMSharedAlloc(
11571265 hContext, hDevice, pUSMDesc, pool, size, AllocType::SHARED_USM, ppMem);
11581266}
11591267
1268+ // /////////////////////////////////////////////////////////////////////////////
1269+ // / @brief Intercept function for urUSMFree
1270+ __urdlllocal ur_result_t UR_APICALL urUSMFree (
1271+ // / [in] handle of the context object
1272+ ur_context_handle_t hContext,
1273+ // / [in] pointer to USM memory object
1274+ void *pMem) {
1275+ UR_LOG_L (getContext ()->logger , DEBUG, " ==== urUSMFree" );
1276+
1277+ return getTsanInterceptor ()->releaseMemory (hContext, pMem);
1278+ }
1279+
11601280// /////////////////////////////////////////////////////////////////////////////
11611281// / @brief Intercept function for urEnqueueKernelLaunch
11621282ur_result_t urEnqueueKernelLaunch (
@@ -1285,6 +1405,13 @@ ur_result_t urGetProgramProcAddrTable(
12851405 return UR_RESULT_ERROR_INVALID_NULL_POINTER;
12861406 }
12871407
1408+ pDdiTable->pfnCreateWithIL = ur_sanitizer_layer::tsan::urProgramCreateWithIL;
1409+ pDdiTable->pfnCreateWithBinary =
1410+ ur_sanitizer_layer::tsan::urProgramCreateWithBinary;
1411+ pDdiTable->pfnCreateWithNativeHandle =
1412+ ur_sanitizer_layer::tsan::urProgramCreateWithNativeHandle;
1413+ pDdiTable->pfnRetain = ur_sanitizer_layer::tsan::urProgramRetain;
1414+ pDdiTable->pfnRelease = ur_sanitizer_layer::tsan::urProgramRelease;
12881415 pDdiTable->pfnBuild = ur_sanitizer_layer::tsan::urProgramBuild;
12891416 pDdiTable->pfnLink = ur_sanitizer_layer::tsan::urProgramLink;
12901417
@@ -1380,6 +1507,7 @@ __urdlllocal ur_result_t UR_APICALL urGetUSMProcAddrTable(
13801507 pDdiTable->pfnDeviceAlloc = ur_sanitizer_layer::tsan::urUSMDeviceAlloc;
13811508 pDdiTable->pfnHostAlloc = ur_sanitizer_layer::tsan::urUSMHostAlloc;
13821509 pDdiTable->pfnSharedAlloc = ur_sanitizer_layer::tsan::urUSMSharedAlloc;
1510+ pDdiTable->pfnFree = ur_sanitizer_layer::tsan::urUSMFree;
13831511
13841512 return UR_RESULT_SUCCESS;
13851513}
0 commit comments