Skip to content

Commit

Permalink
Fix/dump_manager (#1163)
Browse files Browse the repository at this point in the history
* fix dump manager

* Apply code-format changes

* update

* Apply code-format changes

* update

---------

Co-authored-by: curioyang <[email protected]>
Co-authored-by: FusionBolt <[email protected]>
Co-authored-by: FusionBolt <[email protected]>
  • Loading branch information
4 people authored Feb 1, 2024
1 parent 546d774 commit e7d0aa1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 22 deletions.
6 changes: 1 addition & 5 deletions src/Native/src/runtime/dump_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ void dump_output_impl(dump_manager &dump_manager_, nncase::value_t value,
dump_data(stream, IN_CAST(_in_type, data), value_tensor); \
return; \
}

dump(
dump_by_path(
dump_manager_, value,
[incr, &dump_manager_](auto &stream, auto &&value_tensor) {
auto *data = force_get_data(value_tensor);
Expand All @@ -98,9 +97,6 @@ void dump_output_impl(dump_manager &dump_manager_, nncase::value_t value,
dump_data(stream, IN_CAST(nncase::half, data), value_tensor);
return;
}
// std::cout << "unsupported type:"
// << (int)value_tensor->dtype()->typecode() <<
// std::endl;
},
path);
if (incr) {
Expand Down
30 changes: 13 additions & 17 deletions src/Native/src/runtime/dump_manager_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,32 +27,32 @@ void dump_append(dump_manager &dump_manager_, F &&f, const std::string &path) {
}

template <typename F>
void dump(dump_manager &dump_manager_, nncase::value_t value, F &&f) {
dump(dump_manager_, value, f, dump_manager_.dump_path());
}

template <typename F>
void dump(dump_manager &dump_manager_, nncase::value_t value, F &&f,
const std::string &path) {
auto stream = dump_manager_.get_stream(path);
void dump_by_steam(dump_manager &dump_manager_, nncase::value_t value, F &&f,
std::ofstream &stream) {
if (value.is_a<nncase::tensor>()) {
auto value_tensor = value.as<nncase::tensor>().unwrap();
f(stream, value_tensor);
stream.close();
} else if (value.is_a<nncase::tuple>()) {
// stream << "tuple" << "\n";
stream.close();
auto value_tuple = value.as<nncase::tuple>().unwrap();
for (auto &field : value_tuple->fields()) {
dump(dump_manager_, field, f, path);
dump_by_steam(dump_manager_, field, f, stream);
std::cout << std::endl;
}
} else {
std::cout << "unknown in dump" << std::endl;
stream << "unknown in dump\n";
return;
}
}

// dump_by_path create a new steam by path and close steam after dump_by_stream.
template <typename F>
void dump_by_path(dump_manager &dump_manager_, nncase::value_t value, F &&f,
const std::string &path) {
auto stream = dump_manager_.get_stream(path);
dump_by_steam(dump_manager_, value, f, stream);
stream.close();
}

inline std::string to_str(const nncase::dims_t &shape) {
std::stringstream stream;
if (shape.size() == 0) {
Expand All @@ -69,10 +69,6 @@ inline std::string to_str(const nncase::dims_t &shape) {
template <typename T>
void dump_data(std::ostream &stream, const T *data,
nncase::tensor value_tensor) {
// std::cout << "out_shape:";
// for (auto d : value_tensor->shape()) {
// std::cout << d << " ";
// }
stream << "type:"
<< std::to_string(to_typecode(value_tensor->dtype()).unwrap())
<< std::endl;
Expand Down

0 comments on commit e7d0aa1

Please sign in to comment.