Skip to content

Commit a475be0

Browse files
authored
Use L-BFGS-B Fortran library for native logistic regression benchmark (#8)
This PR swaps out the native logistic regression benchmark's solver for the same one used in SciPy. L-BFGS-B is wrapped in a minimal DAAL optimization_solver class and directly set as the solver for DAAL's logistic regression. This brings native performance for this benchmark to match our optimized scikit-learn performance for a sample binary classification problem with 100k samples and 1k features. Because we must now directly call BLAS and LAPACK functions instead of using DAAL's internal BLAS and LAPACK implementations, we add a dependency on MKL as well.
1 parent 01690a4 commit a475be0

File tree

12 files changed

+4562
-16
lines changed

12 files changed

+4562
-16
lines changed

LICENSES_bundled

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
scikit-learn_bench bundles parts of the compatibly-licensed libraries
2+
listed below.
3+
4+
Name: CLI11
5+
Files: native/include/CLI11.hpp
6+
License: BSD license
7+
For details, see https://github.com/CLIUtils/CLI11
8+
9+
Name: L-BFGS-B
10+
Files: native/lbfgsb/*.f
11+
License: BSD license
12+
For details, see scipy/optimize/lbfgsb/README
13+
14+
Name: scipy
15+
Files: native/lbfgsb/linpack.f
16+
License: 3-clause BSD
17+
For details, see scipy/optimize/lbfgsb/README

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Python*. See benchmark results [here](https://intelpython.github.io/scikit-learn
55

66
## Prerequisites
77
- python and scikit-learn to run python versions
8-
- `icc` and `daal` to compile and run native benchmarks
8+
- `icc`, `ifort`, `mkl`, `daal` to compile and run native benchmarks
99

1010
## Automatically build and run
1111
- Run `make`. This will generate data, compile benchmarks, and run them.

native/Makefile

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55
BENCHMARKS += distances kmeans linear ridge pca \
66
two_class_svm multi_class_svm log_reg_lbfgs \
77
decision_forest_regr decision_forest_clsf
8+
FOBJ = $(addprefix lbfgsb/,lbfgsb.o linpack.o timer.o)
89
CXXSRCS = $(addsuffix _bench.cpp,$(BENCHMARKS))
910

1011
CXX = icc
1112
CXXFLAGS += -m64 -fPIC -fp-model strict -O3 -fomit-frame-pointer \
1213
-xSSE4.2 -axCORE-AVX2,COMMON-AVX512
1314
CXXFLAGS += -std=c++14 -g
14-
LDFLAGS += -ldaal_core -ldaal_thread -Wl,-rpath,$(CONDA_PREFIX)/lib
15+
LDFLAGS += -ltbb -lstdc++ -lpthread -lm -ldaal_core -ldaal_thread \
16+
-Wl,-rpath,$(CONDA_PREFIX)/lib
1517
CXXINCLUDE += include
1618

1719
ifneq ($(CONDA_PREFIX),)
@@ -26,10 +28,19 @@ all: $(addprefix bin/,$(BENCHMARKS))
2628
bin:
2729
mkdir -p bin
2830

31+
bin/log_reg_lbfgs: log_reg_lbfgs_bench.cpp $(FOBJ) | bin
32+
$(CXX) $^ $(CXXINCLUDE) $(CXXFLAGS) $(LDFLAGS) -mkl=parallel \
33+
-lmkl_rt -lifcore -limf -o $@
34+
35+
2936
bin/%: %_bench.cpp | bin
3037
$(CXX) $< $(CXXINCLUDE) $(CXXFLAGS) $(LDFLAGS) -o $@
3138

3239

40+
$(FOBJ):
41+
make -C lbfgsb
42+
43+
3344
clean:
3445
rm -rf bin/
3546

native/lbfgsb/Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FC = ifort
2+
FFLAGS = -g -O3 -m64 -fPIC -fp-model strict -xSSE4.2 -fomit-frame-pointer \
3+
-axCORE-AVX2,COMMON-AVX512 -mkl
4+
FSRC = lbfgsb.f linpack.f timer.f
5+
6+
all: $(FSRC:.f=.o)
7+
8+
%.o: %.f
9+
$(FC) $(FFLAGS) -c $< -o $@
10+

native/lbfgsb/README

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
L-BFGS-B
2+
========
3+
4+
This directory contains version 3.0 of L-BFGS-B in Fortran, available
5+
at http://users.iems.northwestern.edu/~nocedal/lbfgsb.html
6+
under the terms of the 3-clause BSD license. Fortran files `lbfgsb.f`,
7+
`linpack.f`, and `timer.f` come from this library.
8+
9+
`linpack.f` was modified to include calls to LAPACK as in scipy v0.10.0.
10+
Scipy is also licensed under the BSD license.
11+
12+
`lbfgsb.h` contains a C header to call the Fortran setulb_ routine.
13+
`lbfgsb_daal.h` contains a DAAL class wrapping the L-BFGS-B library for use
14+
as a DAAL iterative solver.
15+
16+
The authors of the library ask that we quote at least one of the references
17+
below.
18+
19+
References
20+
----------
21+
22+
1. R. H. Byrd, P. Lu and J. Nocedal. A Limited Memory Algorithm for Bound
23+
Constrained Optimization, (1995), SIAM Journal on Scientific and
24+
Statistical Computing , 16, 5, pp. 1190-1208.
25+
2. C. Zhu, R. H. Byrd and J. Nocedal. L-BFGS-B: Algorithm 778: L-BFGS-B,
26+
FORTRAN routines for large scale bound constrained optimization (1997),
27+
ACM Transactions on Mathematical Software, Vol 23, Num. 4, pp. 550 - 560.
28+
3. J.L. Morales and J. Nocedal. L-BFGS-B: Remark on Algorithm 778: L-BFGS-B,
29+
FORTRAN routines for large scale bound constrained optimization (2011),
30+
to appear in ACM Transactions on Mathematical Software.
31+

0 commit comments

Comments
 (0)