From b0cb0ef6e5aa0244c208cd0052f4b86c7272032a Mon Sep 17 00:00:00 2001 From: Xiang Zhang Date: Fri, 15 Nov 2019 17:43:44 -0800 Subject: [PATCH] User/xianz/win ml telemetry (#2410) * add option to enable winml telemetry * add option to enable winml telemetry * clean logs while developping * clean the log of GUID * compile onnxruntime_common with winml telemetry * use option for use_telemetry * rename option winml_use_telemetry to onnxruntime_use_telemetry * little change --- cmake/CMakeLists.txt | 1 + cmake/onnxruntime_common.cmake | 4 ++++ cmake/winml.cmake | 3 +++ .../core/platform/windows/TraceLoggingConfig.h | 3 +++ tools/ci_build/build.py | 2 ++ .../github/azure-pipelines/templates/win-ci.yml | 10 ++++++++++ 6 files changed, 23 insertions(+) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index ea2cf2e538..07167b1653 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -84,6 +84,7 @@ option(onnxruntime_ENABLE_LANGUAGE_INTEROP_OPS "Enable operator implemented in l option(onnxruntime_DEBUG_NODE_INPUTS_OUTPUTS "Dump node input shapes and output data to standard output when executing the model." OFF) option(onnxruntime_USE_DML "Build with DirectML support" OFF) option(onnxruntime_USE_ACL "Build with ACL support" OFF) +option(onnxruntime_USE_TELEMETRY "Build with Telemetry" OFF) set(protobuf_BUILD_TESTS OFF CACHE BOOL "Build protobuf tests" FORCE) #nsync tests failed on Mac Build diff --git a/cmake/onnxruntime_common.cmake b/cmake/onnxruntime_common.cmake index 12180fd25a..d1c983b87f 100644 --- a/cmake/onnxruntime_common.cmake +++ b/cmake/onnxruntime_common.cmake @@ -52,6 +52,10 @@ source_group(TREE ${REPO_ROOT} FILES ${onnxruntime_common_src}) add_library(onnxruntime_common ${onnxruntime_common_src}) +if (onnxruntime_USE_TELEMETRY) + set_target_properties(onnxruntime_common PROPERTIES COMPILE_FLAGS "/FI${ONNXRUNTIME_INCLUDE_DIR}/core/platform/windows/TraceLoggingConfigPrivate.h") +endif() + if (onnxruntime_USE_MIMALLOC) if(onnxruntime_USE_CUDA OR onnxruntime_USE_OPENVINO) message(WARNING "Ignoring directive to use mimalloc on unimplemented targets") diff --git a/cmake/winml.cmake b/cmake/winml.cmake index a56548be7f..ab4ce2b69b 100644 --- a/cmake/winml.cmake +++ b/cmake/winml.cmake @@ -89,6 +89,9 @@ add_library(winml_lib_telemetry STATIC # Compiler options target_compile_features(winml_lib_telemetry PRIVATE cxx_std_17) target_compile_options(winml_lib_telemetry PRIVATE /GR- /await /wd4238) +if (onnxruntime_USE_TELEMETRY) + set_target_properties(winml_lib_telemetry PROPERTIES COMPILE_FLAGS "/FI${ONNXRUNTIME_INCLUDE_DIR}/core/platform/windows/TraceLoggingConfigPrivate.h") +endif() # Compiler flags target_compile_definitions(winml_lib_telemetry PRIVATE PLATFORM_WINDOWS) diff --git a/include/onnxruntime/core/platform/windows/TraceLoggingConfig.h b/include/onnxruntime/core/platform/windows/TraceLoggingConfig.h index 02f55f954a..c217054506 100644 --- a/include/onnxruntime/core/platform/windows/TraceLoggingConfig.h +++ b/include/onnxruntime/core/platform/windows/TraceLoggingConfig.h @@ -31,8 +31,11 @@ Environment: // Configuration macro for use in TRACELOGGING_DEFINE_PROVIDER. The definition // in this file configures the provider as a normal (non-telemetry) provider. +#ifndef TraceLoggingOptionMicrosoftTelemetry #define TraceLoggingOptionMicrosoftTelemetry() \ + TraceLoggingOptionGroup(0000000000, 00000, 00000, 0000, 0000, 0000, 0000, 0000, 000, 0000, 0000) // Empty definition for TraceLoggingOptionMicrosoftTelemetry +#endif // Configuration macro for use in TRACELOGGING_DEFINE_PROVIDER. The definition // in this file configures the provider as a normal (non-telemetry) provider. diff --git a/tools/ci_build/build.py b/tools/ci_build/build.py index 09b19bd21c..760b344114 100755 --- a/tools/ci_build/build.py +++ b/tools/ci_build/build.py @@ -161,6 +161,7 @@ Use the individual flags to only run the specified stages. parser.add_argument("--enable_multi_device_test", action='store_true', help="Test with multi-device. Mostly used for multi-device GPU") parser.add_argument("--use_dml", action='store_true', help="Build with DirectML.") parser.add_argument("--use_winml", action='store_true', help="Build with WinML.") + parser.add_argument("--use_telemetry", action='store_true', help="Only official builds can set this flag to enable telemetry.") return parser.parse_args() def resolve_executable_path(command_or_path): @@ -374,6 +375,7 @@ def generate_build_tree(cmake_path, source_dir, build_dir, cuda_home, cudnn_home "-Donnxruntime_ENABLE_LANGUAGE_INTEROP_OPS=" + ("ON" if args.enable_language_interop_ops or (args.config != 'Debug' and bool(os.getenv('NIGHTLY_BUILD') == '1')) else "OFF"), "-Donnxruntime_USE_DML=" + ("ON" if args.use_dml else "OFF"), "-Donnxruntime_USE_WINML=" + ("ON" if args.use_winml and args.use_dml else "OFF"), + "-Donnxruntime_USE_TELEMETRY=" + ("ON" if args.use_telemetry else "OFF"), ] if args.use_brainslice: bs_pkg_name = args.brain_slice_package_name.split('.', 1) diff --git a/tools/ci_build/github/azure-pipelines/templates/win-ci.yml b/tools/ci_build/github/azure-pipelines/templates/win-ci.yml index 417f4bb406..874ad996a3 100644 --- a/tools/ci_build/github/azure-pipelines/templates/win-ci.yml +++ b/tools/ci_build/github/azure-pipelines/templates/win-ci.yml @@ -32,6 +32,16 @@ jobs: CUDA_VERSION: ${{ parameters.CudaVersion }} steps: + - powershell: | + if($env:WINMLTELEMETRYGUID) + { + $length = $env:WINMLTELEMETRYGUID.length + $fileContent = "#define TraceLoggingOptionMicrosoftTelemetry() \ + TraceLoggingOptionGroup("+$env:WINMLTELEMETRYGUID.substring(1, $length-2)+")" + New-Item -Path "$(Build.SourcesDirectory)\include\onnxruntime\core\platform\windows\TraceLoggingConfigPrivate.h" -ItemType "file" -Value "$fileContent" -Force + } + displayName: 'Create TraceLoggingConfigPrivate.h For WinML Telemetry' + - template: set-test-data-variables-step.yml - template: windows-build-tools-setup-steps.yml parameters: