-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Caffe2 ARM ComputeLibrary integration #2015
Conversation
@jerryzh168 has updated the pull request. View: changes |
caffe2/mobile/contrib/CMakeLists.txt
Outdated
@@ -1,5 +1,8 @@ | |||
add_subdirectory(ios) | |||
add_subdirectory(opengl) | |||
if (USE_ARM_COMPUTE AND ANDROID) | |||
add_subdirectory(arm-compute) |
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 convert to spaces
@@ -0,0 +1,11 @@ | |||
if(USE_ARM_COMPUTE AND ANDROID) |
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.
Typically we just disable options on unsupported platforms, e.g. see https://github.com/caffe2/caffe2/blob/1f9e79f920a22aed1a370bf5faec1ce5e1ef73d7/cmake/Dependencies.cmake#L460-L465
brew install scons | ||
``` | ||
|
||
use the build\_android.sh: |
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.
typo?
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.
Which word? build_android.sh? that is probably for markdown..
|
||
CAFFE_DEFINE_REGISTRY(GLOperatorRegistry, OperatorBase, const OperatorDef &, | ||
Workspace *); | ||
CAFFE_REGISTER_DEVICE_TYPE(DeviceType::OPENGL, GLOperatorRegistry); |
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.
This probably collides with our OpenGL ES 3.0 backend
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.
Is OpenGL ES 3.0 backend removed already?
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.
No, its still in the source tree, and potentially even being built.
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.
Should we change it to something else? I think DeviceType::OPENGL is a pre-defined device type.
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.
I think we should use a different device type, similar to how we use different device type for MKL-DNN (which, albeit runs on CPU, keeps tensors in a non-standard layout)
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.
cc @hlu1 to check if this can conflict with OpenGL ES 3.0
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.
#ifdef CAFFE2_OPENGL_BACKEND
#error Can only build one OpenGL backend at a time.
#else
#define CAFFE2_OPENGL_BACKEND
#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.
OpenGL ES 3.0 backend does not use DeviceType. It prefixes operator names with OpenGL instead
CMakeLists.txt
Outdated
@@ -25,6 +25,7 @@ cmake_dependent_option( | |||
"NOT BUILD_SHARED_LIBS" OFF) | |||
option(BUILD_OBSERVERS "Build performance observers/loggers in caffe2/share/observers directory" OFF) | |||
option(BUILD_TEST "Build C++ test binaries (need gtest and gbenchmark)" ON) | |||
option(USE_ARM_COMPUTE "Use ARM Compute Library" ON) |
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.
lets turn this off by default, as it has a scons dependency at the moment
.gitmodules
Outdated
@@ -61,6 +61,9 @@ | |||
[submodule "third_party/python-six"] | |||
path = third_party/python-six | |||
url = https://github.com/benjaminp/six.git | |||
[submodule "third_party/ComputeLibrary"] | |||
path = third_party/ComputeLibrary | |||
url = https://github.com/ARM-software/ComputeLibrary |
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.
.git
for consistency
scripts/build_android.sh
Outdated
|
||
# Disable unused dependencies | ||
CMAKE_ARGS+=("-DUSE_CUDA=OFF") | ||
CMAKE_ARGS+=("-DUSE_GFLAGS=OFF") |
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.
can you add this back?
scripts/build_android.sh
Outdated
# Use android-cmake to build Android project from CMake. | ||
CMAKE_ARGS+=("-DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake") | ||
|
||
# Don't build artifacts we don't need | ||
CMAKE_ARGS+=("-DBUILD_TEST=OFF") | ||
CMAKE_ARGS+=("-DBUILD_TEST=ON") |
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.
I think this is on by default, either way the comment above doesn't make sense anymore
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.
Should we turn on the test by default?
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.
Better keep it off. When needed, tests can be built with scripts/build_android.sh -DBUILD_TEST=ON
scripts/build_android.sh
Outdated
CMAKE_ARGS+=($@) | ||
USE_ARM_COMPUTE=false | ||
for arg in ${CMAKE_ARGS[@]};do | ||
if [ $arg == "-DUSE_ARM_COMPUTE=ON" ];then |
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.
there are a couple other ways to set things "true" in cmake, it might be good to check for all of those
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.
-DUSE_ARM_COMPUTE=1? what else?
scripts/build_android.sh
Outdated
|
||
cmake "$CAFFE2_ROOT" \ | ||
-DCMAKE_INSTALL_PREFIX=../install \ | ||
-DCMAKE_BUILD_TYPE=Release \ | ||
"${CMAKE_ARGS[@]}" | ||
-G Ninja \ |
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.
this should not be a default
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.
some changes got lost, will revert to the master
scripts/build_android.sh
Outdated
else | ||
cmake --build . -- "-j$(nproc)" | ||
fi | ||
ninja |
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.
lets leave this bit
caffe2/CMakeLists.txt
Outdated
@@ -10,6 +10,7 @@ set(Caffe2_GPU_SRCS) | |||
# files for CPU and GPU tests respectively. | |||
set(Caffe2_CPU_TEST_SRCS) | |||
set(Caffe2_GPU_TEST_SRCS) | |||
set(Caffe2_MOBILE_TEST_SRCS) |
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.
Why do we need Caffe2_MOBILE_TEST_SRCS
? IIUC, Caffe2_GPU_TEST_SRCS
exist because it is built with a different compiler
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.
So that we can build only those tests when we build on mobile? I'm not sure, @bwasti what do you think?
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.
cc @Yangqing as well
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.
yea, we can chuck everything into CPU_TEST_SRCS. semantically, we could rename them to CC_SRCS and NVCC_SRCS huh?
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.
agree, CC_SRCS
+ NVCC_SRCS
would make more sense
scripts/build_android.sh
Outdated
|
||
cmake "$CAFFE2_ROOT" \ | ||
-DCMAKE_INSTALL_PREFIX=../install \ | ||
-DCMAKE_BUILD_TYPE=Release \ | ||
"${CMAKE_ARGS[@]}" | ||
-G Ninja \ |
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.
I like the idea of switching to ninja
, but lets leave it for a separate PR
Could you keep changes to CMakeLists to a minimum? |
@jerryzh168 has updated the pull request. View: changes |
@Maratyszcza @bwasti could you review again? it would be great if we can merge this today |
@jerryzh168 has updated the pull request. View: changes |
caffe2/CMakeLists.txt
Outdated
@@ -169,7 +182,7 @@ if (BUILD_TEST) | |||
${test_name} ${Caffe2_MAIN_LIBS} ${Caffe2_DEPENDENCY_LIBS} | |||
gtest_main) | |||
endif() | |||
if (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 3.0) | |||
if (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 3.0 AND NOT ANDROID) |
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.
Why the change? The sources still use cxx_range_for
when building for android. target_compile_features
tells CMake to set appropriate flags. Without it, compiler may default to c++98.
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.
target_compile_features
is not recognized before for some reason.. resolved now.
remaining issue |
@jerryzh168 has updated the pull request. View: changes |
CMakeLists.txt
Outdated
@@ -25,6 +25,7 @@ cmake_dependent_option( | |||
"NOT BUILD_SHARED_LIBS" OFF) | |||
option(BUILD_OBSERVERS "Build performance observers/loggers in caffe2/share/observers directory" OFF) | |||
option(BUILD_TEST "Build C++ test binaries (need gtest and gbenchmark)" ON) | |||
option(USE_ARM_COMPUTE "Use ARM Compute Library" OFF) |
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.
The name is ambiguous: users may think they have to enable it for any ARM builds. Please change to USE_ACL
, USE_ARMCL
, or USE_ARM_COMPUTE_LIBRARY
scripts/build_android.sh
Outdated
CMAKE_ARGS+=("-DBUILD_BINARY=OFF") | ||
CMAKE_ARGS+=("-DBUILD_PYTHON=OFF") | ||
CMAKE_ARGS+=("-DBUILD_SHARED_LIBS=OFF") | ||
|
||
if $USE_ARM_COMPUTE;then | ||
CMAKE_ARGS+=("-DANDROID_TOOLCHAIN_NAME=arm-linux-androideabi-4.9") |
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.
This line have the same effect as -DANDROID_TOOLCHAIN=gcc
. See https://android.googlesource.com/platform/ndk/+/master/build/cmake/android.toolchain.cmake#103
scripts/build_android.sh
Outdated
@@ -103,7 +115,7 @@ fi | |||
cmake "$CAFFE2_ROOT" \ | |||
-DCMAKE_INSTALL_PREFIX=../install \ | |||
-DCMAKE_BUILD_TYPE=Release \ | |||
"${CMAKE_ARGS[@]}" | |||
"${CMAKE_ARGS[@]}" \ |
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.
Revert?
scripts/build_android.sh
Outdated
@@ -52,6 +52,13 @@ CMAKE_ARGS=() | |||
# target architecture and need an exact version match. | |||
CMAKE_ARGS+=("-DCAFFE2_CUSTOM_PROTOC_EXECUTABLE=$CAFFE2_ROOT/build_host_protoc/bin/protoc") | |||
|
|||
CMAKE_ARGS+=($@) | |||
USE_ARM_COMPUTE=false |
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 remove this snippet, its not needed
set (ARM_COMPUTE_CORE_LIB "${CMAKE_CURRENT_BINARY_DIR}/libarm_compute_core.a") | ||
set (ARM_COMPUTE_LIBS ${ARM_COMPUTE_LIB} ${ARM_COMPUTE_CORE_LIB}) | ||
|
||
add_custom_command( |
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.
The custom command doesn't have DEPENDS
, so it won't rebuild the sources e.g. after a submodule update. Hopefully, ARM CL would just add CMakeLists, and we don't have to monkey-patch it.
cmake/Dependencies.cmake
Outdated
@@ -464,6 +501,14 @@ if (USE_METAL) | |||
endif() | |||
endif() | |||
|
|||
|
|||
if (USE_ARM_COMPUTE) |
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.
This should be above the code that imports arm compute library targets from Scons. The motivation is to check only if (USE_ARM_COMPUTE)
, so if we need to enable this backend on other platforms, we need to patch only one snippet.
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 do the following before merging:
- Remove
Caffe2_MOBILE_TEST_SRCS
, useCaffe2_CPU_TEST_SRCS
- Remove code that sets and uses
USE_ARM_COMPUTE
fromscripts/build_android.sh
- Replace
if (USE_ARM_COMPUTE AND ANDROID)
withif (USE_ARM_COMPUTE)
. Only the snippet that disables ARMCL on non-Android platforms should check the platform. - Rename
USE_ARM_COMPUTE
option to something less ambiguous. Current name may suggest that this option is required for all builds for ARM. - Check that is builds with ARM Compute Library for ARMv7 and ARM64, and with -DBUILD_TEST=ON as well.
I didn't look much at C++ code, assume @bwasti understands it.
namespace caffe2 { | ||
|
||
typedef half_float::half half; | ||
typedef half DataType; |
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.
Do you need to check if float16 is supported on device?
@jerryzh168 has updated the pull request. View: changes |
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 rename the PR to be a bit more informative?
@jerryzh168 has updated the pull request. View: changes |
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.
@jerryzh168 has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
No description provided.