diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 019c2e674c..947bb7a73d 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -946,3 +946,16 @@ if (onnxruntime_BUILD_CSHARP) # set_property(GLOBAL PROPERTY VS_DOTNET_TARGET_FRAMEWORK_VERSION "netstandard2.0") include(onnxruntime_csharp.cmake) endif() + +if (onnxruntime_BUILD_FOR_WINDOWS_STORE) + set_target_properties(onnxruntime PROPERTIES VS_GLOBAL_AppContainerApplication true) + set_target_properties(winml_dll PROPERTIES VS_GLOBAL_AppContainerApplication true) + + target_link_options(onnxruntime PRIVATE /DYNAMICBASE /NXCOMPAT /APPCONTAINER) + target_link_options(winml_dll PRIVATE /DYNAMICBASE /NXCOMPAT /APPCONTAINER) + + if (onnxruntime_target_platform STREQUAL "x86") + target_link_options(onnxruntime PRIVATE /SAFESEH) + target_link_options(winml_dll PRIVATE /SAFESEH) + endif() +endif() diff --git a/cmake/onnxruntime_providers.cmake b/cmake/onnxruntime_providers.cmake index 7afdb69270..0b202013a9 100644 --- a/cmake/onnxruntime_providers.cmake +++ b/cmake/onnxruntime_providers.cmake @@ -430,7 +430,14 @@ if (onnxruntime_USE_DML) endfunction() target_add_dml(onnxruntime_providers_dml) - target_link_libraries(onnxruntime_providers_dml PRIVATE d3d12.lib dxgi.lib delayimp.lib) + target_link_libraries(onnxruntime_providers_dml PRIVATE d3d12.lib dxgi.lib) + + if (onnxruntime_BUILD_FOR_WINDOWS_STORE) + target_link_libraries(onnxruntime_providers_dml PRIVATE dloadhelper.lib) + else() + target_link_libraries(onnxruntime_providers_dml PRIVATE delayimp.lib) + endif() + set(onnxruntime_DELAYLOAD_FLAGS "${onnxruntime_DELAYLOAD_FLAGS} /DELAYLOAD:DirectML.dll /DELAYLOAD:d3d12.dll /DELAYLOAD:dxgi.dll") # The DML EP requires C++17 diff --git a/cmake/winml.cmake b/cmake/winml.cmake index 2f6af2248f..47e7ea6242 100644 --- a/cmake/winml.cmake +++ b/cmake/winml.cmake @@ -615,7 +615,11 @@ target_link_libraries(winml_dll PRIVATE winml_lib_api) target_link_libraries(winml_dll PRIVATE winml_lib_image) target_link_libraries(winml_dll PRIVATE winml_lib_ort) target_link_libraries(winml_dll PRIVATE winml_lib_telemetry) -target_link_libraries(winml_dll PRIVATE delayimp.lib) +if (onnxruntime_BUILD_FOR_WINDOWS_STORE) + target_link_libraries(winml_dll PRIVATE dloadhelper.lib) +else() + target_link_libraries(winml_dll PRIVATE delayimp.lib) +endif() # Any project that links in debug_alloc.obj needs this lib. # unresolved external symbol __imp_SymSetOptions diff --git a/csharp/OnnxRuntime.CSharp.proj b/csharp/OnnxRuntime.CSharp.proj index 3f583996e4..01ed2eb326 100644 --- a/csharp/OnnxRuntime.CSharp.proj +++ b/csharp/OnnxRuntime.CSharp.proj @@ -72,7 +72,7 @@ CMake creates a target to this project - + @@ -119,8 +119,24 @@ CMake creates a target to this project - + + + + + + + + + + + + + + + + + diff --git a/csharp/src/Microsoft.ML.OnnxRuntime/Microsoft.AI.MachineLearning.props b/csharp/src/Microsoft.ML.OnnxRuntime/Microsoft.AI.MachineLearning.props new file mode 100644 index 0000000000..9cba31ea5c --- /dev/null +++ b/csharp/src/Microsoft.ML.OnnxRuntime/Microsoft.AI.MachineLearning.props @@ -0,0 +1,11 @@ + + + + + $(MSBuildThisFileDirectory)../../build/native/include/;%(AdditionalIncludeDirectories) + + + $(MSBuildThisFileDirectory)../../build/native/include/;%(AdditionalIncludeDirectories) + + + diff --git a/csharp/src/Microsoft.ML.OnnxRuntime/Microsoft.AI.MachineLearning.targets b/csharp/src/Microsoft.ML.OnnxRuntime/Microsoft.AI.MachineLearning.targets new file mode 100644 index 0000000000..a88b5c23fd --- /dev/null +++ b/csharp/src/Microsoft.ML.OnnxRuntime/Microsoft.AI.MachineLearning.targets @@ -0,0 +1,34 @@ + + + + x86 + $(Platform) + + + + $(MSBuildThisFileDirectory)..\..\runtimes\win-$(WindowsAI-Platform)\native\Microsoft.AI.MachineLearning.dll + $(MSBuildThisFileDirectory)..\..\runtimes\win-$(WindowsAI-Platform)\native\onnxruntime.dll + $(MSBuildThisFileDirectory)..\..\runtimes\win-$(WindowsAI-Platform)\native\directml.dll + + + + + $(WindowsAIBinary) + + + + + $(WindowsAIBinary);$(OnnxRuntimeBinary);$(DirectMLBinary) + + + $(WindowsAIBinary);$(OnnxRuntimeBinary) + + + + + Binplacing WindowsAI binaries: {0} and {1}. + + + + + diff --git a/csharp/src/Microsoft.ML.OnnxRuntime/Microsoft.ML.OnnxRuntime.csproj b/csharp/src/Microsoft.ML.OnnxRuntime/Microsoft.ML.OnnxRuntime.csproj index bceeb06ba1..1cef1ee54e 100644 --- a/csharp/src/Microsoft.ML.OnnxRuntime/Microsoft.ML.OnnxRuntime.csproj +++ b/csharp/src/Microsoft.ML.OnnxRuntime/Microsoft.ML.OnnxRuntime.csproj @@ -93,78 +93,6 @@ CopyToOutputDirectory="Always" Visible="false" /> - - - - - - - - wheel_filename_file + set /p WHEEL_FILENAME=') -def generate_dependencies(list, version): - list.append('') +def generate_dependencies(list, package_name, version): + if (package_name != 'Microsoft.AI.MachineLearning'): + list.append('') + # Support .Net Core + list.append('') + list.append('') + list.append('') + # Support .Net Standard + list.append('') + list.append('') + list.append('') + # Support .Net Framework + list.append('') + list.append('') + list.append('') - # Support .Net Core - list.append('') - list.append('') - list.append('') - - # Support .Net Standard - list.append('') - list.append('') - list.append('') - - # Support .Net Framework - list.append('') - list.append('') - list.append('') - - list.append('') + list.append('') def get_env_var(key): return os.environ.get(key) @@ -106,7 +104,7 @@ def generate_metadata(list, args): generate_license(metadata_list) generate_project_url(metadata_list, 'https://github.com/Microsoft/onnxruntime') generate_repo_url(metadata_list, 'https://github.com/Microsoft/onnxruntime.git', args.commit_id) - generate_dependencies(metadata_list, args.package_version) + generate_dependencies(metadata_list, args.package_name, args.package_version) generate_release_notes(metadata_list) metadata_list.append('') @@ -115,90 +113,106 @@ def generate_metadata(list, args): def generate_files(list, args): files_list = [''] + is_cpu_package = args.package_name == 'Microsoft.ML.OnnxRuntime' + is_mklml_package = args.package_name == 'Microsoft.ML.OnnxRuntime.MKLML' + is_cuda_gpu_package = args.package_name == 'Microsoft.ML.OnnxRuntime.Gpu' + is_dml_package = args.package_name == 'Microsoft.ML.OnnxRuntime.DirectML' + is_windowsai_package = args.package_name == 'Microsoft.AI.MachineLearning' + + includes_cuda = is_cuda_gpu_package or is_cpu_package # Why does the CPU package ship the cuda provider headers? + includes_winml = is_windowsai_package + includes_directml = (is_dml_package or is_windowsai_package) and (args.target_architecture == 'x64' or args.target_architecture == 'x86') + # Process headers files_list.append('') files_list.append('') - if (args.package_name != 'Microsoft.ML.OnnxRuntime.DirectML'): + if includes_cuda: files_list.append('') - else: # it is a DirectML package + + if includes_directml: files_list.append('') - # Process DirectML dll - if os.path.exists(os.path.join(args.native_build_path, 'DirectML.dll')): - files_list.append('') - files_list.append('') - files_list.append('') - + + if includes_winml: + # Add microsoft.ai.machinelearning headers + files_list.append('') + files_list.append('') + files_list.append('') + # Process microsoft.ai.machinelearning.winmd + files_list.append('') + + # Process runtimes # Process onnxruntime import lib, dll, and pdb files_list.append('') files_list.append('') files_list.append('') + + if includes_directml: + files_list.append('') + files_list.append('') + files_list.append('') + + if includes_winml: + # Process microsoft.ai.machinelearning import lib, dll, and pdb + files_list.append('') + files_list.append('') + files_list.append('') + + if is_cpu_package or is_cuda_gpu_package or is_dml_package or is_mklml_package: + # Process dnll.dll + if os.path.exists(os.path.join(args.native_build_path, 'dnnl.dll')): + files_list.append('') + + # Process mklml.dll + if os.path.exists(os.path.join(args.native_build_path, 'mklml.dll')): + files_list.append('') - if (is_windows()): - # Process Microsoft.AI.MachineLearning lib, dll, and pdb - if (args.package_name == 'Microsoft.ML.OnnxRuntime.DirectML' or args.package_name == 'Microsoft.ML.OnnxRuntime'): - files_list.append('') - if (args.package_name == 'Microsoft.ML.OnnxRuntime.DirectML' or args.package_name == 'Microsoft.ML.OnnxRuntime'): - files_list.append('') - if (args.package_name == 'Microsoft.ML.OnnxRuntime.DirectML' or args.package_name == 'Microsoft.ML.OnnxRuntime'): - files_list.append('') - # Process microsoft.ai.machinelearning.winmd - if (args.package_name == 'Microsoft.ML.OnnxRuntime.DirectML' or args.package_name == 'Microsoft.ML.OnnxRuntime'): - files_list.append('') - # Process microsoft.ai.machinelearning headers - if (args.package_name == 'Microsoft.ML.OnnxRuntime.DirectML' or args.package_name == 'Microsoft.ML.OnnxRuntime'): - files_list.append('') - if (args.package_name == 'Microsoft.ML.OnnxRuntime.DirectML' or args.package_name == 'Microsoft.ML.OnnxRuntime'): - files_list.append('') - if (args.package_name == 'Microsoft.ML.OnnxRuntime.DirectML' or args.package_name == 'Microsoft.ML.OnnxRuntime'): - files_list.append('') - - if (args.package_name == 'Microsoft.ML.OnnxRuntime.DirectML' or args.package_name == 'Microsoft.ML.OnnxRuntime') and os.path.exists(os.path.join(args.ort_build_path, args.build_config, 'dualapipartitionattribute.h')): - files_list.append('') - - # Process dnll.dll - if os.path.exists(os.path.join(args.native_build_path, 'dnnl.dll')): - files_list.append('') + # Process libiomp5md.dll + if os.path.exists(os.path.join(args.native_build_path, 'libiomp5md.dll')): + files_list.append('') - # Process mklml.dll - if os.path.exists(os.path.join(args.native_build_path, 'mklml.dll')): - files_list.append('') + # Process tvm.dll + if os.path.exists(os.path.join(args.native_build_path, 'tvm.dll')): + files_list.append('') - # Process libiomp5md.dll - if os.path.exists(os.path.join(args.native_build_path, 'libiomp5md.dll')): - files_list.append('') - - # Process tvm.dll - if os.path.exists(os.path.join(args.native_build_path, 'tvm.dll')): - files_list.append('') + # Some tools to be packaged in nightly build only, should not be released + # These are copied to the runtimes folder for convenience of loading with the dlls + if args.is_release_build.lower() != 'true' and args.target_architecture == 'x64' and os.path.exists(os.path.join(args.native_build_path, 'onnxruntime_perf_test.exe')): + files_list.append('') + if args.is_release_build.lower() != 'true' and args.target_architecture == 'x64' and os.path.exists(os.path.join(args.native_build_path, 'onnx_test_runner.exe')): + files_list.append('') + + # Process props and targets files + if is_windowsai_package: + # Process props file + windowsai_props = os.path.join(args.sources_path, 'csharp', 'src', 'Microsoft.ML.OnnxRuntime', 'Microsoft.AI.MachineLearning.props') + files_list.append('') + # Process targets files + windowsai_targets = os.path.join(args.sources_path, 'csharp', 'src', 'Microsoft.ML.OnnxRuntime', 'Microsoft.AI.MachineLearning.targets') + files_list.append('') + + if is_cpu_package or is_cuda_gpu_package or is_dml_package or is_mklml_package: + # Process props file + source_props = os.path.join(args.sources_path, 'csharp', 'src', 'Microsoft.ML.OnnxRuntime', 'props.xml') + target_props = os.path.join(args.sources_path, 'csharp', 'src', 'Microsoft.ML.OnnxRuntime', args.package_name + '.props') + os.system('copy ' + source_props + ' ' + target_props) + files_list.append('') + files_list.append('') + + # Process targets file + source_targets = os.path.join(args.sources_path, 'csharp', 'src', 'Microsoft.ML.OnnxRuntime', 'targets.xml') + target_targets = os.path.join(args.sources_path, 'csharp', 'src', 'Microsoft.ML.OnnxRuntime', args.package_name + '.targets') + os.system('copy ' + source_targets + ' ' + target_targets) + files_list.append('') + files_list.append('') + + # Process License, ThirdPartyNotices, Privacy, README files_list.append('') files_list.append('') files_list.append('') files_list.append('') - - # Process props file - source_props = os.path.join(args.sources_path, 'csharp', 'src', 'Microsoft.ML.OnnxRuntime', 'props.xml') - target_props = os.path.join(args.sources_path, 'csharp', 'src', 'Microsoft.ML.OnnxRuntime', args.package_name + '.props') - os.system('copy ' + source_props + ' ' + target_props) - files_list.append('') - files_list.append('') - - # Process targets file - source_targets = os.path.join(args.sources_path, 'csharp', 'src', 'Microsoft.ML.OnnxRuntime', 'targets.xml') - target_targets = os.path.join(args.sources_path, 'csharp', 'src', 'Microsoft.ML.OnnxRuntime', args.package_name + '.targets') - os.system('copy ' + source_targets + ' ' + target_targets) - files_list.append('') - files_list.append('') - - # Some tools to be packaged in nightly build only, should not be released - # These are copied to the runtimes folder for convenience of loading with the dlls - if args.is_release_build.lower() != 'true' and args.target_architecture == 'x64' and os.path.exists(os.path.join(args.native_build_path, 'onnxruntime_perf_test.exe')): - files_list.append('') - - if args.is_release_build.lower() != 'true' and args.target_architecture == 'x64' and os.path.exists(os.path.join(args.native_build_path, 'onnx_test_runner.exe')): - files_list.append('') files_list.append('')