rnatm

Load and structure data describing an atmosphere
git clone git://git.meso-star.fr/rnatm.git
Log | Files | Refs | README | LICENSE

commit 35a63aebb3f389190e5eb0ad574b4f1737a6e23c
parent e8c8103518187338164104fe5712a99e948a1b33
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Mon, 22 Aug 2022 15:08:13 +0200

Updating the memory layout of a partition

Diffstat:
Msrc/rnatm_octree.c | 4++--
Msrc/rnatm_voxel.h | 2+-
Msrc/rnatm_voxel_partition.c | 36++++++++++++++++++++++++++++--------
Msrc/rnatm_voxel_partition.h | 9++++++---
4 files changed, 37 insertions(+), 14 deletions(-)

diff --git a/src/rnatm_octree.c b/src/rnatm_octree.c @@ -414,7 +414,7 @@ update_voxel ASSERT(atm && radcoefs && part); (void)atm; - vx = partition_get_voxel(part, vx_mcode); + vx = partition_get_voxel(part, vx_mcode, 0/*TODO handle batch_size > 1*/); /* Update the range of the radiative coefficients of the voxel */ vx_ka_min = vx[voxel_idata(RNATM_RADCOEF_Ka, RNATM_SVX_OP_MIN)]; @@ -845,7 +845,7 @@ vx_get(const size_t xyz[3], const uint64_t mcode, void* dst, void* context) } } - vx = partition_cget_voxel(ctx->part, ivx); + vx = partition_cget_voxel(ctx->part, ivx, 0/*TODO handle batch_size > 1*/); memcpy(dst, vx, NFLOATS_PER_VOXEL * sizeof(float)); } diff --git a/src/rnatm_voxel.h b/src/rnatm_voxel.h @@ -27,7 +27,7 @@ * Memory layout of a voxel * ------------------------ * - * The data of a voxel is stored in a list of N single-precision floating-point + * The data of a voxel are stored in a list of N single-precision floating-point * numbers, with N defined as below: * * N = RNATM_RADCOEFS_COUNT__ * RNATM_SVX_OPS_COUNT__ diff --git a/src/rnatm_voxel_partition.c b/src/rnatm_voxel_partition.c @@ -27,7 +27,12 @@ #include <rsys/mutex.h> #include <rsys/ref_count.h> -struct tile { +/* A tile stores N*M voxels where N is the number of voxels and M is the voxel + * width as defined when creating the pool. This width makes it possible to + * store in the same tile the radiative coefficients of a voxel for several + * spectral data. For each voxel, the tile actually stores M voxels stored one + * after the other */ + struct tile { struct list_node node; float voxels[1]; /* Flexible array member */ }; @@ -62,6 +67,7 @@ struct pool { size_t next_part_id; /* Indentifier of the next partition */ size_t partition_definition; /* #voxels along the 3 axis */ size_t partition_nvoxels; /* Overall number of voxels in a partition */ + size_t voxel_width; /* Number of items per voxel data */ struct mem_allocator* allocator; ATOMIC error; /* Is the pool not valid? */ @@ -76,6 +82,7 @@ check_pool_create_args(const struct pool_create_args* args) { if(!args || !args->npartitions + || !args->voxel_width || args->npartitions < args->npreallocated_partitions || !IS_POW2(args->partition_definition)) { return RES_BAD_ARG; @@ -308,20 +315,29 @@ partition_get_definition(const struct partition* partition) } float* -partition_get_voxel(struct partition* part, const size_t ivoxel) +partition_get_voxel + (struct partition* part, + const size_t ivoxel, + const size_t iitem) { ASSERT(part && ivoxel < part->pool->partition_nvoxels && part->tile != NULL); - return part->tile->voxels + (ivoxel*NFLOATS_PER_VOXEL); + ASSERT(iitem < part->pool->voxel_width); + return part->tile->voxels + + NFLOATS_PER_VOXEL*(ivoxel*part->pool->voxel_width + iitem); } const float* -partition_cget_voxel(struct partition* part, const size_t ivoxel) +partition_cget_voxel + (struct partition* part, + const size_t ivoxel, + const size_t iitem) { ASSERT(part && ivoxel < part->pool->partition_nvoxels); + ASSERT(iitem < part->pool->voxel_width); if(part->tile == NULL) { return part->pool->empty_voxel; } else { - return part->tile->voxels + (ivoxel*NFLOATS_PER_VOXEL); + return partition_get_voxel(part, ivoxel, iitem); } } @@ -334,8 +350,11 @@ partition_clear_voxels(struct partition* partition) if(partition->tile == NULL) return; /* Nothing to do */ FOR_EACH(ivoxel, 0, partition->pool->partition_nvoxels) { - float* voxel = partition_get_voxel(partition, ivoxel); - voxel_clear(voxel); + size_t iitem = 0; + FOR_EACH(iitem, 0, partition->pool->voxel_width) { + float* voxel = partition_get_voxel(partition, ivoxel, iitem); + voxel_clear(voxel); + } } } @@ -364,6 +383,7 @@ pool_create } pool->allocator = allocator; pool->partition_definition = args->partition_definition; + pool->voxel_width = args->voxel_width; pool->partition_nvoxels = pool->partition_definition * pool->partition_definition @@ -393,7 +413,7 @@ pool_create tile_sz = sizeof(struct tile) - sizeof(float)/*Dummy member*/ - + sizeof(float[NFLOATS_PER_VOXEL]) * nvoxels; + + sizeof(float[NFLOATS_PER_VOXEL]) * nvoxels * pool->voxel_width; tile_sz = ALIGN_SIZE(tile_sz, ALIGNOF(struct tile)); pool->tiles = MEM_CALLOC(allocator, args->npreallocated_partitions, tile_sz); if(!pool->tiles) { res = RES_MEM_ERR; goto error; } diff --git a/src/rnatm_voxel_partition.h b/src/rnatm_voxel_partition.h @@ -30,13 +30,14 @@ struct pool_create_args { size_t partition_definition; /* #voxels along XYZ. Must be a power of 2 */ size_t npartitions; /* Overall number of partitions managed by the pool */ + size_t voxel_width; /* Number of items for each voxel data */ /* Number of pre-allocated partitions must be <= npartitions */ size_t npreallocated_partitions; struct mem_allocator* allocator; /* NULL <=> default allocator */ }; -#define POOL_CREATE_ARGS_DEFAULT__ {0, 32, 32, NULL} +#define POOL_CREATE_ARGS_DEFAULT__ {0, 32, 1, 32, NULL} static const struct pool_create_args POOL_CREATE_ARGS_DEFAULT = POOL_CREATE_ARGS_DEFAULT__; @@ -72,14 +73,16 @@ partition_empty extern LOCAL_SYM float* partition_get_voxel (struct partition* partition, - const size_t ivoxel); + const size_t ivoxel, + const size_t iitem); /* Returns a voxel even if the partition is empty. In the latter case, it * always returns an empty voxel */ extern LOCAL_SYM const float* partition_cget_voxel (struct partition* partition, - const size_t ivoxel); + const size_t ivoxel, + const size_t iitem); extern LOCAL_SYM void partition_clear_voxels