commit 0c21df7c893092976311dd4dc8f7e88c2cf8b374
parent 5d935b2c33cecb379338404920dce1a6ff993e68
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Fri, 30 Apr 2021 10:55:55 +0200
Allow to define the use of SIMD at runtime
Diffstat:
5 files changed, 61 insertions(+), 31 deletions(-)
diff --git a/src/atrstm.c b/src/atrstm.c
@@ -165,7 +165,7 @@ atrstm_create
atrstm = MEM_CALLOC(allocator, 1, sizeof(*atrstm));
if(!atrstm) {
if(args->verbose) {
- #define ERR_STR "Could not allocate the AtrGM data structure.\n"
+ #define ERR_STR "Could not allocate the AtrSTM data structure.\n"
if(logger) {
logger_print(logger, LOG_ERROR, ERR_STR);
} else {
@@ -196,6 +196,17 @@ atrstm_create
setup_log_default(atrstm);
}
+ if(args->use_simd) {
+ #ifdef ATRSTM_USE_SIMD
+ atrstm->use_simd = 1;
+ #else
+ log_warn(atrstm,
+ "Cannot use the SIMD instruction set: "
+ "AtrSTM was compiled without SIMD support.\n");
+ atrstm->use_simd = 0;
+ #endif
+ }
+
if(args->spectral_type == ATRSTM_SPECTRAL_SW
&& args->wlen_range[0] != args->wlen_range[1]) {
log_err(atrstm,
diff --git a/src/atrstm.h b/src/atrstm.h
@@ -112,6 +112,7 @@ struct atrstm_args {
double optical_thickness; /* Threshold used during octree building */
int precompute_normals; /* Pre-compute the tetrahedra normals */
+ int use_simd; /* Enable the use of the SIMD instruction set if available */
unsigned nthreads; /* Hint on the number of threads to use */
int verbose; /* Verbosity level */
@@ -138,6 +139,7 @@ struct atrstm_args {
1, /* Optical thickness */ \
\
0, /* Precompute tetrahedra normals */ \
+ 1, /* Use SIMD */ \
\
(unsigned)~0, /* #threads */ \
0 /* Verbosity level */ \
@@ -330,7 +332,7 @@ atrstm_at
const double pos[3],
struct suvm_primitive* prim, /* Volumetric primitive */
double barycentric_coords[4]); /* `pos' in `prim' */
-
+
ATRSTM_API res_T
atrstm_fetch_radcoefs
(const struct atrstm* atrstm,
diff --git a/src/atrstm_c.h b/src/atrstm_c.h
@@ -64,6 +64,7 @@ struct atrstm {
struct logger* logger;
struct logger logger__; /* Default logger */
int verbose;
+ int use_simd;
ref_T ref;
};
diff --git a/src/atrstm_radcoefs.c b/src/atrstm_radcoefs.c
@@ -33,44 +33,48 @@
/*******************************************************************************
* Exported functions
******************************************************************************/
-#ifndef ATRSTM_USE_SIMD
res_T
atrstm_fetch_radcoefs
(const struct atrstm* atrstm,
const struct atrstm_fetch_radcoefs_args* args,
atrstm_radcoefs_T radcoefs)
{
- return fetch_radcoefs(atrstm, args, radcoefs);
-}
-
-#else /* ATRSTM_USE_SIMD */
-res_T
-atrstm_fetch_radcoefs
- (const struct atrstm* atrstm,
- const struct atrstm_fetch_radcoefs_args* args,
- atrstm_radcoefs_T radcoefs)
-{
- const res_T res = fetch_radcoefs_simd4(atrstm, args, radcoefs);
- if(res != RES_OK) goto error;
+ res_T res = RES_OK;
- #ifndef NDEBUG
+ #ifndef ATRSTM_USE_SIMD
{
- atrstm_radcoefs_T radcoefs_scalar;
- int i;
-
- ASSERT(fetch_radcoefs(atrstm, args, radcoefs_scalar) == RES_OK);
- FOR_EACH(i, 0, ATRSTM_RADCOEFS_COUNT__) {
- ASSERT(eq_eps(radcoefs[i], radcoefs_scalar[i], radcoefs[i]*1e-4));
+ ASSERT(atrstm->use_simd == 0);
+ res = fetch_radcoefs(atrstm, args, radcoefs);
+ if(res != RES_OK) goto error;
+ }
+ #else
+ {
+ if(!atrstm->use_simd) {
+ res = fetch_radcoefs(atrstm, args, radcoefs);
+ if(res != RES_OK) goto error;
+ } else {
+ res = fetch_radcoefs_simd4(atrstm, args, radcoefs);
+ if(res != RES_OK) goto error;
+ #ifndef NDEBUG
+ {
+ atrstm_radcoefs_T radcoefs_scalar;
+ int i;
+
+ ASSERT(fetch_radcoefs(atrstm, args, radcoefs_scalar) == RES_OK);
+ FOR_EACH(i, 0, ATRSTM_RADCOEFS_COUNT__) {
+ ASSERT(eq_eps(radcoefs[i], radcoefs_scalar[i], radcoefs[i]*1e-4));
+ }
+ }
+ #endif /* !NDEBUG */
}
}
- #endif
+ #endif /* ATRSTM_USE_SIMD */
exit:
return res;
error:
goto exit;
}
-#endif /* !ATRSTM_USE_SIMD */
/*******************************************************************************
* Local functions functions
diff --git a/src/atrstm_setup_octrees.c b/src/atrstm_setup_octrees.c
@@ -238,13 +238,25 @@ voxelize_partition
voxel_commit_radcoefs_range
(vox, ATRSTM_CPNT_GAS, &radcoefs_min, &radcoefs_max);
-#ifdef ATRSTM_USE_SIMD
- res = primitive_compute_radcoefs_range_simd4
- (atrstm, refract_id, &prim, &radcoefs_min, &radcoefs_max);
-#else
- res = primitive_compute_radcoefs_range
- (atrstm, refract_id, &prim, &radcoefs_min, &radcoefs_max);
-#endif
+ /* Compute the range of the radiative coefficient for the current
+ * primitive */
+ #ifndef ATRSTM_USE_SIMD
+ {
+ res = primitive_compute_radcoefs_range
+ (atrstm, refract_id, &prim, &radcoefs_min, &radcoefs_max);
+ ASSERT(atrstm->use_simd == 0);
+ }
+ #else
+ {
+ if(atrstm->use_simd) {
+ res = primitive_compute_radcoefs_range_simd4
+ (atrstm, refract_id, &prim, &radcoefs_min, &radcoefs_max);
+ } else {
+ res = primitive_compute_radcoefs_range
+ (atrstm, refract_id, &prim, &radcoefs_min, &radcoefs_max);
+ }
+ }
+ #endif
if(UNLIKELY(res != RES_OK)) goto error;
voxel_commit_radcoefs_range
(vox, ATRSTM_CPNT_SOOT, &radcoefs_min, &radcoefs_max);