Skip to content
Snippets Groups Projects
Commit 0a740561 authored by Cyril Moineau's avatar Cyril Moineau
Browse files

Revert "Merge branch 'DevQAT' into 'dev'"

This reverts merge request !18
parent 4ca11b6e
No related tags found
1 merge request!19Revert "Merge branch 'DevQAT' into 'dev'"
Pipeline #59034 failed
Showing
with 68 additions and 417 deletions
# CMake >= 3.18 is required for good support of FindCUDAToolkit
cmake_minimum_required(VERSION 3.18) # XXX 3.18
cmake_minimum_required(VERSION 3.15)
file(READ "${CMAKE_SOURCE_DIR}/version.txt" version)
file(READ "${CMAKE_SOURCE_DIR}/project_name.txt" project)
......@@ -11,7 +11,6 @@ message(STATUS "Project version: ${version}")
set(module_name _${project}) # target name
project(${project})
set(CXX_STANDARD 14)
##############################################
# Import utils CMakeLists
......@@ -23,7 +22,6 @@ option(PYBIND "python binding" OFF)
option(WERROR "Warning as error" OFF)
option(TEST "Enable tests" ON)
option(COVERAGE "Enable coverage" OFF)
option(CUDA "Enable CUDA backend" ON) # XXX OFF
##############################################
# Import utils CMakeLists
......@@ -34,14 +32,6 @@ if(CMAKE_COMPILER_IS_GNUCXX AND COVERAGE)
Include(CodeCoverage)
endif()
if(CUDA)
enable_language(CUDA)
message(STATUS "Cuda compiler version = ${CMAKE_CUDA_COMPILER_VERSION}")
# Define a preprocessor macro with the Cuda compiler version
add_definitions(-DCUDA_COMPILER_VERSION="${CMAKE_CUDA_COMPILER_VERSION}")
endif()
# ##############################################
# Find system dependencies
Include(FetchContent)
......@@ -56,49 +46,26 @@ set(FMT_SYSTEM_HEADERS ON)
FetchContent_MakeAvailable(fmt)
set_property(TARGET fmt PROPERTY POSITION_INDEPENDENT_CODE ON)
if(CUDA)
find_package(CUDAToolkit REQUIRED)
endif()
##############################################
# Find system dependencies
find_package(aidge_core REQUIRED)
find_package(aidge_backend_cpu REQUIRED)
if(CUDA)
find_package(aidge_backend_cuda REQUIRED)
endif()
##############################################
# Create target and set properties
if(CUDA)
file(GLOB_RECURSE src_files "src/*.cpp" "src/*.cu")
file(GLOB_RECURSE inc_files "include/*.hpp")
add_library(${module_name} ${src_files} ${inc_files})
target_link_libraries(${module_name}
PUBLIC
_aidge_core # _ is added because we link the target not the project
_aidge_backend_cpu
# _aidge_backend_cuda # XXX
CUDA::cudart
CUDA::cublas
cudnn
)
else()
file(GLOB_RECURSE src_files "src/*.cpp")
file(GLOB_RECURSE inc_files "include/*.hpp")
add_library(${module_name} ${src_files} ${inc_files})
target_link_libraries(${module_name}
PUBLIC
_aidge_core # _ is added because we link the target not the project
_aidge_backend_cpu
)
endif()
file(GLOB_RECURSE src_files "src/*.cpp")
file(GLOB_RECURSE inc_files "include/*.hpp")
add_library(${module_name} ${src_files} ${inc_files})
target_link_libraries(${module_name}
PUBLIC
_aidge_core # _ is added because we link the target not the project
_aidge_backend_cpu
)
#Set target properties
set_property(TARGET ${module_name} PROPERTY POSITION_INDEPENDENT_CODE ON)
target_include_directories(${module_name}
PUBLIC
$<INSTALL_INTERFACE:include>
......@@ -107,16 +74,6 @@ target_include_directories(${module_name}
${CMAKE_CURRENT_SOURCE_DIR}/src
)
if(CUDA)
if(NOT DEFINED CMAKE_CUDA_STANDARD)
set(CMAKE_CUDA_STANDARD 14)
set(CMAKE_CUDA_STANDARD_REQUIRED ON)
endif()
set_target_properties(${module_name} PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
endif()
set_property(TARGET ${module_name} PROPERTY POSITION_INDEPENDENT_CODE ON)
# PYTHON BINDING
if (PYBIND)
# Handles Python + pybind11 headers dependencies
......@@ -136,13 +93,8 @@ target_link_libraries(${module_name} PUBLIC fmt::fmt)
target_compile_features(${module_name} PRIVATE cxx_std_14)
target_compile_options(${module_name} PRIVATE
$<$<COMPILE_LANGUAGE:CPP>:$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>:
-Wall -Wextra -Wold-style-cast -Winline -pedantic -Werror=narrowing -Wshadow $<$<BOOL:${WERROR}>:-Werror>>>)
if(CUDA)
target_compile_options(${module_name} PRIVATE
$<$<COMPILE_LANGUAGE:CUDA>:
-Wall>)
endif()
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>:
-Wall -Wextra -Wold-style-cast -Winline -pedantic -Werror=narrowing -Wshadow $<$<BOOL:${WERROR}>:-Werror>>)
target_compile_options(${module_name} PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:
/W4>)
......
// /********************************************************************************
// * 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_QUANTIZATION_CUDA_IMPORTS_H_
#define AIDGE_QUANTIZATION_CUDA_IMPORTS_H_
#include "aidge/backend/cuda/operator/LSQImpl.hpp"
#include "aidge/backend/cuda/operator/FixedQImpl.hpp"
// ...
#endif /* AIDGE_QUANTIZATION_CUDA_IMPORTS_H_ */
\ No newline at end of file
......@@ -27,7 +27,7 @@ namespace Aidge {
// Operator implementation entry point for the backend
using FixedQImpl_cpu = OperatorImpl_cpu<FixedQ_Op,
void(const std::size_t, const float, const bool, const std::size_t, const void*, void*),
void(const std::size_t, const void*, void*)>;
void(const std::size_t, const float, const bool, const std::size_t, const void*, const void*, void*)>;
// Implementation entry point registration to Operator
REGISTRAR(FixedQ_Op, "cpu", Aidge::FixedQImpl_cpu::create);
......
......@@ -25,8 +25,7 @@ void FixedQImpl_cpu_forward_kernel(
bool isOutputUnsigned,
std::size_t inputLenght,
const void* input_,
void* output_)
{
void* output_) {
I span = static_cast<I> (span_);
I stepSize = span / static_cast<I> (1 << (nbBits - 1));
......@@ -47,31 +46,45 @@ void FixedQImpl_cpu_forward_kernel(
}
template <class GI, class GO>
template <class I, class GI, class GO>
void FixedQImpl_cpu_backward_kernel(
std::size_t nbBits,
float span_,
bool isOutputUnsigned,
const std::size_t inputLenght,
const void* input_,
const void* grad_output_,
void* grad_input_)
{
void* grad_input_) {
I span = static_cast<I> (span_);
I stepSize = span / static_cast<I> (1 << (nbBits - 1));
if (isOutputUnsigned) {
stepSize /= 2;
}
const I upper = span - stepSize;
const I lower = isOutputUnsigned ? 0 : -span;
const I* input = static_cast<const I*>(input_);
const GO* grad_output = static_cast<const GO*>(grad_output_);
GI* grad_input = static_cast<GI*>(grad_input_);
for (std::size_t i = 0; i < inputLenght; ++i) {
// Straight Through Estimator
grad_input[i] = grad_output[i];
// Clipped Straight Through Estimator
grad_input[i] = ((input[i] > lower) && (input[i] < upper)) ? grad_output[i] : 0;
}
}
// Kernels registration to implementation entry point
REGISTRAR(FixedQImpl_cpu,
{{DataType::Int32, DataFormat::NCHW}, {DataType::Int32, DataFormat::NCHW}},
{ProdConso::inPlaceModel, Aidge::FixedQImpl_cpu_forward_kernel<int, int>, Aidge::FixedQImpl_cpu_backward_kernel<int, int>});
{ProdConso::inPlaceModel, Aidge::FixedQImpl_cpu_forward_kernel<int, int>, Aidge::FixedQImpl_cpu_backward_kernel<int, int, int>});
REGISTRAR(FixedQImpl_cpu,
{{DataType::Float32, DataFormat::NCHW}, {DataType::Float32, DataFormat::NCHW}},
{ProdConso::inPlaceModel, Aidge::FixedQImpl_cpu_forward_kernel<float, float>, Aidge::FixedQImpl_cpu_backward_kernel<float, float>});
{ProdConso::inPlaceModel, Aidge::FixedQImpl_cpu_forward_kernel<float, float>, Aidge::FixedQImpl_cpu_backward_kernel<float, float, float>});
REGISTRAR(FixedQImpl_cpu,
{{DataType::Float64, DataFormat::NCHW}, {DataType::Float64, DataFormat::NCHW}},
{ProdConso::inPlaceModel, Aidge::FixedQImpl_cpu_forward_kernel<double, double>, Aidge::FixedQImpl_cpu_backward_kernel<double, double>});
{ProdConso::inPlaceModel, Aidge::FixedQImpl_cpu_forward_kernel<double, double>, Aidge::FixedQImpl_cpu_backward_kernel<double, double, double>});
} // namespace Aidge
......
......@@ -26,8 +26,19 @@ namespace Aidge {
// compute kernel registry for forward and backward
using LSQImpl_cpu = OperatorImpl_cpu<LSQ_Op,
void(const std::size_t, std::pair<int, int>&, const void*, const void*, void*),
void(const std::size_t, std::pair<int, int>&, const void*, const void*, const void*, void*,void*)>;
void(const std::size_t,
std::pair<int, int>&,
const void*,
const void*,
void*),
void(const std::size_t,
std::pair<int, int>&,
const void*,
const void*,
const void*,
void*,
void*)>;
// Implementation entry point registration to Operator
REGISTRAR(LSQ_Op, "cpu", Aidge::LSQImpl_cpu::create);
......
/********************************************************************************
* 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_FIXEDQIMPL_H_
#define AIDGE_CUDA_OPERATOR_FIXEDQIMPL_H_
#include <cstddef> // std::size_t
#include <memory>
#include <tuple> // std::tuple
#include <vector>
#include "aidge/backend/OperatorImpl.hpp"
#include "aidge/backend/cuda/operator/OperatorImpl.hpp"
#include "aidge/operator/FixedQ.hpp"
#include "aidge/utils/Registrar.hpp"
#include "aidge/utils/Types.h"
namespace Aidge {
// The following helper cannot be used because of extra attributes ...
using FixedQImpl_cuda = OperatorImpl_cuda<FixedQ_Op,
void(const std::size_t, const float, const bool, const std::size_t, const void*, void*),
void(const std::size_t, const void*, void*)>;
// Implementation entry point registration to Operator
REGISTRAR(FixedQ_Op, "cuda", Aidge::FixedQImpl_cuda::create);
} // namespace Aidge
#endif /* AIDGE_CUDA_OPERATOR_FIXEDQIMPL_H_ */
/********************************************************************************
* Copyright (c) 2024 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_FIXEDQIMPL_KERNELS_H_
#define AIDGE_CUDA_OPERATOR_FIXEDQIMPL_KERNELS_H_
#include "aidge/data/Data.hpp"
#include "aidge/backend/cuda/utils/CudaUtils.hpp"
#include "aidge/backend/cuda/operator/FixedQImpl.hpp"
namespace Aidge {
template <class I, class O>
void FixedQImpl_cuda_forward_kernel(std::size_t nbBits,
float span_,
bool isOutputUnsigned,
std::size_t inputLength,
const void* input_,
void* output_);
template <class GI, class GO>
void FixedQImpl_cuda_backward_kernel(const std::size_t inputLength,
const void* grad_output_,
void* grad_input_);
// Kernels registration to implementation entry point
//REGISTRAR(FixedQImpl_cuda,
// {{DataType::Float16, DataFormat::NCHW}, {DataType::Float16, DataFormat::NCHW}},
// {ProdConso::inPlaceModel, Aidge::FixedQImpl_cuda_forward_kernel<half_float::half, half_float::half>, Aidge::FixedQImpl_cuda_backward_kernel<half_float::half, half_float::half, half_float::half>});
REGISTRAR(FixedQImpl_cuda,
{{DataType::Float32, DataFormat::NCHW}, {DataType::Float32, DataFormat::NCHW}},
{ProdConso::inPlaceModel, Aidge::FixedQImpl_cuda_forward_kernel<float, float>, Aidge::FixedQImpl_cuda_backward_kernel<float, float>});
REGISTRAR(FixedQImpl_cuda,
{{DataType::Float64, DataFormat::NCHW}, {DataType::Float64, DataFormat::NCHW}},
{ProdConso::inPlaceModel, Aidge::FixedQImpl_cuda_forward_kernel<double, double>, Aidge::FixedQImpl_cuda_backward_kernel<double, double>});
} // namespace Aidge
#endif /* AIDGE_CUDA_OPERATOR_FIXEDQIMPL_KERNELS_H_ */
/********************************************************************************
* 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_LSQIMPL_H_
#define AIDGE_CUDA_OPERATOR_LSQIMPL_H_
#include <cstddef> // std::size_t
#include <memory>
#include <tuple> // std::tuple
#include <vector>
#include "aidge/backend/OperatorImpl.hpp"
#include "aidge/operator/LSQ.hpp"
#include "aidge/utils/Registrar.hpp"
#include "aidge/utils/Types.h"
namespace Aidge {
// The following helper cannot be used because of extra attributes ...
// using LSQImpl_cuda = OperatorImpl_cuda<LSQ_Op,
// void(const std::size_t, std::pair<int, int>&, const void*, const void*, void*),
// void(const std::size_t, std::pair<int, int>&, const void*, const void*, const void*, void*, void*, void*)>;
class LSQImpl_cuda : public OperatorImpl,
public Registrable<
LSQImpl_cuda,
ImplSpec,
Impl<
void(const std::size_t, std::pair<int, int>&, const void*, const void*, void*),
void(const std::size_t, std::pair<int, int>&, const void*, const void*, const void*, void*, void* , void*)
>
>
{
public:
LSQImpl_cuda(const LSQ_Op& op) : OperatorImpl(op, "cuda") {}
static std::unique_ptr<LSQImpl_cuda> create(const LSQ_Op& op) {
return std::make_unique<LSQImpl_cuda>(op);
}
virtual std::shared_ptr<ProdConso> getProdConso() const override {
const auto impl = Registrar<LSQImpl_cuda>::create(getBestMatch(getRequiredSpec()));
return impl.prodConso(mOp);
}
virtual std::vector<ImplSpec> getAvailableImplSpecs() const override {
// return Registrar<LSQImpl_cuda>::getKeys(); // Note: cannot return set due to python binding
std::set<ImplSpec> implSpecsSet = Registrar<LSQImpl_cuda>::getKeys();
return std::vector<ImplSpec>(implSpecsSet.begin(), implSpecsSet.end());
}
void forward() override;
void backward() override;
~LSQImpl_cuda();
private:
size_t mWorkspaceSize = 0;
void* mWorkspace = nullptr;
};
// Implementation entry point registration to Operator
REGISTRAR(LSQ_Op, "cuda", Aidge::LSQImpl_cuda::create);
} // namespace Aidge
#endif /* AIDGE_CUDA_OPERATOR_LSQIMPL_H_ */
/********************************************************************************
* Copyright (c) 2024 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_LSQIMPL_KERNELS_H_
#define AIDGE_CUDA_OPERATOR_LSQIMPL_KERNELS_H_
#include "aidge/data/Data.hpp"
#include "aidge/backend/cuda/utils/CudaUtils.hpp"
#include "aidge/backend/cuda/operator/LSQImpl.hpp"
namespace Aidge {
template <class I, class O>
void LSQImpl_cuda_forward_kernel(std::size_t inputLength,
const std::pair<int, int>& range,
const void* input_,
const void* stepSize_,
void* output_);
template <class I, class GI, class GO>
void LSQImpl_cuda_backward_kernel(const std::size_t inputLength,
const std::pair<int, int>& range,
const void* input_,
const void* stepSize_,
const void* grad_output_,
void* grad_input_,
void* grad_stepSize_,
void* grad_workspace_);
// Kernels registration to implementation entry point
//REGISTRAR(LSQImpl_cuda,
// {{DataType::Float16, DataFormat::NCHW}, {DataType::Float16, DataFormat::NCHW}},
// {ProdConso::inPlaceModel, Aidge::LSQImpl_cuda_forward_kernel<half_float::half, half_float::half>, Aidge::LSQImpl_cuda_backward_kernel<half_float::half, half_float::half, half_float::half>});
REGISTRAR(LSQImpl_cuda,
{{DataType::Float32, DataFormat::NCHW}, {DataType::Float32, DataFormat::NCHW}},
{ProdConso::inPlaceModel, Aidge::LSQImpl_cuda_forward_kernel<float, float>, Aidge::LSQImpl_cuda_backward_kernel<float, float, float>});
REGISTRAR(LSQImpl_cuda,
{{DataType::Float64, DataFormat::NCHW}, {DataType::Float64, DataFormat::NCHW}},
{ProdConso::inPlaceModel, Aidge::LSQImpl_cuda_forward_kernel<double, double>, Aidge::LSQImpl_cuda_backward_kernel<double, double, double>});
} // namespace Aidge
#endif /* AIDGE_CUDA_OPERATOR_LSQIMPL_KERNELS_H_ */
......@@ -85,7 +85,6 @@ public:
static const std::vector<std::string> getOutputsName(){
return {"data_output"};
}
};
/**
......
......@@ -36,7 +36,7 @@ namespace Aidge
* @param inputDataSet The input dataset, consisting of a vector of input samples.
* @return A map associating each node name to it's corresponding activation histogram.
*/
std::map<std::string, std::vector<int>> computeHistograms(std::map<std::string, float> valueRanges, int nbBins, std::shared_ptr<GraphView> graphView, std::vector<std::shared_ptr<Tensor>> inputDataSet, bool useCuda);
std::map<std::string, std::vector<int>> computeHistograms(std::map<std::string, float> valueRanges, int nbBins, std::shared_ptr<GraphView> graphView, std::vector<std::shared_ptr<Tensor>> inputDataSet);
/**
* @brief Given an input activation histogram, compute the optimal clipping value in the sense of the Lp norm.
......@@ -67,7 +67,7 @@ namespace Aidge
* @param verbose Whether to print the clipping values or not.
* @return The corrected map associating each provided node to its clipped range.
*/
std::map<std::string, float> adjustRanges(Clipping clippingMode, std::map<std::string, float> valueRanges, std::uint8_t nbBits, std::shared_ptr<GraphView> graphView, std::vector<std::shared_ptr<Tensor>> inputDataSet, bool useCuda, bool verbose);
std::map<std::string, float> adjustRanges(Clipping clippingMode, std::map<std::string, float> valueRanges, std::uint8_t nbBits, std::shared_ptr<GraphView> graphView, std::vector<std::shared_ptr<Tensor>> inputDataSet, bool verbose);
}
......
......@@ -31,7 +31,7 @@ namespace Aidge {
/**
* @brief Set of the types of the nodes which does not affect the PTQ process
*/
static const std::set<std::string> seamlessNodeTypes({"LeakyReLU", "Pad2D", "MaxPooling2D", "AvgPooling2D", "PaddedMaxPooling2D", "PaddedAvgPooling2D", "GlobalAveragePooling", "Reshape", "Transpose", "Gather"});
static const std::set<std::string> seamlessNodeTypes({"Pad2D", "MaxPooling2D", "AvgPooling2D", "PaddedMaxPooling2D", "PaddedAvgPooling2D", "GlobalAveragePooling", "Reshape", "Transpose", "Gather"});
/**
* @brief Set of the types of the nodes that merge multiple branches into one
......@@ -98,7 +98,7 @@ namespace Aidge {
* @param scalingNodesOnly Whether to restrain the retreival of the ranges to scaling nodes only or not.
* @return A map associating each affine node name to it's corresponding output range.
*/
std::map<std::string, float> computeRanges(std::shared_ptr<GraphView> graphView, std::vector<std::shared_ptr<Tensor>> inputDataSet, bool scalingNodesOnly, bool useCuda);
std::map<std::string, float> computeRanges(std::shared_ptr<GraphView> graphView, std::vector<std::shared_ptr<Tensor>> inputDataSet, bool scalingNodesOnly);
/**
* @brief Normalize the activations of each affine node so that they fit in the [-1:1] range.
......@@ -138,7 +138,7 @@ namespace Aidge {
* @param singleShift Whether to convert the scaling factors into powers of two. If true the approximations are compensated using the previous nodes weights.
* @param verbose Whether to print internal informations about the quantization process.
*/
void quantizeNetwork(std::shared_ptr<GraphView> graphView, std::uint8_t nbBits, std::vector<std::shared_ptr<Tensor>> inputDataSet, Clipping clippingMode, bool applyRounding, bool optimizeSigns, bool singleShift, bool useCuda, bool verbose);
void quantizeNetwork(std::shared_ptr<GraphView> graphView, std::uint8_t nbBits, std::vector<std::shared_ptr<Tensor>> inputDataSet, Clipping clippingMode, bool applyRounding, bool optimizeSigns, bool singleShift, bool verbose);
/**
* @brief Compute the weight ranges of every affine node. Provided for debugging purposes.
......
/********************************************************************************
* 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_QUANTIZATION_QUANTRECIPES_H_
#define AIDGE_QUANTIZATION_QUANTRECIPES_H_
#include "aidge/data/Tensor.hpp"
#include "aidge/graph/GraphView.hpp"
namespace Aidge
{
/**
* @brief Remove all the SoftMax leaf nodes of a GraphView.
* @param graphView The GraphView to process.
*/
void popSoftMax(std::shared_ptr<GraphView> graphView);
/**
* @brief Insert a BatchNorm node after every Convolutional node of a GraphView
* @param graphView The GraphView to process.
*/
void insertBatchNormNodes(std::shared_ptr<GraphView> graphView);
/**
* @brief Given a base name, create a node name that is unique in a considered GraphView
* @param graphView The GraphView to process.
*/
std::string makeUniqueName(std::string baseName, std::shared_ptr<GraphView> graphView);
/**
* @brief Given a GraphView, ensure that each node name is unique
* @param graphView The GraphView to process.
*/
void sanitizeNodeNames(std::shared_ptr<GraphView> graphView);
}
#endif /* AIDGE_QUANTIZATION_QUANTRECIPES_H_ */
......@@ -15,9 +15,6 @@
#include "aidge/operator/LSQ.hpp"
#include "aidge/operator/OperatorTensor.hpp"
//#include "aidge/backend/cuda/operator/LSQImpl.hpp"
//#include "aidge/backend/cuda/operator/LSQImpl_CUDA_kernels.hpp"
namespace py = pybind11;
namespace Aidge {
......
......@@ -14,10 +14,11 @@
#include <string>
#include "aidge/quantization/PTQ/Clipping.hpp"
#include "aidge/quantization/PTQ/Clip.hpp"
#include "aidge/quantization/PTQ/CLE.hpp"
#include "aidge/quantization/PTQ/PTQ.hpp"
#include "aidge/hook/Hook.hpp"
#include "aidge/graph/GraphView.hpp"
namespace py = pybind11;
......@@ -55,7 +56,7 @@ void init_PTQ(py::module &m) {
:type network: :py:class:`aidge_core.GraphView`
)mydelimiter");
m.def("compute_ranges", &computeRanges, py::arg("network"), py::arg("input_dataset"), py::arg("scaling_nodes_only"), py::arg("use_cuda"),
m.def("compute_ranges", &computeRanges, py::arg("network"), py::arg("input_dataset"), py::arg("scaling_nodes_only"),
R"mydelimiter(
Compute the activation ranges of every affine node, given an input dataset.
:param network: The GraphView containing the affine nodes, on which the inferences are performed.
......@@ -93,8 +94,8 @@ void init_PTQ(py::module &m) {
:type verbose: bool
)mydelimiter");
m.def("quantize_network", &quantizeNetwork ,py::arg("network"), py::arg("nb_bits"), py::arg("input_dataset"), py::arg("clipping_mode") = Clipping::MAX , py::arg("apply_rounding") = true, py::arg("optimize_signs") = false, py::arg("single_shift") = false, py::arg("use_cuda"), py::arg("verbose") = false,
R"mydelimiter(
m.def("quantize_network", &quantizeNetwork ,py::arg("network"), py::arg("nb_bits"), py::arg("input_dataset"), py::arg("clipping_mode") = Clipping::MAX, py::arg("apply_rounding") = true, py::arg("optimize_signs") = false, py::arg("single_shift") = false, py::arg("verbose") = false,
R"mydelimiter(
Main quantization routine. Performs every step of the quantization pipeline.
:param network: The GraphView to be quantized.
:type network: :py:class:`aidge_core.GraphView`
......@@ -114,7 +115,7 @@ void init_PTQ(py::module &m) {
:type verbose: bool
)mydelimiter");
m.def("compute_histograms", &computeHistograms, py::arg("value_ranges"), py::arg("nb_bins"), py::arg("network"), py::arg("input_dataset"), py::arg("use_cuda"),
m.def("compute_histograms", &computeHistograms, py::arg("value_ranges"), py::arg("nb_bins"), py::arg("network"), py::arg("input_dataset"),
R"mydelimiter(
Compute the histograms of the activations of each node contained in the map of the ranges (passed as argument).
:param value_ranges: A map associating each considered node name to its corresponding output range.
......@@ -153,7 +154,7 @@ void init_PTQ(py::module &m) {
:rtype: float
)mydelimiter");
m.def("adjust_ranges", &adjustRanges, py::arg("clipping_mode"), py::arg("value_ranges"), py::arg("nb_bits"), py::arg("network"), py::arg("input_dataset"), py::arg("use_cuda"), py::arg("verbose") = false,
m.def("adjust_ranges", &adjustRanges, py::arg("clipping_mode"), py::arg("value_ranges"), py::arg("nb_bits"), py::arg("network"), py::arg("input_dataset"), py::arg("verbose") = false,
R"mydelimiter(
Return a corrected map of the provided activation ranges.
To do so compute the optimal clipping values for every node and multiply the input ranges by those values.
......
......@@ -13,6 +13,7 @@
#include <pybind11/stl.h>
#include "aidge/quantization/QAT/QAT_FixedQ.hpp"
#include "aidge/hook/Hook.hpp"
#include "aidge/graph/GraphView.hpp"
namespace py = pybind11;
......
......@@ -13,6 +13,7 @@
#include <pybind11/stl.h>
#include "aidge/quantization/QAT/QAT_LSQ.hpp"
#include "aidge/hook/Hook.hpp"
#include "aidge/graph/GraphView.hpp"
namespace py = pybind11;
......
......@@ -13,10 +13,7 @@
#include <pybind11/stl.h>
#include "aidge/backend/QuantizationCPU.hpp"
#ifdef CUDA_COMPILER_VERSION
#include "aidge/backend/QuantizationCUDA.hpp"
#endif
//#include "aidge/backend/QuantizationCUDA.hpp"
namespace py = pybind11;
......@@ -29,11 +26,11 @@ void init_LSQ(py::module& m);
void init_TanhClamp(py::module& m);
void init_DoReFa(py::module& m);
// quantization routines
void init_PTQ(py::module &m);
void init_QAT_FixedQ(py::module &m);
void init_QAT_LSQ(py::module &m);
void init_QuantRecipes(py::module &m);
PYBIND11_MODULE(aidge_quantization, m)
......@@ -46,7 +43,6 @@ PYBIND11_MODULE(aidge_quantization, m)
init_PTQ(m);
init_QAT_FixedQ(m);
init_QAT_LSQ(m);
init_QuantRecipes(m);
}
} // namespace Aidge
/********************************************************************************
* 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 <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include "aidge/recipes/QuantRecipes.hpp"
//#include "aidge/hook/Hook.hpp"
#include "aidge/graph/GraphView.hpp"
namespace py = pybind11;
namespace Aidge {
void init_QuantRecipes(py::module &m) {
m.def("pop_softmax", &popSoftMax, py::arg("network"));
m.def("insert_batchnorm_nodes", &insertBatchNormNodes, py::arg("network"));
m.def("sanitize_node_names", &sanitizeNodeNames, py::arg("network"));
}
} // namespace Aidge
......@@ -10,7 +10,7 @@
********************************************************************************/
#include "aidge/quantization/PTQ/CLE.hpp"
#include "aidge/quantization/PTQ/Clipping.hpp"
#include "aidge/quantization/PTQ/Clip.hpp"
#include "aidge/quantization/PTQ/PTQ.hpp"
#include "aidge/graph/GraphView.hpp"
......
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