Skip to content

Commit c4e1b16

Browse files
committed
Add comments and revert enum value name
Signed-off-by: James Brodman <[email protected]>
1 parent 5bf9770 commit c4e1b16

File tree

3 files changed

+143
-60
lines changed

3 files changed

+143
-60
lines changed

sycl/include/CL/cl_usm_ext.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ typedef cl_uint cl_mem_info_intel;
5252
#define CL_MEM_ALLOC_TYPE_INTEL 0x419A
5353
#define CL_MEM_ALLOC_BASE_PTR_INTEL 0x419B
5454
#define CL_MEM_ALLOC_SIZE_INTEL 0x419C
55-
#define CL_MEM_ALLOC_INFO_DEVICE_INTEL 0x419D
55+
#define CL_MEM_ALLOC_DEVICE_INTEL 0x419D
5656
/* CL_MEM_ALLOC_FLAGS_INTEL - defined above */
5757
#define CL_MEM_ALLOC_INFO_TBD0_INTEL 0x419E /* reserved for future */
5858
#define CL_MEM_ALLOC_INFO_TBD1_INTEL 0x419F /* reserved for future */

sycl/include/CL/sycl/detail/pi.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,7 @@ typedef enum {
951951
PI_MEM_ALLOC_TYPE = CL_MEM_ALLOC_TYPE_INTEL,
952952
PI_MEM_ALLOC_BASE_PTR = CL_MEM_ALLOC_BASE_PTR_INTEL,
953953
PI_MEM_ALLOC_SIZE = CL_MEM_ALLOC_SIZE_INTEL,
954-
PI_MEM_ALLOC_INFO_DEVICE = CL_MEM_ALLOC_INFO_DEVICE_INTEL,
954+
PI_MEM_ALLOC_DEVICE = CL_MEM_ALLOC_DEVICE_INTEL,
955955
PI_MEM_ALLOC_INFO_TBD0 = CL_MEM_ALLOC_INFO_TBD0_INTEL,
956956
PI_MEM_ALLOC_INFO_TBD1 = CL_MEM_ALLOC_INFO_TBD1_INTEL,
957957
} _pi_mem_info;

sycl/plugins/opencl/pi_opencl.cpp

Lines changed: 141 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -496,10 +496,16 @@ pi_result OCL(piEnqueueMemBufferMap)(
496496
// USM
497497
//
498498

499-
// Allocates host memory accessible by the device.
500-
pi_result OCL(piHostMemAlloc)(void **result_ptr, pi_context context,
501-
pi_usm_mem_properties *properties, size_t size,
502-
pi_uint32 alignment) {
499+
/// Allocates host memory accessible by the device.
500+
///
501+
/// @param result_ptr contains the allocated memory
502+
/// @param context is the pi_context
503+
/// @param pi_usm_mem_properties are optional allocation properties
504+
/// @param size_t is the size of the allocation
505+
/// @param alignment is the desired alignment of the allocation
506+
pi_result OCL(piextUSMHostAlloc)(void **result_ptr, pi_context context,
507+
pi_usm_mem_properties *properties, size_t size,
508+
pi_uint32 alignment) {
503509

504510
void *Ptr = nullptr;
505511
pi_result RetVal = PI_INVALID_OPERATION;
@@ -522,11 +528,18 @@ pi_result OCL(piHostMemAlloc)(void **result_ptr, pi_context context,
522528
return RetVal;
523529
}
524530

525-
// Allocates device memory.
526-
pi_result OCL(piDeviceMemAlloc)(void **result_ptr, pi_context context,
527-
pi_device device,
528-
pi_usm_mem_properties *properties, size_t size,
529-
pi_uint32 alignment) {
531+
/// Allocates device memory
532+
///
533+
/// @param result_ptr contains the allocated memory
534+
/// @param context is the pi_context
535+
/// @param device is the device the memory will be allocated on
536+
/// @param pi_usm_mem_properties are optional allocation properties
537+
/// @param size_t is the size of the allocation
538+
/// @param alignment is the desired alignment of the allocation
539+
pi_result OCL(piextUSMDeviceAlloc)(void **result_ptr, pi_context context,
540+
pi_device device,
541+
pi_usm_mem_properties *properties,
542+
size_t size, pi_uint32 alignment) {
530543

531544
void *Ptr = nullptr;
532545
pi_result RetVal = PI_INVALID_OPERATION;
@@ -549,11 +562,18 @@ pi_result OCL(piDeviceMemAlloc)(void **result_ptr, pi_context context,
549562
return RetVal;
550563
}
551564

552-
// Allocates memory accessible on host and device.
553-
pi_result OCL(piSharedMemAlloc)(void **result_ptr, pi_context context,
554-
pi_device device,
555-
pi_usm_mem_properties *properties, size_t size,
556-
pi_uint32 alignment) {
565+
/// Allocates memory accessible on both host and device
566+
///
567+
/// @param result_ptr contains the allocated memory
568+
/// @param context is the pi_context
569+
/// @param device is the device the memory will be allocated on
570+
/// @param pi_usm_mem_properties are optional allocation properties
571+
/// @param size_t is the size of the allocation
572+
/// @param alignment is the desired alignment of the allocation
573+
pi_result OCL(piextUSMSharedAlloc)(void **result_ptr, pi_context context,
574+
pi_device device,
575+
pi_usm_mem_properties *properties,
576+
size_t size, pi_uint32 alignment) {
557577

558578
void *Ptr = nullptr;
559579
pi_result RetVal = PI_INVALID_OPERATION;
@@ -576,7 +596,11 @@ pi_result OCL(piSharedMemAlloc)(void **result_ptr, pi_context context,
576596
return RetVal;
577597
}
578598

579-
pi_result OCL(piMemFree)(pi_context context, void *ptr) {
599+
/// Frees allocated USM memory
600+
///
601+
/// @param context is the pi_context of the allocation
602+
/// @param ptr is the memory to be freed
603+
pi_result OCL(piextUSMFree)(pi_context context, void *ptr) {
580604

581605
clMemFreeINTEL_fn FuncPtr;
582606
pi_result RetVal = getExtFuncFromContext<clMemFreeINTEL_fn>(
@@ -588,10 +612,17 @@ pi_result OCL(piMemFree)(pi_context context, void *ptr) {
588612
return cast<pi_result>(FuncPtr(cast<cl_context>(context), ptr));
589613
}
590614

591-
// Sets up pointer arguments to CL kernels
592-
pi_result OCL(piKernelSetArgMemPointer)(pi_kernel kernel, pi_uint32 arg_index,
593-
size_t arg_size,
594-
const void *arg_value) {
615+
/// Sets up pointer arguments for CL kernels. An extra indirection
616+
/// is required due to CL argument conventions.
617+
///
618+
/// @param kernel is the kernel to be launched
619+
/// @param arg_index is the index of the kernel argument
620+
/// @param arg_size is the size in bytes of the argument (ignored in CL)
621+
/// @param arg_value is the pointer argument
622+
pi_result OCL(piextUSMKernelSetArgMemPointer)(pi_kernel kernel,
623+
pi_uint32 arg_index,
624+
size_t arg_size,
625+
const void *arg_value) {
595626

596627
// Size is unused in CL as pointer args are passed by value.
597628

@@ -617,9 +648,11 @@ pi_result OCL(piKernelSetArgMemPointer)(pi_kernel kernel, pi_uint32 arg_index,
617648
return cast<pi_result>(FuncPtr(cast<cl_kernel>(kernel), arg_index, DerefPtr));
618649
}
619650

620-
// Enables indirect access of pointers in kernels.
621-
// Necessary to avoid telling CL about every pointer that might be used.
622-
pi_result OCL(piKernelSetIndirectAccess)(pi_kernel kernel, pi_queue queue) {
651+
/// Enables indirect access of pointers in kernels.
652+
/// Necessary to avoid telling CL about every pointer that might be used.
653+
///
654+
/// @param kernel is the kernel to be launched
655+
pi_result OCL(piextUSMKernelSetIndirectAccess)(pi_kernel kernel) {
623656

624657
// We test that each alloc type is supported before we actually try to
625658
// set KernelExecInfo.
@@ -660,11 +693,21 @@ pi_result OCL(piKernelSetIndirectAccess)(pi_kernel kernel, pi_queue queue) {
660693
return PI_SUCCESS;
661694
}
662695

663-
// USM memset API
664-
pi_result OCL(piEnqueueMemset)(pi_queue queue, void *ptr, pi_int32 value,
665-
size_t count, pi_uint32 num_events_in_waitlist,
666-
const pi_event *events_waitlist,
667-
pi_event *event) {
696+
/// USM Memset API
697+
///
698+
/// @param queue is the queue to submit to
699+
/// @param ptr is the ptr to memset
700+
/// @param value is value to set. It is interpreted as an 8-bit value and the upper
701+
/// 24 bits are ignored
702+
/// @param count is the size in bytes to memset
703+
/// @param num_events_in_waitlist is the number of events to wait on
704+
/// @param events_waitlist is an array of events to wait on
705+
/// @param event is the event that represents this operation
706+
pi_result OCL(piextUSMEnqueueMemset)(pi_queue queue, void *ptr, pi_int32 value,
707+
size_t count,
708+
pi_uint32 num_events_in_waitlist,
709+
const pi_event *events_waitlist,
710+
pi_event *event) {
668711

669712
// Have to look up the context from the kernel
670713
cl_context CLContext;
@@ -687,12 +730,22 @@ pi_result OCL(piEnqueueMemset)(pi_queue queue, void *ptr, pi_int32 value,
687730
cast<const cl_event *>(events_waitlist), cast<cl_event *>(event)));
688731
}
689732

690-
// USM routine to copy data between host and device
691-
pi_result OCL(piEnqueueMemcpy)(pi_queue queue, pi_bool blocking, void *dst_ptr,
692-
const void *src_ptr, pi_int32 size,
693-
pi_uint32 num_events_in_waitlist,
694-
const pi_event *events_waitlist,
695-
pi_event *event) {
733+
/// USM Memcpy API
734+
///
735+
/// @param queue is the queue to submit to
736+
/// @param blocking is whether this operation should block the host
737+
/// @param src_ptr is the data to be copied
738+
/// @param dst_ptr is the location the data will be copied
739+
/// @param size is number of bytes to copy
740+
/// @param num_events_in_waitlist is the number of events to wait on
741+
/// @param events_waitlist is an array of events to wait on
742+
/// @param event is the event that represents this operation
743+
pi_result OCL(piextUSMEnqueueMemcpy)(pi_queue queue, pi_bool blocking,
744+
void *dst_ptr, const void *src_ptr,
745+
pi_int32 size,
746+
pi_uint32 num_events_in_waitlist,
747+
const pi_event *events_waitlist,
748+
pi_event *event) {
696749

697750
// Have to look up the context from the kernel
698751
cl_context CLContext;
@@ -716,12 +769,21 @@ pi_result OCL(piEnqueueMemcpy)(pi_queue queue, pi_bool blocking, void *dst_ptr,
716769
cast<cl_event *>(event)));
717770
}
718771

719-
// Hint to migrate memory to the device
720-
pi_result OCL(piEnqueuePrefetch)(pi_queue queue, const void *ptr, size_t size,
721-
pi_usm_migration_flags flags,
722-
pi_uint32 num_events_in_waitlist,
723-
const pi_event *events_waitlist,
724-
pi_event *event) {
772+
/// Hint to migrate memory to the device
773+
///
774+
/// @param queue is the queue to submit to
775+
/// @param ptr points to the memory to migrate
776+
/// @param size is the number of bytes to migrate
777+
/// @param flags is a bitfield used to specify memory migration options
778+
/// @param num_events_in_waitlist is the number of events to wait on
779+
/// @param events_waitlist is an array of events to wait on
780+
/// @param event is the event that represents this operation
781+
pi_result OCL(piextUSMEnqueuePrefetch)(pi_queue queue, const void *ptr,
782+
size_t size,
783+
pi_usm_migration_flags flags,
784+
pi_uint32 num_events_in_waitlist,
785+
const pi_event *events_waitlist,
786+
pi_event *event) {
725787

726788
return cast<pi_result>(clEnqueueMarkerWithWaitList(
727789
cast<cl_command_queue>(queue), num_events_in_waitlist,
@@ -753,9 +815,17 @@ pi_result OCL(piEnqueuePrefetch)(pi_queue queue, const void *ptr, size_t size,
753815
*/
754816
}
755817

818+
/// USM Memadvise API
819+
///
820+
/// @param queue is the queue to submit to
821+
/// @param ptr is the data to be advised
822+
/// @param length is the size in bytes of the meory to advise
823+
/// @param advice is device specific advice
824+
/// @param event is the event that represents this operation
756825
// USM memadvise API to govern behavior of automatic migration mechanisms
757-
pi_result OCL(piEnqueueMemAdvise)(pi_queue queue, const void *ptr,
758-
size_t length, int advice, pi_event *event) {
826+
pi_result OCL(piextUSMEnqueueMemAdvise)(pi_queue queue, const void *ptr,
827+
size_t length, int advice,
828+
pi_event *event) {
759829

760830
return cast<pi_result>(
761831
clEnqueueMarkerWithWaitList(cast<cl_command_queue>(queue), 0, nullptr,
@@ -789,12 +859,25 @@ pi_result OCL(piEnqueueMemAdvise)(pi_queue queue, const void *ptr,
789859
*/
790860
}
791861

792-
// API to query information about USM pointers including type and
793-
// device allocated against
794-
pi_result OCL(piGetMemAllocInfo)(pi_context context, const void *ptr,
795-
pi_mem_info param_name,
796-
size_t param_value_size, void *param_value,
797-
size_t *param_value_size_ret) {
862+
/// API to query information about USM pointers including type and
863+
/// device allocated against
864+
/// Examples include:
865+
/// PI_MEM_ALLOC_TYPE
866+
/// PI_MEM_ALLOC_BASE_PTR
867+
/// PI_MEM_ALLOC_SIZE
868+
/// PI_MEM_ALLOC_DEVICE
869+
///
870+
/// @param context is the pi_context
871+
/// @param ptr is the pointer to query
872+
/// @param param_name is the type of query to perform
873+
/// @param param_value_size is the size of the result in bytes
874+
/// @param param_value is the result
875+
/// @param param_value_ret is how many bytes were written
876+
pi_result OCL(piextUSMGetMemAllocInfo)(pi_context context, const void *ptr,
877+
pi_mem_info param_name,
878+
size_t param_value_size,
879+
void *param_value,
880+
size_t *param_value_size_ret) {
798881

799882
clGetMemAllocInfoINTEL_fn FuncPtr;
800883
pi_result RetVal = getExtFuncFromContext<clGetMemAllocInfoINTEL_fn>(
@@ -903,17 +986,17 @@ pi_result piPluginInit(pi_plugin *PluginInit) {
903986
_PI_CL(piEnqueueMemBufferMap, OCL(piEnqueueMemBufferMap))
904987
_PI_CL(piEnqueueMemUnmap, clEnqueueUnmapMemObject)
905988
// USM
906-
_PI_CL(piextUSMHostAlloc, OCL(piHostMemAlloc))
907-
_PI_CL(piextUSMDeviceAlloc, OCL(piDeviceMemAlloc))
908-
_PI_CL(piextUSMSharedAlloc, OCL(piSharedMemAlloc))
909-
_PI_CL(piextUSMFree, OCL(piMemFree))
910-
_PI_CL(piextUSMKernelSetArgMemPointer, OCL(piKernelSetArgMemPointer))
911-
_PI_CL(piextUSMKernelSetIndirectAccess, OCL(piKernelSetIndirectAccess))
912-
_PI_CL(piextUSMEnqueueMemset, OCL(piEnqueueMemset))
913-
_PI_CL(piextUSMEnqueueMemcpy, OCL(piEnqueueMemcpy))
914-
_PI_CL(piextUSMEnqueuePrefetch, OCL(piEnqueuePrefetch))
915-
_PI_CL(piextUSMEnqueueMemAdvise, OCL(piEnqueueMemAdvise))
916-
_PI_CL(piextUSMGetMemAllocInfo, OCL(piGetMemAllocInfo))
989+
_PI_CL(piextUSMHostAlloc, OCL(piextUSMHostAlloc))
990+
_PI_CL(piextUSMDeviceAlloc, OCL(piextUSMDeviceAlloc))
991+
_PI_CL(piextUSMSharedAlloc, OCL(piextUSMSharedAlloc))
992+
_PI_CL(piextUSMFree, OCL(piextUSMFree))
993+
_PI_CL(piextUSMKernelSetArgMemPointer, OCL(piextUSMKernelSetArgMemPointer))
994+
_PI_CL(piextUSMKernelSetIndirectAccess, OCL(piextUSMKernelSetIndirectAccess))
995+
_PI_CL(piextUSMEnqueueMemset, OCL(piextUSMEnqueueMemset))
996+
_PI_CL(piextUSMEnqueueMemcpy, OCL(piextUSMEnqueueMemcpy))
997+
_PI_CL(piextUSMEnqueuePrefetch, OCL(piextUSMEnqueuePrefetch))
998+
_PI_CL(piextUSMEnqueueMemAdvise, OCL(piextUSMEnqueueMemAdvise))
999+
_PI_CL(piextUSMGetMemAllocInfo, OCL(piextUSMGetMemAllocInfo))
9171000

9181001
#undef _PI_CL
9191002

0 commit comments

Comments
 (0)