mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-07 12:21:27 +01:00
Summary: Remove code dup in import.cpp / export_modules.cpp such that 1. Only one copy of switching logic (detect flatbuffer / is_flatbuffer); 2. Move detection of includeness of flatbuffer to runtime (so no more macros) This also reverts the dependency of import.cpp -> flatbuffer_loader.cpp to flatbuffer_loader.cpp -> import.cpp. Differential Revision: D36926217 Pull Request resolved: https://github.com/pytorch/pytorch/pull/79184 Approved by: https://github.com/zhxchen17
33 lines
644 B
C++
33 lines
644 B
C++
#pragma once
|
|
#include <cstring>
|
|
#include <caffe2/serialize/read_adapter_interface.h>
|
|
|
|
|
|
namespace caffe2 {
|
|
namespace serialize {
|
|
|
|
class MemoryReadAdapter final : public caffe2::serialize::ReadAdapterInterface {
|
|
public:
|
|
explicit MemoryReadAdapter(const void* data, off_t size)
|
|
: data_(data), size_(size) {}
|
|
|
|
size_t size() const override {
|
|
return size_;
|
|
}
|
|
|
|
size_t read(uint64_t pos, void* buf, size_t n, const char* what = "")
|
|
const override {
|
|
(void) what;
|
|
memcpy(buf, (int8_t*)(data_) + pos, n);
|
|
return n;
|
|
}
|
|
|
|
private:
|
|
const void* data_;
|
|
off_t size_;
|
|
};
|
|
|
|
|
|
} // namespace serialize
|
|
} // namespace caffe2
|