Skip to main content

class closure_hydrator

Declaration

class closure_hydrator { /* full declaration omitted */ };

Description

The closure hydrator is used to inject information into objects (currently host/device and local accessors) that have been captured into a lambda closure. We abuse the copy constructor of the captured objects to modify them while the containing closure is being copied by the hydrate() function. Accessors request their corresponding information by means of per-closure unique "hydration ids" that are assigned upon accessor creation. The hydrator is implemented as a thread-local singleton that needs to be explicitly enabled per-thread. This is because kernel command function closures may be copied any number of times after having been passed to SYCL, which should not trigger the hydration mechanism.

Member Variables

std::vector<accessor_info> m_accessor_infos
std::optional<target> m_armed_for = std::nullopt
bool m_is_hydrating = false
sycl::handler* m_sycl_cgh = nullptr
static std::unique_ptr<closure_hydrator> m_instance

Member Function Overview

  • arm(target tgt, std::vector<accessor_info> accessor_infos) → void
  • closure_hydrator(closure_hydrator &&)
  • closure_hydrator(const closure_hydrator &)
  • template <target Tgt>
    get_accessor_info(hydration_id hid) → accessor_info
  • get_instance() → static closure_hydrator &
  • get_sycl_handler() → sycl::handler &
  • template <target Tgt, typename Closure, std::enable_if_t<Tgt == target::device, int> = 0>
    hydrate(sycl::handler & cgh, const Closure & closure) → [[nodiscard]] auto
  • template <target Tgt, typename Closure, std::enable_if_t<Tgt == target::host_task, int> = 0>
    hydrate(const Closure & closure) → [[nodiscard]] auto
  • is_available() → static bool
  • is_hydrating() const → bool
  • make_available() → static void
  • operator=(closure_hydrator &&) → closure_hydrator &
  • operator=(const closure_hydrator &) → closure_hydrator &
  • teardown() → static void
  • ~closure_hydrator()
  • closure_hydrator()
  • template <typename Closure>
    hydrate(target tgt, sycl::handler * cgh, const Closure & closure) → [[nodiscard]] auto

Member Functions

void arm(
    target tgt,
    std::vector<accessor_info> accessor_infos)

Description

Puts the hydrator into the "armed" state, after which hydrate() can be called to hydrate kernel functions. accessor_infos must contain one entry for each hydration id that has been assigned to accessors in the closure that is to be hydrated, in matching order.

Parameters

target tgt
std::vector<accessor_info> accessor_infos

closure_hydrator(closure_hydrator&&)

Parameters

closure_hydrator&&

closure_hydrator(const closure_hydrator&)

Parameters

const closure_hydrator&

template <target Tgt>
accessor_info get_accessor_info(hydration_id hid)

Template Parameters

target Tgt

Parameters

hydration_id hid

static closure_hydrator& get_instance()


sycl::handler& get_sycl_handler()


template <target Tgt,
          typename Closure,
          std::enable_if_t<Tgt == target::device,
                           int> = 0>
[[nodiscard]] auto hydrate(sycl::handler& cgh,
                           const Closure& closure)

Description

Hydrates the provided closure by copying it in a context where calls to get_accessor_info and get_sycl_handler are allowed.

Template Parameters

target Tgt
Closure
std::enable_if_t<Tgt == target::device, int> = 0

Parameters

sycl::handler& cgh
const Closure& closure

template <
    target Tgt,
    typename Closure,
    std::enable_if_t<Tgt == target::host_task,
                     int> = 0>
[[nodiscard]] auto hydrate(const Closure& closure)

Description

Hydrates the provided closure by copying it in a context where calls to get_accessor_info are allowed.

Template Parameters

target Tgt
Closure
std::enable_if_t<Tgt == target::host_task, int> = 0

Parameters

const Closure& closure

static bool is_available()


bool is_hydrating() const


static void make_available()


closure_hydrator& operator=(closure_hydrator&&)

Parameters

closure_hydrator&&

closure_hydrator& operator=(
    const closure_hydrator&)

Parameters

const closure_hydrator&

static void teardown()


~closure_hydrator()


closure_hydrator()


template <typename Closure>
[[nodiscard]] auto hydrate(target tgt,
                           sycl::handler* cgh,
                           const Closure& closure)

Template Parameters

Closure

Parameters

target tgt
sycl::handler* cgh
const Closure& closure