Skip to content

Commit fc96533

Browse files
committed
Fix issue for QNNContextProc
1 parent 8d2e640 commit fc96533

File tree

2 files changed

+75
-15
lines changed

2 files changed

+75
-15
lines changed

pybind/AppBuilder.h

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,35 @@ static inline py::dtype inferOutputNumpyDtype(size_t outputSizeBytes,
140140
return fallback;
141141
}
142142

143+
ModelInfo_t getModelInfo_P(std::string model_name, std::string proc_name,
144+
std::string input, size_t graphIndex = 0) {
145+
146+
std::vector<void*> outputBuffers;
147+
std::vector<size_t> outputSize;
148+
ModelInfo_t output = g_LibAppBuilder.getModelInfo(model_name, proc_name, input);
149+
return output;
150+
}
151+
152+
std::vector<std::vector<size_t>> getInputShapes(const std::string& model_name, const std::string& proc_name){
153+
::ModelInfo_t m_moduleInfo = getModelInfo_P(model_name, proc_name, "is", /*perf_profile, graphIndex*/ 0);
154+
return m_moduleInfo.inputShapes;
155+
};
156+
157+
std::vector<std::string> getInputDataType(const std::string& model_name, const std::string& proc_name){
158+
::ModelInfo_t m_moduleInfo = getModelInfo_P(model_name, model_name, "id");
159+
return m_moduleInfo.inputDataType;
160+
};
161+
162+
std::vector<std::vector<size_t>> getOutputShapes(const std::string& model_name, const std::string& proc_name){
163+
::ModelInfo_t m_moduleInfo = getModelInfo_P(model_name, model_name, "os");
164+
return m_moduleInfo.outputShapes;
165+
};
166+
167+
std::vector<std::string> getOutputDataType(const std::string& model_name, const std::string& proc_name){
168+
::ModelInfo_t m_moduleInfo = getModelInfo_P(model_name, model_name, "od");
169+
return m_moduleInfo.outputDataType;
170+
};
171+
143172
/*
144173
QNN_LOG_LEVEL_ERROR = 1,
145174
QNN_LOG_LEVEL_WARN = 2,
@@ -310,8 +339,8 @@ std::vector<py::array> inference_P(std::string model_name, std::string proc_name
310339
//QNN_INF("inference_P::inference output vector length: %d\n", outputBuffers.size());
311340

312341
// dtype list like: ['float16', 'float16', ...]
313-
std::vector<std::string> outDtypes = g_LibAppBuilder.getOutputDataType(model_name);
314-
std::vector<std::vector<size_t>> outShapes = g_LibAppBuilder.getOutputShapes(model_name);
342+
std::vector<std::string> outDtypes = getOutputDataType(model_name, proc_name);
343+
std::vector<std::vector<size_t>> outShapes = getOutputShapes(model_name, proc_name);
315344

316345
std::vector<py::array> output;
317346

@@ -350,15 +379,6 @@ std::vector<py::array> inference_P(std::string model_name, std::string proc_name
350379
return output;
351380
}
352381

353-
ModelInfo_t getModelInfo_P(std::string model_name, std::string proc_name,
354-
std::string input, size_t graphIndex = 0) {
355-
356-
std::vector<void*> outputBuffers;
357-
std::vector<size_t> outputSize;
358-
ModelInfo_t output = g_LibAppBuilder.getModelInfo(model_name, proc_name, input);
359-
return output;
360-
}
361-
362382
bool ApplyBinaryUpdate(const std::vector<LoraAdapter>& lora_adapters);
363383

364384
int create_memory(std::string share_memory_name, size_t share_memory_size) {

setup.py

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88

99
# Compile Commands:
1010
# [windows]
11-
# Set QNN_SDK_ROOT=C:/Qualcomm/AIStack/QAIRT/2.40.0.251030/
11+
# Set QNN_SDK_ROOT=C:/Qualcomm/AIStack/QAIRT/2.42.0.251225/
1212
# Set QNN_SDK_ROOT=C:/Qualcomm/AIStack/QAIRT/2.38.0.250901/
1313
# python setup.py bdist_wheel
1414
# [linux]
1515
# export QNN_SDK_ROOT=~/QAIRT/2.38.0.250901/
16-
# python setup.py bdist_wheel
16+
# python setup.py bdist_wheel --hexagonarch 81
17+
# python setup.py bdist_wheel --hexagonarch 81 --toolchains aarch64-windows-msvc
1718

1819
import os
1920
import platform
@@ -23,6 +24,7 @@
2324
from pathlib import Path
2425
import shutil
2526
import zipfile
27+
from shlex import quote
2628

2729
from setuptools import Extension, setup, find_packages
2830
from setuptools.command.build_ext import build_ext
@@ -35,6 +37,37 @@
3537
sysinfo = sys.version
3638

3739
generate = "-G \"Visual Studio 17 2022\""
40+
41+
# -----------------------------------------------------------------------------
42+
# For "x64 Python + ARM64EC extension" builds:
43+
# - CMake FindPython (new mode) enforces interpreter architecture == target arch
44+
# when both Interpreter and Development are requested, which fails here.
45+
# (ARM64EC target + x64 python.exe => "Wrong architecture").
46+
# (https://learn.arm.com/learning-paths/laptops-and-desktops/win_arm64ec_porting/how-to-2/)[5](https://getdocs.org/Cmake/docs/3.21/module/findpython)
47+
# - pybind11 provides a compat/classic mode to avoid the new FindPython path,
48+
# selectable via PYBIND11_FINDPYTHON=COMPAT.
49+
# (https://stackoverflow.com/questions/64632484/cmake-python-cannot-use-the-interpreter)[4](https://github.com/msys2/MINGW-packages/issues/20569)
50+
# - We also pass multiple Python executable variables to satisfy different
51+
# discovery code paths (Python_EXECUTABLE / Python3_EXECUTABLE / PYTHON_EXECUTABLE).
52+
# (https://learn.arm.com/learning-paths/laptops-and-desktops/win_arm64ec_porting/how-to-2/)
53+
# -----------------------------------------------------------------------------
54+
def _cmake_python_hints():
55+
py = os.environ.get("PYTHON_X64_EXECUTABLE", sys.executable)
56+
# Quote for safety when paths include spaces.
57+
pyq = quote(py)
58+
# Force pybind11 to use classic/compat mode (avoid FindPython arch check).
59+
# See pybind11 CMake docs for PYBIND11_FINDPYTHON=COMPAT. [3](https://stackoverflow.com/questions/64632484/cmake-python-cannot-use-the-interpreter)[4](https://github.com/msys2/MINGW-packages/issues/20569)
60+
hints = []
61+
hints.append(f" -DPYBIND11_FINDPYTHON=COMPAT")
62+
# Make sure pybind11 classic mode finds the right version when multiple Pythons exist.
63+
hints.append(f" -DPYBIND11_PYTHON_VERSION={sys.version_info.major}.{sys.version_info.minor}")
64+
# Provide Python executable under both "new" and "old" variable names.
65+
hints.append(f" -DPython_EXECUTABLE={pyq}")
66+
hints.append(f" -DPython3_EXECUTABLE={pyq}")
67+
hints.append(f" -DPYTHON_EXECUTABLE={pyq}")
68+
return "".join(hints)
69+
70+
3871
arch = "ARM64"
3972

4073
if machine == "AMD64" or "AMD64" in sysinfo:
@@ -121,7 +154,10 @@ def build_cmake():
121154
os.mkdir("build")
122155
os.chdir("build")
123156

124-
subprocess.run("cmake .. " + generate, shell=True)
157+
# subprocess.run("cmake .. " + generate, shell=True)
158+
# Pass Python/pybind11 hints to avoid FindPython arch mismatch for x64 python + ARM64EC target.
159+
subprocess.run("cmake .. " + generate + _cmake_python_hints(), shell=True)
160+
125161
subprocess.run("cmake --build ./ --config " + CONFIG, shell=True)
126162
os.chdir("../")
127163

@@ -253,7 +289,11 @@ def build_extension(self, ext: CMakeExtension) -> None:
253289

254290
cmake_generator = os.environ.get("CMAKE_GENERATOR", "")
255291

256-
cmake_args = f" -DCMAKE_LIBRARY_OUTPUT_DIRECTORY={extdir}{os.sep}" + f" -DPYTHON_EXECUTABLE={sys.executable}" + f" -DCMAKE_BUILD_TYPE={cfg}" # not used on MSVC, but no harm
292+
# cmake_args = f" -DCMAKE_LIBRARY_OUTPUT_DIRECTORY={extdir}{os.sep}" + f" -DPYTHON_EXECUTABLE={sys.executable}" + f" -DCMAKE_BUILD_TYPE={cfg}" # not used on MSVC, but no harm
293+
# IMPORTANT:
294+
# - Do NOT rely on FindPython (new) here: it rejects x64 interpreter for ARM64EC target when Development is requested.
295+
# - Force pybind11 compat mode and pass x64 python executable via multiple variables.
296+
cmake_args = f" -DCMAKE_LIBRARY_OUTPUT_DIRECTORY={extdir}{os.sep}" + f" -DCMAKE_BUILD_TYPE={cfg}" + _cmake_python_hints() # not used on MSVC, but no harm
257297

258298
build_args = ""
259299

0 commit comments

Comments
 (0)