Give choice of ATLAS, MKL, and OpenBLAS (with option to override paths)

- configure build for ATLAS, MKL, or OpenBLAS on Linux and OSX
- allow overriding of the include or lib dirs
- replace magic numbers with BLAS names (atlas, mkl, open)

Follow-up from #305 and #325.
This commit is contained in:
Evan Shelhamer 2014-04-15 01:37:06 -06:00
Родитель 426f089df4
Коммит ed38827284
3 изменённых файлов: 33 добавлений и 25 удалений

Просмотреть файл

@ -109,8 +109,6 @@ TEST_ALL_BIN := $(TEST_BIN_DIR)/test_all.testbin
##############################
CUDA_INCLUDE_DIR := $(CUDA_DIR)/include
CUDA_LIB_DIR := $(CUDA_DIR)/lib64 $(CUDA_DIR)/lib
BLAS_INCLUDE_DIR := $(BLAS_DIR)/include
BLAS_LIB_DIR := $(BLAS_DIR)/lib
INCLUDE_DIRS += $(BUILD_INCLUDE_DIR)
INCLUDE_DIRS += ./src ./include $(CUDA_INCLUDE_DIR)
@ -176,31 +174,36 @@ else
COMMON_FLAGS := -DNDEBUG -O2
endif
# MKL switch (default = ATLAS)
BLAS ?= 0
ifeq ($(BLAS), 1)
# BLAS configuration (default = ATLAS)
BLAS ?= atlas
ifeq ($(BLAS), mkl)
# MKL
LIBRARIES += mkl_rt
COMMON_FLAGS += -DUSE_MKL
INCLUDE_DIRS += $(BLAS_INCLUDE_DIR)
LIBRARY_DIRS += $(BLAS_LIB_DIR) $(BLAS_DIR)/lib/intel64
MKL_DIR = /opt/intel/mkl
BLAS_INCLUDE ?= $(MKL_DIR)/include
BLAS_LIB ?= $(MKL_DIR)/lib $(MKL_DIR)/lib/intel64
else ifeq ($(BLAS), open)
# OpenBLAS
LIBRARIES += openblas
else
# ATLAS
ifeq ($(LINUX), 1)
ifeq ($(BLAS), 0)
# Linux simply has cblas and atlas
LIBRARIES += cblas atlas
else ifeq ($(BLAS), 2)
LIBRARIES += openblas
endif
INCLUDE_DIRS += $(BLAS_INCLUDE_DIR)
LIBRARY_DIRS += $(BLAS_LIB_DIR)
ifeq ($(BLAS), atlas)
# Linux simply has cblas and atlas
LIBRARIES += cblas atlas
endif
else ifeq ($(OSX), 1)
# OS X packages atlas as the vecLib framework
INCLUDE_DIRS += /System/Library/Frameworks/vecLib.framework/Versions/Current/Headers/
BLAS_INCLUDE ?= /System/Library/Frameworks/vecLib.framework/Versions/Current/Headers/
LIBRARIES += cblas
LDFLAGS += -framework vecLib
endif
endif
INCLUDE_DIRS += $(BLAS_INCLUDE)
LIBRARY_DIRS += $(BLAS_LIB)
# Complete build flags.
COMMON_FLAGS += $(foreach includedir,$(INCLUDE_DIRS),-I$(includedir))
CXXFLAGS += -pthread -fPIC $(COMMON_FLAGS)
NVCCFLAGS := -ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS)

Просмотреть файл

@ -10,13 +10,16 @@ CUDA_ARCH := -gencode arch=compute_20,code=sm_20 \
-gencode arch=compute_30,code=sm_30 \
-gencode arch=compute_35,code=sm_35
# BLAS switch:
# 0 for ATLAS BLAS (default)
# 1 for MKL BLAS
# 2 for OpenBlas
BLAS := 0
# (MKL/ATLAS/OpenBlas) directory contains include/ and lib/ directions that we need.
#BLAS_DIR := /opt/intel/mkl
# BLAS choice:
# atlas for ATLAS (default)
# mkl for MKL
# open for OpenBlas
BLAS := atlas
# Custom (MKL/ATLAS/OpenBLAS) include and lib directories.
# Leave commented to accept the defaults for your choice of BLAS
# (which should work)!
# BLAS_INCLUDE := /path/to/your/blas
# BLAS_LIB := /path/to/your/blas
# This is required only if you will compile the matlab interface.
# MATLAB directory should contain the mex binary in /bin.

Просмотреть файл

@ -47,8 +47,10 @@ N.B. one can install the CUDA libraries without the CUDA driver in order to buil
+ OS X: already installed as the [Accelerate / vecLib Framework](https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man7/Accelerate.7.html).
* [Intel MKL](http://software.intel.com/en-us/intel-mkl): commercial; however free trial or [student](http://software.intel.com/en-us/intel-education-offerings) licenses are available. Caffe was originally developed with MKL.
1. Install MKL
2. Set `USE_MKL := 1` in `Makefile.config`
* [OpenBLAS](http://www.openblas.net/): free and open source; this optimized BLAS is left as an exercise because it requires more effort to install, although it might offer a speedup.
2. Set `BLAS := mkl` in `Makefile.config`
* [OpenBLAS](http://www.openblas.net/): free and open source; this optimized and parallel BLAS could require more effort to install, although it might offer a speedup.
1. Install OpenBLAS
2. Set `BLAS := open` in `Makefile.config`
**The Rest**: you will also need other packages, most of which can be installed via apt-get using: