Skip to content

Commit 0ca7527

Browse files
committed
Alternative memcpy implementation
1 parent 3fbdf61 commit 0ca7527

File tree

13 files changed

+542
-142
lines changed

13 files changed

+542
-142
lines changed

offload/liboffload/API/Device.td

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,15 @@ def : Function {
104104
Return<"OL_ERRC_INVALID_DEVICE">
105105
];
106106
}
107+
108+
def : Function {
109+
let name = "olGetHostDevice";
110+
let desc = "Return the special host device used to represent the host in memory transfer operations";
111+
let details = [
112+
"The host device does not support queues"
113+
];
114+
let params = [
115+
Param<"ol_device_handle_t*", "Device", "Output pointer for the device">
116+
]; // TODO: Take a platform?
117+
let returns = [];
118+
}

offload/liboffload/API/Enqueue.td

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,28 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
def : Function {
14-
let name = "olEnqueueDataWrite";
14+
let name = "olEnqueueMemcpy";
15+
let desc = "Enqueue a memcpy operation.";
16+
let details = [
17+
"For host pointers, use the device returned by olGetHostDevice",
18+
"At least one device must be a non-host device"
19+
];
20+
let params = [
21+
Param<"ol_queue_handle_t", "Queue", "handle of the queue", PARAM_IN>,
22+
Param<"void*", "DstPtr", "pointer to copy to", PARAM_IN>,
23+
Param<"ol_device_handle_t", "DstDevice", "device that DstPtr belongs to", PARAM_IN>,
24+
Param<"void*", "SrcPtr", "pointer to copy from", PARAM_IN>,
25+
Param<"ol_device_handle_t", "SrcDevice", "device that SrcPtr belongs to", PARAM_IN>,
26+
Param<"size_t", "Size", "size in bytes of data to copy", PARAM_IN>,
27+
Param<"ol_event_handle_t*", "EventOut", "optional recorded event for the enqueued operation", PARAM_OUT_OPTIONAL>
28+
];
29+
let returns = [
30+
Return<"OL_ERRC_INVALID_SIZE", ["`Size == 0`"]>
31+
];
32+
}
33+
34+
def : Function {
35+
let name = "olEnqueueMemcpyHtoD";
1536
let desc = "Enqueue a write operation from host to device memory";
1637
let details = [];
1738
let params = [
@@ -27,7 +48,7 @@ def : Function {
2748
}
2849

2950
def : Function {
30-
let name = "olEnqueueDataRead";
51+
let name = "olEnqueueMemcpyDtoH";
3152
let desc = "Enqueue a read operation from device to host memory";
3253
let details = [];
3354
let params = [
@@ -41,7 +62,7 @@ def : Function {
4162
}
4263

4364
def : Function {
44-
let name = "olEnqueueDataCopy";
65+
let name = "olEnqueueMemcpyDtoD";
4566
let desc = "Enqueue a write operation between device allocations";
4667
let details = [];
4768
let params = [

offload/liboffload/include/generated/OffloadAPI.h

Lines changed: 111 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,24 @@ OL_APIEXPORT ol_result_t OL_APICALL olGetDeviceInfoSize(
474474
// [out] pointer to the number of bytes required to store the query
475475
size_t *PropSizeRet);
476476

477+
///////////////////////////////////////////////////////////////////////////////
478+
/// @brief Return the special host device used to represent the host in memory
479+
/// transfer operations
480+
///
481+
/// @details
482+
/// - The host device does not support queues
483+
///
484+
/// @returns
485+
/// - ::OL_RESULT_SUCCESS
486+
/// - ::OL_ERRC_UNINITIALIZED
487+
/// - ::OL_ERRC_DEVICE_LOST
488+
/// - ::OL_ERRC_INVALID_NULL_HANDLE
489+
/// - ::OL_ERRC_INVALID_NULL_POINTER
490+
/// + `NULL == Device`
491+
OL_APIEXPORT ol_result_t OL_APICALL olGetHostDevice(
492+
// Output pointer for the device
493+
ol_device_handle_t *Device);
494+
477495
///////////////////////////////////////////////////////////////////////////////
478496
/// @brief Represents the type of allocation made with olMemAlloc
479497
typedef enum ol_alloc_type_t {
@@ -653,6 +671,42 @@ OL_APIEXPORT ol_result_t OL_APICALL olWaitEvent(
653671
// [in] handle of the event
654672
ol_event_handle_t Event);
655673

674+
///////////////////////////////////////////////////////////////////////////////
675+
/// @brief Enqueue a memcpy operation.
676+
///
677+
/// @details
678+
/// - For host pointers, use the device returned by olGetHostDevice
679+
/// - At least one device must be a non-host device
680+
///
681+
/// @returns
682+
/// - ::OL_RESULT_SUCCESS
683+
/// - ::OL_ERRC_UNINITIALIZED
684+
/// - ::OL_ERRC_DEVICE_LOST
685+
/// - ::OL_ERRC_INVALID_SIZE
686+
/// + `Size == 0`
687+
/// - ::OL_ERRC_INVALID_NULL_HANDLE
688+
/// + `NULL == Queue`
689+
/// + `NULL == DstDevice`
690+
/// + `NULL == SrcDevice`
691+
/// - ::OL_ERRC_INVALID_NULL_POINTER
692+
/// + `NULL == DstPtr`
693+
/// + `NULL == SrcPtr`
694+
OL_APIEXPORT ol_result_t OL_APICALL olEnqueueMemcpy(
695+
// [in] handle of the queue
696+
ol_queue_handle_t Queue,
697+
// [in] pointer to copy to
698+
void *DstPtr,
699+
// [in] device that DstPtr belongs to
700+
ol_device_handle_t DstDevice,
701+
// [in] pointer to copy from
702+
void *SrcPtr,
703+
// [in] device that SrcPtr belongs to
704+
ol_device_handle_t SrcDevice,
705+
// [in] size in bytes of data to copy
706+
size_t Size,
707+
// [out][optional] optional recorded event for the enqueued operation
708+
ol_event_handle_t *EventOut);
709+
656710
///////////////////////////////////////////////////////////////////////////////
657711
/// @brief Enqueue a write operation from host to device memory
658712
///
@@ -669,7 +723,7 @@ OL_APIEXPORT ol_result_t OL_APICALL olWaitEvent(
669723
/// - ::OL_ERRC_INVALID_NULL_POINTER
670724
/// + `NULL == DstPtr`
671725
/// + `NULL == SrcPtr`
672-
OL_APIEXPORT ol_result_t OL_APICALL olEnqueueDataWrite(
726+
OL_APIEXPORT ol_result_t OL_APICALL olEnqueueMemcpyHtoD(
673727
// [in] handle of the queue
674728
ol_queue_handle_t Queue,
675729
// [in] device pointer to copy to
@@ -695,7 +749,7 @@ OL_APIEXPORT ol_result_t OL_APICALL olEnqueueDataWrite(
695749
/// - ::OL_ERRC_INVALID_NULL_POINTER
696750
/// + `NULL == DstPtr`
697751
/// + `NULL == SrcPtr`
698-
OL_APIEXPORT ol_result_t OL_APICALL olEnqueueDataRead(
752+
OL_APIEXPORT ol_result_t OL_APICALL olEnqueueMemcpyDtoH(
699753
// [in] handle of the queue
700754
ol_queue_handle_t Queue,
701755
// [in] host pointer to copy to
@@ -722,7 +776,7 @@ OL_APIEXPORT ol_result_t OL_APICALL olEnqueueDataRead(
722776
/// - ::OL_ERRC_INVALID_NULL_POINTER
723777
/// + `NULL == DstPtr`
724778
/// + `NULL == SrcPtr`
725-
OL_APIEXPORT ol_result_t OL_APICALL olEnqueueDataCopy(
779+
OL_APIEXPORT ol_result_t OL_APICALL olEnqueueMemcpyDtoD(
726780
// [in] handle of the queue
727781
ol_queue_handle_t Queue,
728782
// [in] device that the destination pointer is resident on
@@ -1008,6 +1062,13 @@ typedef struct ol_get_device_info_size_params_t {
10081062
size_t **pPropSizeRet;
10091063
} ol_get_device_info_size_params_t;
10101064

1065+
///////////////////////////////////////////////////////////////////////////////
1066+
/// @brief Function parameters for olGetHostDevice
1067+
/// @details Each entry is a pointer to the parameter passed to the function;
1068+
typedef struct ol_get_host_device_params_t {
1069+
ol_device_handle_t **pDevice;
1070+
} ol_get_host_device_params_t;
1071+
10111072
///////////////////////////////////////////////////////////////////////////////
10121073
/// @brief Function parameters for olMemAlloc
10131074
/// @details Each entry is a pointer to the parameter passed to the function;
@@ -1078,38 +1139,51 @@ typedef struct ol_wait_event_params_t {
10781139
} ol_wait_event_params_t;
10791140

10801141
///////////////////////////////////////////////////////////////////////////////
1081-
/// @brief Function parameters for olEnqueueDataWrite
1142+
/// @brief Function parameters for olEnqueueMemcpy
1143+
/// @details Each entry is a pointer to the parameter passed to the function;
1144+
typedef struct ol_enqueue_memcpy_params_t {
1145+
ol_queue_handle_t *pQueue;
1146+
void **pDstPtr;
1147+
ol_device_handle_t *pDstDevice;
1148+
void **pSrcPtr;
1149+
ol_device_handle_t *pSrcDevice;
1150+
size_t *pSize;
1151+
ol_event_handle_t **pEventOut;
1152+
} ol_enqueue_memcpy_params_t;
1153+
1154+
///////////////////////////////////////////////////////////////////////////////
1155+
/// @brief Function parameters for olEnqueueMemcpyHtoD
10821156
/// @details Each entry is a pointer to the parameter passed to the function;
1083-
typedef struct ol_enqueue_data_write_params_t {
1157+
typedef struct ol_enqueue_memcpy_hto_d_params_t {
10841158
ol_queue_handle_t *pQueue;
10851159
void **pDstPtr;
10861160
void **pSrcPtr;
10871161
size_t *pSize;
10881162
ol_event_handle_t **pEventOut;
1089-
} ol_enqueue_data_write_params_t;
1163+
} ol_enqueue_memcpy_hto_d_params_t;
10901164

10911165
///////////////////////////////////////////////////////////////////////////////
1092-
/// @brief Function parameters for olEnqueueDataRead
1166+
/// @brief Function parameters for olEnqueueMemcpyDtoH
10931167
/// @details Each entry is a pointer to the parameter passed to the function;
1094-
typedef struct ol_enqueue_data_read_params_t {
1168+
typedef struct ol_enqueue_memcpy_dto_h_params_t {
10951169
ol_queue_handle_t *pQueue;
10961170
void **pDstPtr;
10971171
void **pSrcPtr;
10981172
size_t *pSize;
10991173
ol_event_handle_t **pEventOut;
1100-
} ol_enqueue_data_read_params_t;
1174+
} ol_enqueue_memcpy_dto_h_params_t;
11011175

11021176
///////////////////////////////////////////////////////////////////////////////
1103-
/// @brief Function parameters for olEnqueueDataCopy
1177+
/// @brief Function parameters for olEnqueueMemcpyDtoD
11041178
/// @details Each entry is a pointer to the parameter passed to the function;
1105-
typedef struct ol_enqueue_data_copy_params_t {
1179+
typedef struct ol_enqueue_memcpy_dto_d_params_t {
11061180
ol_queue_handle_t *pQueue;
11071181
ol_device_handle_t *pDstDevice;
11081182
void **pDstPtr;
11091183
void **pSrcPtr;
11101184
size_t *pSize;
11111185
ol_event_handle_t **pEventOut;
1112-
} ol_enqueue_data_copy_params_t;
1186+
} ol_enqueue_memcpy_dto_d_params_t;
11131187

11141188
///////////////////////////////////////////////////////////////////////////////
11151189
/// @brief Function parameters for olEnqueueKernelLaunch
@@ -1262,6 +1336,13 @@ OL_APIEXPORT ol_result_t OL_APICALL olGetDeviceInfoSizeWithCodeLoc(
12621336
ol_device_handle_t Device, ol_device_info_t PropName, size_t *PropSizeRet,
12631337
ol_code_location_t *CodeLocation);
12641338

1339+
///////////////////////////////////////////////////////////////////////////////
1340+
/// @brief Variant of olGetHostDevice that also sets source code location
1341+
/// information
1342+
/// @details See also ::olGetHostDevice
1343+
OL_APIEXPORT ol_result_t OL_APICALL olGetHostDeviceWithCodeLoc(
1344+
ol_device_handle_t *Device, ol_code_location_t *CodeLocation);
1345+
12651346
///////////////////////////////////////////////////////////////////////////////
12661347
/// @brief Variant of olMemAlloc that also sets source code location information
12671348
/// @details See also ::olMemAlloc
@@ -1327,26 +1408,35 @@ OL_APIEXPORT ol_result_t OL_APICALL olWaitEventWithCodeLoc(
13271408
ol_event_handle_t Event, ol_code_location_t *CodeLocation);
13281409

13291410
///////////////////////////////////////////////////////////////////////////////
1330-
/// @brief Variant of olEnqueueDataWrite that also sets source code location
1411+
/// @brief Variant of olEnqueueMemcpy that also sets source code location
1412+
/// information
1413+
/// @details See also ::olEnqueueMemcpy
1414+
OL_APIEXPORT ol_result_t OL_APICALL olEnqueueMemcpyWithCodeLoc(
1415+
ol_queue_handle_t Queue, void *DstPtr, ol_device_handle_t DstDevice,
1416+
void *SrcPtr, ol_device_handle_t SrcDevice, size_t Size,
1417+
ol_event_handle_t *EventOut, ol_code_location_t *CodeLocation);
1418+
1419+
///////////////////////////////////////////////////////////////////////////////
1420+
/// @brief Variant of olEnqueueMemcpyHtoD that also sets source code location
13311421
/// information
1332-
/// @details See also ::olEnqueueDataWrite
1333-
OL_APIEXPORT ol_result_t OL_APICALL olEnqueueDataWriteWithCodeLoc(
1422+
/// @details See also ::olEnqueueMemcpyHtoD
1423+
OL_APIEXPORT ol_result_t OL_APICALL olEnqueueMemcpyHtoDWithCodeLoc(
13341424
ol_queue_handle_t Queue, void *DstPtr, void *SrcPtr, size_t Size,
13351425
ol_event_handle_t *EventOut, ol_code_location_t *CodeLocation);
13361426

13371427
///////////////////////////////////////////////////////////////////////////////
1338-
/// @brief Variant of olEnqueueDataRead that also sets source code location
1428+
/// @brief Variant of olEnqueueMemcpyDtoH that also sets source code location
13391429
/// information
1340-
/// @details See also ::olEnqueueDataRead
1341-
OL_APIEXPORT ol_result_t OL_APICALL olEnqueueDataReadWithCodeLoc(
1430+
/// @details See also ::olEnqueueMemcpyDtoH
1431+
OL_APIEXPORT ol_result_t OL_APICALL olEnqueueMemcpyDtoHWithCodeLoc(
13421432
ol_queue_handle_t Queue, void *DstPtr, void *SrcPtr, size_t Size,
13431433
ol_event_handle_t *EventOut, ol_code_location_t *CodeLocation);
13441434

13451435
///////////////////////////////////////////////////////////////////////////////
1346-
/// @brief Variant of olEnqueueDataCopy that also sets source code location
1436+
/// @brief Variant of olEnqueueMemcpyDtoD that also sets source code location
13471437
/// information
1348-
/// @details See also ::olEnqueueDataCopy
1349-
OL_APIEXPORT ol_result_t OL_APICALL olEnqueueDataCopyWithCodeLoc(
1438+
/// @details See also ::olEnqueueMemcpyDtoD
1439+
OL_APIEXPORT ol_result_t OL_APICALL olEnqueueMemcpyDtoDWithCodeLoc(
13501440
ol_queue_handle_t Queue, ol_device_handle_t DstDevice, void *DstPtr,
13511441
void *SrcPtr, size_t Size, ol_event_handle_t *EventOut,
13521442
ol_code_location_t *CodeLocation);

0 commit comments

Comments
 (0)