Skip to content

Commit

Permalink
Improve global schedule algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
maikel committed Oct 25, 2023
1 parent e54ffc6 commit 362fb91
Show file tree
Hide file tree
Showing 4 changed files with 289 additions and 69 deletions.
2 changes: 1 addition & 1 deletion include/exec/__detail/__atomic_intrusive_queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace exec {
class __atomic_intrusive_queue;

template <class _Tp, _Tp* _Tp::*_NextPtr>
class __atomic_intrusive_queue<_NextPtr> {
class alignas(64) __atomic_intrusive_queue<_NextPtr> {
public:
using __node_pointer = _Tp*;
using __atomic_node_pointer = std::atomic<_Tp*>;
Expand Down
9 changes: 5 additions & 4 deletions include/exec/__detail/__bwos_lifo_queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ namespace exec::bwos {
++back;
++first;
}
tail_.store(back, std::memory_order_relaxed);
tail_.store(back, std::memory_order_release);
return first;
}

Expand All @@ -413,8 +413,9 @@ namespace exec::bwos {
if (front == back) [[unlikely]] {
return {lifo_queue_error_code::empty, nullptr};
}
tail_.store(back - 1, std::memory_order_relaxed);
return {lifo_queue_error_code::success, static_cast<Tp &&>(ring_buffer_[back - 1])};
Tp value = static_cast<Tp &&>(ring_buffer_[back - 1]);
tail_.store(back - 1, std::memory_order_release);
return {lifo_queue_error_code::success, value};
}

template <class Tp, class Allocator>
Expand All @@ -425,7 +426,7 @@ namespace exec::bwos {
result.status = lifo_queue_error_code::done;
return result;
}
std::uint64_t back = tail_.load(std::memory_order_relaxed);
std::uint64_t back = tail_.load(std::memory_order_acquire);
if (spos == back) [[unlikely]] {
result.status = lifo_queue_error_code::empty;
return result;
Expand Down
70 changes: 70 additions & 0 deletions include/exec/__detail/__xorshift.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright (c) 2023 Maikel Nadolski
* Copyright (c) 2023 NVIDIA Corporation
*
* Licensed under the Apache License Version 2.0 with LLVM Exceptions
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* https://llvm.org/LICENSE.txt
*
* 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.
*/

/* I have taken and modified this code from https://gist.github.com/Leandros/6dc334c22db135b033b57e9ee0311553 */
/* Copyright (c) 2018 Arvid Gerstmann. */
/* This code is licensed under MIT license. */

#include <cstddef>
#include <random>

namespace exec {

class xorshift {
public:
using result_type = std::uint32_t;

static constexpr result_type(min)() {
return 0;
}

static constexpr result_type(max)() {
return UINT32_MAX;
}

friend bool operator==(xorshift const &, xorshift const &) = default;

xorshift()
: m_seed(0xc1f651c67c62c6e0ull) {
}

explicit xorshift(std::random_device &rd) {
seed(rd);
}

void seed(std::random_device &rd) {
m_seed = std::uint64_t(rd()) << 31 | std::uint64_t(rd());
}

result_type operator()() {
std::uint64_t result = m_seed * 0xd989bcacc137dcd5ull;
m_seed ^= m_seed >> 11;
m_seed ^= m_seed << 31;
m_seed ^= m_seed >> 18;
return std::uint32_t(result >> 32ull);
}

void discard(unsigned long long n) {
for (unsigned long long i = 0; i < n; ++i)
operator()();
}

private:
std::uint64_t m_seed;
};

} // namespace exec
Loading

0 comments on commit 362fb91

Please sign in to comment.