Esempio n. 1
0
    def shaped(cls, ctx, shape, cl_dtype, order="C"):
        """Creates a LocalMemory instance with shape, type and order metadata.

        See :meth:`Buffer.shaped` for an explanation of the arguments.
        """
        size = cl_dtype.sizeof_for(ctx.device) * cypy.prod(shape)
        if size <= 0:
            raise Error("Invalid local memory size: %s." % str(size))
        local_mem = LocalMemory(size)
        local_mem.shape = shape
        local_mem.cl_dtype = cl_dtype
        local_mem.order = order
Esempio n. 2
0
 def shaped(cls, ctx, shape=None, cl_dtype=None, order=None,
            flags=mem_flags.READ_WRITE, hostbuf=None, constant=False):
     """Creates a Buffer with shape, element type and order metadata.        
     
     - If ``hostbuf`` is provided, it will be synchronously copied to the 
       device.
     - If mem_flags.USE_HOST_PTR is not included and a ``hostbuf`` is 
       specified, it will be added automatically.
     - Metadata will be inferred from ``hostbuf`` if not explicitly provided.
 
     ``shape``
         If an int is provided, converted to a one-dimensional tuple. 
         Dimensions be positive integers (arr). 
 
     It is highly recommended that you use the methods available in
     :class:`Context` to create buffers rather than doing so explicitly.
     """
     if cypy.is_int_like(shape):
         shape = (shape,)
     if hostbuf is not None:
         if shape is None:
             shape = cls.infer_shape(hostbuf)
         if cl_dtype is None:
             cl_dtype = cls.infer_cl_dtype(hostbuf)
         if order is None:
             try:
                 order = cls.infer_order(hostbuf)
             except Error:
                 order = "C"
         flags |= mem_flags.USE_HOST_PTR
     size = cl_dtype.sizeof_for(ctx.device)
     size *= cypy.prod(shape)
     if size <= 0:
         raise Error("Invalid buffer size %s." % str(size))
     assert size > 0
     buffer = cls(ctx, flags, size, hostbuf)
     buffer.shape = shape
     buffer.cl_dtype = cl_dtype
     buffer.order = order
     buffer.constant = constant
     return buffer
Esempio n. 3
0
 def max_work_items(self):
     """Returns the maximum number of work items that can be enqueued on 
     this device.
     """
     return cypy.prod(self.max_work_item_sizes)