From 1ae9353725a77a42d89d10a6622f1e78d42d1b5a Mon Sep 17 00:00:00 2001 From: Olivier BICHLER <olivier.bichler@cea.fr> Date: Sun, 10 Dec 2023 18:35:22 +0100 Subject: [PATCH] Added Producer impl --- include/aidge/backend/cuda.hpp | 1 + .../backend/cuda/operator/ProducerImpl.hpp | 40 +++++++++++++++++++ src/operator/ProducerImpl.cpp | 34 ++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 include/aidge/backend/cuda/operator/ProducerImpl.hpp create mode 100644 src/operator/ProducerImpl.cpp diff --git a/include/aidge/backend/cuda.hpp b/include/aidge/backend/cuda.hpp index a6bae17..cfae53b 100644 --- a/include/aidge/backend/cuda.hpp +++ b/include/aidge/backend/cuda.hpp @@ -14,5 +14,6 @@ #include "aidge/backend/cuda/data/TensorImpl.hpp" #include "aidge/backend/cuda/operator/ConvImpl.hpp" +#include "aidge/backend/cuda/operator/ProducerImpl.hpp" #endif /* AIDGE_BACKEND_CUDA_IMPORTS_H_ */ \ No newline at end of file diff --git a/include/aidge/backend/cuda/operator/ProducerImpl.hpp b/include/aidge/backend/cuda/operator/ProducerImpl.hpp new file mode 100644 index 0000000..9912133 --- /dev/null +++ b/include/aidge/backend/cuda/operator/ProducerImpl.hpp @@ -0,0 +1,40 @@ +/******************************************************************************** + * Copyright (c) 2023 CEA-List + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + * + ********************************************************************************/ + +#ifndef AIDGE_CUDA_OPERATOR_PRODUCERIMPL_H_ +#define AIDGE_CUDA_OPERATOR_PRODUCERIMPL_H_ + +#include <memory> + +#include "aidge/backend/OperatorImpl.hpp" +#include "aidge/operator/Producer.hpp" +#include "aidge/utils/Registrar.hpp" +#include "aidge/utils/Types.h" + +namespace Aidge { +class ProducerImpl_cuda : public OperatorImpl { +public: + ProducerImpl_cuda(const Producer_Op &op) : OperatorImpl(op) {} + + static std::unique_ptr<ProducerImpl_cuda> create(const Producer_Op &op) { + return std::make_unique<ProducerImpl_cuda>(op); + } + + NbElts_t getNbProducedData(const IOIndex_t outputIdx) const override final; + void forward() override; +}; + +namespace { +static Registrar<Producer_Op> registrarProducerImpl_cuda("cuda", Aidge::ProducerImpl_cuda::create); +} // namespace +} // namespace Aidge + +#endif /* AIDGE_CUDA_OPERATOR_PRODUCERIMPL_H_ */ diff --git a/src/operator/ProducerImpl.cpp b/src/operator/ProducerImpl.cpp new file mode 100644 index 0000000..aca3c49 --- /dev/null +++ b/src/operator/ProducerImpl.cpp @@ -0,0 +1,34 @@ +/******************************************************************************** + * Copyright (c) 2023 CEA-List + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + * + ********************************************************************************/ + +#include <cassert> +#include <numeric> // std::accumulate +#include <vector> + +#include "aidge/data/Tensor.hpp" +#include "aidge/operator/Producer.hpp" +#include "aidge/utils/Types.h" + +#include "aidge/backend/cuda/operator/ProducerImpl.hpp" + +Aidge::DimSize_t Aidge::ProducerImpl_cuda::getNbProducedData( + Aidge::IOIndex_t outputIdx) const +{ + // Requires the whole tensors, regardless of available data on inputs + assert(outputIdx == 0 && "operator has only one output"); + (void) outputIdx; + + return std::static_pointer_cast<Tensor>(mOp.getRawOutput(0))->size(); +} + +void Aidge::ProducerImpl_cuda::forward() +{ +} -- GitLab