aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--meson.build2
-rw-r--r--tests/CMakeLists.txt3
-rw-r--r--tests/gpu_sim_check.c115
-rw-r--r--tests/gpu_sim_check.geom28
-rw-r--r--tests/meson.build17
5 files changed, 73 insertions, 92 deletions
diff --git a/meson.build b/meson.build
index 46a1ed45..dcaa755b 100644
--- a/meson.build
+++ b/meson.build
@@ -235,6 +235,8 @@ endif
executable('pattern_sim', pattern_sim_sources,
dependencies : [mdep, libcrystfeldep, gsldep, hdf5dep, opencldep],
install : true)
+# For testing (see tests/meson.build)
+simulation_bits = files(['src/diffraction.c', 'src/diffraction-gpu.c', 'src/cl-utils.c'])
# ************************ Testing ************************
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 01abe3eb..373187c9 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -68,7 +68,8 @@ if (HAVE_OPENCL)
../src/diffraction-gpu.c ../src/cl-utils.c)
target_include_directories(gpu_sim_check PRIVATE ${COMMON_INCLUDES} ${OpenCL_INCLUDE_DIRS})
target_link_libraries(gpu_sim_check ${COMMON_LIBRARIES} ${OpenCL_LIBRARIES})
- add_test(gpu_sim_check gpu_sim_check)
+ add_test(NAME gpu_sim_check
+ COMMAND gpu_sim_check ${CMAKE_CURRENT_SOURCE_DIR}/gpu_sim_check.geom)
endif (HAVE_OPENCL)
add_executable(rational_check rational_check.c)
diff --git a/tests/gpu_sim_check.c b/tests/gpu_sim_check.c
index d8f85290..f0b3193e 100644
--- a/tests/gpu_sim_check.c
+++ b/tests/gpu_sim_check.c
@@ -35,11 +35,15 @@
#include <sys/time.h>
#endif
+#define CL_TARGET_OPENCL_VERSION 220
+
#include "../src/diffraction.h"
#include "../src/diffraction-gpu.h"
#include "../src/cl-utils.h"
-#include <detector.h>
+
+#include <datatemplate.h>
#include <utils.h>
+#include <image.h>
#include <symmetry.h>
#include <cell-utils.h>
@@ -71,16 +75,15 @@ static double get_hires_seconds()
int main(int argc, char *argv[])
{
struct gpu_context *gctx;
- struct image gpu_image;
- struct image cpu_image;
+ struct image *gpu_image;
+ struct image *cpu_image;
+ DataTemplate *dtempl;
UnitCell *cell;
UnitCell *cell_raw;
- struct detector *det;
int i;
double gpu_min, gpu_max, gpu_tot;
double cpu_min, cpu_max, cpu_tot;
double dev, perc;
- const double sep = 20.0;
double start, end;
double gpu_time, cpu_time;
SymOpList *sym;
@@ -104,73 +107,14 @@ int main(int argc, char *argv[])
cell = cell_rotate(cell_raw, random_quaternion(rng));
- det = calloc(1, sizeof(struct detector));
- det->n_panels = 2;
- det->panels = calloc(2, sizeof(struct panel));
-
- det->panels[0].orig_min_fs = 0;
- det->panels[0].orig_max_fs = 1023;
- det->panels[0].orig_min_ss = 0;
- det->panels[0].orig_max_ss = 511;
- det->panels[0].w = 1024;
- det->panels[0].h = 512;
- det->panels[0].fsx = 1.0;
- det->panels[0].fsy = 0.0;
- det->panels[0].fsz = 0.4;
- det->panels[0].ssx = 0.0;
- det->panels[0].ssy = 1.0;
- det->panels[0].ssz = 0.0;
- det->panels[0].xfs = 1.0;
- det->panels[0].yfs = 0.0;
- det->panels[0].xss = 0.0;
- det->panels[0].yss = 1.0;
- det->panels[0].cnx = -512.0;
- det->panels[0].cny = -512.0-sep;
- det->panels[0].clen = 100.0e-3;
- det->panels[0].res = 9090.91;
- det->panels[0].adu_per_eV = 1.0;
- det->panels[0].data = NULL;
-
- det->panels[1].orig_min_fs = 0;
- det->panels[1].orig_max_fs = 1023;
- det->panels[1].orig_min_ss = 512;
- det->panels[1].orig_max_ss = 1023;
- det->panels[1].w = 1024;
- det->panels[1].h = 512;
- det->panels[1].fsx = 1.0;
- det->panels[1].fsy = 0.0;
- det->panels[1].fsz = 0.0;
- det->panels[1].ssx = 0.0;
- det->panels[1].ssy = 1.0;
- det->panels[1].ssz = 1.4;
- det->panels[1].xfs = 1.0;
- det->panels[1].yfs = 0.0;
- det->panels[1].xss = 0.0;
- det->panels[1].yss = 1.0;
- det->panels[1].cnx = -512.0;
- det->panels[1].cny = sep;
- det->panels[1].clen = 100.0e-3;
- det->panels[1].res = 9090.91;
- det->panels[1].adu_per_eV = 1.0;
- det->panels[1].data = NULL;
-
- cpu_image.det = det;
- gpu_image.det = det;
- cpu_image.beam = NULL;
- gpu_image.beam = NULL;
-
- cpu_image.lambda = ph_en_to_lambda(eV_to_J(6000));
- gpu_image.lambda = ph_en_to_lambda(eV_to_J(6000));
- cpu_image.bw = 1.0 / 100.0;
- gpu_image.bw = 1.0 / 100.0;
-
- cpu_image.spectrum = spectrum_generate_tophat(cpu_image.lambda,
- cpu_image.bw);
- gpu_image.spectrum = spectrum_generate_tophat(gpu_image.lambda,
- gpu_image.bw);
+ dtempl = data_template_new_from_file(argv[1]);
+ if ( dtempl == NULL ) return 1;
+
+ cpu_image = image_create_for_simulation(dtempl);
+ gpu_image = image_create_for_simulation(dtempl);
start = get_hires_seconds();
- if ( get_diffraction_gpu(gctx, &gpu_image, 8, 8, 8, cell, 0, 0, 10) ) {
+ if ( get_diffraction_gpu(gctx, gpu_image, 8, 8, 8, cell, 0, 0, 10) ) {
return 1;
}
end = get_hires_seconds();
@@ -178,22 +122,22 @@ int main(int argc, char *argv[])
sym = get_pointgroup("1");
- cpu_image.dp = malloc(det->n_panels * sizeof(float *));
- if ( cpu_image.dp == NULL ) {
+ cpu_image->dp = malloc(cpu_image->detgeom->n_panels * sizeof(float *));
+ if ( cpu_image->dp == NULL ) {
ERROR("Couldn't allocate memory for result.\n");
return 1;
}
- for ( i=0; i<det->n_panels; i++ ) {
- struct panel *p = &det->panels[i];
- cpu_image.dp[i] = calloc(p->w * p->h, sizeof(float));
- if ( cpu_image.dp[i] == NULL ) {
+ for ( i=0; i<cpu_image->detgeom->n_panels; i++ ) {
+ struct detgeom_panel *p = &cpu_image->detgeom->panels[i];
+ cpu_image->dp[i] = calloc(p->w * p->h, sizeof(float));
+ if ( cpu_image->dp[i] == NULL ) {
ERROR("Couldn't allocate memory for panel %i\n", i);
return 1;
}
}
start = get_hires_seconds();
- get_diffraction(&cpu_image, 8, 8, 8, NULL, NULL, NULL, cell,
+ get_diffraction(cpu_image, 8, 8, 8, NULL, NULL, NULL, cell,
GRADIENT_MOSAIC, sym, 0, 0, 10);
end = get_hires_seconds();
cpu_time = end - start;
@@ -205,15 +149,15 @@ int main(int argc, char *argv[])
gpu_min = +INFINITY; gpu_max = -INFINITY; gpu_tot = 0.0;
cpu_min = +INFINITY; cpu_max = -INFINITY; cpu_tot = 0.0;
dev = 0.0;
- for ( i=0; i<det->n_panels; i++ ) {
+ for ( i=0; i<cpu_image->detgeom->n_panels; i++ ) {
int j;
- struct panel *p = &det->panels[i];
+ struct detgeom_panel *p = &cpu_image->detgeom->panels[i];
for ( j=0; j<p->w*p->h; j++ ) {
- const double cpu = cpu_image.dp[i][j];
- const double gpu = gpu_image.dp[i][j];
+ const double cpu = cpu_image->dp[i][j];
+ const double gpu = gpu_image->dp[i][j];
if ( cpu > cpu_max ) cpu_max = cpu;
if ( cpu < cpu_min ) cpu_min = cpu;
@@ -237,8 +181,8 @@ int main(int argc, char *argv[])
STATUS("Test failed! I'm writing cpu-sim.h5 and gpu-sim.h5"
" for you to inspect.\n");
- hdf5_write_image("cpu-sim.h5", &cpu_image, NULL);
- hdf5_write_image("gpu-sim.h5", &gpu_image, NULL);
+ image_write(cpu_image, dtempl, "cpu-sim.h5");
+ image_write(gpu_image, dtempl, "gpu-sim.h5");
return 1;
@@ -246,8 +190,9 @@ int main(int argc, char *argv[])
gsl_rng_free(rng);
cell_free(cell);
- free_detector_geometry(det);
-
+ image_free(cpu_image);
+ image_free(gpu_image);
+ data_template_free(dtempl);
return 0;
}
diff --git a/tests/gpu_sim_check.geom b/tests/gpu_sim_check.geom
new file mode 100644
index 00000000..0faa345d
--- /dev/null
+++ b/tests/gpu_sim_check.geom
@@ -0,0 +1,28 @@
+photon_energy = 6 keV
+bandwidth = 0.01
+
+panel0/min_fs = 0
+panel0/max_fs = 1023
+panel0/min_ss = 0
+panel0/max_ss = 511
+panel0/corner_x = -512.0
+panel0/corner_y = -532.0
+panel0/clen = 100 mm
+panel0/res = 9090.91
+panel0/adu_per_eV = 1
+panel0/data = /data/panel0
+panel0/fs = x
+panel0/ss = y
+
+panel1/min_fs = 0
+panel1/max_fs = 1023
+panel1/min_ss = 512
+panel1/max_ss = 1023
+panel1/corner_x = -512.0
+panel1/corner_y = 20.0
+panel1/clen = 100 mm
+panel1/res = 9090.91
+panel1/adu_per_eV = 1
+panel1/data = /data/panel1
+panel1/fs = x
+panel1/ss = y \ No newline at end of file
diff --git a/tests/meson.build b/tests/meson.build
index 7c06b74f..5b368f9b 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -44,14 +44,11 @@ simple_tests = ['ambi_check',
'evparse6',
'evparse7']
-
-if opencldep.found()
- simple_tests += 'gpu_sim_check'
-endif
-
foreach name : simple_tests
exe = executable(name, ''.join([name, '.c']),
- dependencies : [libcrystfeldep, mdep, gsldep, hdf5dep, opencldep])
+ dependencies : [libcrystfeldep, mdep, gsldep, hdf5dep],
+ include_directories: conf_inc)
+
test(name, exe, timeout : 60)
endforeach
@@ -69,6 +66,14 @@ exe = executable('prof2d_check',
dependencies : [libcrystfeldep, mdep, gsldep])
test('prof2d_check', exe)
+exe = executable('gpu_sim_check',
+ ['gpu_sim_check.c',
+ simulation_bits],
+ dependencies : [libcrystfeldep, mdep, gsldep, opencldep],
+ include_directories: conf_inc)
+geom = files('gpu_sim_check.geom')
+test('gpu_sim_check', exe, args: [geom])
+
# Event enumeration tests
ev_enum_tests = ['ev_enum1',