-
Notifications
You must be signed in to change notification settings - Fork 14
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
ExtraBuffers: revamping of the idea #802
base: master
Are you sure you want to change the base?
Changes from all commits
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 |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// | ||
// Distributed Linear Algebra with Future (DLAF) | ||
// | ||
// Copyright (c) 2018-2023, ETH Zurich | ||
// All rights reserved. | ||
// | ||
// Please, refer to the LICENSE file in the root directory. | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
// | ||
|
||
#pragma once | ||
|
||
#include <vector> | ||
|
||
#include "dlaf/blas/tile_extensions.h" | ||
#include "dlaf/matrix/matrix.h" | ||
#include "dlaf/types.h" | ||
|
||
namespace dlaf { | ||
|
||
template <class T, Device D> | ||
struct ExtraBuffers : protected Matrix<T, D> { | ||
ExtraBuffers(const TileElementSize bs, const SizeType size) | ||
: Matrix<T, D>{{bs.rows() * size, bs.cols()}, bs}, nbuffers_(size) { | ||
namespace ex = pika::execution::experimental; | ||
for (const auto& i : common::iterate_range2d(Matrix<T, D>::distribution().localNrTiles())) | ||
ex::start_detached(Matrix<T, D>::readwrite_sender(i) | | ||
tile::set0(dlaf::internal::Policy<dlaf::DefaultBackend_v<D>>( | ||
pika::execution::thread_priority::high))); | ||
} | ||
|
||
auto read_sender(SizeType index) { | ||
return Matrix<T, D>::read_sender(internalIndex(index)); | ||
} | ||
|
||
auto readwrite_sender(SizeType index) { | ||
return Matrix<T, D>::readwrite_sender(internalIndex(index)); | ||
} | ||
|
||
template <class TileSender> | ||
[[nodiscard]] auto reduce(TileSender tile) { | ||
namespace di = dlaf::internal; | ||
namespace ex = pika::execution::experimental; | ||
|
||
std::vector<ex::any_sender<pika::shared_future<matrix::Tile<const T, D>>>> buffers; | ||
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. The type is so cumbersome, probably @msimberg is aware of this and is going to say that it is something we will manage when we will make the tile sender mechanism pika::future free. I don't know if there is any workaround available, but AFAIK currently our 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. I see your complaint, but |
||
for (SizeType index = 0; index < nbuffers_; ++index) | ||
buffers.emplace_back(read_sender(index)); | ||
|
||
return ex::when_all(std::move(tile), ex::when_all_vector(std::move(buffers))) | | ||
di::transform(di::Policy<DefaultBackend_v<D>>(), | ||
[](const matrix::Tile<T, D>& tile, | ||
const std::vector<pika::shared_future<matrix::Tile<const T, D>>>& buffers, | ||
auto&&... ts) { | ||
for (const auto& buffer : buffers) | ||
dlaf::tile::internal::add(T(1), buffer.get(), tile, ts...); | ||
}); | ||
} | ||
|
||
protected: | ||
LocalTileIndex internalIndex(SizeType index) const noexcept { | ||
return LocalTileIndex{index % nbuffers_, 0}; | ||
} | ||
|
||
SizeType nbuffers_; | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// | ||
// Distributed Linear Algebra with Future (DLAF) | ||
// | ||
// Copyright (c) 2018-2023, ETH Zurich | ||
// All rights reserved. | ||
// | ||
// Please, refer to the LICENSE file in the root directory. | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
// | ||
|
||
#include "dlaf/matrix/extra_buffers.h" | ||
|
||
#include <gtest/gtest.h> | ||
|
||
#include "dlaf/common/range2d.h" | ||
#include "dlaf/matrix/print_numpy.h" | ||
|
||
#include "dlaf_test/matrix/util_tile.h" | ||
|
||
using namespace dlaf; | ||
|
||
TEST(ExtraBuffersTest, Basic) { | ||
using T = float; | ||
constexpr auto D = Device::CPU; | ||
|
||
namespace ex = pika::execution::experimental; | ||
namespace tt = pika::this_thread::experimental; | ||
|
||
TileElementSize tile_size(2, 2); | ||
Matrix<T, D> tile({tile_size.rows(), tile_size.cols()}, tile_size); | ||
constexpr SizeType nbuffers = 10; | ||
ExtraBuffers<T, D> buffers(tile_size, nbuffers); | ||
|
||
for (SizeType i = 0; i < nbuffers; ++i) { | ||
tt::sync_wait(ex::when_all(buffers.readwrite_sender(i), ex::just(T(1))) | | ||
ex::then([](const auto& tile, const T value) { matrix::test::set(tile, value); })); | ||
} | ||
|
||
ex::start_detached(buffers.reduce(tile.readwrite_sender(LocalTileIndex{0, 0}))); | ||
|
||
print(format::numpy{}, tile.read(LocalTileIndex(0, 0)).get()); | ||
} |
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.
Probably better to create a continuation with a single task?