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
3 changes: 2 additions & 1 deletion include/nvexec/stream/common.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,8 @@ namespace nv::execution
return get_stream_provider(env)->own_stream_.value();
}

STDEXEC_ATTRIBUTE(host, device) auto operator()() const noexcept
STDEXEC_ATTRIBUTE(host, device)
auto operator()() const noexcept
{
return STDEXEC::read_env(*this);
}
Expand Down
10 changes: 8 additions & 2 deletions include/stdexec/__detail/__completion_behavior.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,17 @@ namespace STDEXEC
struct __common_t
{
template <__behavior... _CSs>
requires(sizeof...(_CSs) > 0)
STDEXEC_ATTRIBUTE(nodiscard, host, device)
constexpr auto operator()(__constant_t<_CSs>... __cbs) const noexcept
{
return (__cbs | ...);
if constexpr (sizeof...(_CSs) == 0)
{
return __completion_behavior::__unknown;
}
else
{
return (__cbs | ...);
}
}
};

Expand Down
1 change: 1 addition & 0 deletions include/stdexec/__detail/__config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,7 @@ namespace STDEXEC
struct __assertion_failure
{};

STDEXEC_ATTRIBUTE(noreturn, host, device)
inline void __throw_assertion_failure()
{
STDEXEC_THROW(__assertion_failure{});
Expand Down
359 changes: 186 additions & 173 deletions include/stdexec/__detail/__let.hpp

Large diffs are not rendered by default.

50 changes: 27 additions & 23 deletions test/nvexec/bulk.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#include <stdexec/execution.hpp>
#include <test_common/catch2.hpp>

#include <stdexec/execution.hpp>

#include <exec/env.hpp>

#include <nvexec/stream_context.cuh>

#include "common.cuh"
#include "nvexec/stream_context.cuh"

#include <cuda/std/span>

Expand All @@ -26,7 +30,7 @@ namespace
nvexec::stream_context stream_ctx{};
auto const snd = ex::schedule(stream_ctx.get_scheduler()) | ex::bulk(ex::par, 1, [](int) {});

REQUIRE(STDEXEC::sync_wait(snd).has_value());
REQUIRE(ex::sync_wait(snd).has_value());
}

TEST_CASE("nvexec bulk executes on GPU", "[cuda][stream][adaptors][bulk]")
Expand All @@ -46,7 +50,7 @@ namespace
flags.set(idx);
}
});
STDEXEC::sync_wait(std::move(snd));
ex::sync_wait(std::move(snd));

REQUIRE(flags_storage.all_set_once());
}
Expand All @@ -71,7 +75,7 @@ namespace
}
}
});
STDEXEC::sync_wait(std::move(snd));
ex::sync_wait(std::move(snd));

REQUIRE(flags_storage.all_set_once());
}
Expand All @@ -96,7 +100,7 @@ namespace
}
}
});
auto const [i, d] = STDEXEC::sync_wait(std::move(snd)).value();
auto const [i, d] = ex::sync_wait(std::move(snd)).value();

REQUIRE(flags_storage.all_set_once());
REQUIRE(i == 42);
Expand All @@ -122,7 +126,7 @@ namespace
flags.set(idx);
}
});
[[maybe_unused]] auto [flags_actual] = STDEXEC::sync_wait(std::move(snd)).value();
[[maybe_unused]] auto [flags_actual] = ex::sync_wait(std::move(snd)).value();

REQUIRE(flags_storage.all_set_once());
}
Expand Down Expand Up @@ -152,7 +156,7 @@ namespace
flags.set(2);
}
});
STDEXEC::sync_wait(std::move(snd));
ex::sync_wait(std::move(snd));

REQUIRE(flags_storage.all_set_once());
}
Expand Down Expand Up @@ -183,7 +187,7 @@ namespace
flags.set(idx);
}
});
STDEXEC::sync_wait(std::move(snd));
ex::sync_wait(std::move(snd));

REQUIRE(flags_storage.all_set_once());
}
Expand All @@ -205,7 +209,7 @@ namespace
flags.set(idx);
}
});
STDEXEC::sync_wait(std::move(snd)).value();
ex::sync_wait(std::move(snd)).value();

REQUIRE(flags_storage.all_set_once());
}
Expand All @@ -220,19 +224,19 @@ namespace
int const nelems = 10;
cudaMallocManaged(&inout, nelems * sizeof(double));

auto task = STDEXEC::just(cuda::std::span<double>{inout, nelems})
| STDEXEC::continues_on(ctx.get_scheduler())
| STDEXEC::bulk(ex::par,
nelems,
[](std::size_t i, cuda::std::span<double> out)
{ out[i] = (double) i; })
| STDEXEC::let_value([](cuda::std::span<double> out) { return STDEXEC::just(out); })
| STDEXEC::bulk(ex::par,
nelems,
[](std::size_t i, cuda::std::span<double> out)
{ out[i] = 2.0 * out[i]; });

STDEXEC::sync_wait(std::move(task)).value();
auto task = ex::just(cuda::std::span<double>{inout, nelems})
| ex::continues_on(ctx.get_scheduler())
| ex::bulk(ex::par,
nelems,
[](std::size_t i, cuda::std::span<double> out) { out[i] = (double) i; })
| ex::let_value([](cuda::std::span<double> out) { return ex::just(out); })
| exec::write_attrs(
ex::prop{ex::get_completion_scheduler<ex::set_value_t>, ctx.get_scheduler()})
| ex::bulk(ex::par,
nelems,
[](std::size_t i, cuda::std::span<double> out) { out[i] = 2.0 * out[i]; });

ex::sync_wait(std::move(task)).value();

for (int i = 0; i < nelems; ++i)
{
Expand Down
26 changes: 16 additions & 10 deletions test/nvexec/let_value.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#include <stdexec/execution.hpp>
#include <test_common/catch2.hpp>

#include <stdexec/execution.hpp>

#include <exec/env.hpp>

#include <nvexec/stream_context.cuh>

#include "common.cuh"
#include "nvexec/stream_context.cuh"

namespace ex = STDEXEC;

Expand Down Expand Up @@ -36,7 +40,7 @@ namespace
}
return ex::just();
});
STDEXEC::sync_wait(std::move(snd));
ex::sync_wait(std::move(snd));

REQUIRE(flags_storage.all_set_once());
}
Expand All @@ -61,7 +65,7 @@ namespace
}
return ex::just();
});
STDEXEC::sync_wait(std::move(snd));
ex::sync_wait(std::move(snd));

REQUIRE(flags_storage.all_set_once());
}
Expand All @@ -87,7 +91,7 @@ namespace
}
return ex::just();
});
STDEXEC::sync_wait(std::move(snd));
ex::sync_wait(std::move(snd));

REQUIRE(flags_storage.all_set_once());
}
Expand All @@ -98,7 +102,7 @@ namespace

auto snd = ex::schedule(stream_ctx.get_scheduler())
| ex::let_value([=]() { return ex::just(is_on_gpu()); });
auto const [result] = STDEXEC::sync_wait(std::move(snd)).value();
auto const [result] = ex::sync_wait(std::move(snd)).value();

REQUIRE(result == 1);
}
Expand Down Expand Up @@ -130,7 +134,7 @@ namespace
flags.set(1);
}
});
STDEXEC::sync_wait(std::move(snd));
ex::sync_wait(std::move(snd));

REQUIRE(flags_storage.all_set_once());
}
Expand All @@ -153,7 +157,7 @@ namespace

return ex::schedule(sch);
});
STDEXEC::sync_wait(std::move(snd));
ex::sync_wait(std::move(snd));

REQUIRE(flags_storage.all_set_once());
}
Expand All @@ -165,7 +169,9 @@ namespace
flags_storage_t flags_storage{};
auto flags = flags_storage.get();

auto snd = ex::schedule(sch) | ex::let_value([] { return nvexec::get_stream(); })
auto snd = ex::schedule(sch) //
| ex::let_value([] { return nvexec::get_stream(); }) //
| exec::write_attrs(ex::prop{ex::get_completion_scheduler<ex::set_value_t>, sch}) //
| ex::then(
[flags](cudaStream_t stream)
{
Expand All @@ -175,7 +181,7 @@ namespace
}
return stream;
});
auto [stream] = STDEXEC::sync_wait(std::move(snd)).value();
auto [stream] = ex::sync_wait(std::move(snd)).value();
static_assert(std::same_as<decltype(+stream), cudaStream_t>);

REQUIRE(flags_storage.all_set_once());
Expand Down
12 changes: 7 additions & 5 deletions test/stdexec/algos/adaptors/test_let_error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
#include <catch2/catch_all.hpp>

#define STDEXEC_PARALLEL_SCHEDULER_HEADER_ONLY 1
#include <stdexec/execution.hpp>

#include <exec/env.hpp>
Expand Down Expand Up @@ -390,11 +391,12 @@ namespace

TEST_CASE("let_error can be customized", "[adaptors][let_error]")
{
basic_inline_scheduler<let_error_test_domain> sched{};
auto attrs = ex::prop{ex::get_completion_domain<ex::set_error_t>, let_error_test_domain{}};

// The customization will return a different value
auto snd = ex::just(std::string{"hello"})
| ex::let_error([](std::exception_ptr) { return ex::just(std::string{"err"}); });
wait_for_value(ex::starts_on(sched, std::move(snd)), std::string{"what error?"});
// The customization will return a different stopped
auto snd = ex::schedule(ex::get_parallel_scheduler()) //
| exec::write_attrs(attrs) //
| ex::let_error([](std::exception_ptr) { return ex::just(std::string{"stopped"}); });
wait_for_value(std::move(snd), std::string{"what error?"});
}
} // namespace
6 changes: 4 additions & 2 deletions test/stdexec/algos/adaptors/test_let_stopped.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
#include <catch2/catch_all.hpp>

#define STDEXEC_PARALLEL_SCHEDULER_HEADER_ONLY 1
#include <stdexec/execution.hpp>

#include <exec/env.hpp>
Expand Down Expand Up @@ -231,10 +232,11 @@ namespace

TEST_CASE("let_stopped can be customized", "[adaptors][let_stopped]")
{
basic_inline_scheduler<let_stopped_test_domain> sched;
auto attrs = ex::prop{ex::get_completion_domain<ex::set_stopped_t>, let_stopped_test_domain{}};

// The customization will return a different stopped
auto snd = ex::just(std::string{"hello"}) | ex::continues_on(sched)
auto snd = ex::schedule(ex::get_parallel_scheduler()) //
| exec::write_attrs(attrs) //
| ex::let_stopped([] { return ex::just(std::string{"stopped"}); });
wait_for_value(std::move(snd), std::string{"Don't stop me now"});
}
Expand Down
2 changes: 1 addition & 1 deletion test/test_common/schedulers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace
template <class Scheduler, ex::__completion_tag... Tags>
struct sched_attrs
{
sched_attrs(Scheduler sched, Tags...)
explicit sched_attrs(Scheduler sched, Tags...)
: scheduler_(std::move(sched))
{}

Expand Down
Loading