-
Notifications
You must be signed in to change notification settings - Fork 163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RNG] Add mcg59 #152
base: develop
Are you sure you want to change the base?
[RNG] Add mcg59 #152
Changes from 1 commit
722c312
7382d38
28f8bde
a04b09d
f50b2c2
cd6a555
a8861e7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -210,6 +210,77 @@ class mrg32k3a { | |
const std::vector<sycl::event>& dependencies); | ||
}; | ||
|
||
// Class oneapi::mkl::rng::mcg59 | ||
// | ||
// Represents Mcg59 counter-based pseudorandom number generator | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should here be MCG59, not Mcg59? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
// | ||
// Supported parallelization methods: | ||
// leapfrog | ||
class mcg59 { | ||
public: | ||
static constexpr std::uint64_t default_seed = 0; | ||
|
||
mcg59(sycl::queue queue, std::uint64_t seed = default_seed) | ||
: pimpl_(detail::create_mcg59(get_device_id(queue), queue, seed)) {} | ||
|
||
#ifdef ENABLE_MKLCPU_BACKEND | ||
mcg59(backend_selector<backend::mklcpu> selector, std::uint64_t seed = default_seed) | ||
: pimpl_(mklcpu::create_mcg59(selector.get_queue(), seed)) {} | ||
|
||
#endif | ||
|
||
#ifdef ENABLE_MKLGPU_BACKEND | ||
mcg59(backend_selector<backend::mklgpu> selector, std::uint64_t seed = default_seed) | ||
: pimpl_(mklgpu::create_mcg59(selector.get_queue(), seed)) {} | ||
|
||
#endif | ||
|
||
#ifdef ENABLE_CURAND_BACKEND | ||
mcg59(backend_selector<backend::curand> selector, std::uint64_t seed = default_seed) | ||
: pimpl_(curand::create_mcg59(selector.get_queue(), seed)) {} | ||
#endif | ||
|
||
mcg59(const mcg59& other) { | ||
pimpl_.reset(other.pimpl_.get()->copy_state()); | ||
} | ||
|
||
mcg59(mcg59&& other) { | ||
pimpl_ = std::move(other.pimpl_); | ||
} | ||
|
||
mcg59& operator=(const mcg59& other) { | ||
if (this == &other) | ||
return *this; | ||
pimpl_.reset(other.pimpl_.get()->copy_state()); | ||
return *this; | ||
} | ||
|
||
mcg59& operator=(mcg59&& other) { | ||
if (this == &other) | ||
return *this; | ||
pimpl_ = std::move(other.pimpl_); | ||
return *this; | ||
} | ||
|
||
private: | ||
std::unique_ptr<detail::engine_impl> pimpl_; | ||
|
||
template <typename Engine> | ||
friend void skip_ahead(Engine& engine, std::uint64_t num_to_skip); | ||
|
||
template <typename Engine> | ||
friend void leapfrog(Engine& engine, std::uint64_t idx, std::uint64_t stride); | ||
|
||
template <typename Distr, typename Engine> | ||
friend void generate(const Distr& distr, Engine& engine, std::int64_t n, | ||
sycl::buffer<typename Distr::result_type, 1>& r); | ||
|
||
template <typename Distr, typename Engine> | ||
friend sycl::event generate(const Distr& distr, Engine& engine, std::int64_t n, | ||
typename Distr::result_type* r, | ||
const std::vector<sycl::event>& dependencies); | ||
}; | ||
|
||
// Default engine to be used for common cases | ||
using default_engine = philox4x32x10; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/******************************************************************************* | ||
* cuRAND back-end Copyright (c) 2021, The Regents of the University of | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Am I right that we should have 2022? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
* California, through Lawrence Berkeley National Laboratory (subject to receipt | ||
* of any required approvals from the U.S. Dept. of Energy). All rights | ||
* reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* | ||
* (1) Redistributions of source code must retain the above copyright notice, | ||
* this list of conditions and the following disclaimer. | ||
* | ||
* (2) Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* (3) Neither the name of the University of California, Lawrence Berkeley | ||
* National Laboratory, U.S. Dept. of Energy nor the names of its contributors | ||
* may be used to endorse or promote products derived from this software | ||
* without specific prior written permission. | ||
* | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
* You are under no obligation whatsoever to provide any bug fixes, patches, | ||
* or upgrades to the features, functionality or performance of the source | ||
* code ("Enhancements") to anyone; however, if you choose to make your | ||
* Enhancements available either publicly, or directly to Lawrence Berkeley | ||
* National Laboratory, without imposing a separate written license agreement | ||
* for such Enhancements, then you hereby grant the following license: a | ||
* non-exclusive, royalty-free perpetual license to install, use, modify, | ||
* prepare derivative works, incorporate into other computer software, | ||
* distribute, and sublicense such enhancements or derivative works thereof, | ||
* in binary and source code form. | ||
* | ||
* If you have questions about your rights to use or distribute this software, | ||
* please contact Berkeley Lab's Intellectual Property Office at | ||
* [email protected]. | ||
* | ||
* NOTICE. This Software was developed under funding from the U.S. Department | ||
* of Energy and the U.S. Government consequently retains certain rights. As | ||
* such, the U.S. Government has been granted for itself and others acting on | ||
* its behalf a paid-up, nonexclusive, irrevocable, worldwide license in the | ||
* Software to reproduce, distribute copies to the public, prepare derivative | ||
* works, and perform publicly and display publicly, and to permit others to do | ||
* so. | ||
******************************************************************************/ | ||
|
||
#include <CL/sycl.hpp> | ||
#include <CL/sycl/backend/cuda.hpp> | ||
#include <iostream> | ||
|
||
#include "oneapi/mkl/rng/detail/engine_impl.hpp" | ||
// #include "oneapi/mkl/rng/engines.hpp" | ||
#include "curand_helper.hpp" | ||
#include "oneapi/mkl/exceptions.hpp" | ||
#include "oneapi/mkl/rng/detail/curand/onemkl_rng_curand.hpp" | ||
|
||
namespace oneapi { | ||
namespace mkl { | ||
namespace rng { | ||
namespace curand { | ||
/* | ||
* Note that cuRAND consists of two pieces: a host (CPU) API and a device (GPU) | ||
* API. The host API acts like any standard library; the `curand.h' header is | ||
* included and the functions can be called as usual. The generator is | ||
* instantiated on the host and random numbers can be generated on either the | ||
* host CPU or device. For device-side generation, calls to the library happen | ||
* on the host, but the actual work of RNG is done on the device. In this case, | ||
* the resulting random numbers are stored in global memory on the device. These | ||
* random numbers can then be used in other kernels or be copied back to the | ||
* host for further processing. For host-side generation, everything is done on | ||
* the host, and the random numbers are stored in host memory. | ||
* | ||
* The second piece is the device header, `curand_kernel.h'. Using this file | ||
* permits setting up random number generator states and generating sequences of | ||
* random numbers. This allows random numbers to be generated and immediately | ||
* consumed in other kernels without requiring the random numbers to be written | ||
* to, and read from, global memory. | ||
* | ||
* Here we utilize the host API since this is most aligned with how oneMKL | ||
* generates random numbers. | ||
* | ||
*/ | ||
|
||
oneapi::mkl::rng::detail::engine_impl* create_mcg59(sycl::queue queue, std::uint64_t seed) { | ||
throw oneapi::mkl::unimplemented("rng", "mcg59 engine"); | ||
return nullptr; | ||
} | ||
|
||
oneapi::mkl::rng::detail::engine_impl* create_mcg59( | ||
cl::sycl::queue queue, std::initializer_list<std::uint64_t> seed) { | ||
throw oneapi::mkl::unimplemented("rng", "mcg59 engine"); | ||
return nullptr; | ||
} | ||
|
||
} // namespace curand | ||
} // namespace rng | ||
} // namespace mkl | ||
} // namespace oneapi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cl::sycl::
is for SYCL 1.2.1. For SYCL 2020 we can use justsycl::
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think, as described in issue #149, using the sycl:: namespace is only SYCL conformant when the
sycl/sycl.hpp
header is included.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a PR from ROCK RAND. Will change after them merge