Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for macOS #18

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 48 additions & 27 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# 是否开启openmp 1 开启 0 不开启 单线程版本
# 是否开启openmp1 开启0 不开启 单线程版本
OPENMP = 1
# 是否生成汇编代码,生成的汇编代码在 asm 目录下。1 生成,0 不生成。
# 是否生成汇编代码,生成的汇编代码在 asm 目录下。1 生成0 不生成。
ASM_COMPILE = 0
# MKL_INT 和 ALPHA_INT 是否使用64位, 1 使用64位,0 使用32位。
# MKL_INT 和 ALPHA_INT 是否使用64位,1 使用64位,0 使用32位。
INT_64 = 0
# 表示编不编译
# 表示编不编译
HIP_ON = $(shell echo $${HIP_ON:-0})
# PLAIN 依赖 mkl
PLAIN_ON = $(shell echo $${PLAIN_ON:-1})
Expand All @@ -17,45 +17,51 @@ HYGON_ON = 0
HAS_MKL = 0
PLAIN_ON = 0
ROOT = $(shell pwd)
OS := $(shell uname -s)

LIB_DIR = $(ROOT)/lib
INC_DIR = $(ROOT)/include
INC_DIR = $(ROOT)/include
OBJ_DIR = $(ROOT)/obj
BIN_DIR = $(ROOT)/bin
ASM_DIR = $(ROOT)/asm

ifeq ($(DEBUG_ON),1)
ifeq ($(DEBUG_ON), 1)
CPPFLAGS += -ggdb
endif

ifeq ($(HIP_ON),1)
ifeq ($(HIP_ON), 1)
ROCM_DIR = /public/software/compiler/rocm/rocm-3.9.1
ROCSP_DIR = /home/gcx/csparse
endif

LIBNAME = libalpha_spblas

INC += -I$(INC_DIR)
INC += -I$(INC_DIR)

ifeq ($(HIP_ON),1)
ifeq ($(HIP_ON), 1)
INC += -I$(ROCM_DIR)/hip/include
endif

export ROOT LIB_DIR INC_DIR OBJ_DIR BIN_DIR ASM_DIR INC DEFINE LIBNAME OPENMP ASM_COMPILE INT_64 HIP_ON PLAIN_ON HAS_MKL ARM_ON HYGON_ON
GCC_VERSION_GE9_3_1 := $(shell expr `gcc --version | awk -F" " '/^gcc/{print $$3}' | tr -d '.' ` \>= 931)

ifneq ($(OS), Darwin)
CPUVENDOR := $(shell lscpu | awk -F"[ ;]" '/^Vendor/ {print $$NF}' )
endif

MAKE = make
CC = gcc
HCC= hipcc
AR = ar
LDFLAGS = -L$(LIB_DIR)
LDFLAGS = -L$(LIB_DIR)

CPPFLAGS += -std=c++11 -fPIC -Ofast -I$(INC_DIR)
CPPFLAGS += -std=c++11 -fPIC -Ofast -I$(INC_DIR)
CFLAGS += -Ofast
CFLAGS += -std=c11
CFLAGS += -g
ifeq ($(OPENMP), 1)
CFLAGS += -fopenmp
CPPFLAGS += -fopenmp
CFLAGS += -fopenmp
CPPFLAGS += -fopenmp
endif
# CFLAGS += -mcmodel=large
CFLAGS += -Wall
Expand All @@ -70,27 +76,40 @@ CFLAGS += -fPIC
# CFLAGS += -Wl,-z,relro -Wl,-z,noexecstack -Wl,-z,now

ARCH = $(shell uname -m)
ifeq ($(ARCH),aarch64)
ifeq ($(ARCH), aarch64)
CC = gcc
DEFINE += -D__aarch64__
ifeq ($(GCC_VERSION_GE9_3_1),1)
ifeq ($(GCC_VERSION_GE9_3_1), 1)
CFLAGS += -march=armv8.3-a
DEFINE += -DCMLA
endif
endif
ifeq ($(ARCH),x86_64)
ifeq ($(ARCH), x86_64)
CC = gcc
ifeq ($(CPUVENDOR),GenuineIntel)
ifneq ($(OS), Darwin)
ifeq ($(CPUVENDOR), GenuineIntel)
CC = icc
endif
CFLAGS += -march=native
endif
CFLAGS += -m64
CFLAGS += -march=native
DEFINE += -D__x86_64__
ifeq ($(HAS_MKL), 1)
DEFINE += -D__MKL__
endif
endif
ifeq ($(ARCH), ppc)
CC = gcc
CFLAGS += -mtune=native
CFLAGS += -arch ppc
DEFINE += -Dppc
endif
ifeq ($(ARCH), ppc64)
CC = gcc
CFLAGS += -mtune=native
CFLAGS += -arch ppc64
DEFINE += -Dppc64
endif
ifeq ($(CC), gcc)
endif
ifeq ($(CC), icc)
Expand All @@ -101,33 +120,35 @@ DEFINE += -DMKL_ILP64
DEFINE += -DALPHA_INT=int64_t
endif

ifeq ($(HIP_ON), 1)
CEXTRAFLAGS += -lstdc++ -L$(ROCM_DIR)/hip/lib -L$(ROCM_DIR)/rocsparse/lib -lamdhip64 -lrocsparse

ifeq ($(HIP_ON),1)
LDFLAGS += $(CEXTRAFLAGS)
DEFINE += -D__DCU__
endif

ifeq ($(PLAIN_ON),1)
ifeq ($(PLAIN_ON), 1)
DEFINE += -D__PLAIN__
endif

export MAKE CC HCC AR CFLAGS CPPFLAGS CEXTRAFLAGS ARCH LDFLAGS

.PHONY : clean lib test tool
.PHONY : clean lib so test

all : lib test tool so
all : lib so test

lib :
lib :
$(MAKE) -C src $(@F)

so : lib
$(CC) -shared -o $(LIB_DIR)/$(LIBNAME).so -Wl,--whole-archive $(LIB_DIR)/$(LIBNAME).a -Wl,--no-whole-archive
# FIXME: this will not work on macOS:
so : lib
$(CC) -shared -o $(LIB_DIR)/$(LIBNAME).so -Wl,--whole-archive $(LIB_DIR)/$(LIBNAME).a -Wl,--no-whole-archive

# TODO: implement tests for PPC.
test : lib
$(MAKE) -C test $(@F)

# tool :
# TODO: implement tool target (needs fixes to makefiles).
# tool :
# $(MAKE) -C tools $(@F)

clean :
Expand Down
28 changes: 14 additions & 14 deletions Makefile.tail
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ SPBLASOBJS = $(XSSPBLASOBJS) $(XDSPBLASOBJS) $(XCSPBLASOBJS) $(XZSPBLASOBJS) \
$(XSSPBLASOBJSCPP) $(XDSPBLASOBJSCPP) $(XCSPBLASOBJSCPP) $(XZSPBLASOBJSCPP) \
$(FSSPBLASOBJSCPP) $(FDSPBLASOBJSCPP) $(CCSPBLASOBJSCPP) $(CZSPBLASOBJSCPP)

$(XSSPBLASOBJS) $(FSSPBLASOBJS): override CFLAGS += -UDOUBLE -UCOMPLEX
$(XDSPBLASOBJS) $(FDSPBLASOBJS): override CFLAGS += -DDOUBLE -UCOMPLEX
$(XCSPBLASOBJS) $(CCSPBLASOBJS): override CFLAGS += -UDOUBLE -DCOMPLEX
$(XZSPBLASOBJS) $(CZSPBLASOBJS): override CFLAGS += -DDOUBLE -DCOMPLEX
$(XSSPBLASOBJS) $(FSSPBLASOBJS): override CFLAGS += -UDOUBLE -UCOMPLEX
$(XDSPBLASOBJS) $(FDSPBLASOBJS): override CFLAGS += -DDOUBLE -UCOMPLEX
$(XCSPBLASOBJS) $(CCSPBLASOBJS): override CFLAGS += -UDOUBLE -DCOMPLEX
$(XZSPBLASOBJS) $(CZSPBLASOBJS): override CFLAGS += -DDOUBLE -DCOMPLEX

$(XSSPBLASOBJSCPP) $(FSSPBLASOBJSCPP): override CPPFLAGS += -UDOUBLE -UCOMPLEX
$(XDSPBLASOBJSCPP) $(FDSPBLASOBJSCPP): override CPPFLAGS += -DDOUBLE -UCOMPLEX
$(XCSPBLASOBJSCPP) $(CCSPBLASOBJSCPP): override CPPFLAGS += -UDOUBLE -DCOMPLEX
$(XZSPBLASOBJSCPP) $(CZSPBLASOBJSCPP): override CPPFLAGS += -DDOUBLE -DCOMPLEX
$(XSSPBLASOBJSCPP) $(FSSPBLASOBJSCPP): override CPPFLAGS += -UDOUBLE -UCOMPLEX
$(XDSPBLASOBJSCPP) $(FDSPBLASOBJSCPP): override CPPFLAGS += -DDOUBLE -UCOMPLEX
$(XCSPBLASOBJSCPP) $(CCSPBLASOBJSCPP): override CPPFLAGS += -UDOUBLE -DCOMPLEX
$(XZSPBLASOBJSCPP) $(CZSPBLASOBJSCPP): override CPPFLAGS += -DDOUBLE -DCOMPLEX

.SECONDEXPANSION:

Expand Down Expand Up @@ -121,19 +121,19 @@ $(CZSPBLASOBJSCPP) : $(OBJ_DIR)/%.o : $$(subst _z_,_c_,%.cpp)
$(HCC) -c -o $@ $^ $(CPPFLAGS) -UONAME -DONAME=$(*F)

$(COMMONOBJS) : $(OBJ_DIR)/%.o : %.c
$(CC) -c -o $@ $^ $(CFLAGS) -UONAME
$(CC) -c -o $@ $^ $(CFLAGS) -UONAME

$(COMMONOBJSCPP) : $(OBJ_DIR)/%.o : %.cpp
$(HCC) -c -o $@ $^ $(CPPFLAGS) -UONAME
$(COMMONOBJSCPP) : $(OBJ_DIR)/%.o : %.cpp
$(HCC) -c -o $@ $^ $(CPPFLAGS) -UONAME

$(ASMOBJS) : $(OBJ_DIR)/%.o : %.S
$(CC) -c -o $@ $^ $(CFLAGS) -UONAME
$(CC) -c -o $@ $^ $(CFLAGS) -UONAME

$(OBJ) : $(OBJ_DIR)/%.o : %.c
$(CC) -c -o $@ $^ $(CFLAGS) -UONAME
$(CC) -c -o $@ $^ $(CFLAGS) -UONAME

$(OBJCPP) : $(OBJ_DIR)/%.o : %.cpp
$(HCC) -c -o $@ $^ $(CPPFLAGS) -UONAME
$(HCC) -c -o $@ $^ $(CPPFLAGS) -UONAME

$(BIN_DIR)/% : $(OBJ_DIR)/%.o $(LIB_DIR)/libalpha_spblas.a $(TEST_COMMON_OBJS)
$(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS)
Expand Down
5 changes: 5 additions & 0 deletions include/alphasparse/opt.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@
*/

#include "alphasparse/util/thread.h"

#ifndef __COMPAR_FN_T
#define __COMPAR_FN_T
typedef int (*__compar_fn_t)(const void *, const void *);
#endif
16 changes: 8 additions & 8 deletions src/Makefile
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
CFLAGS += $(INC) $(DEFINE)
CPPFLAGS += $(INC) $(DEFINE)

SUBDIRS = core kernel util tuning
SUBDIRS = core kernel util

ifeq ($(HIP_ON),1)
SUBDIRS += util_cpp
SUBDIRS += tuning
endif
ifeq ($(PLAIN_ON),1)
SUBDIRS += plain
endif
ifeq ($(HIP_ON),1)
SUBDIRS += util_cpp
# SUBDIRS += tuning
endif
ifeq ($(ARM_ON),1)
SUBDIRS += tuning
# SUBDIRS += tuning
endif

.PHONY : lib

lib :
lib :
@for d in $(SUBDIRS) ; \
do if test -d $$d; then \
$(MAKE) -C $$d $(@F) || exit 1 ; \
fi; \
done
done
2 changes: 1 addition & 1 deletion src/util/malloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include "alphasparse/util/malloc.h"

#include <malloc.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>

Expand Down
2 changes: 1 addition & 1 deletion src/util_cpp/malloc_dcu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ extern "C" {
}
#endif

#include <malloc.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#ifdef __DCU__
Expand Down
2 changes: 1 addition & 1 deletion test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ test :
# CFLAGS += $(INC) -I$(ROOT)/test/include $(DEFINE)
# CPPFLAGS += $(INC) -I$(ROOT)/test/include $(DEFINE)
# $(TEST_COMMON_OBJS) : $(OBJ_DIR)/%.o : %.c
# $(CC) -c -o $@ $^ $(CFLAGS)
# $(CC) -c -o $@ $^ $(CFLAGS)
2 changes: 1 addition & 1 deletion test/dcu/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ TEST_BIN = $(patsubst %.cpp, $(BIN_DIR)/%, $(notdir $(TEST_SRC)) )
CFLAGS += $(INC) $(LIB) $(DEFINE) -l:libalpha_spblas.a -lm -I$(ROOT)/test

CPPFLAGS += $(INC) $(DEFINE) -I$(ROOT)/test
LDFLAGS += -l:libalpha_spblas.a -lm -lstdc++
LDFLAGS += -l:libalpha_spblas.a -lm -lstdc++
CFLAGS += $(INC) $(DEFINE) -I$(ROOT)/test
include $(ROOT)/Makefile.tail
8 changes: 4 additions & 4 deletions test/x86_64/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ TEST_SRC = $(wildcard $(SRC_DIR)/*.c)
OBJ = $(patsubst $(SRC_DIR)/%.c, $(OBJ_DIR)/%.o, $(TEST_SRC) )
TEST_BIN = $(patsubst $(SRC_DIR)/%.c, $(BIN_DIR)/%, $(TEST_SRC) )

CFLAGS += -lmkl_cdft_core -lmkl_intel_thread -lmkl_core -lpthread -lmkl_rt -ldl
CFLAGS += -lmkl_cdft_core -lmkl_intel_thread -lmkl_core -lpthread -lmkl_rt -ldl
ifeq ($(INT_64),1)
CFLAGS += -lmkl_intel_ilp64
CFLAGS += -lmkl_intel_ilp64
else
CFLAGS += -lmkl_intel_lp64
CFLAGS += -lmkl_intel_lp64
endif
ifeq ($(OPENMP),1)
CFLAGS += -liomp5
endif

CFLAGS += $(INC) $(LIB) $(DEFINE) -l:libalphasparse.a -lm
CFLAGS += $(INC) $(LIB) $(DEFINE) -l:libalpha_spblas.a -lm

include $(ROOT)/Makefile.tail
2 changes: 1 addition & 1 deletion tools/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ TOOL_BIN = $(patsubst %.c, $(BIN_DIR)/%, $(TOOL_SRC) )

CFLAGS = -w -g -O2 -std=c11 -lm

include $(ROOT)/Makefile.tail
include $(ROOT)/Makefile.tail
5 changes: 5 additions & 0 deletions tools/reversible_sparse_gen.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
#include <time.h>
#include <stdint.h>

#ifndef __COMPAR_FN_T
#define __COMPAR_FN_T
typedef int (*__compar_fn_t)(const void *, const void *);
#endif

inline static int random_int(int m)
{
return rand() % m;
Expand Down
5 changes: 5 additions & 0 deletions tools/sparse_gen.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
#include <time.h>
#include <stdint.h>

#ifndef __COMPAR_FN_T
#define __COMPAR_FN_T
typedef int (*__compar_fn_t)(const void *, const void *);
#endif

inline static int random_int(int m)
{
return rand() % m;
Expand Down
5 changes: 5 additions & 0 deletions tools/sparse_gen_symv.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
#include <time.h>
#include <stdint.h>

#ifndef __COMPAR_FN_T
#define __COMPAR_FN_T
typedef int (*__compar_fn_t)(const void *, const void *);
#endif

inline static int random_int(int m)
{
return rand() % m;
Expand Down