Skip to content

Commit

Permalink
clang format
Browse files Browse the repository at this point in the history
  • Loading branch information
andreyfe1 committed Sep 30, 2024
1 parent e4855c4 commit 0247c0d
Show file tree
Hide file tree
Showing 6 changed files with 185 additions and 170 deletions.
4 changes: 2 additions & 2 deletions include/oneapi/mkl/rng/device/detail/beta_impl.hpp
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ class distribution_base<oneapi::mkl::rng::device::beta<RealType, Method>> {
res = acc_rej_kernel<EngineType::vec_size>(res, engine);
}
if constexpr (std::is_same_v<Method, beta_method::cja_accurate>) {
for(std::int32_t i = 0; i < EngineType::vec_size; i++) {
for (std::int32_t i = 0; i < EngineType::vec_size; i++) {
if (res[i] < a_)
res[i] = a_;
if (res[i] > a_ + b_)
Expand All @@ -416,7 +416,7 @@ class distribution_base<oneapi::mkl::rng::device::beta<RealType, Method>> {
res = acc_rej_kernel<1>(z, engine);
}
if constexpr (std::is_same_v<Method, beta_method::cja_accurate>) {
for(std::int32_t i = 0; i < EngineType::vec_size; i++) {
for (std::int32_t i = 0; i < EngineType::vec_size; i++) {
if (res[i] < a_)
res[i] = a_;
if (res[i] > a_ + b_)
Expand Down
4 changes: 2 additions & 2 deletions include/oneapi/mkl/rng/device/detail/exponential_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class distribution_base<oneapi::mkl::rng::device::exponential<RealType, Method>>
if constexpr (EngineType::vec_size == 1) {
res = std::fmax(res, a_);
}
else{
else {
for (int i = 0; i < EngineType::vec_size; i++) {
res[i] = std::fmax(res[i], a_);
}
Expand All @@ -109,7 +109,7 @@ class distribution_base<oneapi::mkl::rng::device::exponential<RealType, Method>>
if constexpr (EngineType::vec_size == 1) {
res = std::fmax(res, a_);
}
else{
else {
for (int i = 0; i < EngineType::vec_size; i++) {
res[i] = std::fmax(res[i], a_);
}
Expand Down
2 changes: 1 addition & 1 deletion include/oneapi/mkl/rng/device/detail/gamma_impl.hpp
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ class distribution_base<oneapi::mkl::rng::device::gamma<RealType, Method>> {
}
auto res = a_ + beta_ * z;
if constexpr (std::is_same_v<Method, gamma_method::marsaglia_accurate>) {
for(std::int32_t i = 0; i < EngineType::vec_size; i++) {
for (std::int32_t i = 0; i < EngineType::vec_size; i++) {
if (res[i] < a_)
res[i] = a_;
}
Expand Down
58 changes: 32 additions & 26 deletions include/oneapi/mkl/rng/device/detail/uniform_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,21 @@ static inline std::uint64_t umul_hi_64(const std::uint64_t a, const std::uint64_
const std::uint64_t ab_md = a_hi * b_lo;
const std::uint64_t ba_md = b_hi * a_lo;

const std::uint64_t bias = ((ab_md & 0xFFFFFFFFULL) + (ba_md & 0xFFFFFFFFULL) + (ab_lo >> 32)) >> 32;
const std::uint64_t bias =
((ab_md & 0xFFFFFFFFULL) + (ba_md & 0xFFFFFFFFULL) + (ab_lo >> 32)) >> 32;

return ab_hi + (ab_md >> 32) + (ba_md >> 32) + bias;
}

template <typename EngineType, typename Generator>
static inline void generate_leftover(std::uint64_t range, Generator generate,
std::uint64_t& res_64, std::uint64_t& leftover) {
static inline void generate_leftover(std::uint64_t range, Generator generate, std::uint64_t& res_64,
std::uint64_t& leftover) {
if constexpr (std::is_same_v<EngineType, mcg31m1<EngineType::vec_size>>) {
std::uint32_t res_1 = generate();
std::uint32_t res_2 = generate();
std::uint32_t res_3 = generate();
res_64 = (static_cast<std::uint64_t>(res_3) << 62) +
(static_cast<std::uint64_t>(res_2) << 31) + res_1;
(static_cast<std::uint64_t>(res_2) << 31) + res_1;
}
else {
std::uint32_t res_1 = generate();
Expand Down Expand Up @@ -121,7 +122,8 @@ class distribution_base<oneapi::mkl::rng::device::uniform<Type, Method>> {
float>::type;
OutType res;
if constexpr (std::is_integral<Type>::value) {
if constexpr (std::is_same_v<Type, std::int32_t> || std::is_same_v<Type, std::uint32_t>) {
if constexpr (std::is_same_v<Type, std::int32_t> ||
std::is_same_v<Type, std::uint32_t>) {
return generate_single_int<FpType, OutType>(engine);
}
else {
Expand All @@ -141,15 +143,15 @@ class distribution_base<oneapi::mkl::rng::device::uniform<Type, Method>> {
std::uint32_t res_1, res_2;
std::uint64_t res_64, leftover;

generate_leftover<EngineType>(range, [&engine](){return engine.generate();},
res_64, leftover);
generate_leftover<EngineType>(
range, [&engine]() { return engine.generate(); }, res_64, leftover);

if (range == uint_max64)
return res_64;

while (leftover < threshold) {
generate_leftover<EngineType>(range, [&engine](){return engine.generate();},
res_64, leftover);
generate_leftover<EngineType>(
range, [&engine]() { return engine.generate(); }, res_64, leftover);
}

res = a_ + umul_hi_64(res_64, range);
Expand All @@ -168,23 +170,25 @@ class distribution_base<oneapi::mkl::rng::device::uniform<Type, Method>> {

for (int i = 0; i < EngineType::vec_size; i++) {
res_64[i] = (static_cast<std::uint64_t>(res_3[i]) << 62) +
(static_cast<std::uint64_t>(res_2[i]) << 31) + res_1[i];
(static_cast<std::uint64_t>(res_2[i]) << 31) + res_1[i];
}
}
else {
if constexpr (EngineType::vec_size == 3) {
res_64[0] = (static_cast<std::uint64_t>(res_1[1]) << 32) +
static_cast<std::uint64_t>(res_1[0]);
static_cast<std::uint64_t>(res_1[0]);
res_64[1] = (static_cast<std::uint64_t>(res_2[0]) << 32) +
static_cast<std::uint64_t>(res_1[2]);
static_cast<std::uint64_t>(res_1[2]);
res_64[2] = (static_cast<std::uint64_t>(res_2[2]) << 32) +
static_cast<std::uint64_t>(res_2[1]);
} else {
static_cast<std::uint64_t>(res_2[1]);
}
else {
for (int i = 0; i < EngineType::vec_size / 2; i++) {
res_64[i] = (static_cast<std::uint64_t>(res_1[2 * i + 1]) << 32) +
static_cast<std::uint64_t>(res_1[2 * i]);
res_64[i + EngineType::vec_size / 2] = (static_cast<std::uint64_t>(res_2[2 * i + 1]) << 32) +
static_cast<std::uint64_t>(res_2[2 * i]);
static_cast<std::uint64_t>(res_1[2 * i]);
res_64[i + EngineType::vec_size / 2] =
(static_cast<std::uint64_t>(res_2[2 * i + 1]) << 32) +
static_cast<std::uint64_t>(res_2[2 * i]);
}
}
}
Expand All @@ -196,8 +200,9 @@ class distribution_base<oneapi::mkl::rng::device::uniform<Type, Method>> {
leftover = res_64[i] * range;

while (leftover < threshold) {
generate_leftover<EngineType>(range, [&engine](){return engine.generate_single();},
res_64[i], leftover);
generate_leftover<EngineType>(
range, [&engine]() { return engine.generate_single(); }, res_64[i],
leftover);
}

res[i] = a_ + umul_hi_64(res_64[i], range);
Expand All @@ -219,7 +224,7 @@ class distribution_base<oneapi::mkl::rng::device::uniform<Type, Method>> {
res = std::fmax(res, a_);
res = std::fmin(res, b_);
}
else{
else {
for (int i = 0; i < EngineType::vec_size; i++) {
res[i] = std::fmax(res[i], a_);
res[i] = std::fmin(res[i], b_);
Expand All @@ -239,7 +244,8 @@ class distribution_base<oneapi::mkl::rng::device::uniform<Type, Method>> {
float>::type;
Type res;
if constexpr (std::is_integral<Type>::value) {
if constexpr (std::is_same_v<Type, std::int32_t> || std::is_same_v<Type, std::uint32_t>) {
if constexpr (std::is_same_v<Type, std::int32_t> ||
std::is_same_v<Type, std::uint32_t>) {
FpType res_fp =
engine.generate_single(static_cast<FpType>(a_), static_cast<FpType>(b_));
res_fp = sycl::floor(res_fp);
Expand Down Expand Up @@ -267,15 +273,15 @@ class distribution_base<oneapi::mkl::rng::device::uniform<Type, Method>> {
std::uint32_t res_1, res_2;
std::uint64_t res_64, leftover;

generate_leftover<EngineType>(range, [&engine](){return engine.generate_single();},
res_64, leftover);
generate_leftover<EngineType>(
range, [&engine]() { return engine.generate_single(); }, res_64, leftover);

if (range == uint_max64)
return res_64;

while (leftover < threshold) {
generate_leftover<EngineType>(range, [&engine](){return engine.generate_single();},
res_64, leftover);
generate_leftover<EngineType>(
range, [&engine]() { return engine.generate_single(); }, res_64, leftover);
}

res = a_ + umul_hi_64(res_64, range);
Expand All @@ -295,7 +301,7 @@ class distribution_base<oneapi::mkl::rng::device::uniform<Type, Method>> {
res = std::fmax(res, a_);
res = std::fmin(res, b_);
}
else{
else {
for (int i = 0; i < EngineType::vec_size; i++) {
res[i] = std::fmax(res[i], a_);
res[i] = std::fmin(res[i], b_);
Expand Down
8 changes: 4 additions & 4 deletions include/oneapi/mkl/rng/device/distributions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ class uniform : detail::distribution_base<uniform<Type, Method>> {
Type(0.0),
std::is_integral<Type>::value
? ((std::is_same_v<Type, std::uint64_t> || std::is_same_v<Type, std::int64_t>)
? (std::numeric_limits<Type>::max)()
: (std::is_same<Method, uniform_method::standard>::value
? (1 << 23)
: (std::numeric_limits<Type>::max)()))
? (std::numeric_limits<Type>::max)()
: (std::is_same<Method, uniform_method::standard>::value
? (1 << 23)
: (std::numeric_limits<Type>::max)()))
: Type(1.0)) {}

explicit uniform(Type a, Type b) : detail::distribution_base<uniform<Type, Method>>(a, b) {}
Expand Down
Loading

0 comments on commit 0247c0d

Please sign in to comment.