forked from pytorch/pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BE][flatbuffer] Remove code duplications and refactor (pytorch#79184)
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: pytorch#79184 Approved by: https://github.com/zhxchen17
- Loading branch information
1 parent
7de231a
commit fed12ff
Showing
24 changed files
with
617 additions
and
560 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,32 @@ | ||
#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 |
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
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.