From c0a3c2605e440fbb456e70e73fc8944540a2607f Mon Sep 17 00:00:00 2001 From: cmoineau <cyril.moineau@cea.fr> Date: Tue, 5 Sep 2023 13:15:36 +0000 Subject: [PATCH] Remove the consumer/producer system from the forward method. --- include/aidge/operator/AddImpl.hpp | 6 +++- include/aidge/operator/AvgPoolingImpl.hpp | 3 +- include/aidge/operator/BatchNormImpl.hpp | 3 +- include/aidge/operator/ConvDepthWiseImpl.hpp | 3 +- include/aidge/operator/ConvImpl.hpp | 3 +- include/aidge/operator/FCImpl.hpp | 4 +-- include/aidge/operator/LeakyReLUImpl.hpp | 4 +-- include/aidge/operator/ProducerImpl.hpp | 3 +- include/aidge/operator/ReLUImpl.hpp | 4 +-- include/aidge/operator/SoftmaxImpl.hpp | 4 +-- src/operator/AddImpl.cpp | 35 +++++++++++--------- src/operator/AvgPoolingImpl.cpp | 15 ++++----- src/operator/BatchNormImpl.cpp | 12 ++++--- src/operator/ConvDepthWiseImpl.cpp | 15 ++++----- src/operator/ConvImpl.cpp | 15 ++++----- src/operator/FCImpl.cpp | 23 ++++++------- src/operator/LeakyReLUImpl.cpp | 9 +++-- src/operator/ProducerImpl.cpp | 5 +-- src/operator/ReLUImpl.cpp | 8 ++--- src/operator/SoftmaxImpl.cpp | 7 ++++ 20 files changed, 99 insertions(+), 82 deletions(-) diff --git a/include/aidge/operator/AddImpl.hpp b/include/aidge/operator/AddImpl.hpp index 4df4f18a..6e1cd03a 100644 --- a/include/aidge/operator/AddImpl.hpp +++ b/include/aidge/operator/AddImpl.hpp @@ -97,6 +97,7 @@ class AddImpl_cpu : public OperatorImpl { assert(outputIdx < mNbProducedData.size()); return mNbProducedData[outputIdx]; } + void updateConsummerProducer() override final; void forward() { // nothing @@ -130,6 +131,7 @@ class AddImpl_cpu<1> : public OperatorImpl { NbElts_t getNbConsumedData(const IOIndex_t /*inputIdx*/) const override final; NbElts_t getNbProducedData(const IOIndex_t /*outputIdx*/) const override final; + void updateConsummerProducer() override final; void forward(); @@ -161,6 +163,7 @@ class AddImpl_cpu<2> : public OperatorImpl { NbElts_t getNbConsumedData(const IOIndex_t inputIdx) const override final; NbElts_t getNbProducedData(const IOIndex_t /*outputIdx*/) const override final; + void updateConsummerProducer() override final; void forward(); @@ -191,6 +194,7 @@ class AddImpl_cpu<3> : public OperatorImpl { NbElts_t getNbConsumedData(const IOIndex_t inputIdx) const override final; NbElts_t getNbProducedData(const IOIndex_t outputIdx) const override final; + void updateConsummerProducer() override final; void forward(); @@ -204,4 +208,4 @@ static Registrar<Add_Op<3>> registrarAddImpl3I_cpu("cpu", Aidge::AddImpl_cpu<3>: } // namespace } // namespace Aidge -#endif /* AIDGE_CPU_OPERATOR_ADDIMPL_H_ */ \ No newline at end of file +#endif /* AIDGE_CPU_OPERATOR_ADDIMPL_H_ */ diff --git a/include/aidge/operator/AvgPoolingImpl.hpp b/include/aidge/operator/AvgPoolingImpl.hpp index 429d4285..8373cb84 100644 --- a/include/aidge/operator/AvgPoolingImpl.hpp +++ b/include/aidge/operator/AvgPoolingImpl.hpp @@ -54,6 +54,7 @@ class AvgPoolingImpl2D_cpu : public OperatorImpl { NbElts_t getRequiredMemory(const IOIndex_t /*outputIdx*/, const std::vector<DimSize_t> &inputsSize) const override final; NbElts_t getNbConsumedData(const IOIndex_t inputIdx) const override final; NbElts_t getNbProducedData(const IOIndex_t outputIdx) const override final; + void updateConsummerProducer() override final; void forward(); @@ -66,4 +67,4 @@ static Registrar<AvgPooling_Op<2>> registrarAvgPoolingImpl2D_cpu("cpu", Aidge::A } // namespace } // namespace Aidge -#endif /* AIDGE_CPU_OPERATOR_AVGPOOLINGIMPL_H_ */ \ No newline at end of file +#endif /* AIDGE_CPU_OPERATOR_AVGPOOLINGIMPL_H_ */ diff --git a/include/aidge/operator/BatchNormImpl.hpp b/include/aidge/operator/BatchNormImpl.hpp index 567a1580..d9f25b4a 100644 --- a/include/aidge/operator/BatchNormImpl.hpp +++ b/include/aidge/operator/BatchNormImpl.hpp @@ -69,6 +69,7 @@ class BatchNormImpl2D_cpu : public OperatorImpl { NbElts_t getRequiredMemory(const IOIndex_t /*outputIdx*/, const std::vector<DimSize_t> &inputsSize) const override final; NbElts_t getNbConsumedData(const IOIndex_t inputIdx) const override final; NbElts_t getNbProducedData(const IOIndex_t outputIdx) const override final; + void updateConsummerProducer() override final; void forward(); @@ -81,4 +82,4 @@ static Registrar<BatchNorm_Op<2>> registrarBatchNormImpl2D_cpu("cpu", Aidge::Bat } // namespace } // namespace Aidge -#endif /* AIDGE_CPU_OPERATOR_BATCHNORMIMPL_H_ */ \ No newline at end of file +#endif /* AIDGE_CPU_OPERATOR_BATCHNORMIMPL_H_ */ diff --git a/include/aidge/operator/ConvDepthWiseImpl.hpp b/include/aidge/operator/ConvDepthWiseImpl.hpp index e54025db..0d21c676 100644 --- a/include/aidge/operator/ConvDepthWiseImpl.hpp +++ b/include/aidge/operator/ConvDepthWiseImpl.hpp @@ -56,6 +56,7 @@ class ConvDepthWiseImpl2D_cpu : public OperatorImpl { NbElts_t getRequiredMemory(const IOIndex_t /*outputIdx*/, const std::vector<DimSize_t> &/*inputsSize*/) const override final; NbElts_t getNbConsumedData(const IOIndex_t inputIdx) const override final; NbElts_t getNbProducedData(const IOIndex_t outputIdx) const override final; + void updateConsummerProducer() override final; void forward(); @@ -68,4 +69,4 @@ static Registrar<ConvDepthWise_Op<2>> registrarConvDepthWiseImpl2D_cpu("cpu", Ai } // namespace } // namespace Aidge -#endif /* AIDGE_CPU_OPERATOR_CONVDEPTHWISEIMPL_H_ */ \ No newline at end of file +#endif /* AIDGE_CPU_OPERATOR_CONVDEPTHWISEIMPL_H_ */ diff --git a/include/aidge/operator/ConvImpl.hpp b/include/aidge/operator/ConvImpl.hpp index d6216cde..1f3dffe4 100644 --- a/include/aidge/operator/ConvImpl.hpp +++ b/include/aidge/operator/ConvImpl.hpp @@ -56,6 +56,7 @@ class ConvImpl2D_cpu : public OperatorImpl { NbElts_t getRequiredMemory(const IOIndex_t /*outputIdx*/, const std::vector<DimSize_t> &/*inputsSize*/) const override final; NbElts_t getNbConsumedData(const IOIndex_t inputIdx) const override final; NbElts_t getNbProducedData(const IOIndex_t outputIdx) const override final; + void updateConsummerProducer() override final; void forward(); @@ -68,4 +69,4 @@ static Registrar<Conv_Op<2>> registrarConvImpl2D_cpu("cpu", Aidge::ConvImpl2D_cp } // namespace } // namespace Aidge -#endif /* AIDGE_CPU_OPERATOR_CONVIMPL_H_ */ \ No newline at end of file +#endif /* AIDGE_CPU_OPERATOR_CONVIMPL_H_ */ diff --git a/include/aidge/operator/FCImpl.hpp b/include/aidge/operator/FCImpl.hpp index 9c577216..c69cc0b0 100644 --- a/include/aidge/operator/FCImpl.hpp +++ b/include/aidge/operator/FCImpl.hpp @@ -50,7 +50,7 @@ class FCImpl_cpu : public OperatorImpl { NbElts_t getRequiredMemory(const IOIndex_t /*outputIdx*/, const std::vector<DimSize_t> &/*inputsSize*/) const override final; NbElts_t getNbConsumedData(const IOIndex_t inputIdx) const override final; NbElts_t getNbProducedData(const IOIndex_t outputIdx) const override final; - + void updateConsummerProducer() override final; void forward(); void backward(); @@ -61,4 +61,4 @@ static Registrar<FC_Op> registrarFCImpl_cpu("cpu", Aidge::FCImpl_cpu::create); } } // namespace Aidge -#endif /* AIDGE_CPU_OPERATOR_FCIMPL_H_ */ \ No newline at end of file +#endif /* AIDGE_CPU_OPERATOR_FCIMPL_H_ */ diff --git a/include/aidge/operator/LeakyReLUImpl.hpp b/include/aidge/operator/LeakyReLUImpl.hpp index b817306e..abe167be 100644 --- a/include/aidge/operator/LeakyReLUImpl.hpp +++ b/include/aidge/operator/LeakyReLUImpl.hpp @@ -49,7 +49,7 @@ class LeakyReLUImpl_cpu : public OperatorImpl { NbElts_t getRequiredMemory(const IOIndex_t /*outputIdx*/, const std::vector<DimSize_t>& /*inputsSize*/) const override final; NbElts_t getNbConsumedData(const IOIndex_t inputIdx) const override final; NbElts_t getNbProducedData(const IOIndex_t outputIdx) const override final; - + void updateConsummerProducer() override final; void forward(); void backward(); @@ -60,4 +60,4 @@ static Registrar<LeakyReLU_Op> registrarLeakyReLUImpl_cpu("cpu", Aidge::LeakyReL } } // namespace Aidge -#endif /* AIDGE_CPU_OPERATOR_LEAKYRELUIMPL_H_ */ \ No newline at end of file +#endif /* AIDGE_CPU_OPERATOR_LEAKYRELUIMPL_H_ */ diff --git a/include/aidge/operator/ProducerImpl.hpp b/include/aidge/operator/ProducerImpl.hpp index ee3d3d72..032172db 100644 --- a/include/aidge/operator/ProducerImpl.hpp +++ b/include/aidge/operator/ProducerImpl.hpp @@ -37,6 +37,7 @@ class ProducerImpl_cpu : public OperatorImpl { NbElts_t getRequiredMemory(const IOIndex_t /*outputIdx*/, const std::vector<DimSize_t> &/*inputsSize*/) const override final; NbElts_t getNbConsumedData(const IOIndex_t inputIdx) const override final; NbElts_t getNbProducedData(const IOIndex_t outputIdx) const override final; + void updateConsummerProducer() override final; void forward(); @@ -48,4 +49,4 @@ static Registrar<Producer_Op> registrarProducer1DImpl_cpu("cpu", Aidge::Producer } // namespace } // namespace Aidge -#endif /* AIDGE_CPU_OPERATOR_PRODUCERIMPL_H_ */ \ No newline at end of file +#endif /* AIDGE_CPU_OPERATOR_PRODUCERIMPL_H_ */ diff --git a/include/aidge/operator/ReLUImpl.hpp b/include/aidge/operator/ReLUImpl.hpp index b28da884..537bdeea 100644 --- a/include/aidge/operator/ReLUImpl.hpp +++ b/include/aidge/operator/ReLUImpl.hpp @@ -49,7 +49,7 @@ class ReLUImpl_cpu : public OperatorImpl { NbElts_t getRequiredMemory(const IOIndex_t /*outputIdx*/, const std::vector<DimSize_t>& /*inputsSize*/) const override final; NbElts_t getNbConsumedData(const IOIndex_t inputIdx) const override final; NbElts_t getNbProducedData(const IOIndex_t outputIdx) const override final; - + void updateConsummerProducer() override final; void forward(); void backward(); @@ -60,4 +60,4 @@ static Registrar<ReLU_Op> registrarReLUImpl_cpu("cpu", Aidge::ReLUImpl_cpu::crea } } // namespace Aidge -#endif /* AIDGE_CPU_OPERATOR_RELUIMPL_H_ */ \ No newline at end of file +#endif /* AIDGE_CPU_OPERATOR_RELUIMPL_H_ */ diff --git a/include/aidge/operator/SoftmaxImpl.hpp b/include/aidge/operator/SoftmaxImpl.hpp index 7641a355..08567ab9 100644 --- a/include/aidge/operator/SoftmaxImpl.hpp +++ b/include/aidge/operator/SoftmaxImpl.hpp @@ -49,7 +49,7 @@ class SoftmaxImpl_cpu : public OperatorImpl { NbElts_t getRequiredMemory(const IOIndex_t /*outputIdx*/, const std::vector<DimSize_t>& /*inputsSize*/) const override final; NbElts_t getNbConsumedData(const IOIndex_t inputIdx) const override final; NbElts_t getNbProducedData(const IOIndex_t outputIdx) const override final; - + void updateConsummerProducer() override final; void forward(); void backward(); @@ -60,4 +60,4 @@ static Registrar<Softmax_Op> registrarSoftmaxImpl_cpu("cpu", Aidge::SoftmaxImpl_ } } // namespace Aidge -#endif /* AIDGE_CPU_OPERATOR_SOFTMAXIMPL_H_ */ \ No newline at end of file +#endif /* AIDGE_CPU_OPERATOR_SOFTMAXIMPL_H_ */ diff --git a/src/operator/AddImpl.cpp b/src/operator/AddImpl.cpp index ece1967a..96ef58fc 100644 --- a/src/operator/AddImpl.cpp +++ b/src/operator/AddImpl.cpp @@ -48,7 +48,13 @@ Aidge::NbElts_t Aidge::AddImpl_cpu<1>::getNbConsumedData(Aidge::IOIndex_t /*inpu Aidge::NbElts_t Aidge::AddImpl_cpu<1>::getNbProducedData(Aidge::IOIndex_t /*outputIdx*/) const { return mNbProducedData[0]; } +void Aidge::AddImpl_cpu<1>::updateConsummerProducer(){ + // Update producer-consumer data + for (IOIndex_t inputIdx = 0; static_cast<NbElts_t>(inputIdx) < mNbConsumedData.size(); ++inputIdx) + mNbConsumedData[inputIdx]+= getNbRequiredData(inputIdx); // each input is consumed by the minimum amount for a forward pass + mNbProducedData[0]+= getRequiredMemory(0, {}); +} void Aidge::AddImpl_cpu<1>::forward() { // FIXME: uncomment the following code once memory handling will work assert(mOp.getInput(0) && "missing input #0"); @@ -63,11 +69,6 @@ void Aidge::AddImpl_cpu<1>::forward() { mOp.getInput(0)->getImpl()->rawPtr(), mOp.getOutput(0)->getImpl()->rawPtr()); - // Update producer-consumer data - for (IOIndex_t inputIdx = 0; static_cast<NbElts_t>(inputIdx) < mNbConsumedData.size(); ++inputIdx) - mNbConsumedData[inputIdx]+= getNbRequiredData(inputIdx); // each input is consumed by the minimum amount for a forward pass - - mNbProducedData[0]+= getRequiredMemory(0, {}); } void Aidge::AddImpl_cpu<1>::backward() { @@ -112,7 +113,13 @@ Aidge::NbElts_t Aidge::AddImpl_cpu<2>::getNbConsumedData(Aidge::IOIndex_t inputI Aidge::NbElts_t Aidge::AddImpl_cpu<2>::getNbProducedData(Aidge::IOIndex_t /*outputIdx*/) const { return mNbProducedData[0]; } +void Aidge::AddImpl_cpu<2>::updateConsummerProducer(){ + // Update producer-consumer data + for (IOIndex_t inputIdx = 0; static_cast<NbElts_t>(inputIdx) < mNbConsumedData.size(); ++inputIdx) + mNbConsumedData[inputIdx]+= getNbRequiredData(inputIdx); // each input is consumed by the minimum amount for a forward pass + mNbProducedData[0]+= getRequiredMemory(0, {}); +} void Aidge::AddImpl_cpu<2>::forward() { // FIXME: uncomment the following code once memory handling will work assert(mOp.getInput(0) && "missing input #0"); @@ -130,11 +137,6 @@ void Aidge::AddImpl_cpu<2>::forward() { mOp.mInputs[1]->getImpl()->rawPtr(), mOp.getOutput(0)->getImpl()->rawPtr()); - // Update producer-consumer data - for (std::size_t inputIdx = 0; inputIdx < mNbConsumedData.size(); ++inputIdx) - mNbConsumedData[inputIdx]+= getNbRequiredData(static_cast<IOIndex_t>(inputIdx)); // each input is consumed by the minimum amount for a forward pass - - mNbProducedData[0]+= getRequiredMemory(0, {}); } void Aidge::AddImpl_cpu<2>::backward() { @@ -180,7 +182,13 @@ Aidge::NbElts_t Aidge::AddImpl_cpu<3>::getNbProducedData(Aidge::IOIndex_t output assert(static_cast<std::size_t>(outputIdx) < mNbProducedData.size()); return mNbProducedData[static_cast<std::size_t>(outputIdx)]; } +void Aidge::AddImpl_cpu<3>::updateConsummerProducer(){ + // Update producer-consumer data + for (IOIndex_t inputIdx = 0; static_cast<NbElts_t>(inputIdx) < mNbConsumedData.size(); ++inputIdx) + mNbConsumedData[inputIdx]+= getNbRequiredData(inputIdx); // each input is consumed by the minimum amount for a forward pass + mNbProducedData[0]+= getRequiredMemory(0, {}); +} void Aidge::AddImpl_cpu<3>::forward() { // FIXME: uncomment the following code once memory handling will work assert(mOp.getInput(0) && "missing input #0"); @@ -201,13 +209,8 @@ void Aidge::AddImpl_cpu<3>::forward() { mOp.mInputs[2]->getImpl()->rawPtr(), mOp.getOutput(0)->getImpl()->rawPtr()); - // Update producer-consumer data - for (IOIndex_t inputIdx = 0; static_cast<NbElts_t>(inputIdx) < mNbConsumedData.size(); ++inputIdx) - mNbConsumedData[inputIdx]+= getNbRequiredData(inputIdx); // each input is consumed by the minimum amount for a forward pass - - mNbProducedData[0]+= getRequiredMemory(0, {}); } void Aidge::AddImpl_cpu<3>::backward() { printf("Not implemented yet.\n"); -} \ No newline at end of file +} diff --git a/src/operator/AvgPoolingImpl.cpp b/src/operator/AvgPoolingImpl.cpp index eebaa5dd..0f54ea52 100644 --- a/src/operator/AvgPoolingImpl.cpp +++ b/src/operator/AvgPoolingImpl.cpp @@ -54,7 +54,13 @@ Aidge::NbElts_t Aidge::AvgPoolingImpl2D_cpu::getNbProducedData(Aidge::IOIndex_t assert((outputIdx == 0) && (static_cast<std::size_t>(outputIdx) < mNbProducedData.size())); return mNbProducedData[static_cast<std::size_t>(outputIdx)]; } - +void Aidge::AvgPoolingImpl2D_cpu::updateConsummerProducer(){ + // Update producer-consumer data + for (std::size_t inputIdx = 0; inputIdx < mNbConsumedData.size(); ++inputIdx) + mNbConsumedData[inputIdx] += getNbRequiredData(static_cast<IOIndex_t>(inputIdx)); // each input is consumed by the minimum + // amount for a forward pass + mNbProducedData[0] += getRequiredMemory(0, {}); +} void Aidge::AvgPoolingImpl2D_cpu::forward() { // FIXME: uncomment the following code once memory handling will work assert(mOp.getInput(0) && "missing input #0"); @@ -69,13 +75,6 @@ void Aidge::AvgPoolingImpl2D_cpu::forward() { mOp.getInput(0)->getImpl()->rawPtr(), mOp.getOutput(0)->getImpl()->rawPtr()); - - // Update producer-consumer data - for (std::size_t inputIdx = 0; inputIdx < mNbConsumedData.size(); ++inputIdx) - mNbConsumedData[inputIdx] += getNbRequiredData(static_cast<IOIndex_t>(inputIdx)); // each input is consumed by the minimum - // amount for a forward pass - - mNbProducedData[0] += getRequiredMemory(0, {}); } void Aidge::AvgPoolingImpl2D_cpu::backward() { printf("Not implemented yet.\n"); } diff --git a/src/operator/BatchNormImpl.cpp b/src/operator/BatchNormImpl.cpp index c8783b36..aff01853 100644 --- a/src/operator/BatchNormImpl.cpp +++ b/src/operator/BatchNormImpl.cpp @@ -53,7 +53,14 @@ Aidge::NbElts_t Aidge::BatchNormImpl2D_cpu::getNbProducedData(Aidge::IOIndex_t o assert((outputIdx == 0) && (static_cast<std::size_t>(outputIdx) < mNbProducedData.size())); return mNbProducedData[static_cast<std::size_t>(outputIdx)]; } +void Aidge::BatchNormImpl2D_cpu::updateConsummerProducer(){ + // Update producer-consumer data + for (std::size_t inputIdx = 0; inputIdx < mNbConsumedData.size(); ++inputIdx) + mNbConsumedData[inputIdx] += getNbRequiredData(static_cast<IOIndex_t>(inputIdx)); // each input is consumed by the minimum + // amount for a forward pass + mNbProducedData[0] += getRequiredMemory(0, {}); +} void Aidge::BatchNormImpl2D_cpu::forward() { // FIXME: uncomment the following code once memory handling will work assert(mOp.getInput(0) && "missing input #0"); @@ -79,12 +86,7 @@ void Aidge::BatchNormImpl2D_cpu::forward() { mOp.getOutput(0)->getImpl()->rawPtr(), true); - // Update producer-consumer data - for (std::size_t inputIdx = 0; inputIdx < mNbConsumedData.size(); ++inputIdx) - mNbConsumedData[inputIdx] += getNbRequiredData(static_cast<IOIndex_t>(inputIdx)); // each input is consumed by the minimum - // amount for a forward pass - mNbProducedData[0] += getRequiredMemory(0, {}); } void Aidge::BatchNormImpl2D_cpu::backward() { printf("Not implemented yet.\n"); } diff --git a/src/operator/ConvDepthWiseImpl.cpp b/src/operator/ConvDepthWiseImpl.cpp index 75a35cff..e49c68cf 100644 --- a/src/operator/ConvDepthWiseImpl.cpp +++ b/src/operator/ConvDepthWiseImpl.cpp @@ -55,7 +55,14 @@ Aidge::NbElts_t Aidge::ConvDepthWiseImpl2D_cpu::getNbProducedData(Aidge::IOIndex assert((outputIdx == 0) && (static_cast<std::size_t>(outputIdx) < mNbProducedData.size())); return mNbProducedData[static_cast<std::size_t>(outputIdx)]; } +void Aidge::ConvDepthWiseImpl2D_cpu::updateConsummerProducer(){ + // Update producer-consumer data + for (std::size_t inputIdx = 0; inputIdx < mNbConsumedData.size(); ++inputIdx) + mNbConsumedData[inputIdx] += getNbRequiredData(static_cast<IOIndex_t>(inputIdx)); // each input is consumed by the minimum + // amount for a forward pass + mNbProducedData[0] += getRequiredMemory(0, {}); +} void Aidge::ConvDepthWiseImpl2D_cpu::forward() { // FIXME: uncomment the following code once memory handling will work assert(mOp.getInput(0) && "missing input #0"); @@ -73,14 +80,6 @@ void Aidge::ConvDepthWiseImpl2D_cpu::forward() { kernelFunc(mOp.getParams(), std::static_pointer_cast<Tensor>(mOp.getInput(0))->dims<4>(), mOp.getInput(0)->getImpl()->rawPtr(), mOp.getInput(1)->getImpl()->rawPtr(), mOp.getInput(2)->getImpl()->rawPtr(), mOp.getOutput(0)->getImpl()->rawPtr()); - - - // Update producer-consumer data - for (std::size_t inputIdx = 0; inputIdx < mNbConsumedData.size(); ++inputIdx) - mNbConsumedData[inputIdx] += getNbRequiredData(static_cast<IOIndex_t>(inputIdx)); // each input is consumed by the minimum - // amount for a forward pass - - mNbProducedData[0] += getRequiredMemory(0, {}); } void Aidge::ConvDepthWiseImpl2D_cpu::backward() { printf("Not implemented yet.\n"); } diff --git a/src/operator/ConvImpl.cpp b/src/operator/ConvImpl.cpp index e75fab10..65779c62 100644 --- a/src/operator/ConvImpl.cpp +++ b/src/operator/ConvImpl.cpp @@ -55,7 +55,14 @@ Aidge::NbElts_t Aidge::ConvImpl2D_cpu::getNbProducedData(Aidge::IOIndex_t output assert((outputIdx == 0) && (static_cast<std::size_t>(outputIdx) < mNbProducedData.size())); return mNbProducedData[static_cast<std::size_t>(outputIdx)]; } +void Aidge::ConvImpl2D_cpu::updateConsummerProducer(){ + // Update producer-consumer data + for (std::size_t inputIdx = 0; inputIdx < mNbConsumedData.size(); ++inputIdx) + mNbConsumedData[inputIdx] += getNbRequiredData(static_cast<IOIndex_t>(inputIdx)); // each input is consumed by the minimum + // amount for a forward pass + mNbProducedData[0] += getRequiredMemory(0, {}); +} void Aidge::ConvImpl2D_cpu::forward() { // FIXME: uncomment the following code once memory handling will work assert(mOp.getInput(0) && "missing input #0"); @@ -72,15 +79,7 @@ void Aidge::ConvImpl2D_cpu::forward() { mOp.getInput(0)->getImpl()->rawPtr(), mOp.getInput(1)->getImpl()->rawPtr(), mOp.getInput(2)->getImpl()->rawPtr(), mOp.getOutput(0)->getImpl()->rawPtr()); - // FIXME: Dummy wait for some earlier scheduler tests - std::this_thread::sleep_for(std::chrono::milliseconds(mOp.get<ConvParam::OutChannels>())); - // Update producer-consumer data - for (std::size_t inputIdx = 0; inputIdx < mNbConsumedData.size(); ++inputIdx) - mNbConsumedData[inputIdx] += getNbRequiredData(static_cast<IOIndex_t>(inputIdx)); // each input is consumed by the minimum - // amount for a forward pass - - mNbProducedData[0] += getRequiredMemory(0, {}); } void Aidge::ConvImpl2D_cpu::backward() { printf("Not implemented yet.\n"); } diff --git a/src/operator/FCImpl.cpp b/src/operator/FCImpl.cpp index 970ce690..c485ba2c 100644 --- a/src/operator/FCImpl.cpp +++ b/src/operator/FCImpl.cpp @@ -70,6 +70,16 @@ Aidge::NbElts_t Aidge::FCImpl_cpu::getNbProducedData(Aidge::IOIndex_t outputIdx) return mNbProducedData[static_cast<std::size_t>(outputIdx)]; } +void Aidge::FCImpl_cpu::updateConsummerProducer(){ + // Update producer-consumer data + for (IOIndex_t inputIdx = 0; static_cast<std::size_t>(inputIdx) < mNbConsumedData.size(); ++inputIdx) + mNbConsumedData[inputIdx] + += getNbRequiredData(static_cast<std::size_t>(inputIdx)); // each input is consumed by the minimum + // amount for a forward pass + + mNbProducedData[0] += getRequiredMemory(0, {}); +} + void Aidge::FCImpl_cpu::forward() { // FIXME: uncomment the following code once memory handling will work @@ -94,7 +104,7 @@ void Aidge::FCImpl_cpu::forward() // mOp.mInputs[2]->getImpl()->rawPtr(), // mOp.getOutput(0)->getImpl()->rawPtr()); // } - // else + // else kernelFunc( mOp.getParams(), mOp.getInput(0)->dims()[0], @@ -103,19 +113,8 @@ void Aidge::FCImpl_cpu::forward() mOp.mInputs[1]->getImpl()->rawPtr(), mOp.mInputs[2]->getImpl()->rawPtr(), mOp.getOutput(0)->getImpl()->rawPtr()); - - - - // FIXME: Dummy wait for some earlier scheduler tests - std::this_thread::sleep_for(std::chrono::milliseconds(mOp.get<FCParam::OutChannels>())); - // Update producer-consumer data - for (IOIndex_t inputIdx = 0; static_cast<std::size_t>(inputIdx) < mNbConsumedData.size(); ++inputIdx) - mNbConsumedData[inputIdx] - += getNbRequiredData(static_cast<std::size_t>(inputIdx)); // each input is consumed by the minimum - // amount for a forward pass - mNbProducedData[0] += getRequiredMemory(0, {}); } void Aidge::FCImpl_cpu::backward() diff --git a/src/operator/LeakyReLUImpl.cpp b/src/operator/LeakyReLUImpl.cpp index 1e86de4a..656ba5db 100644 --- a/src/operator/LeakyReLUImpl.cpp +++ b/src/operator/LeakyReLUImpl.cpp @@ -51,7 +51,11 @@ Aidge::NbElts_t Aidge::LeakyReLUImpl_cpu::getNbConsumedData(Aidge::IOIndex_t /*i Aidge::NbElts_t Aidge::LeakyReLUImpl_cpu::getNbProducedData(Aidge::IOIndex_t /*outputIdx*/) const { return mNbProducedData[0]; } +void Aidge::LeakyReLUImpl_cpu::updateConsummerProducer(){ + mNbConsumedData[0]+= getNbRequiredData(0); // each input is consumed by the minimum amount for a forward pass + mNbProducedData[0]+= getRequiredMemory(0, {}); +} void Aidge::LeakyReLUImpl_cpu::forward() { // FIXME: uncomment the following code once memory handling will work assert(mOp.getInput(0) && "missing input #0"); @@ -66,11 +70,6 @@ void Aidge::LeakyReLUImpl_cpu::forward() { std::static_pointer_cast<Tensor>(mOp.getInput(0))->size(), mOp.getInput(0)->getImpl()->rawPtr(), mOp.getOutput(0)->getImpl()->rawPtr()); - - - mNbConsumedData[0]+= getNbRequiredData(0); // each input is consumed by the minimum amount for a forward pass - - mNbProducedData[0]+= getRequiredMemory(0, {}); } void Aidge::LeakyReLUImpl_cpu::backward() { diff --git a/src/operator/ProducerImpl.cpp b/src/operator/ProducerImpl.cpp index 6c1de523..3ca6d706 100644 --- a/src/operator/ProducerImpl.cpp +++ b/src/operator/ProducerImpl.cpp @@ -61,7 +61,8 @@ Aidge::DimSize_t Aidge::ProducerImpl_cpu::getNbProducedData( { return getRequiredMemory(0, {}); } - +void Aidge::ProducerImpl_cpu::updateConsummerProducer(){ +} void Aidge::ProducerImpl_cpu::forward() { @@ -71,4 +72,4 @@ void Aidge::ProducerImpl_cpu::forward() void Aidge::ProducerImpl_cpu::backward() { printf("Not implemented yet.\n"); -} \ No newline at end of file +} diff --git a/src/operator/ReLUImpl.cpp b/src/operator/ReLUImpl.cpp index 61c11937..222b1366 100644 --- a/src/operator/ReLUImpl.cpp +++ b/src/operator/ReLUImpl.cpp @@ -51,7 +51,11 @@ Aidge::NbElts_t Aidge::ReLUImpl_cpu::getNbConsumedData(Aidge::IOIndex_t /*inputI Aidge::NbElts_t Aidge::ReLUImpl_cpu::getNbProducedData(Aidge::IOIndex_t /*outputIdx*/) const { return mNbProducedData[0]; } +void Aidge::ReLUImpl_cpu::updateConsummerProducer(){ + mNbConsumedData[0]+= getNbRequiredData(0); // each input is consumed by the minimum amount for a forward pass + mNbProducedData[0]+= getRequiredMemory(0, {}); +} void Aidge::ReLUImpl_cpu::forward() { // FIXME: uncomment the following code once memory handling will work assert(mOp.getInput(0) && "missing input #0"); @@ -66,10 +70,6 @@ void Aidge::ReLUImpl_cpu::forward() { mOp.getInput(0)->getImpl()->rawPtr(), mOp.getOutput(0)->getImpl()->rawPtr()); - - mNbConsumedData[0]+= getNbRequiredData(0); // each input is consumed by the minimum amount for a forward pass - - mNbProducedData[0]+= getRequiredMemory(0, {}); } void Aidge::ReLUImpl_cpu::backward() { diff --git a/src/operator/SoftmaxImpl.cpp b/src/operator/SoftmaxImpl.cpp index 50673042..a28f3b45 100644 --- a/src/operator/SoftmaxImpl.cpp +++ b/src/operator/SoftmaxImpl.cpp @@ -51,7 +51,14 @@ Aidge::NbElts_t Aidge::SoftmaxImpl_cpu::getNbConsumedData(Aidge::IOIndex_t /*inp Aidge::NbElts_t Aidge::SoftmaxImpl_cpu::getNbProducedData(Aidge::IOIndex_t /*outputIdx*/) const { return mNbProducedData[0]; } +void Aidge::SoftmaxImpl_cpu::updateConsummerProducer(){ + // Update producer-consumer data + for (std::size_t inputIdx = 0; inputIdx < mNbConsumedData.size(); ++inputIdx) + mNbConsumedData[inputIdx] += getNbRequiredData(static_cast<IOIndex_t>(inputIdx)); // each input is consumed by the minimum + // amount for a forward pass + mNbProducedData[0] += getRequiredMemory(0, {}); +} void Aidge::SoftmaxImpl_cpu::forward() { // FIXME: uncomment the following code once memory handling will work assert(mOp.getInput(0) && "missing input #0"); -- GitLab