示例#1
0
文件: pocl_util.c 项目: larsmans/pocl
cl_int pocl_create_command (_cl_command_node **cmd,
                            cl_command_queue command_queue,
                            cl_command_type command_type, cl_event *event_p,
                            cl_int num_events, const cl_event *wait_list)
{
  int i;
  int err;
  cl_event *event = NULL;
  /* the provided waiting list will be cloned, because the calling program
   * might recycle the array for a different command.
   */
  cl_event *event_wl = NULL;
  /* Additionally, if the command queue is non-empty and in-order, we want to
   * add the previous command to the waiting list: double-bang to ensure that
   * add_prev_command will be 1 in this case, and 0 otherwise
   */
  cl_int add_prev_command = !!(
    !(command_queue->properties & CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE)
    && command_queue->root != NULL);

  if ((wait_list == NULL && num_events != 0) ||
      (wait_list != NULL && num_events == 0))
    return CL_INVALID_EVENT_WAIT_LIST;

  for (i = 0; i < num_events; ++i)
    {
      if (wait_list[i] == NULL)
        return CL_INVALID_EVENT_WAIT_LIST;
    }

  *cmd = pocl_mem_manager_new_command ();

  if (*cmd == NULL)
    return CL_OUT_OF_HOST_MEMORY;

  if (num_events || add_prev_command)
    {
      event_wl = (cl_event*)malloc((num_events + add_prev_command)*sizeof(cl_event));
      if (event_wl == NULL)
        return CL_OUT_OF_HOST_MEMORY;
    }

  /* if user does not provide event pointer, create event anyway */
  event = &((*cmd)->event);
  err = pocl_create_event(event, command_queue->context, command_queue, command_type);
  if (err != CL_SUCCESS)
    {
      POCL_MEM_FREE(event_wl);
      POCL_MEM_FREE(*cmd);
      return err;
    }
  if (event_p)
    *event_p = *event;
  else
    (*event)->implicit_event = 1;

  /* clone the event list */
  for (i = 0; i < num_events; ++i)
    {
      event_wl[i] = wait_list[i];
    }

  if (add_prev_command)
    {
      // find the previous command
      _cl_command_node *prev_command;
      for (prev_command = command_queue->root; prev_command->next != NULL;
           prev_command = prev_command->next){}
      //printf("create_command: prev_com=%d prev_com->event = %d \n",prev_command, prev_command->event);
      event_wl[i] = prev_command->event;
    }
#if 0
  for (i = 0; i < num_events + add_prev_command; ++i)
    {
      printf("create-command: event_wl[%i]=%p\n", i, event_wl[i]);
    }
#endif
  (*cmd)->event_wait_list = event_wl;
  (*cmd)->num_events_in_wait_list = num_events + add_prev_command;
  (*cmd)->type = command_type;
  (*cmd)->next = NULL;
  (*cmd)->device = command_queue->device;

  //printf("create_command (end): event=%d new_event=%d cmd->event=%d cmd=%d\n", event, new_event, (*cmd)->event, *cmd);


  return CL_SUCCESS;
}
示例#2
0
文件: pocl_util.c 项目: kylelutz/pocl
cl_int pocl_create_command (_cl_command_node **cmd, 
                            cl_command_queue command_queue, 
                            cl_command_type command_type, cl_event *event, 
                            cl_int num_events, const cl_event *wait_list)
{
  int i;
  int err;
  cl_event new_event = NULL;

  if ((wait_list == NULL && num_events != 0) ||
      (wait_list != NULL && num_events == 0))
    return CL_INVALID_EVENT_WAIT_LIST;
  
  for (i = 0; i < num_events; ++i)
    {
      if (wait_list[i] == NULL)
        return CL_INVALID_EVENT_WAIT_LIST;
    }
  
  (*cmd) = (_cl_command_node*)malloc (sizeof (_cl_command_node));
  if (*cmd == NULL)
    return CL_OUT_OF_HOST_MEMORY;
  
  if (event == NULL)
    {
      err = pocl_create_event(&new_event, command_queue, 0);
      if (err != CL_SUCCESS)
        {
          free (*cmd);
          return err;
        }
    }

  /* if in-order command queue and queue is not empty, add event from 
     previous command to new commands event_waitlist */
  if (!(command_queue->properties & CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE) 
      && command_queue->root != NULL)
    {
      _cl_command_node *prev_command;
      for (prev_command = command_queue->root; prev_command->next != NULL;
           prev_command = prev_command->next){}
      //printf("create_command: prev_com=%d prev_com->event = %d \n",prev_command, prev_command->event);
      cl_event *new_wl = (cl_event*)malloc ((num_events +1)*sizeof (cl_event));
      for (i = 0; i < num_events; ++i)
        {
          new_wl[i] = wait_list[i];
        }
      new_wl[i] = prev_command->event;
      (*cmd)->event_wait_list = new_wl;
      (*cmd)->num_events_in_wait_list = num_events + 1;
      for (i = 0; i < num_events + 1; ++i)
        {
          //printf("create-command: new_wl[%i]=%d\n", i, new_wl[i]);
        }
    }
  else
    {
      (*cmd)->event_wait_list = wait_list;  
      (*cmd)->num_events_in_wait_list = num_events;
    }
  (*cmd)->type = command_type;
  (*cmd)->next = NULL;
  (*cmd)->event = event ? (*event) : new_event;
  (*cmd)->device = command_queue->device;

  //printf("create_command (end): event=%d new_event=%d cmd->event=%d cmd=%d\n", event, new_event, (*cmd)->event, *cmd);
  

  return CL_SUCCESS;
}