Skip to content

Conversation

AshkanAliabadi
Copy link
Contributor

@AshkanAliabadi AshkanAliabadi commented Aug 30, 2019

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

@pytorchbot pytorchbot added module: build Build system issues module: docs Related to our documentation, both in docs/ and docblocks module: infra Relates to CI infrastructure module: internals Related to internal abstractions in c10 and ATen module: operators oncall: quantization Quantization support in PyTorch labels Aug 30, 2019
INCLUDE(GNUInstallDirs)

# ---[ Project and semantic versioning.
PROJECT(PYTORCH_QNNPACK C CXX ASM)
Copy link
Contributor Author

@AshkanAliabadi AshkanAliabadi Aug 30, 2019

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 {
Copy link
Contributor Author

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.

@supriyar supriyar requested a review from ajtulloch August 30, 2019 22:32
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()
Copy link
Contributor Author

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.

Copy link
Collaborator

@dzhulgakov dzhulgakov left a 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)
Copy link
Collaborator

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)

Copy link
Contributor Author

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.

Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Contributor

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.

Copy link
Contributor Author

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 @@
/*
Copy link
Collaborator

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

Copy link
Contributor Author

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.

Copy link
Contributor

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?

Copy link
Contributor Author

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

@ezyang ezyang self-requested a review September 4, 2019 00:14
@ezyang
Copy link
Contributor

ezyang commented Sep 4, 2019

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.

@ezyang
Copy link
Contributor

ezyang commented Sep 4, 2019

My questions are primarily procedural:

  1. What is the long term plan for this fork? Based on Users/ashkan/requantize QNNPACK#66 it doesn't look like you intend to ever upstream this as a compile time option. QNNPACK seems to be a low maintenance library, but judging from the commit history, maintenance does happen. Are upstream fixes going to make it back to this fork, or is this fork just striking it out on its own? If you strike it out on your own, we are responsible for the long term maintenance of this copy. Do we have the appropriate knowledge and bandwidth to do so? (Standard litmus test: you need to get a code review on a functional change to this fork of QNNPACK, in this repository. Who can you get it from in a timely manner? Is this @ajtulloch?)

  2. You haven't deleted the old copy of qnnpack. Based on @ajtulloch's comment in the old PR, it sounds like you want to end up in a place where this version of qnnpack is closely integrated with facilities in PyTorch. When can the old copy of qnnpack be deleted? Or if it can't be deleted, why not?

  3. I am a random developer who happens to need to interact with our integration with qnnpack. At some point, I realize that we actually have two copies of qnnpack in the project: pytorch_qnnpack and qnnpack. Where can I find out what the difference is? How do I know which one is appropriate for my use? There appears to be zero documentation about what is going on here. (To make matters worse: this fork of qnnpack appears to already come with the functional changes proposed from Users/ashkan/requantize QNNPACK#66 ; so I cannot even run a git diff to see what the changes are.)

  4. What is the testing strategy?

@AshkanAliabadi
Copy link
Contributor Author

Thank you for your comments @ezyang. We synched offline but for the record, the motivation for this move, and our long-term commitment to maintaining and integrating this code into ATen and PyTorch is described in the issue below:

#25621

Copy link
Contributor

@ljk53 ljk53 left a 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.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a 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.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a 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.

zdevito pushed a commit to zdevito/ATen that referenced this pull request Sep 8, 2019
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
@facebook-github-bot
Copy link
Contributor

@AshkanAliabadi merged this pull request in 825f471.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Merged module: build Build system issues module: docs Related to our documentation, both in docs/ and docblocks module: infra Relates to CI infrastructure module: internals Related to internal abstractions in c10 and ATen oncall: quantization Quantization support in PyTorch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants