Skip to content

Commit

Permalink
Split codes into core snippets for small PR.
Browse files Browse the repository at this point in the history
Split codes into core snippets for small PR.

ONE-DCO-1.0-Signed-off-by: Banseok Lee <[email protected]>
  • Loading branch information
BLee-bot committed Nov 4, 2024
1 parent 535e697 commit 4eacb30
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 147 deletions.
85 changes: 0 additions & 85 deletions compiler/record-hessian/src/RecordHessian.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,88 +104,3 @@ void verifyTypeShape(const luci::CircleInput *input_node, const DataType &dtype,
}

} // namespace

namespace record_hessian
{

void RecordHessian::initialize(luci::Module *module)
{
// Create and initialize interpreters and observers

_module = module;

auto interpreter = std::make_unique<luci_interpreter::Interpreter>(module);
auto observer = std::make_unique<HessianObserver>();

interpreter->attachObserver(observer.get());

_observer = std::move(observer);
_interpreter = std::move(interpreter);
}

std::unique_ptr<HessianMap> RecordHessian::profileData(const std::string &input_data_path)
{
try
{
dio::hdf5::HDF5Importer importer(input_data_path);
importer.importGroup("value");

bool is_raw_data = importer.isRawData();

const auto num_records = importer.numData();
if (num_records == 0)
throw std::runtime_error("RecordHessian: The input data file does not contain any record.");

const auto input_nodes = loco::input_nodes(_module->graph());
const auto num_inputs = input_nodes.size();

for (int32_t record_idx = 0; record_idx < num_records; record_idx++)
{
if (num_inputs != static_cast<uint32_t>(importer.numInputs(record_idx)))
throw std::runtime_error("RecordHessian: Wrong number of inputs.");

std::cout << "Recording " << record_idx << "'th data for hessian." << std::endl;

for (uint32_t input_idx = 0; input_idx < num_inputs; input_idx++)
{
const auto *input_node = loco::must_cast<const luci::CircleInput *>(input_nodes[input_idx]);
assert(input_node->index() == input_idx);
checkInputDimension(input_node);
std::vector<char> input_data(getTensorSize(input_node));

if (!is_raw_data)
{
DataType dtype;
Shape shape;
importer.readTensor(record_idx, input_idx, &dtype, &shape, input_data.data(),
input_data.size());

// Check the type and the shape of the input data is valid
verifyTypeShape(input_node, dtype, shape);
}
else
{
// Skip type/shape check for raw data
importer.readTensor(record_idx, input_idx, input_data.data(), input_data.size());
}

// TODO: Input data is copied twice (file -> buffer (input_data) -> interpreter inputs)
// We can redcue the copy by directly writing data from file to interpreter inputs
getInterpreter()->writeInputTensor(input_node, input_data.data(), input_data.size());
}

getInterpreter()->interpret();
}

std::cout << "Recording finished. Number of recorded data: " << num_records << std::endl;
}
catch (const H5::Exception &e)
{
H5::Exception::printErrorStack();
throw std::runtime_error("RecordHessian: HDF5 error occurred.");
}

return getObserver()->hessianData();
}

} // namespace record_hessian
62 changes: 0 additions & 62 deletions compiler/record-hessian/src/RecordHessian.test.cpp

This file was deleted.

0 comments on commit 4eacb30

Please sign in to comment.