Skip to content

Commit f0f228e

Browse files
committed
Changed signatures to follow new proposed spec
1 parent 26a9b47 commit f0f228e

File tree

12 files changed

+183
-163
lines changed

12 files changed

+183
-163
lines changed

sycl/include/sycl/detail/cg_types.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ enum class CGType : unsigned int {
6565
SemaphoreSignal = 25,
6666
ProfilingTag = 26,
6767
EnqueueNativeCommand = 27,
68+
PrefetchUSMExpD2H = 28,
6869
};
6970

7071
template <typename, typename T> struct check_fn_signature {

sycl/include/sycl/ext/oneapi/experimental/enqueue_functions.hpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <sycl/detail/common.hpp>
1414
#include <sycl/event.hpp>
1515
#include <sycl/ext/oneapi/experimental/graph.hpp>
16+
#include <sycl/ext/oneapi/experimental/enqueue_types.hpp>
1617
#include <sycl/ext/oneapi/properties/properties.hpp>
1718
#include <sycl/handler.hpp>
1819
#include <sycl/nd_range.hpp>
@@ -349,14 +350,18 @@ void fill(sycl::queue Q, T *Ptr, const T &Pattern, size_t Count,
349350
submit(Q, [&](handler &CGH) { fill<T>(CGH, Ptr, Pattern, Count); }, CodeLoc);
350351
}
351352

352-
inline void prefetch(handler &CGH, void *Ptr, size_t NumBytes) {
353-
CGH.prefetch(Ptr, NumBytes);
353+
inline void prefetch(handler &CGH, void *Ptr, size_t NumBytes, prefetch_type type = prefetch_type::device) {
354+
if (type == prefetch_type::device) {
355+
CGH.prefetch(Ptr, NumBytes);
356+
} else {
357+
CGH.ext_oneapi_prefetch_d2h(Ptr, NumBytes);
358+
}
354359
}
355360

356-
inline void prefetch(queue Q, void *Ptr, size_t NumBytes,
361+
inline void prefetch(queue Q, void *Ptr, size_t NumBytes, prefetch_type type = prefetch_type::device,
357362
const sycl::detail::code_location &CodeLoc =
358363
sycl::detail::code_location::current()) {
359-
submit(Q, [&](handler &CGH) { prefetch(CGH, Ptr, NumBytes); }, CodeLoc);
364+
submit(Q, [&](handler &CGH) { prefetch(CGH, Ptr, NumBytes, type); }, CodeLoc);
360365
}
361366

362367
inline void mem_advise(handler &CGH, void *Ptr, size_t NumBytes, int Advice) {
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//==-------- usm_prefetch_exp.hpp --- SYCL USM prefetch extensions ---------==//
1+
//==------ enqueue_functions.hpp ------- SYCL enqueue free functions -------==//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
@@ -10,16 +10,13 @@
1010

1111
namespace sycl {
1212
inline namespace _V1 {
13-
1413
namespace ext::oneapi::experimental {
1514

16-
/// @brief Indicates USM memory migration direction: either from host to device,
17-
/// or device to host.
18-
enum class migration_direction {
19-
HOST_TO_DEVICE, /// Move data from host USM to device USM
20-
DEVICE_TO_HOST /// Move data from device USM to host USM
15+
enum class prefetch_type {
16+
device,
17+
host
2118
};
2219

2320
} // namespace ext::oneapi::experimental
2421
} // namespace _V1
25-
} // namespace sycl
22+
} // namespace sycl

sycl/include/sycl/handler.hpp

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
#include <sycl/ext/oneapi/bindless_images_mem_handle.hpp>
3333
#include <sycl/ext/oneapi/device_global/device_global.hpp>
3434
#include <sycl/ext/oneapi/device_global/properties.hpp>
35-
#include <sycl/ext/oneapi/experimental/USM/prefetch_exp.hpp>
3635
#include <sycl/ext/oneapi/experimental/cluster_group_prop.hpp>
36+
#include <sycl/ext/oneapi/experimental/enqueue_types.hpp>
3737
#include <sycl/ext/oneapi/experimental/graph.hpp>
3838
#include <sycl/ext/oneapi/experimental/raw_kernel_arg.hpp>
3939
#include <sycl/ext/oneapi/experimental/use_root_sync_prop.hpp>
@@ -163,9 +163,10 @@ template <class _name, class _dataT, int32_t _min_capacity, class _propertiesT,
163163
class pipe;
164164
}
165165

166-
namespace ext ::oneapi ::experimental {
166+
namespace ext::oneapi::experimental {
167167
template <typename, typename> class work_group_memory;
168168
struct image_descriptor;
169+
void prefetch(handler &CGH, void *Ptr, size_t NumBytes, prefetch_type type);
169170
} // namespace ext::oneapi::experimental
170171

171172
namespace ext::oneapi::experimental::detail {
@@ -2832,20 +2833,6 @@ class __SYCL_EXPORT handler {
28322833
/// \param Count is a number of bytes to be prefetched.
28332834
void prefetch(const void *Ptr, size_t Count);
28342835

2835-
/// Experimental implementation of prefetch supporting bidirectional USM data
2836-
/// migration: Provides hints to the runtime library that data should be made
2837-
/// available on a device earlier than Unified Shared Memory would normally
2838-
/// require it to be available.
2839-
///
2840-
/// \param CGH is the handler to be used for prefetching.
2841-
/// \param Ptr is a USM pointer to the memory to be prefetched to the
2842-
/// destination. \param Count is a number of bytes to be prefetched. \param
2843-
/// Direction indicates the direction to prefetch data to/from.
2844-
void ext_oneapi_prefetch_exp(
2845-
const void *Ptr, size_t Count,
2846-
ext::oneapi::experimental::migration_direction Direction =
2847-
ext::oneapi::experimental::migration_direction::HOST_TO_DEVICE);
2848-
28492836
/// Provides additional information to the underlying runtime about how
28502837
/// different allocations are used.
28512838
///
@@ -3274,9 +3261,6 @@ class __SYCL_EXPORT handler {
32743261
detail::code_location MCodeLoc = {};
32753262
bool MIsFinalized = false;
32763263
event MLastEvent;
3277-
/// Enum to indicate USM data migration direction
3278-
ext::oneapi::experimental::migration_direction MDirection =
3279-
ext::oneapi::experimental::migration_direction::HOST_TO_DEVICE;
32803264

32813265
// Make queue_impl class friend to be able to call finalize method.
32823266
friend class detail::queue_impl;
@@ -3554,6 +3538,11 @@ class __SYCL_EXPORT handler {
35543538
bool IsDeviceImageScoped, size_t NumBytes,
35553539
size_t Offset);
35563540

3541+
// Implementation of USM prefetch, fetching from device back to host.
3542+
void ext_oneapi_prefetch_d2h(const void *Ptr, size_t Count);
3543+
// Friend prefetch from the enqueue functions extension to allow call to private function ext_oneapi_prefetch_d2h
3544+
friend void sycl::ext::oneapi::experimental::prefetch(handler &CGH, void *Ptr, size_t NumBytes, sycl::ext::oneapi::experimental::prefetch_type type);
3545+
35573546
// Changing values in this will break ABI/API.
35583547
enum class StableKernelCacheConfig : int32_t {
35593548
Default = 0,

sycl/include/sycl/queue.hpp

Lines changed: 68 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
#include <sycl/exception_list.hpp> // for defaultAsyncHa...
3131
#include <sycl/ext/oneapi/device_global/device_global.hpp> // for device_global
3232
#include <sycl/ext/oneapi/device_global/properties.hpp> // for device_image_s...
33-
#include <sycl/ext/oneapi/experimental/USM/prefetch_exp.hpp> // for migration...
3433
#include <sycl/ext/oneapi/experimental/graph.hpp> // for command_graph...
3534
#include <sycl/ext/oneapi/properties/properties.hpp> // for empty_properti...
3635
#include <sycl/handler.hpp> // for handler, isDev...
@@ -746,27 +745,27 @@ class __SYCL_EXPORT queue : public detail::OwnerLessBase<queue> {
746745
TlsCodeLocCapture.query());
747746
}
748747

749-
/// Experimental implementation of prefetch supporting bidirectional USM data
750-
/// migration: Provides hints to the runtime library that data should be made
751-
/// available on a device earlier than Unified Shared Memory would normally
752-
/// require it to be available.
753-
///
754-
/// \param Ptr is a USM pointer to the memory to be prefetched to the device.
755-
/// \param Count is a number of bytes to be prefetched.
756-
/// \param Direction indicates the direction to prefetch data to/from.
757-
/// \return an event representing prefetch operation.
758-
event ext_oneapi_prefetch_exp(
759-
const void *Ptr, size_t Count,
760-
ext::oneapi::experimental::migration_direction Direction =
761-
ext::oneapi::experimental::migration_direction::HOST_TO_DEVICE,
762-
const detail::code_location &CodeLoc = detail::code_location::current()) {
763-
detail::tls_code_loc_t TlsCodeLocCapture(CodeLoc);
764-
return submit(
765-
[=](handler &CGH) {
766-
CGH.ext_oneapi_prefetch_exp(Ptr, Count, Direction);
767-
},
768-
TlsCodeLocCapture.query());
769-
}
748+
// /// Experimental implementation of prefetch supporting bidirectional USM data
749+
// /// migration: Provides hints to the runtime library that data should be made
750+
// /// available on a device earlier than Unified Shared Memory would normally
751+
// /// require it to be available.
752+
// ///
753+
// /// \param Ptr is a USM pointer to the memory to be prefetched to the device.
754+
// /// \param Count is a number of bytes to be prefetched.
755+
// /// \param Direction indicates the direction to prefetch data to/from.
756+
// /// \return an event representing prefetch operation.
757+
// event ext_oneapi_prefetch_exp(
758+
// const void *Ptr, size_t Count,
759+
// ext::oneapi::experimental::migration_direction Direction =
760+
// ext::oneapi::experimental::migration_direction::HOST_TO_DEVICE,
761+
// const detail::code_location &CodeLoc = detail::code_location::current()) {
762+
// detail::tls_code_loc_t TlsCodeLocCapture(CodeLoc);
763+
// return submit(
764+
// [=](handler &CGH) {
765+
// CGH.ext_oneapi_prefetch_exp(Ptr, Count, Direction);
766+
// },
767+
// TlsCodeLocCapture.query());
768+
// }
770769

771770
/// Provides hints to the runtime library that data should be made available
772771
/// on a device earlier than Unified Shared Memory would normally require it
@@ -788,29 +787,29 @@ class __SYCL_EXPORT queue : public detail::OwnerLessBase<queue> {
788787
TlsCodeLocCapture.query());
789788
}
790789

791-
/// Experimental implementation of prefetch supporting bidirectional USM data
792-
/// migration: Provides hints to the runtime library that data should be made
793-
/// available on a device earlier than Unified Shared Memory would normally
794-
/// require it to be available.
795-
///
796-
/// \param Ptr is a USM pointer to the memory to be prefetched to the device.
797-
/// \param Count is a number of bytes to be prefetched.
798-
/// \param DepEvent is an event that specifies the kernel dependencies.
799-
/// \param Direction indicates the direction to prefetch data to/from.
800-
/// \return an event representing prefetch operation.
801-
event ext_oneapi_prefetch_exp(
802-
const void *Ptr, size_t Count, event DepEvent,
803-
ext::oneapi::experimental::migration_direction Direction =
804-
ext::oneapi::experimental::migration_direction::HOST_TO_DEVICE,
805-
const detail::code_location &CodeLoc = detail::code_location::current()) {
806-
detail::tls_code_loc_t TlsCodeLocCapture(CodeLoc);
807-
return submit(
808-
[=](handler &CGH) {
809-
CGH.depends_on(DepEvent);
810-
CGH.ext_oneapi_prefetch_exp(Ptr, Count, Direction);
811-
},
812-
TlsCodeLocCapture.query());
813-
}
790+
// /// Experimental implementation of prefetch supporting bidirectional USM data
791+
// /// migration: Provides hints to the runtime library that data should be made
792+
// /// available on a device earlier than Unified Shared Memory would normally
793+
// /// require it to be available.
794+
// ///
795+
// /// \param Ptr is a USM pointer to the memory to be prefetched to the device.
796+
// /// \param Count is a number of bytes to be prefetched.
797+
// /// \param DepEvent is an event that specifies the kernel dependencies.
798+
// /// \param Direction indicates the direction to prefetch data to/from.
799+
// /// \return an event representing prefetch operation.
800+
// event ext_oneapi_prefetch_exp(
801+
// const void *Ptr, size_t Count, event DepEvent,
802+
// ext::oneapi::experimental::migration_direction Direction =
803+
// ext::oneapi::experimental::migration_direction::HOST_TO_DEVICE,
804+
// const detail::code_location &CodeLoc = detail::code_location::current()) {
805+
// detail::tls_code_loc_t TlsCodeLocCapture(CodeLoc);
806+
// return submit(
807+
// [=](handler &CGH) {
808+
// CGH.depends_on(DepEvent);
809+
// CGH.ext_oneapi_prefetch_exp(Ptr, Count, Direction);
810+
// },
811+
// TlsCodeLocCapture.query());
812+
// }
814813

815814
/// Provides hints to the runtime library that data should be made available
816815
/// on a device earlier than Unified Shared Memory would normally require it
@@ -833,30 +832,30 @@ class __SYCL_EXPORT queue : public detail::OwnerLessBase<queue> {
833832
TlsCodeLocCapture.query());
834833
}
835834

836-
/// Experimental implementation of prefetch supporting bidirectional USM data
837-
/// migration: Provides hints to the runtime library that data should be made
838-
/// available on a device earlier than Unified Shared Memory would normally
839-
/// require it to be available.
840-
///
841-
/// \param Ptr is a USM pointer to the memory to be prefetched to the device.
842-
/// \param Count is a number of bytes to be prefetched.
843-
/// \param DepEvents is a vector of events that specifies the kernel
844-
/// dependencies.
845-
/// \param Direction indicates the direction to prefetch data to/from.
846-
/// \return an event representing prefetch operation.
847-
event ext_oneapi_prefetch_exp(
848-
const void *Ptr, size_t Count, const std::vector<event> &DepEvents,
849-
ext::oneapi::experimental::migration_direction Direction =
850-
ext::oneapi::experimental::migration_direction::HOST_TO_DEVICE,
851-
const detail::code_location &CodeLoc = detail::code_location::current()) {
852-
detail::tls_code_loc_t TlsCodeLocCapture(CodeLoc);
853-
return submit(
854-
[=](handler &CGH) {
855-
CGH.depends_on(DepEvents);
856-
CGH.ext_oneapi_prefetch_exp(Ptr, Count, Direction);
857-
},
858-
TlsCodeLocCapture.query());
859-
}
835+
// /// Experimental implementation of prefetch supporting bidirectional USM data
836+
// /// migration: Provides hints to the runtime library that data should be made
837+
// /// available on a device earlier than Unified Shared Memory would normally
838+
// /// require it to be available.
839+
// ///
840+
// /// \param Ptr is a USM pointer to the memory to be prefetched to the device.
841+
// /// \param Count is a number of bytes to be prefetched.
842+
// /// \param DepEvents is a vector of events that specifies the kernel
843+
// /// dependencies.
844+
// /// \param Direction indicates the direction to prefetch data to/from.
845+
// /// \return an event representing prefetch operation.
846+
// event ext_oneapi_prefetch_exp(
847+
// const void *Ptr, size_t Count, const std::vector<event> &DepEvents,
848+
// ext::oneapi::experimental::migration_direction Direction =
849+
// ext::oneapi::experimental::migration_direction::HOST_TO_DEVICE,
850+
// const detail::code_location &CodeLoc = detail::code_location::current()) {
851+
// detail::tls_code_loc_t TlsCodeLocCapture(CodeLoc);
852+
// return submit(
853+
// [=](handler &CGH) {
854+
// CGH.depends_on(DepEvents);
855+
// CGH.ext_oneapi_prefetch_exp(Ptr, Count, Direction);
856+
// },
857+
// TlsCodeLocCapture.query());
858+
// }
860859

861860
/// Copies data from one 2D memory region to another, both pointed by
862861
/// USM pointers.

sycl/source/detail/cg.hpp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include <sycl/detail/ur.hpp> // for ur_rect_region_t, ur_rect_offset_t
1616
#include <sycl/event.hpp> // for event_impl
1717
#include <sycl/exception_list.hpp> // for queue_impl
18-
#include <sycl/ext/oneapi/experimental/USM/prefetch_exp.hpp> // for migration_direction
1918
#include <sycl/kernel.hpp> // for kernel_impl
2019
#include <sycl/kernel_bundle.hpp> // for kernel_bundle_impl
2120

@@ -394,19 +393,28 @@ class CGFillUSM : public CG {
394393
class CGPrefetchUSM : public CG {
395394
void *MDst;
396395
size_t MLength;
397-
ext::oneapi::experimental::migration_direction MDirection;
398396

399397
public:
400398
CGPrefetchUSM(void *DstPtr, size_t Length, CG::StorageInitHelper CGData,
401-
ext::oneapi::experimental::migration_direction Direction,
402399
detail::code_location loc = {})
403400
: CG(CGType::PrefetchUSM, std::move(CGData), std::move(loc)),
404-
MDst(DstPtr), MLength(Length), MDirection(Direction) {}
401+
MDst(DstPtr), MLength(Length) {}
402+
void *getDst() { return MDst; }
403+
size_t getLength() { return MLength; }
404+
};
405+
406+
/// "Prefetch USM" command group class.
407+
class CGPrefetchUSMExpD2H : public CG {
408+
void *MDst;
409+
size_t MLength;
410+
411+
public:
412+
CGPrefetchUSMExpD2H(void *DstPtr, size_t Length, CG::StorageInitHelper CGData,
413+
detail::code_location loc = {})
414+
: CG(CGType::PrefetchUSMExpD2H, std::move(CGData), std::move(loc)),
415+
MDst(DstPtr), MLength(Length) {}
405416
void *getDst() { return MDst; }
406417
size_t getLength() { return MLength; }
407-
ext::oneapi::experimental::migration_direction getDirection() {
408-
return MDirection;
409-
}
410418
};
411419

412420
/// "Advise USM" command group class.

sycl/source/detail/memory_manager.cpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -966,16 +966,14 @@ void MemoryManager::fill_usm(void *Mem, QueueImplPtr Queue, size_t Length,
966966

967967
void MemoryManager::prefetch_usm(
968968
void *Mem, QueueImplPtr Queue, size_t Length,
969-
sycl::ext::oneapi::experimental::migration_direction Direction,
970969
std::vector<ur_event_handle_t> DepEvents, ur_event_handle_t *OutEvent,
971-
const detail::EventImplPtr &OutEventImpl) {
970+
const detail::EventImplPtr &OutEventImpl,
971+
sycl::ext::oneapi::experimental::prefetch_type Dest) {
972972
assert(Queue && "USM prefetch must be called with a valid device queue");
973973
const AdapterPtr &Adapter = Queue->getAdapter();
974974
ur_usm_migration_flags_t migration_flag =
975-
UR_USM_MIGRATION_FLAG_HOST_TO_DEVICE;
976-
if (Direction ==
977-
sycl::ext::oneapi::experimental::migration_direction::DEVICE_TO_HOST)
978-
migration_flag = UR_USM_MIGRATION_FLAG_DEVICE_TO_HOST;
975+
(Dest == sycl::ext::oneapi::experimental::prefetch_type::device) ?
976+
UR_USM_MIGRATION_FLAG_HOST_TO_DEVICE : UR_USM_MIGRATION_FLAG_DEVICE_TO_HOST;
979977
if (OutEventImpl != nullptr)
980978
OutEventImpl->setHostEnqueueTime();
981979
Adapter->call<UrApiKind::urEnqueueUSMPrefetch>(
@@ -1617,15 +1615,13 @@ void MemoryManager::ext_oneapi_fill_cmd_buffer(
16171615
void MemoryManager::ext_oneapi_prefetch_usm_cmd_buffer(
16181616
sycl::detail::ContextImplPtr Context,
16191617
ur_exp_command_buffer_handle_t CommandBuffer, void *Mem, size_t Length,
1620-
sycl::ext::oneapi::experimental::migration_direction Direction,
16211618
std::vector<ur_exp_command_buffer_sync_point_t> Deps,
1622-
ur_exp_command_buffer_sync_point_t *OutSyncPoint) {
1619+
ur_exp_command_buffer_sync_point_t *OutSyncPoint,
1620+
sycl::ext::oneapi::experimental::prefetch_type Dest) {
16231621
const AdapterPtr &Adapter = Context->getAdapter();
16241622
ur_usm_migration_flags_t migration_flag =
1625-
UR_USM_MIGRATION_FLAG_HOST_TO_DEVICE;
1626-
if (Direction ==
1627-
sycl::ext::oneapi::experimental::migration_direction::DEVICE_TO_HOST)
1628-
migration_flag = UR_USM_MIGRATION_FLAG_DEVICE_TO_HOST;
1623+
(Dest == sycl::ext::oneapi::experimental::prefetch_type::device) ?
1624+
UR_USM_MIGRATION_FLAG_HOST_TO_DEVICE : UR_USM_MIGRATION_FLAG_DEVICE_TO_HOST;
16291625
Adapter->call<UrApiKind::urCommandBufferAppendUSMPrefetchExp>(
16301626
CommandBuffer, Mem, Length, migration_flag, Deps.size(), Deps.data(), 0,
16311627
nullptr, OutSyncPoint, nullptr, nullptr);

0 commit comments

Comments
 (0)