diff --git a/src/pb_env.cc b/src/pb_env.cc index 310ebff4..cc1a042a 100644 --- a/src/pb_env.cc +++ b/src/pb_env.cc @@ -42,6 +42,26 @@ 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."))); + } +} + #ifndef _WIN32 void CopySingleArchiveEntry(archive* input_archive, archive* output_archive) @@ -309,24 +329,4 @@ EnvironmentManager::~EnvironmentManager() } #endif -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."))); - } -} - }}} // namespace triton::backend::python diff --git a/src/pb_stub.cc b/src/pb_stub.cc index cbf15bd7..f838fba8 100644 --- a/src/pb_stub.cc +++ b/src/pb_stub.cc @@ -1452,8 +1452,7 @@ Logger::Log( // and pass messages to cerr if (!BackendLoggingActive()) { std::string path(filename); - const std::string os_slash = FileSeparator(); - size_t pos = path.rfind(os_slash); + size_t pos = path.rfind(std::filesystem::path::preferred_separator); if (pos != std::string::npos) { path = path.substr(pos + 1, std::string::npos); } @@ -1841,7 +1840,7 @@ ModelContext::Init( const std::string& model_path, const std::string& runtime_modeldir, const std::string& triton_install_path, const std::string& model_version) { - const std::string os_slash = FileSeparator(); + const char os_slash = std::filesystem::path::preferred_separator; type_ = ModelType::kDefault; if (runtime_modeldir != "DEFAULT") { // For python based backends, existence of `model.py` in the corresponding @@ -1867,7 +1866,7 @@ ModelContext::Init( void ModelContext::StubSetup(py::module& sys) { - const std::string os_slash = FileSeparator(); + const char os_slash = std::filesystem::path::preferred_separator; std::string model_name = python_model_path_.substr(python_model_path_.find_last_of(os_slash) + 1); @@ -1943,7 +1942,7 @@ main(int argc, char** argv) // Find the package name from model path. size_t prev = 0, pos = 0; - const std::string os_slash = FileSeparator(); + const char os_slash = std::filesystem::path::preferred_separator; do { pos = model_path.find(os_slash, prev); if (pos == std::string::npos) diff --git a/src/pb_stub.h b/src/pb_stub.h index b8e38895..a51f25f5 100644 --- a/src/pb_stub.h +++ b/src/pb_stub.h @@ -30,6 +30,8 @@ #include #include +#include + #include "infer_request.h" #include "infer_response.h" #include "ipc_message.h" @@ -125,7 +127,7 @@ class LogMessage { LogMessage(const char* file, int line, LogLevel level) : level_(level) { std::string path(file); - const std::string os_slash = FileSeparator(); + const char os_slash = std::filesystem::path::preferred_separator; size_t pos = path.rfind(os_slash); if (pos != std::string::npos) { path = path.substr(pos + 1, std::string::npos); diff --git a/src/pb_utils.cc b/src/pb_utils.cc index 6043a76b..2e4eec9b 100644 --- a/src/pb_utils.cc +++ b/src/pb_utils.cc @@ -286,34 +286,16 @@ IsUsingCUDAPool( #endif // TRITON_ENABLE_GPU -const std::string& -FileSeparator() -{ -#ifdef _WIN32 - static std::string file_separator = "\\"; -#else - static std::string file_separator = "/"; -#endif - return file_separator; -} - +// FIXME: We should not need this function. However, some +// paths are being retrieved from core that are not platform- +// agnostic. DLIS-6078 has been created to track the effort +// to clean up external modules and remove this function. void SanitizePath(std::string& path) { std::replace(path.begin(), path.end(), '/', '\\'); } -const std::string& -StubExecutableName() -{ -#ifdef _WIN32 - static std::string executable_name = "triton_python_backend_stub.exe"; -#else - static std::string executable_name = "triton_python_backend_stub"; -#endif - return executable_name; -} - #ifndef TRITON_PB_STUB std::shared_ptr WrapTritonErrorInSharedPtr(TRITONSERVER_Error* error) diff --git a/src/pb_utils.h b/src/pb_utils.h index ca72edcb..3acdc390 100644 --- a/src/pb_utils.h +++ b/src/pb_utils.h @@ -321,9 +321,7 @@ class ScopedSetDevice { // Utility functions to get the correct file separator depending on the OS. // Can likely be replaced with std::filesystem with the upgrade to C++17 -const std::string& FileSeparator(); void SanitizePath(std::string& path); -const std::string& StubExecutableName(); // Check if the data is allocated from the pool by the base address. bool IsUsingCUDAPool( diff --git a/src/python_be.cc b/src/python_be.cc index 968263ba..9e51832b 100644 --- a/src/python_be.cc +++ b/src/python_be.cc @@ -25,6 +25,8 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "python_be.h" +#include + #include "gpu_buffers.h" #include "infer_payload.h" #include "model_loader.h" @@ -2238,10 +2240,10 @@ TRITONBACKEND_Initialize(TRITONBACKEND_Backend* backend) RETURN_IF_ERROR( TRITONBACKEND_BackendArtifacts(backend, &artifact_type, &clocation)); - const std::string os_slash = FileSeparator(); + const char os_slash = std::filesystem::path::preferred_separator; + std::string location(clocation); #ifdef _WIN32 const std::string stub_executable_name = "triton_python_backend_stub.exe"; - std::string location(clocation); SanitizePath(location); SanitizePath(default_backend_dir_string); #else @@ -2249,8 +2251,6 @@ TRITONBACKEND_Initialize(TRITONBACKEND_Backend* backend) #endif // Check if `triton_python_backend_stub` and `triton_python_backend_utils.py` // are located under `location`. - // DLIS-5596: Add forward slash to be platform agnostic - // (i.e. For Windows, we need to use backward slash). std::string default_python_backend_dir = default_backend_dir_string + os_slash + "python"; std::string backend_stub_path = location + os_slash + stub_executable_name; diff --git a/src/stub_launcher.cc b/src/stub_launcher.cc index dbb1a53a..71f2349d 100644 --- a/src/stub_launcher.cc +++ b/src/stub_launcher.cc @@ -26,6 +26,8 @@ #include "stub_launcher.h" +#include + #include "python_be.h" #ifdef _WIN32 @@ -86,7 +88,7 @@ StubLauncher::Initialize(ModelState* model_state) model_version_ = model_state->Version(); std::stringstream ss; - const std::string os_slash = FileSeparator(); + const char os_slash = std::filesystem::path::preferred_separator; ss << model_repository_path_ << os_slash << model_version_ << os_slash; std::string artifact_name; RETURN_IF_ERROR(model_state->ModelConfig().MemberAsString( @@ -229,7 +231,7 @@ StubLauncher::Launch() stub_name = model_instance_name_; } - const std::string os_slash = FileSeparator(); + const char os_slash = std::filesystem::path::preferred_separator; #ifdef _WIN32 const std::string stub_executable_name = "triton_python_backend_stub.exe"; SanitizePath(model_path_); @@ -366,8 +368,7 @@ StubLauncher::Launch() stub_args[3] = nullptr; // Last argument must be nullptr // Default Python backend stub - std::string python_backend_stub = - python_lib_ + os_slash_ + "triton_python_backend_stub"; + std::string python_backend_stub = python_lib_ + "/triton_python_backend_stub"; // Path to alternative Python backend stub std::string model_python_backend_stub =