Skip to content

Commit

Permalink
[record-hessian] Introduce HessianObserver. (#14292)
Browse files Browse the repository at this point in the history
This commit introduce hessian observer.

ONE-DCO-1.0-Signed-off-by: Banseok Lee <[email protected]>
  • Loading branch information
BLee-bot authored Nov 4, 2024
1 parent 8c470d8 commit 85bcba8
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 0 deletions.
46 changes: 46 additions & 0 deletions compiler/record-hessian/include/record-hessian/HessianObserver.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* 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"

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

#include <memory>

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(); }

private:
HessianComputer _hessian_computer;
};

} // namespace record_hessian

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

namespace record_hessian
{

void HessianObserver::postTensorWrite(const luci::CircleNode *node,
const luci_interpreter::Tensor *tensor)
{
assert(node != nullptr);
assert(tensor != nullptr);

auto node_outputs = loco::succs(node);
for (auto node_output : node_outputs)
{
auto cur_node = dynamic_cast<luci::CircleNode *>(node_output);
if (cur_node == nullptr)
{
throw std::runtime_error("Record Hessian: node output shouldn't be null.");
}
// 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

0 comments on commit 85bcba8

Please sign in to comment.