diff --git a/include/aidge/hook/ExecTime.hpp b/include/aidge/hook/ExecTime.hpp deleted file mode 100644 index 0964d9575b7ad345d5e07c9f19c7e56a3b69c813..0000000000000000000000000000000000000000 --- a/include/aidge/hook/ExecTime.hpp +++ /dev/null @@ -1,59 +0,0 @@ -/** - * \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 diff --git a/include/aidge/hook/Hook.hpp b/include/aidge/hook/Hook.hpp deleted file mode 100644 index 5edf231d51f913f58351b4817e145b5f48953ddd..0000000000000000000000000000000000000000 --- a/include/aidge/hook/Hook.hpp +++ /dev/null @@ -1,41 +0,0 @@ -/** - * \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_ */ diff --git a/include/aidge/hook/OutputRange.hpp b/include/aidge/hook/OutputRange.hpp deleted file mode 100644 index 355f4aaa15a6bcd77d99ec2dad344a45f8f9edc0..0000000000000000000000000000000000000000 --- a/include/aidge/hook/OutputRange.hpp +++ /dev/null @@ -1,74 +0,0 @@ -/** - * \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 diff --git a/include/aidge/operator/Add.hpp b/include/aidge/operator/Add.hpp index daf50771703d6608dbbe90364aac8667aefbdd1d..f96996079b9e89f80c78b8e409830369480705a8 100644 --- a/include/aidge/operator/Add.hpp +++ b/include/aidge/operator/Add.hpp @@ -18,8 +18,9 @@ #include "aidge/operator/OperatorTensor.hpp" #include "aidge/graph/Node.hpp" -#include "aidge/utils/Types.h" #include "aidge/utils/ErrorHandling.hpp" +#include "aidge/utils/Types.h" +#include "aidge/utils/Registrar.hpp" namespace Aidge { diff --git a/include/aidge/operator/Operator.hpp b/include/aidge/operator/Operator.hpp index 1cfb0d92eb72d4fee76cf3117c7ec4072966ff3e..a799153e1db5eb83964ed06dd3bc0fb06da64de8 100644 --- a/include/aidge/operator/Operator.hpp +++ b/include/aidge/operator/Operator.hpp @@ -28,7 +28,7 @@ #include "aidge/data/Data.hpp" #include "aidge/utils/Attributes.hpp" #include "aidge/utils/Types.h" -#include "aidge/hook/Hook.hpp" + #ifdef PYBIND namespace py = pybind11; @@ -51,7 +51,6 @@ class Operator : public std::enable_shared_from_this<Operator> { protected: std::shared_ptr<OperatorImpl> mImpl; // implementation of the operator std::shared_ptr<DynamicAttributes> mInheritedAttrs; - std::map<std::string, std::shared_ptr<Hook>> mHooks; private: std::string mType; @@ -82,9 +81,7 @@ public: 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. // 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) { mInheritedAttrs = attrs; return shared_from_this(); @@ -121,14 +118,6 @@ public: 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; - 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 diff --git a/python_binding/operator/pybind_Operator.cpp b/python_binding/operator/pybind_Operator.cpp index 6ffbdd007b9f929ccac18de12f2319dcd68b1eda..e22f88687eff6856ce57fab6621781ffc86873b4 100644 --- a/python_binding/operator/pybind_Operator.cpp +++ b/python_binding/operator/pybind_Operator.cpp @@ -60,8 +60,6 @@ void init_Operator(py::module& m){ .def("set_impl", &Operator::setImpl, py::arg("implementation"), py::keep_alive<1, 2>()) .def("type", &Operator::type) .def("get_impl", &Operator::getImpl) - .def("get_hook", &Operator::getHook) - .def("add_hook", &Operator::addHook) .def_property_readonly("attr", &Operator::attributes) .def("set_back_edges", &Operator::setBackEdges, py::arg("input_indexes")) .def("is_back_edge", &Operator::isBackEdge, py::arg("input_index")) diff --git a/src/operator/Operator.cpp b/src/operator/Operator.cpp index f15a7dc3899a7bc864e8e76ff0946fb70584bf05..bd09e9d1297ec612b08634f59bfe33f0802ef3fd 100644 --- a/src/operator/Operator.cpp +++ b/src/operator/Operator.cpp @@ -65,20 +65,14 @@ void Aidge::Operator::resetConsummerProducer(){ mImpl->prodConso()->resetConsummerProducer(); } -void Aidge::Operator::runHooks() const { - for (auto& hook : mHooks) { - hook.second->call(); - } -} void Aidge::Operator::forward() { AIDGE_ASSERT(mImpl != nullptr, "forward(): an implementation is required for {}!", type()); mImpl->forward(); - runHooks(); } void Aidge::Operator::backward() { 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) { diff --git a/src/operator/Producer.cpp b/src/operator/Producer.cpp index fdba4ac2e22d857a31779df2e5ff789c3eb92f5c..3d48b88ab400596d68cbfa34502e795766ff94f0 100644 --- a/src/operator/Producer.cpp +++ b/src/operator/Producer.cpp @@ -92,8 +92,6 @@ void Aidge::Producer_Op::forward() { if (!backend().empty()) { mImpl->forward(); } - - runHooks(); } void Aidge::Producer_Op::setOutput(const Aidge::IOIndex_t outputIdx, const std::shared_ptr<Aidge::Data>& data) const {