AQUAgpusph 5.0.4
Loading...
Searching...
No Matches
3D.h File Reference

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

Go to the source code of this file.

Macros

#define vec   float4
#define dvec   double4
#define ivec   int4
#define lvec   long4
#define uivec   uint4
#define ulvec   ulong4
#define svec   usize4
#define ssvec   ssize4
#define matrix   float16
#define VEC_ZERO   ((float4)(0.f,0.f,0.f,0.f))
 Null vec, i.e. filled with zero components.
#define VEC_ONE   ((float4)(1.f, 1.f, 1.f, 0.f))
 Ones vec, i.e. filled with one components (except the w component).
#define VEC_ALL_ONE   ((float4)(1.f, 1.f, 1.f, 1.f))
 Ones vec, i.e. filled with one components.
#define VEC_INFINITY   ((float4)(INFINITY, INFINITY, INFINITY, 0.f))
 Infinity vec, i.e. filled with infinity components (except the w component).
#define VEC_ALL_INFINITY   ((float4)(INFINITY, INFINITY, INFINITY, INFINITY))
 Infinity vec, i.e. filled with infinity components.
#define VEC_NEG_INFINITY   (-VEC_INFINITY)
 -Infinity vec, i.e. filled with -infinity components (except the w component).
#define VEC_ALL_NEG_INFINITY   (-VEC_ALL_INFINITY)
 -Infinity vec, i.e. filled with -infinity components.
#define MAT_ZERO
 Null matrix, i.e. filled with zero components.
#define MAT_ONE
 Ones matrix, i.e. filled with one components, except the last row and column.
#define MAT_ALL_ONE
 Ones matrix, i.e. filled with one components.
#define MAT_EYE
 Eye matrix , except the south-east component, which is filled with a zero.
#define MAT_ALL_EYE
 Eye matrix.
#define XYZ   xyz
 Convenient access to the vector components.
#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 BEGIN_NEIGHS(CELL, NPARTS, NCELLS, ICELL, IHOC)
 Loop over the neighbours to compute the interactions.
#define END_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(_M, _V)
 Multiply a matrix by a vector (inner product)
#define MATRIX_MUL(_M1, _M2)
 Multiply a matrix by a matrix (inner product)
#define MATRIX_MUL_ALL(_M1, _M2)
 Multiply a matrix by a matrix (inner product)
#define TRANSPOSE   s048C159D26AE37BF
 Transpose a matrix.
#define DIAG   s05A
 The matrix diagonal (as vector)
#define MATRIX_FROM_DIAG(_V)
 Build up a matrix from the diagonal information (as vector)
#define MATRIX_TRACE(_M)
 Trace of the matrix.
#define MATRIX_INV(_M)
 Pseudo-inverse of a matrix.
#define vec_xyz   vec3
 Vectors with the minimum number of components.
#define dvec_xyz   dvec3
#define ivec_xyz   ivec3
#define lvec_xyz   lvec3
#define uivec_xyz   uivec3
#define ulvec_xyz   ulvec3
#define svec_xyz   svec3
#define ssvec_xyz   ssvec3

Functions

matrix outer (const vec3 v1, const vec3 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 (3D version).

Macro Definition Documentation

◆ 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++) { \
for(int ck = -1; ck <= 1; ck++) { \
const usize c_j = c_i + \
ci + \
cj * n_cells.x + \
ck * n_cells.x * n_cells.y; \
usize j = ihoc[c_j]; \
while((j < N) && (icell[j] == c_j)) {
#define C_I()

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

◆ BEGIN_NEIGHS

#define BEGIN_NEIGHS ( CELL,
NPARTS,
NCELLS,
ICELL,
IHOC )
Value:
for(int __ci = -1; __ci <= 1; __ci++) { \
for(int __cj = -1; __cj <= 1; __cj++) { \
for(int __ck = -1; __ck <= 1; __ck++) { \
const uint __c_j = CELL + \
__ci + \
__cj * NCELLS.x + \
__ck * NCELLS.x * NCELLS.y; \
uint j = IHOC[__c_j]; \
while((j < NPARTS) && (ICELL[j] == __c_j)) {

Loop over the neighbours to compute the interactions.

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

The resulting neighs will be automatically identified by the unsigned integer variable j. To discard a neighbour particle, remember calling

j++

followed by

continue

The following variables will be declared, and therefore cannot be used within the loop scope:

  • __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
Parameters
CELLCell of the main particle (usually
icell[i]
)
NPARTSNumber of particles (usually
N
)
NCELLSNumber of cells at each direction (usually
n_cells
)
ICELLArray of cells for each particle (usually
icell
)
IHOCArray of head of cells (usually
ihoc
)
See also
END_NEIGHS
Note
This macro is created to replace the old BEGIN_LOOP_OVER_NEIGHS, which does not easily allows to do multi-gpu computations

◆ DIAG

#define DIAG   s05A

The matrix diagonal (as vector)

◆ dvec

#define dvec   double4

◆ dvec_xyz

#define dvec_xyz   dvec3

◆ 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

◆ END_NEIGHS

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

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

See also
BEGIN_LOOP_OVER_NEIGHS
Note
This macro is created to replace the old END_LOOP_OVER_NEIGHS, which does not easily allows to do multi-gpu computations

◆ ivec

#define ivec   int4

◆ ivec_xyz

#define ivec_xyz   ivec3

◆ lvec

#define lvec   long4

◆ lvec_xyz

#define lvec_xyz   lvec3

◆ MAT_ALL_EYE

#define MAT_ALL_EYE
Value:
((float16)(1.f, 0.f, 0.f, 0.f, \
0.f, 1.f, 0.f, 0.f, \
0.f, 0.f, 1.f, 0.f, \
0.f, 0.f, 0.f, 1.f))

Eye matrix.

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

◆ MAT_ALL_ONE

#define MAT_ALL_ONE
Value:
((float16)(1.f, 1.f, 1.f, 1.f, \
1.f, 1.f, 1.f, 1.f, \
1.f, 1.f, 1.f, 1.f, \
1.f, 1.f, 1.f, 1.f))

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

◆ MAT_EYE

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

Eye matrix , except the south-east component, which is filled with a zero.

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

◆ MAT_ONE

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

Ones matrix, i.e. filled with one components, except the last row and column.

◆ MAT_ZERO

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

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

◆ matrix

#define matrix   float16

◆ MATRIX_DOT

#define MATRIX_DOT ( _M,
_V )
Value:
((float4)(dot(_M.s012, _V.xyz), \
dot(_M.s456, _V.xyz), \
dot(_M.s89A, _V.xyz), \
0.f))

Multiply a matrix by a vector (inner product)

Note
The vector should have 3 components, not 4.

◆ MATRIX_DOT_ALL

#define MATRIX_DOT_ALL ( _M,
_V )
Value:
((float4)(dot(_M.s0123, _V), \
dot(_M.s4567, _V), \
dot(_M.s89AB, _V), \
dot(_M.sCDEF, _V)))

Multiply a matrix by a vector (inner product)

◆ MATRIX_FROM_DIAG

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

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

Note
The component w of the vector is ignored (and 0.f is used instead)

◆ MATRIX_INV

#define MATRIX_INV ( _M)
Value:
MATRIX_MUL(inv(MATRIX_MUL(_M.TRANSPOSE, _M)), _M.TRANSPOSE)
matrix inv(const matrix m)
Inverse of a matrix.
Definition 2D.h:266
#define MATRIX_MUL(_M1, _M2)
Multiply a matrix by a matrix (inner product)
Definition 2D.h:207

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:
((float16)( \
dot(_M1.s012, _M2.s048), dot(_M1.s012, _M2.s159), dot(_M1.s012, _M2.s26A), 0.f, \
dot(_M1.s456, _M2.s048), dot(_M1.s456, _M2.s159), dot(_M1.s456, _M2.s26A), 0.f, \
dot(_M1.s89A, _M2.s048), dot(_M1.s89A, _M2.s159), dot(_M1.s89A, _M2.s26A), 0.f, \
0.f, 0.f, 0.f, 0.f))

Multiply a matrix by a matrix (inner product)

Note
The last row and column of each matrix will be ignored. To perform a complete inner product use MATRIX_MUL_ALL

◆ MATRIX_MUL_ALL

#define MATRIX_MUL_ALL ( _M1,
_M2 )
Value:
((float16)( \
dot(_M1.s0123, _M2.s048C), dot(_M1.s0123, _M2.s159D), dot(_M1.s0123, _M2.s26AE), dot(_M1.s0123, _M2.s37BF), \
dot(_M1.s4567, _M2.s048C), dot(_M1.s4567, _M2.s159D), dot(_M1.s4567, _M2.s26AE), dot(_M1.s4567, _M2.s37BF), \
dot(_M1.s89AB, _M2.s048C), dot(_M1.s89AB, _M2.s159D), dot(_M1.s89AB, _M2.s26AE), dot(_M1.s89AB, _M2.s37BF), \
dot(_M1.sCDEF, _M2.s048C), dot(_M1.sCDEF, _M2.s159D), dot(_M1.sCDEF, _M2.s26AE), dot(_M1.sCDEF, _M2.s37BF)))

Multiply a matrix by a matrix (inner product)

Note
For performance purposes, using MATRIX_MUL instead of this operator is strongly recommended.

◆ MATRIX_TRACE

#define MATRIX_TRACE ( _M)
Value:
(_M.s0 + _M.s5 + _M.sA)

Trace of the matrix.

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

◆ ssvec

#define ssvec   ssize4

◆ ssvec_xyz

#define ssvec_xyz   ssvec3

◆ svec

#define svec   usize4

◆ svec_xyz

#define svec_xyz   svec3

◆ TRANSPOSE

#define TRANSPOSE   s048C159D26AE37BF

Transpose a matrix.

◆ uivec

#define uivec   uint4

◆ uivec_xyz

#define uivec_xyz   uivec3

◆ ulvec

#define ulvec   ulong4

◆ ulvec_xyz

#define ulvec_xyz   ulvec3

◆ vec

#define vec   float4

◆ VEC_ALL_INFINITY

#define VEC_ALL_INFINITY   ((float4)(INFINITY, INFINITY, INFINITY, INFINITY))

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

◆ VEC_ALL_NEG_INFINITY

#define VEC_ALL_NEG_INFINITY   (-VEC_ALL_INFINITY)

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

◆ VEC_ALL_ONE

#define VEC_ALL_ONE   ((float4)(1.f, 1.f, 1.f, 1.f))

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

◆ VEC_INFINITY

#define VEC_INFINITY   ((float4)(INFINITY, INFINITY, INFINITY, 0.f))

Infinity vec, i.e. filled with infinity components (except the w component).

◆ VEC_NEG_INFINITY

#define VEC_NEG_INFINITY   (-VEC_INFINITY)

-Infinity vec, i.e. filled with -infinity components (except the w component).

◆ VEC_ONE

#define VEC_ONE   ((float4)(1.f, 1.f, 1.f, 0.f))

Ones vec, i.e. filled with one components (except the w component).

◆ vec_xyz

#define vec_xyz   vec3

Vectors 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   ((float4)(0.f,0.f,0.f,0.f))

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

◆ XYZ

#define XYZ   xyz

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, eye matrix will be returned. Consider using MATRIX_INV pseudo-inverse instead
Note
The matrix will be considered as a 3x3 matrix, i.e. the last row and column will be filled by zeroes (except the bottom right corner, which will be set as 1).
Here is the call graph for this function:

◆ outer()

matrix outer ( const vec3 v1,
const vec3 v2 )

Perform the outer product of two vectors.

Parameters
v1Left operand vector (of 3 components)
v2Right operand vector (of 3 components)