From e4f2691250177f7bf5ab86a59c51516ee8a01fc9 Mon Sep 17 00:00:00 2001 From: Samaresh Kumar Singh Date: Thu, 22 Jan 2026 20:08:15 -0600 Subject: [PATCH] Fix: DirectML device enumeration fails with --temp-dir option Fixes #8 When --temp-dir is set to current directory (.), the DirectML/DXCore device enumeration would fail because AddDllDirectory() returns an invalid handle. This caused device enumeration to return empty list, making even device ID 0 invalid and preventing benchmark initialization. --- src/CIL/common/directml/adapter_enumeration.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/CIL/common/directml/adapter_enumeration.cpp b/src/CIL/common/directml/adapter_enumeration.cpp index b7ead711..8391d23d 100644 --- a/src/CIL/common/directml/adapter_enumeration.cpp +++ b/src/CIL/common/directml/adapter_enumeration.cpp @@ -102,9 +102,12 @@ std::vector EnumerateDirectMLAdapters( const std::string& directml_directory) { LibraryPathHandle path_handle; - if (!directml_directory.empty()) { + // Only add to DLL search path if directory is not empty and contains actual DLL files + // Skip for current directory "." as it may interfere with system DLL loading + if (!directml_directory.empty() && + fs::exists(fs::path(directml_directory) / "DirectML.dll")) { path_handle = AddLibraryPath(directml_directory); - if (!path_handle.IsValid()) return {}; + // Don't fail if AddLibraryPath returns invalid handle, just proceed without it }; ScopeExit library_path_cleanup([path_handle]() { @@ -239,9 +242,12 @@ std::vector EnumerateDXCoreAdapters( const std::string& dxcore_directory) { LibraryPathHandle path_handle; - if (!dxcore_directory.empty()) { + // Only add to DLL search path if directory is not empty and contains actual DLL files + // Skip for current directory "." as it may interfere with system DLL loading + if (!dxcore_directory.empty() && + fs::exists(fs::path(dxcore_directory) / "DXCore.dll")) { path_handle = AddLibraryPath(dxcore_directory); - if (!path_handle.IsValid()) return {}; + // Don't fail if AddLibraryPath returns invalid handle, just proceed without it }; ScopeExit library_path_cleanup([path_handle]() { @@ -367,4 +373,4 @@ const DeviceEnumeration::DeviceList& DeviceEnumeration::EnumerateDevices( } // namespace common } // namespace cil -#endif \ No newline at end of file +#endif