-
Notifications
You must be signed in to change notification settings - Fork 283
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove batch args, and add test in graph mode
Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
- Loading branch information
Showing
7 changed files
with
211 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
==============================================================================*/ | ||
|
||
#include "tensorflow/core/lib/io/inputstream_interface.h" | ||
#include "tensorflow/core/lib/io/random_inputstream.h" | ||
|
||
namespace tensorflow { | ||
namespace data { | ||
|
||
// Note: This SizedRandomAccessFile should only lives within Compute() | ||
// of the kernel as buffer could be released by outside. | ||
class SizedRandomAccessFile : public tensorflow::RandomAccessFile { | ||
public: | ||
SizedRandomAccessFile(Env* env, const string& filename, const void* optional_memory_buff, const size_t optional_memory_size) | ||
: file_(nullptr) | ||
, size_(optional_memory_size) | ||
, buff_((const char *)(optional_memory_buff)) | ||
, size_status_(Status::OK()) { | ||
if (size_ == 0) { | ||
size_status_ = env->GetFileSize(filename, &size_); | ||
if (size_status_.ok()) { | ||
size_status_ = env->NewRandomAccessFile(filename, &file_); | ||
} | ||
} | ||
} | ||
|
||
virtual ~SizedRandomAccessFile() {} | ||
Status Read(uint64 offset, size_t n, StringPiece* result, char* scratch) const override { | ||
if (file_.get() != nullptr) { | ||
return file_.get()->Read(offset, n, result, scratch); | ||
} | ||
size_t bytes_to_read = 0; | ||
if (offset < size_) { | ||
bytes_to_read = (offset + n < size_) ? n : (size_ - offset); | ||
} | ||
if (bytes_to_read > 0) { | ||
memcpy(scratch, &buff_[offset], bytes_to_read); | ||
} | ||
*result = StringPiece(scratch, bytes_to_read); | ||
if (bytes_to_read < n) { | ||
return errors::OutOfRange("EOF reached"); | ||
} | ||
return Status::OK(); | ||
} | ||
Status GetFileSize(uint64* size) { | ||
if (size_status_.ok()) { | ||
*size = size_; | ||
} | ||
return size_status_; | ||
} | ||
private: | ||
std::unique_ptr<tensorflow::RandomAccessFile> file_; | ||
uint64 size_; | ||
const char *buff_; | ||
Status size_status_; | ||
}; | ||
|
||
} // namespace data | ||
} // namespace tensorflow |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.