diff --git a/include/aidge/backend/cpu.hpp b/include/aidge/backend/cpu.hpp index 6d090403c40995ced7dd098dc5fe67847119335c..8b0001c2230ed6ad6b928f7ec8eed5340ae37087 100644 --- a/include/aidge/backend/cpu.hpp +++ b/include/aidge/backend/cpu.hpp @@ -54,7 +54,6 @@ #include "aidge/backend/cpu/operator/ResizeImpl.hpp" #include "aidge/backend/cpu/operator/ReLUImpl.hpp" #include "aidge/backend/cpu/operator/RoundImpl.hpp" -#include "aidge/backend/cpu/operator/ScalingImpl.hpp" #include "aidge/backend/cpu/operator/SigmoidImpl.hpp" #include "aidge/backend/cpu/operator/SqrtImpl.hpp" #include "aidge/backend/cpu/operator/SliceImpl.hpp" diff --git a/include/aidge/backend/cpu/operator/ScalingImpl.hpp b/include/aidge/backend/cpu/operator/ScalingImpl.hpp deleted file mode 100644 index c1cc247c548701d43e01b1e92d02f42a11cfc710..0000000000000000000000000000000000000000 --- a/include/aidge/backend/cpu/operator/ScalingImpl.hpp +++ /dev/null @@ -1,38 +0,0 @@ -/******************************************************************************** - * 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_CPU_OPERATOR_ScalingIMPL_H__ -#define __AIDGE_CPU_OPERATOR_ScalingIMPL_H__ - -#include "aidge/backend/cpu/operator/OperatorImpl.hpp" -#include "aidge/operator/Scaling.hpp" -#include "aidge/utils/Registrar.hpp" -#include "aidge/utils/Types.h" -#include "aidge/backend/cpu/data/GetCPUPtr.h" -#include <memory> -#include <vector> -#include <array> - -namespace Aidge { -// Operator implementation entry point for the backend -using ScalingImpl_cpu = OperatorImpl_cpu<Scaling_Op, - void(const float, - const std::size_t, - const bool, - std::size_t, - const void*, - void*)>; - -// Implementation entry point registration to Operator -REGISTRAR(Scaling_Op, "cpu", Aidge::ScalingImpl_cpu::create); -} // namespace Aidge - -#endif /* __AIDGE_CPU_OPERATOR_ScalingIMPL_H__ */ \ No newline at end of file diff --git a/include/aidge/backend/cpu/operator/ScalingImpl_kernels.hpp b/include/aidge/backend/cpu/operator/ScalingImpl_kernels.hpp deleted file mode 100644 index f9ca00b73193c9dbd54d286125da1f084ae25587..0000000000000000000000000000000000000000 --- a/include/aidge/backend/cpu/operator/ScalingImpl_kernels.hpp +++ /dev/null @@ -1,107 +0,0 @@ -/******************************************************************************** - * 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_CPU_OPERATOR_SCALINGIMPL_KERNELS_H_ -#define AIDGE_CPU_OPERATOR_SCALINGIMPL_KERNELS_H_ - -#include <cmath> -#include <cstddef> -#include "aidge/utils/Registrar.hpp" -#include "aidge/backend/cpu/operator/ScalingImpl.hpp" - -//TODO : improve propagate, n2d2 : -/* -template<typename T> -void N2D2::floatingPointScaling_propagate(const Tensor<T>& input, Tensor<T>& output, - std::size_t batchSize, std::size_t nbChannels, - std::size_t height, std::size_t width, - bool isClipped, - const std::vector<Float_T>& clippingFactorPerChannel, - const std::vector<Float_T>& scalingFactorPerChannel, - std::size_t quantizedNbBits, bool isOutputUnsigned) -{ - std::size_t index = 0; - for (std::size_t batch = 0; batch < batchSize; batch++) { - for(std::size_t ch = 0; ch < nbChannels; ch++) { - for(std::size_t y = 0; y < height; y++) { - for(std::size_t x = 0; x < width; x++) { - - T res = isClipped ? Clip(input(index), clippingFactorPerChannel[ch]) - : input(index); - res = Scale(res, scalingFactorPerChannel[ch]); - - if(quantizedNbBits > 0) { - res = saturate(std::round(res), quantizedNbBits, isOutputUnsigned); - } - output(index) = (T) res; - index++; - } - } - } - } -} -*/ - - -namespace Aidge { - -template <class O> -const O& clamp(const O& x, const O& min, const O& max) -{ - return (x < min) ? min : (x > max) ? max : x; -} - -template<class O> -O saturate(const O value, const std::size_t quantizedNbBits, const bool isOutputUnsigned) { - // TODO: no assertions in kernel - assert(quantizedNbBits > 0); - - const O min = isOutputUnsigned ? 0 : - -(1ll << (quantizedNbBits - 1ll)); - const O max = isOutputUnsigned ? (1ll << quantizedNbBits) - 1ll : - (1ll << (quantizedNbBits - 1ll)) - 1ll; - - return clamp(value, min, max); -} - -template <class I, class O> -void ScalingImpl_cpu_forward_kernel(const float scalingFactor, - const std::size_t quantizedNbBits, - const bool isOutputUnsigned, - std::size_t inputLength, - const void* input_, - void* output_) { - - const I* input = static_cast<const I*>(input_); - O* output = static_cast<O*>(output_); - - for (std::size_t i = 0; i < inputLength; ++i) { - output[i] = static_cast<O>(input[i] * static_cast<I>(scalingFactor)); - - if(quantizedNbBits > 0) { - output[i] = saturate(std::round(output[i]), quantizedNbBits, isOutputUnsigned); - } - } -} - -// Kernels registration to implementation entry point -REGISTRAR(ScalingImpl_cpu, - {DataType::Float32}, - {ProdConso::inPlaceModel, Aidge::ScalingImpl_cpu_forward_kernel<float, float>, nullptr}); -REGISTRAR(ScalingImpl_cpu, - {DataType::Float64}, - {ProdConso::inPlaceModel, Aidge::ScalingImpl_cpu_forward_kernel<double, double>, nullptr}); -REGISTRAR(ScalingImpl_cpu, - {DataType::Int32}, - {ProdConso::inPlaceModel, Aidge::ScalingImpl_cpu_forward_kernel<int32_t, int32_t>, nullptr}); -} // namespace Aidge - -#endif /* AIDGE_CPU_OPERATOR_SCALINGIMPL_KERNELS_H_ */ \ No newline at end of file diff --git a/src/operator/ExpandImpl.cpp b/src/operator/ExpandImpl.cpp index dfd4d2d82edc4dfb5bbaec6f5b33bf1c00bf3c75..8aa5af56c06e4699496018492377e73d222db8f0 100644 --- a/src/operator/ExpandImpl.cpp +++ b/src/operator/ExpandImpl.cpp @@ -28,13 +28,11 @@ template <> void ExpandImpl_cpu::forward() { const Expand_Op &op_ = static_cast<const Expand_Op &>(mOp); // Check if input are provided AIDGE_ASSERT(op_.getInput(0), - "{}: missing input 0: {}", - Expand_Op::Type, - Expand_Op::getInputsName()[0]); + "{}: missing input 0", + Expand_Op::Type); AIDGE_ASSERT(op_.getInput(1), - "{}: missing input 1: {}", - Expand_Op::Type, - Expand_Op::getInputsName()[1]); + "{}: missing input 1", + Expand_Op::Type); // Find the correct kernel type const auto impl = diff --git a/src/operator/ScalingImpl.cpp b/src/operator/ScalingImpl.cpp deleted file mode 100644 index 1e7a408f267c5eb2d60d188f0ed2ba0394222561..0000000000000000000000000000000000000000 --- a/src/operator/ScalingImpl.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************** - * 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 <functional> // std::multiplies -#include <vector> - -#include "aidge/operator/Scaling.hpp" - -#include "aidge/backend/cpu/operator/ScalingImpl.hpp" -#include "aidge/backend/cpu/operator/ScalingImpl_kernels.hpp" -#include "aidge/utils/Types.h" -#include "aidge/backend/cpu/data/GetCPUPtr.h" - -template <> -void Aidge::ScalingImpl_cpu::forward() { - const auto& op_ = dynamic_cast<const Scaling_Op&>(mOp); - AIDGE_ASSERT(op_.getInput(0), "missing input #0 in Scaling Operator."); - - // Find the correct kernel type - const auto impl = Registrar<ScalingImpl_cpu>::create(getBestMatch(getRequiredSpec())); - - // Call kernel - impl.forward(op_.scalingFactor(), - op_.quantizedNbBits(), - op_.isOutputUnsigned(), - op_.getInput(0)->size(), - getCPUPtr(mOp.getRawInput(0)), - getCPUPtr(mOp.getRawOutput(0))); -} - -template <> -void Aidge::ScalingImpl_cpu::backward() { - AIDGE_THROW_OR_ABORT(std::runtime_error, "Backward not yet implemented for Scaling_Op on backend cpu"); -}