xopto.mcbase.mcobject module

class McObject[source]

Bases: object

Base class of all Monte Carlo objects that interface with the OpenCL simulator kernel.

cl_declaration = None

Declaration of one or more OpenCL data types exposed by the class. This can be a str of valid OpenCL code or a callable that takes a simulator instance as the first input argument and returns a str (can be a regular method, static method or a class method). Default implementation (None) - no exposed OpenCL declarations.

cl_implementation = None

Implementation of one or more OpenCL functions exposed by the class. This can be a str of valid OpenCL code or a callable that takes a simulator instance as the first input argument and returns a str (can be a regular method, static method or a class method). Default implementation (None) - no exposed OpenCL implementation.

cl_options = None

Definition of one or simulator options exposed by the class. This attribute can be a list of options defined as [(name, value), (name, value), …] or a callable that takes a simulator instance as the first input argument and returns a list of options (can be a regular method, static method or a class method). The options will be coverted to defines (“#define <name> <value>”) Default implementation (None) - no exposed OpenCL options.

cl_type = None

Definition of OpenCL data type (a basic cltypes or a Structure type) exposed by the class. This attribute can be a str or a callable that takes a simulator instance as the first input argument and returns a basic cltypes object or a Structure type. (can be a regular method, static method or a class method). Default implementation (None) - no exposed OpenCL types.

fetch_cl_declaration(mc: xopto.mcbase.mcobject.McObject)str[source]

Fetch OpenCL declarations of the object. OpenCL declaration is defined through the cl_declaration attribute that can be a callable or a string. A callable attribute will be called with a target simulator instance as the first input argument and should return a str (valid OpenCL code).

Parameters

mc (McObject) – Simulator instance.

Returns

declaration – OpenCl declarations.

Return type

str

fetch_cl_implementation(mc: xopto.mcbase.mcobject.McObject)str[source]

Fetch OpenCL implementation of the object. OpenCl implementation is defined through the cl_declaration attribute that can be a callable or a string. A callable attribute will be called with a target simulator instance as the first input argument and should return a str (valid OpenCL code).

Parameters

mc (McObject) – Simulator instance.

Returns

implementation – OpenCl implementation.

Return type

str

fetch_cl_options(mc: xopto.mcbase.mcobject.McObject)List[Tuple[str, str]][source]

Fetch OpenCL options of the object. OpenCl options of an object are defined through the cl_options attribute that can be a callable or a list of options defined as [(name, value), …]. A callable attribute will be called with a simulator instance as the first input argument and should return a list of options.

Parameters

mc (McObject) – Simulator instance.

Returns

options – A list of OpenCl options defined as [(name, value), …].

Return type

list[RawOption]

fetch_cl_type(mc: xopto.mcbase.mcobject.McObject)xopto.cl.cltypes.Structure[source]

Fetch the OpenCL type representation of this object. The type representation of an object is defined through the cl_type attribute that can be a basic cltypes or Structure, or a callable. A callable attribute will be called with a simulator instance as the first input argument and should return a data type.

Parameters

mc (McObject) – Simulator instance.

Returns

cl_type – OpenCL type representing this object in the OpenCL kernel.

Return type

Structure or basic ctypes object