Skip to content

Commit

Permalink
This commit introduce hessian observer.
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 committed Nov 4, 2024
1 parent ccf6510 commit 1b54938
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
45 changes: 45 additions & 0 deletions compiler/record-hessian/include/record-hessian/HessianObserver.h
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.
*/

#ifndef __RECORD_HESSIAN_HESSIANOBSERVER_H__
#define __RECORD_HESSIAN_HESSIANOBSERVER_H__

#include "record-hessian/HessianComputer.h"

#include <luci_interpreter/Interpreter.h>
#include <luci_interpreter/core/Tensor.h>
#include <luci/IR/CircleNodes.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(); }

private:
HessianComputer _hessian_computer;
};

} // namespace record_hessian

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

#include <luci/IR/CircleOpcode.h>
#include <luci/IR/CircleNodes.h>

using DataType = luci_interpreter::DataType;

namespace record_hessian
{

void HessianObserver::postTensorWrite(const luci::CircleNode *node,
const luci_interpreter::Tensor *tensor)
{

auto node_outputs = loco::succs(node);
for (auto node : node_outputs)
{
auto _node = dynamic_cast<luci::CircleNode *>(node);
// TODO : ADD TCONV/DepthCONV cases
if (_node->opcode() == luci::CircleOpcode::FULLY_CONNECTED ||
_node->opcode() == luci::CircleOpcode::CONV_2D)
{
_hessian_computer.recordHessian(_node, tensor);
}
}
}

} // namespace record_hessian

0 comments on commit 1b54938

Please sign in to comment.