commit 75602875eca5d21be91e216dffe572124f6068e4
parent 6310c772a495cb2d9af3c5c873f2c51d27d6009c
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Fri, 30 Apr 2021 18:52:49 +0200
Add the SIMD option to the htrd-combustion CLI
Diffstat:
5 files changed, 55 insertions(+), 10 deletions(-)
diff --git a/src/combustion/htrdr_combustion.c b/src/combustion/htrdr_combustion.c
@@ -103,6 +103,38 @@ error:
}
static res_T
+setup_simd
+ (struct htrdr_combustion* cmd,
+ const struct htrdr_combustion_args* args)
+{
+ ASSERT(cmd && args);
+
+ if(!args->use_simd) {
+ cmd->rdgfa_simd = SSF_SIMD_NONE;
+ } else {
+ struct ssf_info ssf_info = SSF_INFO_NULL;
+
+ /* Check SIMD support for the RDG-FA phase function */
+ ssf_get_info(&ssf_info);
+ if(ssf_info.simd_256) {
+ htrdr_log(cmd->htrdr,
+ "Use the SIMD-256 instruction set for the RDG-FA phase function.\n");
+ cmd->rdgfa_simd = SSF_SIMD_256;
+ } else if(ssf_info.simd_128) {
+ htrdr_log(cmd->htrdr,
+ "Use the SIMD-128 instruction set for the RDG-FA phase function.\n");
+ cmd->rdgfa_simd = SSF_SIMD_128;
+ } else {
+ htrdr_log_warn(cmd->htrdr,
+ "Cannot use SIMD for the RDG-FA phase function: the "
+ "Star-ScatteringFunction library was compiled without SIMD support.\n");
+ cmd->rdgfa_simd = SSF_SIMD_NONE;
+ }
+ }
+ return RES_OK;
+}
+
+static res_T
setup_geometry
(struct htrdr_combustion* cmd,
const struct htrdr_combustion_args* args)
@@ -264,6 +296,7 @@ setup_medium
atrstm_args.fractal_dimension = args->fractal_dimension;
atrstm_args.optical_thickness = args->optical_thickness;
atrstm_args.precompute_normals = args->precompute_normals;
+ atrstm_args.use_simd = args->use_simd;
atrstm_args.nthreads = args->nthreads;
atrstm_args.verbose = args->verbose;
@@ -472,6 +505,8 @@ htrdr_combustion_create
res = setup_output(cmd, args);
if(res != RES_OK) goto error;
+ res = setup_simd(cmd, args);
+ if(res != RES_OK) goto error;
res = setup_geometry(cmd, args);
if(res != RES_OK) goto error;
res = setup_camera(cmd, args);
diff --git a/src/combustion/htrdr_combustion_args.c b/src/combustion/htrdr_combustion_args.c
@@ -43,8 +43,8 @@ print_help(const char* cmd)
" man page for the list of camera options.\n");
printf(
" -D FLUX_DENSITY\n"
-" flux density of the laser in W/m^2. By default the\n"
-" flux density is %g W/m^2.\n",
+" flux density of the laser in W/m^2\n"
+" (default: %g W/m^2).\n",
HTRDR_COMBUSTION_ARGS_DEFAULT.laser_flux_density);
printf(
" -d <octrees|laser>\n"
@@ -54,9 +54,9 @@ print_help(const char* cmd)
" -F <fractal-coefs>\n"
" value of the fractal prefactor and fractal dimension\n"
" to use in the RDG-FA model. Refer to the man page\n"
-" for the syntax of the <fractal-coefs> option. Default\n"
-" fractal prefactor is %g and the default fractal\n"
-" dimension is %g.\n",
+" for the syntax of the <fractal-coefs> option\n"
+" (default fractal prefactor = %g;\n"
+" default fractal dimension = %g).\n",
HTRDR_COMBUSTION_ARGS_DEFAULT.fractal_prefactor,
HTRDR_COMBUSTION_ARGS_DEFAULT.fractal_dimension);
printf(
@@ -80,16 +80,18 @@ print_help(const char* cmd)
" -O CACHE path of the cache file used to store/restore the\n"
" volumetric data. By default do not use any cache.\n");
printf(
-" -o OUTPUT file where data are written. If not defined, data are\n"
-" written to standard output.\n");
+" -o OUTPUT file where data are written\n"
+" (default: write data to standard output).\n");
printf(
" -p THERMOPROPS path toward the thermodynamic properties.\n");
printf(
" -r REFRACT_ID path toward the per wavelength refractive\n"
" indices.\n");
printf(
+" -s use of the SIMD instruction set if available.\n");
+ printf(
" -T THRESHOLD optical thickness used as threshold during the octree\n"
-" building. By default its value is %g.\n",
+" building. (default: %g).\n",
HTRDR_COMBUSTION_ARGS_DEFAULT.optical_thickness);
printf(
" -t NTHREADS hint on the number of threads to use. By default use\n"
@@ -104,7 +106,7 @@ print_help(const char* cmd)
" -v make the command verbose.\n");
printf(
" -w WAVELENGTH wavelength definition of the laser in nanometer.\n"
-" By default its value is %g.\n",
+" (default: %g).\n",
HTRDR_COMBUSTION_ARGS_DEFAULT.wavelength);
printf("\n");
@@ -237,7 +239,7 @@ htrdr_combustion_args_init
*args = HTRDR_COMBUSTION_ARGS_DEFAULT;
- while((opt = getopt(argc, argv, "C:D:d:F:fg:hi:l:m:NO:o:p:r:T:t:V:vw:")) != -1) {
+ while((opt = getopt(argc, argv, "C:D:d:F:fg:hi:l:m:NO:o:p:r:sT:t:V:vw:")) != -1) {
switch(opt) {
case 'C':
res = htrdr_args_camera_parse(&args->camera, optarg);
@@ -273,6 +275,7 @@ htrdr_combustion_args_init
case 'o': args->path_output = optarg; break;
case 'p': args->path_therm_props = optarg; break;
case 'r': args->path_refract_ids = optarg; break;
+ case 's': args->use_simd = 1; break;
case 'T':
res = cstr_to_double(optarg, &args->optical_thickness);
if(res == RES_OK && args->optical_thickness < 0) res = RES_BAD_ARG;
diff --git a/src/combustion/htrdr_combustion_args.h b/src/combustion/htrdr_combustion_args.h
@@ -83,6 +83,7 @@ struct htrdr_combustion_args {
int precompute_normals; /* Pre-compute the tetrahedra normals */
int force_overwriting;
int verbose; /* Verbosity level */
+ int use_simd; /* Use the SIMD instruction set if available */
int quit; /* Stop the command */
};
@@ -116,6 +117,7 @@ struct htrdr_combustion_args {
0, /* Precompute normals */ \
0, /* Force overwriting */ \
0, /* Verbose flag */ \
+ 0, /* Use SIMD */ \
0 /* Stop the command */ \
}
static const struct htrdr_combustion_args HTRDR_COMBUSTION_ARGS_DEFAULT =
diff --git a/src/combustion/htrdr_combustion_c.h b/src/combustion/htrdr_combustion_c.h
@@ -24,6 +24,8 @@
#include "core/htrdr_args.h"
#include "core/htrdr_buffer.h"
+#include <star/ssf.h>
+
#include <rsys/ref_count.h>
#include <rsys/str.h>
@@ -60,6 +62,7 @@ struct htrdr_combustion {
struct ssf_phase** rdgfa_phase_functions; /* Per thread RDG-FA phase func */
struct ssf_phase** hg_phase_functions; /* Per thread Henyey-Greenstein func */
+ enum ssf_simd rdgfa_simd; /* SIMD support for the RDG-FA phase func */
struct htrdr_buffer_layout buf_layout;
struct htrdr_buffer* buf; /* NULL on non master processes */
diff --git a/src/combustion/htrdr_combustion_compute_radiance_sw.c b/src/combustion/htrdr_combustion_compute_radiance_sw.c
@@ -658,6 +658,7 @@ laser_once_scattered
setup_rdgfa_args.wavelength = rdgfa_param.wavelength;
setup_rdgfa_args.fractal_dimension = rdgfa_param.fractal_dimension;
setup_rdgfa_args.gyration_radius = rdgfa_param.gyration_radius;
+ setup_rdgfa_args.simd = cmd->rdgfa_simd;
SSF(phase_rdgfa_setup(phase, &setup_rdgfa_args));
/* Evaluate the phase function at the scattering position */
@@ -712,6 +713,7 @@ sample_scattering_direction
setup_rdgfa_args.wavelength = rdgfa_param.wavelength;
setup_rdgfa_args.fractal_dimension = rdgfa_param.fractal_dimension;
setup_rdgfa_args.gyration_radius = rdgfa_param.gyration_radius;
+ setup_rdgfa_args.simd = cmd->rdgfa_simd;
SSF(phase_rdgfa_setup(phase, &setup_rdgfa_args));
/* Sample a new optical path direction from the phase function */