Skip to content
113 changes: 113 additions & 0 deletions sycl/include/sycl/queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1059,6 +1059,119 @@ class __SYCL_EXPORT queue {
CodeLoc);
}

/// Copies data from a memory region pointed to by a placeholder accessor to
/// another memory region pointed to by a shared_ptr.
///
/// \param Src is a placeholder accessor to the source memory.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure the API works with placeholder accessors only, does it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically it should be as this is a function on queue, so at this level it should only be possible to have placeholder and host accessors, the latter being moved to host_accessor. We could have a check to make sure it is not a host accessor in the meantime.

/// \param Dest is a shared_ptr to the destination memory.
/// \return an event representing copy operation.
template <typename SrcT, int SrcDims, access_mode SrcMode, target SrcTgt,
access::placeholder IsPlaceholder, typename DestT>
event copy(accessor<SrcT, SrcDims, SrcMode, SrcTgt, IsPlaceholder> Src,
std::shared_ptr<DestT> Dest) {
return submit([&](handler &CGH) {
CGH.require(Src);
CGH.copy(Src, Dest);
});
}

/// Copies data from a memory region pointed to by a shared_ptr to another
/// memory region pointed to by a placeholder accessor.
///
/// \param Src is a shared_ptr to the source memory.
/// \param Dest is a placeholder accessor to the destination memory.
/// \return an event representing copy operation.
template <typename SrcT, typename DestT, int DestDims, access_mode DestMode,
target DestTgt, access::placeholder IsPlaceholder>
event copy(std::shared_ptr<SrcT> Src,
accessor<DestT, DestDims, DestMode, DestTgt, IsPlaceholder> Dest) {
return submit([&](handler &CGH) {
CGH.require(Dest);
CGH.copy(Src, Dest);
});
}

/// Copies data from a memory region pointed to by a placeholder accessor to
/// another memory region pointed to by a raw pointer.
///
/// \param Src is a placeholder accessor to the source memory.
/// \param Dest is a raw pointer to the destination memory.
/// \return an event representing copy operation.
template <typename SrcT, int SrcDims, access_mode SrcMode, target SrcTgt,
access::placeholder IsPlaceholder, typename DestT>
event copy(accessor<SrcT, SrcDims, SrcMode, SrcTgt, IsPlaceholder> Src,
DestT *Dest) {
return submit([&](handler &CGH) {
CGH.require(Src);
CGH.copy(Src, Dest);
});
}

/// Copies data from a memory region pointed to by a raw pointer to another
/// memory region pointed to by a placeholder accessor.
///
/// \param Src is a raw pointer to the source memory.
/// \param Dest is a placeholder accessor to the destination memory.
/// \return an event representing copy operation.
template <typename SrcT, typename DestT, int DestDims, access_mode DestMode,
target DestTgt, access::placeholder IsPlaceholder>
event copy(const SrcT *Src,
accessor<DestT, DestDims, DestMode, DestTgt, IsPlaceholder> Dest) {
return submit([&](handler &CGH) {
CGH.require(Dest);
CGH.copy(Src, Dest);
});
}

/// Copies data from one memory region to another, both pointed by placeholder
/// accessors.
///
/// \param Src is a placeholder accessor to the source memory.
/// \param Dest is a placeholder accessor to the destination memory.
/// \return an event representing copy operation.
template <typename SrcT, int SrcDims, access_mode SrcMode, target SrcTgt,
access::placeholder IsSrcPlaceholder, typename DestT, int DestDims,
access_mode DestMode, target DestTgt,
access::placeholder IsDestPlaceholder>
event
copy(accessor<SrcT, SrcDims, SrcMode, SrcTgt, IsSrcPlaceholder> Src,
accessor<DestT, DestDims, DestMode, DestTgt, IsDestPlaceholder> Dest) {
return submit([&](handler &CGH) {
CGH.require(Src);
CGH.require(Dest);
CGH.copy(Src, Dest);
});
}

/// Provides guarantees that the memory object accessed via Acc is updated
/// on the host after operation is complete.
///
/// \param Acc is a SYCL accessor that needs to be updated on host.
/// \return an event representing update_host operation.
template <typename T, int Dims, access_mode Mode, target Tgt,
access::placeholder IsPlaceholder>
event update_host(accessor<T, Dims, Mode, Tgt, IsPlaceholder> Acc) {
return submit([&](handler &CGH) {
CGH.require(Acc);
CGH.update_host(Acc);
});
}

/// Fills the specified memory with the specified data.
///
/// \param Dest is the placeholder accessor to the memory to fill.
/// \param Src is the data to fill the memory with. T should be
/// trivially copyable.
/// \return an event representing fill operation.
template <typename T, int Dims, access_mode Mode, target Tgt,
access::placeholder IsPlaceholder>
event fill(accessor<T, Dims, Mode, Tgt, IsPlaceholder> Dest, const T &Src) {
return submit([&](handler &CGH) {
CGH.require(Dest);
CGH.fill<T>(Dest, Src);
});
}

// Clean KERNELFUNC macros.
#undef _KERNELFUNCPARAM

Expand Down