diff options
author | qiaoli <qiaoli@google.com> | 2023-06-27 17:26:19 +0000 |
---|---|---|
committer | qiaoli <qiaoli@google.com> | 2023-07-18 00:51:03 +0000 |
commit | 3b849307dbdfc75c68ce8918d0a5663c13fab379 (patch) | |
tree | a16bd6de61fe6a60083eefd8b3dbb191e9f2ceab /fcp/tensorflow/file_descriptor_filesystem.h | |
parent | 9e36da1f564c3b5a6c0c7565d0dc423c5e694779 (diff) | |
download | federated-compute-3b849307dbdfc75c68ce8918d0a5663c13fab379.tar.gz |
Add tensoflow filesytem support file descriptor
Bug: 281758731
Test: atest
Change-Id: I19d6d2deb8a8a66d5ef66c6a1640b867f3434b80
Diffstat (limited to 'fcp/tensorflow/file_descriptor_filesystem.h')
-rw-r--r-- | fcp/tensorflow/file_descriptor_filesystem.h | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/fcp/tensorflow/file_descriptor_filesystem.h b/fcp/tensorflow/file_descriptor_filesystem.h new file mode 100644 index 0000000..86a4084 --- /dev/null +++ b/fcp/tensorflow/file_descriptor_filesystem.h @@ -0,0 +1,72 @@ +#ifndef FCP_TENSORFLOW_FILE_DESCRIPTOR_FILESYSTEM_H_ +#define FCP_TENSORFLOW_FILE_DESCRIPTOR_FILESYSTEM_H_ + +#include <memory> +#include <vector> + +#include "tensorflow/core/platform/file_system.h" + +namespace tensorflow { +namespace fcp { + +// Filesystem for file descriptors that reads URIs in the form "fd:///<int>", +// where <int> is a valid file descriptor number. This filesystem can be useful +// to support situations in which a file descriptor is opened in Java and passed +// to the JNI layer. +// +// CAVEATS: +// * This filesystem is non-hierarchical and read-only; many functions simply +// return tensorflow::error::code::UNIMPLEMENTED. +// * To read a file descriptor, this filesystem makes a dup and closes the dup +// when it is done with it. The code that originally created the URI is +// responsible for closing the original file descriptor. +class FileDescriptorFileSystem : public tensorflow::FileSystem { + public: + FileDescriptorFileSystem() = default; + ~FileDescriptorFileSystem() override = default; + + tensorflow::Status NewRandomAccessFile( + const std::string& filename, + std::unique_ptr<RandomAccessFile>* result) override; + + // Clears *results and stores pattern if pattern is a literal match of a valid + // file descriptor. As such, this does not support the full pattern matching + // specification as described by FileSystem::GetMatchingPaths. + tensorflow::Status GetMatchingPaths( + const std::string& pattern, std::vector<std::string>* results) override; + + tensorflow::Status Stat(const std::string& fname, + tensorflow::FileStatistics* stats) override; + + tensorflow::Status GetFileSize(const std::string& fname, + uint64* size) override; + + // Not necessary to read TF checkpoints; these always return UNIMPLEMENTED + tensorflow::Status NewReadOnlyMemoryRegionFromFile( + const std::string& filename, + std::unique_ptr<ReadOnlyMemoryRegion>* result) override; + + tensorflow::Status FileExists(const std::string& fname) override; + + // The fd filesystem is non-hierarchical; this always returns UNIMPLEMENTED + tensorflow::Status GetChildren(const std::string& dir, + std::vector<string>* r) override; + + // The fd filesystem is read-only; these always return UNIMPLEMENTED + tensorflow::Status NewWritableFile( + const std::string& fname, std::unique_ptr<WritableFile>* result) override; + tensorflow::Status NewAppendableFile( + const std::string& fname, std::unique_ptr<WritableFile>* result) override; + tensorflow::Status DeleteFile(const std::string& f) override; + tensorflow::Status CreateDir(const std::string& d) override; + tensorflow::Status DeleteDir(const std::string& d) override; + tensorflow::Status RenameFile(const std::string& s, + const std::string& t) override; + tensorflow::Status CanCreateTempFile(const std::string& fname, + bool* can_create_temp_file) override; +}; + +} // namespace fcp +} // namespace tensorflow + +#endif // FCP_TENSORFLOW_FILE_DESCRIPTOR_FILESYSTEM_H_ |