ultra_infer_init.bat 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. @echo off
  2. set __script_action_type=%1
  3. set __ultra_infer_sdk_dir=%2
  4. set __another_target_dir=%3
  5. set __install_infos_flag=%4
  6. @rem help
  7. if "%__script_action_type%" == "help" (
  8. call:__print_long_line
  9. echo [1] [help] print help information: ultra_infer_init.bat help
  10. echo [2] [show] show all dlls/libs/include paths: ultra_infer_init.bat show ultra_infer-sdk-dir
  11. echo [3] [init] init all dlls paths for current terminal: ultra_infer_init.bat init ultra_infer-sdk-dir [WARNING: need copy onnxruntime.dll manually]
  12. echo [4] [setup] setup path env for current terminal: ultra_infer_init.bat setup ultra_infer-sdk-dir [WARNING: need copy onnxruntime.dll manually]
  13. echo [5] [install] install all dlls to a specific dir: ultra_infer_init.bat install ultra_infer-sdk-dir another-dir-to-install-dlls **[RECOMMEND]**
  14. echo [6] [install] install all dlls with logging infos: ultra_infer_init.bat install ultra_infer-sdk-dir another-dir-to-install-dlls info
  15. call:__print_long_line
  16. goto:eof
  17. )
  18. @rem show dlls and libs
  19. if "%__script_action_type%" == "show" (
  20. call:__print_long_line
  21. echo [SDK] %__ultra_infer_sdk_dir%
  22. call:__print_long_line
  23. set __have_openvino_flag=false
  24. set __ultra_infer_lib_dir=%__ultra_infer_sdk_dir%\lib
  25. @setlocal enabledelayedexpansion
  26. echo [DLL] !__ultra_infer_lib_dir!\ultra_infer.dll **[NEEDED]**
  27. for /f "delims= " %%a in ('dir /s /b %__ultra_infer_sdk_dir%\third_libs ^| findstr /e \.dll ^| findstr /v "vc14\\bin\\opencv"') do (
  28. set __3rd_dll_file=%%a && set __3rd_needed_flag=true
  29. echo !__3rd_dll_file! | findstr "openvino">nul && set __have_openvino_flag=true
  30. echo !__3rd_dll_file! | findstr d\.dll>nul && set __3rd_needed_flag=false
  31. if "!__3rd_needed_flag!"=="false" (echo !__3rd_dll_file! | findstr /v opencv>nul && set __3rd_needed_flag=true)
  32. echo !__3rd_dll_file! | findstr debug\.dll>nul && set __3rd_needed_flag=false
  33. if "!__3rd_needed_flag!"=="true" (echo [DLL] !__3rd_dll_file! **[NEEDED]**) else (echo [DLL] !__3rd_dll_file!)
  34. )
  35. call:__print_long_line
  36. echo [Lib] !__ultra_infer_lib_dir!\ultra_infer.lib **[NEEDED][ultra_infer]**
  37. for /f "delims= " %%a in ('dir /s /b %__ultra_infer_sdk_dir%\third_libs ^| findstr /e \.lib ^| findstr /v "vc14\\lib\\opencv"') do (
  38. set __3rd_lib_file=%%a && set __3rd_needed_flag=false && set __api_tag=ultra_infer
  39. echo !__3rd_lib_file! | findstr "opencv">nul && set __3rd_needed_flag=true
  40. echo !__3rd_lib_file! | findstr "opencv">nul && set __api_tag=!__api_tag!::vision
  41. if "!__3rd_needed_flag!"=="true" (echo !__3rd_lib_file! | findstr d\.lib>nul && set __3rd_needed_flag=false)
  42. echo !__3rd_lib_file! | findstr "fast_tokenizer">nul && set __3rd_needed_flag=true
  43. echo !__3rd_lib_file! | findstr "fast_tokenizer">nul && set __api_tag=!__api_tag!::text
  44. if "!__3rd_needed_flag!"=="true" (echo [Lib] !__3rd_lib_file! **[NEEDED][!__api_tag!]**) else (echo [Lib] !__3rd_lib_file!)
  45. )
  46. call:__print_long_line
  47. set __ultra_infer_include_dir=%__ultra_infer_sdk_dir%\include
  48. echo [Include] !__ultra_infer_include_dir! **[NEEDED][ultra_infer]**
  49. for /f "delims= " %%a in ('dir /s /b %__ultra_infer_sdk_dir%\third_libs ^| findstr /e include ^| findstr /v "vc14\\bin\\opencv"') do (
  50. set __3rd_include_dir=%%a && set __3rd_needed_flag=false && set __api_tag=ultra_infer
  51. echo !__3rd_include_dir! | findstr "opencv">nul && set __3rd_needed_flag=true
  52. echo !__3rd_include_dir! | findstr "opencv">nul && set __api_tag=!__api_tag!::vision
  53. echo !__3rd_include_dir! | findstr "fast_tokenizer">nul && set __3rd_needed_flag=true
  54. echo !__3rd_include_dir! | findstr "fast_tokenizer">nul && set __api_tag=!__api_tag!::text
  55. if "!__3rd_needed_flag!"=="true" (echo [Include] !__3rd_include_dir! **[NEEDED][!__api_tag!]**) else (echo [Include] !__3rd_include_dir!)
  56. )
  57. call:__print_long_line
  58. if "!__have_openvino_flag!"=="true" (
  59. for /f "delims= " %%a in ('dir /s /b %__ultra_infer_sdk_dir%\third_libs ^| findstr /e \.xml ^| findstr "openvino"') do (
  60. set __openvino_plugin_xml=%%a
  61. echo [XML] !__openvino_plugin_xml! **[NEEDED]**
  62. )
  63. call:__print_long_line
  64. )
  65. @setlocal disabledelayedexpansion
  66. goto:eof
  67. )
  68. @rem init all paths for dlls
  69. if "%__script_action_type%" == "init" (
  70. @setlocal enabledelayedexpansion
  71. set /p yes_or_no=Init dll paths for UltraInfer in current terminal: [y/n]
  72. if "!yes_or_no!"=="y" (echo YES.) else (echo NO. && pause && goto:eof)
  73. @setlocal disabledelayedexpansion
  74. if exist bin.txt (del /Q bin.txt)
  75. if exist lib.txt (del /Q lib.txt)
  76. for /f "delims= " %%a in ('dir /s /b /A:D %__ultra_infer_sdk_dir% ^| findstr /v include ^| findstr /e bin ^| findstr /v "vc14\\bin"') do (>>bin.txt set /p=%%a;<nul)
  77. for /f "delims= " %%a in ('dir /s /b /A:D %__ultra_infer_sdk_dir% ^| findstr /v include ^| findstr /e lib ^| findstr /v "vc14\\lib"') do (>>lib.txt set /p=%%a;<nul)
  78. for /f %%i in (bin.txt) do (endlocal & set __ultra_infer_bin_paths=%%i)
  79. for /f %%j in (lib.txt) do (endlocal & set __ultra_infer_lib_paths=%%j)
  80. pause
  81. call:__print_long_line
  82. echo [INFO] UltraInfer dlls paths init done! Please run: [ultra_infer_init.bat setup ultra_infer-sdk-dir]
  83. echo [INFO] command to push these dlls paths into PATH ENV in current terminal.
  84. call:__print_long_line
  85. goto:eof
  86. )
  87. @rem setup PATH ENV for all dlls
  88. if "%__script_action_type%" == "setup" (
  89. @setlocal enabledelayedexpansion
  90. set /p yes_or_no=Setup PATH ENV for UltraInfer in current terminal: [y/n]
  91. if "!yes_or_no!"=="y" (echo YES.) else (echo NO. && pause && goto:eof)
  92. @setlocal disabledelayedexpansion
  93. if not exist bin.txt (echo Can not found bin.txt, Please run init before setup && goto:eof)
  94. if not exist lib.txt (echo Can not found lib.txt, Please run init before setup && goto:eof)
  95. for /f %%i in (bin.txt) do (endlocal & set __ultra_infer_bin_paths=%%i)
  96. for /f %%j in (lib.txt) do (endlocal & set __ultra_infer_lib_paths=%%j)
  97. set "PATH=%__ultra_infer_bin_paths%%__ultra_infer_lib_paths%%PATH%"
  98. pause
  99. call:__print_long_line
  100. echo [INFO] UltraInfer PATH ENV setup done! Please use [set PATH] to check PATH ENV in current terminal.
  101. echo [INFO] Just setup once again if the paths of UltraInfer can not be found in your PATH ENV.
  102. call:__print_long_line
  103. echo [WARN] Please copy all onnxruntime dlls manually to your-exe-or-custom-dll-dir if ENABLE_ORT_BACKEND=ON.
  104. echo [WARN] Use [ultra_infer_init.bat show ultra_infer-sdk-dir] to find the dll's location of onnxruntime.
  105. call:__print_long_line
  106. goto:eof
  107. )
  108. @rem copy all dlls to a specific location
  109. if "%__script_action_type%" == "install" (
  110. @setlocal enabledelayedexpansion
  111. if "!__install_infos_flag!"=="noconfirm" (
  112. echo [INFO] Installing all UltraInfer dlls ...
  113. ) else (
  114. echo [INFO] Do you want to install all UltraInfer dlls ?
  115. echo [INFO] From: !__ultra_infer_sdk_dir!
  116. echo [INFO] To: !__another_target_dir!
  117. set /p yes_or_no=Choose y means YES, n means NO: [y/n]
  118. if "!yes_or_no!"=="y" (echo YES.) else (echo NO. && pause && goto:eof)
  119. pause
  120. )
  121. @setlocal disabledelayedexpansion
  122. if not exist %__ultra_infer_sdk_dir% ( echo [ERROR] %__ultra_infer_sdk_dir% is not exist ! && goto:eof )
  123. if not exist %__another_target_dir% ( mkdir %__another_target_dir% && echo [INFO] Created %__another_target_dir% done!)
  124. set __have_openvino_flag=false
  125. @setlocal enabledelayedexpansion
  126. for /f "delims= " %%a in ('dir /s /b %__ultra_infer_sdk_dir% ^| findstr /e \.dll ^| findstr /v "vc14\\bin\\opencv"') do (
  127. set __3rd_or_fd_dll_file=%%a && set __3rd_or_fd_needed_flag=true
  128. echo !__3rd_or_fd_dll_file! | findstr "openvino">nul && set __have_openvino_flag=true
  129. echo !__3rd_or_fd_dll_file! | findstr d\.dll>nul && set __3rd_or_fd_needed_flag=false
  130. if "!__3rd_or_fd_needed_flag!"=="false" ( echo !__3rd_or_fd_dll_file! | findstr /v opencv>nul && set __3rd_or_fd_needed_flag=true)
  131. echo !__3rd_or_fd_dll_file! | findstr debug\.dll>nul && set __3rd_or_fd_needed_flag=false
  132. if "!__3rd_or_fd_needed_flag!"=="true" (
  133. copy /Y !__3rd_or_fd_dll_file! %__another_target_dir%
  134. if "!__install_infos_flag!"=="info" ( echo [Installed][DLL] !__3rd_or_fd_dll_file! "--->" %__another_target_dir%)
  135. )
  136. )
  137. if "!__have_openvino_flag!"=="true" (
  138. for /f "delims= " %%a in ('dir /s /b %__ultra_infer_sdk_dir% ^| findstr /e \.xml ^| findstr "openvino"') do (
  139. set __openvino_plugin_xml=%%a
  140. copy /Y !__openvino_plugin_xml! %__another_target_dir%
  141. if "!__install_infos_flag!"=="info" ( echo [Installed][XML] !__openvino_plugin_xml! "--->" %__another_target_dir% )
  142. )
  143. )
  144. @setlocal disabledelayedexpansion
  145. goto:eof
  146. )
  147. goto:eof
  148. @rem helpers
  149. :__print_long_line
  150. echo ------------------------------------------------------------------------------------------------------------------------------------------------------------
  151. goto:eof
  152. @rem end
  153. @echo on