xopto.cl.cleasy module

class ArgArray(argtype: numpy.dtype, access: str = 'rw', initializer: Optional[numpy.ndarray] = None)[source]

Bases: object

Used to declare an array kernel argument with the Program.declare() method.

Parameters
  • argtype (np.dtype) – Argument data type as a numpy dtype.

  • access (str) – Access specifier for the argument. Must be one of “r”, “w” or “rw”. Note that the access flags are defined as seen by the OpenCL kernel (not as seen by the host/python).

  • initializer (np.ndarray) – Initializer for the OpenCL buffer.

access()str[source]

Access flags of the variable (“r”, “w”, “rw” or “”) as seen by the OpenCL kernel (NOT as seen by the host/python)

fromdevice(queue: pyopencl._cl.CommandQueue, npdata: numpy.ndarray, clbuffer: pyopencl._cl.Buffer)numpy.ndarray[source]

Transfer data from OpenCL device into a numpy buffer.

This method is called by the Program instance after executing an OpenCL kernel and should not be called directly.

Parameters
  • queue (cl.CommandQueue) – OpenCL queue.

  • npdata (np.ndarray) – Target numpy array.

  • buffer (cl.Buffer) – OpenCL buffer that will be transferred to the npdata numpy array.

Returns

npdata – The input numpy array filled with the contents of the OpenCL buffer.

Return type

np.ndarray

Note

Data will be transferred only if the OpenCL buffer has a write flag (“w”). OpenCL buffers with no write flag cannot be modified and there is no point in transfering the data.

initializer()numpy.ndarray[source]

Returns the initializer passed to the constructor.

todevice(ctx: pyopencl._cl.Context, queue: pyopencl._cl.CommandQueue, npdata: numpy.ndarray, clbuffer=None, argind: Optional[int] = None, verbose: bool = False)pyopencl._cl.Buffer[source]

Transfer data to OpenCL device.

This method is called by the Program instance before executing an OpenCL kernel and should not be called directly

Parameters
  • ctx (cl.Context) – OpenCL context.

  • queue (cl.CommandQueue) – OpenCL queue.

  • npdata (np.ndarray) – Value that is used to update the argument before it is passed to the kernel. Use existing value if None.

  • buffer (cl.Buffer) – Target OpenCL device buffer or None to create a new one.

  • argind (int) – Index of this argument.

  • verbose (bool) – Turn on verbose reporting.

Returns

buffer – The input buffer or a new buffer that is properly initialized with the data.

Return type

cl.Buffer

class ArgLocalMemory(byte_size: int)[source]

Bases: object

Used to declare a local memory buffer kernel argument with the Program.declare method.

Parameters

byte_size (int) – Size of the local buffer in bytes.

access()str[source]

Returns the argument access mode passed to the constructor. Note that local memory buffers do not support access attributes.

initializer()numpy.ndarray[source]

Returns the initializer passed to the constructor. Note that initializers are not supported by local memory buffers.

todevice(ctx: Optional[pyopencl._cl.Context] = None, queue: Optional[pyopencl._cl.CommandQueue] = None, nparray: Optional[numpy.ndarray] = None, clbuffer: Optional[pyopencl._cl.Buffer] = None, argind: Optional[int] = None, verbose: bool = False)pyopencl._cl.Buffer[source]

Transfer data to the OpenCL device.

This method is called by the Program instance before executing an OpenCL kernel and should not be called directly

Parameters
  • ctx (cl.Context) – OpenCL context.

  • queue (cl.CommandQueue) – OpenCL queue.

  • nparray (np.ndarray) – Value that is used to update the argument before it is passed to the kernel. Use existing value if None. Cannot be used with local OpenCL memory type.

  • clbuffer (cl.Buffer) – OpenCL device buffer that will be used or None.

  • verbose (bool) – Turn on verbose reporting.

  • argind (int) – Index of the kernel argument.

Returns

buffer – OpenCL device buffer.

Return type

cl.Buffer

class ArgScalar(argtype: numpy.dtype, initializer: Optional[bool] = None)[source]

Bases: object

Used to declare a scalar kernel argument with the Program.declare() method.

Parameters
  • argtype (numpy.dtype) – Argument data type.

  • initializer (int, float, scalar numpy types) – Initializer for the OpenCL buffer.

access()str[source]

Access mode of the argument (“r”, “w”, “rw” or “”) as seen by the kernel (NOT by the host/python).

initializer()bool[source]

Returns the initializer passed to the constructor.

todevice(ctx: pyopencl._cl.Context, queue: pyopencl._cl.CommandQueue, value=None, buffer: Optional[pyopencl._cl.Buffer] = None, argind: Optional[int] = None, verbose: bool = False)[source]

Transfer data to OpenCL device.

This method is called by the Program instance before executing an OpenCL kernel and should not be called directly.

Parameters
  • ctx (cl.Context) – OpenCL context.

  • queue (cl.CommandQueue) – OpenCL command queue.

  • value (bool or int or float or np.ndarray) – Value that is used to update the argument before it is passed to the kernel. Use existing value if None.

  • buffer (cl,Buffer) – Target OpenCL device buffer or None to create a new one.

  • argind (int) – Index of this argument.

  • verbose – Turn on verbose reporting.

Returns

buffer – The input buffer or a new buffer that is properly initialized with the data.

Return type

cl.Buffer

class Program(code: str, device: Optional[str] = None, buildopts: list = [], verbose: bool = False, exportsrc: bool = False)[source]

Bases: object

Creates a new instance of an OpenCL program.

Parameters
  • code (str) – OpenCL code as a string.

  • device (str or list or tuple or cl.Device) – A list of devices on which the code is to be executed. Can use the same arguments as with the xopto.cl.clinfo.device() function.

  • buildopts (list) – A list of build options passed to the OpenCL compiler.

  • verbose (bool) – If set to True, additional information is displayed during the build and kernel calls.

  • exportsrc – A path (default is used if True) where the target OpnCL source code is saved.

  • bool – A path (default is used if True) where the target OpnCL source code is saved.

  • src – A path (default is used if True) where the target OpnCL source code is saved.

BASE_LIB = "/******************************** Begin license ********************************\n * Copyright (C) Laboratory of Imaging technologies,\n *               Faculty of Electrical Engineering,\n *               University of Ljubljana.\n *\n * This file is part of PyXOpto.\n *\n * PyXOpto is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * PyXOpto is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with PyXOpto. If not, see <https://www.gnu.org/licenses/>.\n ******************************** End license *********************************/\n\n#ifndef CLBASE_DEFINES_\n#define CLBASE_DEFINES_\n\n/*########## Start basic data types, constants and math functions  ###########*/\n/**\n * @addtogroup cl_types_constants_math Math, Types and Constants\n * @{\n */\n\n/** @brief 8-bit signed integer type. */\ntypedef char int8_t;\ntypedef char2 int8v2_t;\ntypedef char3 int8v3_t;\ntypedef char4 int8v4_t;\ntypedef char8 int8v8_t;\ntypedef char16 int8v16_t;\n/** @brief 8-bit unsigned integer type. */\ntypedef unsigned char uint8_t;\ntypedef uchar2 uint8v2_t;\ntypedef uchar3 uint8v3_t;\ntypedef uchar4 uint8v4_t;\ntypedef uchar8 uint8v8_t;\ntypedef uchar16 uint8v16_t;\n/** @brief 16-bit signed integer type. */\ntypedef short int16_t;\ntypedef short2 int16v2_t;\ntypedef short3 int16v3_t;\ntypedef short4 int16v4_t;\ntypedef short8 int16v8_t;\ntypedef short16 int16v16_t;\n/** @brief 16-bit unsigned integer type. */\ntypedef ushort uint16_t;\ntypedef ushort2 uint16v2_t;\ntypedef ushort3 uint16v3_t;\ntypedef ushort4 uint16v4_t;\ntypedef ushort8 uint16v8_t;\ntypedef ushort16 uint16v16_t;\n/** @brief 32-bit signed integer type. */\ntypedef int int32_t;\ntypedef int2 int32v2_t;\ntypedef int3 int32v3_t;\ntypedef int4 int32v4_t;\ntypedef int8 int32v8_t;\ntypedef int16 int32v16_t;\n/** @brief 32-bit unsigned signed integer type. */\ntypedef uint uint32_t;\ntypedef uint2 uint32v2_t;\ntypedef uint3 uint32v3_t;\ntypedef uint4 uint32v4_t;\ntypedef uint8 uint32v8_t;\ntypedef uint16 uint32v16_t;\n/** @brief 64-bit signed integer type. */\ntypedef long int64_t;\ntypedef long2 int64v2_t;\ntypedef long3 int64v3_t;\ntypedef long4 int64v4_t;\ntypedef long8 int64v8_t;\ntypedef long16 int64v16_t;\n/** @brief 64-bit unsigned integer type. */\ntypedef ulong uint64_t;\ntypedef ulong2 uint64v2_t;\ntypedef ulong3 uint64v3_t;\ntypedef ulong4 uint64v4_t;\ntypedef ulong8 uint64v8_t;\ntypedef ulong16 uint64v16_t;\n\n#if USE_DOUBLE_PRECISION || defined(__DOXYGEN__)\n\t/** @brief  Define a double precision floating-point literal when ::USE_DOUBLE_PRECISION is TRUE. */\n\t#define FP_LITERAL(value) value\n\t/** @brief Using double precision floating-point. */\n\ttypedef double fp_t;\n\ttypedef double2 fpv2_t;\n\ttypedef double3 fpv3_t;\n\ttypedef double4 fpv4_t;\n\ttypedef double8 fpv8_t;\n\ttypedef double16 fpv16_t;\n#else\n\t/** @brief  Define a single precision floating-point literal when ::USE_DOUBLE_PRECISION is NOT TRUE. */\n\t#define FP_LITERAL(value) value##f\n\t/** @brief Using single precision floating-point. */\n\ttypedef float fp_t;\n\ttypedef float2 fpv2_t;\n\ttypedef float3 fpv3_t;\n\ttypedef float4 fpv4_t;\n\ttypedef float8 fpv8_t;\n\ttypedef float16 fpv16_t;\n#endif\n\n/** @brief A short way to define a floating-point literal using the default precision. */\n#define FPL(value) FP_LITERAL(value)\n\n#if USE_64_BIT_INTEGER || defined(__DOXYGEN__)\n\t/** @brief Using 64-bit signed integers when ::USE_64_BIT_INTEGER is TRUE. */\n\ttypedef int64_t int_t;\n\t/** @brief Using 64-bit signed integer vector[2] when ::USE_64_BIT_INTEGER is TRUE. */\n\ttypedef int64v2_t intv2_t;\n\t/** @brief Using 64-bit signed integer vector[3] when ::USE_64_BIT_INTEGER is TRUE. */\n\ttypedef int64v3_t intv3_t;\n\t/** @brief Using 64-bit signed integer vector[4] when ::USE_64_BIT_INTEGER is TRUE. */\n\ttypedef int64v4_t intv4_t;\n\t/** @brief Using 64-bit signed integer vector[8] when ::USE_64_BIT_INTEGER is TRUE. */\n\ttypedef int64v8_t intv8_t;\n\t/** @brief Using 64-bit signed integer vector[16] when ::USE_64_BIT_INTEGER is TRUE. */\n\ttypedef int64v16_t intv16_t;\n\t\n\t/** @brief Using 64-bit unsigned integers when ::USE_64_BIT_INTEGER is TRUE. */\n\ttypedef uint64_t uint_t;\n\t/** @brief Using 64-bit unsigned integer vector[2] when ::USE_64_BIT_INTEGER is TRUE. */\n\ttypedef uint64v2_t uintv2_t;\n\t/** @brief Using 64-bit unsigned integer vector[3] when ::USE_64_BIT_INTEGER is TRUE. */\n\ttypedef uint64v3_t uintv3_t;\n\t/** @brief Using 64-bit unsigned integer vector[4] when ::USE_64_BIT_INTEGER is TRUE. */\n\ttypedef uint64v4_t uintv4_t;\n\t/** @brief Using 64-bit unsigned integer vector[8] when ::USE_64_BIT_INTEGER is TRUE. */\n\ttypedef uint64v8_t uintv8_t;\n\t/** @brief Using 64-bit unsigned integer vector[16] when ::USE_64_BIT_INTEGER is TRUE. */\n\ttypedef uint64v16_t uintv16_t;\n#else\n\t/** @brief Using 32-bit signed integers when ::USE_64_BIT_INTEGER is NOT TRUE. */\n\ttypedef int32_t int_t;\n\t/** @brief Using 32-bit signed integer vector[2] when ::USE_64_BIT_INTEGER is NOT TRUE. */\n\ttypedef int32v2_t intv2_t;\n\t/** @brief Using 32-bit signed integer vector[3] when ::USE_64_BIT_INTEGER is NOT TRUE. */\n\ttypedef int32v3_t intv3_t;\n\t/** @brief Using 32-bit signed integer vector[4] when ::USE_64_BIT_INTEGER is NOT TRUE. */\n\ttypedef int32v4_t intv4_t;\n\t/** @brief Using 32-bit signed integer vector[8] when ::USE_64_BIT_INTEGER is NOT TRUE. */\n\ttypedef int32v8_t intv8_t;\n\t/** @brief Using 32-bit signed integer vector[16] when ::USE_64_BIT_INTEGER is NOT TRUE. */\n\ttypedef int32v16_t intv16_t;\n\n\t/** @brief Using 32-bit unsigned integers when ::USE_64_BIT_INTEGER is NOT TRUE. */\n\ttypedef uint32_t uint_t;\n\t/** @brief Using 32-bit unsigned integer vector[2] when ::USE_64_BIT_INTEGER is NOT TRUE. */\n\ttypedef uint32v2_t uintv2_t;\n\t/** @brief Using 32-bit unsigned integer vector[3] when ::USE_64_BIT_INTEGER is NOT TRUE. */\n\ttypedef uint32v3_t uintv3_t;\n\t/** @brief Using 32-bit unsigned integer vector[4] when ::USE_64_BIT_INTEGER is NOT TRUE. */\n\ttypedef uint32v4_t uintv4_t;\n\t/** @brief Using 32-bit unsigned integer vector[8] when ::USE_64_BIT_INTEGER is NOT TRUE. */\n\ttypedef uint32v8_t uintv8_t;\n\t/** @brief Using 32-bit unsigned integer vector[16] when ::USE_64_BIT_INTEGER is NOT TRUE. */\n\ttypedef uint32v16_t uintv16_t;\n#endif\n\n/** @brief Default floating-point type. */\ntypedef fp_t cl_fp_t;\n/** @brief Default floating-point vector[2] type. */\ntypedef fpv2_t cl_fpv2_t;\n/** @brief Default floating-point vector[3] type. */\ntypedef fpv3_t cl_fpv3_t;\n/** @brief Default floating-point vector[4] type. */\ntypedef fpv4_t cl_fpv4_t;\n/** @brief Default floating-point vector[8] type. */\ntypedef fpv8_t cl_fpv8_t;\n/** @brief Default floating-point vector[16] type. */\ntypedef fpv16_t cl_fpv16_t;\n\n/** @brief Default signed integer type. */\ntypedef int_t cl_int_t;\n/** @brief Default signed integer vector[2] type. */\ntypedef intv2_t cl_intv2_t;\n/** @brief Default signed integer vector[3] type. */\ntypedef intv3_t cl_intv3_t;\n/** @brief Default signed integer vector[4] type. */\ntypedef intv4_t cl_intv4_t;\n/** @brief Default signed integer vector[8] type. */\ntypedef intv8_t cl_intv8_t;\n/** @brief Default signed integer vector[16] type. */\ntypedef intv16_t cl_intv16_t;\n\n/** @brief Default unsigned integer type. */\ntypedef uint_t cl_uint_t;\n/** @brief Default unsigned integer vector[2] type. */\ntypedef uintv2_t cl_uintv2_t;\n/** @brief Default unsigned integer vector[3] type. */\ntypedef uintv3_t cl_uintv3_t;\n/** @brief Default unsigned integer vector[4] type. */\ntypedef uintv4_t cl_uintv4_t;\n/** @brief Default unsigned integer vector[8] type. */\ntypedef uintv8_t cl_uintv8_t;\n/** @brief Default unsigned integer vector[16] type. */\ntypedef uintv16_t cl_uintv16_t;\n\n#if USE_DOUBLE_PRECISION || defined(__DOXYGEN__)\n\t/** @brief Double precision EPS. */\n\t#define FP_EPS\t\t\tFP_LITERAL(2.220446049250313e-16)\n\t/** @brief Maximum integer (4503599627370495) that can be represented by a double precision floating-point number. */\n\t#define FP_MAXINT\t\t((uint64_t)0xFFFFFFFFFFFFFul)\n#else\n\t/** @brief Single precision EPS. */\n\t#define FP_EPS\t\t\tFP_LITERAL(1.1920929e-07)\n\t/** @brief Maximum integer (8388607) that can be represented by a single precision floating-point number. */\n\t#define FP_MAX_INT\t\t(0x7FFFFF)\n#endif\n\n/** @brief A floating-point constant: zero. */\n#define FP_0\t\t\tFP_LITERAL(0.0)\n/** @brief A floating-point constant: 1/27. */\n#define FP_1d27\t\t\tFP_LITERAL(0.037037037037037035f)\n/** @brief A floating-point constant: quarter. */\n#define FP_0p25\t\t\tFP_LITERAL(0.25)\n/** @brief A floating-point constant: zero point five. */\n#define FP_0p5\t\t\tFP_LITERAL(0.5)\n/** @brief A floating-point constant: one point zero. */\n#define FP_1\t\t\tFP_LITERAL(1.0)\n/** @brief A floating-point constant: one point five. */\n#define FP_1p5\t\t\tFP_LITERAL(1.5)\n/** @brief A floating-point constant: two point zero. */\n#define FP_2\t\t\tFP_LITERAL(2.0)\n/** @brief A floating-point constant: two point five. */\n#define FP_2p5\t\t\tFP_LITERAL(2.5)\n/** @brief A floating-point constant: half pi. */\n#define FP_HALF_PI\t\tFP_LITERAL(1.5707963267948966)\n/** @brief A floating-point constant: pi. */\n#define FP_PI\t\t\tFP_LITERAL(3.141592653589793)\n/** @brief A floating-point constant: 2 times pi. */\n#define FP_2PI\t\t\tFP_LITERAL(6.283185307179586)\n/** @brief A floating-point constant: cos(30deg). */\n#define FP_COS_30\t\tFP_LITERAL(0.8660254037844386f)\n/** @brief floating-point infinity constant. */\n#define FP_INF\t\t\tINFINITY\n\n#if USE_NATIVE_MATH || defined(__DOXYGEN__)\n\t/** @brief Native sine function. */\n\t#define cl_sin(x)\t\t\t\t\tnative_sin(x)\n\t/** @brief Native cosine function. */\n\t#define cl_cos(x)\t\t\t\t\tnative_cos(x)\n\t/** @brief Native division function. */\n\t#define cl_fdiv(a,b)\t\t\t\tnative_divide((cl_fp_t)(a), (cl_fp_t)(b))\n\t/** @brief Native reciprocal. */\n\t#define cl_reciprocal(x)\t\t\tnative_recip((cl_fp_t)(x))\n\t/** @brief Native natural logarithm function. */\n\t#define cl_log(x)\t\t\t\t\tnative_log(x)\n\t/** @brief Native square root function. */\n\t#define cl_sqrt(x)\t\t\t\t\tnative_sqrt((cl_fp_t)(x))\n\t/** @brief Native reciprocal square root function. */\n\t#define cl_rsqrt(x)\t\t\t\t\tnative_rsqrt((cl_fp_t)(x))\n\t/** @brief Native power function, where x >= 0. */\n\t#define cl_pow(x, y)\t\t\t\tnative_powr(x, y)\n\t/** @brief Standard exponential function, where x >= 0. */\n\t#define cl_exp(x)\t\t\t\t\tnative_exp(x)\n\t/** @brief Native Simultaneous sine and cosine computation. */\n\t#define cl_sincos(fi, ps, pc)\t\t(*(ps)=sincos(fi, (pc)))\n\t/* Native sin and cos functions seem to be highly inacurate on many platforms. */\n\t/*#define cl_sincos(fi, ps, pc)\t\t{*(ps) = native_sin(fi); *(pc) = native_cos(fi);} */\n#elif USE_HALF_MATH\n\t/** @brief Native half precision sine function. */\n\t#define cl_sin(x)\t\t\t\t\thalf_sin(x)\n\t/** @brief Native half precision cosine function. */\n\t#define cl_cos(x)\t\t\t\t\thalf_cos(x)\n\t/** @brief Native half precision division function. */\n\t#define cl_fdiv(a,b)\t\t\t\thalf_divide((cl_fp_t)(a), (cl_fp_t)(b))\n\t/** @brief Native half precision reciprocal. */\n\t#define cl_reciprocal(x)\t\t\thalf_recip((cl_fp_t)(x))\n\t/** @brief Native half precision natural logarithm function. */\n\t#define cl_log(x)\t\t\t\t\thalf_log(x)\n\t/** @brief Native half precision square root function. */\n\t#define cl_sqrt(x)\t\t\t\t\thalf_sqrt((cl_fp_t)(x))\n\t/** @brief Native half precision reciprocal square root function. */\n\t#define cl_rsqrt(x)\t\t\t\t\thalf_rsqrt((cl_fp_t)(x))\n\t/** @brief Native half precision power function, where x >= 0. */\n\t#define cl_pow(x, y)\t\t\t\thalf_powr(x, y)\n\t/** @brief Half precision exponential function, where x >= 0. */\n\t#define cl_exp(x)\t\t\t\t\thalf_exp(x)\n\t/** @brief Half precision simultaneous sine and cosine computation. */\n\t#define cl_sincos(fi, ps, pc)\t\t(*(ps)=sincos(fi, (pc)))\n\t/* Half sin and cos functions are far too inacurate. */\n\t/* #define cl_sincos(fi, ps, pc)\t{*(ps) = half_sin(fi); *(pc) = half_cos(fi);} */\n#else\n\t/** @brief Standard sine function. */\n\t#define cl_sin(x)\t\t\t\t\tsin(x)\n\t/** @brief Standard cosine function. */\n\t#define cl_cos(x)\t\t\t\t\tcos(x)\n\t/** @brief Standard single precision division function. */\n\t#define cl_fdiv(a,b)\t\t\t\t((cl_fp_t)(a)/(cl_fp_t)(b))\n\t/** @brief Native single precision reciprocal. */\n\t#define cl_reciprocal(x)\t\t\tcl_fdiv((cl_fp_t)(1), (cl_fp_t)(x))\n\t/** @brief Standard single precision reciprocal square root function. */\n\t#define cl_rsqrt(x)\t\t\t\t\trsqrt((cl_fp_t)(x))\n\t/** @brief Standard single precision square root function. */\n\t#define cl_sqrt(x)\t\t\t\t\tsqrt((cl_fp_t)(x))\n\t/** @brief Standard natural logarithm function. */\n\t#define cl_log(x)\t\t\t\t\tlog(x)\n\t/** @brief Standard power function, where x >= 0. */\n\t#define cl_pow(x, y)\t\t\t\tpowr(x, y)\n\t/** @brief Standard exponential function, where x >= 0. */\n\t#define cl_exp(x)\t\t\t\t\texp(x)\n\t/** @brief Simultaneous sine and cosine computation. */\n\t#define cl_sincos(fi, ps, pc)\t\t(*(ps)=sincos(fi, (pc)))\n#endif\n\n/** @brief Copy the sign of a floating-point number. */\n#define cl_fcopysign(to, from)\t\t(copysign(to, from))\n/** @brief Evaluate to integer sign of a floating-point number. */\n#define cl_fsign(x)\t\t\t\t\t(((x) >= FP_0) ? 1 : -1)\n/** @brief Evaluate to integer sign of an integer number. */\n#define cl_sign(x)\t\t\t\t\t(((x) >= 0) ? 1 : -1)\n/** @brief Absolute value of a floating-point number. */\n#define cl_fabs(x)\t\t\t\t\tfabs((cl_fp_t)(x))\n/** @brief Minimum of two floating-point numbers. */\n#define cl_fmin(x,y)\t\t\t\tfmin((cl_fp_t)(x), (cl_fp_t)(y))\n/** @brief Maximum of two floating-point numbers. */\n#define cl_fmax(x,y)\t\t\t\tfmax((cl_fp_t)(x), (cl_fp_t)(y))\n/** @brief Minimum of two integer numbers. */\n#define cl_min(x,y)\t\t\t\t\tmin((cl_int_t)(x), (cl_int_t)(y))\n/** @brief Maximum of two floating-point numbers. */\n#define cl_max(x,y)\t\t\t\t\tmax((cl_int_t)(x), (cl_int_t)(y))\n/** @brief Clip integer value to the specified range. */\n#define cl_clip(x, low, high)\t\tcl_min(cl_max((x), (low)), (high))\n/** @brief Clip floating-point value to the specified range. */\n#define cl_fclip(x, low, high)\t\tcl_fmin(cl_fmax((x), (low)), (high))\n/** @brief Compute the cube root of x */\n#define cl_cbrt(x)\t\t\t\t\tcbrt((cl_fp_t)(x))\n/** @brief Type cast a floating-point value to integer value. */\n#define cl_int(x)\t\t\t\t\tconvert_int(x)\n/** @brief Round a floating-point value towards minus infinity. */\n#define cl_round(x)\t\t\t\t\troundf(x)\n/** @brief Round a floating-point value towards the closest integer. */\n#define cl_floor(x)\t\t\t\t\tfloor(x)\n/** @brief Checks if a floating-point number is finite. */\n#define cl_isfinite(x)\t\t\t\tisinf(x)\n\n/**\n * @} // end @addtogroup cl_types_constants_math\n */\n/*########### End basic data types, constants and math functions  ############*/\n\n\n/*###################### Start random number generator #######################*/\n/**\n * @addtogroup cl_rng OpneCL random number generators\n * @{\n */\n\n/**\n * @brief Generates a random number from open interval (0.0, 1.0) given a state\n *\tof the generator in terms of two unsigned integers. The two states/seeds \n *\tshould be initialized independently for each thread. See Python module\n *\tclrng for generating pairs of unsigned integer seeds.\n * @param[in, out] rngStateX Pointer to 64-bit unsigned number/state\n *\t\t\t\t\t updated on return.\n * @param[in, out] rngStateA Pointer to 32-bit unsigned number/state.\n * @return A single random number from (0.0, 1.0).\n * \n * @details George Marsaglia's Random Number Generator. A single precision \n *\tfloating point number has a 23-bit mantisa, hence only integers from \n *\t[0, 2^23 - 1] can be represented without loss of information.\n */\n inline float mlrngoof(uint64_t *rngStateX, uint32_t rngStateA){\n\t*rngStateX = (*rngStateX & (uint64_t)0xFFFFFFFFUL)*\n\t\t(rngStateA) + (*rngStateX >> 32);\n\t\n\t/* Generate a random number from open interval (0.0, 1.0). */\n\treturn cl_fdiv( ((float)(1 | ((uint32_t)(*rngStateX) & 0x7FFFFF) )), \n\t\t(float)0x800000);\n};\n\n/**\n * @brief Generates a random number from open/closed interval (0.0, 1.0] given \n *\ta state of the generator in terms of two unsigned integers. The two \n *\tstates/seeds  should be initialized independently for each thread. \n *\tSee Python module clrng for generating pairs of unsigned integer seeds.\n * @param[in, out] rngStateX Pointer to 64-bit unsigned number/state\n *\t\t\t\t\t updated on return.\n * @param[in, out] rngStateA Pointer to 32-bit unsigned number/state.\n * @return A single random number from (0.0, 1.0).\n * \n * @details George Marsaglia's Random Number Generator. A single precision \n *\tfloating point number has a 23-bit mantisa, hence only integers from \n *\t[0, 2^23 - 1] can be represented without loss of information.\n */\n inline float mlrngocf(uint64_t *rngStateX, uint32_t rngStateA){\n\t*rngStateX = (*rngStateX & (uint64_t)0xFFFFFFFFUL)*\n\t\t(rngStateA) + (*rngStateX >> 32);\n\t\n\t/* Generate a random number from open interval (0.0, 1.0). */\n\treturn cl_fdiv( ((float)(1 | ((uint32_t)(*rngStateX) & 0x7FFFFF) )), \n\t\t(float)0x7FFFFF);\n};\n\n/**\n * @brief Generates a random number from closed/open interval [0.0, 1.0) given \n *\ta state of the generator in terms of two unsigned integers. The two \n *\tstates/seeds  should be initialized independently for each thread. \n *\tSee Python module clrng for generating pairs of unsigned integer seeds.\n * @param[in, out] rngStateX Pointer to 64-bit unsigned number/state\n *\t\t\t\t\t updated on return.\n * @param[in, out] rngStateA Pointer to 32-bit unsigned number/state.\n * @return A single random number from (0.0, 1.0).\n * \n * @details George Marsaglia's Random Number Generator. A single precision \n *\tfloating point number has a 23-bit mantisa, hence only integers from \n *\t[0, 2^23 - 1] can be represented without loss of information.\n */\n inline float mlrngcof(uint64_t *rngStateX, uint32_t rngStateA){\n\t*rngStateX = (*rngStateX & (uint64_t)0xFFFFFFFFUL)*\n\t\t(rngStateA) + (*rngStateX >> 32);\n\t\n\t/* Generate a random number from open interval (0.0, 1.0). */\n\treturn cl_fdiv( ((float)(((uint32_t)(*rngStateX) & 0x7FFFFF) )), \n\t\t(float)0x800000);\n};\n\n/**\n * @brief Generates a random number from closed/closed interval [0.0, 1.0] given \n *\ta state of the generator in terms of two unsigned integers. The two \n *\tstates/seeds  should be initialized independently for each thread. \n *\tSee Python module clrng for generating pairs of unsigned integer seeds.\n * @param[in, out] rngStateX Pointer to 64-bit unsigned number/state\n *\t\t\t\t\t updated on return.\n * @param[in, out] rngStateA Pointer to 32-bit unsigned number/state.\n * @return A single random number from (0.0, 1.0).\n * \n * @details George Marsaglia's Random Number Generator. A single precision \n *\tfloating point number has a 23-bit mantisa, hence only integers from \n *\t[0, 2^23 - 1] can be represented without loss of information.\n */\n inline float mlrngccf(uint64_t *rngStateX, uint32_t rngStateA){\n\t*rngStateX = (*rngStateX & (uint64_t)0xFFFFFFFFUL)*\n\t\t(rngStateA) + (*rngStateX >> 32);\n\t\n\t/* Generate a random number from open interval (0.0, 1.0). */\n\treturn cl_fdiv( ((float)(((uint32_t)(*rngStateX) & 0x7FFFFF) )), \n\t\t(float)0x7FFFFF);\n};\n\n#if defined(ML_DOUBLE_PRECISION)\n\t/**\n\t * @brief Generates a random number from open interval (0.0, 1.0) given a state \n\t *\tof the generator in terms of two unsigned integers. The two states/seeds \n\t *\tshould be initialized independently for each thread. See Python module\n\t *\tclrng for generating pairs of unsigned integer seeds.\n\t * @param[in, out] rngStateX Pointer to 64-bit unsigned number/state\n\t *\t\t\t\t\tupdated on return.\n\t * @param[in, out] rngStateA Pointer to 32-bit unsigned number/state.\n\t * @return A double precision random number from (0.0, 1.0).\n\t * \n\t * @details George Marsaglia's Random Number Generator. A double precision \n\t *\tfloating point number has a 52-bit mantisa, hence only integers from \n\t *\t[0, 2^52 - 1] can be represented without loss of information.\n\t */\n\t inline double mlrngood(uint64_t *rngStateX, uint32_t rngStateA){\n\t\t*rngStateX = (*rngStateX & (uint64_t)0xFFFFFFFFUL)*\n\t\t\t(rngStateA) + (*rngStateX >> 32);\n\t\t\n\t\t/* Generate a random number from open interval (0.0, 1.0). */\n\t\treturn cl_fdiv( ((double)(1 | (*rngStateX & (uint64_t)0xFFFFFFFFFFFFFUL))), \n\t\t\t(double)0x10000000000000UL);\n\t};\n\n\t/**\n\t * @brief Generates a random number from open/closed interval (0.0, 1.0] given\n\t *\t a state of the generator in terms of two unsigned integers. The two  \n\t *\tstates/seeds should be initialized independently for each thread.\n\t *\tSee Python module clrng for generating pairs of unsigned integer seeds.\n\t * @param[in, out] rngStateX Pointer to 64-bit unsigned number/state\n\t *\t\t\t\t\tupdated on return.\n\t * @param[in, out] rngStateA Pointer to 32-bit unsigned number/state.\n\t * @return A double precision random number from (0.0, 1.0).\n\t * \n\t * @details George Marsaglia's Random Number Generator. A double precision \n\t *\tfloating point number has a 52-bit mantisa, hence only integers from \n\t *\t[0, 2^52 - 1] can be represented without loss of information.\n\t */\n\t inline double mlrngocd(uint64_t *rngStateX, uint32_t rngStateA){\n\t\t*rngStateX = (*rngStateX & (uint64_t)0xFFFFFFFFUL)*\n\t\t\t(rngStateA) + (*rngStateX >> 32);\n\t\t\n\t\t/* Generate a random number from open interval (0.0, 1.0). */\n\t\treturn cl_fdiv( ((double)(1 | (*rngStateX & (uint64_t)0xFFFFFFFFFFFFFUL))), \n\t\t\t(double)0xFFFFFFFFFFFFFUL);\n\t};\n\n\t/**\n\t * @brief Generates a random number from closed/open interval [0.0, 1.0) given\n\t *\t a state of the generator in terms of two unsigned integers. The two  \n\t *\tstates/seeds should be initialized independently for each thread.\n\t *\tSee Python module clrng for generating pairs of unsigned integer seeds.\n\t * @param[in, out] rngStateX Pointer to 64-bit unsigned number/state\n\t *\t\t\t\t\tupdated on return.\n\t * @param[in, out] rngStateA Pointer to 32-bit unsigned number/state.\n\t * @return A double precision random number from (0.0, 1.0).\n\t * \n\t * @details George Marsaglia's Random Number Generator. A double precision \n\t *\tfloating point number has a 52-bit mantisa, hence only integers from \n\t *\t[0, 2^52 - 1] can be represented without loss of information.\n\t */\n\t inline double mlrngcod(uint64_t *rngStateX, uint32_t rngStateA){\n\t\t*rngStateX = (*rngStateX & (uint64_t)0xFFFFFFFFUL)*\n\t\t\t(rngStateA) + (*rngStateX >> 32);\n\t\t\n\t\t/* Generate a random number from open interval (0.0, 1.0). */\n\t\treturn cl_fdiv( ((double)((*rngStateX & (uint64_t)0xFFFFFFFFFFFFFUL))), \n\t\t\t(double)0x10000000000000UL);\n\t};\n\n\t/**\n\t * @brief Generates a random number from closed/closed interval [0.0, 1.0] given\n\t *\t a state of the generator in terms of two unsigned integers. The two  \n\t *\tstates/seeds should be initialized independently for each thread.\n\t *\tSee Python module clrng for generating pairs of unsigned integer seeds.\n\t * @param[in, out] rngStateX Pointer to 64-bit unsigned number/state\n\t *\t\t\t\t\tupdated on return.\n\t * @param[in, out] rngStateA Pointer to 32-bit unsigned number/state.\n\t * @return A double precision random number from (0.0, 1.0).\n\t * \n\t * @details George Marsaglia's Random Number Generator. A double precision \n\t *\tfloating point number has a 52-bit mantisa, hence only integers from \n\t *\t[0, 2^52 - 1] can be represented without loss of information.\n\t */\n\t inline double mlrngccd(uint64_t *rngStateX, uint32_t rngStateA){\n\t\t*rngStateX = (*rngStateX & (uint64_t)0xFFFFFFFFUL)*\n\t\t\t(rngStateA) + (*rngStateX >> 32);\n\t\t\n\t\t/* Generate a random number from open interval (0.0, 1.0). */\n\t\treturn cl_fdiv( ((double)((*rngStateX & (uint64_t)0xFFFFFFFFFFFFFUL))), \n\t\t\t(double)0xFFFFFFFFFFFFFUL);\n\t};\n#endif /* ML_DOUBLE_PRECISION */\n\n/**\n * @} // @addtogroup cl_rng OpneCL random number generators\n */\n/*####################### End random number generator ########################*/\n\n#endif /* CLBASE_DEFINES_ */\n\n"
DEFAULT_CL_DIR = '/home/miran/src/pyxopto/tmp/release/pyxopto/xopto/cl/kernel'

Place to look for the OpenCL kernels related to this class.

DEFAULT_EXPORT_FILE = '/home/miran/.xopto/pyxopto/tmp/clprogram.c'

Default filename suffix for auto-generated OpenCL source code

static clbase(doubleprecision: bool = False)str[source]

Return the class-related OpenCL source code in the requested precision.

Parameters

doubleprecision (bool) – Turns on double precision if set to True.

Returns

clcode – OpenCL code in requested precision.

Return type

str

declare(kernel: str, args: List[xopto.cl.cleasy.ArgScalar])List[xopto.cl.cleasy.ArgScalar][source]

Use this function to declare a kernel by name. Use the same name as in the OpenCL code.

Parameters
  • kernel (str) – Kernel name as in the OpenCL file.

  • args (list/tuple of arguments) – Define a list of arguments in terms of ArgScalar, ArgArray or ArgLocalMemory instances.

Returns

decl – Declaration of kernel arguments.

Return type

list

device()pyopencl._cl.Device[source]

Return the OpenCL context device.

fid = <_io.TextIOWrapper name='/home/miran/src/pyxopto/tmp/release/pyxopto/xopto/cl/kernel/clbase.h' mode='rt' encoding='UTF-8'>
kernelinfo(name: str)List[dict][source]

Returns information about the arguments of the specified kernel.

Parameters

kernel (str) – Kernel name as in the OpenCL source file.

Returns

info – A list of dicts with information on the kernel arguments.

Return type

List[dict]

upload_kernel_arg(kernel: str, arg_index: int, np_data: numpy.ndarray)[source]

Updates the contents of the OpenCL buffer for the given kernel argument.

Parameters
  • kernel (str) – A declared OpenCL kernel name.

  • arg_inex (int) – Index of the kernel argument.

  • np_data (npy.ndarray) – Numpy data to transfer to the kernel argument.