Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions cmake/onnxruntime_hosting.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ find_package(Boost 1.69 COMPONENTS system context thread program_options REQUIRE
set(re2_src ${REPO_ROOT}/cmake/external/re2)

# Setup source code
file(GLOB_RECURSE onnxruntime_hosting_lib_srcs
"${ONNXRUNTIME_ROOT}/hosting/http/*.cc"
set(onnxruntime_hosting_lib_srcs
"${ONNXRUNTIME_ROOT}/hosting/http/json_handling.cc"
"${ONNXRUNTIME_ROOT}/hosting/http/predict_request_handler.cc"
"${ONNXRUNTIME_ROOT}/hosting/http/util.cc"
"${ONNXRUNTIME_ROOT}/hosting/environment.cc"
"${ONNXRUNTIME_ROOT}/hosting/executor.cc"
"${ONNXRUNTIME_ROOT}/hosting/converter.cc"
Expand All @@ -42,10 +44,27 @@ if(NOT WIN32)
endif()
endif()

file(GLOB_RECURSE onnxruntime_hosting_http_core_lib_srcs
"${ONNXRUNTIME_ROOT}/hosting/http/core/*.cc"
)

file(GLOB_RECURSE onnxruntime_hosting_srcs
"${ONNXRUNTIME_ROOT}/hosting/main.cc"
)

# HTTP core library
add_library(onnxruntime_hosting_http_core_lib STATIC
${onnxruntime_hosting_http_core_lib_srcs})
target_include_directories(onnxruntime_hosting_http_core_lib
PUBLIC
${ONNXRUNTIME_ROOT}/hosting/http/core
${Boost_INCLUDE_DIR}
${re2_src}
)
target_link_libraries(onnxruntime_hosting_http_core_lib PRIVATE
${Boost_LIBRARIES}
)

# Hosting library
add_library(onnxruntime_hosting_lib ${onnxruntime_hosting_lib_srcs})
onnxruntime_add_include_to_target(onnxruntime_hosting_lib gsl onnx_proto hosting_proto)
Expand All @@ -62,6 +81,7 @@ target_include_directories(onnxruntime_hosting_lib PRIVATE
target_link_libraries(onnxruntime_hosting_lib PRIVATE
hosting_proto
${Boost_LIBRARIES}
onnxruntime_hosting_http_core_lib
onnxruntime_session
onnxruntime_optimizer
onnxruntime_providers
Expand Down Expand Up @@ -95,6 +115,7 @@ target_include_directories(${PROJECT_NAME} PRIVATE
)

target_link_libraries(${PROJECT_NAME} PRIVATE
onnxruntime_hosting_http_core_lib
onnxruntime_hosting_lib
)

2 changes: 1 addition & 1 deletion cmake/onnxruntime_unittests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ if (onnxruntime_BUILD_HOSTING)
add_library(onnxruntime_test_utils_for_hosting ${onnxruntime_test_hosting_src})
onnxruntime_add_include_to_target(onnxruntime_test_utils_for_hosting onnxruntime_test_utils gtest gmock gsl onnx onnx_proto hosting_proto)
add_dependencies(onnxruntime_test_utils_for_hosting onnxruntime_hosting ${onnxruntime_EXTERNAL_DEPENDENCIES})
target_include_directories(onnxruntime_test_utils_for_hosting PUBLIC ${Boost_INCLUDE_DIR} ${REPO_ROOT}/cmake/external/re2 ${CMAKE_CURRENT_BINARY_DIR}/onnx ${ONNXRUNTIME_ROOT}/hosting/http PRIVATE ${ONNXRUNTIME_ROOT} )
target_include_directories(onnxruntime_test_utils_for_hosting PUBLIC ${Boost_INCLUDE_DIR} ${REPO_ROOT}/cmake/external/re2 ${CMAKE_CURRENT_BINARY_DIR}/onnx ${ONNXRUNTIME_ROOT}/hosting/http ${ONNXRUNTIME_ROOT}/hosting/http/core PRIVATE ${ONNXRUNTIME_ROOT} )
target_link_libraries(onnxruntime_test_utils_for_hosting ${Boost_LIBRARIES} ${onnx_test_libs})

AddTest(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

#ifndef ONNXRUNTIME_HOSTING_HTTP_CONTEXT_H
#define ONNXRUNTIME_HOSTING_HTTP_CONTEXT_H
#ifndef ONNXRUNTIME_HOSTING_HTTP_CORE_CONTEXT_H
#define ONNXRUNTIME_HOSTING_HTTP_CORE_CONTEXT_H

// boost random is using a deprecated header in 1.69
// See: https://github.com/boostorg/random/issues/49
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

#ifndef ONNXRUNTIME_HOSTING_HTTP_BEAST_HTTP_H
#define ONNXRUNTIME_HOSTING_HTTP_BEAST_HTTP_H
#ifndef ONNXRUNTIME_HOSTING_HTTP_CORE_HTTP_SERVER_H
#define ONNXRUNTIME_HOSTING_HTTP_CORE_HTTP_SERVER_H

#include <functional>
#include <iostream>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

#ifndef ONNXRUNTIME_HOSTING_HTTP_LISTENER_H
#define ONNXRUNTIME_HOSTING_HTTP_LISTENER_H
#ifndef ONNXRUNTIME_HOSTING_HTTP_CORE_LISTENER_H
#define ONNXRUNTIME_HOSTING_HTTP_CORE_LISTENER_H

#include <memory>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

#ifndef ONNXRUNTIME_HOSTING_HTTP_ROUTES_H
#define ONNXRUNTIME_HOSTING_HTTP_ROUTES_H
#ifndef ONNXRUNTIME_HOSTING_HTTP_CORE_ROUTES_H
#define ONNXRUNTIME_HOSTING_HTTP_CORE_ROUTES_H

#include <boost/beast/http.hpp>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

#ifndef ONNXRUNTIME_HOSTING_HTTP_HTTP_SESSION_H
#define ONNXRUNTIME_HOSTING_HTTP_HTTP_SESSION_H
#ifndef ONNXRUNTIME_HOSTING_HTTP_CORE_HTTP_SESSION_H
#define ONNXRUNTIME_HOSTING_HTTP_CORE_HTTP_SESSION_H

#include <memory>
#include <boost/beast/version.hpp>
Expand Down
20 changes: 20 additions & 0 deletions onnxruntime/hosting/http/core/util.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

#include <iostream>

#include <boost/beast/core.hpp>

#include "context.h"
#include "util.h"

namespace onnxruntime {
namespace hosting {

// Report a failure
void ErrorHandling(beast::error_code ec, char const* what) {
std::cerr << what << " failed: " << ec.value() << " : " << ec.message() << "\n";
}

} // namespace hosting
} // namespace onnxruntime
23 changes: 23 additions & 0 deletions onnxruntime/hosting/http/core/util.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

#ifndef ONNXRUNTIME_HOSTING_HTTP_CORE_UTIL_H
#define ONNXRUNTIME_HOSTING_HTTP_CORE_UTIL_H

#include <boost/beast/core.hpp>
#include <boost/beast/http/status.hpp>

#include "context.h"

namespace onnxruntime {
namespace hosting {

namespace beast = boost::beast; // from <boost/beast.hpp>

// Report a failure
void ErrorHandling(beast::error_code ec, char const* what);

} // namespace hosting
} // namespace onnxruntime

#endif // ONNXRUNTIME_HOSTING_HTTP_UTIL_H
5 changes: 0 additions & 5 deletions onnxruntime/hosting/http/util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ static std::unordered_set<std::string> protobuf_mime_types{
"application/vnd.google.protobuf",
"application/x-protobuf"};

// Report a failure
void ErrorHandling(beast::error_code ec, char const* what) {
std::cerr << what << " failed: " << ec.value() << " : " << ec.message() << "\n";
}

boost::beast::http::status GetHttpStatusCode(const protobufutil::Status& status) {
switch (status.error_code()) {
case protobufutil::error::Code::OK:
Expand Down
5 changes: 1 addition & 4 deletions onnxruntime/hosting/http/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <boost/beast/http/status.hpp>
#include <google/protobuf/stubs/status.h>

#include "context.h"
#include "hosting/http/core/context.h"

namespace onnxruntime {
namespace hosting {
Expand All @@ -21,9 +21,6 @@ enum class SupportedContentType : int {
PbByteArray
};

// Report a failure
void ErrorHandling(beast::error_code ec, char const* what);

// Mapping protobuf status to http status
boost::beast::http::status GetHttpStatusCode(const google::protobuf::util::Status& status);

Expand Down
2 changes: 1 addition & 1 deletion onnxruntime/test/hosting/http_routes_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <iostream>

#include "gtest/gtest.h"
#include "hosting/http/routes.h"
#include "hosting/http/core/routes.h"

namespace onnxruntime {
namespace hosting {
Expand Down
4 changes: 2 additions & 2 deletions onnxruntime/test/hosting/util_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

#include <google/protobuf/stubs/status.h>
#include "gtest/gtest.h"
#include "context.h"
#include "util.h"
#include "hosting/http/core/context.h"
#include "hosting/http/util.h"

namespace onnxruntime {
namespace hosting {
Expand Down