cgen
– C-Generation Reference Documentation¶
- class cgen.Generable[source]¶
Bases:
object
- cgen.Module[source]¶
alias of
Collection
Data and Functions¶
Preprocessor Code¶
Declarators¶
- class cgen.Declarator[source]¶
Bases:
Generable
- generate(with_semicolon=True)[source]¶
Generate (i.e. yield) the lines making up this code construct.
- get_decl_pair()[source]¶
Return a tuple
(type_lines, rhs)
.type_lines is a non-empty list of lines (most often just a single one) describing the type of this declarator. rhs is the right- hand side that actually contains the function/array/constness notation making up the bulk of the declarator syntax.
- class cgen.Value(typename, name)[source]¶
Bases:
Declarator
A simple declarator: typename and name are given as strings.
- class cgen.POD(dtype, name)[source]¶
Bases:
Declarator
A simple declarator: The type is given as a
numpy.dtype
and the name is given as a string.
- class cgen.Struct(tpname, fields, declname=None, pad_bytes=0)[source]¶
Bases:
Declarator
A structure declarator.
- class cgen.GenerableStruct(tpname, fields, declname=None, align_bytes=None, aligned_prime_to=None)[source]¶
Bases:
Struct
- __init__(tpname, fields, declname=None, align_bytes=None, aligned_prime_to=None)[source]¶
Initialize a structure declarator. tpname is the name of the structure, while declname is the name used for the declarator. pad_bytes is the number of padding bytes added at the end of the structure. fields is a list of
Declarator
instances.align_bytes is an integer that causes the structure to be padded to an integer multiple of itself. aligned_prime_to is a list of integers. If the resulting structure’s size is
s
, thens//align_bytes
will be made prime to all numbers in aligned_prime_to. (Sounds obscure? It’s needed for avoiding bank conflicts in CUDA programming.)
- make(**kwargs)[source]¶
Build a binary, packed representation of self in a
str
instance with members set to the values specified in kwargs.
- class cgen.Enum[source]¶
Bases:
Generable
An enum-like class for Python that can generate an equivalent C-level declaration. Does not work within the usual “declarator” framework because it uses macros to define values, and a separate typedef to define the value type.
Added in version 2013.2.
To use, derive from this class, and define the following things:
- c_name¶
- dtype¶
- c_value_prefix¶
A (usually upper-case) prefix to be used as a prefix to the names defined on the Python side.
- VALUE¶
Any class attribute with an all-upper-case name is taken to be as an enum value.
Nested Declarators¶
- class cgen.NestedDeclarator(subdecl)[source]¶
Bases:
Declarator
- class cgen.ArrayOf(subdecl, count=None)[source]¶
Bases:
NestedDeclarator
- class cgen.Const(subdecl)[source]¶
Bases:
NestedDeclarator
- class cgen.FunctionDeclaration(subdecl, arg_decls)[source]¶
Bases:
NestedDeclarator
- class cgen.MaybeUnused(subdecl)[source]¶
Bases:
NestedDeclarator
- class cgen.Pointer(subdecl)[source]¶
Bases:
NestedDeclarator
- class cgen.Template(template_spec, subdecl)[source]¶
Bases:
NestedDeclarator
- class cgen.AlignedAttribute(align_bytes, subdecl)[source]¶
Bases:
NestedDeclarator
Assigns an alignment for a definition of a type or an array.
- class cgen.AlignValueAttribute(align_bytes, subdecl)[source]¶
Bases:
NestedDeclarator
Assigns an alignment for value of a pointer.
This is used for pointers where the user guarantees to the compiler that the value of the pointer has the alignment stated.
AlignedAttribute
on the other hand tells the compiler to declare the type or the array with the given alignment and cannot be used for telling the compiler that an existing pointer has a certain alignment guarantee. This attribute is currently supported by clang [1] and Intel [2] and is ignored by gcc.[1]: https://reviews.llvm.org/D4635 [2]: https://www.intel.com/content/www/us/en/develop/documentation/oneapi-dpcpp-cpp-compiler-dev-guide-and-reference/top/compiler-reference/attributes/align-value.html
Declaration Specifiers¶
- class cgen.DeclSpecifier(subdecl, spec, sep=' ')[source]¶
Bases:
NestedDeclarator
- class cgen.Static(subdecl)[source]¶
Bases:
DeclSpecifier
- class cgen.Typedef(subdecl)[source]¶
Bases:
DeclSpecifier
Statements¶
cgen.cuda
– Extensions to generate CUDA-compatible C Sources¶
This module adds a few Nvidia CUDA features to cgen’s repertoire. This makes cgen a perfect complement to PyCuda: cgen generates the code, PyCuda compiles it, uploads it to the GPU and executes it.
The PyCuda manual has a tutorial on using the two together.
- class cgen.cuda.CudaGlobal(subdecl)[source]¶
Bases:
DeclSpecifier
- class cgen.cuda.CudaDevice(subdecl)[source]¶
Bases:
DeclSpecifier
Bases:
DeclSpecifier
- class cgen.cuda.CudaConstant(subdecl)[source]¶
Bases:
DeclSpecifier
cgen.opencl
– Extensions to generate OpenCL-compatible C Sources¶
Kernels and Kernel Arguments¶
- class cgen.opencl.CLKernel(subdecl)[source]¶
Bases:
DeclSpecifier
- class cgen.opencl.CLConstant(subdecl)[source]¶
Bases:
DeclSpecifier
- class cgen.opencl.CLLocal(subdecl)[source]¶
Bases:
DeclSpecifier
- class cgen.opencl.CLGlobal(subdecl)[source]¶
Bases:
DeclSpecifier
Function Attributes¶
- class cgen.opencl.CLVecTypeHint(subdecl, dtype=None, count=None, type_str=None)[source]¶
Bases:
NestedDeclarator
Vector PODs¶
- class cgen.opencl.CLVectorPOD(dtype, count, name)[source]¶
Bases:
Declarator