Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cmake/oomph_common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ mark_as_advanced(OOMPH_USE_FAST_PIMPL)
# ---------------------------------------------------------------------
# compiler and linker flags
# ---------------------------------------------------------------------
#set(cxx_lang "$<COMPILE_LANGUAGE:CXX>")
function(oomph_target_compile_options target)
set_target_properties(${target} PROPERTIES INTERFACE_POSITION_INDEPENDENT_CODE ON)
target_compile_options(${target} PRIVATE -Wall -Wextra -Wpedantic)
#target_compile_options(${target} PRIVATE
# $<${cxx_lang}:$<BUILD_INTERFACE:-Wall -Wextra -Wpedantic>>
#)
endfunction()

function(oomph_target_link_options target)
Expand Down
18 changes: 9 additions & 9 deletions include/oomph/communicator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@

namespace oomph
{
class context;
class send_channel_base;
class recv_channel_base;

class context_impl;
class communicator_impl;

namespace detail
{
communicator get_communicator(context_impl* c);
} // namespace detail

class communicator
{
public:
Expand All @@ -42,9 +44,7 @@ class communicator
static constexpr tag_type any_tag = -1;

private:
friend class context;
friend class send_channel_base;
friend class recv_channel_base;
friend communicator detail::get_communicator(context_impl*);

public:
struct schedule
Expand Down Expand Up @@ -198,7 +198,7 @@ class communicator
// ====================

template<typename T>
[[nodiscard]] recv_request recv(message_buffer<T>& msg, rank_type src, tag_type tag)
recv_request recv(message_buffer<T>& msg, rank_type src, tag_type tag)
{
assert(msg);
auto& scheduled = m_schedule->scheduled_recvs;
Expand All @@ -209,7 +209,7 @@ class communicator
}

template<typename T>
[[nodiscard]] send_request send(message_buffer<T> const& msg, rank_type dst, tag_type tag)
send_request send(message_buffer<T> const& msg, rank_type dst, tag_type tag)
{
assert(msg);
auto& scheduled = m_schedule->scheduled_sends;
Expand Down
5 changes: 5 additions & 0 deletions include/oomph/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <oomph/util/heap_pimpl.hpp>
#include <oomph/message_buffer.hpp>
#include <oomph/communicator.hpp>
#include <oomph/tensor/map_fwd.hpp>
#include <hwmalloc/config.hpp>
#include <hwmalloc/device.hpp>

Expand Down Expand Up @@ -83,6 +84,10 @@ class context

communicator get_communicator();

template<typename Layout, typename T>
tensor::map<T, Layout> map_tensor(
tensor::vector<std::size_t, Layout::max_arg + 1> const& extents, T* first, T* last);

private:
detail::message_buffer make_buffer_core(std::size_t size);
detail::message_buffer make_buffer_core(void* ptr, std::size_t size);
Expand Down
31 changes: 31 additions & 0 deletions include/oomph/tensor/buffer_cache.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* ghex-org
*
* Copyright (c) 2014-2021, ETH Zurich
* All rights reserved.
*
* Please, refer to the LICENSE file in the root directory.
* SPDX-License-Identifier: BSD-3-Clause
*/
#pragma once

#include <oomph/tensor/detail/buffer_cache.hpp>

namespace oomph
{
namespace tensor
{
template<typename T>
struct buffer_cache
{
std::shared_ptr<detail::buffer_cache<T, communicator*>> m_cache;

buffer_cache()
: m_cache{std::make_shared<detail::buffer_cache<T, communicator*>>()}
{
}
buffer_cache(buffer_cache const&) = default;
buffer_cache& operator=(buffer_cache const&) = default;
};
} // namespace tensor
} // namespace oomph
104 changes: 104 additions & 0 deletions include/oomph/tensor/detail/buffer_cache.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
* ghex-org
*
* Copyright (c) 2014-2021, ETH Zurich
* All rights reserved.
*
* Please, refer to the LICENSE file in the root directory.
* SPDX-License-Identifier: BSD-3-Clause
*/
#pragma once

#include <oomph/communicator.hpp>
#include <memory>
#include <vector>
#include <map>
#include <set>

namespace oomph
{
namespace tensor
{
namespace detail
{
template<typename T, typename Id>
struct buffer_cache
{
std::vector<std::shared_ptr<message_buffer<T>>> m_messages;
std::map<Id, std::set<std::size_t>> m_available_idx;

buffer_cache() noexcept = default;
buffer_cache(buffer_cache&&) noexcept = default;
buffer_cache& operator=(buffer_cache&&) noexcept = default;

std::shared_ptr<message_buffer<T>> operator()(communicator& comm, std::size_t size, Id id)
{
std::set<std::size_t>* index_set = nullptr;
auto it = m_available_idx.find(id);
if (it == m_available_idx.end())
{
index_set = &(m_available_idx[id]);
for (std::size_t i = 0; i < m_messages.size(); ++i) index_set->insert(i);
}
else
{
index_set = &(it->second);
}

auto m_it = std::find_if(index_set->begin(), index_set->end(),
[this, size](std::size_t i) { return (m_messages[i]->size() == size); });

if (m_it == index_set->end())
{
m_messages.push_back(std::make_shared<message_buffer<T>>(comm.make_buffer<T>(size)));
for (auto& s : m_available_idx) s.second.insert(m_messages.size() - 1);
index_set->erase(m_messages.size() - 1);
return m_messages.back();
}
else
{
auto res = *m_it;
index_set->erase(m_it);
return m_messages[res];
}
}

template<typename Id2>
std::shared_ptr<message_buffer<T>> operator()(communicator& comm, std::size_t size, Id id,
buffer_cache<T, Id2>& c2, Id2 id2)
{
std::set<std::size_t>* index_set = nullptr;
auto it = m_available_idx.find(id);
if (it == m_available_idx.end())
{
index_set = &(m_available_idx[id]);
for (std::size_t i = 0; i < m_messages.size(); ++i) index_set->insert(i);
}
else
{
index_set = &(it->second);
}

auto m_it = std::find_if(index_set->begin(), index_set->end(),
[this, size](std::size_t i) { return (m_messages[i]->size() == size); });

if (m_it == index_set->end())
{
auto res = c2(comm, size, id2);
m_messages.push_back(res);
for (auto& s : m_available_idx) s.second.insert(m_messages.size() - 1);
index_set->erase(m_messages.size() - 1);
return res;
}
else
{
auto res = *m_it;
index_set->erase(m_it);
return m_messages[res];
}
}
};

} // namespace detail
} // namespace tensor
} // namespace oomph
74 changes: 74 additions & 0 deletions include/oomph/tensor/detail/map.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* ghex-org
*
* Copyright (c) 2014-2021, ETH Zurich
* All rights reserved.
*
* Please, refer to the LICENSE file in the root directory.
* SPDX-License-Identifier: BSD-3-Clause
*/
#pragma once

#include <oomph/tensor/vector.hpp>

namespace oomph
{
namespace tensor
{
namespace detail
{
template<typename T, typename Layout>
class map
{
public:
static constexpr std::size_t dim() noexcept { return Layout::max_arg + 1; };

using vec = vector<std::size_t, dim()>;

protected:
static constexpr std::size_t s_stride_1_dim = Layout::find(dim() - 1);

protected:
T* m_data;
std::size_t m_num_elements;
vec m_extents;
vec m_strides;
std::size_t m_line_size;

public:
map(vec const& extents, T* first, T* last)
: m_data{first}
, m_num_elements{product(extents)}
, m_extents{extents}
{
auto const stride_1_extent = m_extents[s_stride_1_dim];
auto const num_lines = m_num_elements / stride_1_extent;
auto const total_padding = (((last + 1) - first) - m_num_elements) * sizeof(T);
std::size_t const padding = (num_lines == 1) ? 0 : total_padding / (num_lines - 1);
m_strides[s_stride_1_dim] = 1;
std::size_t s = stride_1_extent * sizeof(T) + padding;
assert((s / sizeof(T)) * sizeof(T) == s);
s /= sizeof(T);
m_line_size = s;
for (std::size_t i = 1; i < dim(); ++i)
{
m_strides[Layout::find(dim() - 1 - i)] = s;
s *= m_extents[Layout::find(dim() - 1 - i)];
}
}

map(map const&) noexcept = default;
map(map&&) noexcept = default;
map& operator=(map const&) noexcept = default;
map& operator=(map&&) noexcept = default;

public:
auto const& strides() const noexcept { return m_strides; }
vec const& extents() const noexcept { return m_extents; }
std::size_t line_size() const noexcept { return m_line_size; }
T* get_address(vec coord) const noexcept { return m_data + dot(coord, m_strides); }
};

} // namespace detail
} // namespace tensor
} // namespace oomph
Loading