Skip to content
60 changes: 30 additions & 30 deletions onnxruntime/core/providers/qnn/qnn_provider_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,6 @@
#include "core/providers/qnn/qnn_execution_provider.h"
#include "core/providers/qnn/builder/qnn_utils.h"

/// @brief Gets the path of directory containing the dynamic library that contains the address.
/// @param address An address of a function or variable in the dynamic library.
/// @return The path of the directory containing the dynamic library, or an empty string if the path cannot be determined.
static onnxruntime::PathString GetDynamicLibraryLocationByAddress(const void* address) {
#ifdef _WIN32
HMODULE moduleHandle;
if (!::GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
reinterpret_cast<LPCWSTR>(address), &moduleHandle)) {
return {};
}
std::wstring buffer;
for (std::uint32_t size{70}; size < 4096; size *= 2) {
buffer.resize(size, L'\0');
const std::uint32_t requiredSize = ::GetModuleFileNameW(moduleHandle, buffer.data(), size);
if (requiredSize == 0) {
break;
}
if (requiredSize == size) {
continue;
}
buffer.resize(requiredSize);
return {std::move(buffer)};
}
#else
std::ignore = address;
#endif
return {};
}

namespace onnxruntime {
struct QNNProviderFactory : IExecutionProviderFactory {
QNNProviderFactory(const ProviderOptions& provider_options_map, const ConfigOptions* config_options)
Expand Down Expand Up @@ -148,6 +119,35 @@ ORT_API(onnxruntime::Provider*, GetProvider) {
#include "core/framework/error_code_helper.h"
#include "onnxruntime_config.h" // for ORT_VERSION

/// @brief Gets the path of directory containing the dynamic library that contains the address.
/// @param address An address of a function or variable in the dynamic library.
/// @return The path of the directory containing the dynamic library, or an empty string if the path cannot be determined.
static onnxruntime::PathString GetDynamicLibraryLocationByAddress(const void* address) {
#ifdef _WIN32
HMODULE moduleHandle;
if (!::GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
reinterpret_cast<LPCWSTR>(address), &moduleHandle)) {
return {};
}
std::wstring buffer;
for (std::uint32_t size{70}; size < 4096; size *= 2) {
buffer.resize(size, L'\0');
const std::uint32_t requiredSize = ::GetModuleFileNameW(moduleHandle, buffer.data(), size);
if (requiredSize == 0) {
break;
}
if (requiredSize == size) {
continue;
}
buffer.resize(requiredSize);
return {std::move(buffer)};
}
#else
std::ignore = address;
#endif
return {};
}

// OrtEpApi infrastructure to be able to use the QNN EP as an OrtEpFactory for auto EP selection.
struct QnnEpFactory : OrtEpFactory {
QnnEpFactory(const OrtApi& ort_api_in,
Expand Down Expand Up @@ -268,7 +268,7 @@ struct QnnEpFactory : OrtEpFactory {
}

static OrtStatus* ORT_API_CALL CreateSyncStreamForDeviceImpl(OrtEpFactory* this_ptr,
const OrtMemoryDevice* memory_device,
const OrtMemoryDevice* /*memory_device*/,
const OrtKeyValuePairs* /*stream_options*/,
OrtSyncStreamImpl** ort_stream) noexcept {
auto& factory = *static_cast<QnnEpFactory*>(this_ptr);
Expand Down
2 changes: 2 additions & 0 deletions onnxruntime/test/providers/qnn/einsum_op_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ constexpr char kEinsumOp[] = "Einsum";
constexpr char kEinsumEquation[] = "equation";
constexpr char kQnnBackendType[] = "backend_type";
constexpr char kQnnBackendTypeCpu[] = "cpu";
#if defined(_M_ARM64)
constexpr char kQnnBackendTypeGpu[] = "gpu";
#endif
constexpr char kQnnBackendTypeHtp[] = "htp";
constexpr char kOffloadGraphIoQuantization[] = "offload_graph_io_quantization";
constexpr char kOffloadGraphIoQuantizationDisable[] = "0";
Expand Down
2 changes: 2 additions & 0 deletions tools/ci_build/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ def use_dev_mode(args):
return False
if is_macOS() and (args.ios or args.visionos or args.tvos):
return False
if args.use_qnn:
return True
SYSTEM_COLLECTIONURI = os.getenv("SYSTEM_COLLECTIONURI") # noqa: N806
if SYSTEM_COLLECTIONURI and SYSTEM_COLLECTIONURI != "https://dev.azure.com/onnxruntime/":
return False
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ stages:
name: ${{ parameters.qnn_ep_build_pool_name }}
variables:
OrtPackageId: ${{ parameters.OrtNugetPackageId }}
commonBuildArgs: '--compile_no_warning_as_error --skip_submodule_sync --build_shared_lib --client_package_build --cmake_generator "Visual Studio 17 2022" --config ${{ parameters.build_config }} --parallel --use_vcpkg --use_vcpkg_ms_internal_asset_cache --use_binskim_compliant_compile_flags '
commonBuildArgs: '--skip_submodule_sync --build_shared_lib --client_package_build --cmake_generator "Visual Studio 17 2022" --config ${{ parameters.build_config }} --parallel --use_vcpkg --use_vcpkg_ms_internal_asset_cache --use_binskim_compliant_compile_flags '

steps:
- template: set-version-number-variables-step.yml
Expand Down
Loading