AQUAgpusph 4.1.2
Loading...
Searching...
No Matches
Macros | Functions
2D.h File Reference

Type definitions for the OpenCL kernels (2D version). More...

Go to the source code of this file.

Macros

#define INFINITY   FLT_MAX
 
#define unit   unsigned int
 
#define vec2   float2
 
#define vec3   float3
 
#define vec4   float4
 
#define ivec2   int2
 
#define ivec3   int3
 
#define ivec4   int4
 
#define uivec2   uint2
 
#define uivec3   uint3
 
#define uivec4   uint4
 
#define vec   float2
 
#define ivec   int2
 
#define uivec   uint2
 
#define matrix   float4
 
#define _CONVERT(TYPE)   convert_ ## TYPE
 Helper function for CONVERT()
 
#define CONVERT(TYPE, v)   _CONVERT(TYPE)(v)
 Conversor between complex types.
 
#define VEC_ZERO   ((float2)(0.f,0.f))
 Null vec, i.e. filled with zero components.
 
#define VEC_ONE   ((float2)(1.f, 1.f))
 Ones vec, i.e. filled with one components.
 
#define VEC_ALL_ONE   VEC_ONE
 VEC_ONE.
 
#define VEC_INFINITY   ((float2)(INFINITY, INFINITY))
 Infinity vec, i.e. filled with infinity components.
 
#define VEC_ALL_INFINITY   VEC_INFINITY
 VEC_INFINITY.
 
#define VEC_NEG_INFINITY   (-VEC_INFINITY)
 -Infinity vec, i.e. filled with -infinity components.
 
#define VEC_ALL_NEG_INFINITY   (-VEC_ALL_INFINITY)
 VEC_NEG_INFINITY.
 
#define MAT_ZERO
 Null matrix, i.e. filled with zero components.
 
#define MAT_ONE
 Ones matrix, i.e. filled with one components.
 
#define MAT_ALL_ONE   MAT_ONE
 MAT_ONE.
 
#define MAT_EYE
 Eye matrix.
 
#define MAT_ALL_EYE   MAT_EYE
 MAT_EYE.
 
#define vec_xyz   vec2
 Vector of real components with the minimum number of components.
 
#define ivec_xyz   ivec2
 Vector of integer components.
 
#define uivec_xyz   uivec2
 Vector of unsigned integer components.
 
#define XYZ   xy
 Convenient access to the vector components.
 
#define C_I()   const uint c_i = icell[i]
 Utility to can redefine the cell of the particle to be computed.
 
#define BEGIN_LOOP_OVER_NEIGHS()
 Loop over the neighs to compute the interactions.
 
#define END_LOOP_OVER_NEIGHS()
 End of the loop over the neighs to compute the interactions.
 
#define MATRIX_DOT(_M, _V)
 Multiply a matrix by a vector (inner product)
 
#define MATRIX_DOT_ALL   MATRIX_DOT
 MATRIX_DOT
 
#define MATRIX_MUL(_M1, _M2)
 Multiply a matrix by a matrix (inner product)
 
#define MATRIX_MUL_ALL   MATRIX_MUL
 MATRIX_MUL
 
#define TRANSPOSE   s0213
 Transpose a matrix.
 
#define DIAG   s03
 The matrix diagonal (as vector)
 
#define MATRIX_FROM_DIAG(_V)
 Build up a matrix from the diagonal information (as vector)
 
#define MATRIX_TRACE(_M)   (_M.s0 + _M.s3)
 Trace of the matrix.
 
#define MATRIX_INV(_M)    MATRIX_MUL(inv(MATRIX_MUL(_M.TRANSPOSE, _M)), _M.TRANSPOSE)
 Pseudo-inverse of a matrix.
 

Functions

matrix outer (const vec v1, const vec v2)
 Perform the outer product of two vectors.
 
float det (const matrix m)
 Determinant of a matrix.
 
matrix inv (const matrix m)
 Inverse of a matrix.
 

Detailed Description

Type definitions for the OpenCL kernels (2D version).

Macro Definition Documentation

◆ _CONVERT

#define _CONVERT (   TYPE)    convert_ ## TYPE

Helper function for CONVERT()

The helper is required because the preprocessor is only recursively expanding macros if the definition is not affected by # nor ## string operators. Then, this inner function is concatenating the unexpanded words, while CONVERT() is effectively expanding the type name.

◆ BEGIN_LOOP_OVER_NEIGHS

#define BEGIN_LOOP_OVER_NEIGHS ( )
Value:
C_I(); \
for(int ci = -1; ci <= 1; ci++) { \
for(int cj = -1; cj <= 1; cj++) { \
const uint c_j = c_i + \
ci + \
cj * n_cells.x; \
uint j = ihoc[c_j]; \
while((j < N) && (icell[j] == c_j)) {
#define C_I()
Utility to can redefine the cell of the particle to be computed.
Definition: 2D.h:156

Loop over the neighs to compute the interactions.

All the code between this macro and END_LOOP_OVER_NEIGHS will be executed for all the neighbours.

To use this macro, the main particle (the one which the interactions are intended to be computed) should be identified by an unsigned integer variable i, while the resulting neighs will be automatically identified by the unsigned integer variable j. To discard a neighbour particle, remember calling

j++

before

continue

The following variables will be declared, and therefore cannot be used elsewhere:

  • c_i: The cell where the particle i is placed
  • ci: Index of the cell of the neighbour particle j, in the x direction
  • cj: Index of the cell of the neighbour particle j, in the x direction
  • ck: Index of the cell of the neighbour particle j, in the x direction
  • c_j: Index of the cell of the neighbour particle j
  • j: Index of the neighbour particle.
See also
END_LOOP_OVER_NEIGHS

◆ C_I

#define C_I ( )    const uint c_i = icell[i]

Utility to can redefine the cell of the particle to be computed.

It can be used for mirrrored particles, which are temporary associated to a different cell.

See also
BEGIN_LOOP_OVER_NEIGHS

◆ CONVERT

#define CONVERT (   TYPE,
 
)    _CONVERT(TYPE)(v)

Conversor between complex types.

In OpenCL, to convert between complex types the functions convert_TYPEN should be used. Otherwise casting errors will be received.

This definition provides a convenient function to become used with the overloaded types vec, ivec and uivec.

For instance, to convert a vec variable, v, to an ivec variable, you can call CONVERT(ivec, v);

◆ DIAG

#define DIAG   s03

The matrix diagonal (as vector)

◆ END_LOOP_OVER_NEIGHS

#define END_LOOP_OVER_NEIGHS ( )
Value:
j++; \
} \
} \
}

End of the loop over the neighs to compute the interactions.

See also
BEGIN_LOOP_OVER_NEIGHS

◆ INFINITY

#define INFINITY   FLT_MAX

◆ ivec

#define ivec   int2

◆ ivec2

#define ivec2   int2

◆ ivec3

#define ivec3   int3

◆ ivec4

#define ivec4   int4

◆ ivec_xyz

#define ivec_xyz   ivec2

Vector of integer components.

The number of components depends on weather the 2D version or 3D version is compiled:

  • 2D = 2 components
  • 3D = 3 components

This type can be used for the local variables to reduce the VGPRs.

◆ MAT_ALL_EYE

#define MAT_ALL_EYE   MAT_EYE

MAT_EYE.

◆ MAT_ALL_ONE

#define MAT_ALL_ONE   MAT_ONE

MAT_ONE.

◆ MAT_EYE

#define MAT_EYE
Value:
((float4)(1.f, 0.f, \
0.f, 1.f))

Eye matrix.

\( m_{ii} = 1; m_{ij} = 1 \leftrightarrow i \neq j \)

◆ MAT_ONE

#define MAT_ONE
Value:
((float4)(1.f, 1.f, \
1.f, 1.f))

Ones matrix, i.e. filled with one components.

◆ MAT_ZERO

#define MAT_ZERO
Value:
((float4)(0.f, 0.f, \
0.f, 0.f))

Null matrix, i.e. filled with zero components.

◆ matrix

#define matrix   float4

◆ MATRIX_DOT

#define MATRIX_DOT (   _M,
  _V 
)
Value:
((float2)(dot(_M.s01, _V), \
dot(_M.s23, _V)))

Multiply a matrix by a vector (inner product)

◆ MATRIX_DOT_ALL

#define MATRIX_DOT_ALL   MATRIX_DOT

◆ MATRIX_FROM_DIAG

#define MATRIX_FROM_DIAG (   _V)
Value:
((float4)(_V.x, 0.f, \
0.f, _V.y))

Build up a matrix from the diagonal information (as vector)

◆ MATRIX_INV

#define MATRIX_INV (   _M)     MATRIX_MUL(inv(MATRIX_MUL(_M.TRANSPOSE, _M)), _M.TRANSPOSE)

Pseudo-inverse of a matrix.

The SVD Moore-Penrose method is applied:

\[ A^{\dag} = \left( A^T A \right)^{-1} A^T \]

◆ MATRIX_MUL

#define MATRIX_MUL (   _M1,
  _M2 
)
Value:
((float4)(dot(_M1.s01, _M2.s02), dot(_M1.s01, _M2.s13), \
dot(_M1.s23, _M2.s02), dot(_M1.s23, _M2.s13)))

Multiply a matrix by a matrix (inner product)

◆ MATRIX_MUL_ALL

#define MATRIX_MUL_ALL   MATRIX_MUL

◆ MATRIX_TRACE

#define MATRIX_TRACE (   _M)    (_M.s0 + _M.s3)

Trace of the matrix.

i.e. The sum of the diagonal elements of the matrix.

◆ TRANSPOSE

#define TRANSPOSE   s0213

Transpose a matrix.

◆ uivec

#define uivec   uint2

◆ uivec2

#define uivec2   uint2

◆ uivec3

#define uivec3   uint3

◆ uivec4

#define uivec4   uint4

◆ uivec_xyz

#define uivec_xyz   uivec2

Vector of unsigned integer components.

The number of components depends on weather the 2D version or 3D version is compiled:

  • 2D = 2 components
  • 3D = 3 components

This type can be used for the local variables to reduce the VGPRs.

◆ unit

#define unit   unsigned int

◆ vec

#define vec   float2

◆ vec2

#define vec2   float2

◆ vec3

#define vec3   float3

◆ vec4

#define vec4   float4

◆ VEC_ALL_INFINITY

#define VEC_ALL_INFINITY   VEC_INFINITY

VEC_INFINITY.

◆ VEC_ALL_NEG_INFINITY

#define VEC_ALL_NEG_INFINITY   (-VEC_ALL_INFINITY)

VEC_NEG_INFINITY.

◆ VEC_ALL_ONE

#define VEC_ALL_ONE   VEC_ONE

VEC_ONE.

◆ VEC_INFINITY

#define VEC_INFINITY   ((float2)(INFINITY, INFINITY))

Infinity vec, i.e. filled with infinity components.

◆ VEC_NEG_INFINITY

#define VEC_NEG_INFINITY   (-VEC_INFINITY)

-Infinity vec, i.e. filled with -infinity components.

◆ VEC_ONE

#define VEC_ONE   ((float2)(1.f, 1.f))

Ones vec, i.e. filled with one components.

◆ vec_xyz

#define vec_xyz   vec2

Vector of real components with the minimum number of components.

The number of components depends on weather the 2D version or 3D version is compiled:

  • 2D = 2 components
  • 3D = 3 components

This type can be used for the local variables to reduce the VGPRs.

◆ VEC_ZERO

#define VEC_ZERO   ((float2)(0.f,0.f))

Null vec, i.e. filled with zero components.

◆ XYZ

#define XYZ   xy

Convenient access to the vector components.

It is useful to be used with vec_xyz, ivec_xyz and uivec_xyz type:

  • 2D = .xy
  • 3D = .xyz

Function Documentation

◆ det()

float det ( const matrix  m)

Determinant of a matrix.

Parameters
mMatrix to invert
Returns
Determinant

◆ inv()

matrix inv ( const matrix  m)

Inverse of a matrix.

Parameters
mMatrix to invert
Returns
Inverse of the matrix
Remarks
If the input matrix m is singular, nan values matrix will be returned. Consider using MATRIX_INV pseudo-inverse instead
Here is the call graph for this function:

◆ outer()

matrix outer ( const vec  v1,
const vec  v2 
)

Perform the outer product of two vectors.

Parameters
v1Left operand vector
v2Right operand vector
Returns
Outer product matrix