Skip to content

Commit 7d5b2f2

Browse files
committed
vulkan solution 2
1 parent 08c07fa commit 7d5b2f2

File tree

6 files changed

+20
-11
lines changed

6 files changed

+20
-11
lines changed

CMakeLists.txt

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,15 @@ endif()
577577

578578
add_library(executorch_core ${_executorch_core__srcs})
579579

580+
add_library(executorch_headers INTERFACE)
581+
582+
target_include_directories(executorch_headers INTERFACE
583+
${_common_include_directories}
584+
)
585+
target_compile_definitions(executorch_headers INTERFACE C10_USING_CUSTOM_GENERATED_MACROS)
586+
587+
add_library(executorch_jni SHARED extension/android/empty.cpp)
588+
580589
# Legacy name alias.
581590
add_library(executorch_no_prim_ops ALIAS executorch_core)
582591

@@ -631,12 +640,15 @@ endif()
631640
# Does not contain portable kernels or other full operators. Does not contain
632641
# any backends.
633642
#
634-
add_library(executorch ${_executorch__srcs})
635-
target_link_libraries(executorch PUBLIC executorch_core)
643+
add_library(executorch SHARED ${_executorch__srcs})
644+
target_link_libraries(executorch PRIVATE executorch_core)
636645
target_include_directories(executorch PUBLIC ${_common_include_directories})
637646
target_compile_definitions(executorch PUBLIC C10_USING_CUSTOM_GENERATED_MACROS)
638647
target_compile_options(executorch PUBLIC ${_common_compile_options})
639-
target_link_options_shared_lib(executorch)
648+
# target_link_options_shared_lib(executorch)
649+
target_link_options(executorch PRIVATE "-Wl,-soname,libexecutorch_jni.so")
650+
set_target_properties(executorch PROPERTIES NO_SONAME TRUE)
651+
target_link_options_shared_lib(executorch_core)
640652

641653
#
642654
# portable_ops_lib: A library to register core ATen ops using portable kernels,

backends/vulkan/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ file(GLOB vulkan_backend_cpp ${RUNTIME_PATH}/*.cpp)
109109
list(APPEND vulkan_backend_cpp ${vulkan_graph_cpp})
110110
list(APPEND vulkan_backend_cpp ${vulkan_standard_shaders_cpp})
111111

112-
add_library(vulkan_backend STATIC ${vulkan_backend_cpp})
112+
add_library(vulkan_backend SHARED ${vulkan_backend_cpp})
113113
target_include_directories(
114114
vulkan_backend PRIVATE ${SCHEMA_INCLUDE_DIR} ${COMMON_INCLUDES}
115115
)
@@ -119,7 +119,6 @@ target_compile_options(vulkan_backend PRIVATE ${VULKAN_CXX_FLAGS})
119119
target_link_options_shared_lib(vulkan_backend)
120120

121121
set_property(TARGET vulkan_backend PROPERTY CXX_STANDARD 17)
122-
123122
# Executor Runner
124123

125124
if(NOT CMAKE_TOOLCHAIN_FILE MATCHES ".*(iOS|ios\.toolchain)\.cmake$")

extension/android/CMakeLists.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,6 @@ if(TARGET xnnpack_backend)
105105
list(APPEND link_libraries xnnpack_backend XNNPACK pthreadpool cpuinfo microkernels-prod)
106106
endif()
107107

108-
if(TARGET vulkan_backend)
109-
target_link_options_shared_lib(vulkan_backend)
110-
list(APPEND link_libraries vulkan_backend)
111-
endif()
112-
113108
if(EXECUTORCH_BUILD_KERNELS_CUSTOM)
114109
list(APPEND link_libraries $<LINK_LIBRARY:WHOLE_ARCHIVE,custom_ops>)
115110
endif()

extension/android/executorch_android/src/androidTest/java/org/pytorch/executorch/ModuleInstrumentationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
/** Unit tests for {@link Module}. */
3939
@RunWith(AndroidJUnit4.class)
4040
public class ModuleInstrumentationTest {
41-
private static String TEST_FILE_NAME = "/add.pte";
41+
private static String TEST_FILE_NAME = "/vk_add.pte";
4242
private static String MISSING_FILE_NAME = "/missing.pte";
4343
private static String NON_PTE_FILE_NAME = "/test.txt";
4444
private static String FORWARD_METHOD = "forward";

extension/android/executorch_android/src/main/java/org/pytorch/executorch/NativePeer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class NativePeer {
2323
static {
2424
// Loads libexecutorch.so from jniLibs
2525
NativeLoader.loadLibrary("executorch");
26+
NativeLoader.loadLibrary("vulkan_backend");
2627
}
2728

2829
private final HybridData mHybridData;

scripts/build_android_library.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ build_android_native_library() {
3838
-DCMAKE_TOOLCHAIN_FILE="${ANDROID_NDK}/build/cmake/android.toolchain.cmake" \
3939
-DANDROID_ABI="${ANDROID_ABI}" \
4040
-DANDROID_PLATFORM=android-26 \
41+
-DANDROID_ALLOW_UNDEFINED_SYMBOLS=OFF \
4142
-DBUILD_TESTING=OFF \
4243
-DEXECUTORCH_ENABLE_LOGGING=ON \
4344
-DEXECUTORCH_LOG_LEVEL=Info \
@@ -86,6 +87,7 @@ build_android_native_library() {
8687
local SO_STAGE_DIR="cmake-out-android-so/${ANDROID_ABI}"
8788
mkdir -p ${SO_STAGE_DIR}
8889
cp "${CMAKE_OUT}"/extension/android/*.so "${SO_STAGE_DIR}/libexecutorch.so"
90+
cp "${CMAKE_OUT}"/lib/libvulkan_backend.so "${SO_STAGE_DIR}/" || true
8991

9092
# Copy QNN related so library
9193
if [ -n "$QNN_SDK_ROOT" ] && [ "$ANDROID_ABI" == "arm64-v8a" ]; then

0 commit comments

Comments
 (0)