8#include <nlohmann/json.hpp>
10#include <unordered_map>
18 std::size_t
operator()(
const std::pair<int32_t, bool>& p)
const {
19 return std::hash<int32_t>()(p.first) ^ p.second ? 0x40000000 : 0;
29 const std::vector<size_t>
dims{0};
31 std::shared_ptr<const std::filesystem::path>
ext_file;
32 std::shared_ptr<const std::vector<uint8_t>>
data;
46 ext_file(std::move(other.ext_file)),
data(std::move(other.data)) {}
51 const nlohmann::json& entry,
53 std::filesystem::path base_path = std::filesystem::path()
61 std::unordered_map<std::string, uint32_t>
invokes_ = std::unordered_map<std::string, uint32_t>{};
77 const std::vector<size_t>& dims,
79 std::string node_id = std::string{}
85 const std::vector<size_t>& dims,
86 std::filesystem::path& file,
88 std::string node_id = std::string{}
99 template<
typename T = ArgCaptureIO>
100 static std::shared_ptr<T>
from_index(
const std::filesystem::path& file);
112 if (!std::filesystem::exists(file)) {
113 throw std::runtime_error(
"Index file does not exist: " + file.string());
116 std::ifstream ifs(file);
117 if (!ifs.is_open()) {
118 throw std::runtime_error(
"Failed to open index file for reading: " + file.string());
125 throw std::runtime_error(
"Unsupported index format version");
128 auto name = j[
"target"].get<std::string>();
129 auto invokes = j[
"invocation"].get<uint32_t>();
130 auto element_id = j[
"element_id"].get<std::string>();
132 auto captureIO = std::make_shared<T>(name.c_str());
133 captureIO->invokes_[element_id] = invokes;
135 auto& capture_map = captureIO->current_captures_[element_id];
136 for (
const auto& entry : j[
"captures"]) {
ArgCaptureIO(const char *name)
Definition arg_capture_io.h:65
bool create_and_capture_to_file(int arg_idx, bool after, int primitive_type, const std::vector< size_t > &dims, std::filesystem::path &file, const void *data, std::string node_id=std::string{})
std::unordered_map< std::string, uint32_t > invokes_
Definition arg_capture_io.h:61
static std::shared_ptr< T > from_index(const std::filesystem::path &file)
Definition arg_capture_io.h:111
uint32_t get_current_invocation(std::string element_id) const
bool write_capture_to_file(ArgCapture &capture, std::filesystem::path file, const void *data)
void invocation(std::string element_id)
std::string name_
Definition arg_capture_io.h:60
static bool write_data_to_raw_file(const std::filesystem::path &file, const void *src_data, size_t size)
const std::string & get_name() const
bool capture_inline(ArgCapture &capture, const void *data, std::string node_id=std::string{})
bool create_and_capture_inline(int arg_idx, bool after, int primitive_type, const std::vector< size_t > &dims, const void *data, std::string node_id=std::string{})
std::unordered_map< std::string, std::unordered_map< std::pair< int32_t, bool >, ArgCapture, MyHash > > current_captures_
Definition arg_capture_io.h:62
static void read_data_from_raw_file(const std::filesystem::path &file, void *write_ptr, size_t size)
const std::unordered_map< std::string, std::unordered_map< std::pair< int32_t, bool >, ArgCapture, MyHash > > & get_captures() const
void write_index(std::filesystem::path base_file)
Definition arg_capture_io.h:15
static const uint32_t INDEX_FORMAT_VERSION
Definition arg_capture_io.h:108
Definition arg_capture_io.h:23
std::shared_ptr< const std::vector< uint8_t > > data
Definition arg_capture_io.h:32
int primitive_type
Definition arg_capture_io.h:30
void serialize_into(nlohmann::json &j) const
const std::vector< size_t > dims
innermost dimension is always the element size
Definition arg_capture_io.h:29
std::shared_ptr< const std::filesystem::path > ext_file
Definition arg_capture_io.h:31
ArgCapture(const ArgCapture &&other) noexcept
Definition arg_capture_io.h:44
ArgCapture(int32_t idx, bool after, int primitive_type, const std::vector< size_t > dims)
Definition arg_capture_io.h:37
bool after
Definition arg_capture_io.h:25
int32_t arg_idx
Definition arg_capture_io.h:24
static void parse_from(const nlohmann::json &entry, std::unordered_map< std::pair< int32_t, bool >, ArgCapture, MyHash > &map, std::filesystem::path base_path=std::filesystem::path())
ArgCapture(const ArgCapture &other)
Definition arg_capture_io.h:40
Definition arg_capture_io.h:17
std::size_t operator()(const std::pair< int32_t, bool > &p) const
Definition arg_capture_io.h:18