Repository: microsoft/onnxruntime
File: onnxruntime/core/providers/qnn/qnn_provider_factory.cc (C++)

Code before:
            factory->ort_api.GetEpApi()->CreateEpDevice(factory, &device, nullptr, ep_options,
                                                        &ep_devices[num_ep_devices++]));
      }
    }

    return nullptr;
  }

  static OrtStatus* CreateEpImpl(OrtEpFactory* /*this_ptr*/,
                                 _In_reads_(num_devices) const OrtHardwareDevice* const* /*devices*/,
                                 _In_reads_(num_devices) const OrtKeyValuePairs* const* /*ep_metadata*/,
                                 _In_ size_t /*num_devices*/,
                                 _In_ const OrtSessionOptions* /*session_options*/,
                                 _In_ const OrtLogger* /*logger*/,
                                 _Out_ OrtEp** /*ep*/) {
    return onnxruntime::CreateStatus(ORT_INVALID_ARGUMENT, "QNN EP factory does not support this method.");
  }

  static void ReleaseEpImpl(OrtEpFactory* /*this_ptr*/, OrtEp* /*ep*/) {
    // no-op as we never create an EP here.
  }

  const OrtApi& ort_api;
  const std::string ep_name;                       // EP name
  const std::string vendor{"Microsoft"};           // EP vendor name
  const uint32_t vendor_id{0x4d4f4351};            // Qualcomm vendor ID
  const OrtHardwareDeviceType ort_hw_device_type;  // Supported OrtHardwareDevice
  const std::string qnn_backend_type;              // QNN backend type for OrtHardwareDevice
};

extern "C" {
//
// Public symbols
//
OrtStatus* CreateEpFactories(const char* /*registration_name*/, const OrtApiBase* ort_api_base,
                             OrtEpFactory** factories, size_t max_factories, size_t* num_factories) {
  const OrtApi* ort_api = ort_api_base->GetApi(ORT_API_VERSION);

  // Factory could use registration_name or define its own EP name.
  auto factory_npu = std::make_unique<QnnEpFactory>(*ort_api,
                                                    onnxruntime::kQnnExecutionProvider,
                                                    OrtHardwareDeviceType_NPU, "htp");

  // If want to support GPU, create a new factory instance because QNN EP is not currently setup to partition a single model
  // among heterogeneous devices.
  // std::unique_ptr<OrtEpFactory> factory_gpu = std::make_unique<QnnEpFactory>(*ort_api, "QNNExecutionProvider_GPU", OrtHardwareDeviceType_GPU, "gpu");

  if (max_factories < 1) {
    return ort_api->CreateStatus(ORT_INVALID_ARGUMENT,
                                 "Not enough space to return EP factory. Need at least one.");
  }

Review comment (suggestion):
should maybe point out that this isn't an official vendor id. it's an arbitrary value created by bitshifting QCOM. a link to the cpuid_info code would be good. 

https://github.com/microsoft/onnxruntime/blob/6fa8ba107f461d72073ee4842830a9d0a96d2546/onnxruntime/core/common/cpuid_info.cc#L158

but maybe I've screwed that up. I shifted the Q by 24 bits (original code had it as the first byte) thinking that would make the values 0xQCOM but if the vendor_id is 0x4d4f4351 I've not taken into account it's little endian and I've made it 0xMOCQ which is the complete opposite of my intention.

Code after:
            factory->ort_api.GetEpApi()->CreateEpDevice(factory, &device, nullptr, ep_options,
                                                        &ep_devices[num_ep_devices++]));
      }
    }

    return nullptr;
  }

  static OrtStatus* CreateEpImpl(OrtEpFactory* /*this_ptr*/,
                                 _In_reads_(num_devices) const OrtHardwareDevice* const* /*devices*/,
                                 _In_reads_(num_devices) const OrtKeyValuePairs* const* /*ep_metadata*/,
                                 _In_ size_t /*num_devices*/,
                                 _In_ const OrtSessionOptions* /*session_options*/,
                                 _In_ const OrtLogger* /*logger*/,
                                 _Out_ OrtEp** /*ep*/) {
    return onnxruntime::CreateStatus(ORT_INVALID_ARGUMENT, "QNN EP factory does not support this method.");
  }

  static void ReleaseEpImpl(OrtEpFactory* /*this_ptr*/, OrtEp* /*ep*/) {
    // no-op as we never create an EP here.
  }

  const OrtApi& ort_api;
  const std::string ep_name;              // EP name
  const std::string vendor{"Microsoft"};  // EP vendor name

  // Qualcomm vendor ID. Refer to the ACPI ID registry (search Qualcomm): https://uefi.org/ACPI_ID_List
  const uint32_t vendor_id{'Q' | ('C' << 8) | ('O' << 16) | ('M' << 24)};
  const OrtHardwareDeviceType ort_hw_device_type;  // Supported OrtHardwareDevice
  const std::string qnn_backend_type;              // QNN backend type for OrtHardwareDevice
};

extern "C" {
//
// Public symbols
//
OrtStatus* CreateEpFactories(const char* /*registration_name*/, const OrtApiBase* ort_api_base,
                             OrtEpFactory** factories, size_t max_factories, size_t* num_factories) {
  const OrtApi* ort_api = ort_api_base->GetApi(ORT_API_VERSION);

  // Factory could use registration_name or define its own EP name.
  auto factory_npu = std::make_unique<QnnEpFactory>(*ort_api,
                                                    onnxruntime::kQnnExecutionProvider,
                                                    OrtHardwareDeviceType_NPU, "htp");

  // If want to support GPU, create a new factory instance because QNN EP is not currently setup to partition a single model
  // among heterogeneous devices.
  // std::unique_ptr<OrtEpFactory> factory_gpu = std::make_unique<QnnEpFactory>(*ort_api, "QNNExecutionProvider_GPU", OrtHardwareDeviceType_GPU, "gpu");

  if (max_factories < 1) {
    return ort_api->CreateStatus(ORT_INVALID_ARGUMENT,