Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[record-hessian] Introduce RecordHessian. #14295

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
50 changes: 50 additions & 0 deletions compiler/record-hessian/include/record-hessian/RecordHessian.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* 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 __RECORD_HESSIAN_RECORD_HESSIAN_H__
#define __RECORD_HESSIAN_RECORD_HESSIAN_H__

#include "record-hessian/HessianObserver.h"

#include <luci/IR/Module.h>
#include <luci_interpreter/Interpreter.h>

namespace record_hessian
{

class RecordHessian
{
public:
RecordHessian() {}

void initialize(luci::Module *module);
std::unique_ptr<HessianMap> profileData(const std::string &input_data_path);

private:
luci_interpreter::Interpreter *getInterpreter() const { return _interpreter.get(); }

// Never return nullptr
HessianObserver *getObserver() const { return _observer.get(); }

luci::Module *_module = nullptr;

std::unique_ptr<luci_interpreter::Interpreter> _interpreter;
std::unique_ptr<HessianObserver> _observer;
};

} // namespace record_hessian

#endif // __RECORD_HESSIAN_RECORD_HESSIAN_H__
57 changes: 57 additions & 0 deletions compiler/record-hessian/src/RecordHessian.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* 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 "record-hessian/RecordHessian.h"
#include "record-hessian/HessianObserver.h"

#include <dio_hdf5/HDF5Importer.h>

#include <iostream>

using Shape = std::vector<loco::Dimension>;

namespace record_hessian
{

void RecordHessian::initialize(luci::Module *module)
BLee-bot marked this conversation as resolved.
Show resolved Hide resolved
{
// 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());
}

std::unique_ptr<HessianMap> RecordHessian::profileData(const std::string &input_data_path)
{
try
{
dio::hdf5::HDF5Importer importer(input_data_path);
// To be implemented
}
catch (const H5::Exception &e)
{
H5::Exception::printErrorStack();
throw std::runtime_error("RecordHessian: HDF5 error occurred.");
}

return getObserver()->hessianData();
}

} // namespace record_hessian