From 3afab7753349408b1734337ce37b5c984493a2c0 Mon Sep 17 00:00:00 2001 From: jpekkila Date: Wed, 29 Jul 2020 19:58:21 +0300 Subject: [PATCH] Removed astaroth_utils from astaroth_core dependencies --- include/astaroth.h | 14 ++++++++ include/astaroth_utils.h | 29 ++++++++--------- src/core/CMakeLists.txt | 2 +- src/core/astaroth.cc | 62 ++++++++++++++++++++++++++++++++++++ src/core/astaroth_fortran.cc | 1 - src/core/device.cc | 1 - src/utils/config_loader.c | 39 ----------------------- src/utils/memory.c | 23 ------------- 8 files changed, 91 insertions(+), 80 deletions(-) diff --git a/include/astaroth.h b/include/astaroth.h index be323ef..09a1405 100644 --- a/include/astaroth.h +++ b/include/astaroth.h @@ -562,6 +562,20 @@ AcResult acDeviceReduceVec(const Device device, const Stream stream_type, const /** */ AcResult acDeviceRunMPITest(void); +/* + * ============================================================================= + * Helper functions + * ============================================================================= + */ +/** Updates the built-in parameters based on nx, ny and nz */ +AcResult acUpdateBuiltinParams(AcMeshInfo* config); + +/** Creates a mesh stored in host memory */ +AcResult acMeshCreate(const AcMeshInfo mesh_info, AcMesh* mesh); + +/** Destroys a mesh stored in host memory */ +AcResult acMeshDestroy(AcMesh* mesh); + #ifdef __cplusplus } // extern "C" #endif diff --git a/include/astaroth_utils.h b/include/astaroth_utils.h index d96074c..ee5ebd4 100644 --- a/include/astaroth_utils.h +++ b/include/astaroth_utils.h @@ -70,20 +70,16 @@ bool printErrorToScreen(const Error error); /** Loads data from the config file */ AcResult acLoadConfig(const char* config_path, AcMeshInfo* config); -/** Updates the built-in parameters based on nx, ny and nz */ -AcResult acUpdateBuiltinParams(AcMeshInfo* config); +/** */ +AcScalReductionTestCase acCreateScalReductionTestCase(const char* label, + const VertexBufferHandle vtxbuf, + const ReductionType rtype); /** */ -AcResult acMeshCreate(const AcMeshInfo mesh_info, AcMesh* mesh); - -/** */ -AcResult acMeshDestroy(AcMesh* mesh); - -/** */ -AcScalReductionTestCase acCreateScalReductionTestCase(const char* label, const VertexBufferHandle vtxbuf, const ReductionType rtype); - -/** */ -AcVecReductionTestCase acCreateVecReductionTestCase(const char* label, const VertexBufferHandle a, const VertexBufferHandle b, const VertexBufferHandle c, const ReductionType rtype); +AcVecReductionTestCase acCreateVecReductionTestCase(const char* label, const VertexBufferHandle a, + const VertexBufferHandle b, + const VertexBufferHandle c, + const ReductionType rtype); /** */ AcResult acMeshSet(const AcReal value, AcMesh* mesh); @@ -104,16 +100,19 @@ AcResult acModelIntegrateStep(AcMesh mesh, const AcReal dt); AcReal acModelReduceScal(const AcMesh mesh, const ReductionType rtype, const VertexBufferHandle a); /** TODO */ -AcReal acModelReduceVec(const AcMesh mesh, const ReductionType rtype, const VertexBufferHandle a, const VertexBufferHandle b, const VertexBufferHandle c); +AcReal acModelReduceVec(const AcMesh mesh, const ReductionType rtype, const VertexBufferHandle a, + const VertexBufferHandle b, const VertexBufferHandle c); /** */ AcResult acVerifyMesh(const AcMesh model, const AcMesh candidate); /** */ -AcResult acVerifyScalReductions(const AcMesh model, const AcScalReductionTestCase* testCases, const size_t numCases); +AcResult acVerifyScalReductions(const AcMesh model, const AcScalReductionTestCase* testCases, + const size_t numCases); /** */ -AcResult acVerifyVecReductions(const AcMesh model, const AcVecReductionTestCase* testCases, const size_t numCases); +AcResult acVerifyVecReductions(const AcMesh model, const AcVecReductionTestCase* testCases, + const size_t numCases); #ifdef __cplusplus } // extern "C" diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 1a70f93..9e2a556 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -2,7 +2,7 @@ find_package(CUDAToolkit) ## Astaroth Core add_library(astaroth_core STATIC device.cc node.cc astaroth.cc astaroth_fortran.cc) -target_link_libraries(astaroth_core astaroth_utils astaroth_kernels CUDA::cudart CUDA::cuda_driver) +target_link_libraries(astaroth_core astaroth_kernels CUDA::cudart CUDA::cuda_driver) ## Options if (MPI_ENABLED) diff --git a/src/core/astaroth.cc b/src/core/astaroth.cc index 3821e3a..3a38240 100644 --- a/src/core/astaroth.cc +++ b/src/core/astaroth.cc @@ -158,3 +158,65 @@ acGetNode(void) ERRCHK_ALWAYS(num_nodes > 0); return nodes[0]; } + +AcResult +acUpdateBuiltinParams(AcMeshInfo* config) +{ + config->int_params[AC_mx] = config->int_params[AC_nx] + STENCIL_ORDER; + ///////////// PAD TEST + // config->int_params[AC_mx] = config->int_params[AC_nx] + STENCIL_ORDER + PAD_SIZE; + ///////////// PAD TEST + config->int_params[AC_my] = config->int_params[AC_ny] + STENCIL_ORDER; + config->int_params[AC_mz] = config->int_params[AC_nz] + STENCIL_ORDER; + + // Bounds for the computational domain, i.e. nx_min <= i < nx_max + config->int_params[AC_nx_min] = STENCIL_ORDER / 2; + config->int_params[AC_nx_max] = config->int_params[AC_nx_min] + config->int_params[AC_nx]; + config->int_params[AC_ny_min] = STENCIL_ORDER / 2; + config->int_params[AC_ny_max] = config->int_params[AC_ny] + STENCIL_ORDER / 2; + config->int_params[AC_nz_min] = STENCIL_ORDER / 2; + config->int_params[AC_nz_max] = config->int_params[AC_nz] + STENCIL_ORDER / 2; + +// These do not have to be defined by empty projects any more. +// These should be set only if stdderiv.h is included +#ifdef AC_dsx + config->real_params[AC_inv_dsx] = (AcReal)(1.) / config->real_params[AC_dsx]; +#endif +#ifdef AC_dsy + config->real_params[AC_inv_dsy] = (AcReal)(1.) / config->real_params[AC_dsy]; +#endif +#ifdef AC_dsz + config->real_params[AC_inv_dsz] = (AcReal)(1.) / config->real_params[AC_dsz]; +#endif + + /* Additional helper params */ + // Int helpers + config->int_params[AC_mxy] = config->int_params[AC_mx] * config->int_params[AC_my]; + config->int_params[AC_nxy] = config->int_params[AC_nx] * config->int_params[AC_ny]; + config->int_params[AC_nxyz] = config->int_params[AC_nxy] * config->int_params[AC_nz]; + + return AC_SUCCESS; +} + +AcResult +acMeshCreate(const AcMeshInfo info, AcMesh* mesh) +{ + mesh->info = info; + + const size_t bytes = acVertexBufferSizeBytes(mesh->info); + for (int w = 0; w < NUM_VTXBUF_HANDLES; ++w) { + mesh->vertex_buffer[w] = (AcReal*)malloc(bytes); + ERRCHK_ALWAYS(mesh->vertex_buffer[w]); + } + + return AC_SUCCESS; +} + +AcResult +acMeshDestroy(AcMesh* mesh) +{ + for (int w = 0; w < NUM_VTXBUF_HANDLES; ++w) + free(mesh->vertex_buffer[w]); + + return AC_SUCCESS; +} diff --git a/src/core/astaroth_fortran.cc b/src/core/astaroth_fortran.cc index 80ee033..18aa749 100644 --- a/src/core/astaroth_fortran.cc +++ b/src/core/astaroth_fortran.cc @@ -1,7 +1,6 @@ #include "astaroth_fortran.h" #include "astaroth.h" -#include "astaroth_utils.h" #include "errchk.h" /** diff --git a/src/core/device.cc b/src/core/device.cc index e465017..5495286 100644 --- a/src/core/device.cc +++ b/src/core/device.cc @@ -2,7 +2,6 @@ #include -#include "astaroth_utils.h" #include "errchk.h" #include "math_utils.h" #include "timer_hires.h" diff --git a/src/utils/config_loader.c b/src/utils/config_loader.c index 6d7f930..50ed84c 100644 --- a/src/utils/config_loader.c +++ b/src/utils/config_loader.c @@ -74,45 +74,6 @@ parse_config(const char* path, AcMeshInfo* config) fclose(fp); } -AcResult -acUpdateBuiltinParams(AcMeshInfo* config) -{ - config->int_params[AC_mx] = config->int_params[AC_nx] + STENCIL_ORDER; - ///////////// PAD TEST - // config->int_params[AC_mx] = config->int_params[AC_nx] + STENCIL_ORDER + PAD_SIZE; - ///////////// PAD TEST - config->int_params[AC_my] = config->int_params[AC_ny] + STENCIL_ORDER; - config->int_params[AC_mz] = config->int_params[AC_nz] + STENCIL_ORDER; - - // Bounds for the computational domain, i.e. nx_min <= i < nx_max - config->int_params[AC_nx_min] = STENCIL_ORDER / 2; - config->int_params[AC_nx_max] = config->int_params[AC_nx_min] + config->int_params[AC_nx]; - config->int_params[AC_ny_min] = STENCIL_ORDER / 2; - config->int_params[AC_ny_max] = config->int_params[AC_ny] + STENCIL_ORDER / 2; - config->int_params[AC_nz_min] = STENCIL_ORDER / 2; - config->int_params[AC_nz_max] = config->int_params[AC_nz] + STENCIL_ORDER / 2; - - // These do not have to be defined by empty projects any more. - // These should be set only if stdderiv.h is included - #ifdef AC_dsx - config->real_params[AC_inv_dsx] = (AcReal)(1.) / config->real_params[AC_dsx]; - #endif - #ifdef AC_dsy - config->real_params[AC_inv_dsy] = (AcReal)(1.) / config->real_params[AC_dsy]; - #endif - #ifdef AC_dsz - config->real_params[AC_inv_dsz] = (AcReal)(1.) / config->real_params[AC_dsz]; - #endif - - /* Additional helper params */ - // Int helpers - config->int_params[AC_mxy] = config->int_params[AC_mx] * config->int_params[AC_my]; - config->int_params[AC_nxy] = config->int_params[AC_nx] * config->int_params[AC_ny]; - config->int_params[AC_nxyz] = config->int_params[AC_nxy] * config->int_params[AC_nz]; - - return AC_SUCCESS; -} - /** \brief Loads data from astaroth.conf into a config struct. \return AC_SUCCESS on success, AC_FAILURE if there are potentially uninitialized values. diff --git a/src/utils/memory.c b/src/utils/memory.c index ae50872..f587f4d 100644 --- a/src/utils/memory.c +++ b/src/utils/memory.c @@ -20,29 +20,6 @@ #include "errchk.h" -AcResult -acMeshCreate(const AcMeshInfo info, AcMesh* mesh) -{ - mesh->info = info; - - const size_t bytes = acVertexBufferSizeBytes(mesh->info); - for (int w = 0; w < NUM_VTXBUF_HANDLES; ++w) { - mesh->vertex_buffer[w] = malloc(bytes); - ERRCHK_ALWAYS(mesh->vertex_buffer[w]); - } - - return AC_SUCCESS; -} - -AcResult -acMeshDestroy(AcMesh* mesh) -{ - for (int w = 0; w < NUM_VTXBUF_HANDLES; ++w) - free(mesh->vertex_buffer[w]); - - return AC_SUCCESS; -} - AcResult acMeshSet(const AcReal value, AcMesh* mesh) {