|
1 | 1 | //*****************************************************************************
|
2 |
| -// Copyright (c) 2016-2022, Intel Corporation |
| 2 | +// Copyright (c) 2022, Intel Corporation |
3 | 3 | // All rights reserved.
|
4 | 4 | //
|
5 | 5 | // Redistribution and use in source and binary forms, with or without
|
|
23 | 23 | // THE POSSIBILITY OF SUCH DAMAGE.
|
24 | 24 | //*****************************************************************************
|
25 | 25 |
|
| 26 | +/* |
| 27 | + * This header file is for interface Cython with C++. |
| 28 | + * It should not contains any backend specific headers (like SYCL or math library) because |
| 29 | + * all included headers will be exposed in Cython compilation procedure |
| 30 | + * |
| 31 | + * We would like to avoid backend specific things in higher level Cython modules. |
| 32 | + * Any backend interface functions and types should be defined here. |
| 33 | + * |
| 34 | + * Also, this file should contains documentation on functions and types |
| 35 | + * which are used in the interface |
| 36 | + */ |
| 37 | + |
26 | 38 | #pragma once
|
27 | 39 | #ifndef BACKEND_RANDOM_STATE_H // Cython compatibility
|
28 | 40 | #define BACKEND_RANDOM_STATE_H
|
29 | 41 |
|
30 |
| -#include <CL/sycl.hpp> |
31 |
| -#include <oneapi/mkl/rng.hpp> |
| 42 | +#ifdef _WIN32 |
| 43 | +#define INP_DLLEXPORT __declspec(dllexport) |
| 44 | +#else |
| 45 | +#define INP_DLLEXPORT |
| 46 | +#endif |
32 | 47 |
|
33 |
| -namespace mkl_rng = oneapi::mkl::rng; |
| 48 | +#include <dpctl_sycl_interface.h> |
34 | 49 |
|
35 | 50 | // Structure storing MKL engine for MT199374x32x10 algorithm
|
36 | 51 | struct mt19937_struct
|
37 | 52 | {
|
38 |
| - mkl_rng::mt19937* engine; |
| 53 | + void* engine; |
39 | 54 | };
|
40 | 55 |
|
41 | 56 | /**
|
42 |
| - * @brief Create a MKL engine from scalar seed |
| 57 | + * @ingroup BACKEND_API |
| 58 | + * @brief Create a MKL engine from scalar seed. |
43 | 59 | *
|
44 | 60 | * Invoke a common seed initialization of the engine for MT199374x32x10 algorithm.
|
| 61 | + * |
| 62 | + * @param [in] mt19937 A structure with MKL engine which will be filled with generated value by MKL. |
| 63 | + * @param [in] q_ref A refference on SYCL queue which will be used to obtain random numbers. |
| 64 | + * @param [in] seed An initial condition of the generator state. |
45 | 65 | */
|
46 |
| -void MT19937_InitScalarSeed(mt19937_struct *mt19937, DPCTLSyclQueueRef q_ref, uint32_t seed = 1) |
47 |
| -{ |
48 |
| - sycl::queue q = *(reinterpret_cast<sycl::queue *>(q_ref)); |
49 |
| - mt19937->engine = new mkl_rng::mt19937(q, seed); |
50 |
| - return; |
51 |
| -} |
| 66 | +INP_DLLEXPORT void MT19937_InitScalarSeed(mt19937_struct *mt19937, DPCTLSyclQueueRef q_ref, uint32_t seed = 1); |
52 | 67 |
|
53 | 68 | /**
|
54 |
| - * @brief Create a MKL engine from seed vector |
| 69 | + * @ingroup BACKEND_API |
| 70 | + * @brief Create a MKL engine from seed vector. |
55 | 71 | *
|
56 |
| - * Invoke an extended seed initialization of the engine for MT199374x32x10 algorithm. |
| 72 | + * Invoke an extended seed initialization of the engine for MT199374x32x10 algorithm.. |
57 | 73 | *
|
58 |
| - * @note the vector size is limited by length=3 |
| 74 | + * @param [in] mt19937 A structure with MKL engine which will be filled with generated value by MKL. |
| 75 | + * @param [in] q_ref A refference on SYCL queue which will be used to obtain random numbers. |
| 76 | + * @param [in] seed A vector with the initial conditions of the generator state. |
| 77 | + * @param [in] n Length of the vector. |
59 | 78 | */
|
60 |
| -void MT19937_InitVectorSeed(mt19937_struct *mt19937, DPCTLSyclQueueRef q_ref, uint32_t * seed, unsigned int n) { |
61 |
| - sycl::queue q = *(reinterpret_cast<sycl::queue *>(q_ref)); |
62 |
| - |
63 |
| - switch (n) { |
64 |
| - case 1: mt19937->engine = new mkl_rng::mt19937(q, {seed[0]}); break; |
65 |
| - case 2: mt19937->engine = new mkl_rng::mt19937(q, {seed[0], seed[1]}); break; |
66 |
| - case 3: mt19937->engine = new mkl_rng::mt19937(q, {seed[0], seed[1], seed[2]}); break; |
67 |
| - default: |
68 |
| - // TODO need to get rid of the limitation for seed vector length |
69 |
| - throw std::runtime_error("Too long seed vector"); |
70 |
| - } |
71 |
| - return; |
72 |
| -} |
| 79 | +INP_DLLEXPORT void MT19937_InitVectorSeed(mt19937_struct *mt19937, DPCTLSyclQueueRef q_ref, uint32_t * seed, unsigned int n); |
73 | 80 |
|
74 |
| -void MT19937_Delete(mt19937_struct *mt19937) { |
75 |
| - delete mt19937->engine; |
76 |
| - mt19937->engine = nullptr; |
77 |
| - return; |
78 |
| -} |
| 81 | +/** |
| 82 | + * @ingroup BACKEND_API |
| 83 | + * @brief Release a MKL engine. |
| 84 | + * |
| 85 | + * Release all resource required for storing of the MKL engine. |
| 86 | + * |
| 87 | + * @param [in] mt19937 A structure with the MKL engine. |
| 88 | + */ |
| 89 | +INP_DLLEXPORT void MT19937_Delete(mt19937_struct *mt19937); |
79 | 90 |
|
80 | 91 | #endif // BACKEND_RANDOM_STATE_H
|
0 commit comments