Skip to content
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

enable android build #715

Merged
merged 18 commits into from
Apr 18, 2019
Merged

enable android build #715

merged 18 commits into from
Apr 18, 2019

Conversation

daquexian
Copy link
Contributor

@daquexian daquexian commented Mar 27, 2019

Fix #271, tested with android ndk r19b.

I don't use build.sh but only cmake

cmake -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake -DANDROID_CPP_FEATURES=exceptions -DANDROID_PLATFORM=android-28 -DANDROID_ABI=arm64-v8a -DCMAKE_BUILD_TYPE=Release -Donnxruntime_CROSS_COMPILING=ON -Donnxruntime_BUILD_x86=OFF -DONNX_CUSTOM_PROTOC_EXECUTABLE=/usr/bin/protoc ../cmake 

My changes:

  1. Android NDK (at least for r19b) always output x86_64-unknown-linux-gnu for -dumpmachine on my PC, so the arch should be determined by the cmake official way
  2. Android NDK doesn't support filesystem so far (std::filesystem support android/ndk#609), so I set the two flags explicitly for Android. What's more, the header_files_test should be disabled if filesystem is not supported. Filesystem is not needed since fb2a44f.

The result of onnxruntime_test_all on Android:

[----------] Global test environment tear-down
[==========] 957 tests from 104 test cases ran. (3713 ms total)
[ PASSED ] 918 tests.
[ FAILED ] 39 tests, listed below:
[ FAILED ] GraphTransformationTests.IdentityElimination
[ FAILED ] GraphTransformationTests.SliceElimination
[ FAILED ] GraphTransformationTests.ConstantFolding1
[ FAILED ] GraphTransformationTests.FuseConvBNMulAddUnsqueeze
[ FAILED ] GraphTransformationTests.FuseConvActivation
[ FAILED ] GraphTransformationTests.FuseConvBNNoBias
[ FAILED ] GraphTransformationTests.FuseConvMulNoBias
[ FAILED ] GraphTransformationTests.FuseConvAddNoBias
[ FAILED ] GraphTransformationTests.FuseConvBNMulAddUnsqueezeNoBias
[ FAILED ] GraphTransformationTests.FuseConvAddMul3D
[ FAILED ] GraphTransformationTests.MatMulAddFusion_two_input
[ FAILED ] GraphTransformationTests.MatMulAddFusion_three_input
[ FAILED ] GraphTransformationTests.Gemm_Relu_three_input
[ FAILED ] GraphTransformationTests.FuseConvBnAddMulFloat16
[ FAILED ] Float16_Tests.Mul_16_Test
[ FAILED ] InferenceSessionTests.NoTimeout
[ FAILED ] InferenceSessionTests.DisableCPUArena
[ FAILED ] InferenceSessionTests.CheckRunLogger
[ FAILED ] InferenceSessionTests.CheckRunProfilerWithSessionOptions
[ FAILED ] InferenceSessionTests.CheckRunProfilerWithStartProfile
[ FAILED ] InferenceSessionTests.MultipleSessionsNoTimeout
[ FAILED ] InferenceSessionTests.PreAllocateOutputVector
[ FAILED ] InferenceSessionTests.ConfigureVerbosityLevel
[ FAILED ] InferenceSessionTests.TestWithIstream
[ FAILED ] InferenceSessionTests.TestRegisterExecutionProvider
[ FAILED ] InferenceSessionTests.InvalidInputTypeOfTensorElement
[ FAILED ] InferenceSessionTests.ModelWithoutOpset
[ FAILED ] InferenceSessionTests.TestTruncatedSequence
[ FAILED ] InferenceSessionTests.TestCopyToFromDevices
[ FAILED ] InferenceSessionTests.TestL1Transformers
[ FAILED ] InferenceSessionTests.TestL1AndL2Transformers
[ FAILED ] InferenceSessionTests.TestCustomTransformers
[ FAILED ] InferenceSessionTests.DisableAllTransformers
[ FAILED ] CustomKernelTests.CustomKernelWithBuildInSchema
[ FAILED ] CustomKernelTests.CustomKernelWithCustomSchema
[ FAILED ] CustomKernelTests.CustomKernelWithOptionalOutput
[ FAILED ] MemcpyTest.copy1
[ FAILED ] Random.MultinomialGoodCase
[ FAILED ] Random.MultinomialDefaultDType

@daquexian daquexian requested a review from a team as a code owner March 27, 2019 04:46
@msftclas
Copy link

msftclas commented Mar 27, 2019

CLA assistant check
All CLA requirements met.

@snnn
Copy link
Member

snnn commented Mar 27, 2019

libprotobuf-lite is a static lib, you don't need to call target_link_libraries on it. Therefore, I don't think you need to change protobuf's source code.

@snnn snnn requested a review from a team March 27, 2019 08:55
@daquexian
Copy link
Contributor Author

@snnn Thanks for your review. Even though protobuf-lite is a static lib, the compiler flag will be spread to the executable by cmake.

And what is your opinion on protocolbuffers/protobuf#2719? -llog should be added somewhere to solve the undefined reference.

@daquexian
Copy link
Contributor Author

daquexian commented Mar 30, 2019

@snnn I have rebased this branch on master. However I believe -llog should be added somewhere to solve the undefined reference caused by protocolbuffers/protobuf#2719

A possible solution is that since the minimum cmake version is 3.13 now, we can set CMP0079 to NEW so that we can add dependency to protobuf-lite in onnxruntime's cmake.

@snnn
Copy link
Member

snnn commented Apr 2, 2019

In CMakeLists.txt, you may add "log" to onnxruntime_EXTERNAL_LIBRARIES.

@snnn
Copy link
Member

snnn commented Apr 2, 2019

Hi @manashgoswami, could you find someone verifying this PR? Thanks

@daquexian
Copy link
Contributor Author

daquexian commented Apr 2, 2019

@snnn Thanks! I have updated my PR according to your advice. Now the tests compile.

@snnn
Copy link
Member

snnn commented Apr 2, 2019

Are you doing cross-compiling or native ?

@daquexian
Copy link
Contributor Author

@snnn cross-compiling via android ndk.

@snnn
Copy link
Member

snnn commented Apr 2, 2019

the arch should be determined by the cmake official way

Any suggestion?

@daquexian
Copy link
Contributor Author

daquexian commented Apr 2, 2019

@snnn My PR determines the architecture by CMAKE_ANDROID_ARCH_ABI, which is the variable used by CMake. This is what "cmake official way" means :)

Reference: The cmake manual for Android and CMAKE_ANDROID_ARCH_ABI.

@@ -581,6 +581,10 @@ else()
set(onnxruntime_EXTERNAL_LIBRARIES_DEBUG ${onnxruntime_EXTERNAL_LIBRARIES})
endif()

if (CMAKE_SYSTEM_NAME STREQUAL "Android")
list(APPEND onnxruntime_EXTERNAL_LIBRARIES log)
Copy link
Member

Choose a reason for hiding this comment

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

What's this library for?

@daquexian
Copy link
Contributor Author

Hi @snnn @yufenglee , is there still something I need to do for this PR? :)

@pranavsharma
Copy link
Contributor

@daquexian can you please check-in a CI yaml file to ensure future changes don't break the Android build?

@daquexian
Copy link
Contributor Author

@pranavsharma Hi, I have uploaded the new ci pipeline, however, I haven't tested it and I don't know how to enable it.

I build binary directly by cmake instead of build.py, so the python part is not needed. If you approve this way, I will remove all the code about python in android pipeline.

@daquexian daquexian closed this Apr 17, 2019
@daquexian daquexian reopened this Apr 17, 2019
@daquexian
Copy link
Contributor Author

daquexian commented Apr 17, 2019

I have tested this PR using my own azure account and verified the CI works(log: https://dev.azure.com/daquexian/onnxruntime/_build/results?buildId=14 for commit 1acfb67. I have reverted two commits which are only for my own azure pipeline). Now it can be tested in this Microsoft repo as long as an admin starts the CI. @linkerzhang @snnn @pranavsharma

And @linkerzhang , could I get the privilege to start the CI of this repo for the future development?

@pranavsharma
Copy link
Contributor

/AzurePipelines run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 7 pipeline(s), but failed to run 1 pipeline(s).

@daquexian
Copy link
Contributor Author

@pranavsharma Thanks! Could you please enable the new Android CI for this PR? The yaml is tools/ci_build/github/azure-pipelines/android-arm64-crosscompile-ci-pipeline.yml

@linkerzhang linkerzhang merged commit ac82c1f into microsoft:master Apr 18, 2019
@daquexian daquexian deleted the android_build branch April 18, 2019 02:02
@daquexian
Copy link
Contributor Author

@linkerzhang Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

deploy on ARM device(Android)
6 participants