Example #1
0
cl_int pocl_create_event (cl_event *event, cl_context context,
                          cl_command_queue command_queue,
                          cl_command_type command_type)
{
  if (context == NULL || !(context->valid))
    return CL_INVALID_CONTEXT;
  if (event != NULL)
    {
      *event = pocl_mem_manager_new_event ();
      if (event == NULL)
        return CL_OUT_OF_HOST_MEMORY;

      (*event)->context = context;
      POname(clRetainContext) (context);
      (*event)->queue = command_queue;
      /* user events have a NULL command queue, don't retain it */
      if (command_queue)
        POname(clRetainCommandQueue) (command_queue);
      (*event)->command_type = command_type;
      (*event)->callback_list = NULL;
      (*event)->implicit_event = 0;
      (*event)->next = NULL;
    }
  return CL_SUCCESS;
}
Example #2
0
cl_int pocl_create_event (cl_event *event, cl_command_queue command_queue, 
                          cl_command_type command_type)
{
  if (event != NULL)
    {
      *event = (cl_event)malloc (sizeof (struct _cl_event));
      if (event == NULL)
        return CL_OUT_OF_HOST_MEMORY;
      
      POCL_INIT_OBJECT(*event);
      (*event)->queue = command_queue;
      POname(clRetainCommandQueue) (command_queue);
      (*event)->command_type = command_type;
      (*event)->callback_list = NULL;
    }
  return CL_SUCCESS;
}
Example #3
0
cl_int pocl_create_event (cl_event *event, cl_command_queue command_queue, 
                          cl_command_type command_type)
{
  if (event != NULL)
    {
      *event = pocl_mem_manager_new_event ();
      if (event == NULL)
        return CL_OUT_OF_HOST_MEMORY;
      
      (*event)->queue = command_queue;
      POname(clRetainCommandQueue) (command_queue);
      (*event)->command_type = command_type;
      (*event)->callback_list = NULL;
      (*event)->implicit_event = 0;
      (*event)->next = NULL;
    }
  return CL_SUCCESS;
}
Example #4
0
int context_set_properties(cl_context                    context,
                           const cl_context_properties * properties,
                           cl_int *                      errcode)
{
  unsigned i;
  int num_properties = 0;
  
  context->properties = NULL;
  
  /* verify if data in properties is valid
   * and set them */
  if (properties)
    {
      const cl_context_properties *p = properties;
      const cl_context_properties *q;
      
      cl_platform_id platforms[1];
      cl_uint num_platforms;
      cl_bool platform_found;

      POname(clGetPlatformIDs)(1, platforms, &num_platforms);

      num_properties = 0;
      while (p[0] != 0)
        {
          /* redefinition of the same property */
          for(q=properties; q<p; q+=2)
            if (q[0] == p[0])
              {
                POCL_MSG_ERR("Duplicate properties: %lu\n", (unsigned long)q[0]);
                *errcode = CL_INVALID_PROPERTY; 
                return 0;
              }
          
          switch (p[0])
            {
            case CL_CONTEXT_PLATFORM:

              /* pocl just have one platform */
              platform_found = CL_FALSE;
              for (i=0; i<num_platforms; i++)
                if ((cl_platform_id)p[1] == platforms[i])
                  platform_found = CL_TRUE;

              if (platform_found == CL_FALSE)
                {
                  POCL_MSG_ERR("Could not find platform %p\n", (void*)p[1]);
                  *errcode = CL_INVALID_PLATFORM;
                  return 0;
                }

              p += 2;
              break;

            default: 
              POCL_MSG_ERR("Unknown context property: %lu\n", (unsigned long)p[0]);
              *errcode = CL_INVALID_PROPERTY;
              return 0;
            }
          num_properties++;
        }

      context->properties = (cl_context_properties *) malloc
        ((num_properties * 2 + 1) * sizeof(cl_context_properties));
      if (context->properties == NULL)
        {
          *errcode = CL_OUT_OF_HOST_MEMORY;
          return 0;
        }
      
      memcpy(context->properties, properties, 
             (num_properties * 2 + 1) * sizeof(cl_context_properties));
      context->num_properties = num_properties;

      *errcode = 0;
      return num_properties;
    }
  else
    {
      context->properties     = NULL;
      context->num_properties = 0;
      
      *errcode = 0;
      return 0;
    }
}
Example #5
0
static void exec_commands (_cl_command_node *node_list)
{
  int i;
  cl_event *event;
  _cl_command_node *node;
  cl_command_queue command_queue = NULL;
  LL_FOREACH (node_list, node)
    {
      event = &(node->event);
      /* Command queue is needed for POCL_UPDATE_EVENT macros */
      if (node->event)
        command_queue = node->event->queue;

      switch (node->type)
        {
        case CL_COMMAND_READ_BUFFER:
          POCL_UPDATE_EVENT_RUNNING;
          node->device->read
            (node->command.read.data, 
             node->command.read.host_ptr, 
             node->command.read.device_ptr, 
             node->command.read.cb); 
          POCL_UPDATE_EVENT_COMPLETE;
          POname(clReleaseMemObject) (node->command.read.buffer);
          break;
        case CL_COMMAND_WRITE_BUFFER:
          POCL_UPDATE_EVENT_RUNNING;
          node->device->write
            (node->command.write.data, 
             node->command.write.host_ptr, 
             node->command.write.device_ptr, 
             node->command.write.cb);
          POCL_UPDATE_EVENT_COMPLETE;
          POname(clReleaseMemObject) (node->command.write.buffer);
          break;
        case CL_COMMAND_COPY_BUFFER:
          POCL_UPDATE_EVENT_RUNNING;
          node->device->copy
            (node->command.copy.data, 
             node->command.copy.src_ptr, 
             node->command.copy.dst_ptr,
             node->command.copy.cb);
          POCL_UPDATE_EVENT_COMPLETE;
          POname(clReleaseMemObject) (node->command.copy.src_buffer);
          POname(clReleaseMemObject) (node->command.copy.dst_buffer);
          break;
        case CL_COMMAND_MAP_BUFFER: 
          POCL_UPDATE_EVENT_RUNNING;            
          pocl_map_mem_cmd (node->device, node->command.map.buffer, 
                            node->command.map.mapping);
          POCL_UPDATE_EVENT_COMPLETE;
          break;
        case CL_COMMAND_MAP_IMAGE:
          POCL_UPDATE_EVENT_RUNNING; 
          node->device->read_rect 
            (node->command.map_image.data, node->command.map_image.map_ptr,
             node->command.map_image.device_ptr, node->command.map_image.origin,
             node->command.map_image.origin, node->command.map_image.region, 
             node->command.map_image.rowpitch, 
             node->command.map_image.slicepitch,
             node->command.map_image.rowpitch,
             node->command.map_image.slicepitch);
          POCL_UPDATE_EVENT_COMPLETE;
          break;
        case CL_COMMAND_WRITE_IMAGE:
          POCL_UPDATE_EVENT_RUNNING; 
          node->device->write_rect 
            (node->command.map_image.data, node->command.map_image.map_ptr,
             node->command.map_image.device_ptr, node->command.map_image.origin,
             node->command.map_image.origin, node->command.map_image.region, 
             node->command.map_image.rowpitch, 
             node->command.map_image.slicepitch,
             node->command.map_image.rowpitch,
             node->command.map_image.slicepitch);
          POCL_UPDATE_EVENT_COMPLETE;
          break;
        case CL_COMMAND_READ_IMAGE:
          POCL_UPDATE_EVENT_RUNNING; 
          node->device->read_rect 
            (node->command.map_image.data, node->command.map_image.map_ptr,
             node->command.map_image.device_ptr, node->command.map_image.origin,
             node->command.map_image.origin, node->command.map_image.region, 
             node->command.map_image.rowpitch, 
             node->command.map_image.slicepitch,
             node->command.map_image.rowpitch,
             node->command.map_image.slicepitch);
          POCL_UPDATE_EVENT_COMPLETE;
          break;
        case CL_COMMAND_UNMAP_MEM_OBJECT:
          POCL_UPDATE_EVENT_RUNNING;
          if ((node->command.unmap.memobj)->flags & 
              (CL_MEM_USE_HOST_PTR | CL_MEM_ALLOC_HOST_PTR))
            {
              /* TODO: should we ensure the device global region is updated from
                 the host memory? How does the specs define it,
                 can the host_ptr be assumed to point to the host and the
                 device accessible memory or just point there until the
                 kernel(s) get executed or similar? */
              /* Assume the region is automatically up to date. */
            } else 
            {
              /* TODO: fixme. The offset computation must be done at the device 
                 driver. */
              if (node->device->unmap_mem != NULL)        
                node->device->unmap_mem
                  (node->device->data, 
                   (node->command.unmap.mapping)->host_ptr, 
                   (node->command.unmap.memobj)->device_ptrs[node->device->dev_id], 
                   (node->command.unmap.mapping)->size);
            }
          DL_DELETE((node->command.unmap.memobj)->mappings, 
                    node->command.unmap.mapping);
          (node->command.unmap.memobj)->map_count--;
          POCL_UPDATE_EVENT_COMPLETE;
          break;
        case CL_COMMAND_NDRANGE_KERNEL:
          assert (*event == node->event);
          POCL_UPDATE_EVENT_RUNNING;
          node->device->run(node->command.run.data, node);
          POCL_UPDATE_EVENT_COMPLETE;
          for (i = 0; i < node->command.run.arg_buffer_count; ++i)
            {
              cl_mem buf = node->command.run.arg_buffers[i];
              if (buf == NULL) continue;
              /*printf ("### releasing arg %d - the buffer %x of kernel %s\n", i, 
                buf,  node->command.run.kernel->function_name); */
              POname(clReleaseMemObject) (buf);
            }
          free (node->command.run.arg_buffers);
          free (node->command.run.tmp_dir);
          for (i = 0; i < node->command.run.kernel->num_args + 
                 node->command.run.kernel->num_locals; ++i)
            {
              pocl_aligned_free (node->command.run.arguments[i].value);
            }
          free (node->command.run.arguments);
      
          POname(clReleaseKernel)(node->command.run.kernel);
          break;
        case CL_COMMAND_FILL_IMAGE:
          POCL_UPDATE_EVENT_RUNNING;
          node->device->fill_rect 
            (node->command.fill_image.data, 
             node->command.fill_image.device_ptr,
             node->command.fill_image.buffer_origin,
             node->command.fill_image.region,
             node->command.fill_image.rowpitch, 
             node->command.fill_image.slicepitch,
             node->command.fill_image.fill_pixel,
             node->command.fill_image.pixel_size);
          free(node->command.fill_image.fill_pixel);
          POCL_UPDATE_EVENT_COMPLETE;
          break;
        case CL_COMMAND_MARKER:
          POCL_UPDATE_EVENT_RUNNING;
          POCL_UPDATE_EVENT_COMPLETE;
          break;
        default:
          POCL_ABORT_UNIMPLEMENTED();
          break;
        }   
    }
Example #6
0
extern cl_int
pocl_check_device_supports_image(const cl_mem image,
                                 const cl_command_queue command_queue)
{
  cl_uint num_entries;
  cl_int errcode;
  const cl_device_id device = command_queue->device;
  cl_image_format* supported_image_formats = NULL;
  unsigned i;

  POCL_RETURN_ERROR_ON((!device->image_support), CL_INVALID_OPERATION,
          "Device does not support images");

  if (image->type == CL_MEM_OBJECT_IMAGE1D ||
      image->type == CL_MEM_OBJECT_IMAGE1D_ARRAY)
    {
      POCL_RETURN_ERROR_ON((image->image_width > device->image2d_max_width),
        CL_INVALID_IMAGE_SIZE, "Image width > device.image2d_max_width");
    }

  if (image->type == CL_MEM_OBJECT_IMAGE2D ||
      image->type == CL_MEM_OBJECT_IMAGE2D_ARRAY)
    {
      POCL_RETURN_ERROR_ON((image->image_width > device->image2d_max_width),
        CL_INVALID_IMAGE_SIZE, "Image width > device.image2d_max_width");
      POCL_RETURN_ERROR_ON((image->image_height > device->image2d_max_height),
        CL_INVALID_IMAGE_SIZE, "Image height > device.image2d_max_height");
    }

  if (image->type == CL_MEM_OBJECT_IMAGE3D)
    {
      POCL_RETURN_ERROR_ON((image->image_width > device->image3d_max_width),
        CL_INVALID_IMAGE_SIZE, "Image width > device.image3d_max_width");
      POCL_RETURN_ERROR_ON((image->image_height > device->image3d_max_height),
        CL_INVALID_IMAGE_SIZE, "Image height > device.image3d_max_height");
      POCL_RETURN_ERROR_ON((image->image_depth > device->image3d_max_depth),
        CL_INVALID_IMAGE_SIZE, "Image depth > device.image3d_max_depth");
    }

  /* check if image format is supported */
  errcode = POname(clGetSupportedImageFormats)
    (command_queue->context, 0, image->type, 0, NULL, &num_entries);

  POCL_RETURN_ERROR_ON((errcode != CL_SUCCESS), errcode,
        "clGetSupportedImageFormats call failed");

  POCL_RETURN_ERROR_ON((num_entries == 0), errcode,
        "This device does not support these images "
        "(clGetSupportedImageFormats returned 0 entries)");

  supported_image_formats = (cl_image_format*) malloc (num_entries * sizeof(cl_image_format));
  if (supported_image_formats == NULL)
      return CL_OUT_OF_HOST_MEMORY;

  errcode = POname(clGetSupportedImageFormats)
    (command_queue->context, 0, image->type, num_entries,
     supported_image_formats, NULL);

  POCL_GOTO_ERROR_ON((errcode != CL_SUCCESS), errcode,
        "2nd call of clGetSupportedImageFormats failed");

  for (i = 0; i < num_entries; i++)
    {
      if (supported_image_formats[i].image_channel_order ==
          image->image_channel_order &&
          supported_image_formats[i].image_channel_data_type ==
          image->image_channel_data_type)
        {
          errcode = CL_SUCCESS;
          goto ERROR;
        }
    }

  POCL_GOTO_ERROR_ON(1, CL_INVALID_IMAGE_FORMAT_DESCRIPTOR,
    "The image format is not supported by the device");

ERROR:
  free(supported_image_formats);
  return errcode;
}