Skip to content

Commit

Permalink
STDEXEC_ATTRIBUTE portability macro
Browse files Browse the repository at this point in the history
  • Loading branch information
ericniebler committed Oct 11, 2023
1 parent b64bab6 commit b269913
Show file tree
Hide file tree
Showing 32 changed files with 303 additions and 287 deletions.
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: Yes
AttributeMacros: [
'STDEXEC_ATTRIBUTE',
'STDEXEC_NO_UNIQUE_ADDRESS',
'STDEXEC_IMMOVABLE_NO_UNIQUE_ADDRESS',
'STDEXEC_DETAIL_CUDACC_HOST_DEVICE',
]
BinPackArguments: false
BinPackParameters: false
Expand Down
55 changes: 20 additions & 35 deletions examples/nvexec/maxwell/common.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ struct deleter_t {
};

template <class T>
STDEXEC_DETAIL_CUDACC_HOST_DEVICE inline std::unique_ptr<T, deleter_t>
allocate_on(bool gpu, std::size_t elements = 1) {
STDEXEC_ATTRIBUTE((host, device))
inline std::unique_ptr<T, deleter_t> allocate_on(bool gpu, std::size_t elements = 1) {
T *ptr{};

#if defined(_NVHPC_CUDA) || defined(__CUDACC__)
Expand Down Expand Up @@ -90,9 +90,7 @@ struct fields_accessor {

float *base_ptr;

[[nodiscard]] STDEXEC_DETAIL_CUDACC_HOST_DEVICE //
float *
get(field_id id) const {
STDEXEC_ATTRIBUTE((nodiscard, host, device)) float *get(field_id id) const {
return base_ptr + static_cast<int>(id) * cells;
}
};
Expand Down Expand Up @@ -124,9 +122,8 @@ struct grid_t {

constexpr float C0 = 299792458.0f; // Speed of light [metres per second]

STDEXEC_DETAIL_CUDACC_HOST_DEVICE //
inline bool
is_circle_part(float x, float y, float object_x, float object_y, float object_size) {
STDEXEC_ATTRIBUTE((host, device))
inline bool is_circle_part(float x, float y, float object_x, float object_y, float object_size) {
const float os2 = object_size * object_size;
return ((x - object_x) * (x - object_x) + (y - object_y) * (y - object_y) <= os2);
}
Expand All @@ -140,9 +137,7 @@ struct grid_initializer_t {
float dt;
fields_accessor accessor;

STDEXEC_DETAIL_CUDACC_HOST_DEVICE //
void
operator()(std::size_t cell_id) const {
STDEXEC_ATTRIBUTE((host, device)) void operator()(std::size_t cell_id) const {
const std::size_t row = cell_id / accessor.n;
const std::size_t column = cell_id % accessor.n;

Expand Down Expand Up @@ -185,36 +180,30 @@ inline grid_initializer_t grid_initializer(float dt, fields_accessor accessor) {
return {dt, accessor};
}

STDEXEC_DETAIL_CUDACC_HOST_DEVICE //
inline std::size_t
right_nid(std::size_t cell_id, std::size_t col, std::size_t N) {
STDEXEC_ATTRIBUTE((host, device))
inline std::size_t right_nid(std::size_t cell_id, std::size_t col, std::size_t N) {
return col == N - 1 ? cell_id - (N - 1) : cell_id + 1;
}

STDEXEC_DETAIL_CUDACC_HOST_DEVICE //
inline std::size_t
left_nid(std::size_t cell_id, std::size_t col, std::size_t N) {
STDEXEC_ATTRIBUTE((host, device))
inline std::size_t left_nid(std::size_t cell_id, std::size_t col, std::size_t N) {
return col == 0 ? cell_id + N - 1 : cell_id - 1;
}

STDEXEC_DETAIL_CUDACC_HOST_DEVICE //
inline std::size_t
bottom_nid(std::size_t cell_id, std::size_t row, std::size_t N) {
STDEXEC_ATTRIBUTE((host, device))
inline std::size_t bottom_nid(std::size_t cell_id, std::size_t row, std::size_t N) {
return row == 0 ? cell_id + N * (N - 1) : cell_id - N;
}

STDEXEC_DETAIL_CUDACC_HOST_DEVICE //
inline std::size_t
top_nid(std::size_t cell_id, std::size_t row, std::size_t N) {
STDEXEC_ATTRIBUTE((host, device))
inline std::size_t top_nid(std::size_t cell_id, std::size_t row, std::size_t N) {
return row == N - 1 ? cell_id - N * (N - 1) : cell_id + N;
}

struct h_field_calculator_t {
fields_accessor accessor;

STDEXEC_DETAIL_CUDACC_HOST_DEVICE //
void
operator()(std::size_t cell_id) const __attribute__((always_inline)) {
STDEXEC_ATTRIBUTE((always_inline, host, device)) void operator()(std::size_t cell_id) const {
const std::size_t N = accessor.n;
const std::size_t column = cell_id % N;
const std::size_t row = cell_id / N;
Expand All @@ -240,23 +229,19 @@ struct e_field_calculator_t {
fields_accessor accessor;
std::size_t source_position;

[[nodiscard]] STDEXEC_DETAIL_CUDACC_HOST_DEVICE //
float
gaussian_pulse(float t, float t_0, float tau) const {
STDEXEC_ATTRIBUTE((nodiscard, host, device))
float gaussian_pulse(float t, float t_0, float tau) const {
return exp(-(((t - t_0) / tau) * (t - t_0) / tau));
}

[[nodiscard]] STDEXEC_DETAIL_CUDACC_HOST_DEVICE //
float
calculate_source(float t, float frequency) const {
STDEXEC_ATTRIBUTE((nodiscard, host, device))
float calculate_source(float t, float frequency) const {
const float tau = 0.5f / frequency;
const float t_0 = 6.0f * tau;
return gaussian_pulse(t, t_0, tau);
}

STDEXEC_DETAIL_CUDACC_HOST_DEVICE //
void
operator()(std::size_t cell_id) const __attribute__((always_inline)) {
STDEXEC_ATTRIBUTE((always_inline, host, device)) void operator()(std::size_t cell_id) const {
const std::size_t N = accessor.n;
const std::size_t column = cell_id % N;
const std::size_t row = cell_id / N;
Expand Down
12 changes: 4 additions & 8 deletions examples/nvexec/maxwell/snr.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,8 @@ namespace repeat_n_detail {
using is_receiver = void;

template <stdexec::__one_of<ex::set_error_t, ex::set_stopped_t> _Tag, class... _Args>
STDEXEC_DETAIL_CUDACC_HOST_DEVICE //
friend void
tag_invoke(_Tag __tag, receiver_t&& __self, _Args&&... __args) noexcept {
STDEXEC_ATTRIBUTE((host, device))
friend void tag_invoke(_Tag __tag, receiver_t&& __self, _Args&&... __args) noexcept {
__tag(std::move(__self.op_state_.rcvr_), (_Args&&) __args...);
}

Expand Down Expand Up @@ -330,8 +329,7 @@ inline constexpr repeat_n_t repeat_n{};

template <class SchedulerT>
[[nodiscard]] bool is_gpu_scheduler(SchedulerT&& scheduler) {
auto snd = ex::just()
| exec::on(scheduler, ex::then([] { return nvexec::is_on_gpu(); }));
auto snd = ex::just() | exec::on(scheduler, ex::then([] { return nvexec::is_on_gpu(); }));
auto [on_gpu] = stdexec::sync_wait(std::move(snd)).value();
return on_gpu;
}
Expand Down Expand Up @@ -363,9 +361,7 @@ void run_snr(
time_storage_t time{is_gpu_scheduler(computer)};
fields_accessor accessor = grid.accessor();

auto init =
ex::just()
| exec::on(computer, ex::bulk(grid.cells, grid_initializer(dt, accessor)));
auto init = ex::just() | exec::on(computer, ex::bulk(grid.cells, grid_initializer(dt, accessor)));
stdexec::sync_wait(init);

auto snd = maxwell_eqs_snr(dt, time.get(), write_vtk, n_iterations, accessor, computer);
Expand Down
8 changes: 4 additions & 4 deletions include/exec/__detail/__basic_sequence.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ namespace exec {

mutable _ImplFn __impl_;

STDEXEC_DETAIL_CUDACC_HOST_DEVICE //
explicit __seqexpr(_ImplFn __impl)
STDEXEC_ATTRIBUTE((host, device))
explicit __seqexpr(_ImplFn __impl)
: __impl_((_ImplFn&&) __impl) {
}

Expand Down Expand Up @@ -106,8 +106,8 @@ namespace exec {
};

template <class _ImplFn>
STDEXEC_DETAIL_CUDACC_HOST_DEVICE //
__seqexpr(_ImplFn) -> __seqexpr<_ImplFn>;
STDEXEC_ATTRIBUTE((host, device))
__seqexpr(_ImplFn) -> __seqexpr<_ImplFn>;

#if STDEXEC_NVHPC() || (STDEXEC_GCC() && __GNUC__ < 13)
namespace __detail {
Expand Down
4 changes: 2 additions & 2 deletions include/exec/__detail/__sender_facade.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ namespace exec {
}

_Receiver __rcvr_;
STDEXEC_NO_UNIQUE_ADDRESS _Kernel __kernel_;
STDEXEC_NO_UNIQUE_ADDRESS _Data __data_;
STDEXEC_ATTRIBUTE((no_unique_address)) _Kernel __kernel_;
STDEXEC_ATTRIBUTE((no_unique_address)) _Data __data_;
};

struct __t {
Expand Down
8 changes: 4 additions & 4 deletions include/exec/any_sender_of.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ namespace exec {
const __vtable_t* __vtable_{__default_storage_vtable((__vtable_t*) nullptr)};
void* __object_pointer_{nullptr};
alignas(__alignment) std::byte __buffer_[__buffer_size]{};
STDEXEC_NO_UNIQUE_ADDRESS _Allocator __allocator_{};
STDEXEC_ATTRIBUTE((no_unique_address)) _Allocator __allocator_{};
};
};

Expand Down Expand Up @@ -541,7 +541,7 @@ namespace exec {
const __vtable_t* __vtable_{__default_storage_vtable((__vtable_t*) nullptr)};
void* __object_pointer_{nullptr};
alignas(__alignment) std::byte __buffer_[__buffer_size]{};
STDEXEC_NO_UNIQUE_ADDRESS _Allocator __allocator_{};
STDEXEC_ATTRIBUTE((no_unique_address)) _Allocator __allocator_{};
};

struct __empty_vtable {
Expand Down Expand Up @@ -771,7 +771,7 @@ namespace exec {

template <class _Receiver>
struct __operation_base {
STDEXEC_NO_UNIQUE_ADDRESS _Receiver __rcvr_;
STDEXEC_ATTRIBUTE((no_unique_address)) _Receiver __rcvr_;
stdexec::in_place_stop_source __stop_source_{};
using __stop_callback = typename stdexec::stop_token_of_t<
stdexec::env_of_t<_Receiver>>::template callback_type<__on_stop_t>;
Expand Down Expand Up @@ -873,7 +873,7 @@ namespace exec {
}

private:
STDEXEC_NO_UNIQUE_ADDRESS _Receiver __rec_;
STDEXEC_ATTRIBUTE((no_unique_address)) _Receiver __rec_;
__immovable_operation_storage __storage_{};

friend void tag_invoke(start_t, __t& __self) noexcept {
Expand Down
12 changes: 6 additions & 6 deletions include/exec/async_scope.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ namespace exec {
template <class _ReceiverId>
struct __when_empty_op_base : __task {
using _Receiver = __t<_ReceiverId>;
STDEXEC_NO_UNIQUE_ADDRESS _Receiver __rcvr_;
STDEXEC_ATTRIBUTE((no_unique_address)) _Receiver __rcvr_;
};

template <class _ConstrainedId, class _ReceiverId>
Expand Down Expand Up @@ -120,7 +120,7 @@ namespace exec {
}

const __impl* __scope_;
STDEXEC_NO_UNIQUE_ADDRESS _Constrained __c_;
STDEXEC_ATTRIBUTE((no_unique_address)) _Constrained __c_;
};

template <class _Constrained>
Expand All @@ -132,7 +132,7 @@ namespace exec {
struct __nest_op_base : __immovable {
using _Receiver = __t<_ReceiverId>;
const __impl* __scope_;
STDEXEC_NO_UNIQUE_ADDRESS _Receiver __rcvr_;
STDEXEC_ATTRIBUTE((no_unique_address)) _Receiver __rcvr_;
};

template <class _ReceiverId>
Expand Down Expand Up @@ -208,7 +208,7 @@ namespace exec {
using is_sender = void;

const __impl* __scope_;
STDEXEC_NO_UNIQUE_ADDRESS _Constrained __c_;
STDEXEC_ATTRIBUTE((no_unique_address)) _Constrained __c_;

template <class _Receiver>
using __nest_operation_t = __nest_op<_ConstrainedId, __x<_Receiver>>;
Expand Down Expand Up @@ -333,9 +333,9 @@ namespace exec {
}
}

STDEXEC_NO_UNIQUE_ADDRESS _Receiver __rcvr_;
STDEXEC_ATTRIBUTE((no_unique_address)) _Receiver __rcvr_;
std::unique_ptr<__future_state<_Sender, _Env>> __state_;
STDEXEC_NO_UNIQUE_ADDRESS __forward_consumer __forward_consumer_;
STDEXEC_ATTRIBUTE((no_unique_address)) __forward_consumer __forward_consumer_;

public:
~__future_op() noexcept {
Expand Down
10 changes: 5 additions & 5 deletions include/exec/create.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ namespace exec {

template <class _Receiver, class _Args>
struct __context {
STDEXEC_NO_UNIQUE_ADDRESS _Receiver receiver;
STDEXEC_NO_UNIQUE_ADDRESS _Args args;
STDEXEC_ATTRIBUTE((no_unique_address)) _Receiver receiver;
STDEXEC_ATTRIBUTE((no_unique_address)) _Args args;
};

template <class _ReceiverId, class _Fun, class _ArgsId>
Expand All @@ -42,9 +42,9 @@ namespace exec {
using _Result = __call_result_t<_Fun, _Context&>;
using _State = __if_c<same_as<_Result, void>, __void, std::optional<_Result>>;

STDEXEC_NO_UNIQUE_ADDRESS _Context __ctx_;
STDEXEC_NO_UNIQUE_ADDRESS _Fun __fun_;
STDEXEC_NO_UNIQUE_ADDRESS _State __state_{};
STDEXEC_ATTRIBUTE((no_unique_address)) _Context __ctx_;
STDEXEC_ATTRIBUTE((no_unique_address)) _Fun __fun_;
STDEXEC_ATTRIBUTE((no_unique_address)) _State __state_{};

friend void tag_invoke(start_t, __operation& __self) noexcept {
__self.__state_.emplace(__conv{[&]() noexcept {
Expand Down
4 changes: 2 additions & 2 deletions include/exec/env.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ namespace exec {
using _Default = __t<_DefaultId>;
using _Receiver = __t<_ReceiverId>;

STDEXEC_NO_UNIQUE_ADDRESS _Default __default_;
STDEXEC_ATTRIBUTE((no_unique_address)) _Default __default_;
_Receiver __rcvr_;

friend void tag_invoke(start_t, __operation& __self) noexcept {
Expand All @@ -78,7 +78,7 @@ namespace exec {
struct __sender {
using _Default = __t<_DefaultId>;
using is_sender = void;
STDEXEC_NO_UNIQUE_ADDRESS _Default __default_;
STDEXEC_ATTRIBUTE((no_unique_address)) _Default __default_;

template <class _Env>
using __value_t =
Expand Down
2 changes: 1 addition & 1 deletion include/exec/linux/io_uring_context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ namespace exec {

struct __impl {
__context& __context_;
STDEXEC_NO_UNIQUE_ADDRESS _Receiver __receiver_;
STDEXEC_ATTRIBUTE((no_unique_address)) _Receiver __receiver_;

__impl(__context& __context, _Receiver&& __receiver)
: __context_{__context}
Expand Down
6 changes: 3 additions & 3 deletions include/exec/repeat_effect_until.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ namespace exec {
__call_result_t<stdexec::on_t, trampoline_scheduler, _Source &>;
using __source_op_t = stdexec::connect_result_t<__source_on_scheduler_sender, __receiver_t>;

STDEXEC_NO_UNIQUE_ADDRESS _Source __source_;
STDEXEC_NO_UNIQUE_ADDRESS _Receiver __rcvr_;
STDEXEC_ATTRIBUTE((no_unique_address)) _Source __source_;
STDEXEC_ATTRIBUTE((no_unique_address)) _Receiver __rcvr_;
__manual_lifetime<__source_op_t> __source_op_;
trampoline_scheduler __sched_;

Expand Down Expand Up @@ -150,7 +150,7 @@ namespace exec {
struct __t {
using is_sender = void;
using __id = __sender;
STDEXEC_NO_UNIQUE_ADDRESS _Source __source_;
STDEXEC_ATTRIBUTE((no_unique_address)) _Source __source_;

template <class... Ts>
using __value_t = stdexec::completion_signatures<>;
Expand Down
2 changes: 1 addition & 1 deletion include/exec/sequence/empty_sequence.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace exec {

struct __t {
using __id = __operation;
STDEXEC_NO_UNIQUE_ADDRESS _Receiver __rcvr_;
STDEXEC_ATTRIBUTE((no_unique_address)) _Receiver __rcvr_;

friend void tag_invoke(start_t, __t& __self) noexcept {
stdexec::set_value(static_cast<_Receiver&&>(__self.__rcvr_));
Expand Down
11 changes: 5 additions & 6 deletions include/exec/sequence/ignore_all_values.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ namespace exec {

template <class _ItemReceiver, class _ResultVariant>
struct __item_operation_base {
STDEXEC_NO_UNIQUE_ADDRESS _ItemReceiver __receiver_;
STDEXEC_ATTRIBUTE((no_unique_address)) _ItemReceiver __receiver_;
__result_type<_ResultVariant>* __result_;
};

Expand Down Expand Up @@ -123,10 +123,9 @@ namespace exec {
__t(
__result_type<_ResultVariant>* __parent,
_Sender&& __sndr,
_ItemReceiver __rcvr) //
noexcept(
__nothrow_decay_copyable<_ItemReceiver> //
&& __nothrow_connectable<_Sender, __item_receiver_t>)
_ItemReceiver __rcvr) //
noexcept(__nothrow_decay_copyable<_ItemReceiver> //
&& __nothrow_connectable<_Sender, __item_receiver_t>)
: __base_type{static_cast<_ItemReceiver&&>(__rcvr), __parent}
, __op_{stdexec::connect(static_cast<_Sender&&>(__sndr), __item_receiver_t{this})} {
}
Expand Down Expand Up @@ -168,7 +167,7 @@ namespace exec {

template <class _Receiver, class _ResultVariant>
struct __operation_base : __result_type<_ResultVariant> {
STDEXEC_NO_UNIQUE_ADDRESS _Receiver __receiver_;
STDEXEC_ATTRIBUTE((no_unique_address)) _Receiver __receiver_;
};

template <class _ReceiverId, class _ResultVariant>
Expand Down
Loading

0 comments on commit b269913

Please sign in to comment.