Skip to content

Commit 8f329ef

Browse files
committed
fixme! save work on setting command node to failed.
1 parent ecfd50e commit 8f329ef

File tree

8 files changed

+77
-29
lines changed

8 files changed

+77
-29
lines changed

include/pocl.h

+15-1
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,17 @@ typedef union
506506
typedef struct _pocl_buffer_migration_info
507507
pocl_buffer_migration_info;
508508

509+
/**
510+
* Enum that represents different possible states of a command node.
511+
*/
512+
typedef enum
513+
{
514+
POCL_COMMAND_FAILED = -1,
515+
/* Default unless set to ready. */
516+
POCL_COMMAND_NOT_READY = 0,
517+
POCL_COMMAND_READY = 1,
518+
} pocl_command_state;
519+
509520
/* One item in a command queue or a command buffer. */
510521
typedef struct _cl_command_node _cl_command_node;
511522
struct _cl_command_node
@@ -538,7 +549,10 @@ struct _cl_command_node
538549
cl_device_id device;
539550
/* The index of the targeted device in the **program** device list. */
540551
unsigned program_device_i;
541-
cl_int ready;
552+
553+
/* Used to indicate if a node is ready to be executed or failed. */
554+
pocl_command_state state;
555+
542556
/* true if the node belongs to a cl_command_buffer_khr */
543557
cl_int buffered;
544558

lib/CL/devices/basic/basic.c

+9-4
Original file line numberDiff line numberDiff line change
@@ -524,14 +524,14 @@ pocl_basic_submit (_cl_command_node *node, cl_command_queue cq)
524524
{
525525
pocl_update_event_running_unlocked (node->sync.event.event);
526526
POCL_UNLOCK_OBJ (node->sync.event.event);
527-
POCL_UPDATE_EVENT_FAILED (node->sync.event.event);
527+
POCL_UPDATE_EVENT_FAILED (CL_FAILED, node->sync.event.event);
528528
return;
529529
}
530530
node->command.run.device_data = handle;
531531
}
532532
}
533533

534-
node->ready = 1;
534+
node->state = POCL_COMMAND_READY;
535535
POCL_LOCK (d->cq_lock);
536536
pocl_command_push(node, &d->ready_list, &d->command_list);
537537

@@ -575,8 +575,13 @@ pocl_basic_notify (cl_device_id device, cl_event event, cl_event finished)
575575
return;
576576
}
577577

578-
if (!node->ready)
579-
return;
578+
if (node->state != POCL_COMMAND_READY)
579+
{
580+
POCL_MSG_PRINT_EVENTS (
581+
"basic: command related to the notified event %lu not ready\n",
582+
event->id);
583+
return;
584+
}
580585

581586
if (pocl_command_is_ready (event))
582587
{

lib/CL/devices/common.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,7 @@ pocl_exec_command (_cl_command_node *node)
823823
default:
824824
pocl_update_event_running (event);
825825
POCL_UPDATE_EVENT_FAILED_MSG (
826-
event, "pocl_exec_command: Unknown command type\n");
826+
CL_FAILED, event, "pocl_exec_command: Unknown command type\n");
827827
break;
828828
}
829829
}

lib/CL/devices/pthread/pthread.c

+8-3
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ pocl_pthread_run (void *data, _cl_command_node *cmd)
215215
void
216216
pocl_pthread_submit (_cl_command_node *node, cl_command_queue cq)
217217
{
218-
node->ready = 1;
218+
node->state = POCL_COMMAND_READY;
219219
if (pocl_command_is_ready (node->sync.event.event))
220220
{
221221
pocl_update_event_submitted (node->sync.event.event);
@@ -262,8 +262,13 @@ pocl_pthread_notify (cl_device_id device, cl_event event, cl_event finished)
262262
return;
263263
}
264264

265-
if (!node->ready)
266-
return;
265+
if (node->state != POCL_COMMAND_READY)
266+
{
267+
POCL_MSG_PRINT_EVENTS (
268+
"pthread: command related to the notified event %lu not ready\n",
269+
event->id);
270+
return;
271+
}
267272

268273
if (pocl_command_is_ready (node->sync.event.event))
269274
{

lib/CL/devices/pthread/pthread_scheduler.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ pocl_pthread_prepare_kernel (void *data, _cl_command_node *cmd)
443443
!= 0)
444444
{
445445
pocl_update_event_running (cmd->sync.event.event);
446-
POCL_UPDATE_EVENT_FAILED_MSG (cmd->sync.event.event,
446+
POCL_UPDATE_EVENT_FAILED_MSG (CL_FAILED, cmd->sync.event.event,
447447
"CPU: failed to compile GVar init kernel");
448448
return NULL;
449449
}
@@ -456,7 +456,7 @@ pocl_pthread_prepare_kernel (void *data, _cl_command_node *cmd)
456456
if (ci == NULL)
457457
{
458458
pocl_update_event_running (cmd->sync.event.event);
459-
POCL_UPDATE_EVENT_FAILED_MSG (cmd->sync.event.event,
459+
POCL_UPDATE_EVENT_FAILED_MSG (CL_FAILED, cmd->sync.event.event,
460460
"CPU: failed to compile kernel");
461461
return NULL;
462462
}

lib/CL/devices/remote/remote.c

+16-4
Original file line numberDiff line numberDiff line change
@@ -1536,7 +1536,7 @@ pocl_remote_submit (_cl_command_node *node, cl_command_queue cq)
15361536
POCL_INIT_COND (e_d->event_cond);
15371537
e->data = (void *)e_d;
15381538

1539-
node->ready = 1;
1539+
node->state = POCL_COMMAND_READY;
15401540
if (pocl_command_is_ready (node->sync.event.event))
15411541
{
15421542
pocl_update_event_submitted (node->sync.event.event);
@@ -1599,7 +1599,7 @@ pocl_remote_notify (cl_device_id device, cl_event event, cl_event finished)
15991599
return;
16001600
}
16011601

1602-
if (!node->ready)
1602+
if (node->state != POCL_COMMAND_READY)
16031603
{
16041604
POCL_MSG_PRINT_EVENTS (
16051605
"remote: command related to the notified event %lu not ready\n",
@@ -2424,7 +2424,8 @@ remote_start_command (remote_device_data_t *d, _cl_command_node *node)
24242424

24252425
if (*(cq->device->available) == CL_FALSE)
24262426
{
2427-
pocl_update_event_device_lost (event);
2427+
// pocl_update_event_device_lost (event);
2428+
node->state = POCL_COMMAND_FAILED;
24282429
goto EARLY_FINISH;
24292430
}
24302431
pocl_update_event_running (event);
@@ -2739,7 +2740,18 @@ pocl_remote_driver_pthread (void *cldev)
27392740
char msg[128] = "Event ";
27402741
strcat (msg, cstr);
27412742

2742-
POCL_UPDATE_EVENT_COMPLETE_MSG (event, msg);
2743+
/* update event status */
2744+
if (finished->state == POCL_COMMAND_READY)
2745+
{
2746+
POCL_UPDATE_EVENT_COMPLETE_MSG (event, msg);
2747+
}
2748+
else
2749+
{
2750+
cl_int status = CL_FAILED;
2751+
if (*(event->queue->device->available) == CL_FALSE)
2752+
status = CL_DEVICE_NOT_AVAILABLE;
2753+
POCL_UPDATE_EVENT_FAILED_MSG (status, event, msg);
2754+
}
27432755

27442756
POCL_LOCK (d->wq_lock);
27452757
}

lib/CL/pocl_util.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -2103,12 +2103,15 @@ pocl_update_event_finished (cl_int status, const char *func, unsigned line,
21032103
}
21042104

21052105
void
2106-
pocl_update_event_failed (const char *func,
2106+
pocl_update_event_failed (cl_int status,
2107+
const char *func,
21072108
unsigned line,
21082109
cl_event event,
21092110
const char *msg)
21102111
{
2111-
pocl_update_event_finished (CL_FAILED, func, line, event, msg);
2112+
/* Should only be used with error statuses. */
2113+
assert (status < 0);
2114+
pocl_update_event_finished (status, func, line, event, msg);
21122115
}
21132116

21142117
void

lib/CL/pocl_util.h

+21-12
Original file line numberDiff line numberDiff line change
@@ -286,16 +286,25 @@ void pocl_update_event_complete (const char *func, unsigned line,
286286
cl_event event, const char *msg);
287287

288288
/**
289-
* Should be called by a driver when the event execution fails for some reason
289+
* Mark the event as failed with the status and do all the required
290+
* cleanup work (releasing memory, notifying others waiting on the event, etc).
290291
*
291-
* Sets the event status to failure (CL_FAILED) and does all the required
292-
* cleanup work (releasing memory, notifying others waiting on the event, etc)
292+
* \warning Call with event unlocked.
293+
* \warning Eventually clReleaseEvent is called, so this function can end up
294+
* freeing the event.
295+
* \param status [in] Status to be set for the event. Should be an error status
296+
* like CL_FAILED or CL_DEVICE_NOT_AVAILABLE.
297+
* \param func [in] Can be NULL, the function name calling this function.
298+
* \param line [in] Can be 0, the line number which failed.
299+
* \param event [in/out] Event to be marked as failed.
300+
* \param msg [in] Can be NULL, informative error message.
293301
*/
294-
POCL_EXPORT
295-
void pocl_update_event_failed (const char *func,
296-
unsigned line,
297-
cl_event event,
298-
const char *msg);
302+
POCL_EXPORT void
303+
pocl_update_event_failed (cl_int status,
304+
const char *func,
305+
unsigned line,
306+
cl_event event,
307+
const char *msg);
299308

300309
/**
301310
* Same as pocl_update_event_failed, except assumes the event is locked.
@@ -313,11 +322,11 @@ void pocl_update_event_device_lost (cl_event event);
313322
#define POCL_UPDATE_EVENT_COMPLETE(__event) \
314323
pocl_update_event_complete (__func__, __LINE__, (__event), NULL)
315324

316-
#define POCL_UPDATE_EVENT_FAILED(__event) \
317-
pocl_update_event_failed (__func__, __LINE__, (__event), NULL)
325+
#define POCL_UPDATE_EVENT_FAILED(status, __event) \
326+
pocl_update_event_failed ((status), __func__, __LINE__, (__event), NULL)
318327

319-
#define POCL_UPDATE_EVENT_FAILED_MSG(__event, msg) \
320-
pocl_update_event_failed (__func__, __LINE__, (__event), msg)
328+
#define POCL_UPDATE_EVENT_FAILED_MSG(status, __event, msg) \
329+
pocl_update_event_failed ((status), __func__, __LINE__, (__event), msg)
321330

322331
POCL_EXPORT
323332
int pocl_copy_command_node (_cl_command_node *dst_node,

0 commit comments

Comments
 (0)