-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
81d7dfe
commit acb6e4c
Showing
23 changed files
with
780 additions
and
8 deletions.
There are no files selected for viewing
182 changes: 182 additions & 0 deletions
182
cpp/daal/include/algorithms/engines/mrg32k3a/mrg32k3a.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,182 @@ | ||
/* file: mrg32k3a.h */ | ||
/******************************************************************************* | ||
* Copyright 2024 Intel Corporation | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*******************************************************************************/ | ||
|
||
/* | ||
//++ | ||
// Implementation of the Mersenne Twister engine in the batch processing mode | ||
//-- | ||
*/ | ||
|
||
#ifndef __MRG32K3A_H__ | ||
#define __MRG32K3A_H__ | ||
|
||
#include "algorithms/engines/mrg32k3a/mrg32k3a_types.h" | ||
#include "algorithms/engines/engine.h" | ||
|
||
namespace daal | ||
{ | ||
namespace algorithms | ||
{ | ||
namespace engines | ||
{ | ||
namespace mrg32k3a | ||
{ | ||
/** | ||
* @defgroup engines_mrg32k3a_batch Batch | ||
* @ingroup engines_mrg32k3a | ||
* @{ | ||
*/ | ||
namespace interface1 | ||
{ | ||
/** | ||
* <a name="DAAL-CLASS-ALGORITHMS__ENGINES__mrg32k3a__BATCHCONTAINER"></a> | ||
* \brief Provides methods to run implementations of the mrg32k3a engine. | ||
* This class is associated with the \ref mrg32k3a::interface1::Batch "mrg32k3a::Batch" class | ||
* and supports the method of mrg32k3a engine computation in the batch processing mode | ||
* | ||
* \tparam algorithmFPType Data type to use in intermediate computations of mrg32k3a engine, double or float | ||
* \tparam method Computation method of the engine, mrg32k3a::Method | ||
* \tparam cpu Version of the cpu-specific implementation of the engine, daal::CpuType | ||
*/ | ||
template <typename algorithmFPType, Method method, CpuType cpu> | ||
class BatchContainer : public daal::algorithms::AnalysisContainerIface<batch> | ||
{ | ||
public: | ||
/** | ||
* Constructs a container for the mrg32k3a engine with a specified environment | ||
* in the batch processing mode | ||
* \param[in] daalEnv Environment object | ||
*/ | ||
BatchContainer(daal::services::Environment::env * daalEnv); | ||
~BatchContainer(); | ||
/** | ||
* Computes the result of the mrg32k3a engine in the batch processing mode | ||
* | ||
* \return Status of computations | ||
*/ | ||
services::Status compute() DAAL_C11_OVERRIDE; | ||
}; | ||
|
||
/** | ||
* <a name="DAAL-CLASS-ALGORITHMS__ENGINES__mrg32k3a__BATCH"></a> | ||
* \brief Provides methods for mrg32k3a engine computations in the batch processing mode | ||
* | ||
* \tparam algorithmFPType Data type to use in intermediate computations of mrg32k3a engine, double or float | ||
* \tparam method Computation method of the engine, mrg32k3a::Method | ||
* | ||
* \par Enumerations | ||
* - mrg32k3a::Method Computation methods for the mrg32k3a engine | ||
* | ||
* \par References | ||
* - \ref engines::interface1::Input "engines::Input" class | ||
* - \ref engines::interface1::Result "engines::Result" class | ||
*/ | ||
template <typename algorithmFPType = DAAL_ALGORITHM_FP_TYPE, Method method = defaultDense> | ||
class DAAL_EXPORT Batch : public engines::BatchBase | ||
{ | ||
public: | ||
typedef engines::BatchBase super; | ||
|
||
typedef typename super::InputType InputType; | ||
typedef typename super::ResultType ResultType; | ||
|
||
/** | ||
* Creates mrg32k3a engine | ||
* \param[in] seed Initial condition for mrg32k3a engine | ||
* | ||
* \return Pointer to mrg32k3a engine | ||
*/ | ||
static services::SharedPtr<Batch<algorithmFPType, method> > create(size_t seed = 777); | ||
|
||
/** | ||
* Returns method of the engine | ||
* \return Method of the engine | ||
*/ | ||
virtual int getMethod() const DAAL_C11_OVERRIDE { return (int)method; } | ||
|
||
/** | ||
* Returns the structure that contains results of mrg32k3a engine | ||
* \return Structure that contains results of mrg32k3a engine | ||
*/ | ||
ResultPtr getResult() { return _result; } | ||
|
||
/** | ||
* Registers user-allocated memory to store results of mrg32k3a engine | ||
* \param[in] result Structure to store results of mrg32k3a engine | ||
* | ||
* \return Status of computations | ||
*/ | ||
services::Status setResult(const ResultPtr & result) | ||
{ | ||
DAAL_CHECK(result, services::ErrorNullResult) | ||
_result = result; | ||
_res = _result.get(); | ||
return services::Status(); | ||
} | ||
|
||
/** | ||
* Returns a pointer to the newly allocated mrg32k3a engine | ||
* with a copy of input objects and parameters of this mrg32k3a engine | ||
* \return Pointer to the newly allocated engine | ||
*/ | ||
services::SharedPtr<Batch<algorithmFPType, method> > clone() const { return services::SharedPtr<Batch<algorithmFPType, method> >(cloneImpl()); } | ||
|
||
/** | ||
* Allocates memory to store the result of the mrg32k3a engine | ||
* | ||
* \return Status of computations | ||
*/ | ||
virtual services::Status allocateResult() DAAL_C11_OVERRIDE | ||
{ | ||
services::Status s = this->_result->template allocate<algorithmFPType>(&(this->input), NULL, (int)method); | ||
this->_res = this->_result.get(); | ||
return s; | ||
} | ||
|
||
protected: | ||
Batch(size_t seed = 777) { initialize(); } | ||
|
||
Batch(const Batch<algorithmFPType, method> & other) : super(other) { initialize(); } | ||
|
||
virtual Batch<algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE { return new Batch<algorithmFPType, method>(*this); } | ||
|
||
void initialize() | ||
{ | ||
Analysis<batch>::_ac = new __DAAL_ALGORITHM_CONTAINER(batch, BatchContainer, algorithmFPType, method)(&_env); | ||
_in = &input; | ||
_result.reset(new ResultType()); | ||
} | ||
|
||
private: | ||
ResultPtr _result; | ||
|
||
Batch & operator=(const Batch &); | ||
}; | ||
typedef services::SharedPtr<Batch<> > mrg32k3aPtr; | ||
typedef services::SharedPtr<const Batch<> > mrg32k3aConstPtr; | ||
|
||
} // namespace interface1 | ||
using interface1::BatchContainer; | ||
using interface1::Batch; | ||
using interface1::mrg32k3aPtr; | ||
using interface1::mrg32k3aConstPtr; | ||
/** @} */ | ||
} // namespace mrg32k3a | ||
} // namespace engines | ||
} // namespace algorithms | ||
} // namespace daal | ||
#endif |
64 changes: 64 additions & 0 deletions
64
cpp/daal/include/algorithms/engines/mrg32k3a/mrg32k3a_types.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* file: mrg32k3a_types.h */ | ||
/******************************************************************************* | ||
* Copyright 2014 Intel Corporation | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*******************************************************************************/ | ||
|
||
/* | ||
//++ | ||
// Implementation of mrg32k3a engine. | ||
//-- | ||
*/ | ||
|
||
#ifndef __MRG32K3A_TYPES_H__ | ||
#define __MRG32K3A_TYPES_H__ | ||
|
||
#include "algorithms/algorithm.h" | ||
#include "services/daal_defines.h" | ||
#include "data_management/data/numeric_table.h" | ||
#include "data_management/data/homogen_numeric_table.h" | ||
|
||
namespace daal | ||
{ | ||
namespace algorithms | ||
{ | ||
namespace engines | ||
{ | ||
/** | ||
* @defgroup engines_mrg32k3a mrg32k3a Engine | ||
* \copydoc daal::algorithms::engines::mrg32k3a | ||
* @ingroup engines | ||
* @{ | ||
*/ | ||
/** | ||
* \brief Contains classes for mrg32k3a engine | ||
*/ | ||
namespace mrg32k3a | ||
{ | ||
/** | ||
* <a name="DAAL-ENUM-ALGORITHMS__ENGINES__mrg32k3a__METHOD"></a> | ||
* Available methods to compute mrg32k3a engine | ||
*/ | ||
enum Method | ||
{ | ||
defaultDense = 0 /*!< Default: performance-oriented method. */ | ||
}; | ||
|
||
} // namespace mrg32k3a | ||
/** @} */ | ||
} // namespace engines | ||
} // namespace algorithms | ||
} // namespace daal | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* file: mrg32k3a.cpp */ | ||
/******************************************************************************* | ||
* Copyright 2014 Intel Corporation | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*******************************************************************************/ | ||
|
||
//++ | ||
// Implementation of mrg32k3a engine | ||
//-- | ||
|
||
#include "algorithms/engines/mrg32k3a/mrg32k3a.h" | ||
#include "src/externals/service_dispatch.h" | ||
#include "src/algorithms/engines/mrg32k3a/mrg32k3a_batch_impl.h" | ||
|
||
namespace daal | ||
{ | ||
namespace algorithms | ||
{ | ||
namespace engines | ||
{ | ||
namespace mrg32k3a | ||
{ | ||
namespace interface1 | ||
{ | ||
using namespace daal::services; | ||
using namespace mrg32k3a::internal; | ||
|
||
template <typename algorithmFPType, Method method> | ||
SharedPtr<Batch<algorithmFPType, method> > Batch<algorithmFPType, method>::create(size_t seed) | ||
{ | ||
SharedPtr<Batch<algorithmFPType, method> > engPtr; | ||
#define DAAL_CREATE_ENGINE_CPU(cpuId, ...) engPtr.reset(new BatchImpl<cpuId, algorithmFPType, method>(__VA_ARGS__)); | ||
|
||
DAAL_DISPATCH_FUNCTION_BY_CPU(DAAL_CREATE_ENGINE_CPU, seed); | ||
|
||
#undef DAAL_CREATE_ENGINE_CPU | ||
return engPtr; | ||
} | ||
|
||
template class Batch<double, defaultDense>; | ||
template class Batch<float, defaultDense>; | ||
|
||
} // namespace interface1 | ||
} // namespace mrg32k3a | ||
} // namespace engines | ||
} // namespace algorithms | ||
} // namespace daal |
68 changes: 68 additions & 0 deletions
68
cpp/daal/src/algorithms/engines/mrg32k3a/mrg32k3a_batch_container.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* file: mrg32k3a_batch_container.h */ | ||
/******************************************************************************* | ||
* Copyright 2014 Intel Corporation | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*******************************************************************************/ | ||
|
||
/* | ||
//++ | ||
// Implementation of mrg32k3a calculation algorithm container. | ||
//-- | ||
*/ | ||
|
||
#ifndef __mrg32k3a_BATCH_CONTAINER_H__ | ||
#define __mrg32k3a_BATCH_CONTAINER_H__ | ||
|
||
#include "algorithms/engines/mrg32k3a/mrg32k3a.h" | ||
#include "src/algorithms/engines/mrg32k3a/mrg32k3a_kernel.h" | ||
|
||
namespace daal | ||
{ | ||
namespace algorithms | ||
{ | ||
namespace engines | ||
{ | ||
namespace mrg32k3a | ||
{ | ||
namespace interface1 | ||
{ | ||
template <typename algorithmFPType, Method method, CpuType cpu> | ||
BatchContainer<algorithmFPType, method, cpu>::BatchContainer(daal::services::Environment::env * daalEnv) : AnalysisContainerIface<batch>(daalEnv) | ||
{ | ||
__DAAL_INITIALIZE_KERNELS(internal::mrg32k3aKernel, algorithmFPType, method); | ||
} | ||
|
||
template <typename algorithmFPType, Method method, CpuType cpu> | ||
BatchContainer<algorithmFPType, method, cpu>::~BatchContainer() | ||
{ | ||
__DAAL_DEINITIALIZE_KERNELS(); | ||
} | ||
|
||
template <typename algorithmFPType, Method method, CpuType cpu> | ||
services::Status BatchContainer<algorithmFPType, method, cpu>::compute() | ||
{ | ||
daal::services::Environment::env & env = *_env; | ||
engines::Result * result = static_cast<engines::Result *>(_res); | ||
NumericTable * resultTable = result->get(engines::randomNumbers).get(); | ||
|
||
__DAAL_CALL_KERNEL(env, internal::mrg32k3aKernel, __DAAL_KERNEL_ARGUMENTS(algorithmFPType, method), compute, resultTable); | ||
} | ||
|
||
} // namespace interface1 | ||
} // namespace mrg32k3a | ||
} // namespace engines | ||
} // namespace algorithms | ||
} // namespace daal | ||
|
||
#endif |
Oops, something went wrong.