Skip to content

Commit

Permalink
multipy, multiray, multiflow (-2350155711603743498)
Browse files Browse the repository at this point in the history
Reviewed By: mpahsu

Differential Revision: D56236901

fbshipit-source-id: f496d3e81d7e337fc944a01ebf7c92d08606772f
  • Loading branch information
generatedunixname89002005287564 authored and facebook-github-bot committed Apr 17, 2024
1 parent 88b6948 commit e116464
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 17 deletions.
2 changes: 1 addition & 1 deletion multipy/runtime/elf_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace deploy {

/// A section of an ElfFile.
struct Section {
Section() {}
Section() = default;
explicit Section(
std::shared_ptr<MemFile> _memfile,
const char* _name,
Expand Down
2 changes: 1 addition & 1 deletion multipy/runtime/embedded_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ EmbeddedFile::EmbeddedFile(
const std::initializer_list<ExeSection>& sections,
const std::initializer_list<InterpreterSymbol> 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);
Expand Down
2 changes: 1 addition & 1 deletion multipy/runtime/embedded_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions multipy/runtime/interpreter/import_find_sharedfuncptr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions multipy/runtime/interpreter/interpreter_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<torch::deploy::InterpreterObj> iObj : args) {
for (const std::shared_ptr<torch::deploy::InterpreterObj>& iObj : args) {
std::shared_ptr<ConcreteInterpreterObj> cObj =
std::dynamic_pointer_cast<ConcreteInterpreterObj>(iObj);
m_args[i++] = cObj->getPyObject();
Expand Down Expand Up @@ -432,15 +432,15 @@ ConcreteInterpreterImplConstructorCommon(
if (plugin_paths.size() > 0) {
auto sys_path = global_impl("sys", "path").cast<std::vector<std::string>>();
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;
break;
}
}
loadSearchFile(libtorch_python_path.c_str());
for (auto path : plugin_paths) {
for (const auto& path : plugin_paths) {
loadSearchFile(path.c_str());
}
}
Expand Down
2 changes: 1 addition & 1 deletion multipy/runtime/interpreter/interpreter_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ inline at::IValue Obj::toIValue() const {

inline Obj Obj::operator()(at::ArrayRef<Obj> args) {
std::vector<std::shared_ptr<torch::deploy::InterpreterObj>> copy;
for (Obj arg : args) {
for (const Obj& arg : args) {
copy.push_back(arg.baseObj_);
}
return baseObj_->call(copy);
Expand Down
15 changes: 9 additions & 6 deletions multipy/runtime/loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ std::vector<std::string> 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;
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion multipy/runtime/mem_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@

#include <fcntl.h>
#include <multipy/runtime/Exception.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <unistd.h>
#include <cerrno>
#include <cstdio>
#include <cstring>
#include <iostream>

namespace torch {
Expand Down
1 change: 0 additions & 1 deletion multipy/runtime/test_deploy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include <cstring>

#include <c10/util/irange.h>
#include <libgen.h>
#include <multipy/runtime/deploy.h>
#include <torch/script.h>
#include <torch/torch.h>
Expand Down

0 comments on commit e116464

Please sign in to comment.