aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile.am9
-rw-r--r--Makefile.in38
-rw-r--r--src/diffraction-gpu.c35
-rw-r--r--tests/.gitignore1
-rw-r--r--tests/gpu_sim_check.c147
5 files changed, 210 insertions, 20 deletions
diff --git a/Makefile.am b/Makefile.am
index 8719496a..aceeba44 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -7,7 +7,7 @@ bin_PROGRAMS = src/pattern_sim src/process_hkl src/get_hkl src/indexamajig \
src/calibrate_detector src/partialator src/reintegrate \
src/estimate_background src/check_hkl src/sum_stack
-noinst_PROGRAMS = tests/list_check
+noinst_PROGRAMS = tests/list_check tests/gpu_sim_check
TESTS = tests/list_check
@@ -30,6 +30,7 @@ src_pattern_sim_SOURCES = src/pattern_sim.c src/diffraction.c src/utils.c \
src/symmetry.c src/thread-pool.c src/reflist.c
if HAVE_OPENCL
src_pattern_sim_SOURCES += src/diffraction-gpu.c src/cl-utils.c
+TESTS += tests/gpu_sim_check
endif
src_process_hkl_SOURCES = src/process_hkl.c src/sfac.c src/statistics.c \
@@ -109,6 +110,12 @@ src_estimate_background_SOURCES = src/estimate_background.c src/stream.c \
tests_list_check_SOURCES = tests/list_check.c src/reflist.c src/thread-pool.c \
src/utils.c
+tests_gpu_sim_check_SOURCES = tests/gpu_sim_check.c src/utils.c \
+ src/diffraction.c src/diffraction-gpu.c \
+ src/thread-pool.c src/cell.c src/cl-utils.c \
+ src/symmetry.c src/detector.c src/hdf5-file.c \
+ src/image.c
+
INCLUDES = "-I$(top_srcdir)/data"
EXTRA_DIST += src/cell.h src/hdf5-file.h src/image.h src/utils.h \
diff --git a/Makefile.in b/Makefile.in
index 50e4837c..339de1fd 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -42,12 +42,14 @@ bin_PROGRAMS = src/pattern_sim$(EXEEXT) src/process_hkl$(EXEEXT) \
src/partialator$(EXEEXT) src/reintegrate$(EXEEXT) \
src/estimate_background$(EXEEXT) src/check_hkl$(EXEEXT) \
src/sum_stack$(EXEEXT) $(am__EXEEXT_1) $(am__EXEEXT_2)
-noinst_PROGRAMS = tests/list_check$(EXEEXT)
-TESTS = tests/list_check$(EXEEXT)
+noinst_PROGRAMS = tests/list_check$(EXEEXT) \
+ tests/gpu_sim_check$(EXEEXT)
+TESTS = tests/list_check$(EXEEXT) $(am__EXEEXT_3)
@HAVE_GTK_TRUE@am__append_1 = src/hdfsee
@HAVE_CAIRO_TRUE@am__append_2 = src/cubeit
@HAVE_OPENCL_TRUE@am__append_3 = src/diffraction-gpu.c src/cl-utils.c
-@HAVE_OPENCL_TRUE@am__append_4 = src/diffraction-gpu.c src/cl-utils.c
+@HAVE_OPENCL_TRUE@am__append_4 = tests/gpu_sim_check
+@HAVE_OPENCL_TRUE@am__append_5 = src/diffraction-gpu.c src/cl-utils.c
subdir = .
DIST_COMMON = README $(am__configure_deps) $(srcdir)/Makefile.am \
$(srcdir)/Makefile.in $(srcdir)/config.h.in \
@@ -229,6 +231,15 @@ am_src_sum_stack_OBJECTS = src/sum_stack.$(OBJEXT) src/utils.$(OBJEXT) \
src_sum_stack_OBJECTS = $(am_src_sum_stack_OBJECTS)
src_sum_stack_LDADD = $(LDADD)
src_sum_stack_DEPENDENCIES = $(top_builddir)/lib/libgnu.a
+am_tests_gpu_sim_check_OBJECTS = tests/gpu_sim_check.$(OBJEXT) \
+ src/utils.$(OBJEXT) src/diffraction.$(OBJEXT) \
+ src/diffraction-gpu.$(OBJEXT) src/thread-pool.$(OBJEXT) \
+ src/cell.$(OBJEXT) src/cl-utils.$(OBJEXT) \
+ src/symmetry.$(OBJEXT) src/detector.$(OBJEXT) \
+ src/hdf5-file.$(OBJEXT) src/image.$(OBJEXT)
+tests_gpu_sim_check_OBJECTS = $(am_tests_gpu_sim_check_OBJECTS)
+tests_gpu_sim_check_LDADD = $(LDADD)
+tests_gpu_sim_check_DEPENDENCIES = $(top_builddir)/lib/libgnu.a
am_tests_list_check_OBJECTS = tests/list_check.$(OBJEXT) \
src/reflist.$(OBJEXT) src/thread-pool.$(OBJEXT) \
src/utils.$(OBJEXT)
@@ -262,7 +273,8 @@ SOURCES = $(src_calibrate_detector_SOURCES) $(src_check_hkl_SOURCES) \
$(src_partialator_SOURCES) $(src_pattern_sim_SOURCES) \
$(src_powder_plot_SOURCES) $(src_process_hkl_SOURCES) \
$(src_reintegrate_SOURCES) $(src_render_hkl_SOURCES) \
- $(src_sum_stack_SOURCES) $(tests_list_check_SOURCES)
+ $(src_sum_stack_SOURCES) $(tests_gpu_sim_check_SOURCES) \
+ $(tests_list_check_SOURCES)
DIST_SOURCES = $(src_calibrate_detector_SOURCES) \
$(src_check_hkl_SOURCES) $(src_compare_hkl_SOURCES) \
$(am__src_cubeit_SOURCES_DIST) \
@@ -272,7 +284,7 @@ DIST_SOURCES = $(src_calibrate_detector_SOURCES) \
$(am__src_pattern_sim_SOURCES_DIST) $(src_powder_plot_SOURCES) \
$(src_process_hkl_SOURCES) $(src_reintegrate_SOURCES) \
$(src_render_hkl_SOURCES) $(src_sum_stack_SOURCES) \
- $(tests_list_check_SOURCES)
+ $(tests_gpu_sim_check_SOURCES) $(tests_list_check_SOURCES)
RECURSIVE_TARGETS = all-recursive check-recursive dvi-recursive \
html-recursive info-recursive install-data-recursive \
install-dvi-recursive install-exec-recursive \
@@ -311,6 +323,7 @@ ETAGS = etags
CTAGS = ctags
am__tty_colors = \
red=; grn=; lgn=; blu=; std=
+@HAVE_OPENCL_TRUE@am__EXEEXT_3 = tests/gpu_sim_check$(EXEEXT)
DIST_SUBDIRS = $(SUBDIRS)
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
distdir = $(PACKAGE)-$(VERSION)
@@ -596,7 +609,7 @@ src_indexamajig_SOURCES = src/indexamajig.c src/hdf5-file.c \
src/filters.c src/diffraction.c src/detector.c src/sfac.c \
src/dirax.c src/mosflm.c src/reflections.c src/symmetry.c \
src/geometry.c src/thread-pool.c src/beam-parameters.c \
- src/reflist.c $(am__append_4)
+ src/reflist.c $(am__append_5)
@HAVE_GTK_TRUE@src_hdfsee_SOURCES = src/hdfsee.c src/dw-hdfsee.c src/render.c \
@HAVE_GTK_TRUE@ src/hdf5-file.c src/utils.c src/image.c src/filters.c \
@HAVE_GTK_TRUE@ src/thread-pool.c src/detector.c
@@ -653,6 +666,12 @@ src_estimate_background_SOURCES = src/estimate_background.c src/stream.c \
tests_list_check_SOURCES = tests/list_check.c src/reflist.c src/thread-pool.c \
src/utils.c
+tests_gpu_sim_check_SOURCES = tests/gpu_sim_check.c src/utils.c \
+ src/diffraction.c src/diffraction-gpu.c \
+ src/thread-pool.c src/cell.c src/cl-utils.c \
+ src/symmetry.c src/detector.c src/hdf5-file.c \
+ src/image.c
+
INCLUDES = "-I$(top_srcdir)/data"
crystfeldir = $(datadir)/crystfel
crystfel_DATA = data/diffraction.cl data/defs.h data/sfac/Ca.nff \
@@ -915,6 +934,11 @@ tests/$(am__dirstamp):
tests/$(DEPDIR)/$(am__dirstamp):
@$(MKDIR_P) tests/$(DEPDIR)
@: > tests/$(DEPDIR)/$(am__dirstamp)
+tests/gpu_sim_check.$(OBJEXT): tests/$(am__dirstamp) \
+ tests/$(DEPDIR)/$(am__dirstamp)
+tests/gpu_sim_check$(EXEEXT): $(tests_gpu_sim_check_OBJECTS) $(tests_gpu_sim_check_DEPENDENCIES) tests/$(am__dirstamp)
+ @rm -f tests/gpu_sim_check$(EXEEXT)
+ $(AM_V_CCLD)$(LINK) $(tests_gpu_sim_check_OBJECTS) $(tests_gpu_sim_check_LDADD) $(LIBS)
tests/list_check.$(OBJEXT): tests/$(am__dirstamp) \
tests/$(DEPDIR)/$(am__dirstamp)
tests/list_check$(EXEEXT): $(tests_list_check_OBJECTS) $(tests_list_check_DEPENDENCIES) tests/$(am__dirstamp)
@@ -965,6 +989,7 @@ mostlyclean-compile:
-rm -f src/symmetry.$(OBJEXT)
-rm -f src/thread-pool.$(OBJEXT)
-rm -f src/utils.$(OBJEXT)
+ -rm -f tests/gpu_sim_check.$(OBJEXT)
-rm -f tests/list_check.$(OBJEXT)
distclean-compile:
@@ -1012,6 +1037,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/symmetry.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/thread-pool.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/utils.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@tests/$(DEPDIR)/gpu_sim_check.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@tests/$(DEPDIR)/list_check.Po@am__quote@
.c.o:
diff --git a/src/diffraction-gpu.c b/src/diffraction-gpu.c
index 59f19809..74eca439 100644
--- a/src/diffraction-gpu.c
+++ b/src/diffraction-gpu.c
@@ -416,20 +416,29 @@ struct gpu_context *setup_gpu(int no_sfac,
}
free(intensities_ptr);
- if ( strcmp(sym, "1") == 0 ) {
- strncat(cflags, "-DPG1 ", 511-strlen(cflags));
- } else if ( strcmp(sym, "-1") == 0 ) {
- strncat(cflags, "-DPG1BAR ", 511-strlen(cflags));
- } else if ( strcmp(sym, "6/mmm") == 0 ) {
- strncat(cflags, "-DPG6MMM ", 511-strlen(cflags));
- } else if ( strcmp(sym, "6") == 0 ) {
- strncat(cflags, "-DPG6 ", 511-strlen(cflags));
- } else if ( strcmp(sym, "6/m") == 0 ) {
- strncat(cflags, "-DPG6M ", 511-strlen(cflags));
+ if ( sym != NULL ) {
+ if ( strcmp(sym, "1") == 0 ) {
+ strncat(cflags, "-DPG1 ", 511-strlen(cflags));
+ } else if ( strcmp(sym, "-1") == 0 ) {
+ strncat(cflags, "-DPG1BAR ", 511-strlen(cflags));
+ } else if ( strcmp(sym, "6/mmm") == 0 ) {
+ strncat(cflags, "-DPG6MMM ", 511-strlen(cflags));
+ } else if ( strcmp(sym, "6") == 0 ) {
+ strncat(cflags, "-DPG6 ", 511-strlen(cflags));
+ } else if ( strcmp(sym, "6/m") == 0 ) {
+ strncat(cflags, "-DPG6M ", 511-strlen(cflags));
+ } else {
+ ERROR("Sorry! Point group '%s' is not currently"
+ " supported on the GPU."
+ " I'm using '1' instead.\n", sym);
+ strncat(cflags, "-DPG1 ", 511-strlen(cflags));
+ }
} else {
- ERROR("Sorry! Point group '%s' is not currently supported"
- " on the GPU. I'm using '1' instead.\n", sym);
- strncat(cflags, "-DPG1 ", 511-strlen(cflags));
+ if ( intensities != NULL ) {
+ ERROR("You gave me an intensities file but no point"
+ " group. I'm assuming '1'.\n");
+ strncat(cflags, "-DPG1 ", 511-strlen(cflags));
+ }
}
/* Create a flag array */
diff --git a/tests/.gitignore b/tests/.gitignore
index 3c726461..b855d2bd 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -1,4 +1,5 @@
*.o
.deps
list_check
+gpu_sim_check
.dirstamp
diff --git a/tests/gpu_sim_check.c b/tests/gpu_sim_check.c
new file mode 100644
index 00000000..28e85bcc
--- /dev/null
+++ b/tests/gpu_sim_check.c
@@ -0,0 +1,147 @@
+/*
+ * gpu_sim_check.c
+ *
+ * Check that GPU simulation agrees with CPU version
+ *
+ * (c) 2011 Thomas White <taw@physics.org>
+ *
+ * Part of CrystFEL - crystallography with a FEL
+ *
+ */
+
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "../src/diffraction.h"
+#include "../src/diffraction-gpu.h"
+#include "../src/detector.h"
+#include "../src/beam-parameters.h"
+#include "../src/utils.h"
+
+
+int main(int argc, char *argv[])
+{
+ struct gpu_context *gctx;
+ struct image gpu_image;
+ struct image cpu_image;
+ UnitCell *cell;
+ UnitCell *cell_raw;
+ struct detector *det;
+ struct beam_params *beam;
+ int i;
+ double gpu_min, gpu_max, gpu_tot;
+ double cpu_min, cpu_max, cpu_tot;
+ double dev, perc;
+ const double sep = 20.0;
+
+ gctx = setup_gpu(1, NULL, NULL, NULL, 0);
+ if ( gctx == NULL ) {
+ ERROR("Couldn't set up GPU.\n");
+ return 1;
+ }
+
+ cell_raw = cell_new_from_parameters(28.1e-9, 28.1e-9, 16.5e-9,
+ deg2rad(90.0), deg2rad(90.0), deg2rad(120.0));
+
+ cell = cell_rotate(cell_raw, random_quaternion());
+
+ gpu_image.width = 1024;
+ gpu_image.height = 1024;
+ cpu_image.width = 1024;
+ cpu_image.height = 1024;
+ det = calloc(1, sizeof(struct detector));
+ det->n_panels = 2;
+ det->panels = calloc(2, sizeof(struct panel));
+
+ det->panels[0].min_fs = 0;
+ det->panels[0].max_fs = 1023;
+ det->panels[0].min_ss = 0;
+ det->panels[0].max_ss = 511;
+ det->panels[0].fsx = 1;
+ det->panels[0].fsy = 0;
+ det->panels[0].ssx = 0;
+ det->panels[0].ssy = 1;
+ det->panels[0].xfs = 1;
+ det->panels[0].yfs = 0;
+ det->panels[0].xss = 0;
+ det->panels[0].yss = 1;
+ 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[1].min_fs = 0;
+ det->panels[1].max_fs = 1023;
+ det->panels[1].min_ss = 512;
+ det->panels[1].max_ss = 1023;
+ det->panels[1].fsx = 1;
+ det->panels[1].fsy = 0;
+ det->panels[1].ssx = 0;
+ det->panels[1].ssy = 1;
+ det->panels[1].xfs = 1;
+ det->panels[1].yfs = 0;
+ det->panels[1].xss = 0;
+ det->panels[1].yss = 1;
+ det->panels[1].cnx = -512.0;
+ det->panels[1].cny = sep;
+ det->panels[1].clen = 100.0e-3;
+ det->panels[1].res = 9090.91;
+
+ cpu_image.det = det;
+ gpu_image.det = det;
+
+ beam = calloc(1, sizeof(struct beam_params));
+ beam->fluence = 1.0e15;
+ beam->beam_radius = 1.0e-6;
+ beam->photon_energy = 9000.0;
+ beam->bandwidth = 0.1 / 100.0;
+ beam->divergence = 0.0;
+ beam->dqe = 1.0;
+ beam->adu_per_photon = 1.0;
+ cpu_image.beam = beam;
+ gpu_image.beam = beam;
+
+ cpu_image.lambda = ph_en_to_lambda(eV_to_J(beam->photon_energy));
+ gpu_image.lambda = ph_en_to_lambda(eV_to_J(beam->photon_energy));
+
+ get_diffraction_gpu(gctx, &gpu_image, 8, 8, 8, cell);
+ get_diffraction(&cpu_image, 8, 8, 8, NULL, NULL, NULL, cell,
+ GRADIENT_MOSAIC, "1");
+
+ 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<1024*1024; i++ ) {
+
+ const double cpu = cpu_image.data[i];
+ const double gpu = gpu_image.data[i];
+
+ if ( cpu > cpu_max ) cpu_max = cpu;
+ if ( cpu < cpu_min ) cpu_min = cpu;
+ if ( gpu > gpu_max ) gpu_max = gpu;
+ if ( gpu < gpu_min ) gpu_min = gpu;
+ gpu_tot += gpu;
+ cpu_tot += cpu;
+ dev += fabs(gpu - cpu);
+
+ }
+ perc = 100.0*dev/cpu_tot;
+
+ STATUS("GPU: min=%8e, max=%8e, total=%8e\n", gpu_min, gpu_max, gpu_tot);
+ STATUS("CPU: min=%8e, max=%8e, total=%8e\n", cpu_min, cpu_max, cpu_tot);
+ STATUS("dev = %8e (%5.2f%% of CPU total)\n", dev, perc);
+
+ cell_free(cell);
+ free_detector_geometry(det);
+ free(beam);
+
+ if ( perc > 1.0 ) return 1;
+
+ return 0;
+}