From 27f4d1e4ff8cec243718faa07bcf2bfe44145aea Mon Sep 17 00:00:00 2001 From: jpekkila Date: Tue, 23 Jul 2019 13:44:43 +0300 Subject: [PATCH] Added actual functions for getting size of the vertex buffers etc. The previously used macros are now deprecated. Type safety is the major benefit of using functions instead of definitions. --- include/astaroth.h | 53 ++++++++++++++++++++++++++------------ include/astaroth_defines.h | 17 ++++++++++++ 2 files changed, 54 insertions(+), 16 deletions(-) diff --git a/include/astaroth.h b/include/astaroth.h index 3f6fdd6..0c2897f 100644 --- a/include/astaroth.h +++ b/include/astaroth.h @@ -38,22 +38,6 @@ typedef enum { STREAM_ALL } StreamType; -#define AC_VTXBUF_SIZE(mesh_info) \ - ((size_t)(mesh_info.int_params[AC_mx] * mesh_info.int_params[AC_my] * \ - mesh_info.int_params[AC_mz])) - -#define AC_VTXBUF_SIZE_BYTES(mesh_info) (sizeof(AcReal) * AC_VTXBUF_SIZE(mesh_info)) - -#define AC_VTXBUF_COMPDOMAIN_SIZE(mesh_info) \ - (mesh_info.int_params[AC_nx] * mesh_info.int_params[AC_ny] * mesh_info.int_params[AC_nz]) - -#define AC_VTXBUF_COMPDOMAIN_SIZE_BYTES(mesh_info) \ - (sizeof(AcReal) * AC_VTXBUF_COMPDOMAIN_SIZE(mesh_info)) - -#define AC_VTXBUF_IDX(i, j, k, mesh_info) \ - ((i) + (j)*mesh_info.int_params[AC_mx] + \ - (k)*mesh_info.int_params[AC_mx] * mesh_info.int_params[AC_my]) - /** Checks whether there are any CUDA devices available. Returns AC_SUCCESS if there is 1 or more, * AC_FAILURE otherwise. */ AcResult acCheckDeviceAvailability(void); @@ -137,3 +121,40 @@ AcResult acIntegrateStepWithOffsetAsync(const int& isubstep, const AcReal& dt, c /** Performs the boundary condition step on the GPUs in the node. Asynchronous. */ AcResult acBoundcondStep(void); AcResult acBoundcondStepAsync(const StreamType stream); + +/* + * ============================================================================= + * Helper functions + * ============================================================================= + */ +static inline size_t +acVertexBufferSize(const AcMeshInfo& info) +{ + return info.int_params[AC_mx] * info.int_params[AC_my] * info.int_params[AC_mz]; +} + +static inline size_t +acVertexBufferSizeBytes(const AcMeshInfo& info) +{ + return sizeof(AcReal) * acVertexBufferSize(info); +} + +static inline size_t +acVertexBufferCompdomainSize(const AcMeshInfo& info) +{ + return info.int_params[AC_nx] * info.int_params[AC_ny] * info.int_params[AC_nz]; +} + +static inline size_t +acVertexBufferCompdomainSizeBytes(const AcMeshInfo& info) +{ + return sizeof(AcReal) * acVertexBufferCompdomainSize(info); +} + +static inline size_t +acVertexBufferIdx(const int i, const int j, const int k, const AcMeshInfo& info) +{ + return i + // + j * info.int_params[AC_mx] + // + k * info.int_params[AC_mx] * info.int_params[AC_my]; +} diff --git a/include/astaroth_defines.h b/include/astaroth_defines.h index 89808c9..9cbf3ca 100644 --- a/include/astaroth_defines.h +++ b/include/astaroth_defines.h @@ -107,3 +107,20 @@ extern const char* int3param_names[]; extern const char* realparam_names[]; extern const char* real3param_names[]; extern const char* vtxbuf_names[]; + +// Deprecated +#define AC_VTXBUF_SIZE(mesh_info) \ + ((size_t)(mesh_info.int_params[AC_mx] * mesh_info.int_params[AC_my] * \ + mesh_info.int_params[AC_mz])) + +#define AC_VTXBUF_SIZE_BYTES(mesh_info) (sizeof(AcReal) * AC_VTXBUF_SIZE(mesh_info)) + +#define AC_VTXBUF_COMPDOMAIN_SIZE(mesh_info) \ + (mesh_info.int_params[AC_nx] * mesh_info.int_params[AC_ny] * mesh_info.int_params[AC_nz]) + +#define AC_VTXBUF_COMPDOMAIN_SIZE_BYTES(mesh_info) \ + (sizeof(AcReal) * AC_VTXBUF_COMPDOMAIN_SIZE(mesh_info)) + +#define AC_VTXBUF_IDX(i, j, k, mesh_info) \ + ((i) + (j)*mesh_info.int_params[AC_mx] + \ + (k)*mesh_info.int_params[AC_mx] * mesh_info.int_params[AC_my])