diff --git a/torch/csrc/inductor/aoti_torch/shim_common.cpp b/torch/csrc/inductor/aoti_torch/shim_common.cpp index 7ee46730dc8d2..1dd766b3a11a9 100644 --- a/torch/csrc/inductor/aoti_torch/shim_common.cpp +++ b/torch/csrc/inductor/aoti_torch/shim_common.cpp @@ -56,22 +56,30 @@ namespace fs = std::experimental::filesystem; #endif #ifndef _WIN32 +#include #include +#include +#include #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; @@ -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 @@ -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