Beispiel #1
0
void pocl_mem_manager_free_event (cl_event event)
{
  assert (event->status == CL_COMPLETE);
  POCL_LOCK (mm->event_lock);
  LL_PREPEND (mm->event_list, event);
  POCL_UNLOCK(mm->event_lock);
}
Beispiel #2
0
static void
text_tracer_event_updated (cl_event event, int status)
{
  cl_command_queue cq = event->queue;
  cl_ulong ts = cq->device->ops->get_timer_value (cq->device->data);
  _cl_command_node *node = event->command;
  char tmp_buffer[512];
  char *cur_buf = tmp_buffer;
  int text_size = 0;

  /* Some less integrated commands (clEnqueueReadBufferRect) do not use
   * standard mecanism, so check node to be non null */
  if (node == NULL)
    return;

  text_size = sprintf (cur_buf, "%"PRIu64" %s %s ", ts,
                       pocl_command_to_str (event->command_type),
                       pocl_status_to_str(event->status));
  cur_buf += text_size;
  /* Print more informations for some commonly used commands */
  switch (event->command_type)
    {
    case CL_COMMAND_READ_BUFFER:
      text_size += sprintf (cur_buf, "size=%"PRIuS", host_ptr=%p\n",
                            node->command.read.cb,
                            node->command.read.host_ptr);
      break;
    case CL_COMMAND_WRITE_BUFFER:
      text_size += sprintf (cur_buf, "size=%"PRIuS", host_ptr=%p\n\n",
                            node->command.write.cb,
                            node->command.write.host_ptr);
      break;
    case CL_COMMAND_COPY_BUFFER:
      text_size += sprintf (cur_buf, "size=%"PRIuS"\n", node->command.copy.cb);
      break;
    case CL_COMMAND_NDRANGE_KERNEL:
      text_size += sprintf (cur_buf, "name=%s\n",
                            node->command.run.kernel->name);
      break;
    case CL_COMMAND_FILL_BUFFER:
      text_size += sprintf (cur_buf, "size=%"PRIuS"\n", 
                            node->command.memfill.size);
      break;
    default:
      cur_buf[0] = '\n';
      text_size++;
    }

  POCL_LOCK (text_tracer_lock);
  fwrite (tmp_buffer, text_size, 1, text_tracer_file);
  POCL_UNLOCK (text_tracer_lock);
}
Beispiel #3
0
_cl_command_node* pocl_mem_manager_new_command ()
{
  _cl_command_node *cmd = NULL;
  POCL_LOCK (mm->cmd_lock);
  if (cmd = mm->cmd_list)
    LL_DELETE (mm->cmd_list, cmd);
  POCL_UNLOCK (mm->cmd_lock);
  
  if (cmd)
    return cmd;
  
  return calloc (1, sizeof (_cl_command_node));
}
Beispiel #4
0
void pocl_init_mem_manager (void)
{
  static unsigned int init_done = 0;
  static pocl_lock_t pocl_init_lock = POCL_LOCK_INITIALIZER;

  POCL_LOCK(pocl_init_lock);
  if (!mm)
    {
      mm = calloc (1, sizeof (pocl_mem_manager));
      POCL_INIT_LOCK (mm->event_lock);
      POCL_INIT_LOCK (mm->cmd_lock);
    }
  POCL_UNLOCK(pocl_init_lock);
}
Beispiel #5
0
_cl_command_node* pocl_mem_manager_new_command ()
{
  _cl_command_node *cmd = NULL;
  POCL_LOCK (mm->cmd_lock);
  if ((cmd = mm->cmd_list))
    LL_DELETE (mm->cmd_list, cmd);
  POCL_UNLOCK (mm->cmd_lock);
  
  if (cmd)
    {
      memset (cmd, 0, sizeof (struct _cl_command_node));
      return cmd;
    }
  return (_cl_command_node*) calloc (1, sizeof (_cl_command_node));
}
Beispiel #6
0
event_node* pocl_mem_manager_new_event_node ()
{
  event_node *ed = NULL;
  POCL_LOCK(mm->event_node_lock);
  if ((ed = mm->event_node_list))
    LL_DELETE (mm->event_node_list, ed);
  POCL_UNLOCK (mm->event_node_lock);
  
  if (ed)
    {
      memset (ed, 0, sizeof(event_node));
      return ed;
    }

  return calloc (1, sizeof (event_node));
}
Beispiel #7
0
cl_event pocl_mem_manager_new_event ()
{
  cl_event ev = NULL;
  POCL_LOCK (mm->event_lock);
  if ((ev = mm->event_list))
    {
      LL_DELETE (mm->event_list, ev);
      POCL_UNLOCK (mm->event_lock);
      return ev;
    }
  POCL_UNLOCK (mm->event_lock);

  ev = (struct _cl_event*) calloc (1, sizeof (struct _cl_event));
  POCL_INIT_OBJECT(ev);
  ev->pocl_refcount = 1;
  return ev;
}
Beispiel #8
0
void pocl_queue_list_delete(cl_command_queue q)
{
  POCL_LOCK(queue_lock);
  size_t i;
  for (i = 0; i < queue_size; ++i) {
    if (queue_list[i] == q) {
      queue_list[i] = NULL;
      goto unlock;
    }
  }
  // not found (?)
  POCL_MSG_WARN("command queue %p not found during deletion\n", q);

unlock:
  POCL_UNLOCK(queue_lock);
  return;
}
Beispiel #9
0
void
pocl_check_and_invalidate_cache (cl_program program,
                  int device_i, const char* device_tmpdir)
{
  int cache_dirty = 0;
  char *content = NULL, *s_ptr, *ss_ptr;
  int read = 0;

  POCL_LOCK(cache_lock);

  if (!pocl_get_bool_option("POCL_KERNEL_CACHE", POCL_BUILD_KERNEL_CACHE))
    {
      cache_dirty = 1;
      goto bottom;
    }

  /* If program contains "#include", disable caching
     Included headers might get modified, force recompilation in all the cases
     Yes, this is a very dirty way to find "# include"
     but we can live with this for now
   */
  if (!pocl_get_bool_option("POCL_KERNEL_CACHE_IGNORE_INCLUDES", 0) &&
      program->source)
    {
      for (s_ptr = program->source; (*s_ptr); s_ptr++)
        {
          if ((*s_ptr) == '#')
            {
              /* Skip all the white-spaces between # & include */
              for (ss_ptr = s_ptr+1; *ss_ptr == ' '; ss_ptr++) ;
              
              if (strncmp(ss_ptr, "include", 7) == 0)
                cache_dirty = 1;
            }
        }
    }

  bottom:
  if (cache_dirty)
    {
      pocl_remove_directory(device_tmpdir);
      mkdir(device_tmpdir, S_IRWXU);
    }

  POCL_UNLOCK(cache_lock);
}
Beispiel #10
0
cl_event pocl_mem_manager_new_event ()
{
  cl_event ev = NULL;
  POCL_LOCK (mm->event_lock);
  if (ev = mm->event_list)
    {
      LL_DELETE (mm->event_list, ev);
      POCL_UNLOCK (mm->event_lock);
      ev->pocl_refcount = 2; /* no need to lock because event is not in use */
      return ev;
    }
  POCL_UNLOCK (mm->event_lock);
    
  ev = calloc (1, sizeof (struct _cl_event));
  POCL_INIT_OBJECT(ev);
  ev->pocl_refcount = 2;
  return ev;
}
Beispiel #11
0
void pocl_init_queue_list()
{
  POCL_INIT_LOCK(queue_lock);

  POCL_LOCK(queue_lock);
  // will probably never need a realloc, but still
  queue_alloc = QUEUE_ALLOC_SIZE;

  queue_list = calloc(queue_alloc, sizeof(cl_command_queue));

  if (!queue_list)
    POCL_ABORT("unable to allocate queue list!");

  //atexit(pocl_finish_all_queues);

  POCL_UNLOCK(queue_lock);

}
Beispiel #12
0
void pocl_queue_list_insert(cl_command_queue q)
{
  POCL_LOCK(queue_lock);
  if (queue_size == queue_alloc) {
    // queue is full, try and compact it by removing the deleted queues
    pocl_compact_queue_list();
  }

  if (queue_size == queue_alloc) {
    // compaction failed to give us room
    cl_command_queue *resized = realloc(queue_list, queue_alloc + 256);
    if (!resized)
      POCL_ABORT("failed to enlarge queue list!");
    queue_list = resized;
    queue_alloc += 256;
  }

  queue_list[queue_size++] = q;
  POCL_UNLOCK(queue_lock);
}
Beispiel #13
0
void pocl_mem_manager_free_event (cl_event event)
{
  POCL_LOCK (mm->event_lock);
  LL_PREPEND (mm->event_list, event);
  POCL_UNLOCK(mm->event_lock);
}
Beispiel #14
0
void pocl_mem_manager_free_event_node (event_node *ed)
{
  POCL_LOCK (mm->event_node_lock);
  LL_PREPEND (mm->event_node_list, ed);
  POCL_UNLOCK (mm->event_node_lock);
}
Beispiel #15
0
void pocl_mem_manager_free_command (_cl_command_node *cmd_ptr)
{
  POCL_LOCK (mm->cmd_lock);
  LL_PREPEND (mm->cmd_list, cmd_ptr);
  POCL_UNLOCK(mm->cmd_lock);
}
Beispiel #16
0
void 
pocl_init_devices()
{
  static unsigned int init_done = 0;
  static pocl_lock_t pocl_init_lock = POCL_LOCK_INITIALIZER;

  int i, j, dev_index;
  char env_name[1024];
  char dev_name[MAX_DEV_NAME_LEN] = {0};
  unsigned int device_count[POCL_NUM_DEVICE_TYPES];

  if (init_done == 0)
    POCL_INIT_LOCK(pocl_init_lock);
  POCL_LOCK(pocl_init_lock);
  if (init_done) 
    {
      POCL_UNLOCK(pocl_init_lock);
      return;
    }

  /* Set a global debug flag, so we don't have to call pocl_get_bool_option
   * everytime we use the debug macros */
#ifdef POCL_DEBUG_MESSAGES
  pocl_debug_messages = pocl_get_bool_option("POCL_DEBUG", 0);
#endif

  /* Init operations */
  for (i = 0; i < POCL_NUM_DEVICE_TYPES; ++i)
    {
      pocl_devices_init_ops[i](&pocl_device_ops[i]);
      assert(pocl_device_ops[i].device_name != NULL);

      /* Probe and add the result to the number of probbed devices */
      assert(pocl_device_ops[i].probe);
      device_count[i] = pocl_device_ops[i].probe(&pocl_device_ops[i]);
      pocl_num_devices += device_count[i];
    }

  assert(pocl_num_devices > 0);
  pocl_devices = calloc(pocl_num_devices, sizeof(struct _cl_device_id));
  if (pocl_devices == NULL)
    POCL_ABORT("Can not allocate memory for devices\n");

  dev_index = 0;
  /* Init infos for each probbed devices */
  for (i = 0; i < POCL_NUM_DEVICE_TYPES; ++i)
    {
      assert(pocl_device_ops[i].init);
      for (j = 0; j < device_count[i]; ++j)
        {
          pocl_devices[dev_index].ops = &pocl_device_ops[i];
          /* The default value for the global memory space identifier is
             the same as the device id. The device instance can then override 
             it to point to some other device's global memory id in case of
             a shared global memory. */
          pocl_devices[dev_index].global_mem_id = dev_index;
          
          pocl_device_ops[i].init_device_infos(&pocl_devices[dev_index]);

          pocl_device_common_init(&pocl_devices[dev_index]);

          str_toupper(dev_name, pocl_device_ops[i].device_name);
          /* Check if there are device-specific parameters set in the
             POCL_DEVICEn_PARAMETERS env. */
          if (snprintf (env_name, 1024, "POCL_%s%d_PARAMETERS", dev_name, j) < 0)
            POCL_ABORT("Unable to generate the env string.");

          pocl_devices[dev_index].ops->init(&pocl_devices[dev_index], getenv(env_name));

          if (dev_index == 0)
            pocl_devices[dev_index].type |= CL_DEVICE_TYPE_DEFAULT;
          
          ++dev_index;
        }
    }

  init_done = 1;
  POCL_UNLOCK(pocl_init_lock);
}
Beispiel #17
0
void 
pocl_init_devices()
{
  static unsigned int init_done = 0;
  static unsigned int init_in_progress = 0;
  static pocl_lock_t pocl_init_lock = POCL_LOCK_INITIALIZER;

  unsigned i, j, dev_index;
  char env_name[1024];
  char dev_name[MAX_DEV_NAME_LEN] = {0};
  unsigned int device_count[POCL_NUM_DEVICE_TYPES];

  /* This is a workaround to a nasty problem with libhwloc: When
     initializing basic, it calls libhwloc to query device info.
     In case libhwloc has the OpenCL plugin installed, it initializes
     it and it leads to initializing pocl again which leads to an
     infinite loop. */

  if (init_in_progress)
      return;
  init_in_progress = 1;

  if (init_done == 0)
    POCL_INIT_LOCK(pocl_init_lock);
  POCL_LOCK(pocl_init_lock);
  if (init_done) 
    {
      POCL_UNLOCK(pocl_init_lock);
      return;
    }

  /* Set a global debug flag, so we don't have to call pocl_get_bool_option
   * everytime we use the debug macros */
#ifdef POCL_DEBUG_MESSAGES
  pocl_debug_messages = pocl_get_bool_option("POCL_DEBUG", 0);
#endif

  pocl_cache_init_topdir();

  pocl_init_queue_list();

  /* Init operations */
  for (i = 0; i < POCL_NUM_DEVICE_TYPES; ++i)
    {
      pocl_devices_init_ops[i](&pocl_device_ops[i]);
      assert(pocl_device_ops[i].device_name != NULL);

      /* Probe and add the result to the number of probbed devices */
      assert(pocl_device_ops[i].probe);
      device_count[i] = pocl_device_ops[i].probe(&pocl_device_ops[i]);
      pocl_num_devices += device_count[i];
    }

  assert(pocl_num_devices > 0);
  pocl_devices = (struct _cl_device_id*) calloc(pocl_num_devices, sizeof(struct _cl_device_id));
  if (pocl_devices == NULL)
    POCL_ABORT("Can not allocate memory for devices\n");

  dev_index = 0;
  /* Init infos for each probed devices */
  for (i = 0; i < POCL_NUM_DEVICE_TYPES; ++i)
    {
      assert(pocl_device_ops[i].init);
      for (j = 0; j < device_count[i]; ++j)
        {
          pocl_devices[dev_index].ops = &pocl_device_ops[i];
          pocl_devices[dev_index].dev_id = dev_index;
          /* The default value for the global memory space identifier is
             the same as the device id. The device instance can then override 
             it to point to some other device's global memory id in case of
             a shared global memory. */
          pocl_devices[dev_index].global_mem_id = dev_index;
          
          pocl_device_ops[i].init_device_infos(&pocl_devices[dev_index]);

          pocl_device_common_init(&pocl_devices[dev_index]);

          str_toupper(dev_name, pocl_device_ops[i].device_name);
          /* Check if there are device-specific parameters set in the
             POCL_DEVICEn_PARAMETERS env. */
          if (snprintf (env_name, 1024, "POCL_%s%d_PARAMETERS", dev_name, j) < 0)
            POCL_ABORT("Unable to generate the env string.");

          pocl_devices[dev_index].ops->init(&pocl_devices[dev_index], getenv(env_name));

          if (dev_index == 0)
            pocl_devices[dev_index].type |= CL_DEVICE_TYPE_DEFAULT;

          pocl_devices[dev_index].cache_dir_name = strdup(pocl_devices[dev_index].long_name);
          pocl_string_to_dirname(pocl_devices[dev_index].cache_dir_name);
          
          ++dev_index;
        }
    }

  init_done = 1;
  POCL_UNLOCK(pocl_init_lock);
}