Skip to content

Commit

Permalink
Fix dependency on filesystem on Linux (pytorch#137209)
Browse files Browse the repository at this point in the history
Similar to: pytorch#134494
We are seeing come back of pytorch#133437 due to use of filesystem on Linux

Pull Request resolved: pytorch#137209
Approved by: https://github.com/kit1980, https://github.com/malfet
  • Loading branch information
atalman authored and pytorchmergebot committed Oct 3, 2024
1 parent 235f7e0 commit 6241006
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions torch/csrc/inductor/aoti_torch/shim_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,30 @@ namespace fs = std::experimental::filesystem;
#endif

#ifndef _WIN32
#include <limits.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#endif

// HACK for failed builds in ARVR, where it cannot find these symbols within
// std::experimental::filesystem
namespace {
fs::path get_current_path() {
#if __has_include("filesystem")
return fs::current_path();
std::string get_current_path() {
#if __has_include("filesystem") && !defined(__linux__)
return fs::current_path().string();
#else
throw std::runtime_error("Not implemented");
char currentPath[PATH_MAX];
if (getcwd(currentPath, sizeof(currentPath)) != nullptr) {
return std::string(currentPath);
} else {
throw std::runtime_error("Failed to get current path");
}
#endif
}

bool file_exists(std::string& path) {
#ifdef _WIN32
#if __has_include("filesystem") && !defined(__linux__)
return fs::exists(path);
#else
struct stat rc;
Expand All @@ -80,10 +88,13 @@ bool file_exists(std::string& path) {
}

bool create_directories(const std::string& path) {
#if __has_include("filesystem")
#if __has_include("filesystem") && !defined(__linux__)
return fs::create_directories(path);
#else
throw std::runtime_error("Not implemented");
if (mkdir(path.c_str(), 0777) == -1) {
throw std::runtime_error("Failed to create directory");
}
return true;
#endif
}
} // namespace
Expand Down Expand Up @@ -1039,7 +1050,7 @@ AOTI_TORCH_EXPORT void aoti_torch_save_tensor_handle(
at::Tensor* t = tensor_handle_to_tensor_pointer(self);
#ifndef C10_MOBILE
// Save tensor to tmp .pt file for tensors and can be torch.load'ed later
std::string cwd = get_current_path().string();
std::string cwd = get_current_path();
std::string tmp_folder = cwd + "/tmp/aoti_torch/";
if (!file_exists(tmp_folder)) {
std::cout
Expand Down

0 comments on commit 6241006

Please sign in to comment.