Skip to content

Commit

Permalink
Merge pull request #2 from sirzooro/optimizations
Browse files Browse the repository at this point in the history
Optimizations
  • Loading branch information
sirzooro authored Jan 13, 2019
2 parents 7d495ac + 0810bed commit 8767f30
Show file tree
Hide file tree
Showing 10 changed files with 548 additions and 104 deletions.
407 changes: 330 additions & 77 deletions alglib-3.14.0/src/linalg.cpp

Large diffs are not rendered by default.

74 changes: 48 additions & 26 deletions boinc_app/Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
CAMBALA = ../cambala
ALGLIB = ../../alglib
ALGLIB = ../alglib-3.14.0/src
BOINC_DIR = ../../boinc
BOINC_API_DIR = $(BOINC_DIR)/api
BOINC_LIB_DIR = $(BOINC_DIR)/lib
BOINC_ZIP_DIR = $(BOINC_DIR)/zip
FREETYPE_DIR = /usr/include/freetype2

CPP = g++
CPPFLAGS = -O3 \
-std=c++0x -static -Wall -W -Wshadow -Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings -fno-common \
-DAPP_GRAPHICS -D __STDC_LIMIT_MACROS -D __STDC_FORMAT_MACROS -D NDEBUG \
Expand All @@ -20,42 +19,65 @@ CPPFLAGS = -O3 \
-L /usr/X11R6/lib \
-L.

ifeq ($(MinGW32),1)
$(info ===== Compiling MinGW 32-bit app version =====)
CPP = i686-w64-mingw32-g++
else ifeq ($(MinGW64),1)
$(info ===== Compiling MinGW 64-bit app version =====)
CPP = x86_64-w64-mingw32-g++
else ifeq ($(M32),1)
$(info ===== Compiling 32-bit app version =====)
CPP = g++ -m32
else
CPP = g++
endif

ifeq ($(SSE2),1)
$(info ===== Compiling SSE2 app version =====)
CPPFLAGS += -msse2
else ifeq ($(SSE41),1)
$(info ===== Compiling SSE4.1 app version =====)
CPPFLAGS += -msse4.1
else ifeq ($(AVX),1)
$(info ===== Compiling AVX app version =====)
CPPFLAGS += -mavx -mtune=sandybridge
else ifeq ($(AVX2),1)
$(info ===== Compiling AVX2 app version =====)
CPPFLAGS += -mavx2 -mfma -mtune=haswell
else ifeq ($(AVX512),1)
$(info ===== Compiling AVX512 app version =====)
CPPFLAGS += -march=skylake-avx512
ifeq ($(MinGW64),1)
# MinGW needs workaround for "invalid register for .seh_savexmm" bug
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65782
CPPFLAGS += \
-ffixed-xmm16 -ffixed-xmm17 -ffixed-xmm18 -ffixed-xmm19 -ffixed-xmm20 -ffixed-xmm21 -ffixed-xmm22 -ffixed-xmm23 \
-ffixed-xmm24 -ffixed-xmm25 -ffixed-xmm26 -ffixed-xmm27 -ffixed-xmm28 -ffixed-xmm29 -ffixed-xmm30 -ffixed-xmm31
endif
endif

ifeq ($(NOWARN),1)
CPPFLAGS += -w
endif

release: cambala_boinc_app

libstdc++.a:
ln -s `g++ -print-file-name=libstdc++.a`

ttfont.cpp:
ln -s ../../api/ttfont.cpp .
ln -s `${CPP} -print-file-name=libstdc++.a`

clean: distclean

distclean:
/bin/rm -f $(PROGS) *.o libstdc++.a cambala_boinc_app
/bin/rm -f $(PROGS) *.o libstdc++.a cambala_boinc_app cambala_boinc_app.exe

cambala_boinc_app: cambala_boinc_app.o alglibinternal.o alglibmisc.o ap.o linalg.o specialfunctions.o sequential.o \
cambala_boinc_app: cambala_boinc_app.o all.o \
libstdc++.a $(BOINC_API_DIR)/libboinc_api.a $(BOINC_LIB_DIR)/libboinc.a
$(CPP) $(CPPFLAGS) cambala_boinc_app.o alglibinternal.o alglibmisc.o ap.o linalg.o specialfunctions.o sequential.o -o cambala_boinc_app \
$(CPP) $(CPPFLAGS) cambala_boinc_app.o all.o -o cambala_boinc_app \
libstdc++.a -pthread $(BOINC_API_DIR)/libboinc_api.a \
$(BOINC_LIB_DIR)/libboinc.a

specialfunctions.o: $(ALGLIB)/specialfunctions.cpp
${CPP} ${CPPFLAGS} $(ALGLIB)/specialfunctions.cpp -c

linalg.o: $(ALGLIB)/linalg.cpp
${CPP} ${CPPFLAGS} $(ALGLIB)/linalg.cpp -c

ap.o: $(ALGLIB)/ap.cpp
${CPP} ${CPPFLAGS} $(ALGLIB)/ap.cpp -c

alglibmisc.o: $(ALGLIB)/alglibmisc.cpp
${CPP} ${CPPFLAGS} $(ALGLIB)/alglibmisc.cpp -c

alglibinternal.o: $(ALGLIB)/alglibinternal.cpp
${CPP} ${CPPFLAGS} $(ALGLIB)/alglibinternal.cpp -c

sequential.o: $(CAMBALA)/sequential.cpp
${CPP} ${CPPFLAGS} $(CAMBALA)/sequential.cpp -c
all.o: all.cpp $(ALGLIB)/specialfunctions.cpp $(ALGLIB)/linalg.cpp $(ALGLIB)/ap.cpp $(ALGLIB)/alglibmisc.cpp $(ALGLIB)/alglibinternal.cpp $(CAMBALA)/sequential.cpp
${CPP} ${CPPFLAGS} all.cpp -c

cambala_boinc_app.o: cambala_boinc_app.cpp
${CPP} ${CPPFLAGS} cambala_boinc_app.cpp -c
13 changes: 13 additions & 0 deletions boinc_app/all.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"

#include <ap.cpp>
#include <alglibinternal.cpp>
#include <specialfunctions.cpp>
#include <alglibmisc.cpp>
#include <linalg.cpp>

#pragma GCC diagnostic pop

#include <sequential.cpp>
119 changes: 118 additions & 1 deletion boinc_app/cambala_boinc_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,125 @@
#include "utils.h"
#include "point.h"

#if defined(__i386__) || defined (__x86_64__)
#include <cpuid.h>
#endif

#define CHECKPOINT_FILE "chpt"
#define INPUT_FILENAME "in"
#define OUTPUT_FILENAME "out"

__attribute__((noreturn))
void PrintFatalError(const char* str)
{
// print error to unredirected stderr first
fprintf(stderr, "Error: %s", str);

// now try to send it back to server
int retval = boinc_init();
if (0 == retval)
{
fprintf(stderr, "Error: %s", str);
boinc_finish(1);
}

exit(1);
}

void VerifyCpu()
{
#if (defined(__i386__) || defined (__x86_64__)) && defined(__SSE2__)
unsigned int a, b, c, d;

if (!__get_cpuid(1, &a, &b, &c, &d))
{
PrintFatalError("CPUID instruction is not supported by your CPU!\n");
}

if (0 == (d & bit_SSE2))
{
PrintFatalError("SSE2 instructions are not supported by your CPU!\n");
}

#ifdef __SSE4_1__
if (0 == (c & bit_SSE4_1))
{
PrintFatalError("SSE4.1 instructions are not supported by your CPU!\n");
}
#endif

#ifdef __AVX__
if (0 == (c & bit_AVX))
{
PrintFatalError("AVX instructions are not supported by your CPU!\n");
}

// AVX also needs OS support, check for it
if (0 == (c & bit_OSXSAVE))
{
PrintFatalError("OSXSAVE instructions are not supported by your CPU!\n");
}

unsigned int eax, edx;
unsigned int ecx = 0; // _XCR_XFEATURE_ENABLED_MASK
__asm__ ("xgetbv" : "=a" (eax), "=d" (edx) : "c" (ecx));
if (0x6 != (eax & 0x6)) // XSTATE_SSE | XSTATE_YMM
{
PrintFatalError("AVX instructions are not supported by your OS!\n");
}
#endif

#ifdef __AVX2__
if (__get_cpuid_max(0, 0) < 7)
{
PrintFatalError("CPUID level 7 is not supported by your CPU!\n");
}

unsigned int a2, b2, c2, d2;
__cpuid_count(7, 0, a2, b2, c2, d2);

if (0 == (b2 & bit_AVX2))
{
PrintFatalError("AVX2 instructions are not supported by your CPU!\n");
}
#endif

#ifdef __FMA__
// Some AMD CPUs(s) support FMA but no AVX2. FMA does not provide significat
// boost for this app, so it should be enabled on AVX2 CPUs only.
#ifndef __AVX2__
#error AVX2 is not enabled!
#endif
if (0 == (c & bit_FMA))
{
PrintFatalError("FMA instructions are not supported by your CPU!\n");
}
#endif

#ifdef __AVX512F__
// AVX512 consists of few subsets. Skylake-AVX512 target supports F, BW, DQ, VL and CD.
// We need data loaded during AVX and AVX2 checks, make sure we have it
#if !defined(__AVX__) || !defined(__AVX2__)
#error AVX or AVX2 is not enabled!
#endif

const unsigned int avx512bits = bit_AVX512F | bit_AVX512DQ | bit_AVX512CD | bit_AVX512BW | bit_AVX512VL;

if (avx512bits != (b2 & avx512bits))
{
PrintFatalError("AVX512 instructions are not supported by your CPU!\n");
}

// AVX512 also needs OS support, check for it
if (0xe6 != (eax & 0xe6)) // XSTATE_SSE | XSTATE_YMM | XSTATE_OPMASK | XSTATE_ZMM | XSTATE_HI_ZMM
{
PrintFatalError("AVX512 instructions are not supported by your OS!\n");
}
#endif

#endif
}

using namespace std;
char buf[256];

Expand All @@ -46,14 +161,16 @@ int do_checkpoint( const long long &total_points,

int main(int argc, char **argv)
{
VerifyCpu();

int retval = boinc_init();
if ( retval ) {
fprintf(stderr, "%s APP: boinc_init() returned %d\n",
boinc_msg_prefix(buf, sizeof(buf)), retval
);
exit( retval );
}

search_space_point cur_record_point;
cur_record_point.residual = START_HUGE_VALUE;

Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions boinc_app/test/cambala_depths_out.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
23 33 50 300
26 changes: 26 additions & 0 deletions boinc_app/test/cambala_out.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Input parameters :
launch_type bruteforce
object_function_type uniform
ppm 2
init_iterated_local_search_runs 10
cw1_init_arr :
1506 1490 1460
cw2_init_arr :
1506 1490 1480
ncpl_init_arr :
1 1 11
nR 1
R1 7000
R2 7000
ntau 1
tau1 0
tau2 0
nrhob 1
rhob1 1.7
rhob2 1.7
ncb 1
cb1 1700
cb2 1700
dtimes_file ac_modes_R7km_dtimes1.txt
spmag_file no
launch_type bruteforce
File renamed without changes.
1 change: 1 addition & 0 deletions boinc_app/test/out.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.003945 1700 1.7 7000 0 1506 1490 1462 23 33 50 300
11 changes: 11 additions & 0 deletions boinc_app/test/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/bash

rm -f boinc_finish_called cambala_depths_out cambala_out chpt out stderr.txt

time ../cambala_boinc_app

echo

#diff -qs cambala_depths_out cambala_depths_out.ref
#diff -qs cambala_out cambala_out.ref
diff -qs out out.ref

0 comments on commit 8767f30

Please sign in to comment.