Skip to content

Conversation

@smanolloff
Copy link

@smanolloff smanolloff commented Nov 23, 2025

This PR contains changes needed to migrate MMAI from libtorch to onnxruntime as @Laserlicht suggested here

It adds onnxruntime/1.18.1 requirement with several patches address android-arm64 and windows-x86 compilation errors, as well as conan recipe errors from transitive dependencies.

Please take a look and let me know if you have any comments.

The changes were tested with VCMI (develop branch) on MacOS 15 (arm), Windows 10 (x64), iOS 18 and Android 13 without noticing any issue.

This reverts commit 56f3512.

Removing CreateFile2 calls was insufficient to enable win7 support.
There are win8+ API calls which are not straightforward to replace:

    onnxruntime\core\platform\windows\env_time.cc(31): error C2065: 'GetSystemTimePreciseAsFileTime': undeclared identifier
@smanolloff
Copy link
Author

smanolloff commented Nov 25, 2025

Added conan patch which allows to keep macos-intel 10.13 and ios 12.0 min OS versions.
Unfortunately, my attempt at compiling onnxruntime on win7 was not successful: there are other calls such as GetSystemTimePreciseAsFileTime which are not available in the windows 7 API and are seem more difficult to replace. So the win7 / win8 build split remains.

@GeorgeK1ng
Copy link

GeorgeK1ng commented Nov 25, 2025

I think there is issue with FILE_READ_ATTRIBUTES vs GENERIC_READ in W7 patch?

Also keeping 192 which means v142 toolset is needed to keep proper support for builded components for Windows 7.

@smanolloff
Copy link
Author

I think there is issue with FILE_READ_ATTRIBUTES vs GENERIC_READ in W7 patch?

A hasty copy-paste on my side it seems, but that's irrelevant as I reverted the commit due to other compile errors.

Also keeping 192 which means v142 toolset is needed to keep proper support for builded components for Windows 7.

Thanks for pointing that out, I was under the impression "if it compiles, it runs" :) The compiler version is back to 192 for windows 7 now.

@GeorgeK1ng
Copy link

GeorgeK1ng commented Nov 26, 2025

Seems your patches were almost close. This should be Windows 7 compatible patch https://github.com/GeorgeK1ng/vcmi-dependencies/actions/runs/19713613028 - compiled just fine. So you need to grab there Windows 7 patch and recipe ones to allow v142 toolset.

@smanolloff smanolloff force-pushed the mmai branch 2 times, most recently from 0e42897 to 76afc17 Compare November 27, 2025 09:33
@smanolloff
Copy link
Author

smanolloff commented Nov 27, 2025

@GeorgeK1ng Thank you! I have added your suggested patch, finally the win7/win8 split is removed - the last remaining conan change in the PR has been dealt with.

Copy link
Collaborator

@kambala-decapitator kambala-decapitator left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please also update PR description to match the current state

- name: Build recipes with our patches
run: |
set -x
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't forget to remove

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I will remove it. But if I may I ask: why? Don't you find it helpful for troubleshooting?

# Patch conan recipe to prevent dragging libcurl as a dependency
# (can't be done via VCMI's conanfile as onnxruntime is built beforehand)
git apply --ignore-whitespace ../conan_patches/onnxruntime/recipe.diff
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can pass date/*:use_system_tz_db as an option to conan create or simply place it in our profile, to common I guess

Copy link
Author

@smanolloff smanolloff Nov 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The conan recipe also contains this change:

     def _compilers_minimum_version(self):
         return {
             "Visual Studio": "17",
-            "msvc": "193",
+            "msvc": "192",
             "gcc": "9",

It can't be set through command-line options AFAIK, which means the patch remains anyway. Does it still make sense to extract the date/*:use_system_tz_db into a cmdline option and wouldn't that make it harder to follow?

if [[ $package == qt ]] ; then
packagePath="$recipePathQt/5.x.x"
elif [[ $package =~ ^onnx ]] && ${{ contains(matrix.conan_options, 'with_onnxruntime=False') }} ; then
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but I don't see such option in the matrix?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I remove the qt check then as well?

# Some are both build and host requirements and must not be removed
# => exclude them from the list
cat $buildPackagesFile $hostPackagesFile | jq -s '
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unclear why this is needed, no info in PR description

Copy link
Author

@smanolloff smanolloff Nov 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a package is both a build and a host requirement, the old logic removes it. This leads to Missing prebuilt package error because conan is invoked with build=never in the VCMI build. In this case, zlib and protobuf were build requirements and were removed, which made them "missing" during VCMI build. This graph might help:
graph-msvc-x64.html


#Set global compile flags for all the source code(including third_party code like protobuf)
#This section must be before any add_subdirectory, otherwise build may fail because /MD,/MT mismatch
+message(STATUS "MSVC=${MSVC} | CMAKE_VS_PLATFORM_NAME=${CMAKE_VS_PLATFORM_NAME} | CMAKE_C_COMPILER_ARCHITECTURE_ID=${CMAKE_C_COMPILER_ARCHITECTURE_ID} | CMAKE_SYSTEM_PROCESSOR=${CMAKE_SYSTEM_PROCESSOR}")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't forget to remove these debug messages

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are not forgotten, I have left them on purpose. Please see my reply to your next comment regarding x86 vs X86.

set(onnxruntime_target_platform "ARM")
enable_language(ASM_MARMASM)
- elseif (onnxruntime_target_platform STREQUAL "x64" OR onnxruntime_target_platform STREQUAL "x86_64" OR onnxruntime_target_platform STREQUAL "AMD64" OR CMAKE_GENERATOR MATCHES "Win64")
+ elseif (onnxruntime_target_platform MATCHES "[Xx]64" OR onnxruntime_target_platform MATCHES "[Xx]86_64" OR onnxruntime_target_platform STREQUAL "AMD64" OR CMAKE_GENERATOR MATCHES "Win64")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can it really start with capital X?

also not really clear why touching x64 if the patch is for x86

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently it can. Not sure where that comes from, but I find onnxruntime's target platform logic rather confusing. This is why I left the debug messages.

- FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
- OPEN_EXISTING,
- &param)};
+ wil::unique_hfile file_handle{CreateFileW(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are these CreateFile2 -> CreateFileW changes worsening anything on Win 8+? If so, you could use runtime check for OS version or function availability

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing extra. Should be still same result.

- patch_file: "patches/android-64.diff"
patch_description: |
Fixes error for arm64-v8a targets:
onnxruntime/core/mlas/lib/mlasi.h:366:11: error: unknown type name 'bfloat16_t'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and what's the reason? Is it about minimum API level?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't answer this question.
bfloat16 support seems introduced in Armv8.6-A in 2019, but onnxruntime/1.16.1 contains flags for armv8.2. This might cause issues on older chips where these optimized instructions are unavailable.

However, we should be safe. The MMAI models are not using bfloat16 arithmetic. I have tested the model with Samsung Galaxy A71 which has an ARM Cortex-A76 and Cortex-A55, both implementing Arm8.2-A and there have been no issues.

onnxruntime/core/mlas/lib/mlasi.h:366:11: error: unknown type name 'bfloat16_t'
- patch_file: "patches/msvc-x86.diff"
patch_description: |
Fixes detection of x86 windows targets during cross-compilation.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it make sense to upstream this patch? Or upstream dropped 32-bit support?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would first wait to see if the models run on windows-x86 targets - I have no suitable hardware to test (honestly, I was surprised it even compiled. Hopefully it will run!)

@IvanSavenko
Copy link
Member

@kambala-decapitator any further comments?

@kambala-decapitator
Copy link
Collaborator

will check over the weekend

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants