Skip to content

Commit

Permalink
Add CPU parts of the performance-related hyperparameters logic (#2461)
Browse files Browse the repository at this point in the history
* Fix incorrect include in service_hash_table.h file

* Add initial implementation of the base algorithm::Hyperparameter class

* clang-format

* Add Hyperparameter* _hpar field into base Algorithm and AlgorithmContainer classes

* Implement initial version of Hyperparameters class for Covariance algorithm in DAAL

* Extend covariance::BatchImpl (and thus covariance::Batch) interface with the Hyperparameter support

* Remove outdated verionst of setArgument methods

* Add ability to pass hyperparameters from DAAL API to kernels in Covariance algorithm

* 1. Make the hyperparameter field of DAAL Algorithm class constant. 2. Implement passing hyperparameters from oneDAL to DAAL on CPU

* Fix

* Fix Java build

* Move covariance::Hyperparameter class to covariance::internal namespace

* Removal of compression functionality (#2462)

* Temporary disabling gemv test (#2463)

* AVX/SSSE3/AVX512_MIC ISA cleanup (#2465)

* cleanup avx512_mic

* cleanup ssse3

* cleanup avx

* fixing typos

* fixing / typos

* fixing make typos

* clang format

* Updating ISA in install.md

* replace AVX with AVX2 for intersect

* Remove mention of compression in docs (#2467)

* Init addition of online interfaces in Covariance (#2455)

* Add the link to oneAPI samples browser (#2470)

* infra: update binary version (#2468)

* update binary version

* more binary version updates

* Initial input for backend selection (#2396)

* Initial input for backend selection

* Update dev/make/cmplr.gnu.mkl.mk

Co-authored-by: KulikovNikita <nikita.kulikov@intel.com>

* Update dev/make/cmplr.gnu.ref.mk

Co-authored-by: KulikovNikita <nikita.kulikov@intel.com>

* Changed default backend to 'mkl'

* Buildable onedal_c

* Added clang support

* Update dev/make/cmplr.gnu.mkl.mk

Co-authored-by: KulikovNikita <nikita.kulikov@intel.com>

* Update dev/make/cmplr.gnu.ref.mk

Co-authored-by: KulikovNikita <nikita.kulikov@intel.com>

* Compiler fixes for icc, icx, vc plus clang-format

* Update dev/make/cmplr.clang.ref.mk

Co-authored-by: KulikovNikita <nikita.kulikov@intel.com>

* adding support for selecting different math/rng/service backends in case of build with bazel

* fixed build issue with kmeans serialization

* Introducing backend_config param selection to build.sh

* Create openblas.sh

* Introduce CI build for BLAS backend

* adding execute permission on openblas.sh

* Update cpp/daal/src/externals/config_ref.h

Co-authored-by: Victoriya Fedotova <viktoria.nn@gmail.com>

* Update cpp/daal/src/externals/config_ref.h

Co-authored-by: Victoriya Fedotova <viktoria.nn@gmail.com>

* Addressed part of the comments

* Clang-format

* Turned off hyperthreadig for ref config in order to use TBB default number of threads

* Addressed more comments

* Macro fixed (APPLE)

* More changes in REF RNG

* Update build.sh

* Removed 'sed' from Makefile

* Update openblas.sh

* Removed config_template from BAZEL

* Removed backend_config_header from BAZEL

* Update openblas.sh

* Replaced safe function not supported by GNU

* Fixed bugs in ref backend for OpenBLAS build

* Fixed bugs in ref backend for OpenBLAS build #2

* Reduced header file dependencies in REF backend; removed << operator for RNG (compiling issue)

* Update ci.yml

* Fixed export on symbols for OpenBLAS build

* export.def handling in bazel

* Update cpp/daal/src/externals/service_math_ref.h

Co-authored-by: Pavel Yakovlev <p_yak_11@mail.ru>

* Added libfgortran to REF build

* removed config_template auxiliary func

* Removed libgfortran for REF backend

* Fixed BACKEND incdirs for oneAPI; addressed some comments

* Removed unnecessary includes; fixed ifdef in _DECLAR_ files

* fixed omitted ifdef in _DECLAR_ files

* Clang-format

* Clang-format fix

* Added an option to move compression to exclude list for examples

* Excluded compression examples for all configurations

* revert some macros to __intel_compiler

* replase some more macros

* add NO_FORTRAN=1 to openblas.sh script

* Update cpp/daal/src/externals/service_service_ref.h

* Fixed missed fpk symbols for oneapi examples (REF backend)

* Update cpp/daal/src/externals/service_service_ref.h

Co-authored-by: Pavel Yakovlev <p_yak_11@mail.ru>

* Update cpp/daal/src/externals/service_service_ref.h

Co-authored-by: Pavel Yakovlev <p_yak_11@mail.ru>

* Fixed error message in oneapi

* exclude failed examples with ref backend

* exclude examples for oneapi/cpp ifaces

* exclude mpi examples for ref backend

* Apply suggestions from code review

* AVX512_MIC cleanup

* Fixed CI pipeline

* Added more includes for ONEAPI

* Update .ci/pipeline/ci.yml

* Switch to core count for blas build

* Update .ci/env/openblas.sh

* Adding _MKL suffix for job name

* Fixing daal4py job dependency

* Attempt to fix warnings

---------

Co-authored-by: Aleksey Grigorev <a.grigorev@yadro.com>
Co-authored-by: KulikovNikita <nikita.kulikov@intel.com>
Co-authored-by: a.maklaev <a.maklae@yadro.com>
Co-authored-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
Co-authored-by: Victoriya Fedotova <viktoria.nn@gmail.com>
Co-authored-by: Pavel Yakovlev <p_yak_11@mail.ru>
Co-authored-by: Pavel Yakovlev <p.yakovlev@yadro.com>

* resolve merge conflict while rebasing in Fix incorrect include in service_hash_table.h file

* Add ability to pass hyperparameters from DAAL API to kernels in Covariance algorithm

* minor

* update examples

* clang-format

* minor

---------

Co-authored-by: Alexander Andreev <alexander.andreev@intel.com>
Co-authored-by: ethanglaser <42726565+ethanglaser@users.noreply.github.com>
Co-authored-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
Co-authored-by: Aleksandr Solovev <aleksandr.solovev@intel.com>
Co-authored-by: Alexandra <alexandra.epanchinzeva@intel.com>
Co-authored-by: amgrigoriev <majagalz@mail.ru>
Co-authored-by: Aleksey Grigorev <a.grigorev@yadro.com>
Co-authored-by: KulikovNikita <nikita.kulikov@intel.com>
Co-authored-by: a.maklaev <a.maklae@yadro.com>
Co-authored-by: Pavel Yakovlev <p_yak_11@mail.ru>
Co-authored-by: Pavel Yakovlev <p.yakovlev@yadro.com>
Co-authored-by: Md Shafiul Alam <md.shafiul.alam@intel.com>
Co-authored-by: msa <111298646+md-shafiul-alam@users.noreply.github.com>
  • Loading branch information
14 people authored Sep 1, 2023
1 parent 7c5fe5f commit c60a7ec
Show file tree
Hide file tree
Showing 24 changed files with 561 additions and 102 deletions.
14 changes: 12 additions & 2 deletions cpp/daal/include/algorithms/algorithm_base_mode.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Algorithm : public AlgorithmIfaceImpl
{
public:
/** Default constructor */
Algorithm() : _ac(0), _in(0), _pres(0), _res(0), _par(0) {}
Algorithm() : _ac(0), _in(0), _pres(0), _res(0), _par(0), _hpar(0) {}

virtual ~Algorithm()
{
Expand All @@ -75,6 +75,10 @@ class Algorithm : public AlgorithmIfaceImpl
*/
virtual services::Status checkFinalizeComputeParams() = 0;

const Hyperparameter * getBaseHyperparameter() { return _hpar; }

void setHyperparameter(const Hyperparameter * hpar) { _hpar = hpar; }

protected:
PartialResult * allocatePartialResultMemory()
{
Expand Down Expand Up @@ -111,6 +115,7 @@ class Algorithm : public AlgorithmIfaceImpl
PartialResult * _pres;
Result * _res;
Parameter * _par;
const Hyperparameter * _hpar;

private:
Algorithm(const Algorithm &);
Expand All @@ -128,7 +133,7 @@ class Algorithm<batch> : public AlgorithmIfaceImpl
{
public:
/** Default constructor */
Algorithm() : _ac(0), _par(0), _in(0), _res(0) {}
Algorithm() : _ac(0), _par(0), _in(0), _res(0), _hpar(0) {}

virtual ~Algorithm()
{
Expand All @@ -145,6 +150,10 @@ class Algorithm<batch> : public AlgorithmIfaceImpl

Parameter * getBaseParameter() { return _par; }

const Hyperparameter * getBaseHyperparameter() { return _hpar; }

void setHyperparameter(const Hyperparameter * hpar) { _hpar = hpar; }

protected:
services::Status allocateResultMemory()
{
Expand All @@ -160,6 +169,7 @@ class Algorithm<batch> : public AlgorithmIfaceImpl

daal::algorithms::AlgorithmContainerImpl<batch> * _ac;

const Hyperparameter * _hpar;
Parameter * _par;
Input * _in;
Result * _res;
Expand Down
5 changes: 4 additions & 1 deletion cpp/daal/include/algorithms/algorithm_container_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,14 @@ class AlgorithmContainerImpl : public AlgorithmContainer<mode>
* \param[in] in Pointer to the input arguments of the algorithm
* \param[in] pres Pointer to the partial results of the algorithm
* \param[in] par Pointer to the parameters of the algorithm
* \param[in] hpar Pointer to the hyperparameters of the algorithm
*/
void setArguments(Input * in, PartialResult * pres, Parameter * par)
void setArguments(Input * in, PartialResult * pres, Parameter * par, const Hyperparameter * hpar)
{
_in = in;
_pres = pres;
_par = par;
_hpar = hpar;
}

/**
Expand Down Expand Up @@ -204,6 +206,7 @@ class AlgorithmContainerImpl : public AlgorithmContainer<mode>
PartialResult * _pres;
Result * _res;
Parameter * _par;
const Hyperparameter * _hpar;
};

/** @} */
Expand Down
15 changes: 9 additions & 6 deletions cpp/daal/include/algorithms/algorithm_container_base_batch.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,14 @@ class AlgorithmContainerImpl<batch> : public AlgorithmContainer<batch>
* \param[in] in Pointer to the input arguments of the algorithm
* \param[in] res Pointer to the final results of the algorithm
* \param[in] par Pointer to the parameters of the algorithm
* \param[in] hpar Pointer to the hyperparameters of the algorithm
*/
void setArguments(Input * in, Result * res, Parameter * par)
void setArguments(Input * in, Result * res, Parameter * par, const Hyperparameter * hpar)
{
_in = in;
_par = par;
_res = res;
_in = in;
_par = par;
_res = res;
_hpar = hpar;
}

/**
Expand All @@ -124,6 +126,7 @@ class AlgorithmContainerImpl<batch> : public AlgorithmContainer<batch>
virtual services::Status resetCompute() DAAL_C11_OVERRIDE { return services::Status(); }

protected:
const Hyperparameter * _hpar;
Parameter * _par;
Input * _in;
Result * _res;
Expand Down Expand Up @@ -163,13 +166,13 @@ class DAAL_EXPORT AlgorithmDispatchContainer<batch, sse2Container DAAL_KERNEL_SS
services::internal::sycl::ExecutionContextIface & context = services::internal::getDefaultContext();
services::internal::sycl::InfoDevice & deviceInfo = context.getInfoDevice();
if (!daal::services::internal::isImplementedForDevice(deviceInfo, _cntr)) return services::Status(services::ErrorDeviceSupportNotImplemented);
_cntr->setArguments(this->_in, this->_res, this->_par);
_cntr->setArguments(this->_in, this->_res, this->_par, this->_hpar);
return _cntr->compute();
}

virtual services::Status setupCompute() DAAL_C11_OVERRIDE
{
_cntr->setArguments(this->_in, this->_res, this->_par);
_cntr->setArguments(this->_in, this->_res, this->_par, this->_hpar);
return _cntr->setupCompute();
}

Expand Down
6 changes: 3 additions & 3 deletions cpp/daal/include/algorithms/algorithm_container_base_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,20 @@ class DAAL_EXPORT AlgorithmDispatchContainer : public AlgorithmContainerImpl<mod
services::internal::sycl::ExecutionContextIface & context = services::internal::getDefaultContext();
services::internal::sycl::InfoDevice & deviceInfo = context.getInfoDevice();
if (!daal::services::internal::isImplementedForDevice(deviceInfo, _cntr)) return services::Status(services::ErrorDeviceSupportNotImplemented);
_cntr->setArguments(this->_in, this->_pres, this->_par);
_cntr->setArguments(this->_in, this->_pres, this->_par, this->_hpar);
return _cntr->compute();
}

virtual services::Status finalizeCompute() DAAL_C11_OVERRIDE
{
_cntr->setArguments(this->_in, this->_pres, this->_par);
_cntr->setArguments(this->_in, this->_pres, this->_par, this->_hpar);
_cntr->setResult(this->_res);
return _cntr->finalizeCompute();
}

virtual services::Status setupCompute() DAAL_C11_OVERRIDE
{
_cntr->setArguments(this->_in, this->_pres, this->_par);
_cntr->setArguments(this->_in, this->_pres, this->_par, this->_hpar);
_cntr->setResult(this->_res);
return _cntr->setupCompute();
}
Expand Down
114 changes: 114 additions & 0 deletions cpp/daal/include/algorithms/algorithm_types.h
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "data_management/data/data_serialize.h"
#include "data_management/data/data_collection.h"
#include "services/error_handling.h"
#include "services/daal_shared_ptr.h"

namespace daal
{
Expand Down Expand Up @@ -68,6 +69,117 @@ struct Parameter
virtual services::Status check() const { return services::Status(); }
};

/**
* \brief Implements the abstract interface HyperparameterIface.
* Represents the common interface for performance-related hyperparameters of the computation.
*/
struct DAAL_EXPORT HyperparameterIface
{
/**
* Sets integer hyperparameter into this structure
* \param[in] id Unique to the particular algorithm identifier of the hyperparameter
* \param[in] value The value of the hyperparameter
* \return Execution status
*/
virtual services::Status set(std::uint32_t id, std::int64_t value) = 0;

/**
* Sets double precision hyperparameter into this structure
* \param[in] id Unique to the particular algorithm identifier of the hyperparameter
* \param[in] value The value of the hyperparameter
* \return Execution status
*/
virtual services::Status set(std::uint32_t id, double value) = 0;

/**
* Finds integer hyperparameter in this structure
* \param[in] id Unique to the particular algorithm identifier of the hyperparameter
* \param[out] value The value of the hyperparameter
* \return Execution status.
* ErrorHyperparameterNotFound is returned if the 'id' of the hyperparameter cannot be foun
* in the structure.
*/
virtual services::Status find(std::uint32_t id, std::int64_t & value) const = 0;

/**
* Finds double precision hyperparameter in this structure
* \param[in] id Unique to the particular algorithm identifier of the hyperparameter
* \param[out] value The value of the hyperparameter
* \return Execution status.
* ErrorHyperparameterNotFound is returned if the 'id' of the hyperparameter cannot be foun
* in the structure.
*/
virtual services::Status find(std::uint32_t id, double & value) const = 0;

virtual ~HyperparameterIface() {}
};

/**
* \brief %Base class to represent the implementation of performance-related hyperparameters
* of the computation.
*/
struct HyperparameterBaseImpl : public HyperparameterIface
{};

/**
* \brief %Base class to represent performance-related hyperparameters of the computation.
* Algorithm-specific hyperparameters are represented as derivative classes
* of the Hyperparameter class.
*/
struct DAAL_EXPORT Hyperparameter : protected HyperparameterIface
{
DAAL_NEW_DELETE();

/**
* Constructs the requested number of performance-related hyperparameters for the algorithm
* \param[in] intParamCount Number of integer hyperparameters
* \param[in] doubleParamCount Number of double precision hyperparameters
*/
Hyperparameter(size_t intParamCount = 0, size_t doubleParamCount = 0);

virtual ~Hyperparameter() {}

protected:
/**
* Sets integer hyperparameter into this structure
* \param[in] id Unique to the particular algorithm identifier of the hyperparameter
* \param[in] value The value of the hyperparameter
* \return Execution status
*/
services::Status set(std::uint32_t id, std::int64_t value) final;

/**
* Sets double precision hyperparameter into this structure
* \param[in] id Unique to the particular algorithm identifier of the hyperparameter
* \param[in] value The value of the hyperparameter
* \return Execution status
*/
services::Status set(std::uint32_t id, double value) final;

/**
* Finds integer hyperparameter in this structure
* \param[in] id Unique to the particular algorithm identifier of the hyperparameter
* \param[out] value The value of the found hyperparameter
* \return Execution status.
* ErrorHyperparameterNotFound is returned if the 'id' of the hyperparameter cannot be foun
* in the structure.
*/
services::Status find(std::uint32_t id, std::int64_t & value) const final;

/**
* Finds double precision hyperparameter in this structure
* \param[in] id Unique to the particular algorithm identifier of the hyperparameter
* \param[out] value The value of the found hyperparameter
* \return Execution status.
* ErrorHyperparameterNotFound is returned if the 'id' of the hyperparameter cannot be foun
* in the structure.
*/
services::Status find(std::uint32_t id, double & value) const final;

/** Pointer to the implementation */
services::SharedPtr<HyperparameterBaseImpl> _pimpl;
};

/**
* <a name="DAAL-CLASS-ALGORITHMS__ARGUMENT"></a>
* \brief %Base class to represent computation input and output arguments.
Expand Down Expand Up @@ -409,6 +521,8 @@ typedef services::SharedPtr<OptionalArgument> OptionalArgumentPtr;

/** @} */
} // namespace interface1
using interface1::HyperparameterBaseImpl;
using interface1::Hyperparameter;
using interface1::Parameter;
using interface1::Argument;
using interface1::Input;
Expand Down
13 changes: 9 additions & 4 deletions cpp/daal/include/algorithms/covariance/covariance_batch.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ class DAAL_EXPORT BatchImpl : public daal::algorithms::Analysis<batch>
typedef algorithms::covariance::Result ResultType;

/** Default constructor */
BatchImpl() { initialize(); }
BatchImpl() : daal::algorithms::Analysis<batch>() { initialize(); }

/**
* Constructs an algorithm for correlation or variance-covariance matrix computation
Expand All @@ -265,7 +265,11 @@ class DAAL_EXPORT BatchImpl : public daal::algorithms::Analysis<batch>
* \param[in] other An algorithm to be used as the source to initialize the input objects
* and parameters of the algorithm
*/
BatchImpl(const BatchImpl & other) : input(other.input), parameter(other.parameter) { initialize(); }
BatchImpl(const BatchImpl & other) : input(other.input), parameter(other.parameter)
{
initialize();
_hpar = other.daal::algorithms::Analysis<batch>::_hpar;
}

/**
* Returns the structure that contains correlation or variance-covariance matrix
Expand Down Expand Up @@ -304,8 +308,9 @@ class DAAL_EXPORT BatchImpl : public daal::algorithms::Analysis<batch>
void initialize()
{
_result.reset(new ResultType());
_in = &input;
_par = &parameter;
_in = &input;
_par = &parameter;
_hpar = nullptr;
}
virtual BatchImpl * cloneImpl() const DAAL_C11_OVERRIDE = 0;
};
Expand Down
4 changes: 3 additions & 1 deletion cpp/daal/include/services/error_indexes.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ enum ErrorDetailID
ActualValue = 18, /*!< Detail about actual value */
Sycl = 19, /*!< Detail about Sycl */
OpenCL = 20, /*!< Detail about actual OpenCL */
LevelZero = 21 /*!< Detail about actual LevelZero */
LevelZero = 21, /*!< Detail about actual LevelZero */
Key = 22 /*!< Detail about key */
};

/**
Expand Down Expand Up @@ -140,6 +141,7 @@ enum ErrorID
ErrorCloneMethodFailed = -78, /*!< Cloning of algorithm failed */
ErrorDataTypeNotSupported = -79, /*!< Data type not supported */
ErrorBufferSizeIntegerOverflow = -80, /*!< Integer oveflow is occured during buffer size calculation */
ErrorHyperparameterNotFound = -81, /*!< Cannot find a hyperparameter with a given id */

// Environment errors: -2000..-2999
ErrorCpuNotSupported = -2000, /*!< CPU not supported */
Expand Down
4 changes: 2 additions & 2 deletions cpp/daal/src/algorithms/algorithm_base_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ services::Status AlgorithmImpl<mode>::computeNoThrow()

DAAL_CHECK_MALLOC(this->allocatePartialResultMemory());

this->_ac->setArguments(this->_in, this->_pres, this->_par);
this->_ac->setArguments(this->_in, this->_pres, this->_par, this->_hpar);

if (this->isChecksEnabled())
{
Expand Down Expand Up @@ -226,7 +226,7 @@ services::Status AlgorithmImpl<batch>::computeNoThrow()
services::Status s = this->allocateResultMemory();
DAAL_CHECK_MALLOC(s);

this->_ac->setArguments(this->_in, this->_res, this->_par);
this->_ac->setArguments(this->_in, this->_res, this->_par, this->_hpar);

if (this->isChecksEnabled())
{
Expand Down
Loading

0 comments on commit c60a7ec

Please sign in to comment.