summaryrefslogtreecommitdiffstats
path: root/eval
diff options
context:
space:
mode:
authorHaavard <havardpe@yahoo-inc.com>2017-02-07 11:52:08 +0000
committerHaavard <havardpe@yahoo-inc.com>2017-02-07 11:52:08 +0000
commit2287c89dfd47bb9c97f8b70470159d0a60fbefaa (patch)
tree6a86aec30e11137a28acf7d75ba446e998ad84dc /eval
parent115cac2552983f2f1bc5b52f9bfa13cd6ece9628 (diff)
use mapped file input from vespalib
Diffstat (limited to 'eval')
-rw-r--r--eval/src/vespa/eval/eval/value_cache/constant_tensor_loader.cpp29
1 files changed, 3 insertions, 26 deletions
diff --git a/eval/src/vespa/eval/eval/value_cache/constant_tensor_loader.cpp b/eval/src/vespa/eval/eval/value_cache/constant_tensor_loader.cpp
index 37355406952..fc6181acc02 100644
--- a/eval/src/vespa/eval/eval/value_cache/constant_tensor_loader.cpp
+++ b/eval/src/vespa/eval/eval/value_cache/constant_tensor_loader.cpp
@@ -9,6 +9,7 @@
#include <vespa/eval/eval/tensor.h>
#include <vespa/eval/eval/tensor_engine.h>
#include <vespa/eval/eval/tensor_spec.h>
+#include <vespa/vespalib/io/mapped_file_input.h>
LOG_SETUP(".vespalib.eval.value_cache.constant_tensor_loader");
@@ -20,30 +21,6 @@ using ObjectTraverser = slime::ObjectTraverser;
namespace {
-struct File {
- int file;
- char *data;
- size_t size;
- File(const std::string &file_name) : file(open(file_name.c_str(), O_RDONLY)), data((char*)MAP_FAILED), size(0) {
- struct stat info;
- if ((file != -1) && (fstat(file, &info) == 0)) {
- data = (char*)mmap(0, info.st_size, PROT_READ, MAP_SHARED, file, 0);
- if (data != MAP_FAILED) {
- size = info.st_size;
- }
- }
- }
- bool valid() const { return (data != MAP_FAILED); }
- ~File() {
- if (valid()) {
- munmap(data, size);
- }
- if (file != -1) {
- close(file);
- }
- }
-};
-
struct AddressExtractor : ObjectTraverser {
const std::set<vespalib::string> &indexed;
TensorSpec::Address &address;
@@ -80,10 +57,10 @@ ConstantTensorLoader::create(const vespalib::string &path, const vespalib::strin
return std::make_unique<TensorConstant>(_engine.type_of(*tensor), std::move(tensor));
}
Slime slime;
- File file(path);
+ MappedFileInput file(path);
if (!file.valid()) {
LOG(warning, "could not read file: %s", path.c_str());
- } else if (slime::JsonFormat::decode(Memory(file.data, file.size), slime) == 0) {
+ } else if (slime::JsonFormat::decode(file.get(), slime) == 0) {
LOG(warning, "file contains invalid json: %s", path.c_str());
}
std::set<vespalib::string> indexed;