@@ -305,11 +305,28 @@ ur_result_t ur_platform_handle_t_::initialize() {
305305 zeDriverExtensionMap[extension.name ] = extension.version ;
306306 }
307307
308- const auto GraphExtension =
308+ const auto StableGraphExtension =
309309 zeDriverExtensionMap.find (ZE_RECORD_REPLAY_GRAPH_EXT_NAME );
310+ const bool ZeStableGraphExtensionSupported =
311+ StableGraphExtension != zeDriverExtensionMap.end () &&
312+ StableGraphExtension->second >= ZE_RECORD_REPLAY_GRAPH_EXT_VERSION_1_0 ;
313+
314+ // Fallback for drivers that have not yet adopted the stable record & replay
315+ // graph extension and still expose only the experimental variant. The
316+ // experimental extension uses different entry-point names (Exp suffix) and a
317+ // different parameter order for a few functions; both differences are handled
318+ // when the function pointers are populated below.
319+ constexpr char ZeRecordReplayGraphExpName[] =
320+ " ZE_experimental_record_replay_graph" ;
321+ const auto ExpGraphExtension =
322+ zeDriverExtensionMap.find (ZeRecordReplayGraphExpName);
323+ const bool ZeExpGraphExtensionSupported =
324+ !ZeStableGraphExtensionSupported &&
325+ ExpGraphExtension != zeDriverExtensionMap.end () &&
326+ ExpGraphExtension->second >= ZE_MAKE_VERSION (1 , 0 );
327+
310328 const bool ZeGraphExtensionSupported =
311- GraphExtension != zeDriverExtensionMap.end () &&
312- GraphExtension->second >= ZE_RECORD_REPLAY_GRAPH_EXT_VERSION_1_0 ;
329+ ZeStableGraphExtensionSupported || ZeExpGraphExtensionSupported;
313330
314331 ZE2UR_CALL (zelLoaderTranslateHandle, (ZEL_HANDLE_DRIVER , ZeDriver,
315332 (void **)&ZeDriverHandleExpTranslated));
@@ -568,37 +585,66 @@ ur_result_t ur_platform_handle_t_::initialize() {
568585 ZeMemGetPitchFor2dImageExt.zeMemGetPitchFor2dImage != nullptr ;
569586
570587 if (ZeGraphExtensionSupported) {
571- // Populate Graph Extension structure. Mandatory graph functions.
588+ const bool UseExp = ZeExpGraphExtensionSupported;
589+ ZeGraphExt.UsesLegacyExperimentalApi = UseExp;
590+
591+ // Populate Graph Extension structure. Mandatory graph functions whose
592+ // signature is identical between the stable and experimental variants;
593+ // only the entry-point name (Exp vs Ext suffix) differs.
572594 std::unordered_map<std::string, void **> ZeGraphFuncNameToAddrMap = {
573- {" zeGraphCreateExt" ,
574- reinterpret_cast <void **>(&ZeGraphExt.zeGraphCreateExp )},
575- {" zeCommandListBeginGraphCaptureExt" ,
595+ {UseExp ? " zeCommandListBeginGraphCaptureExp"
596+ : " zeCommandListBeginGraphCaptureExt" ,
576597 reinterpret_cast <void **>(
577598 &ZeGraphExt.zeCommandListBeginGraphCaptureExp )},
578- {" zeCommandListBeginCaptureIntoGraphExt" ,
599+ {UseExp ? " zeCommandListBeginCaptureIntoGraphExp"
600+ : " zeCommandListBeginCaptureIntoGraphExt" ,
579601 reinterpret_cast <void **>(
580602 &ZeGraphExt.zeCommandListBeginCaptureIntoGraphExp )},
581- {" zeCommandListEndGraphCaptureExt" ,
582- reinterpret_cast <void **>(
583- &ZeGraphExt.zeCommandListEndGraphCaptureExp )},
584- {" zeGraphInstantiateExt" ,
585- reinterpret_cast <void **>(
586- &ZeGraphExt.zeCommandListInstantiateGraphExp )},
587- {" zeCommandListAppendGraphExt" ,
603+ {UseExp ? " zeCommandListAppendGraphExp" : " zeCommandListAppendGraphExt" ,
588604 reinterpret_cast <void **>(&ZeGraphExt.zeCommandListAppendGraphExp )},
589- {" zeGraphDestroyExt" ,
605+ {UseExp ? " zeGraphDestroyExp " : " zeGraphDestroyExt" ,
590606 reinterpret_cast <void **>(&ZeGraphExt.zeGraphDestroyExp )},
591- {" zeExecutableGraphDestroyExt" ,
607+ {UseExp ? " zeExecutableGraphDestroyExp " : " zeExecutableGraphDestroyExt" ,
592608 reinterpret_cast <void **>(&ZeGraphExt.zeExecutableGraphDestroyExp )},
593- {" zeCommandListIsGraphCaptureEnabledExt" ,
609+ {UseExp ? " zeCommandListIsGraphCaptureEnabledExp"
610+ : " zeCommandListIsGraphCaptureEnabledExt" ,
594611 reinterpret_cast <void **>(
595612 &ZeGraphExt.zeCommandListIsGraphCaptureEnabledExp )},
596- {" zeGraphIsEmptyExt" ,
613+ {UseExp ? " zeGraphIsEmptyExp " : " zeGraphIsEmptyExt" ,
597614 reinterpret_cast <void **>(&ZeGraphExt.zeGraphIsEmptyExp )},
598- {" zeGraphDumpContentsExt" ,
615+ {UseExp ? " zeGraphDumpContentsExp " : " zeGraphDumpContentsExt" ,
599616 reinterpret_cast <void **>(&ZeGraphExt.zeGraphDumpContentsExp )},
600617 };
601618
619+ // Mandatory functions whose parameter order differs between the variants.
620+ // They are loaded into variant-specific fields and dispatched through the
621+ // wrapper helpers on ZeGraphExtension.
622+ if (UseExp) {
623+ ZeGraphFuncNameToAddrMap.emplace (
624+ " zeGraphCreateExp" ,
625+ reinterpret_cast <void **>(&ZeGraphExt.zeGraphCreateExpLegacy ));
626+ ZeGraphFuncNameToAddrMap.emplace (
627+ " zeCommandListEndGraphCaptureExp" ,
628+ reinterpret_cast <void **>(
629+ &ZeGraphExt.zeCommandListEndGraphCaptureExpLegacy ));
630+ ZeGraphFuncNameToAddrMap.emplace (
631+ " zeCommandListInstantiateGraphExp" ,
632+ reinterpret_cast <void **>(
633+ &ZeGraphExt.zeCommandListInstantiateGraphExpLegacy ));
634+ } else {
635+ ZeGraphFuncNameToAddrMap.emplace (
636+ " zeGraphCreateExt" ,
637+ reinterpret_cast <void **>(&ZeGraphExt.zeGraphCreateExp ));
638+ ZeGraphFuncNameToAddrMap.emplace (
639+ " zeCommandListEndGraphCaptureExt" ,
640+ reinterpret_cast <void **>(
641+ &ZeGraphExt.zeCommandListEndGraphCaptureExp ));
642+ ZeGraphFuncNameToAddrMap.emplace (
643+ " zeGraphInstantiateExt" ,
644+ reinterpret_cast <void **>(
645+ &ZeGraphExt.zeCommandListInstantiateGraphExp ));
646+ }
647+
602648 ZeGraphExt.Supported = true ;
603649 for (auto &[funcName, funcAddr] : ZeGraphFuncNameToAddrMap) {
604650 ZE_CALL_NOCHECK (zeDriverGetExtensionFunctionAddress,
@@ -611,9 +657,10 @@ ur_result_t ur_platform_handle_t_::initialize() {
611657 // code in affected function.
612658 std::unordered_map<std::string, void **> ZeGraphOptionalFuncNameToAddrMap =
613659 {
614- {" zeCommandListGetGraphExt" ,
660+ {UseExp ? " zeCommandListGetGraphExp " : " zeCommandListGetGraphExt" ,
615661 reinterpret_cast <void **>(&ZeGraphExt.zeCommandListGetGraphExp )},
616- {" zeGraphSetDestructionCallbackExt" ,
662+ {UseExp ? " zeGraphSetDestructionCallbackExp"
663+ : " zeGraphSetDestructionCallbackExt" ,
617664 reinterpret_cast <void **>(
618665 &ZeGraphExt.zeGraphSetDestructionCallbackExp )},
619666 };
0 commit comments