Skip to content
Snippets Groups Projects
Commit e50a80d0 authored by Maxence Naud's avatar Maxence Naud
Browse files

Remove unused mHook attribute in Operator

Add missing include to Add.hpp
parent 2767bec3
No related branches found
No related tags found
No related merge requests found
/**
* \file execTime.hpp
* \brief execTime structure
* \version file 1.0.0
* \date Creation 27 June 2023
* \date 27 June 2023
* \par ChangeLog
* \par
* v1.0.0, 27 June 2023<br>
* - Initial version.
* \author mn271187, ik243221
* \copyright
* Copyright (c) 2023 CEA, LIST, Embedded Artificial Intelligence Laboratory. All
* rights reserved.
*/
#ifndef execTime_H_
#define execTime_H_
#include "aidge/operator/Operator.hpp"
#include "aidge/hook/Hook.hpp"
#include <memory>
#include <chrono>
#include <vector>
namespace Aidge {
class ExecTime : public Hook {
private:
std::vector<std::chrono::high_resolution_clock::time_point> registeredTimes = std::vector<std::chrono::high_resolution_clock::time_point>();
public:
ExecTime(const std::shared_ptr<Operator> op) : Hook(op) {}
~ExecTime() = default;
void call() override final {
registeredTimes.push_back(std::chrono::high_resolution_clock::now());
}
static std::shared_ptr<ExecTime> create(const std::shared_ptr<Operator> op)
{
return std::make_shared<ExecTime>(op);
}
std::vector<std::chrono::high_resolution_clock::time_point> getTimes() {
return registeredTimes;
}
std::chrono::high_resolution_clock::time_point getTime(size_t idx) {
return registeredTimes[idx];
}
};
namespace {
static Registrar<Hook> registrarHook_ExecTime({"execution_time"}, Aidge::ExecTime::create);
}
}
#endif /* execTime_H_ */
\ No newline at end of file
/**
* \file Hook.hpp
* \brief Hook structure
* \version file 1.0.0
* \date Creation 27 June 2023
* \date 27 June 2023
* \par ChangeLog
* \par
* v1.0.0, 27 June 2023<br>
* - Initial version.
* \author mn271187, ik243221
* \copyright
* Copyright (c) 2023 CEA, LIST, Embedded Artificial Intelligence Laboratory. All
* rights reserved.
*/
#ifndef Hook_H_
#define Hook_H_
#include "aidge/utils/Attributes.hpp"
#include "aidge/utils/Registrar.hpp"
#include <memory>
namespace Aidge {
class Operator;
class Hook : public Registrable<Hook, std::tuple<std::string>, std::function<std::shared_ptr<Hook>(const std::shared_ptr<Operator>)>> {
//class Hook : public Registrable<Hook, std::tuple<std::string>, std::function<std::shared_ptr<Hook>(const std::shared_ptr<Operator>)>>{
protected:
const std::shared_ptr<Operator> mOperator;
public:
Hook(std::shared_ptr<Operator> op) : mOperator(op) {}
virtual ~Hook() = default;
virtual void call() = 0;
};
}
#endif /* Hook_H_ */
/**
* \file execTime.hpp
* \brief execTime structure
* \version file 1.0.0
* \date Creation 27 June 2023
* \date 27 June 2023
* \par ChangeLog
* \par
* v1.0.0, 27 June 2023<br>
* - Initial version.
* \author ik243221
* \copyright
* Copyright (c) 2023 CEA, LIST, Embedded Artificial Intelligence Laboratory. All
* rights reserved.
*/
#ifndef AIDGE_CORE_HOOK_OUTPUTRANGE_H_
#define AIDGE_CORE_HOOK_OUTPUTRANGE_H_
#include "aidge/operator/Operator.hpp"
#include "aidge/hook/Hook.hpp"
#include <memory>
#include <chrono>
#include <vector>
#include <cmath>
namespace Aidge {
class OutputRange : public Hook {
private:
std::vector<float> registeredOutputs = std::vector<float>();
public:
OutputRange(const std::shared_ptr<Operator> op) : Hook(op) {}
~OutputRange() = default;
void call() override final {
//std::cout << "call() outputRange hook " << std::endl;
//this assumes there is only 1 output possible
std::shared_ptr<Tensor> tensor = mOperator->getOutput(0);
//tensor->print();
//std::cout << "call() outputRange hook : tensor printed" << std::endl;
float max_value = 0.;
float * casted_tensor = static_cast<float *>(tensor->getImpl()->rawPtr());
//find the absolute max value in the tensor, save it to registered outputs
for(std::size_t i = 0; i < tensor->size(); ++i) {
//std::cout << "call() outputRange hook : casted_tensor[i] = " << casted_tensor[i] << std::endl;
if(std::abs(casted_tensor[i]) > max_value){
max_value = std::abs(casted_tensor[i]);
}
}
//std::cout << "call() outputRange hook : max_value = " << max_value << std::endl;
registeredOutputs.push_back(max_value);
}
static std::shared_ptr<OutputRange> create(const std::shared_ptr<Operator> op)
{
return std::make_shared<OutputRange>(op);
}
std::vector<float> getOutputs() {
return registeredOutputs;
}
float getOutput(size_t idx) {
return registeredOutputs[idx];
}
};
namespace {
static Registrar<Hook> registrarHook_OutputRange({"output_range"}, Aidge::OutputRange::create);
}
}
#endif /* outputRange_H_ */
\ No newline at end of file
...@@ -18,8 +18,9 @@ ...@@ -18,8 +18,9 @@
#include "aidge/operator/OperatorTensor.hpp" #include "aidge/operator/OperatorTensor.hpp"
#include "aidge/graph/Node.hpp" #include "aidge/graph/Node.hpp"
#include "aidge/utils/Types.h"
#include "aidge/utils/ErrorHandling.hpp" #include "aidge/utils/ErrorHandling.hpp"
#include "aidge/utils/Types.h"
#include "aidge/utils/Registrar.hpp"
namespace Aidge { namespace Aidge {
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
#include "aidge/data/Data.hpp" #include "aidge/data/Data.hpp"
#include "aidge/utils/Attributes.hpp" #include "aidge/utils/Attributes.hpp"
#include "aidge/utils/Types.h" #include "aidge/utils/Types.h"
#include "aidge/hook/Hook.hpp"
#ifdef PYBIND #ifdef PYBIND
namespace py = pybind11; namespace py = pybind11;
...@@ -51,7 +51,6 @@ class Operator : public std::enable_shared_from_this<Operator> { ...@@ -51,7 +51,6 @@ class Operator : public std::enable_shared_from_this<Operator> {
protected: protected:
std::shared_ptr<OperatorImpl> mImpl; // implementation of the operator std::shared_ptr<OperatorImpl> mImpl; // implementation of the operator
std::shared_ptr<DynamicAttributes> mInheritedAttrs; std::shared_ptr<DynamicAttributes> mInheritedAttrs;
std::map<std::string, std::shared_ptr<Hook>> mHooks;
private: private:
std::string mType; std::string mType;
...@@ -82,9 +81,7 @@ public: ...@@ -82,9 +81,7 @@ public:
mImpl = nullptr; mImpl = nullptr;
// Implementation is never cloned. It is up to the non-abstract Operator copy-constructor to create a new implementation matching the copied Operator implementation. // Implementation is never cloned. It is up to the non-abstract Operator copy-constructor to create a new implementation matching the copied Operator implementation.
// See https://gitlab.eclipse.org/eclipse/aidge/aidge_core/-/merge_requests/8#note_1214050 for the discussion. // See https://gitlab.eclipse.org/eclipse/aidge/aidge_core/-/merge_requests/8#note_1214050 for the discussion.
// Hooks are not copied.
} }
std::shared_ptr<Operator> operator()(std::shared_ptr<DynamicAttributes> attrs) { std::shared_ptr<Operator> operator()(std::shared_ptr<DynamicAttributes> attrs) {
mInheritedAttrs = attrs; mInheritedAttrs = attrs;
return shared_from_this(); return shared_from_this();
...@@ -121,14 +118,6 @@ public: ...@@ -121,14 +118,6 @@ public:
virtual void setOutput(const IOIndex_t outputIdx, const std::shared_ptr<Data>& data) const = 0; virtual void setOutput(const IOIndex_t outputIdx, const std::shared_ptr<Data>& data) const = 0;
virtual std::shared_ptr<Data> getRawOutput(const IOIndex_t outputIdx) const = 0; virtual std::shared_ptr<Data> getRawOutput(const IOIndex_t outputIdx) const = 0;
std::shared_ptr<Hook> getHook(const std::string& hookName) {
return mHooks[hookName];
}
void addHook(const std::string& hookName) {
mHooks.insert(std::pair<std::string, std::shared_ptr<Hook>>(hookName,Registrar<Hook>::create({hookName})(shared_from_this())));
}
void runHooks() const;
/////////////////////////////////////////////////////// ///////////////////////////////////////////////////////
// IMPLEMENTATION // IMPLEMENTATION
......
...@@ -60,8 +60,6 @@ void init_Operator(py::module& m){ ...@@ -60,8 +60,6 @@ void init_Operator(py::module& m){
.def("set_impl", &Operator::setImpl, py::arg("implementation"), py::keep_alive<1, 2>()) .def("set_impl", &Operator::setImpl, py::arg("implementation"), py::keep_alive<1, 2>())
.def("type", &Operator::type) .def("type", &Operator::type)
.def("get_impl", &Operator::getImpl) .def("get_impl", &Operator::getImpl)
.def("get_hook", &Operator::getHook)
.def("add_hook", &Operator::addHook)
.def_property_readonly("attr", &Operator::attributes) .def_property_readonly("attr", &Operator::attributes)
.def("set_back_edges", &Operator::setBackEdges, py::arg("input_indexes")) .def("set_back_edges", &Operator::setBackEdges, py::arg("input_indexes"))
.def("is_back_edge", &Operator::isBackEdge, py::arg("input_index")) .def("is_back_edge", &Operator::isBackEdge, py::arg("input_index"))
......
...@@ -65,20 +65,14 @@ void Aidge::Operator::resetConsummerProducer(){ ...@@ -65,20 +65,14 @@ void Aidge::Operator::resetConsummerProducer(){
mImpl->prodConso()->resetConsummerProducer(); mImpl->prodConso()->resetConsummerProducer();
} }
void Aidge::Operator::runHooks() const {
for (auto& hook : mHooks) {
hook.second->call();
}
}
void Aidge::Operator::forward() { void Aidge::Operator::forward() {
AIDGE_ASSERT(mImpl != nullptr, "forward(): an implementation is required for {}!", type()); AIDGE_ASSERT(mImpl != nullptr, "forward(): an implementation is required for {}!", type());
mImpl->forward(); mImpl->forward();
runHooks();
} }
void Aidge::Operator::backward() { void Aidge::Operator::backward() {
AIDGE_ASSERT(mImpl != nullptr, "backward(): an implementation is required for {}!", type()); AIDGE_ASSERT(mImpl != nullptr, "backward(): an implementation is required for {}!", type());
mImpl->backward(); mImpl->backward();
} }
void Aidge::Operator::setBackend(const std::vector<std::pair<std::string, DeviceIdx_t>>& backends) { void Aidge::Operator::setBackend(const std::vector<std::pair<std::string, DeviceIdx_t>>& backends) {
......
...@@ -92,8 +92,6 @@ void Aidge::Producer_Op::forward() { ...@@ -92,8 +92,6 @@ void Aidge::Producer_Op::forward() {
if (!backend().empty()) { if (!backend().empty()) {
mImpl->forward(); mImpl->forward();
} }
runHooks();
} }
void Aidge::Producer_Op::setOutput(const Aidge::IOIndex_t outputIdx, const std::shared_ptr<Aidge::Data>& data) const { void Aidge::Producer_Op::setOutput(const Aidge::IOIndex_t outputIdx, const std::shared_ptr<Aidge::Data>& data) const {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment