From 71a1a7b4711b2cc42b528c7e980d42a5a0fc5cdc Mon Sep 17 00:00:00 2001 From: Sheil Kumar Date: Thu, 4 Nov 2021 00:42:51 -0700 Subject: [PATCH] Enable building winml with --build_nuget (#9632) * Enable building winml with --build_nuget * Fix flake8 errors * semicolor Co-authored-by: Sheil Kumar --- .../Microsoft.AI.MachineLearning.props | 48 +++++++++++++++++++ .../Microsoft.AI.MachineLearning.targets | 16 ------- .../Microsoft.AI.MachineLearning.props | 21 ++++++++ .../Microsoft.AI.MachineLearning.targets | 22 --------- tools/ci_build/build.py | 33 +++++++++---- .../nuget/generate_nuspec_for_native_nuget.py | 3 ++ 6 files changed, 97 insertions(+), 46 deletions(-) create mode 100644 csharp/src/Microsoft.AI.MachineLearning.Interop/Microsoft.AI.MachineLearning.props diff --git a/csharp/src/Microsoft.AI.MachineLearning.Interop/Microsoft.AI.MachineLearning.props b/csharp/src/Microsoft.AI.MachineLearning.Interop/Microsoft.AI.MachineLearning.props new file mode 100644 index 0000000000..548391a559 --- /dev/null +++ b/csharp/src/Microsoft.AI.MachineLearning.Interop/Microsoft.AI.MachineLearning.props @@ -0,0 +1,48 @@ + + + + + $(MSBuildThisFileDirectory)../../build/native/include/;%(AdditionalIncludeDirectories) + + + $(MSBuildThisFileDirectory)../../build/native/include/;%(AdditionalIncludeDirectories) + + + + + + + + + x64 + x86 + x64 + x86 + $(PlatformTarget) + + + + $(MSBuildThisFileDirectory)..\..\runtimes\win-$(WindowsAI-Platform)\_native + static\ + + $(RuntimesDirectory)\$(WindowsAIBinarySubfolder)microsoft.ai.machinelearning.dll + $([System.IO.Path]::GetFullPath($(WindowsAIBinary))) + + $(RuntimesDirectory)\$(WindowsAIBinarySubfolder)onnxruntime.dll + $([System.IO.Path]::GetFullPath($(OnnxRuntimeBinary))) + + $(MSBuildThisFileDirectory)..\..\winmds\Microsoft.AI.MachineLearning.winmd + $(MSBuildThisFileDirectory)..\..\winmds\Microsoft.AI.MachineLearning.Experimental.winmd + + $([System.IO.Path]::GetFullPath($(WindowsAIWinMD))) + $([System.IO.Path]::GetFullPath($(WindowsAIExperimentalWinMD))) + + + + + + true + true + true + + diff --git a/csharp/src/Microsoft.AI.MachineLearning.Interop/Microsoft.AI.MachineLearning.targets b/csharp/src/Microsoft.AI.MachineLearning.Interop/Microsoft.AI.MachineLearning.targets index 397a8d1373..4fdc961e38 100644 --- a/csharp/src/Microsoft.AI.MachineLearning.Interop/Microsoft.AI.MachineLearning.targets +++ b/csharp/src/Microsoft.AI.MachineLearning.Interop/Microsoft.AI.MachineLearning.targets @@ -1,21 +1,5 @@ - - x64 - x86 - x64 - x86 - $(PlatformTarget) - - - - $(MSBuildThisFileDirectory)..\..\runtimes\win-$(WindowsAI-Platform)\lib\uap10.0 - $(MSBuildThisFileDirectory)..\..\runtimes\win-$(WindowsAI-Platform)\_native - static\ - $(RuntimesDirectory)\$(WindowsAIBinarySubfolder)Microsoft.AI.MachineLearning.dll - $(RuntimesDirectory)\$(WindowsAIBinarySubfolder)onnxruntime.dll - - Binplacing WindowsAI binaries: {0} and {1}. diff --git a/csharp/src/Microsoft.AI.MachineLearning/Microsoft.AI.MachineLearning.props b/csharp/src/Microsoft.AI.MachineLearning/Microsoft.AI.MachineLearning.props index ec7bda8625..96c2dcf6dc 100644 --- a/csharp/src/Microsoft.AI.MachineLearning/Microsoft.AI.MachineLearning.props +++ b/csharp/src/Microsoft.AI.MachineLearning/Microsoft.AI.MachineLearning.props @@ -13,6 +13,27 @@ + + x86 + $(Platform) + + + + $(MSBuildThisFileDirectory)..\..\runtimes\win-$(WindowsAI-Platform)\_native + static\ + $(RuntimesDirectory)\$(WindowsAIBinarySubfolder)microsoft.ai.machinelearning.dll + $(MSBuildThisFileDirectory)..\..\winmds\Microsoft.AI.MachineLearning.winmd + $(MSBuildThisFileDirectory)..\..\winmds\Microsoft.AI.MachineLearning.Experimental.winmd + + $([System.IO.Path]::GetFullPath($(WindowsAIBinary))) + $([System.IO.Path]::GetFullPath($(WindowsAIWinMD))) + $([System.IO.Path]::GetFullPath($(WindowsAIExperimentalWinMD))) + + + + $(RuntimesDirectory)\$(WindowsAIBinarySubfolder)onnxruntime.dll + + true diff --git a/csharp/src/Microsoft.AI.MachineLearning/Microsoft.AI.MachineLearning.targets b/csharp/src/Microsoft.AI.MachineLearning/Microsoft.AI.MachineLearning.targets index 9730fa9610..61090cac1c 100644 --- a/csharp/src/Microsoft.AI.MachineLearning/Microsoft.AI.MachineLearning.targets +++ b/csharp/src/Microsoft.AI.MachineLearning/Microsoft.AI.MachineLearning.targets @@ -1,27 +1,5 @@ - - x86 - $(Platform) - - - - $(MSBuildThisFileDirectory)..\..\runtimes\win-$(WindowsAI-Platform)\lib\uap10.0 - $(MSBuildThisFileDirectory)..\..\runtimes\win-$(WindowsAI-Platform)\_native - static\ - $(RuntimesDirectory)\$(WindowsAIBinarySubfolder)microsoft.ai.machinelearning.dll - $(MSBuildThisFileDirectory)..\..\winmds\Microsoft.AI.MachineLearning.winmd - $(MSBuildThisFileDirectory)..\..\winmds\Microsoft.AI.MachineLearning.Experimental.winmd - - $([System.IO.Path]::GetFullPath($(WindowsAIBinary))) - $([System.IO.Path]::GetFullPath($(WindowsAIWinMD))) - $([System.IO.Path]::GetFullPath($(WindowsAIExperimentalWinMD))) - - - - $(RuntimesDirectory)\$(WindowsAIBinarySubfolder)onnxruntime.dll - - $(WindowsAIBinary) diff --git a/tools/ci_build/build.py b/tools/ci_build/build.py index 5a55ea289c..34a98cd49c 100644 --- a/tools/ci_build/build.py +++ b/tools/ci_build/build.py @@ -1767,7 +1767,8 @@ def derive_linux_build_property(): return "/p:IsLinuxBuild=\"true\"" -def build_nuget_package(source_dir, build_dir, configs, use_cuda, use_openvino, use_tensorrt, use_dnnl, use_nuphar): +def build_nuget_package(source_dir, build_dir, configs, use_cuda, use_openvino, use_tensorrt, use_dnnl, use_nuphar, + use_winml): if not (is_windows() or is_linux()): raise BuildError( 'Currently csharp builds and nuget package creation is only supportted ' @@ -1777,9 +1778,13 @@ def build_nuget_package(source_dir, build_dir, configs, use_cuda, use_openvino, is_linux_build = derive_linux_build_property() # derive package name and execution provider based on the build args + target_name = "/t:CreatePackage" execution_provider = "/p:ExecutionProvider=\"None\"" package_name = "/p:OrtPackageId=\"Microsoft.ML.OnnxRuntime\"" - if use_openvino: + if use_winml: + package_name = "/p:OrtPackageId=\"Microsoft.AI.MachineLearning\"" + target_name = "/t:CreateWindowsAIPackage" + elif use_openvino: execution_provider = "/p:ExecutionProvider=\"openvino\"" package_name = "/p:OrtPackageId=\"Microsoft.ML.OnnxRuntime.OpenVino\"" elif use_tensorrt: @@ -1812,13 +1817,24 @@ def build_nuget_package(source_dir, build_dir, configs, use_cuda, use_openvino, configuration = "/p:Configuration=\"" + config + "\"" - cmd_args = ["dotnet", "msbuild", "OnnxRuntime.CSharp.sln", configuration, package_name, is_linux_build, - ort_build_dir] - run_subprocess(cmd_args, cwd=csharp_build_dir) + if not use_winml: + cmd_args = ["dotnet", "msbuild", "OnnxRuntime.CSharp.sln", configuration, package_name, is_linux_build, + ort_build_dir] + run_subprocess(cmd_args, cwd=csharp_build_dir) + else: + winml_interop_dir = os.path.join(source_dir, "csharp", "src", "Microsoft.AI.MachineLearning.Interop") + winml_interop_project = os.path.join(winml_interop_dir, "Microsoft.AI.MachineLearning.Interop.csproj") + winml_interop_project = os.path.normpath(winml_interop_project) + cmd_args = ["dotnet", "msbuild", winml_interop_project, configuration, "/p:Platform=\"Any CPU\"", + ort_build_dir, "-restore"] + run_subprocess(cmd_args, cwd=csharp_build_dir) + + nuget_exe = os.path.normpath(os.path.join(native_dir, config, "nuget_exe", "src", "nuget.exe")) + nuget_exe_arg = "/p:NugetExe=\"" + nuget_exe + "\"" cmd_args = [ - "dotnet", "msbuild", "OnnxRuntime.CSharp.proj", "/t:CreatePackage", - package_name, configuration, execution_provider, is_linux_build, ort_build_dir] + "dotnet", "msbuild", "OnnxRuntime.CSharp.proj", target_name, + package_name, configuration, execution_provider, is_linux_build, ort_build_dir, nuget_exe_arg] run_subprocess(cmd_args, cwd=csharp_build_dir) @@ -2318,7 +2334,8 @@ def main(): args.use_openvino, args.use_tensorrt, args.use_dnnl, - args.use_nuphar + args.use_nuphar, + args.use_winml, ) if args.test and args.build_nuget: diff --git a/tools/nuget/generate_nuspec_for_native_nuget.py b/tools/nuget/generate_nuspec_for_native_nuget.py index 24bfe14058..a1237f4786 100644 --- a/tools/nuget/generate_nuspec_for_native_nuget.py +++ b/tools/nuget/generate_nuspec_for_native_nuget.py @@ -526,8 +526,11 @@ def generate_files(list, args): # Process .net5.0 targets if args.target_architecture == 'x64': interop_src = 'Microsoft.AI.MachineLearning.Interop' + interop_props = 'Microsoft.AI.MachineLearning.props' interop_targets = 'Microsoft.AI.MachineLearning.targets' + windowsai_net50_props = os.path.join(args.sources_path, 'csharp', 'src', interop_src, interop_props) windowsai_net50_targets = os.path.join(args.sources_path, 'csharp', 'src', interop_src, interop_targets) + files_list.append('') files_list.append('') if is_cpu_package or is_cuda_gpu_package or is_dml_package or is_mklml_package: