Skip to content

Commit

Permalink
Merge pull request #1532 from JuliaLang/vs/blas64
Browse files Browse the repository at this point in the history
RFC: 64-bit interfaces for various libraries

Close #1527 and #1556.
  • Loading branch information
ViralBShah committed Dec 20, 2012
2 parents a8860f3 + 9e7e594 commit c78b184
Show file tree
Hide file tree
Showing 14 changed files with 1,029 additions and 822 deletions.
6 changes: 6 additions & 0 deletions Make.inc
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,15 @@ JL_PRIVATE_LIBDIR = lib/$(MULTIARCH)/julia
JL_LIBDIR = lib/$(MULTIARCH)/
endif

# Figure out OS and architecture
OS = $(shell uname)
ARCH = $(shell uname -m)

# Use 64-bit libraries by default on 64-bit architectures
ifeq ($(ARCH), x86_64)
USE_LIB64 = 1
endif

USE_MKL = 0
MKLLIB = /path/to/mkl/lib/intel64

Expand Down
6 changes: 6 additions & 0 deletions base/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ build_h.jl: ../Make.inc ../src/os_detect.h
$(QUIET_PERL) $(CC) -E -P -DJULIA ../src/os_detect.h | grep OS_NAME > $@
@echo "const libblas_name = \"$(LIBBLASNAME)\"" >> $@
@echo "const liblapack_name = \"$(LIBLAPACKNAME)\"" >> $@
ifeq ($(USE_LIB64), 1)
@echo "const USE_LIB64 = true" >> $@
else
@echo "const USE_LIB64 = false" >> $@
endif


clean:
rm -f *# *~
Expand Down
130 changes: 72 additions & 58 deletions base/blas.jl

Large diffs are not rendered by default.

601 changes: 303 additions & 298 deletions base/lapack.jl

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions base/librandom.jl
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ for (genrand_fill, gv_genrand_fill, genrand_fill_name, gv_genrand_fill_name) in
else
ccall(($(string(genrand_fill)),:librandom),
Void,
(Ptr{Void}, Ptr{Float64}, Int32),
s.val, A, n & 0xfffffffe)
(Ptr{Void}, Ptr{Float64}, Int),
s.val, A, n & 0xfffffffffffffffe)
if isodd(n)
A[n] = rand()
end
Expand All @@ -127,8 +127,8 @@ for (genrand_fill, gv_genrand_fill, genrand_fill_name, gv_genrand_fill_name) in
else
ccall(($(string(gv_genrand_fill)),:librandom),
Void,
(Ptr{Void}, Int32),
A, n & 0xfffffffe)
(Ptr{Void}, Int),
A, n & 0xfffffffffffffffe)
if isodd(n)
A[n] = rand()
end
Expand Down
142 changes: 71 additions & 71 deletions base/linalg_dense.jl

Large diffs are not rendered by default.

38 changes: 19 additions & 19 deletions base/matmul.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,30 +62,30 @@ end

# Matrix-vector multiplication

function (*){T<:LapackType}(A::StridedMatrix{T},
function (*){T<:BlasFloat}(A::StridedMatrix{T},
X::StridedVector{T})
Y = similar(A, size(A,1))
gemv(Y, 'N', A, X)
end

A_mul_B{T<:LapackType}(y::StridedVector{T}, A::StridedMatrix{T}, x::StridedVector{T}) = gemv(y, 'N', A, x)
A_mul_B{T<:BlasFloat}(y::StridedVector{T}, A::StridedMatrix{T}, x::StridedVector{T}) = gemv(y, 'N', A, x)
A_mul_B(y::StridedVector, A::StridedMatrix, x::StridedVector) = generic_matvecmul(y, 'N', A, x)

function At_mul_B{T<:LapackType}(A::StridedMatrix{T}, x::StridedVector{T})
function At_mul_B{T<:BlasFloat}(A::StridedMatrix{T}, x::StridedVector{T})
y = similar(A, size(A, 2))
gemv(y, 'T', A, x)
end

At_mul_B{T<:LapackType}(y::StridedVector{T}, A::StridedMatrix{T}, x::StridedVector{T}) = gemv(y, 'T', A, x)
At_mul_B{T<:BlasFloat}(y::StridedVector{T}, A::StridedMatrix{T}, x::StridedVector{T}) = gemv(y, 'T', A, x)
At_mul_B(y::StridedVector, A::StridedMatrix, x::StridedVector) = generic_matvecmul(y, 'T', A, x)

# Matrix-matrix multiplication

(*){T<:LapackType}(A::StridedMatrix{T}, B::StridedMatrix{T}) = gemm_wrapper('N', 'N', A, B)
A_mul_B{T<:LapackType}(C::StridedMatrix{T}, A::StridedMatrix{T}, B::StridedMatrix{T}) = gemm_wrapper(C, 'N', 'N', A, B)
(*){T<:BlasFloat}(A::StridedMatrix{T}, B::StridedMatrix{T}) = gemm_wrapper('N', 'N', A, B)
A_mul_B{T<:BlasFloat}(C::StridedMatrix{T}, A::StridedMatrix{T}, B::StridedMatrix{T}) = gemm_wrapper(C, 'N', 'N', A, B)
A_mul_B{T,S,R}(C::StridedMatrix{R}, A::StridedMatrix{T}, B::StridedMatrix{S}) = generic_matmatmul(C, 'N', 'N', A, B)

function At_mul_B{T<:LapackType}(A::StridedMatrix{T},
function At_mul_B{T<:BlasFloat}(A::StridedMatrix{T},
B::StridedMatrix{T})
if is(A, B)
syrk_wrapper('T', A)
Expand All @@ -94,11 +94,11 @@ function At_mul_B{T<:LapackType}(A::StridedMatrix{T},
end
end

At_mul_B{T<:LapackType}(C::StridedMatrix{T}, A::StridedMatrix{T}, B::StridedMatrix{T}) = gemm_wrapper(C, 'T', 'N', A, B)
At_mul_B{T<:BlasFloat}(C::StridedMatrix{T}, A::StridedMatrix{T}, B::StridedMatrix{T}) = gemm_wrapper(C, 'T', 'N', A, B)
At_mul_B{T,S}(A::StridedMatrix{T}, B::StridedMatrix{S}) = generic_matmatmul('T', 'N', A, B)
At_mul_B{T,S,R}(C::StridedMatrix{R}, A::StridedMatrix{T}, B::StridedMatrix{S}) = generic_matmatmul(C, 'T', 'N', A, B)

function A_mul_Bt{T<:LapackType}(A::StridedMatrix{T},
function A_mul_Bt{T<:BlasFloat}(A::StridedMatrix{T},
B::StridedMatrix{T})
if is(A, B)
syrk_wrapper('N', A)
Expand All @@ -107,12 +107,12 @@ function A_mul_Bt{T<:LapackType}(A::StridedMatrix{T},
end
end

A_mul_Bt{T<:LapackType}(C::StridedMatrix{T}, A::StridedMatrix{T}, B::StridedMatrix{T}) = gemm_wrapper(C, 'N', 'T', A, B)
A_mul_Bt{T<:BlasFloat}(C::StridedMatrix{T}, A::StridedMatrix{T}, B::StridedMatrix{T}) = gemm_wrapper(C, 'N', 'T', A, B)
A_mul_Bt{T,S}(A::StridedMatrix{T}, B::StridedMatrix{S}) = generic_matmatmul('N', 'T', A, B)
A_mul_Bt{T,S,R}(C::StridedMatrix{R}, A::StridedMatrix{T}, B::StridedMatrix{S}) = generic_matmatmul(C, 'N', 'T', A, B)

At_mul_Bt{T<:LapackType}(A::StridedMatrix{T}, B::StridedMatrix{T}) = gemm_wrapper('T', 'T', A, B)
At_mul_Bt{T<:LapackType}(C::StridedMatrix{T}, A::StridedMatrix{T}, B::StridedMatrix{T}) = gemm_wrapper(C, 'T', 'T', A, B)
At_mul_Bt{T<:BlasFloat}(A::StridedMatrix{T}, B::StridedMatrix{T}) = gemm_wrapper('T', 'T', A, B)
At_mul_Bt{T<:BlasFloat}(C::StridedMatrix{T}, A::StridedMatrix{T}, B::StridedMatrix{T}) = gemm_wrapper(C, 'T', 'T', A, B)
At_mul_Bt{T,S}(A::StridedMatrix{T}, B::StridedMatrix{S}) = generic_matmatmul('T', 'T', A, B)
At_mul_Bt{T,S,R}(C::StridedMatrix{R}, A::StridedMatrix{T}, B::StridedMatrix{S}) = generic_matmatmul(C, 'T', 'T', A, B)

Expand Down Expand Up @@ -146,8 +146,8 @@ A_mul_Bc{T<:Union(Complex128,Complex64)}(C::StridedMatrix{T}, A::StridedMatrix{T
A_mul_Bc{T,S}(A::StridedMatrix{T}, B::StridedMatrix{S}) = generic_matmatmul('N', 'C', A, B)
A_mul_Bc{T,S,R}(C::StridedMatrix{R}, A::StridedMatrix{T}, B::StridedMatrix{S}) = generic_matmatmul(C, 'N', 'C', A, B)

Ac_mul_Bc{T<:LapackType}(A::StridedMatrix{T}, B::StridedMatrix{T}) = gemm_wrapper('C', 'C', A, B)
Ac_mul_Bc{T<:LapackType}(C::StridedMatrix{T}, A::StridedMatrix{T}, B::StridedMatrix{T}) = gemm_wrapper(C, 'C', 'C', A, B)
Ac_mul_Bc{T<:BlasFloat}(A::StridedMatrix{T}, B::StridedMatrix{T}) = gemm_wrapper('C', 'C', A, B)
Ac_mul_Bc{T<:BlasFloat}(C::StridedMatrix{T}, A::StridedMatrix{T}, B::StridedMatrix{T}) = gemm_wrapper(C, 'C', 'C', A, B)
Ac_mul_Bt{T,S}(A::StridedMatrix{T}, B::StridedMatrix{S}) = generic_matmatmul('C', 'C', A, B)
Ac_mul_Bt{T,S,R}(C::StridedMatrix{R}, A::StridedMatrix{T}, B::StridedMatrix{S}) = generic_matmatmul(C, 'C', 'C', A, B)

Expand Down Expand Up @@ -195,7 +195,7 @@ end

symmetrize_conj!(A) = symmetrize_conj!(A, true)

function gemv{T<:LapackType}(y::StridedVector{T},
function gemv{T<:BlasFloat}(y::StridedVector{T},
tA,
A::StridedMatrix{T},
x::StridedVector{T})
Expand All @@ -215,7 +215,7 @@ function gemv{T<:LapackType}(y::StridedVector{T},
BLAS.gemv!(tA, one(T), A, x, zero(T), y)
end

function syrk_wrapper{T<:LapackType}(tA, A::StridedMatrix{T})
function syrk_wrapper{T<:BlasFloat}(tA, A::StridedMatrix{T})
if tA == 'T'
(nA, mA) = size(A)
tAt = 'N'
Expand All @@ -234,7 +234,7 @@ function syrk_wrapper{T<:LapackType}(tA, A::StridedMatrix{T})
symmetrize!(BLAS.syrk('U', tA, one(T), A))
end

function herk_wrapper{T<:LapackType}(tA, A::StridedMatrix{T})
function herk_wrapper{T<:BlasFloat}(tA, A::StridedMatrix{T})
if tA == 'C'
(nA, mA) = size(A)
tAt = 'N'
Expand All @@ -256,7 +256,7 @@ function herk_wrapper{T<:LapackType}(tA, A::StridedMatrix{T})
symmetrize_conj!(BLAS.herk('U', tA, one(T), A))
end

function gemm_wrapper{T<:LapackType}(tA, tB,
function gemm_wrapper{T<:BlasFloat}(tA, tB,
A::StridedMatrix{T},
B::StridedMatrix{T})
mA, nA = lapack_size(tA, A)
Expand All @@ -265,7 +265,7 @@ function gemm_wrapper{T<:LapackType}(tA, tB,
gemm_wrapper(C, tA, tB, A, B)
end

function gemm_wrapper{T<:LapackType}(C::StridedMatrix{T}, tA, tB,
function gemm_wrapper{T<:BlasFloat}(C::StridedMatrix{T}, tA, tB,
A::StridedMatrix{T},
B::StridedMatrix{T})
mA, nA = lapack_size(tA, A)
Expand Down
21 changes: 15 additions & 6 deletions deps/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ random/jl_random.c: random/dsfmt-$(DSFMT_VER).tar.gz
cd random && \
mkdir -p dsfmt-$(DSFMT_VER) && \
tar -C dsfmt-$(DSFMT_VER) --strip-components 1 -xf dsfmt-$(DSFMT_VER).tar.gz && \
cd dsfmt-$(DSFMT_VER) && patch < ../dSFMT.h.patch
cd dsfmt-$(DSFMT_VER) && patch < ../dSFMT.h.patch && patch < ../dSFMT.c.patch
touch $@
$(LIBRANDOM_OBJ_SOURCE): random/jl_random.c random/randmtzig.c
cd random && \
Expand Down Expand Up @@ -459,9 +459,9 @@ ifeq ($(OPENBLAS_DYNAMIC_ARCH), 1)
OPENBLAS_BUILD_OPTS += DYNAMIC_ARCH=1
endif

#ifeq ($(ARCH), x86_64)
#OPENBLAS_BUILD_OPTS += -DINTERFACE64=1
#endif
ifeq ($(USE_LIB64), 1)
OPENBLAS_BUILD_OPTS += INTERFACE64=1
endif

compile-openblas: $(OPENBLAS_OBJ_SOURCE)
install-openblas: $(BUILD)/lib/libopenblas.$(SHLIB_EXT)
Expand Down Expand Up @@ -521,6 +521,10 @@ distclean-lapack:

## ARPACK ##

ifeq ($(USE_LIB64), 1)
ARPACK_FFLAGS = -fdefault-integer-8
endif

ARPACK_OBJ_TARGET = $(BUILD)/lib/libarpack.$(SHLIB_EXT)
ARPACK_OBJ_SOURCE = arpack-ng_$(ARPACK_VER)/libarpack.$(SHLIB_EXT)

Expand All @@ -535,7 +539,7 @@ arpack-ng_$(ARPACK_VER)/configure: arpack-ng_$(ARPACK_VER).tar.gz
touch $@
$(ARPACK_OBJ_SOURCE): arpack-ng_$(ARPACK_VER)/configure $(OPENBLAS_OBJ_SOURCE)
cd arpack-ng_$(ARPACK_VER) && \
./configure --prefix=$(abspath $(BUILD)) --with-blas="$(LIBBLAS)" --with-lapack="$(LIBLAPACK)" --disable-mpi --enable-shared F77="$(FC)" MPIF77="$(FC)" CC="$(CC)" CXX="$(CXX)"
./configure --prefix=$(abspath $(BUILD)) --with-blas="$(LIBBLAS)" --with-lapack="$(LIBLAPACK)" --disable-mpi --enable-shared F77="$(FC)" MPIF77="$(FC)" CC="$(CC)" CXX="$(CXX)" FFLAGS="$(ARPACK_FFLAGS)"
touch $@
$(ARPACK_OBJ_TARGET): $(ARPACK_OBJ_SOURCE) | $(BUILD)/lib
cd arpack-ng_$(ARPACK_VER) && \
Expand Down Expand Up @@ -648,6 +652,11 @@ SUITESPARSE_OBJ_SOURCE = SuiteSparse-$(SUITESPARSE_VER)/UMFPACK/Lib/libumfpack.a
SUITESPARSE_OBJ_TARGET = $(BUILD)/lib/libumfpack.$(SHLIB_EXT)
endif

ifeq ($(USE_LIB64), 1)
UMFPACK_CONFIG = -DLONGBLAS='long long'
CHOLMOD_CONFIG = -DLONGBLAS='long long'
endif

SUITE_SPARSE_LIB = -lm
ifneq ($(OS), Darwin)
SUITE_SPARSE_LIB += -lrt
Expand All @@ -664,7 +673,7 @@ SuiteSparse-$(SUITESPARSE_VER)/Makefile: SuiteSparse-$(SUITESPARSE_VER).tar.gz
touch $@
$(SUITESPARSE_OBJ_SOURCE): $(OPENBLAS_OBJ_SOURCE) SuiteSparse-$(SUITESPARSE_VER)/Makefile
cd SuiteSparse-$(SUITESPARSE_VER) && \
$(MAKE) CC="$(CC)" CXX="$(CXX)" BLAS="$(LIBBLAS)" LAPACK="$(LIBLAPACK)" INSTALL_LIB="$(BUILD)/lib" INSTALL_INCLUDE="$(BUILD)/include" LIB="$(SUITE_SPARSE_LIB)"
$(MAKE) CC="$(CC)" CXX="$(CXX)" BLAS="$(LIBBLAS)" LAPACK="$(LIBLAPACK)" INSTALL_LIB="$(BUILD)/lib" INSTALL_INCLUDE="$(BUILD)/include" LIB="$(SUITE_SPARSE_LIB)" UMFPACK_CONFIG="$(UMFPACK_CONFIG)" CHOLMOD_CONFIG="$(CHOLMOD_CONFIG)"
touch $@

ifeq ($(USE_SYSTEM_SUITESPARSE), 0)
Expand Down
100 changes: 100 additions & 0 deletions deps/random/dSFMT.c.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
--- dsfmt-2.2/dSFMT.c 2012-06-29 03:24:27.000000000 -0400
+++ dSFMT-patched.c 2012-12-20 12:45:45.000000000 -0500
@@ -32,13 +32,13 @@
inline static uint32_t ini_func1(uint32_t x);
inline static uint32_t ini_func2(uint32_t x);
inline static void gen_rand_array_c1o2(dsfmt_t *dsfmt, w128_t *array,
- int size);
+ ptrdiff_t size);
inline static void gen_rand_array_c0o1(dsfmt_t *dsfmt, w128_t *array,
- int size);
+ ptrdiff_t size);
inline static void gen_rand_array_o0c1(dsfmt_t *dsfmt, w128_t *array,
- int size);
+ ptrdiff_t size);
inline static void gen_rand_array_o0o1(dsfmt_t *dsfmt, w128_t *array,
- int size);
+ ptrdiff_t size);
inline static int idxof(int i);
static void initial_mask(dsfmt_t *dsfmt);
static void period_certification(dsfmt_t *dsfmt);
@@ -142,8 +142,8 @@
* @param size number of 128-bit pseudorandom numbers to be generated.
*/
inline static void gen_rand_array_c1o2(dsfmt_t *dsfmt, w128_t *array,
- int size) {
- int i, j;
+ ptrdiff_t size) {
+ ptrdiff_t i, j;
w128_t lung;

lung = dsfmt->status[DSFMT_N];
@@ -180,8 +180,8 @@
* @param size number of 128-bit pseudorandom numbers to be generated.
*/
inline static void gen_rand_array_c0o1(dsfmt_t *dsfmt, w128_t *array,
- int size) {
- int i, j;
+ ptrdiff_t size) {
+ ptrdiff_t i, j;
w128_t lung;

lung = dsfmt->status[DSFMT_N];
@@ -223,8 +223,8 @@
* @param size number of 128-bit pseudorandom numbers to be generated.
*/
inline static void gen_rand_array_o0o1(dsfmt_t *dsfmt, w128_t *array,
- int size) {
- int i, j;
+ ptrdiff_t size) {
+ ptrdiff_t i, j;
w128_t lung;

lung = dsfmt->status[DSFMT_N];
@@ -266,8 +266,8 @@
* @param size number of 128-bit pseudorandom numbers to be generated.
*/
inline static void gen_rand_array_o0c1(dsfmt_t *dsfmt, w128_t *array,
- int size) {
- int i, j;
+ ptrdiff_t size) {
+ ptrdiff_t i, j;
w128_t lung;

lung = dsfmt->status[DSFMT_N];
@@ -453,7 +453,7 @@
* memory. Mac OSX doesn't have these functions, but \b malloc of OSX
* returns the pointer to the aligned memory block.
*/
-void dsfmt_fill_array_close1_open2(dsfmt_t *dsfmt, double array[], int size) {
+void dsfmt_fill_array_close1_open2(dsfmt_t *dsfmt, double array[], ptrdiff_t size) {
assert(size % 2 == 0);
assert(size >= DSFMT_N64);
gen_rand_array_c1o2(dsfmt, (w128_t *)array, size / 2);
@@ -471,7 +471,7 @@
* @param size the number of pseudorandom numbers to be generated.
* see also \sa fill_array_close1_open2()
*/
-void dsfmt_fill_array_open_close(dsfmt_t *dsfmt, double array[], int size) {
+void dsfmt_fill_array_open_close(dsfmt_t *dsfmt, double array[], ptrdiff_t size) {
assert(size % 2 == 0);
assert(size >= DSFMT_N64);
gen_rand_array_o0c1(dsfmt, (w128_t *)array, size / 2);
@@ -489,7 +489,7 @@
* @param size the number of pseudorandom numbers to be generated.
* see also \sa fill_array_close1_open2()
*/
-void dsfmt_fill_array_close_open(dsfmt_t *dsfmt, double array[], int size) {
+void dsfmt_fill_array_close_open(dsfmt_t *dsfmt, double array[], ptrdiff_t size) {
assert(size % 2 == 0);
assert(size >= DSFMT_N64);
gen_rand_array_c0o1(dsfmt, (w128_t *)array, size / 2);
@@ -507,7 +507,7 @@
* @param size the number of pseudorandom numbers to be generated.
* see also \sa fill_array_close1_open2()
*/
-void dsfmt_fill_array_open_open(dsfmt_t *dsfmt, double array[], int size) {
+void dsfmt_fill_array_open_open(dsfmt_t *dsfmt, double array[], ptrdiff_t size) {
assert(size % 2 == 0);
assert(size >= DSFMT_N64);
gen_rand_array_o0o1(dsfmt, (w128_t *)array, size / 2);
Loading

0 comments on commit c78b184

Please sign in to comment.