-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove hdf5 dependency on minmax embedding
- Loading branch information
Showing
13 changed files
with
462 additions
and
222 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
|
||
/* | ||
* Copyright (c) 2024 Samsung Electronics Co., Ltd. All Rights Reserved | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include "MinMaxData.h" | ||
|
||
#include <cstdio> | ||
#include <iostream> | ||
|
||
namespace onert | ||
{ | ||
namespace exec | ||
{ | ||
|
||
RawMinMaxDumper::RawMinMaxDumper(const std::string &filename) : _filename(filename) {} | ||
|
||
void RawMinMaxDumper::dump(const exec::IOMinMaxMap &input_minmax, | ||
const exec::OpMinMaxMap &op_minmax) const | ||
{ | ||
// Find file is already exist for modifying | ||
auto file = std::fopen(_filename.c_str(), "rb+"); | ||
uint32_t runs = 1; | ||
if (!file) | ||
{ | ||
// If file is not exist, create new file | ||
file = std::fopen(_filename.c_str(), "wb+"); | ||
|
||
// Write run count | ||
std::fwrite(&runs, sizeof(uint32_t), 1, file); | ||
} | ||
else | ||
{ | ||
// Read run count | ||
auto read_size = std::fread(&runs, sizeof(uint32_t), 1, file); | ||
if (read_size != 1) | ||
throw std::runtime_error{"Failed to read run count"}; | ||
runs++; | ||
|
||
// Overwrite run count | ||
std::fseek(file, 0, SEEK_SET); | ||
std::fwrite(&runs, sizeof(uint32_t), 1, file); | ||
|
||
// Go to end of file to append new data | ||
std::fseek(file, 0, SEEK_END); | ||
} | ||
|
||
uint32_t input_count = input_minmax.size(); | ||
uint32_t op_count = op_minmax.size(); | ||
|
||
// std::cout << "[MinMaxData] runs: " << runs << std::endl; | ||
// std::cout << "[MinMaxData] input_count: " << input_count << std::endl; | ||
// std::cout << "[MinMaxData] op_count: " << op_count << std::endl; | ||
|
||
// Write op_count and input_count | ||
std::fwrite(&op_count, sizeof(uint32_t), 1, file); | ||
std::fwrite(&input_count, sizeof(uint32_t), 1, file); | ||
|
||
// For each op | ||
for (auto &&elem : op_minmax) | ||
{ | ||
const uint32_t model_idx = 0; | ||
const uint32_t subg_idx = elem.first.first.value(); | ||
const uint32_t op_idx = elem.first.second.value(); | ||
|
||
// Write model/subg/op index | ||
std::fwrite(&model_idx, sizeof(uint32_t), 1, file); | ||
std::fwrite(&subg_idx, sizeof(uint32_t), 1, file); | ||
std::fwrite(&op_idx, sizeof(uint32_t), 1, file); | ||
|
||
// Write min/max | ||
std::fwrite(elem.second.data, sizeof(float), 2, file); | ||
|
||
// std::cout << "[MinMaxData] OP [" << model_idx << ", " << subg_idx << ", " << op_idx | ||
// << "]: " << elem.second.data[0] << ", " << elem.second.data[1] << std::endl; | ||
} | ||
|
||
// For each input | ||
for (auto &&elem : input_minmax) | ||
{ | ||
const uint32_t model_idx = 0; | ||
const uint32_t subg_idx = elem.first.first.value(); | ||
const uint32_t input_idx = elem.first.second.value(); | ||
|
||
// Write model/subg/input index | ||
std::fwrite(&model_idx, sizeof(uint32_t), 1, file); | ||
std::fwrite(&subg_idx, sizeof(uint32_t), 1, file); | ||
std::fwrite(&input_idx, sizeof(uint32_t), 1, file); | ||
|
||
// Write min/max | ||
std::fwrite(elem.second.data, sizeof(float), 2, file); | ||
|
||
// std::cout << "[MinMaxData] Input [" << model_idx << ", " << subg_idx << ", " << input_idx | ||
// << "]: " << elem.second.data[0] << ", " << elem.second.data[1] << std::endl; | ||
} | ||
|
||
fclose(file); | ||
} | ||
|
||
} // namespace exec | ||
} // namespace onert |
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,74 @@ | ||
|
||
/* | ||
* Copyright (c) 2024 Samsung Electronics Co., Ltd. All Rights Reserved | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#ifndef __ONERT_EXEC_MINMAX_DATA_H__ | ||
#define __ONERT_EXEC_MINMAX_DATA_H__ | ||
|
||
#include "exec/MinMaxMap.h" | ||
|
||
#include <string> | ||
|
||
namespace onert | ||
{ | ||
namespace exec | ||
{ | ||
|
||
// Because IOMinMaxMap and OpMinMaxMap does not have the ordering and size information, | ||
// we need to dump model, subgraph id for each minmax | ||
|
||
// File structure | ||
// uint32_t num of runs | ||
|
||
// For each run | ||
// uint32_t num of operations | ||
// uint32_t num of inputs | ||
|
||
// For each operation | ||
// uint32_t model id | ||
// uint32_t subgraph id | ||
// uint32_t operation id | ||
// float min | ||
// float max | ||
|
||
// For each input | ||
// uint32_t model id | ||
// uint32_t subgraph id | ||
// uint32_t input id | ||
// float min | ||
// float max | ||
|
||
class RawMinMaxDumper | ||
{ | ||
public: | ||
RawMinMaxDumper(const std::string &filename); | ||
/** | ||
* @brief Dump input minmax map | ||
* | ||
* @param[in] in_minmax input minmax map | ||
* @param[in] op_minmax op minmax map | ||
*/ | ||
|
||
void dump(const exec::IOMinMaxMap &in_minmax, const exec::OpMinMaxMap &op_minmax) const; | ||
|
||
private: | ||
std::string _filename; | ||
}; | ||
|
||
} // namespace exec | ||
} // namespace onert | ||
|
||
#endif // __ONERT_EXEC_MINMAX_DATA_H__ |
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.