@@ -905,8 +905,15 @@ ur_result_t urProgramGetNativeHandle(
905905
906906 std::shared_lock<ur_shared_mutex> Guard (Program->Mutex );
907907 assert (Program->AssociatedDevices .size () > 0 );
908- auto Module =
909- Program->getZeModuleHandle (Program->AssociatedDevices [0 ]->ZeDevice );
908+ // Current API doesn't allow to specify device for which we want to get the
909+ // native handle. So, find the first device with a valid module handle.
910+ ze_module_handle_t Module = nullptr ;
911+ for (const auto &Device : Program->AssociatedDevices ) {
912+ Module = Program->getZeModuleHandle (Device->ZeDevice );
913+ if (Module) {
914+ break ;
915+ }
916+ }
910917 if (!Module)
911918 return UR_RESULT_ERROR_INVALID_OPERATION;
912919
@@ -924,7 +931,6 @@ ur_result_t urProgramCreateWithNativeHandle(
924931 ur_program_handle_t *Program // /< [out] pointer to the handle of the
925932 // /< program object created.
926933) {
927- std::ignore = Properties;
928934 UR_ASSERT (Context && NativeProgram, UR_RESULT_ERROR_INVALID_NULL_HANDLE);
929935 UR_ASSERT (Program, UR_RESULT_ERROR_INVALID_NULL_POINTER);
930936 auto ZeModule = ur_cast<ze_module_handle_t >(NativeProgram);
@@ -934,9 +940,9 @@ ur_result_t urProgramCreateWithNativeHandle(
934940 // executable (state Object).
935941
936942 try {
937- ur_program_handle_t_ *UrProgram =
938- new ur_program_handle_t_ ( ur_program_handle_t_::Exe, Context, ZeModule,
939- Properties->isNativeHandleOwned );
943+ ur_program_handle_t_ *UrProgram = new ur_program_handle_t_ (
944+ ur_program_handle_t_::Exe, Context, ZeModule,
945+ Properties ? Properties->isNativeHandleOwned : false );
940946 *Program = reinterpret_cast <ur_program_handle_t >(UrProgram);
941947 } catch (const std::bad_alloc &) {
942948 return UR_RESULT_ERROR_OUT_OF_HOST_MEMORY;
0 commit comments