Skip to content

Commit

Permalink
fix merged conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
xadupre committed Jun 7, 2024
2 parents 2605674 + 04029e1 commit 3b79239
Show file tree
Hide file tree
Showing 20 changed files with 577 additions and 103 deletions.
11 changes: 10 additions & 1 deletion .pipelines/java_packaging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,19 @@ stages:
jar cmf0 META-INF/MANIFEST.MF onnxruntime-extensions-$(OrtExtVersion).jar *
displayName: Combine and pack JAR with Windows, Linux and MacOS Binaries
- script: |
cd $(Build.ArtifactStagingDirectory)
mkdir drop
cp onnxruntime-extensions-$(OrtExtVersion).jar drop/onnxruntime-extensions-$(OrtExtVersion).jar
cp onnxruntime-extensions-$(OrtExtVersion)-javadoc.jar drop/onnxruntime-extensions-$(OrtExtVersion)-javadoc.jar
cp onnxruntime-extensions-$(OrtExtVersion)-sources.jar drop/onnxruntime-extensions-$(OrtExtVersion)-sources.jar
cp META-INF/maven/com.microsoft.onnxruntime/onnxruntime-extensions/pom.xml drop/onnxruntime-extensions-$(OrtExtVersion).pom
displayName: Move files to a drop folder for publishing
- task: PublishPipelineArtifact@1
displayName: 'Publish MacOS Artifact'
inputs:
targetPath: '$(Build.ArtifactStagingDirectory)'
targetPath: '$(Build.ArtifactStagingDirectory)/drop'
artifact: 'drop-onnxruntime-extensions-java-cpu'

- template: templates/component-governance-component-detection-steps.yml
Expand Down
9 changes: 4 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,11 @@ function(set_msvc_c_cpp_compiler_warning_level warning_level)
endif()
endfunction()

if (NOT ONNXRUNTIME_INCLUDE_DIR)
include(ext_ortlib)
endif()
# set default MSVC warning level to 3 for external dependencies
set_msvc_c_cpp_compiler_warning_level(3)
include(ext_ortlib)
include(gsl)

macro(standardize_output_folder bin_target)
Expand Down Expand Up @@ -681,7 +683,6 @@ endif()

if(OCOS_ENABLE_GPT2_TOKENIZER OR OCOS_ENABLE_WORDPIECE_TOKENIZER)
target_include_directories(ocos_operators PUBLIC ${nlohmann_json_SOURCE_DIR}/single_include)
list(APPEND ocos_libraries nlohmann_json::nlohmann_json)
endif()

# If building a shared library we can't throw an internal exception type across the library boundary as the type
Expand All @@ -695,8 +696,6 @@ if(ANDROID)
list(APPEND ocos_libraries log)
endif()

list(APPEND ocos_libraries Microsoft.GSL::GSL)

list(REMOVE_DUPLICATES OCOS_COMPILE_DEFINITIONS)
target_compile_definitions(noexcep_operators PRIVATE ${OCOS_COMPILE_DEFINITIONS})
if(NOT OCOS_ENABLE_CPP_EXCEPTIONS)
Expand Down Expand Up @@ -899,7 +898,7 @@ if (_ORTX_STANDALONE_PROJECT)
# Run CPack to generate the NuGet package
include(CPack)

if(OCOS_ENABLE_CTEST)
if(OCOS_ENABLE_CTEST AND NOT MAC_CATALYST)
include(ext_tests)
endif()
endif()
22 changes: 18 additions & 4 deletions base/file_sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,20 @@ namespace ort_extensions {
class path {
public:
path() = default;
path(const std::string& path) : path_(path){};
path(const std::string& path) : path_(path) {
#ifdef _WIN32
w_path_ = to_wstring();
#endif // _WIN32
};

#ifdef _WIN32
path(const std::wstring& wpath) {
int size_needed = WideCharToMultiByte(CP_UTF8, 0, wpath.c_str(), -1, nullptr, 0, nullptr, nullptr);
std::string utf8_str(size_needed, 0);
WideCharToMultiByte(CP_UTF8, 0, wpath.c_str(), -1, &utf8_str[0], size_needed, nullptr, nullptr);
path_ = utf8_str;
}
#endif // _WIN32

static constexpr char separator =
#ifdef _WIN32
Expand All @@ -30,7 +43,7 @@ class path {
std::ifstream open(ios_base::openmode mode = ios_base::in) const {
// if Windows, need to convert the string to UTF-16
#ifdef _WIN32
return std::ifstream(to_wstring(), mode);
return std::ifstream(w_path_, mode);
#else
return std::ifstream(path_, mode);
#endif // _WIN32
Expand All @@ -55,7 +68,7 @@ class path {
bool is_directory() const {
#ifdef _WIN32
struct _stat64 info;
if (_wstat64(to_wstring().c_str(), &info) != 0) {
if (_wstat64(w_path_.c_str(), &info) != 0) {
return false;
}
#else
Expand All @@ -69,8 +82,9 @@ class path {

private:
std::string path_;

#ifdef _WIN32
std::wstring w_path_;

std::wstring to_wstring() const {
int size_needed = MultiByteToWideChar(CP_UTF8, 0, path_.c_str(), -1, nullptr, 0);
std::wstring utf16_str(size_needed, 0);
Expand Down
66 changes: 40 additions & 26 deletions cmake/ext_tests.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
if (NOT MAC_CATALYST)

if (OCOS_ENABLE_SELECTED_OPLIST)
# currently the tests don't handle operator exclusion cleanly.
message(FATAL_ERROR "Due to usage of OCOS_ENABLE_SELECTED_OPLIST excluding operators the tests are unable to be built and run")
Expand Down Expand Up @@ -55,7 +53,7 @@ function(add_test_target)
"${TEST_SRC_DIR}/unittest_main/test_main.cc")
target_link_libraries(${ARG_TARGET} PRIVATE
${ARG_LIBRARIES}
gtest gmock)
gtest)

if(OCOS_USE_CUDA)
target_link_directories(${ARG_TARGET} PRIVATE ${CUDAToolkit_LIBRARY_DIR})
Expand Down Expand Up @@ -93,7 +91,7 @@ function(add_test_target)

target_link_libraries(${ARG_TARGET} PRIVATE
${ARG_LIBRARIES}
gtest gmock)
gtest)

set(test_data_destination_root_directory $<TARGET_FILE_DIR:${dummy_testee_target}>)

Expand Down Expand Up @@ -130,9 +128,40 @@ add_test_target(TARGET ocos_test
LIBRARIES ortcustomops ${ocos_libraries})
target_compile_definitions(ocos_test PRIVATE ${OCOS_COMPILE_DEFINITIONS})

if (OCOS_ENABLE_C_API)
file(GLOB pp_api_TEST_SRC
"${TEST_SRC_DIR}/pp_api_test/*.c"
"${TEST_SRC_DIR}/pp_api_test/*.cc"
"${TEST_SRC_DIR}/pp_api_test/*.h")

add_test_target(TARGET pp_api_test
TEST_SOURCES ${pp_api_TEST_SRC}
LIBRARIES onnxruntime_extensions ${ocos_libraries}
TEST_DATA_DIRECTORIES ${TEST_SRC_DIR}/data)

target_compile_definitions(pp_api_test PRIVATE ${OCOS_COMPILE_DEFINITIONS})
target_include_directories(pp_api_test PRIVATE
${PROJECT_SOURCE_DIR}/
"$<TARGET_PROPERTY:ortcustomops,INTERFACE_INCLUDE_DIRECTORIES>"
"$<TARGET_PROPERTY:ocos_operators,INTERFACE_INCLUDE_DIRECTORIES>")

if (ORTX_TEST_DATA2)
file(TO_NATIVE_PATH "${ORTX_TEST_DATA2}/tests/data2" _TEST_DATA2)
add_custom_command(TARGET pp_api_test POST_BUILD
COMMAND ${CMAKE_COMMAND} -E create_symlink ${_TEST_DATA2} ${onnxruntime_extensions_BINARY_DIR}/data2)
endif()
endif()


# -- shared test (needs onnxruntime) --
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH)
find_library(ONNXRUNTIME onnxruntime HINTS "${ONNXRUNTIME_LIB_DIR}")
# avoid blindling searching for onnxruntime library
# wbhich leads to a unpredictable result
if (NOT ONNXRUNTIME_LIB_DIR)
set(ONNXRUNTIME "ONNXRUNTIME-NOTFOUND")
else()
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH)
find_library(ONNXRUNTIME onnxruntime HINTS "${ONNXRUNTIME_LIB_DIR}")
endif()

if("${ONNXRUNTIME}" STREQUAL "ONNXRUNTIME-NOTFOUND")
message(WARNING "The prebuilt onnxruntime library was not found, extensions_test will be skipped.")
Expand Down Expand Up @@ -197,25 +226,10 @@ else()
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${ONNXRUNTIME} ${CMAKE_BINARY_DIR}/lib
)
endif()
endblock()

if (OCOS_ENABLE_C_API)
file(GLOB pp_api_TEST_SRC
"${TEST_SRC_DIR}/pp_api_test/*.c"
"${TEST_SRC_DIR}/pp_api_test/*.cc"
"${TEST_SRC_DIR}/pp_api_test/*.h")

add_test_target(TARGET pp_api_test
TEST_SOURCES ${pp_api_TEST_SRC}
LIBRARIES onnxruntime_extensions ${ocos_libraries}
TEST_DATA_DIRECTORIES ${TEST_SRC_DIR}/data)

target_compile_definitions(pp_api_test PRIVATE ${OCOS_COMPILE_DEFINITIONS})
target_include_directories(pp_api_test PRIVATE
${PROJECT_SOURCE_DIR}/
"$<TARGET_PROPERTY:ortcustomops,INTERFACE_INCLUDE_DIRECTORIES>"
"$<TARGET_PROPERTY:ocos_operators,INTERFACE_INCLUDE_DIRECTORIES>")
endif()
endif()

if (OCOS_ENABLE_C_API)
# avoid copying the same data directory at the same time.
add_dependencies(extensions_test pp_api_test)
endif()
endblock()
endif()
4 changes: 2 additions & 2 deletions cmake/externals/googletest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ FetchContent_Declare(
URL_HASH SHA1=06096d3900c356e468ba060a609642c635131106
)

set(BUILD_GMOCK OFF CACHE BOOL "" FORCE)
set(INSTALL_GTEST OFF CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
set_target_properties(gmock PROPERTIES FOLDER "externals/gtest")
set_target_properties(gmock_main PROPERTIES FOLDER "externals/gtest")
set_target_properties(gtest PROPERTIES FOLDER "externals/gtest")
set_target_properties(gtest_main PROPERTIES FOLDER "externals/gtest")
12 changes: 10 additions & 2 deletions cmake/externals/gsl.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,13 @@ else()
)
endif()

FetchContent_MakeAvailable(GSL)
get_target_property(GSL_INCLUDE_DIR Microsoft.GSL::GSL INTERFACE_INCLUDE_DIRECTORIES)
FetchContent_GetProperties(GSL)
string(TOLOWER "GSL" lcName)
if(NOT ${lcName}_POPULATED)
FetchContent_Populate(GSL)
# add_subdirectory(${GSL_SOURCE_DIR} ${GSL_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()

set(GSL_INCLUDE_DIR ${gsl_SOURCE_DIR}/include)

#get_target_property(GSL_INCLUDE_DIR Microsoft.GSL::GSL INTERFACE_INCLUDE_DIRECTORIES)
1 change: 0 additions & 1 deletion cmake/externals/json.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ set(JSON_BuildTests OFF CACHE INTERNAL "")
FetchContent_GetProperties(nlohmann_json)
if(NOT nlohmann_json_POPULATED)
FetchContent_Populate(nlohmann_json)
add_subdirectory(${nlohmann_json_SOURCE_DIR} ${nlohmann_json_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()
20 changes: 10 additions & 10 deletions cmake/externals/opencv.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,16 @@ set(BUILD_TESTS OFF CACHE INTERNAL "")
set(CV_TRACE OFF CACHE INTERNAL "")

set(CV_DISABLE_OPTIMIZATION ON CACHE INTERNAL "")
set(BUILD_PERF_TESTS OFF CACHE INTERNAL "")
set(BUILD_opencv_java_bindings_generator OFF CACHE INTERNAL "")
set(BUILD_opencv_js_bindings_generator OFF CACHE INTERNAL "")
set(BUILD_opencv_objc_bindings_generator OFF CACHE INTERNAL "")
set(BUILD_opencv_python_bindings_generator OFF CACHE INTERNAL "")
set(BUILD_opencv_python_tests OFF CACHE INTERNAL "")

set(WITH_ADE OFF CACHE INTERNAL "")
set(VIDEOIO_ENABLE_PLUGINS OFF CACHE INTERNAL "")
set(HIGHGUI_ENABLE_PLUGINS OFF CACHE INTERNAL "")

if(IOS)
# copy what OpenCV's platforms/ios/build_framework.py does and set CPU_BASELINE=DETECT
Expand Down Expand Up @@ -157,13 +167,3 @@ endif()

# unset it to avoid affecting other projects.
unset(EXECUTABLE_OUTPUT_PATH CACHE)

if (CMAKE_SYSTEM_NAME MATCHES "Windows")
set(opencv_projs gen_opencv_java_source gen_opencv_js_source gen_opencv_python_source)
list(APPEND opencv_projs gen_opencv_objc_source gen_opencv_objc_source_ios gen_opencv_objc_source_osx)
list(APPEND opencv_projs opencv_highgui_plugins opencv_videoio_plugins)
foreach(p ${opencv_projs})
set_target_properties(${p} PROPERTIES FOLDER "externals/opencv")
set_target_properties(${p} PROPERTIES EXCLUDE_FROM_ALL TRUE EXCLUDE_FROM_DEFAULT_BUILD TRUE)
endforeach()
endif()
46 changes: 46 additions & 0 deletions operators/cuda/add_mul.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

#pragma once
#include "ocos.h"
#include "add_mul_impl.cuh"
#include "ortx_common.h"

namespace contrib {

template <typename T, bool addition>
struct AddOrMulSharedInput {
template <typename TDict>
OrtxStatus OnModelAttach(const TDict& /*dict*/) {
return {};
}
OrtxStatus Compute(Ort::Custom::CUDAKernelContext* ctx,
const ortc::Tensor<T>& tensor_a,
const ortc::Tensor<T>& tensor_b,
const ortc::Tensor<T>& tensor_c,
ortc::Tensor<T>& output_ab,
ortc::Tensor<T>& output_ac) const {
const T* input_data_a = tensor_a.Data();
const T* input_data_b = tensor_b.Data();
const T* input_data_c = tensor_c.Data();

auto length_a = tensor_a.NumberOfElement();
auto length_b = tensor_b.NumberOfElement();
auto length_c = tensor_c.NumberOfElement();

T* output_data_ab = output_ab.Allocate(length_a <= length_b ? tensor_b.Shape() : tensor_a.Shape());
T* output_data_ac = output_ab.Allocate(length_a <= length_c ? tensor_c.Shape() : tensor_a.Shape());

if (0 == input_data_a || 0 == input_data_b || 0 == input_data_c) {
return {};
}
LaunchAddOrMulSharedInputKernel<T>(reinterpret_cast<cudaStream_t>(ctx->GetCudaStream()),
input_data_a, input_data_b, input_data_c,
output_data_ab, output_data_ac,
length_a, length_b, length_c,
addition);
return {};
}
};

} // namespace contrib
Loading

0 comments on commit 3b79239

Please sign in to comment.