diff --git a/Makefile b/Makefile index df99a25..76f3709 100644 --- a/Makefile +++ b/Makefile @@ -56,6 +56,10 @@ ifeq ($(strip $(USE_REFERENCE_VERSION)),true) DEFINES += -DUSE_REFERENCE_VERSION endif +ifeq ($(strip $(DEBUG)),true) + DEFINES += -DDEBUG +endif + ifneq ($(VECTOR_WIDTH),) DEFINES += -DVECTOR_WIDTH=$(VECTOR_WIDTH) endif diff --git a/config.mk b/config.mk index 2f16422..62206d8 100644 --- a/config.mk +++ b/config.mk @@ -10,6 +10,8 @@ DATA_TYPE ?= DP DATA_LAYOUT ?= AOS # Assembly syntax to generate (ATT/INTEL) ASM_SYNTAX ?= ATT +# Debug +DEBUG ?= false # Number of times to run the atoms loop on stubbed variant ATOMS_LOOP_RUNS ?= 1 @@ -30,7 +32,7 @@ COMPUTE_STATS ?= true # AOS or SOA CLUSTER_LAYOUT ?= SOA # Use reference version -USE_REFERENCE_VERSION ?= true +USE_REFERENCE_VERSION ?= false #Feature options OPTIONS = -DALIGNMENT=64 diff --git a/gromacs/force_lj.c b/gromacs/force_lj.c index b861019..166c280 100644 --- a/gromacs/force_lj.c +++ b/gromacs/force_lj.c @@ -186,10 +186,10 @@ double computeForceLJ_4xn(Parameter *param, Atom *atom, Neighbor *neighbor, Stat MD_SIMD_FLOAT dely3 = simd_sub(yi3_tmp, yj_tmp); MD_SIMD_FLOAT delz3 = simd_sub(zi3_tmp, zj_tmp); - MD_SIMD_MASK excl_mask0 = simd_mask_from_u32((unsigned int)(0xff - 0x80 * cond0 - 0x8 * cond1)); - MD_SIMD_MASK excl_mask1 = simd_mask_from_u32((unsigned int)(0xff - 0x40 * cond0 - 0x4 * cond1)); - MD_SIMD_MASK excl_mask2 = simd_mask_from_u32((unsigned int)(0xff - 0x20 * cond0 - 0x2 * cond1)); - MD_SIMD_MASK excl_mask3 = simd_mask_from_u32((unsigned int)(0xff - 0x10 * cond0 - 0x1 * cond1)); + MD_SIMD_MASK excl_mask0 = simd_mask_from_u32((unsigned int)(0xff - 0x1 * cond0 - 0x10 * cond1)); + MD_SIMD_MASK excl_mask1 = simd_mask_from_u32((unsigned int)(0xff - 0x2 * cond0 - 0x20 * cond1)); + MD_SIMD_MASK excl_mask2 = simd_mask_from_u32((unsigned int)(0xff - 0x4 * cond0 - 0x40 * cond1)); + MD_SIMD_MASK excl_mask3 = simd_mask_from_u32((unsigned int)(0xff - 0x8 * cond0 - 0x80 * cond1)); MD_SIMD_FLOAT rsq0 = simd_fma(delx0, delx0, simd_fma(dely0, dely0, simd_mul(delz0, delz0))); MD_SIMD_FLOAT rsq1 = simd_fma(delx1, delx1, simd_fma(dely1, dely1, simd_mul(delz1, delz1))); diff --git a/gromacs/includes/simd.h b/gromacs/includes/simd.h index 1c867df..d089188 100644 --- a/gromacs/includes/simd.h +++ b/gromacs/includes/simd.h @@ -21,11 +21,14 @@ * ======================================================================================= */ +#include #include #include -#define MD_SIMD_FLOAT __m512d -#define MD_SIMD_MASK __mmask8 +#define MD_SIMD_FLOAT __m512d +#define MD_SIMD_MASK __mmask8 +#define SIMD_PRINT_REAL(a) simd_print_real(#a, a); +#define SIMD_PRINT_MASK(a) simd_print_mask(#a, a); static inline MD_SIMD_FLOAT simd_broadcast(double scalar) { return _mm512_set1_pd(scalar); } static inline MD_SIMD_FLOAT simd_zero() { return _mm512_set1_pd(0.0); } @@ -35,7 +38,8 @@ static inline MD_SIMD_FLOAT simd_mul(MD_SIMD_FLOAT a, MD_SIMD_FLOAT b) { return static inline MD_SIMD_FLOAT simd_fma(MD_SIMD_FLOAT a, MD_SIMD_FLOAT b, MD_SIMD_FLOAT c) { return _mm512_fmadd_pd(a, b, c); } static inline MD_SIMD_FLOAT simd_reciprocal(MD_SIMD_FLOAT a) { return _mm512_rcp14_pd(a); } static inline MD_SIMD_FLOAT simd_masked_add(MD_SIMD_FLOAT a, MD_SIMD_FLOAT b, MD_SIMD_MASK m) { return _mm512_mask_add_pd(a, m, a, b); } -static inline MD_SIMD_MASK simd_mask_from_u32(unsigned int m) { return _cvtu32_mask8(m); } +static inline MD_SIMD_MASK simd_mask_from_u32(unsigned int a) { return _cvtu32_mask8(a); } +static inline MD_SIMD_MASK simd_mask_to_u32(unsigned int a) { return _cvtmask8_u32(a); } static inline MD_SIMD_MASK simd_mask_and(MD_SIMD_MASK a, MD_SIMD_MASK b) { return _kand_mask8(a, b); } static inline MD_SIMD_MASK simd_mask_cond_lt(MD_SIMD_FLOAT a, MD_SIMD_FLOAT b) { return _mm512_cmp_pd_mask(a, b, _CMP_LT_OQ); } @@ -59,3 +63,17 @@ static inline MD_FLOAT simd_horizontal_sum(MD_SIMD_FLOAT a) { x = _mm512_add_pd(x, _mm512_permute_pd(x, 0x01)); return *((double *) &x); } + +static inline void simd_print_real(const char *ref, MD_SIMD_FLOAT a) { + double x[8]; + memcpy(x, &a, sizeof(x)); + + fprintf(stdout, "%s: ", ref); + for(int i = 0; i < 8; i++) { + fprintf(stdout, "%f ", x[i]); + } + + fprintf(stdout, "\n"); +} + +static inline void simd_print_mask(const char *ref, MD_SIMD_MASK a) { fprintf(stdout, "%s: %x\n", ref, simd_mask_to_u32(a)); } diff --git a/gromacs/includes/util.h b/gromacs/includes/util.h index c777282..197f253 100644 --- a/gromacs/includes/util.h +++ b/gromacs/includes/util.h @@ -33,9 +33,9 @@ #define ABS(a) ((a) >= 0 ? (a) : -(a)) #endif #ifdef DEBUG -#define DEBUG_MESSAGE(msg) printf +#define DEBUG_MESSAGE printf #else -#define DEBUG_MESSAGE(msg) +#define DEBUG_MESSAGE #endif #define FF_LJ 0