diff --git a/cmake/onnxruntime_unittests.cmake b/cmake/onnxruntime_unittests.cmake index 0d9b7bbf1d..5727880eaa 100644 --- a/cmake/onnxruntime_unittests.cmake +++ b/cmake/onnxruntime_unittests.cmake @@ -312,6 +312,9 @@ endif() if (onnxruntime_USE_MKLDNN) target_compile_definitions(onnxruntime_test_utils_for_framework PUBLIC USE_MKLDNN=1) endif() +if (onnxruntime_USE_DML) + target_link_libraries(onnxruntime_test_utils_for_framework PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/packages/DirectML.0.0.1/build/DirectML.targets) +endif() add_dependencies(onnxruntime_test_utils_for_framework ${onnxruntime_EXTERNAL_DEPENDENCIES}) target_include_directories(onnxruntime_test_utils_for_framework PUBLIC "${TEST_SRC_DIR}/util/include" PRIVATE ${eigen_INCLUDE_DIRS} ${ONNXRUNTIME_ROOT}) # Add the define for conditionally using the framework Environment class in TestEnvironment @@ -327,6 +330,9 @@ endif() if (onnxruntime_USE_MKLDNN) target_compile_definitions(onnxruntime_test_utils PUBLIC USE_MKLDNN=1) endif() +if (onnxruntime_USE_DML) + target_link_libraries(onnxruntime_test_utils PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/packages/DirectML.0.0.1/build/DirectML.targets) +endif() add_dependencies(onnxruntime_test_utils ${onnxruntime_EXTERNAL_DEPENDENCIES}) target_include_directories(onnxruntime_test_utils PUBLIC "${TEST_SRC_DIR}/util/include" PRIVATE ${eigen_INCLUDE_DIRS} ${ONNXRUNTIME_ROOT}) set_target_properties(onnxruntime_test_utils PROPERTIES FOLDER "ONNXRuntimeTest") diff --git a/cmake/winml.cmake b/cmake/winml.cmake index 8112392705..61ed10717f 100644 --- a/cmake/winml.cmake +++ b/cmake/winml.cmake @@ -238,6 +238,9 @@ add_dependencies(winml_lib_image winml_api_native_internal) # Link libraries target_link_libraries(winml_lib_image PRIVATE wil) +if (onnxruntime_USE_DML) + target_link_libraries(winml_lib_image PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/packages/DirectML.0.0.1/build/DirectML.targets) +endif(onnxruntime_USE_DML) ########################### @@ -337,6 +340,9 @@ add_dependencies(winml_lib_api winml_api_native_internal) # Link libraries target_link_libraries(winml_lib_api PRIVATE wil) +if (onnxruntime_USE_DML) + target_link_libraries(winml_lib_api PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/packages/DirectML.0.0.1/build/DirectML.targets) +endif(onnxruntime_USE_DML) ########################### diff --git a/winml/lib/Api.Image/DeviceHelpers.cpp b/winml/lib/Api.Image/DeviceHelpers.cpp index 093fba0d62..67824624a7 100644 --- a/winml/lib/Api.Image/DeviceHelpers.cpp +++ b/winml/lib/Api.Image/DeviceHelpers.cpp @@ -3,7 +3,9 @@ #include "pch.h" -#include "DirectML.h" +#if USE_DML +#include +#endif USE_DML #include #include #include "inc/DeviceHelpers.h" @@ -139,11 +141,14 @@ bool IsFloat16Supported(const winrt::Windows::AI::MachineLearning::LearningModel } bool IsFloat16Supported(ID3D12Device* device) { +#ifndef USE_DML + WINML_THROW_HR_IF_TRUE_MSG(ERROR_NOT_SUPPORTED, true, "IsFloat16Supported is not implemented for WinML only build."); + return false; +#else bool isBlocked; if (FAILED(IsFloat16Blocked(*device, &isBlocked)) || isBlocked) { return false; } - winrt::com_ptr dmlDevice; winrt::check_hresult(DMLCreateDevice( device, @@ -159,8 +164,8 @@ bool IsFloat16Supported(ID3D12Device* device) { &float16Query, sizeof(float16Data), &float16Data)); - return float16Data.IsSupported; +#endif USE_DML } // uses Structured Exception Handling (SEH) to detect for delay load failures of target API.