Open kevinzhow opened 5 years ago
Actually, the neural network part is only a small part of Juman++. The code will probably compile and work on arm64, but I haven't tried.
I had compiled the codes on arm64 yesterday with iOS cmake toolchain https://github.com/leetal/ios-cmake.
First step is to fix the backword.hpp line 3470 for iPhoneSDK
#elif defined(__aarch64__)
error_addr = reinterpret_cast<void*>(uctx->uc_mcontext->__ss.__pc);
Fix the catch platform define logic of catch.hpp
line 59
# if TARGET_OS_OSX == 1
# define CATCH_PLATFORM_MAC
# elif TARGET_OS_IPHONE == 1
# define CATCH_PLATFORM_IPHONE
# endif
Next step, run the command
cmake .. -DCMAKE_TOOLCHAIN_FILE=/Users/zhoukaiwen/Downloads/ChromeDownloads/jumanpp-2.0.0-rc2/bld/toolchain/ios.cmake \
-DPLATFORM=OS64 \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/Users/zhoukaiwen/jumanpp
Outputs show as below which is fine.
-- Merging integrated CMake 3.14+ iOS,tvOS,watchOS,macOS toolchain(s) with this toolchain!
-- Building with Xcode version: 10.3
-- Configuring iphoneos build for platform: OS64, architecture(s): arm64
-- Using SDK: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS12.4.sdk for platform: OS64
-- Using the default min-version since DEPLOYMENT_TARGET not provided!
-- Enabling bitcode support by default. ENABLE_BITCODE not provided!
-- Enabling ARC support by default. ENABLE_ARC not provided!
-- Hiding symbols visibility by default. ENABLE_VISIBILITY not provided!
-- Using C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
-- Using CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++
-- Using libtool: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool
-- Using a data_ptr size of 8
-- Building for minimum iphoneos version: 9.0 (SDK version: 12.4)
-- Version flags set to: -miphoneos-version-min=9.0
-- Enabling bitcode support.
-- Enabling ARC support.
-- Hiding symbols (-fvisibility=hidden).
-- Merging integrated CMake 3.14+ iOS,tvOS,watchOS,macOS toolchain(s) with this toolchain!
-- Building with Xcode version: 10.3
-- Configuring iphoneos build for platform: OS64, architecture(s): arm64
-- Using SDK: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS12.4.sdk for platform: OS64 when checking compatibility
-- Using libtool: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool
-- Using a data_ptr size of 8
-- Building for minimum iphoneos version: 9.0 (SDK version: 12.4)
-- Version flags set to: -miphoneos-version-min=9.0
-- Enabling bitcode support.
-- Enabling ARC support.
-- Hiding symbols (-fvisibility=hidden).
-- The C compiler identification is AppleClang 10.0.1.10010046
-- The CXX compiler identification is AppleClang 10.0.1.10010046
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE
-- Could NOT find Protobuf (missing: Protobuf_LIBRARIES Protobuf_INCLUDE_DIR)
Not using Protobuf-based components
-- Eigen3... OK
Static feature generation:
COMMAND cgtest02_codegen_binary cgtest02 Test02 /Users/zhoukaiwen/Downloads/ChromeDownloads/jumanpp-2.0.0-rc2/bld/src/core/codegen/gen
DEPENDS cgtest02_codegen_binary cg_2_spec.h
OUTPUT /Users/zhoukaiwen/Downloads/ChromeDownloads/jumanpp-2.0.0-rc2/bld/src/core/codegen/gen/cgtest02.cc /Users/zhoukaiwen/Downloads/ChromeDownloads/jumanpp-2.0.0-rc2/bld/src/core/codegen/gen/cgtest02.h
LIBS jpp_core
Static feature generation:
COMMAND jpp_jumandic_cg_codegen_binary jpp_jumandic_cg JumandicStatic /Users/zhoukaiwen/Downloads/ChromeDownloads/jumanpp-2.0.0-rc2/bld/src/jumandic/gen
DEPENDS jpp_jumandic_cg_codegen_binary shared/jumandic_spec.cc
OUTPUT /Users/zhoukaiwen/Downloads/ChromeDownloads/jumanpp-2.0.0-rc2/bld/src/jumandic/gen/jpp_jumandic_cg.cc /Users/zhoukaiwen/Downloads/ChromeDownloads/jumanpp-2.0.0-rc2/bld/src/jumandic/gen/jpp_jumandic_cg.h
LIBS jpp_jumandic_spec
/Users/zhoukaiwen/Downloads/ChromeDownloads/jumanpp-2.0.0-rc2/bld/src/jumandic/gen
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/zhoukaiwen/Downloads/ChromeDownloads/jumanpp-2.0.0-rc2/bld
In the next make
step, we will have problems since the Static feature generation
runs on the local machine.
[ 66%] Building CXX object src/core/analysis/CMakeFiles/jpp_core_analysis_tests.dir/rnn_id_resolver_test.cc.o
[ 67%] Generating gen/cgtest02.cc, gen/cgtest02.h
/bin/sh: cgtest02_codegen_binary: command not found
make[2]: *** [src/core/codegen/gen/cgtest02.cc] Error 127
make[1]: *** [src/core/codegen/CMakeFiles/jpp_codegen_tests.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
To solve this, I compiled cgtest02_codegen_binary
and jpp_jumandic_cg_codegen_binary
for the x86_64
and run these two Static feature generation
COMMAND.
And finally I got bin
and libexec
in the jumanpp folder which contains jumanapp
jumandic.config
and jumandic.jppmdl
when the make install
finished.
But unluckily, the iOS can not exec binary, so I have to find a way to compile the files into static lib.
Change the PLATFORM to OS64COMBINED, and runs the command below.
cmake .. -G Xcode -DCMAKE_TOOLCHAIN_FILE=/Users/zhoukaiwen/Downloads/ChromeDownloads/jumanpp-2.0.0-rc2/bld/toolchain/ios.cmake \
-DPLATFORM=OS64COMBINED \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/Users/zhoukaiwen/jumanpp
It will generate a jumanpp.xcodeproj
project with all targets in it.
But I am being stuck at here because I don't have any experience with C++.
Ah, yes, static feature generation compiles a native binary (non cross-compiled). Need to fix that for cross-compilation at least (or compile natively on arm from the beginning).
Working on cross-compilation, however, is a out of scope for me, sorry.
I'm also not familiar with how the linking works on iOS and whether it is possible to consume C++ libraries from apps easily. The model itself is going to be pretty large (getting the size of your app into several hundreds of megs range) which can be a show-stopper to you as well.
We have an issue on making a C interface #61, but it is sort of in a backlog. Sorry for not being able to help.
A few hundred MB shouldn't be a big problem. Many games are far larger. Right now iOS itself is using mecab in the background when you highlight Japanese text I believe. Would love to get this working.
So we can easily migrate it to mobile device.