-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Fork QNNPACK into aten/src/ATen/native/quantized/cpu/qnnpack #25500
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
Conversation
INCLUDE(GNUInstallDirs) | ||
|
||
# ---[ Project and semantic versioning. | ||
PROJECT(PYTORCH_QNNPACK C CXX ASM) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed project name to PYTORCH_QNNPACK.
/** | ||
* @brief Status code for any QNNPACK function call. | ||
*/ | ||
enum pytorch_qnnp_status { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All symbols prefixed with pytorch to avoid collision.
cmake/Dependencies.cmake
Outdated
set_property(TARGET pytorch_qnnpack PROPERTY POSITION_INDEPENDENT_CODE ON) | ||
set_property(TARGET pthreadpool PROPERTY POSITION_INDEPENDENT_CODE ON) | ||
set_property(TARGET cpuinfo PROPERTY POSITION_INDEPENDENT_CODE ON) | ||
endif() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please double check all changes in this file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have we tried to compile it with C++? It might be easier that way as we can use namespaces.
Also, is the plan to just blindly pull in all of qnnpack (like in this PR) or be more selective? cc @ajtulloch for advice too
INCLUDE(GNUInstallDirs) | ||
|
||
# ---[ Project and semantic versioning. | ||
PROJECT(PYTORCH_QNNPACK C CXX ASM) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can also just drop it as we'd be compiling it inline (but not sure)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that is true. My goal was to minimize modifications to make sure I am not breaking anything in the process inadvertently since different flags may be used between PyTorch and QNNPACK for compilation and linking, but I can definitely try that if that's what you prefer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have we tried to compile it with C++? It might be easier that way as we can use namespaces.
I actually asked the same question about namespace offline :) I don't know how much work to recompile with c++ though. In worst case we can change it back to namespace when things are more clear?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK so I tried compiling with C++, but it's a good deal of work. The compiler is complaining about jumps (use of goto to be exact) bypassing variable initializations, and use of 'restrict' (as it's not a C++ keyword.) All of this can be worked around (using __restrict for instance instead of restrict and initializing all these variables to null / zero prior at them being jumped over), but it's a good deal of work. Making these changes is actually one thing and not terribly difficult, but making sure they do not introduce any hidden bugs is a whole another can of worms that I would rather not open at this point.
https://gist.github.com/AshkanAliabadi/d7e78ce6c0ea6e9b092d71a9bb96b9de
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to compile with C++ for new files. I am planning on adding new APIs to make QNNPACK more functional and it would be a bit clunky if they are written in C as well. That can be part of a different PR though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't have any problems adding new C++ files to QNNPack. QNNPack already has C++ files in the form of tests and benchmarks. It is just that modifying the C files to make them C++-conformant is more work that we can take on right now.
@@ -0,0 +1,123 @@ | |||
/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
have we tried to recompile qnnpack code with c++ - then we can drop this and instead rely on main PyTorch's logging
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can definitely do that but we are under somewhat of a time constraint here. What was supposed to be a simple change (add support for runtime quantization) has already taken a long time because of all this back and forth, but I can definitely make this change if you have a strong preference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's try to make this PR a simple copy and do meaningful changes in separate PRs.
Is it a simple compiler change or do we need fix syntax / measure perf impact / etc?
Sounds like something nice to have - I feel if we have new features to be written in c++ then it's more urgent change, otherwise we can try it after finishing other critical perf work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please refer to my comment above:
OK so I tried compiling with C++, but it's a good deal of work. The compiler is complaining about jumps (use of goto to be exact) bypassing variable initializations, and use of 'restrict' (as it's not a C++ keyword.) All of this can be worked around (using __restrict for instance instead of restrict and initializing all these variables to null / zero prior at them being jumped over), but it's a good deal of work. Making these changes is actually one thing and not terribly difficult, but making sure they do not introduce any hidden bugs is a whole another can of worms that I would rather not open at this point.
https://gist.github.com/AshkanAliabadi/d7e78ce6c0ea6e9b092d71a9bb96b9de
The PR description on this change is insufficient. In private communication you have given more information about why this is being done, but this needs to be recorded in the PR itself, so that people can easily find the information after the fact. |
My questions are primarily procedural:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's land it to keep the ball rolling.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AshkanAliabadi has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AshkanAliabadi has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
Summary: The motivation for this move, and our long-term commitment to maintaining and integrating this code into ATen is described in the issue below: pytorch/pytorch#25621 Pull Request resolved: pytorch/pytorch#25500 Test Plan: QNNPack unit tests, as follows: OSS: x86: mkdir build; cd build; cmake ..; make all -j16 && make test All 26 unit tests pass, both when built with ADD_DEFINITIONS(-DPYTORCH_QNNPACK_RUNTIME_QUANTIZATION=0) and ADD_DEFINITIONS(-DPYTORCH_QNNPACK_RUNTIME_QUANTIZATION=1) ARM: Make sure you have an android device available to adb either through one world or directly connected. To compile and push do $> adb shell mkdir /data/qnnpack && ./scripts/build-android-arm64.sh && adb push ./build/android/arm64-v8a/*-test /data/qnnpack To execute tests, first $> adb shell to login into the device, then run all the tests by $> for t in $(ls /data/qnnpack); do /data/qnnpack/$t; done Repeat the exact same process with ADD_DEFINITIONS(-DPYTORCH_QNNPACK_RUNTIME_QUANTIZATION=0), and ADD_DEFINITIONS(-DPYTORCH_QNNPACK_RUNTIME_QUANTIZATION=1) Repeat the exact same process with ./scripts/build-android-armv7.sh for AARCH32. Reviewed By: ljk53 Differential Revision: D17194732 Pulled By: AshkanAliabadi fbshipit-source-id: 9e627338ebd63aa917a36b717618c0643ccf40c8
@AshkanAliabadi merged this pull request in 825f471. |
The motivation for this move, and our long-term commitment to maintaining and integrating this code into ATen is described in the issue below:
#25621