From e1164643aad9b9b95fd5a6d63bafc0f9deb22692 Mon Sep 17 00:00:00 2001 From: generatedunixname89002005287564 Date: Wed, 17 Apr 2024 12:38:41 -0700 Subject: [PATCH] multipy, multiray, multiflow (-2350155711603743498) Reviewed By: mpahsu Differential Revision: D56236901 fbshipit-source-id: f496d3e81d7e337fc944a01ebf7c92d08606772f --- multipy/runtime/elf_file.h | 2 +- multipy/runtime/embedded_file.cpp | 2 +- multipy/runtime/embedded_file.h | 2 +- .../interpreter/import_find_sharedfuncptr.cpp | 4 ++-- multipy/runtime/interpreter/interpreter_impl.cpp | 6 +++--- multipy/runtime/interpreter/interpreter_impl.h | 2 +- multipy/runtime/loader.cpp | 15 +++++++++------ multipy/runtime/mem_file.h | 2 +- multipy/runtime/test_deploy.cpp | 1 - 9 files changed, 19 insertions(+), 17 deletions(-) diff --git a/multipy/runtime/elf_file.h b/multipy/runtime/elf_file.h index 812e6867..0fdb90f2 100644 --- a/multipy/runtime/elf_file.h +++ b/multipy/runtime/elf_file.h @@ -19,7 +19,7 @@ namespace deploy { /// A section of an ElfFile. struct Section { - Section() {} + Section() = default; explicit Section( std::shared_ptr _memfile, const char* _name, diff --git a/multipy/runtime/embedded_file.cpp b/multipy/runtime/embedded_file.cpp index 6538e64a..e41f523e 100644 --- a/multipy/runtime/embedded_file.cpp +++ b/multipy/runtime/embedded_file.cpp @@ -20,7 +20,7 @@ EmbeddedFile::EmbeddedFile( const std::initializer_list& sections, const std::initializer_list symbols) : libraryName("/tmp/multipy_" + name + "XXXXXX") { - int fd = mkstemp(&libraryName[0]); + int fd = mkstemp(libraryName.data()); MULTIPY_INTERNAL_ASSERT(fd != -1, "failed to create temporary file"); FILE* dst = fdopen(fd, "wb"); MULTIPY_INTERNAL_ASSERT(dst); diff --git a/multipy/runtime/embedded_file.h b/multipy/runtime/embedded_file.h index 8b13458d..2e6530fa 100644 --- a/multipy/runtime/embedded_file.h +++ b/multipy/runtime/embedded_file.h @@ -29,7 +29,7 @@ struct InterpreterSymbol { /// EmbeddedFile makes it easier to load a custom interpreter embedded within /// the binary. struct EmbeddedFile { - std::string libraryName{""}; + std::string libraryName; bool customLoader{false}; EmbeddedFile( diff --git a/multipy/runtime/interpreter/import_find_sharedfuncptr.cpp b/multipy/runtime/interpreter/import_find_sharedfuncptr.cpp index 1418a64c..cbe7775c 100644 --- a/multipy/runtime/interpreter/import_find_sharedfuncptr.cpp +++ b/multipy/runtime/interpreter/import_find_sharedfuncptr.cpp @@ -27,7 +27,7 @@ void loadSearchFile(const char* pathname) { CustomLibrary& lib = *search_files_.back(); lib.add_search_library(SystemLibrary::create(deploy_self)); lib.add_search_library(SystemLibrary::create()); - for (auto f : search_files_) { + for (const auto& f : search_files_) { if (f.get() == &lib) { continue; } @@ -58,7 +58,7 @@ extern "C" dl_funcptr _PyImport_FindSharedFuncptr( assert(deploy_self); lib.add_search_library(SystemLibrary::create(deploy_self)); lib.add_search_library(SystemLibrary::create()); - for (auto f : search_files_) { + for (const auto& f : search_files_) { lib.add_search_library(f); } lib.load(); diff --git a/multipy/runtime/interpreter/interpreter_impl.cpp b/multipy/runtime/interpreter/interpreter_impl.cpp index c94cd57e..3d5f38e1 100644 --- a/multipy/runtime/interpreter/interpreter_impl.cpp +++ b/multipy/runtime/interpreter/interpreter_impl.cpp @@ -301,7 +301,7 @@ struct __attribute__((visibility("hidden"))) ConcreteInterpreterObj MULTIPY_SAFE_RETHROW { py::tuple m_args(args.size()); size_t i = 0; - for (std::shared_ptr iObj : args) { + for (const std::shared_ptr& iObj : args) { std::shared_ptr cObj = std::dynamic_pointer_cast(iObj); m_args[i++] = cObj->getPyObject(); @@ -432,7 +432,7 @@ ConcreteInterpreterImplConstructorCommon( if (plugin_paths.size() > 0) { auto sys_path = global_impl("sys", "path").cast>(); std::string libtorch_python_path; - for (auto path : sys_path) { + for (const auto& path : sys_path) { auto file = path + "/torch/lib/libtorch_python.so"; if (file_exists(file)) { libtorch_python_path = file; @@ -440,7 +440,7 @@ ConcreteInterpreterImplConstructorCommon( } } loadSearchFile(libtorch_python_path.c_str()); - for (auto path : plugin_paths) { + for (const auto& path : plugin_paths) { loadSearchFile(path.c_str()); } } diff --git a/multipy/runtime/interpreter/interpreter_impl.h b/multipy/runtime/interpreter/interpreter_impl.h index d287fc45..d5c18680 100644 --- a/multipy/runtime/interpreter/interpreter_impl.h +++ b/multipy/runtime/interpreter/interpreter_impl.h @@ -172,7 +172,7 @@ inline at::IValue Obj::toIValue() const { inline Obj Obj::operator()(at::ArrayRef args) { std::vector> copy; - for (Obj arg : args) { + for (const Obj& arg : args) { copy.push_back(arg.baseObj_); } return baseObj_->call(copy); diff --git a/multipy/runtime/loader.cpp b/multipy/runtime/loader.cpp index e9b60e42..fc27a25c 100644 --- a/multipy/runtime/loader.cpp +++ b/multipy/runtime/loader.cpp @@ -100,10 +100,10 @@ std::vector split_path(const std::string& s, char delim) { // non-zero amount of chars const char* next = strchr(cur, delim); if (!next) { - result.emplace_back(std::string(cur, end)); + result.emplace_back(cur, end); break; } - result.emplace_back(std::string(cur, next)); + result.emplace_back(cur, next); cur = next + 1; } return result; @@ -114,8 +114,9 @@ void replace_all( std::string& str, const std::string& from, const std::string& to) { - if (from.empty()) + if (from.empty()) { return; + } size_t start_pos = 0; while ((start_pos = str.find(from, start_pos)) != std::string::npos) { str.replace(start_pos, from.length(), to); @@ -746,7 +747,7 @@ void resolve_needed_libraries( continue; } - std::string library_path = ""; + std::string library_path; // (2) it is an absolute path if (strchr(name, '/') != nullptr) { library_path = name; @@ -1247,13 +1248,15 @@ struct __attribute__((visibility("hidden"))) CustomLibraryImpl pthread_key_delete(tls_key_); } void call_function(linker_dtor_function_t f) { - if (f == nullptr || (int64_t)f == -1) + if (f == nullptr || (int64_t)f == -1) { return; + } f(); } void call_function(linker_ctor_function_t f) { - if (f == nullptr || (int64_t)f == -1) + if (f == nullptr || (int64_t)f == -1) { return; + } f(argc_, argv_, environ); } diff --git a/multipy/runtime/mem_file.h b/multipy/runtime/mem_file.h index b7138baa..21353b4e 100644 --- a/multipy/runtime/mem_file.h +++ b/multipy/runtime/mem_file.h @@ -8,12 +8,12 @@ #include #include -#include #include #include #include #include #include +#include #include namespace torch { diff --git a/multipy/runtime/test_deploy.cpp b/multipy/runtime/test_deploy.cpp index 541e808c..1bf9e23e 100644 --- a/multipy/runtime/test_deploy.cpp +++ b/multipy/runtime/test_deploy.cpp @@ -10,7 +10,6 @@ #include #include -#include #include #include #include