Commit 8173daf7 authored by Martin Albrecht's avatar Martin Albrecht

starting M4RIE library for linear algebra over GF(2^n) for small n.

parents
# use glob syntax.
syntax: glob
Makefile.in
aclocal.m4
config.guess
config.sub
configure
depcomp
install-sh
ltmain.sh
m4/libtool.m4
m4/ltoptions.m4
m4/ltsugar.m4
m4/ltversion.m4
m4/lt~obsolete.m4
missing
src/config.h.in~
(END)
This diff is collapsed.
This diff is collapsed.
AUTOMAKE_OPTIONS = gnu
AM_CFLAGS=${SIMD_FLAGS} ${OPENMP_CFLAGS} ${DEBUG_FLAGS}
lib_LTLIBRARIES = libm4rie.la
libm4rie_la_SOURCES = src/finite_field.c src/gf2e_matrix.c src/travolta.c
pkgincludesubdir = $(includedir)/m4rie
pkgincludesub_HEADERS = src/finite_field.h src/gf2e_matrix.h src/m4rie.h src/m4ri_functions.h src/travolta.h
libm4rie_la_LDFLAGS = -release 0.0.19780616
check_PROGRAMS=test_elimination
test_elimination_SOURCES=tests/test_elimination.cc
test_elimination_LDFLAGS= -lm4rie -lm4ri -lgivaro -lntl -lgmpxx -lgmp -lm -lstdc++
TESTS = test_elimination
BENCH_PRGS=bench_elimination
CPUCYCLES_DIR=./cpucycles-20060326
cpucycles.h: cpucycles.o
cpucycles.o:
(cd $(CPUCYCLES_DIR); sh do; cp cpucycles.o ..; cp cpucycles.h ..; cd ..)
bench_elimination: cpucycles.o bench_elimination.cc
g++ -O2 -DNDEBUG -I$(SAGE_ROOT)/local/include -L/$(SAGE_ROOT)/local/lib -I../ -lm4rie -lm4ri -lgivaro -lntl -lgmpxx -lgmp -lm -lstdc++ cpucycles.o bench_elimination.cc -o $@
clean:
rm -f $(BENCH_PRGS)
rm -f *.o cpucycles.h
rm -f $(CPUCYCLES_DIR)/cpucycles.o
rm -f $(CPUCYCLES_DIR)/cpucycles.h
all: $(BENCH_PRGS)
#include <gf2e_cxx/finite_field_givaro.h>
#include <m4rie/m4rie.h>
#include "cpucycles.h"
#include "walltime.h"
using namespace M4RIE;
int main(int argc, char **argv) {
double wt = 0.0;
size_t r;
if (argc < 4)
m4ri_die("syntax: e m n alg");
int k = atoi(argv[1]);
int m = atoi(argv[2]);
int n = atoi(argv[3]);
char *algorithm = argv[4];
FiniteField *F = (FiniteField*)(new GFqDom<int>(2,k));
gf2e *ff = gf2e_init_givgfq(F);
mzed_t *A = mzed_init(ff,m,n);
mzed_randomize(A);
mzed_echelonize_travolta(A,1);
wt = walltime(&wt);
unsigned long long t = cpucycles();
if(strcmp(algorithm,"travolta")==0)
r= mzed_echelonize_travolta(A, 1);
else if(strcmp(algorithm,"naive")==0)
r = mzed_echelonize_naive(A, 1);
printf("m: %5d, n: %5d, r: %5d, cpu cycles: %llu wall time: %lf\n",m, n, r, cpucycles() - t, walltime(&wt));
mzed_free(A);
gf2e_free(ff);
delete F;
}
/*
cpucycles/alpha.c version 20060316
D. J. Bernstein
Public domain.
*/
#include <time.h>
#include <unistd.h>
#include <sys/time.h>
static long long tod(void)
{
struct timeval t;
gettimeofday(&t,(struct timezone *) 0);
return t.tv_sec * (long long) 1000000 + t.tv_usec;
}
static long long rpcc(void)
{
unsigned long long t;
asm volatile("rpcc %0" : "=r"(t));
return t & 0xffffffff;
}
static long long firstrpcc;
static long long firsttod;
static long long lastrpcc;
static long long lasttod;
static double mhz = 0;
static void init(void)
{
firstrpcc = rpcc();
firsttod = tod();
do {
lastrpcc = rpcc();
lasttod = tod();
} while (lasttod - firsttod < 10000);
lastrpcc -= firstrpcc; lastrpcc &= 0xffffffff;
lasttod -= firsttod;
mhz = (double) lastrpcc / (double) lasttod;
}
long long cpucycles_alpha(void)
{
double x;
long long y;
if (!mhz) init();
lastrpcc = rpcc();
lasttod = tod();
lastrpcc -= firstrpcc; lastrpcc &= 0xffffffff;
lasttod -= firsttod;
/* Number of cycles since firstrpcc is lastrpcc + 2^32 y for unknown y. */
/* Number of microseconds since firsttod is lasttod. */
x = (lasttod * mhz - lastrpcc) * 0.00000000023283064365386962890625;
y = x;
while (x > y + 0.5) y += 1;
while (x < y - 0.5) y -= 1;
y *= 4294967296ULL;
lastrpcc += y;
mhz = (double) lastrpcc / (double) lasttod;
return firstrpcc + lastrpcc;
}
long long cpucycles_alpha_persecond(void)
{
if (!mhz) init();
return 1000000.0 * mhz;
}
/*
cpucycles alpha.h version 20060318
D. J. Bernstein
Public domain.
*/
#ifndef CPUCYCLES_alpha_h
#define CPUCYCLES_alpha_h
#ifdef __cplusplus
extern "C" {
#endif
extern long long cpucycles_alpha(void);
extern long long cpucycles_alpha_persecond(void);
#ifdef __cplusplus
}
#endif
#ifndef cpucycles_implementation
#define cpucycles_implementation "alpha"
#define cpucycles cpucycles_alpha
#define cpucycles_persecond cpucycles_alpha_persecond
#endif
#endif
#include <stdio.h>
#include <sys/types.h>
long long cpucycles_amd64cpuinfo(void)
{
unsigned long long result;
asm volatile(".byte 15;.byte 49;shlq $32,%%rdx;orq %%rdx,%%rax"
: "=a" (result) :: "%rdx");
return result;
}
long long cpucycles_amd64cpuinfo_persecond(void)
{
FILE *f;
double result;
int s;
f = fopen("/proc/cpuinfo","r");
if (!f) return 0;
for (;;) {
s = fscanf(f,"cpu MHz : %lf",&result);
if (s > 0) break;
if (s == 0) s = fscanf(f,"%*[^\n]\n");
if (s < 0) { result = 0; break; }
}
fclose(f);
return 1000000.0 * result;
}
/*
cpucycles amd64cpuinfo.h version 20060318
D. J. Bernstein
Public domain.
*/
#ifndef CPUCYCLES_amd64cpuinfo_h
#define CPUCYCLES_amd64cpuinfo_h
#ifdef __cplusplus
extern "C" {
#endif
extern long long cpucycles_amd64cpuinfo(void);
extern long long cpucycles_amd64cpuinfo_persecond(void);
#ifdef __cplusplus
}
#endif
#ifndef cpucycles_implementation
#define cpucycles_implementation "amd64cpuinfo"
#define cpucycles cpucycles_amd64cpuinfo
#define cpucycles_persecond cpucycles_amd64cpuinfo_persecond
#endif
#endif
#include <stdio.h>
#include <sys/types.h>
long long cpucycles_amd64tscfreq(void)
{
unsigned long long result;
asm volatile(".byte 15;.byte 49;shlq $32,%%rdx;orq %%rdx,%%rax"
: "=a" (result) :: "%rdx");
return result;
}
long long cpucycles_amd64tscfreq_persecond(void)
{
long result = 0;
size_t resultlen = sizeof(long);
sysctlbyname("machdep.tsc_freq",&result,&resultlen,0,0);
return result;
}
/*
cpucycles amd64tscfreq.h version 20060318
D. J. Bernstein
Public domain.
*/
#ifndef CPUCYCLES_amd64tscfreq_h
#define CPUCYCLES_amd64tscfreq_h
#ifdef __cplusplus
extern "C" {
#endif
extern long long cpucycles_amd64tscfreq(void);
extern long long cpucycles_amd64tscfreq_persecond(void);
#ifdef __cplusplus
}
#endif
#ifndef cpucycles_implementation
#define cpucycles_implementation "amd64tscfreq"
#define cpucycles cpucycles_amd64tscfreq
#define cpucycles_persecond cpucycles_amd64tscfreq_persecond
#endif
#endif
#include <time.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/sysctl.h>
static double cpufrequency = 0;
static void init(void)
{
long result = 0; size_t resultlen = sizeof(long);
sysctlbyname("machdep.tsc_freq",&result,&resultlen,0,0);
cpufrequency = result;
}
long long cpucycles_clockmonotonic(void)
{
double result;
struct timespec t;
if (!cpufrequency) init();
clock_gettime(CLOCK_MONOTONIC,&t);
result = t.tv_nsec;
result *= 0.000000001;
result += (double) t.tv_sec;
result *= cpufrequency;
return result;
}
long long cpucycles_clockmonotonic_persecond(void)
{
if (!cpufrequency) init();
return cpufrequency;
}
/*
cpucycles clockmonotonic.h version 20060318
D. J. Bernstein
Public domain.
*/
#ifndef CPUCYCLES_clockmonotonic_h
#define CPUCYCLES_clockmonotonic_h
#ifdef __cplusplus
extern "C" {
#endif
extern long long cpucycles_clockmonotonic(void);
extern long long cpucycles_clockmonotonic_persecond(void);
#ifdef __cplusplus
}
#endif
#ifndef cpucycles_implementation
#define cpucycles_implementation "clockmonotonic"
#define cpucycles cpucycles_clockmonotonic
#define cpucycles_persecond cpucycles_clockmonotonic_persecond
#endif
#endif
#!/bin/sh
case "$COMPILER" in
suncc)
case "$ARCHITECTURE" in
64) /opt/SUNWspro/bin/cc -xarch=v9 -O2 "$@" ;;
32) /opt/SUNWspro/bin/cc -xarch=v8 -O2 "$@" ;;
*) /opt/SUNWspro/bin/cc -O2 "$@" ;;
esac
;;
ibmcc)
case "$ARCHITECTURE" in
64) xlc -q64 -O2 "$@" ;;
32) xlc -q32 -O2 "$@" ;;
*) xlc -O2 "$@" ;;
esac
;;
hpcc)
case "$ARCHITECTURE" in
64) /opt/ansic/bin/cc +DD64 -O2 "$@" ;;
32) /opt/ansic/bin/cc +DD32 -O2 "$@" ;;
*) /opt/ansic/bin/cc -O2 "$@" ;;
esac
;;
*)
case "$ARCHITECTURE" in
64) gcc -m64 -O2 "$@" ;;
32) gcc -m32 -O2 "$@" ;;
*) gcc -O2 "$@" ;;
esac
;;
esac
This diff is collapsed.
#!/bin/sh
output="cpucycles.o cpucycles.h"
cleanup="test cpucycles-impl.o cpucycles-impl.h cpucycles-impl.c"
exec 2>do.notes
rm -f $output $cleanup
(
echo amd64tscfreq gcc
echo amd64cpuinfo gcc
echo x86tscfreq gcc
echo x86cpuinfo gcc
echo powerpclinux gcc
echo powerpcmacos gcc
echo powerpcaix gcc
echo powerpcaix ibmcc
echo sparcpsrinfo gcc
echo sparcpsrinfo suncc
echo sparc32psrinfo gcc
echo sparc32psrinfo suncc
echo hppapstat gcc
echo hppapstat hpcc
echo alpha gcc
echo clockmonotonic gcc
echo gettimeofday gcc
) | (
while read name compiler
do
echo ===== Trying $name.c with $compiler... >&2
rm -f $cleanup
cp $name.c cpucycles-impl.c || continue
cp $name.h cpucycles-impl.h || continue
env COMPILER=$compiler ./compile -c cpucycles-impl.c || continue
env COMPILER=$compiler ./compile -o test test.c cpucycles-impl.o || continue
./test || continue
echo ===== Success. Using $name.c. >&2
mv cpucycles-impl.o cpucycles.o
mv cpucycles-impl.h cpucycles.h
rm -f $cleanup
exit 0
done
echo ===== Giving up. >&2
rm -f $output $cleanup
exit 111
)
===== Trying amd64tscfreq.c with gcc...
cpucycles-impl.o: In function `cpucycles_amd64tscfreq_persecond':
cpucycles-impl.c:(.text+0x3a): undefined reference to `sysctlbyname'
collect2: ld returned 1 exit status
===== Trying amd64cpuinfo.c with gcc...
===== Success. Using amd64cpuinfo.c.
#include <time.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/time.h>
static double cpufrequency = 0;
static void init(void)
{
FILE *f;
double result;
int s;
f = fopen("/proc/cpuinfo","r");
if (!f) return;
for (;;) {
s = fscanf(f,"cpu MHz : %lf",&result);
if (s > 0) break;
if (s == 0) s = fscanf(f,"%*[^\n]\n");
if (s < 0) { result = 0; break; }
}
fclose(f);
cpufrequency = 1000000.0 * result;
}
long long cpucycles_gettimeofday(void)
{
double result;
struct timeval t;
if (!cpufrequency) init();
gettimeofday(&t,(struct timezone *) 0);
result = t.tv_usec;
result *= 0.000001;
result += (double) t.tv_sec;
result *= cpufrequency;
return result;
}
long long cpucycles_gettimeofday_persecond(void)
{
if (!cpufrequency) init();
return cpufrequency;
}
/*
cpucycles gettimeofday.h version 20060318
D. J. Bernstein
Public domain.
*/
#ifndef CPUCYCLES_gettimeofday_h
#define CPUCYCLES_gettimeofday_h
#ifdef __cplusplus
extern "C" {
#endif
extern long long cpucycles_gettimeofday(void);
extern long long cpucycles_gettimeofday_persecond(void);
#ifdef __cplusplus
}
#endif
#ifndef cpucycles_implementation
#define cpucycles_implementation "gettimeofday"
#define cpucycles cpucycles_gettimeofday
#define cpucycles_persecond cpucycles_gettimeofday_persecond
#endif
#endif
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/param.h>
#include <sys/pstat.h>
#include <machine/inline.h>
long long cpucycles_hppapstat(void)
{
register long long result;
_MFCTL(16,result);
return result;
}
long long cpucycles_hppapstat_persecond(void)
{
struct pst_processor pst;
union pstun pu;
double result;
pu.pst_processor = &pst;
if (pstat(PSTAT_PROCESSOR,pu,sizeof(pst),1,0) < 0) return 0;
result = pst.psp_iticksperclktick;
result *= (double) sysconf(_SC_CLK_TCK);
return result;
}
/*
cpucycles hppapstat.h version 20060319
D. J. Bernstein
Public domain.
*/
#ifndef CPUCYCLES_hppapstat_h
#define CPUCYCLES_hppapstat_h
#ifdef __cplusplus
extern "C" {
#endif
extern long long cpucycles_hppapstat(void);
extern long long cpucycles_hppapstat_persecond(void);
#ifdef __cplusplus
}
#endif
#ifndef cpucycles_implementation
#define cpucycles_implementation "hppapstat"
#define cpucycles cpucycles_hppapstat
#define cpucycles_persecond cpucycles_hppapstat_persecond
#endif
#endif
#include <time.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/time.h>
#include <sys/types.h>
static long myround(double u)
{
long result = u;
while (result + 0.5 < u) result += 1;
while (result - 0.5 > u) result -= 1;
return result;
}
static long long microseconds(void)
{
struct timeval t;
gettimeofday(&t,(struct timezone *) 0);
return t.tv_sec * (long long) 1000000 + t.tv_usec;
}
static long long timebase(void)
{
unsigned long high;
unsigned long low;
unsigned long newhigh;
unsigned long long result;
asm volatile(
"Lcpucycles:mftbu %0;mftb %1;mftbu %2;cmpw %0,%2;bne Lcpucycles"
: "=r" (high), "=r" (low), "=r" (newhigh)
);
result = high;
result <<= 32;
result |= low;
return result;
}
static double cpufrequency = 0;
static long tbcycles = 0;
static void init(void)
{
FILE *f;
long long tb0; long long us0;
long long tb1; long long us1;
f = popen("/usr/sbin/lsattr -E -l proc0 -a frequency","r");
if (!f) return;
if (fscanf(f,"frequency %lf",&cpufrequency) < 1) cpufrequency = 0;
pclose(f);
if (!cpufrequency) return;
tb0 = timebase();
us0 = microseconds();
do {
tb1 = timebase();
us1 = microseconds();
} while (us1 - us0 < 10000);
if (tb1 <= tb0) return;
tb1 -= tb0;
us1 -= us0;
tbcycles = myround((cpufrequency * 0.000001 * (double) us1) / (double) tb1);
}
long long cpucycles_powerpcaix(void)
{
if (!tbcycles) init();
return timebase() * tbcycles;
}
long long cpucycles_powerpcaix_persecond(void)
{
if (!tbcycles) init();
return cpufrequency;
}
/*
cpucycles powerpcaix.h version 20060318
D. J. Bernstein
Public domain.
*/
#ifndef CPUCYCLES_powerpcaix_h
#define CPUCYCLES_powerpcaix_h
#ifdef __cplusplus
extern "C" {
#endif
extern long long cpucycles_powerpcaix(void);
extern long long cpucycles_powerpcaix_persecond(void);
#ifdef __cplusplus
}
#endif
#ifndef cpucycles_implementation
#define cpucycles_implementation "powerpcaix"
#define cpucycles cpucycles_powerpcaix
#define cpucycles_persecond cpucycles_powerpcaix_persecond
#endif
#endif
#include <time.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/time.h>
#include <sys/types.h>