Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support DML provider on Windows #220

Merged
merged 6 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ else()
list(REMOVE_ITEM generator_srcs ${generator_cuda_srcs})
endif()

if(USE_DML)
if(WIN32)
add_compile_definitions(USE_DML=1)
else()
message(FATAL_ERROR "USE_DML is ON but this isn't windows.")
endif()
endif()

if(ENABLE_TESTS AND TEST_PHI2)
add_compile_definitions(TEST_PHI2=1)
else()
Expand Down
4 changes: 4 additions & 0 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def validate_cuda_home(cuda_home: str | bytes | os.PathLike | None):
def build(
skip_wheel: bool = False,
use_cuda: bool | None = None,
use_dml: bool | None = None,
cuda_home: str | bytes | os.PathLike | None = None,
cmake_generator: str | None = None,
ort_home: str | bytes | os.PathLike | None = None,
Expand Down Expand Up @@ -141,6 +142,7 @@ def build(
"-DCMAKE_POSITION_INDEPENDENT_CODE=ON",
"-DUSE_CXX17=ON",
"-DUSE_CUDA=ON" if cuda_home else "-DUSE_CUDA=OFF",
"-DUSE_DML=ON" if use_dml else "-DUSE_DML=OFF",
f"-DBUILD_WHEEL={build_wheel}",
]

Expand Down Expand Up @@ -218,6 +220,7 @@ def build(
parser.add_argument("--skip_csharp", action="store_true", help="Skip building the C# API.")
parser.add_argument("--build_dir", default=None, help="Path to output directory.")
parser.add_argument("--use_cuda", action="store_true", help="Whether to use CUDA. Default is to not use cuda.")
parser.add_argument("--use_dml", action="store_true", help="Whether to use DML. Default is to not use DML.")
parser.add_argument("--parallel", action="store_true", help="Enable parallel build.")
parser.add_argument(
"--config",
Expand All @@ -231,6 +234,7 @@ def build(
build(
skip_wheel=args.skip_wheel,
use_cuda=args.use_cuda,
use_dml=args.use_dml,
cuda_home=args.cuda_home,
cmake_generator=args.cmake_generator,
ort_home=args.ort_home,
Expand Down
1 change: 1 addition & 0 deletions cmake/options.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
include(CMakeDependentOption)

option(USE_CUDA "Build with CUDA support" ON)
option(USE_DML "Build with DML support" OFF)
option(NO_TOKENIZER "Don't include the Tokenizer" OFF)
option(ENABLE_PYTHON "Build the Python API." ON)
option(ENABLE_TESTS "Enable tests" ON)
Expand Down
14 changes: 13 additions & 1 deletion src/models/model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
#include "decoder_only.h"
#include "whisper.h"
#include "kernels.h"
#ifdef USE_DML
// Because dml_provider_factory includes windows headers that #define min and max, this next line will prevent this from happening
#define NOMINMAX
#include "dml_provider_factory.h"
#endif

namespace Generators {

Expand Down Expand Up @@ -291,7 +296,14 @@ void Model::CreateSessionOptions() {

Ort::ThrowOnError(Ort::api->UpdateROCMProviderOptions(&ort_provider_options, keys.data(), values.data(), keys.size()));
ort_options.AppendExecutionProvider_ROCM(ort_provider_options);
device_type_ = DeviceType::CPU; // Scoring uses CPU, even though the model uses ROCM
#ifdef USE_DML
} else if (provider_options.name == "dml") {
const OrtDmlApi* p_dml_api{};
Ort::ThrowOnError(Ort::api->GetExecutionProviderApi("DML", ORT_API_VERSION, reinterpret_cast<const void**>(&p_dml_api)));
if (!p_dml_api)
throw std::runtime_error("Unexpected nullptr getting OrtDmlApi");
p_dml_api->SessionOptionsAppendExecutionProvider_DML(&ort_options, 0);
#endif
} else
throw std::runtime_error("Unknown provider type: " + provider_options.name);
}
Expand Down
Loading