Create an OpenCL kernel from a Python function.
This class can be used as a decorator:
@kernel
def foo(a):
...
Clear the binary cache in memory.
Compile a kernel or lookup in cache.
Parameters: |
|
---|---|
Returns: | An OpenCL kernel |
internal
get the filename that the binaries can be cached to
Run a kernel this method is subclassable for the task class.
Get the source that would be compiled for specific argument types.
Note
This is meant to have a similar signature to the function call. i.e:
print func.source(queue.context, arg1, arg2)
func(queue, arg1, arg2)
Translate this func into a tuple of (args, defaults, kernel_name, source)
Bind the global work size of an nd range kernel to a arguments.
Parameters: | arg – can be either a list of integers or a function with the same signature as the python kernel. |
---|
Bind the local work size of an nd range kernel to a arguments.
Parameters: | arg – can be either a list of integers or a function with the same signature as the python kernel. |
---|
Set the caching type for a kernel binaries to file. (default is clyther.caching.NoFileCache) Use cache as a decorator:
@cache(HDFCache)
@cly.kernel
def foo(...):
...
Parameters: | chache_obj – Cache object |
---|
Create an OpenCL kernel from a Python function.
Calling this object will enqueue a task.
This class can be used as a decorator:
@task
def foo(a):
...
Run this function in emulation mode.
Run the kernel as a single thread task.
This is the doc for get_global_id
Returns the number of global work-items specified for dimension identified by dimindx. This value is given by the global_work_size argument to
The clyther.array module is designed to replicatie the functionality of numpy for OpenCL memory objects.
the main entry point into this module is the CLArrayContext class.
The end goal is to seamlessly be able to switch between OpenCL and numpy.
Where you would write:
import numpy as np
a = np.arange(0, 10.)
To specify a GPU array you would write:
import opencl as cl
from clyther.array import CLArrayContext
ca = CLArrayContext(device_type=cl.Device.GPU)
a = ca.arange(0, 10.)
classdocs
Return a list of the results of applying the function to the items of the argument sequence(s). If more than one sequence is given, the function is called with an argument list consisting of the corresponding item of each sequence, substituting None for missing values when not all sequences have the same length. If the function is None, return a list of the items of the sequence (or a list of tuples if more than one sequence).
Apply a function of two arguments cumulatively to the items of a sequence, so as to reduce the sequence to a single value. For example, reduce(lambda x, y: x+y, [1, 2, 3, 4, 5]) calculates 1+2+3+4+5.
Since this is a paralell operation the order is undefined.
This is the doc for get_global_id
Returns the number of global work-items specified for dimension identified by dimindx. This value is given by the global_work_size argument to
Run Time Type Tree (rttt)
define a constant value that is defined in the OpenCL runtime.
Parameters: |
|
---|
A function that is defined in the openCL runtime.
Parameters: |
|
---|
param doc: | Either a ctype or a function that returns a ctype |
---|---|
param builtin: | a python builtin function that is equivalent to this function |
param emulate: | A function that emulates the behavior of this function in python. This argument is not required if builtin is given. |
If return_type is a function it must have the same signature as the runtime function.
Create OpenCL source code from a Python function.
Parameters: |
|
---|
Steps:
- Decompile to AST.:
Get AST from python bytecode
- Typify AST:
This transforms the AST in to a partially typed OpenCL AST. It will recursively dive into pure Python functions and add thoes to the OpenCL module. Function names will be replace with placeholders for the namespace conflict resolution stage.
- Replace Constants:
Replace Python constants with values. e.g. math.e -> 2.7182
- Unpack memobjects:
To support multi-dimensional indexing and non contiguous memory arrays. CLyther adds a uint8 to the function signature to store this information.
Replace calls of types to type casts e.g. int(i) -> ((int)(i))
- Format for loops:
only range or a explicit Python list is currently supported as the iterator in a for loop.
Remove arguments to functions that are constant. e.g. python functions.
Move keyword arguments in function calls to positional arguments.
Resolve function place-holders
Make printf statements from print
- Replace Types:
Replace python ctype objects with OpenCL type names. This will also define structs in the module if required.
Generate Source