Skip to content

Python Backend Windows Support #294

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 29 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
3606f3d
Initial checkin - reducing errors
fpetrini15 Sep 11, 2023
c10352e
Removing/Rearranging Header files - error reduction
fpetrini15 Sep 11, 2023
d73bd1d
Error reduction: aligned --> aligas, cmake option edit, intermediate …
fpetrini15 Sep 12, 2023
34f0857
Error reduction: abstracting environment deployments, change enum, la…
fpetrini15 Sep 13, 2023
65d843d
Preventing any more Macro collisions
fpetrini15 Sep 13, 2023
87bd844
Merge remote-tracking branch 'origin/main' into fpetrini-py-to-win
fpetrini15 Sep 13, 2023
7312323
Error reduction: get win32 parent pid to stub, terminate functions in…
fpetrini15 Sep 13, 2023
e4b8f8e
Error Reduction: Change from off_t to handle_t
fpetrini15 Sep 13, 2023
5cbee15
Add win32-equivalent dlfcn functions, py_be function type tweaks, con…
fpetrini15 Sep 15, 2023
734743e
HMODULE fixes, new method fixes
fpetrini15 Sep 15, 2023
2c02a0f
Minor fixes
fpetrini15 Sep 16, 2023
c88e16e
CMakeLists tweaks for WIN32
fpetrini15 Sep 18, 2023
3ebe7bd
Nit fix
fpetrini15 Sep 18, 2023
e718ecc
Typo fix for Linux build
fpetrini15 Sep 20, 2023
e77cdee
Formatting
fpetrini15 Sep 20, 2023
22a9bab
Merge remote-tracking branch 'origin/main' into fpetrini-py-to-win
fpetrini15 Sep 20, 2023
72e9a29
Merge remote-tracking branch 'origin/main' into fpetrini-py-to-win
fpetrini15 Dec 26, 2023
6a52be7
Merge cleanup and file separator simplification
fpetrini15 Jan 4, 2024
386afa8
nvtx_ fix
fpetrini15 Jan 4, 2024
19d77cf
Export API functions
fpetrini15 Jan 5, 2024
08a6e99
Successful inference checkpoint
fpetrini15 Jan 9, 2024
c60f41b
Merge remote-tracking branch 'origin/main' into fpetrini-py-to-win
fpetrini15 Jan 9, 2024
333ba38
Merge remote-tracking branch 'origin/main' into fpetrini-py-to-win
fpetrini15 Jan 22, 2024
b627e34
Use std::filesystem
fpetrini15 Jan 23, 2024
ed31e5c
Fix logic error
fpetrini15 Jan 24, 2024
9e45dbe
Force GPU off
fpetrini15 Jan 25, 2024
e3ef419
Add Jira comments and provide basic error handling
fpetrini15 Feb 1, 2024
80a5a9c
Merge remote-tracking branch 'origin' into fpetrini-py-to-win
fpetrini15 Feb 2, 2024
6d09d28
Remove debug statements
fpetrini15 Feb 8, 2024
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
138 changes: 92 additions & 46 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ option(TRITON_ENABLE_GPU "Enable GPU support in backend" ON)
option(TRITON_ENABLE_STATS "Include statistics collections in backend" ON)
option(TRITON_ENABLE_NVTX "Include nvtx markers collection in backend." OFF)

# FIXME: CI needs to enable the GPU flag. Python for window currently does not
# support GPU tensors. For simplicity, we will override this option here.
if(WIN32)
set(TRITON_ENABLE_GPU OFF CACHE BOOL "GPU disabled" FORCE)
endif()

set(TRITON_BACKEND_REPO_TAG "main" CACHE STRING "Tag for triton-inference-server/backend repo")
set(TRITON_COMMON_REPO_TAG "main" CACHE STRING "Tag for triton-inference-server/common repo")
set(TRITON_CORE_REPO_TAG "main" CACHE STRING "Tag for triton-inference-server/core repo")
Expand Down Expand Up @@ -96,6 +102,9 @@ FetchContent_Declare(
GIT_TAG "v0.8"
GIT_SHALLOW ON
)
# Option must be set off so WIN32 build does not break
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
set(BUILD_MOCK OFF)
FetchContent_MakeAvailable(dlpack)

#
Expand Down Expand Up @@ -129,7 +138,10 @@ if(${TRITON_ENABLE_NVTX})
endif() # TRITON_ENABLE_NVTX

find_package(ZLIB REQUIRED)
find_package(Threads REQUIRED)

if(NOT WIN32)
find_package(Threads REQUIRED)
endif()

include_directories(${CMAKE_BINARY_DIR})
configure_file(src/libtriton_python.ldscript libtriton_python.ldscript COPYONLY)
Expand Down Expand Up @@ -174,21 +186,21 @@ set(
)

set(
PYTHON_BACKEND_SRCS
src/python_be.cc
src/python_be.h
src/pb_env.cc
src/pb_env.h
src/pb_metric_reporter.cc
src/pb_metric_reporter.h
src/memory_manager.cc
src/memory_manager.h
src/request_executor.cc
src/request_executor.h
src/stub_launcher.h
src/stub_launcher.cc
src/infer_payload.h
src/infer_payload.cc
PYTHON_BACKEND_SRCS
src/python_be.cc
src/python_be.h
src/pb_env.cc
src/pb_env.h
src/pb_metric_reporter.cc
src/pb_metric_reporter.h
src/memory_manager.cc
src/memory_manager.h
src/request_executor.cc
src/request_executor.h
src/stub_launcher.h
src/stub_launcher.cc
src/infer_payload.h
src/infer_payload.cc
)

list(APPEND
Expand Down Expand Up @@ -239,48 +251,82 @@ target_compile_options(
triton-python-backend PRIVATE
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>:
-Wall -Wextra -Wno-unused-parameter -Wno-type-limits -Werror>
$<$<CXX_COMPILER_ID:MSVC>:/Wall /D_WIN32_WINNT=0x0A00 /EHsc /Zc:preprocessor>
)

target_compile_features(triton-python-backend-stub PRIVATE cxx_std_${TRITON_MIN_CXX_STANDARD})
target_compile_options(
triton-python-backend-stub PRIVATE
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>:
-fvisibility=hidden -Wall -Wextra -Wno-unused-parameter -Wno-type-limits -Werror>
-fvisibility=hidden -Wall -Wextra -Wno-unused-parameter -Wno-type-limits -Werror>
$<$<CXX_COMPILER_ID:MSVC>:/Wall /D_WIN32_WINNT=0x0A00 /EHsc /Zc:preprocessor>
)
target_compile_definitions(triton-python-backend-stub PRIVATE TRITON_PB_STUB)

target_link_libraries(
triton-python-backend
PRIVATE
# For WIN32 do not link Threads and DL_LIBS
if(WIN32)
target_link_libraries(
triton-python-backend
PRIVATE
dlpack
triton-backend-utils # from repo-backend
-lrt # shared memory
triton-core-serverstub # from repo-core
ZLIB::ZLIB
-larchive
)

target_link_libraries(
triton-python-backend-stub
PRIVATE
dlpack
triton-backend-utils # from repo-backend
pybind11::embed
-lrt # shared memory
-larchive # libarchive
)
else()
target_link_libraries(
triton-python-backend
PRIVATE
dlpack
Threads::Threads
triton-backend-utils # from repo-backend
${CMAKE_DL_LIBS} # dlopen and dlclose
-lrt # shared memory
triton-core-serverstub # from repo-core
ZLIB::ZLIB
-larchive
)

target_link_libraries(
triton-python-backend-stub
PRIVATE
dlpack
Threads::Threads
triton-backend-utils # from repo-backend
${CMAKE_DL_LIBS} # dlopen and dlclose
-lrt # shared memory
triton-core-serverstub # from repo-core
ZLIB::ZLIB
-larchive
)

target_link_libraries(
triton-python-backend-stub
PRIVATE
dlpack
Threads::Threads
triton-backend-utils # from repo-backend
${CMAKE_DL_LIBS} # dlopen and dlclose
pybind11::embed
-lrt # shared memory
-larchive # libarchive
)
triton-backend-utils # from repo-backend
${CMAKE_DL_LIBS} # dlopen and dlclose
pybind11::embed
-lrt # shared memory
-larchive # libarchive
)
endif()

set_target_properties(
triton-python-backend PROPERTIES
POSITION_INDEPENDENT_CODE ON
OUTPUT_NAME triton_python
LINK_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/libtriton_python.ldscript
LINK_FLAGS "-Wl,--version-script libtriton_python.ldscript"
)
if(WIN32)
set_target_properties(
triton-python-backend PROPERTIES
POSITION_INDEPENDENT_CODE ON
OUTPUT_NAME triton_python
)
else()
set_target_properties(
triton-python-backend PROPERTIES
POSITION_INDEPENDENT_CODE ON
OUTPUT_NAME triton_python
LINK_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/libtriton_python.ldscript
LINK_FLAGS "-Wl,--version-script libtriton_python.ldscript"
)
endif()

add_subdirectory(./src/shm_monitor)

Expand Down
2 changes: 1 addition & 1 deletion src/infer_request.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class InferRequest {
const uint64_t timeout = 0, const intptr_t response_factory_address = 0,
const intptr_t request_address = 0,
const PreferredMemory& preferred_memory =
PreferredMemory(PreferredMemory::DEFAULT, 0),
PreferredMemory(PreferredMemory::kDefault, 0),
const InferenceTrace& trace = InferenceTrace());

const std::vector<std::shared_ptr<PbTensor>>& Inputs();
Expand Down
4 changes: 2 additions & 2 deletions src/metric_family.cc
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,9 @@ TRITONSERVER_MetricKind
MetricFamily::ToTritonServerMetricKind(const MetricKind& kind)
{
switch (kind) {
case COUNTER:
case kCounter:
return TRITONSERVER_METRIC_KIND_COUNTER;
case GAUGE:
case kGauge:
return TRITONSERVER_METRIC_KIND_GAUGE;
default:
throw PythonBackendException("Unknown metric kind");
Expand Down
48 changes: 26 additions & 22 deletions src/pb_env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@

#include "pb_env.h"

#ifndef _WIN32
#include <archive.h>
#include <archive_entry.h>
#include <fts.h>
#endif
#include <sys/stat.h>

#include <cstdlib>
Expand All @@ -40,6 +42,29 @@

namespace triton { namespace backend { namespace python {

bool
FileExists(std::string& path)
{
struct stat buffer;
return stat(path.c_str(), &buffer) == 0;
}

void
LastModifiedTime(const std::string& path, time_t* last_modified_time)
{
struct stat result;
if (stat(path.c_str(), &result) == 0) {
*last_modified_time = result.st_mtime;
} else {
throw PythonBackendException(std::string(
"LastModifiedTime() failed as file \'" + path +
std::string("\' does not exists.")));
}
}

// FIXME: [DLIS-5969]: Develop platforom-agnostic functions
// to support custom python environments.
#ifndef _WIN32
void
CopySingleArchiveEntry(archive* input_archive, archive* output_archive)
{
Expand Down Expand Up @@ -73,7 +98,6 @@ CopySingleArchiveEntry(archive* input_archive, archive* output_archive)
}
}


void
ExtractTarFile(std::string& archive_path, std::string& dst_path)
{
Expand Down Expand Up @@ -153,27 +177,6 @@ ExtractTarFile(std::string& archive_path, std::string& dst_path)
}
}

bool
FileExists(std::string& path)
{
struct stat buffer;
return stat(path.c_str(), &buffer) == 0;
}

void
LastModifiedTime(const std::string& path, time_t* last_modified_time)
{
struct stat result;
if (stat(path.c_str(), &result) == 0) {
*last_modified_time = result.st_mtime;
} else {
throw PythonBackendException(std::string(
"LastModifiedTime() failed as file \'" + path +
std::string("\' does not exists.")));
}
}


void
RecursiveDirectoryDelete(const char* dir)
{
Expand Down Expand Up @@ -326,5 +329,6 @@ EnvironmentManager::~EnvironmentManager()
{
RecursiveDirectoryDelete(base_path_);
}
#endif

}}} // namespace triton::backend::python
7 changes: 7 additions & 0 deletions src/pb_env.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
#include <mutex>
#include <string>

#ifdef WIN32
#include <windows.h>
#undef PATH_MAX
#define PATH_MAX MAX_PATH
#endif
namespace triton { namespace backend { namespace python {

void ExtractTarFile(std::string& archive_path, std::string& dst_path);
Expand All @@ -39,6 +44,7 @@ bool FileExists(std::string& path);
//
// A class that manages Python environments
//
#ifndef _WIN32
class EnvironmentManager {
std::map<std::string, std::pair<std::string, time_t>> env_map_;
char base_path_[PATH_MAX + 1];
Expand All @@ -52,5 +58,6 @@ class EnvironmentManager {
std::string ExtractIfNotExtracted(std::string env_path);
~EnvironmentManager();
};
#endif

}}} // namespace triton::backend::python
4 changes: 2 additions & 2 deletions src/pb_preferred_memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ namespace triton { namespace backend { namespace python {

class PreferredMemory {
public:
enum MemoryType { GPU, CPU, DEFAULT };
enum MemoryType { kGPU, kCPU, kDefault };

PreferredMemory()
: preferred_memory_type_(MemoryType::DEFAULT), preferred_device_id_(0)
: preferred_memory_type_(MemoryType::kDefault), preferred_device_id_(0)
{
}

Expand Down
Loading