Skip to content

Conversation

@ljk53
Copy link
Contributor

@ljk53 ljk53 commented Sep 7, 2019

Stack from ghstack:

Summary:
On Android we will release a small set of native APIs designed for mobile use
cases. All of needed libtorch c++ APIs are called from inside this JNI bridge:
android/pytorch_android/src/main/cpp/pytorch_jni.cpp

With NO_EXPORT set for android static library build, it will hide all
original TORCH, CAFFE2, TH/ATen APIs, which will allow linker to strip
out unused ones from mobile library when producing DSO.

If people choose to directly build libtorch DSO then it will still keep
all c++ APIs as the mobile API layer is not part of libtorch build (yet).

Test Plan:

  • build libtorch statically and link into demo app;
  • confirm that linker can strip out unused APIs;

Pull Request resolved: #25816

Differential Revision: D17247237

Summary:
On Android we will release a small set of native APIs designed for mobile use
cases. All of needed libtorch c++ APIs are called from inside this JNI bridge:
android/pytorch_android/src/main/cpp/pytorch_jni.cpp

With NO_EXPORT set for android static library build, it will hide all
original TORCH, CAFFE2, TH/ATen APIs, which will allow linker to strip
out unused ones from mobile library when producing DSO.

If people choose to directly build libtorch DSO then it will still keep
all c++ APIs as the mobile API layer is not part of libtorch build (yet).

Test Plan:
- build libtorch statically and link into demo app;
- confirm that linker can strip out unused APIs;
Copy link
Contributor

@ezyang ezyang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this is exhaustive, but it's fine as a start.

Will we add some sort of test that will audit the number of visible symbols, to make sure they are what we expect?

@ljk53
Copy link
Contributor Author

ljk53 commented Sep 9, 2019

I'm not sure this is exhaustive, but it's fine as a start.

Looks like torch/* all use TORCH_API, caffe2/* all use CAFFE2_API - both are now defined as C10_API / C10_EXPORT. There are a few cases directly exported using C10_EXPORT. So redefining C10_EXPORT should cover most of them.

Will we add some sort of test that will audit the number of visible symbols, to make sure they are what we expect?

I was thinking of tracking the android gradle build size directly. Will see how hard it is to count visible symbols.

…y__ attribute"

Summary:
On Android we will release a small set of native APIs designed for mobile use
cases. All of needed libtorch c++ APIs are called from inside this JNI bridge:
android/pytorch_android/src/main/cpp/pytorch_jni.cpp

With NO_EXPORT set for android static library build, it will hide all
original TORCH, CAFFE2, TH/ATen APIs, which will allow linker to strip
out unused ones from mobile library when producing DSO.

If people choose to directly build libtorch DSO then it will still keep
all c++ APIs as the mobile API layer is not part of libtorch build (yet).

Test Plan:
- build libtorch statically and link into demo app;
- confirm that linker can strip out unused APIs;

Pull Request resolved: #25816

Differential Revision: [D17247237](https://our.internmc.facebook.com/intern/diff/D17247237)
…y__ attribute"

Summary:
On Android we will release a small set of native APIs designed for mobile use
cases. All of needed libtorch c++ APIs are called from inside this JNI bridge:
android/pytorch_android/src/main/cpp/pytorch_jni.cpp

With NO_EXPORT set for android static library build, it will hide all
original TORCH, CAFFE2, TH/ATen APIs, which will allow linker to strip
out unused ones from mobile library when producing DSO.

If people choose to directly build libtorch DSO then it will still keep
all c++ APIs as the mobile API layer is not part of libtorch build (yet).

Test Plan:
- build libtorch statically and link into demo app;
- confirm that linker can strip out unused APIs;

Pull Request resolved: #25816

Differential Revision: [D17247237](https://our.internmc.facebook.com/intern/diff/D17247237)
…y__ attribute"

Summary:
On Android we will release a small set of native APIs designed for mobile use
cases. All of needed libtorch c++ APIs are called from inside this JNI bridge:
android/pytorch_android/src/main/cpp/pytorch_jni.cpp

With NO_EXPORT set for android static library build, it will hide all
original TORCH, CAFFE2, TH/ATen APIs, which will allow linker to strip
out unused ones from mobile library when producing DSO.

If people choose to directly build libtorch DSO then it will still keep
all c++ APIs as the mobile API layer is not part of libtorch build (yet).

Test Plan:
- build libtorch statically and link into demo app;
- confirm that linker can strip out unused APIs;

Pull Request resolved: #25816

Differential Revision: [D17247237](https://our.internmc.facebook.com/intern/diff/D17247237)
@ezyang
Copy link
Contributor

ezyang commented Sep 10, 2019

I was thinking of tracking the android gradle build size directly.

That sounds good. @mingbowan has recently put our binary sizes in scuba, and might know what we should do here.

@facebook-github-bot
Copy link
Contributor

@ljk53 merged this pull request in 6630c3f.

zdevito pushed a commit to zdevito/ATen that referenced this pull request Sep 10, 2019
Summary:
Pull Request resolved: pytorch/pytorch#25816

On Android we will release a small set of native APIs designed for mobile use
cases. All of needed libtorch c++ APIs are called from inside this JNI bridge:
android/pytorch_android/src/main/cpp/pytorch_jni.cpp

With NO_EXPORT set for android static library build, it will hide all
original TORCH, CAFFE2, TH/ATen APIs, which will allow linker to strip
out unused ones from mobile library when producing DSO.

If people choose to directly build libtorch DSO then it will still keep
all c++ APIs as the mobile API layer is not part of libtorch build (yet).

Test Plan:
- build libtorch statically and link into demo app;
- confirm that linker can strip out unused APIs;

Differential Revision: D17247237

Pulled By: ljk53

fbshipit-source-id: de668216b5f2130da0d6988937f98770de571c7a
@facebook-github-bot facebook-github-bot deleted the gh/ljk53/36/head branch October 28, 2019 22:16
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: cpu CPU specific problem (e.g., perf, algorithm) module: internals Related to internal abstractions in c10 and ATen

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants