Skip to content

Commit 2663991

Browse files
committed
Added mcg59 engine
1 parent 378d958 commit 2663991

File tree

12 files changed

+98
-15
lines changed

12 files changed

+98
-15
lines changed

dpnp/backend/extensions/rng/device/dispatch/table_builder.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ class Dispatch3DTableBuilder
7979

8080
void populate(funcPtrT table[][_no_of_types][_no_of_methods]) const
8181
{
82-
const auto map_by_engine = {table_per_type_and_method<mkl_rng_dev::mrg32k3a<8>>()};
82+
const auto map_by_engine = {table_per_type_and_method<mkl_rng_dev::mrg32k3a<8>>(),
83+
table_per_type_and_method<mkl_rng_dev::mcg59<8>>()};
8384
assert(map_by_engine.size() == _no_of_engines);
8485

8586
std::uint16_t engine_id = 0;

dpnp/backend/extensions/rng/device/engine/engine_base.hpp renamed to dpnp/backend/extensions/rng/device/engine/base_engine.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class EngineType {
3434
public:
3535
enum Type : std::uint8_t {
3636
MRG32k3a = 0,
37+
MCG59,
3738
Base, // must be the last always
3839
};
3940

dpnp/backend/extensions/rng/device/engine/builder/base.hpp renamed to dpnp/backend/extensions/rng/device/engine/builder/base_builder.hpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@
2525

2626
#pragma once
2727

28-
#include "engine_base.hpp"
28+
#include "base_engine.hpp"
29+
30+
// TODO: remove the include once issue in MKL is resolved
31+
#include <oneapi/mkl/rng/device.hpp>
32+
namespace mkl_rng_dev = oneapi::mkl::rng::device;
2933

3034

3135
namespace dpnp::backend::ext::rng::device::engine::builder
@@ -71,7 +75,13 @@ class BaseBuilder {
7175
{
7276
switch (no_of_seeds) {
7377
case 1: {
74-
return EngineT({seeds[0]}, {offsets[0]});
78+
if constexpr (std::is_same_v<EngineT, mkl_rng_dev::mcg59<8>>) {
79+
// issue with mcg59<>() constructor which breaks compilation
80+
return EngineT(seeds[0], offsets[0]);
81+
}
82+
else {
83+
return EngineT({seeds[0]}, offsets[0]);
84+
}
7585
}
7686
// TODO: implement full switch
7787
default:
@@ -84,7 +94,13 @@ class BaseBuilder {
8494
{
8595
switch (no_of_seeds) {
8696
case 1: {
87-
return EngineT({seeds[0]}, offset);
97+
if constexpr (std::is_same_v<EngineT, mkl_rng_dev::mcg59<8>>) {
98+
// issue with mcg59<>() constructor which breaks compilation
99+
return EngineT(seeds[0], offsets[0]);
100+
}
101+
else {
102+
return EngineT({seeds[0]}, {offset});
103+
}
88104
}
89105
// TODO: implement full switch
90106
default:

dpnp/backend/extensions/rng/device/engine/builder/mcg31m1.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727

2828
#include <oneapi/mkl/rng/device.hpp>
2929

30-
#include "engine_base.hpp"
31-
#include "base.hpp"
30+
#include "base_engine.hpp"
31+
#include "base_builder.hpp"
3232

3333
namespace dpnp::backend::ext::rng::device::engine::builder
3434
{

dpnp/backend/extensions/rng/device/engine/builder/mcg59.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727

2828
#include <oneapi/mkl/rng/device.hpp>
2929

30-
#include "engine_base.hpp"
31-
#include "base.hpp"
30+
#include "base_engine.hpp"
31+
#include "base_builder.hpp"
3232

3333
namespace dpnp::backend::ext::rng::device::engine::builder
3434
{

dpnp/backend/extensions/rng/device/engine/builder/mrg32k3a.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727

2828
#include <oneapi/mkl/rng/device.hpp>
2929

30-
#include "engine_base.hpp"
31-
#include "base.hpp"
30+
#include "base_engine.hpp"
31+
#include "base_builder.hpp"
3232

3333
namespace dpnp::backend::ext::rng::device::engine::builder
3434
{

dpnp/backend/extensions/rng/device/engine/builder/philox4x32x10.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727

2828
#include <oneapi/mkl/rng/device.hpp>
2929

30-
#include "engine_base.hpp"
31-
#include "base.hpp"
30+
#include "base_engine.hpp"
31+
#include "base_builder.hpp"
3232

3333
namespace dpnp::backend::ext::rng::device::engine::builder
3434
{
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
//*****************************************************************************
2+
// Copyright (c) 2024, Intel Corporation
3+
// All rights reserved.
4+
//
5+
// Redistribution and use in source and binary forms, with or without
6+
// modification, are permitted provided that the following conditions are met:
7+
// - Redistributions of source code must retain the above copyright notice,
8+
// this list of conditions and the following disclaimer.
9+
// - Redistributions in binary form must reproduce the above copyright notice,
10+
// this list of conditions and the following disclaimer in the documentation
11+
// and/or other materials provided with the distribution.
12+
//
13+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
14+
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15+
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16+
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
17+
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18+
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19+
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20+
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21+
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22+
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23+
// THE POSSIBILITY OF SUCH DAMAGE.
24+
//*****************************************************************************
25+
26+
#pragma once
27+
28+
#include "base_engine.hpp"
29+
30+
31+
namespace dpnp::backend::ext::rng::device::engine
32+
{
33+
class MCG59 : public EngineBase {
34+
private:
35+
sycl::queue q_;
36+
std::vector<std::uint64_t> seed_vec;
37+
std::vector<std::uint64_t> offset_vec;
38+
39+
public:
40+
MCG59(sycl::queue &q, std::uint32_t seed, std::uint64_t offset = 0) : q_(q) {
41+
seed_vec.push_back(seed);
42+
offset_vec.push_back(offset);
43+
}
44+
45+
sycl::queue &get_queue() override {
46+
return q_;
47+
}
48+
49+
virtual EngineType get_type() const noexcept override {
50+
return EngineType::MCG59;
51+
}
52+
53+
virtual std::vector<std::uint64_t> get_seeds() const noexcept override {
54+
return seed_vec;
55+
}
56+
57+
virtual std::vector<std::uint64_t> get_offsets() const noexcept override {
58+
return offset_vec;
59+
}
60+
};
61+
} // dpnp::backend::ext::rng::device::engine

dpnp/backend/extensions/rng/device/engine/mrg32k3a_engine.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
#pragma once
2727

28-
#include "engine_base.hpp"
28+
#include "base_engine.hpp"
2929

3030

3131
namespace dpnp::backend::ext::rng::device::engine

dpnp/backend/extensions/rng/device/gaussian.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
#include "common_impl.hpp"
3737
#include "gaussian.hpp"
3838

39-
#include "engine/engine_base.hpp"
39+
#include "engine/base_engine.hpp"
4040
#include "engine/builder/builder.hpp"
4141

4242
#include "dispatch/matrix.hpp"

0 commit comments

Comments
 (0)