Skip to content

Commit

Permalink
java: Support modelbox flow JNI API.
Browse files Browse the repository at this point in the history
  • Loading branch information
pymumu authored and tau233 committed Sep 7, 2022
1 parent 90ad2ea commit 2ea85d6
Show file tree
Hide file tree
Showing 95 changed files with 7,007 additions and 352 deletions.
2 changes: 1 addition & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,5 @@ Checks: >
# clang-analyzer-optin.cplusplus.VirtualCall,

# Turn all the warnings from the checks above into errors.
HeaderFilterRegex: '(src|test/unit|test/drivers|test/mock)/*'
HeaderFilterRegex: '((?!build/)src|test/unit|test/drivers|test/function|test/mock)/*'
FormatStyle: file
24 changes: 22 additions & 2 deletions .github/workflows/merge-request-ascend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ on:
branches:
- main

concurrency:
group: ${{ github.head_ref && github.workflow}}
cancel-in-progress: true

env:
BUILD_TYPE: Release

Expand All @@ -17,16 +21,32 @@ jobs:
steps:
- uses: actions/checkout@v3
- run: apt update
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 11
maven-version: '3.6.2'
cache: 'maven'
- name: Set up Maven
uses: stCarolas/setup-maven@v4.4
with:
maven-version: 3.8.2
- uses: actions/cache@v1
with:
path: /root/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('src/java/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: ccache
uses: hendrikmuhs/ccache-action@v1.2
with:
key: ubuntu-latest
max-size: 1024M
max-size: 512M
- name: Configure CMake
run: |
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DWITH_WEBUI=off -DCLANG_TIDY=on -DCLANG_TIDY_AS_ERROR=on
cmake .. -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DWITH_WEBUI=off -DCLANG_TIDY=on -DCLANG_TIDY_AS_ERROR=on -DWITH_JAVA=on
- name: Build
working-directory: build
Expand Down
26 changes: 23 additions & 3 deletions .github/workflows/merge-request-cuda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ on:
branches:
- main

concurrency:
group: ${{ github.head_ref && github.workflow}}
cancel-in-progress: true

env:
BUILD_TYPE: Release

Expand All @@ -16,17 +20,33 @@ jobs:

steps:
- uses: actions/checkout@v3
- run: apt update
- run: apt update
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 11
maven-version: '3.6.2'
cache: 'maven'
- name: Set up Maven
uses: stCarolas/setup-maven@v4.4
with:
maven-version: 3.8.2
- uses: actions/cache@v1
with:
path: /root/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('src/java/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: ccache
uses: hendrikmuhs/ccache-action@v1.2
with:
key: ubuntu-latest
max-size: 1024M
max-size: 512M
- name: Configure CMake
run: |
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DWITH_WEBUI=off -DCLANG_TIDY=on -DCLANG_TIDY_AS_ERROR=on
cmake .. -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DWITH_WEBUI=off -DCLANG_TIDY=on -DCLANG_TIDY_AS_ERROR=on -DWITH_JAVA=on
- name: Build
working-directory: build
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ ModelBox是一个适用于端边云场景的AI推理应用开发框架,提供
## ModelBox特点

1. **易于开发**
AI推理业务可视化编排开发,功能模块化,丰富组件库;c++,python多语言支持
AI推理业务可视化编排开发,功能模块化,丰富组件库;c++,python, Java多语言支持

1. **易于集成**
集成云上对接的组件,云上对接更容易。
Expand Down
2 changes: 1 addition & 1 deletion README_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ModelBox is an AI application development framework featuring device-edge-cloud
## ModelBox Highlights

1. **Easy to develop**
Simplified orchestration and development of inference applications via a graphical interface, modularized functions, rich component libraries, and multi-language support (C++, Python).
Simplified orchestration and development of inference applications via a graphical interface, modularized functions, rich component libraries, and multi-language support (C++, Python, Java).

1. **Easy to integrate**
Easy to integrate different components on the cloud.
Expand Down
2 changes: 1 addition & 1 deletion src/demo/hello_world/flowunit/hello_world/hello_world.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def process(self, data_context):
out_data = data_context.output("out_data")

for buffer in in_data:
request_body = json.loads(buffer.as_object().strip(chr(0)))
request_body = json.loads(str(buffer))
msg = request_body.get("msg")
msg = msg.title()
msg = addTimestamp(msg)
Expand Down
4 changes: 1 addition & 3 deletions src/drivers/virtual/inference/virtualdriver_inference.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ class VirtualInferenceFlowUnitDesc : public modelbox::FlowUnitDesc {
std::shared_ptr<modelbox::Configuration> config_;
};

class InferenceVirtualDriver
: public modelbox::VirtualDriver,
public std::enable_shared_from_this<InferenceVirtualDriver> {
class InferenceVirtualDriver : public modelbox::VirtualDriver {
public:
InferenceVirtualDriver() = default;
~InferenceVirtualDriver() override = default;
Expand Down
4 changes: 1 addition & 3 deletions src/drivers/virtual/java/virtualdriver_java.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ class VirtualJavaFlowUnitDesc : public modelbox::FlowUnitDesc {
std::string jar_file_path_;
};

class JavaVirtualDriver
: public modelbox::VirtualDriver,
public std::enable_shared_from_this<JavaVirtualDriver> {
class JavaVirtualDriver : public modelbox::VirtualDriver {
public:
JavaVirtualDriver() = default;
~JavaVirtualDriver() override = default;
Expand Down
4 changes: 1 addition & 3 deletions src/drivers/virtual/python/virtualdriver_python.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ class VirtualPythonFlowUnitDesc : public modelbox::FlowUnitDesc {
std::string python_file_path_;
};

class PythonVirtualDriver
: public modelbox::VirtualDriver,
public std::enable_shared_from_this<PythonVirtualDriver> {
class PythonVirtualDriver : public modelbox::VirtualDriver {
public:
PythonVirtualDriver() = default;
~PythonVirtualDriver() override = default;
Expand Down
4 changes: 1 addition & 3 deletions src/drivers/virtual/yolobox/virtualdriver_yolobox.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ class YoloBoxVirtualFlowUnitDesc : public modelbox::FlowUnitDesc {
std::shared_ptr<modelbox::Configuration> config_;
};

class YoloBoxVirtualDriver
: public modelbox::VirtualDriver,
public std::enable_shared_from_this<YoloBoxVirtualDriver> {
class YoloBoxVirtualDriver : public modelbox::VirtualDriver {
public:
YoloBoxVirtualDriver() = default;
~YoloBoxVirtualDriver() override = default;
Expand Down
21 changes: 19 additions & 2 deletions src/java/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,32 @@ endif()
set(TEST_CONFIG_JSON_FILE ${CMAKE_CURRENT_BINARY_DIR}/src/test/java/com/modelbox/TestConfig.json)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/test/java/com/modelbox/TestConfig.json.in ${TEST_CONFIG_JSON_FILE})
set(MODELBOX_JNI_HEADER_DIR ${CMAKE_CURRENT_BINARY_DIR} CACHE INTERNAL "")
set(JAVA_NATIVE_SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/src/main/java/com/modelbox)

file(MAKE_DIRECTORY ${MODELBOX_JNI_HEADER_DIR})

add_subdirectory(jni)

ADD_CUSTOM_TARGET(modelbox-java-jni-header
DEPENDS ${MODELBOX_JNI_HEADER_DIR}/*.h
)

add_custom_command(OUTPUT ${MODELBOX_JNI_HEADER_DIR}/*.h
COMMAND javac -h ${MODELBOX_JNI_HEADER_DIR} ${JAVA_NATIVE_SOURCE}/* -cp ${CMAKE_CURRENT_BINARY_DIR}/*.jar -d ${MODELBOX_JNI_HEADER_DIR}
DEPENDS ${JAVA_NATIVE_SOURCE}
)
set_source_files_properties(${MODELBOX_JNI_HEADER_DIR} PROPERTIES
GENERATED TRUE
)

add_dependencies(modelbox-java-jni-header modelbox-java)

add_custom_target(
modelbox-java
COMMAND mvn package -DskipTests -DbuildDirectory=${CMAKE_CURRENT_BINARY_DIR}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)


add_custom_target(
unittest-java
${CMAKE_COMMAND} -E env "TEST_CONFIG_JSON_FILE=${TEST_CONFIG_JSON_FILE}"
Expand All @@ -74,4 +90,5 @@ install(CODE
)

add_dependencies(unittest-java modelbox-java)
add_dependencies(unittest-java modelbox-jni)
add_dependencies(unittest-java modelbox-jni)
add_dependencies(unittest-java all-drivers)
15 changes: 9 additions & 6 deletions src/java/jni/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,24 @@ include_directories(${LIBMODELBOX_INCLUDE})
include_directories(${LIBMODELBOX_BASE_INCLUDE})
include_directories(${CMAKE_CURRENT_LIST_DIR}/include)
include_directories(${JNI_INCLUDE_DIRS})
include_directories(${CMAKE_CURRENT_LIST_DIR})
include_directories(${MODELBOX_JNI_HEADER_DIR})
include_directories(${HUAWEI_SECURE_C_INCLUDE_DIR})

set(MODELBOX_JNI "modelbox-jni")
file(GLOB_RECURSE LIBMODELBOX_JAVA_JNI_SOURCES *.cpp *.cc *.c)
add_library(modelbox-jni SHARED ${LIBMODELBOX_JAVA_JNI_SOURCES})

add_dependencies(modelbox-jni modelbox-java)
add_library(${MODELBOX_JNI} SHARED ${LIBMODELBOX_JAVA_JNI_SOURCES})
target_compile_options(${MODELBOX_JNI} PUBLIC -fvisibility=hidden)
add_dependencies(${MODELBOX_JNI} modelbox-java-jni-header)

set(MODELBOX_JNI "modelbox-jni")
target_link_libraries(${MODELBOX_JNI} ${LIBMODELBOX_SHARED})
set(JNI_LIBRARY_DIR ${CMAKE_CURRENT_BINARY_DIR} CACHE INTERNAL "")
set(JNI_PACKAGE_INSTALLDIR "/usr/java/packages/lib")

install(TARGETS modelbox-jni
install(TARGETS ${MODELBOX_JNI}
COMPONENT cpu-device-flowunit
RUNTIME DESTINATION ${CMAKE_INSTALL_FULL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}
LIBRARY DESTINATION ${JNI_PACKAGE_INSTALLDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}
OPTIONAL
)
Expand Down
Loading

0 comments on commit 2ea85d6

Please sign in to comment.