Skip to content

Commit 554a8eb

Browse files
authored
Merge pull request #10959 from wckzhang/ipcapi
opal/accelerator: Add IPC APIs
2 parents 4984355 + b816edf commit 554a8eb

File tree

1 file changed

+155
-2
lines changed

1 file changed

+155
-2
lines changed

opal/mca/accelerator/accelerator.h

Lines changed: 155 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,19 @@ struct opal_accelerator_stream_t {
111111
};
112112
typedef struct opal_accelerator_stream_t opal_accelerator_stream_t;
113113

114+
#define MAX_IPC_HANDLE_SIZE 64
115+
struct opal_accelerator_ipc_handle_t {
116+
size_t size;
117+
uint8_t handle[MAX_IPC_HANDLE_SIZE];
118+
};
119+
typedef struct opal_accelerator_ipc_handle_t opal_accelerator_ipc_handle_t;
120+
121+
struct opal_accelerator_ipc_event_handle_t {
122+
size_t size;
123+
uint8_t handle[MAX_IPC_HANDLE_SIZE];
124+
};
125+
typedef struct opal_accelerator_ipc_event_handle_t opal_accelerator_ipc_event_handle_t;
126+
114127
struct opal_accelerator_pci_attr_t {
115128
uint16_t domain_id;
116129
uint8_t bus_id;
@@ -150,7 +163,9 @@ typedef int (*opal_accelerator_base_module_check_addr_fn_t)(
150163

151164
/**
152165
* Creates a stream for asynchonous operations. This function will allocate
153-
* memory for the object. To release the memory, call OBJ_RELEASE(*stream);
166+
* memory for the object.
167+
* To release the memory and associated resources,
168+
* call opal_accelerator_base_module_create_stream_fn_t
154169
*
155170
* @param[IN] dev_id Associated device for the stream or
156171
* MCA_ACCELERATOR_NO_DEVICE_ID
@@ -161,11 +176,45 @@ typedef int (*opal_accelerator_base_module_check_addr_fn_t)(
161176
typedef int (*opal_accelerator_base_module_create_stream_fn_t)(
162177
int dev_id, opal_accelerator_stream_t **stream);
163178

179+
/**
180+
* Destroys a stream and release the object memory.
181+
* This function should return immediately, but resources associated with
182+
* the stream may be released later.
183+
*
184+
* @param[IN] stream Stream to destroy
185+
*
186+
* @return OPAL_SUCCESS or error status on failure
187+
*/
188+
typedef int (*opal_accelerator_base_module_destroy_stream_fn_t)(
189+
opal_accelerator_stream_t *stream);
190+
191+
/**
192+
* Wait until a stream's operations are complete
193+
*
194+
* @param[IN] stream Stream to wait for
195+
*
196+
* @return OPAL_SUCCESS or error status on failure
197+
*/
198+
typedef int (*opal_accelerator_base_module_synchronize_stream_fn_t)(
199+
opal_accelerator_stream_t *stream);
200+
201+
/**
202+
* Make a stream wait on an event
203+
*
204+
* @param[IN] stream Stream to wait
205+
* @param[IN] event Event to wait on
206+
*
207+
* @return OPAL_SUCCESS or error status on failure
208+
*/
209+
typedef int (*opal_accelerator_base_module_stream_wait_event_fn_t)(
210+
opal_accelerator_stream_t *stream, opal_accelerator_event_t *event);
211+
164212
/**
165213
* Creates an event. An event is a synchronization marker that can be
166214
* appended to a stream to monitor device progress or synchronize the
167215
* corresponding stream. This function will allocate memory for the object.
168-
* To release the memory, call OBJ_RELEASE(*event);
216+
* To release the object memory and associated resources
217+
* call opal_accelerator_base_module_destroy_event_fn_t
169218
*
170219
* @param[IN] dev_id Associated device for the event or
171220
* MCA_ACCELERATOR_NO_DEVICE_ID
@@ -176,6 +225,18 @@ typedef int (*opal_accelerator_base_module_create_stream_fn_t)(
176225
typedef int (*opal_accelerator_base_module_create_event_fn_t)(
177226
int dev_id, opal_accelerator_event_t **event);
178227

228+
/**
229+
* Destroys an event and release the object memory.
230+
* This function should return immediately, but the event may complete
231+
* and associated resources are released later.
232+
*
233+
* @param[IN] event Event to destroy
234+
*
235+
* @return OPAL_SUCCESS or error status on failure.
236+
*/
237+
typedef int (*opal_accelerator_base_module_destroy_event_fn_t)(
238+
opal_accelerator_event_t *event);
239+
179240
/**
180241
* Records an event on a stream. An event recorded on the stream is
181242
* a synchronization marker that can be used to monitor the device's
@@ -318,6 +379,87 @@ typedef int (*opal_accelerator_base_module_mem_release_fn_t)(
318379
typedef int (*opal_accelerator_base_module_get_address_range_fn_t)(
319380
int dev_id, const void *ptr, void **base, size_t *size);
320381

382+
/*********************************************************/
383+
/**** Inter Process Communication (IPC) Functions ****/
384+
/*********************************************************/
385+
386+
/**
387+
* Queries whether the device supports IPC or not.
388+
*
389+
* If true, the functions:
390+
*
391+
* opal_accelerator_base_module_get_ipc_handle_fn_t()
392+
* opal_accelerator_base_module_open_ipc_handle_fn_t()
393+
* opal_accelerator_base_module_close_ipc_handle_fn_t()
394+
*
395+
* must be implemented.
396+
*
397+
* @return true IPC supported
398+
* @return false IPC not supported
399+
*/
400+
typedef bool (*opal_accelerator_base_module_is_ipc_enabled_fn_t)(void);
401+
402+
/**
403+
* Gets an IPC memory handle for an existing device memory allocation.
404+
*
405+
* @param[IN] dev_id Associated device for the IPC memory handle or
406+
* MCA_ACCELERATOR_NO_DEVICE_ID
407+
* @param[IN] dev_ptr Device memory address
408+
* @param[OUT] handle Pointer to IPC handle object
409+
*
410+
* @return OPAL_SUCCESS or error status on failure
411+
*
412+
*/
413+
typedef int (*opal_accelerator_base_module_get_ipc_handle_fn_t)(
414+
int dev_id, void *dev_ptr, opal_accelerator_ipc_handle_t *handle);
415+
416+
/**
417+
* Opens an IPC memory handle from another process and returns
418+
* a device pointer usable in the local process.
419+
*
420+
* @param[IN] dev_id Associated device for the IPC memory handle or
421+
* MCA_ACCELERATOR_NO_DEVICE_ID
422+
* @param[IN] handle IPC handle object from another process
423+
* @param[OUT] dev_ptr Returned device pointer
424+
*
425+
* @return OPAL_SUCCESS or error status on failure
426+
*/
427+
typedef int (*opal_accelerator_base_module_open_ipc_handle_fn_t)(
428+
int dev_id, opal_accelerator_ipc_handle_t *handle, void **dev_ptr);
429+
430+
/**
431+
* Gets an IPC event handle for an event created by opal_accelerator_base_module_create_event_fn_t.
432+
*
433+
* @param[IN] event Event created previously
434+
* @param[OUT] handle Pointer to IPC event handle object
435+
*
436+
* @return OPAL_SUCCESS or error status on failure
437+
*/
438+
typedef int (*opal_accelerator_base_module_get_ipc_event_handle_fn_t)(
439+
opal_accelerator_event_t *event, opal_accelerator_ipc_event_handle_t *handle);
440+
441+
/**
442+
* Opens an IPC event handle from another process opened by
443+
* opal_accelerator_base_module_get_ipc_event_handle_fn_t.
444+
*
445+
* @param[IN] handle IPC event handle from another process
446+
* @param[OUT] event Pointer to store the opened event
447+
*
448+
* @return OPAL_SUCCESS or error status on failure
449+
*/
450+
typedef int (*opal_accelerator_base_module_open_ipc_event_handle_fn_t)(
451+
opal_accelerator_ipc_event_handle_t *handle, opal_accelerator_event_t *event);
452+
453+
/**
454+
* Closes IPC memory mapped with opal_accelerator_base_module_open_ipc_handle_fn_t().
455+
*
456+
* @param[IN] dev_id Associated device for the IPC memory handle or
457+
* MCA_ACCELERATOR_NO_DEVICE_ID
458+
* @param[IN] dev_ptr IPC device pointer returned from
459+
* opal_accelerator_base_module_open_ipc_handle_fn_t()
460+
*/
461+
typedef int (*opal_accelerator_base_module_close_ipc_handle_fn_t)(int dev_id, void *dev_ptr);
462+
321463
/**
322464
* Page-locks the memory range specified by ptr and size
323465
*
@@ -402,7 +544,11 @@ typedef struct {
402544
opal_accelerator_base_module_check_addr_fn_t check_addr;
403545

404546
opal_accelerator_base_module_create_stream_fn_t create_stream;
547+
opal_accelerator_base_module_destroy_stream_fn_t destroy_stream;
548+
opal_accelerator_base_module_synchronize_stream_fn_t synchronize_stream;
549+
opal_accelerator_base_module_stream_wait_event_fn_t stream_wait_event;
405550
opal_accelerator_base_module_create_event_fn_t create_event;
551+
opal_accelerator_base_module_destroy_event_fn_t destroy_event;
406552
opal_accelerator_base_module_record_event_fn_t record_event;
407553
opal_accelerator_base_module_query_event_fn_t query_event;
408554

@@ -414,6 +560,13 @@ typedef struct {
414560
opal_accelerator_base_module_mem_release_fn_t mem_release;
415561
opal_accelerator_base_module_get_address_range_fn_t get_address_range;
416562

563+
opal_accelerator_base_module_is_ipc_enabled_fn_t is_ipc_enabled;
564+
opal_accelerator_base_module_get_ipc_handle_fn_t get_ipc_handle;
565+
opal_accelerator_base_module_open_ipc_handle_fn_t open_ipc_handle;
566+
opal_accelerator_base_module_close_ipc_handle_fn_t close_ipc_handle;
567+
opal_accelerator_base_module_get_ipc_event_handle_fn_t get_ipc_event_handle;
568+
opal_accelerator_base_module_open_ipc_event_handle_fn_t open_ipc_event_handle;
569+
417570
opal_accelerator_base_module_host_register_fn_t host_register;
418571
opal_accelerator_base_module_host_unregister_fn_t host_unregister;
419572

0 commit comments

Comments
 (0)