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 HessianObserver. #14292

Merged
merged 5 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions compiler/record-hessian/include/record-hessian/HessianObserver.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* 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_HESSIANOBSERVER_H__
#define __RECORD_HESSIAN_HESSIANOBSERVER_H__

#include "record-hessian/HessianComputer.h"

namespace record_hessian
{

class HessianObserver : public luci_interpreter::ExecutionObserver
{
public:
HessianObserver() = default;

void postTensorWrite(const luci::CircleNode *node,
const luci_interpreter::Tensor *tensor) override;

std::unique_ptr<HessianMap> hessianData() { return _hessian_computer.getMap(); }
BLee-bot marked this conversation as resolved.
Show resolved Hide resolved

private:
HessianComputer _hessian_computer;
};

} // namespace record_hessian

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

using DataType = luci_interpreter::DataType;
seanshpark marked this conversation as resolved.
Show resolved Hide resolved

namespace record_hessian
{

void HessianObserver::postTensorWrite(const luci::CircleNode *node,
const luci_interpreter::Tensor *tensor)
{
BLee-bot marked this conversation as resolved.
Show resolved Hide resolved

BLee-bot marked this conversation as resolved.
Show resolved Hide resolved
auto node_outputs = loco::succs(node);
for (auto node_output : node_outputs)
{
auto cur_node = dynamic_cast<luci::CircleNode *>(node_output);
assert(cur_node != nullptr);
BLee-bot marked this conversation as resolved.
Show resolved Hide resolved
// TODO : ADD TCONV/DepthCONV cases
if (cur_node->opcode() == luci::CircleOpcode::FULLY_CONNECTED ||
cur_node->opcode() == luci::CircleOpcode::CONV_2D)
{
_hessian_computer.recordHessian(cur_node, tensor);
}
}
}

} // namespace record_hessian