Permalink
Browse files

added binary OVA

  • Loading branch information...
1 parent b4628b6 commit 7c15d405ba67bce036aa00c490b17614db096153 Claudio A Andreoni committed Apr 19, 2012
Showing with 898 additions and 441 deletions.
  1. +61 −33 asgd/Makefile
  2. +6 −3 asgd/asgd.c
  3. +3 −3 asgd/asgd.h
  4. +1 −3 asgd/asgd_blas.h
  5. +183 −50 asgd/asgd_core.c
  6. +79 −32 asgd/asgd_core.h
  7. +192 −176 asgd/casgd.py
  8. +156 −40 asgd/simple_blas.c
  9. +33 −4 asgd/simple_blas.h
  10. +2 −2 asgd/tests/asgd_unit.c
  11. +182 −95 asgd/tests/simple_blas_unit.c
View
@@ -1,57 +1,85 @@
-# GCC
-CC = gcc
-#DEBUG = -g
-CFLAGS = -Wall -std=c99 -fPIC -O3 -march=nocona
+# ******* INSTRUCTIONS ******* #
+# ASGD can be compiled either against an external cBLAS library (provided by the installer),
+# or against a naive BLAS implementation (part of the ASGD distribution).
+#
+# make will default to the naive implementation.
+# To use an external BLAS library, please set:
+# TYPE = blas (for instance, call `make TYPE=blas`)
+# BLAS_INCDIRS = (dirs with cBLAS headers)
+# BLAS_LIBDIRS = (dirs with cBLAS libs)
+# BLAS_LIBS = (cBLAS lib files to link against)
+# BLAS_HEADER = (name of the cBLAS header file in brackets, e.g. <cblas.h>)
+#
+# Available make targets are:
+#
+# simple_blas_unit
+# Compiles a unit test for the naive BLAS implementation
+# The unit test will exit with status 0 if the test passes
-# ICC
-#CC = icc
-#CFLAGS = -Wall -std=c99 -fPIC -O2 -xhost -ipo -fno-fnalias
-# stock ATLAS
-INCDIR = -I/usr/include/
-LIBDIR = -L/usr/lib64/atlas
+# ******* COMPILATION SETTINGS ******* #
-# custom ATLAS
-#INCDIR = -I/home/cloud/projects/asgd/ATLASobj/include
-#LIBDIR = -L/home/cloud/projects/asgd/ATLASobj/lib
+# list of directories with headers
+INCDIRS =
-# MKL
-#INCDIR = -I/opt/intel/mkl/include
-#LIBDIR = -L/opt/intel/mkl/lib/intel64
+# list of directories with libraries
+LIBDIRS =
+
+# list of libraries to link against
+LIBS = -lm
+
+# list of object files to compile with
+OBJS =
-MATHLIB = -lm
-#MATHLIB =
+# list of macros to define for the compiler
+DEFS =
+
+# compiler
+CC = gcc
+# debug flags
+DEBUG = -g
+
+# compiler flags
+CFLAGS = -Wall -std=c99 -fPIC
+
+# MKL
+BLAS_INCDIRS = -I/opt/intel/mkl/include
+BLAS_LIBDIRS = -L/opt/intel/mkl/lib/intel64
+BLAS_LIBS = -lmkl_intel_lp64 -lmkl_intel_thread -lmkl_core -liomp5 -lmkl_mc3 -lmkl_def -lpthread -fopenmp
+# lmkl_mc3 and -lmkl_def are necessary because of a bug when loading .so from Python
+BLAS_HEADER = <mkl_cblas.h>
+
+# if TYPE=blas, link against external BLAS library
ifeq ($(TYPE),blas)
-LIBS = $(MATHLIB) -lcblas
-DEFS = -DASGD_BLAS
-OBJS =
+INCDIRS += $(BLAS_INCDIRS)
+LIBDIRS += $(BLAS_LIBDIRS)
+LIBS += $(BLAS_LIBS)
+DEFS += -DASGD_BLAS -DBLAS_HEADER='$(BLAS_HEADER)'
else
-LIBS = $(MATHLIB)
-DEFS =
-OBJS = simple_blas.o
+OBJS += simple_blas.o
endif
asgd_unit: asgd.o asgd_core.o simple_blas.o tests/asgd_unit.c
- $(CC) $(CFLAGS) $(DEBUG) $(INCDIR) $(LIBDIR) $(LIBS) $(DEFS) -o bin/asgd_unit $(OBJS) asgd.o asgd_core.o tests/asgd_unit.c
+ $(CC) $(CFLAGS) $(DEBUG) $(INCDIRS) $(LIBDIRS) $(LIBS) $(DEFS) -o bin/asgd_unit $(OBJS) asgd.o asgd_core.o tests/asgd_unit.c
asgd.o: simple_blas.o asgd_core.o asgd.c asgd.h
- $(CC) $(CFLAGS) $(DEBUG) $(INCDIR) $(LIBDIR) $(LIBS) $(DEFS) -c -o asgd.o asgd.c
+ $(CC) $(CFLAGS) $(DEBUG) $(INCDIRS) $(LIBDIRS) $(LIBS) $(DEFS) -c -o asgd.o $(OBJS) asgd.c
asgd_core.o: simple_blas.o asgd_core.c asgd_core.h
- $(CC) $(CFLAGS) $(DEBUG) $(INCDIR) $(LIBDIR) $(LIBS) $(DEFS) -c -o asgd_core.o asgd_core.c
- $(CC) -shared $(CFLAGS) $(DEBUG) $(INCDIR) $(LIBDIR) $(LIBS) $(DEFS) -o asgd_core.so $(OBJS) asgd_core.c
+ $(CC) $(CFLAGS) $(DEBUG) $(INCDIRS) $(LIBDIRS) $(LIBS) $(DEFS) -c -o asgd_core.o $(OBJS) asgd_core.c
+ $(CC) -shared $(CFLAGS) $(DEBUG) $(INCDIRS) $(LIBDIRS) $(LIBS) $(DEFS) -o asgd_core.so $(OBJS) asgd_core.c
-simple_blas_unit: simple_blas.c simple_blas.h tests/simple_blas_unit.c
- $(CC) $(CFLAGS) $(DEBUG) $(INCDIR) $(LIBDIR) $(LIBS) $(DEFS) -o bin/simple_blas_unit tests/simple_blas_unit.c
+simple_blas_unit: simple_blas.o tests/simple_blas_unit.c
+ $(CC) $(CFLAGS) $(DEBUG) $(INCDIRS) $(LIBDIRS) $(LIBS) $(DEFS) -o bin/simple_blas_unit $(OBJS) tests/simple_blas_unit.c
simple_blas.o: simple_blas.c simple_blas.h
- $(CC) $(CFLAGS) $(DEBUG) $(INCDIR) $(LIBDIR) $(LIBS) $(DEFS) -c -o simple_blas.o simple_blas.c
+ $(CC) $(CFLAGS) $(DEBUG) $(INCDIRS) $(LIBDIRS) $(LIBS) $(DEFS) -c -o simple_blas.o simple_blas.c
# clean up compilation byproducts
.PHONY: clean
clean:
rm -fR *.o
rm -fR *.so
- rm -f bin/asgd_unit
- rm -f bin/simple_blas_unit
+ rm -fR bin/*
+
View
@@ -151,9 +151,11 @@ void nb_asgd_destr(
void partial_fit(
nb_asgd_t *data,
matrix_t *X,
- matrix_t *y)
+ matrix_t *y,
+ size_t batch_size)
{
core_partial_fit(
+ batch_size,
&data->n_observs,
&data->sgd_step_size,
&data->asgd_step_size,
@@ -192,7 +194,8 @@ void fit(
nb_asgd_t *data,
matrix_t *X,
matrix_t *y,
- int *r)
+ int *r,
+ size_t batch_size)
{
mex_assert(X->rows > 1, "fit: X should be a matrix");
mex_assert(y->cols == 1, "fit: y should be a column vector");
@@ -203,7 +206,7 @@ void fit(
matrix_row_shuffle(Xb, r+i*Xb->rows);
matrix_t *yb = matrix_clone(y);
matrix_row_shuffle(yb, r+i*Xb->rows);
- partial_fit(data, Xb, yb);
+ partial_fit(data, Xb, yb, batch_size);
matrix_destr(Xb);
matrix_destr(yb);
View
@@ -57,7 +57,7 @@ struct nb_asgd
float asgd_step_size;
float asgd_step_size0;
- long n_observs;
+ unsigned long n_observs;
};
nb_asgd_t *nb_asgd_init(
@@ -70,9 +70,9 @@ nb_asgd_t *nb_asgd_init(
void nb_asgd_destr(
nb_asgd_t *data);
-void fit(nb_asgd_t *data, matrix_t *X, matrix_t *y, int *r);
+void fit(nb_asgd_t *data, matrix_t *X, matrix_t *y, int *r, size_t batch_size);
-void partial_fit(nb_asgd_t *data, matrix_t *X, matrix_t *y);
+void partial_fit(nb_asgd_t *data, matrix_t *X, matrix_t *y, size_t batch_size);
void decision_function(nb_asgd_t *data, matrix_t *X, matrix_t *r);
View
@@ -2,9 +2,7 @@
// determine which BLAS implementation to use
#if defined ASGD_BLAS
-#include <cblas.h>
-#elif defined ASGD_SSE
-#include "sse_blas.h"
+#include BLAS_HEADER
#else
#include "simple_blas.h"
#endif
Oops, something went wrong.

0 comments on commit 7c15d40

Please sign in to comment.