-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SPMV is in Sparse Linear Algebra Dwarf. Code added for C, JS, ASM and…
… OpenCL
- Loading branch information
Faiz KHAN
authored and
Faiz KHAN
committed
Mar 13, 2014
1 parent
8675c4d
commit 45eed25
Showing
28 changed files
with
3,930 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
# Makefile for SPMV | ||
# | ||
# | ||
|
||
# DEBUG can be set to YES to include debugging info, or NO otherwise | ||
DEBUG := YES | ||
|
||
# PROFILE can be set to YES to include profiling info, or NO otherwise | ||
PROFILE := NO | ||
|
||
# ------------ name of the executable ---------------------------------------- | ||
EXECUTABLE := spmv | ||
|
||
# ------------ list of all source files -------------------------------------- | ||
SOURCES := csr_spmv.c ../common/common.c ../common/common_args_serial.c \ | ||
../common/sparse_formats.c ../common/ziggurat.c | ||
|
||
# ------------ compiler ------------------------------------------------------ | ||
CC := emcc | ||
CXX := g++ | ||
|
||
# ------------ compiler flags ------------------------------------------------ | ||
DEBUG_CFLAGS := -Wall -O2 -g | ||
RELEASE_CFLAGS := -Wall -O2 | ||
COMMON_CFLAGS := | ||
EMCC_MEMORY := 1000000000 | ||
|
||
# ------------ compiler defs ------------------------------------------------ | ||
DEBUG_CDEFS := -DSERIAL | ||
RELEASE_CDEFS := -DSERIAL | ||
COMMON_CDEFS := | ||
|
||
# ------------ linker flags -------------------------------------------------- | ||
DEBUG_LDFLAGS := -g | ||
RELEASE_LDFLAGS := | ||
COMMON_LDFLAGS := | ||
|
||
ifeq (YES, ${DEBUG}) | ||
CFLAGS := ${DEBUG_CFLAGS} ${DEBUG_CDEFS} | ||
CXXFLAGS := ${DEBUG_CXXFLAGS} ${DEBUG_CDEFS} | ||
LDFLAGS := ${DEBUG_LDFLAGS} | ||
else | ||
CFLAGS := ${RELEASE_CFLAGS} ${RELEASE_CDEFS} | ||
CXXFLAGS := ${RELEASE_CXXFLAGS} ${RELEASE_CDEFS} | ||
LDFLAGS := ${RELEASE_LDFLAGS} | ||
endif | ||
|
||
CFLAGS := ${CFLAGS} ${COMMON_CFLAGS} | ||
CXXFLAGS := ${CXXFLAGS} ${COMMON_CFLAGS} | ||
LDFLAGS := ${LDFLAGS} ${COMMON_LDFLAGS} | ||
|
||
ifeq (YES, ${PROFILE}) | ||
CFLAGS := ${CFLAGS} -pg -O3 | ||
CXXFLAGS := ${CXXFLAGS} -pg -O3 | ||
LDFLAGS := ${LDFLAGS} -pg | ||
endif | ||
|
||
# ------------ additional system include directories ------------------------- | ||
GLOBAL_INC_DIR = | ||
|
||
# ------------ private include directories ----------------------------------- | ||
LOCAL_INC_DIR = ../common | ||
|
||
# ------------ system libraries (e.g. -lm ) --------------------------------- | ||
SYS_LIBS = -lm | ||
|
||
# ------------ additional system library directories ------------------------- | ||
GLOBAL_LIB_DIR = | ||
|
||
# ------------ additional system libraries ----------------------------------- | ||
GLOBAL_LIBS = | ||
|
||
# ------------ private library directories ----------------------------------- | ||
LOCAL_LIB_DIR = | ||
|
||
# ------------ private libraries (e.g. libxyz.a ) --------------------------- | ||
LOCAL_LIBS = | ||
|
||
|
||
C_SOURCES = $(filter %.c, $(SOURCES)) | ||
CPP_SOURCES = $(filter-out %.c, $(SOURCES)) | ||
ALL_INC_DIR = $(addprefix -I, $(LOCAL_INC_DIR) $(GLOBAL_INC_DIR)) | ||
ALL_LIB_DIR = $(addprefix -L, $(LOCAL_LIB_DIR) $(GLOBAL_LIB_DIR)) | ||
GLOBAL_LIBSS = $(addprefix $(GLOBAL_LIB_DIR)/, $(GLOBAL_LIBS)) | ||
LOCAL_LIBSS = $(addprefix $(LOCAL_LIB_DIR)/, $(LOCAL_LIBS)) | ||
ALL_CFLAGS = $(CFLAGS) $(ALL_INC_DIR) | ||
ALL_LFLAGS = $(LDFLAGS) $(ALL_LIB_DIR) | ||
BASENAMES = $(basename $(SOURCES)) | ||
|
||
# ------------ generate the names of the object files ------------------------ | ||
OBJECTS = $(addsuffix .o,$(BASENAMES)) | ||
|
||
# ------------ make the executable (the default goal) ------------------------ | ||
$(EXECUTABLE): $(OBJECTS) | ||
ifeq ($(strip $(CPP_SOURCES)),) | ||
$(CC) $(ALL_LFLAGS) -o $(EXECUTABLE) $(OBJECTS) $(LOCAL_LIBSS) $(GLOBAL_LIBSS) $(SYS_LIBS) | ||
mv $(EXECUTABLE) $(EXECUTABLE).bc | ||
emcc $(EXECUTABLE).bc -o $(EXECUTABLE).js -s TOTAL_MEMORY=$(EMCC_MEMORY) | ||
else | ||
$(CXX) $(ALL_LFLAGS) -o $(EXECUTABLE) $(OBJECTS) $(LOCAL_LIBSS) $(GLOBAL_LIBSS) $(SYS_LIBS) | ||
endif | ||
|
||
# ------------ make the objects ---------------------------------------------- | ||
%.o: %.c | ||
$(CC) -c $(ALL_CFLAGS) $< -o $@ | ||
|
||
%.o: %.cc | ||
$(CXX) -c $(ALL_CFLAGS) $< -o $@ | ||
|
||
%.o: %.cpp | ||
$(CXX) -c $(ALL_CFLAGS) $< -o $@ | ||
|
||
%.o: %.C | ||
$(CXX) -c $(ALL_CFLAGS) $< -o $@ | ||
|
||
clean: | ||
-rm --force $(EXECUTABLE) $(EXECUTABLE).js $(EXECUTABLE).bc $(EXECUTABLE).js.map $(OBJECTS) *~ | ||
|
||
.PHONY: clean | ||
|
||
# ============================================================================== | ||
#C = gcc | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
#ifndef SERIAL | ||
#define SERIAL | ||
#endif | ||
|
||
#include "../common/sparse_formats.h" | ||
#include "../common/common.h" | ||
#include <getopt.h> | ||
#include <stdlib.h> | ||
/** | ||
* Sparse Matrix-Vector Multiply | ||
* | ||
* Multiplies csr matrix by vector x, adds vector y, and stores output in vector out | ||
*/ | ||
void spmv_csr_cpu(const csr_matrix* csr,const float* x,const float* y,float* out) | ||
{ | ||
unsigned int row,row_start,row_end,jj; | ||
float sum = 0; | ||
for(row=0; row < csr->num_rows; row++) | ||
{ | ||
sum = y[row]; | ||
row_start = csr->Ap[row]; | ||
row_end = csr->Ap[row+1]; | ||
|
||
for (jj = row_start; jj < row_end; jj++){ | ||
sum += csr->Ax[jj] * x[csr->Aj[jj]]; | ||
} | ||
out[row] = sum; | ||
} | ||
} | ||
|
||
static struct option long_options[] = { | ||
/* name, has_arg, flag, val */ | ||
{"stddev", 1, NULL, 's'}, | ||
{"density", 1, NULL, 'd'}, | ||
{"size", 1, NULL, 'n'}, | ||
{0,0,0,0} | ||
}; | ||
|
||
int main(int argc, char *argv[]){ | ||
int opt, option_index=0; | ||
unsigned int dim=1024, density=5000; | ||
double normal_stdev=0.01; | ||
unsigned long seed = 10000; | ||
float *v; | ||
stopwatch sw; | ||
|
||
while ((opt = getopt_long(argc, argv, "s:d:n:", long_options, &option_index)) != -1){ | ||
switch(opt){ | ||
case 's': | ||
normal_stdev = atof(optarg); | ||
break; | ||
case 'd': | ||
density = atoi(optarg); | ||
break; | ||
case 'n': | ||
dim = atoi(optarg); | ||
break ; | ||
default: | ||
printf("Usage: %s [-s stddev] [-d density] [-n dimension]", argv[0]); | ||
break; | ||
} | ||
} | ||
|
||
float *sum = malloc(dim*sizeof(*sum)); | ||
float *result = malloc(dim*sizeof(*result)); | ||
memset(sum, 0.0, sizeof(sum)); | ||
memset(result, 0.0, sizeof(result)); | ||
|
||
csr_matrix sm = rand_csr(dim, density, normal_stdev, &seed, stdout); | ||
create_vector_from_random(&v, dim); | ||
|
||
stopwatch_start(&sw); | ||
spmv_csr_cpu(&sm,v,sum, result); | ||
stopwatch_stop(&sw); | ||
|
||
printf("The spmv benchmark took a total time of %lf seconds!\n", get_interval_by_sec(&sw)); | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
# Makefile for SPMV | ||
# | ||
# | ||
|
||
# DEBUG can be set to YES to include debugging info, or NO otherwise | ||
DEBUG := YES | ||
|
||
# PROFILE can be set to YES to include profiling info, or NO otherwise | ||
PROFILE := NO | ||
|
||
# ------------ name of the executable ---------------------------------------- | ||
EXECUTABLE := spmv | ||
|
||
# ------------ list of all source files -------------------------------------- | ||
SOURCES := csr_spmv.c ../common/common.c ../common/common_args_serial.c \ | ||
../common/sparse_formats.c ../common/ziggurat.c | ||
|
||
# ------------ compiler ------------------------------------------------------ | ||
CC := gcc | ||
CXX := g++ | ||
|
||
# ------------ compiler flags ------------------------------------------------ | ||
DEBUG_CFLAGS := -Wall -O0 -g | ||
RELEASE_CFLAGS := -Wall -O3 | ||
COMMON_CFLAGS := -std=c99 | ||
|
||
# ------------ compiler defs ------------------------------------------------ | ||
DEBUG_CDEFS := -DSERIAL | ||
RELEASE_CDEFS := -DSERIAL | ||
COMMON_CDEFS := | ||
|
||
# ------------ linker flags -------------------------------------------------- | ||
DEBUG_LDFLAGS := -g | ||
RELEASE_LDFLAGS := | ||
COMMON_LDFLAGS := | ||
|
||
ifeq (YES, ${DEBUG}) | ||
CFLAGS := ${DEBUG_CFLAGS} ${DEBUG_CDEFS} | ||
CXXFLAGS := ${DEBUG_CXXFLAGS} ${DEBUG_CDEFS} | ||
LDFLAGS := ${DEBUG_LDFLAGS} | ||
else | ||
CFLAGS := ${RELEASE_CFLAGS} ${RELEASE_CDEFS} | ||
CXXFLAGS := ${RELEASE_CXXFLAGS} ${RELEASE_CDEFS} | ||
LDFLAGS := ${RELEASE_LDFLAGS} | ||
endif | ||
|
||
CFLAGS := ${CFLAGS} ${COMMON_CFLAGS} | ||
CXXFLAGS := ${CXXFLAGS} ${COMMON_CFLAGS} | ||
LDFLAGS := ${LDFLAGS} ${COMMON_LDFLAGS} | ||
|
||
ifeq (YES, ${PROFILE}) | ||
CFLAGS := ${CFLAGS} -pg -O3 | ||
CXXFLAGS := ${CXXFLAGS} -pg -O3 | ||
LDFLAGS := ${LDFLAGS} -pg | ||
endif | ||
|
||
# ------------ additional system include directories ------------------------- | ||
GLOBAL_INC_DIR = | ||
|
||
# ------------ private include directories ----------------------------------- | ||
LOCAL_INC_DIR = ../common | ||
|
||
# ------------ system libraries (e.g. -lm ) --------------------------------- | ||
SYS_LIBS = -lm | ||
|
||
# ------------ additional system library directories ------------------------- | ||
GLOBAL_LIB_DIR = | ||
|
||
# ------------ additional system libraries ----------------------------------- | ||
GLOBAL_LIBS = | ||
|
||
# ------------ private library directories ----------------------------------- | ||
LOCAL_LIB_DIR = | ||
|
||
# ------------ private libraries (e.g. libxyz.a ) --------------------------- | ||
LOCAL_LIBS = | ||
|
||
|
||
C_SOURCES = $(filter %.c, $(SOURCES)) | ||
CPP_SOURCES = $(filter-out %.c, $(SOURCES)) | ||
ALL_INC_DIR = $(addprefix -I, $(LOCAL_INC_DIR) $(GLOBAL_INC_DIR)) | ||
ALL_LIB_DIR = $(addprefix -L, $(LOCAL_LIB_DIR) $(GLOBAL_LIB_DIR)) | ||
GLOBAL_LIBSS = $(addprefix $(GLOBAL_LIB_DIR)/, $(GLOBAL_LIBS)) | ||
LOCAL_LIBSS = $(addprefix $(LOCAL_LIB_DIR)/, $(LOCAL_LIBS)) | ||
ALL_CFLAGS = $(CFLAGS) $(ALL_INC_DIR) | ||
ALL_LFLAGS = $(LDFLAGS) $(ALL_LIB_DIR) | ||
BASENAMES = $(basename $(SOURCES)) | ||
|
||
# ------------ generate the names of the object files ------------------------ | ||
OBJECTS = $(addsuffix .o,$(BASENAMES)) | ||
|
||
# ------------ make the executable (the default goal) ------------------------ | ||
$(EXECUTABLE): $(OBJECTS) | ||
ifeq ($(strip $(CPP_SOURCES)),) | ||
$(CC) $(ALL_LFLAGS) -o $(EXECUTABLE) $(OBJECTS) $(LOCAL_LIBSS) $(GLOBAL_LIBSS) $(SYS_LIBS) | ||
else | ||
$(CXX) $(ALL_LFLAGS) -o $(EXECUTABLE) $(OBJECTS) $(LOCAL_LIBSS) $(GLOBAL_LIBSS) $(SYS_LIBS) | ||
endif | ||
|
||
# ------------ make the objects ---------------------------------------------- | ||
%.o: %.c | ||
$(CC) -c $(ALL_CFLAGS) $< -o $@ | ||
|
||
%.o: %.cc | ||
$(CXX) -c $(ALL_CFLAGS) $< -o $@ | ||
|
||
%.o: %.cpp | ||
$(CXX) -c $(ALL_CFLAGS) $< -o $@ | ||
|
||
%.o: %.C | ||
$(CXX) -c $(ALL_CFLAGS) $< -o $@ | ||
|
||
clean: | ||
-rm --force $(EXECUTABLE) $(OBJECTS) *~ | ||
|
||
.PHONY: clean | ||
|
||
# ============================================================================== | ||
#C = gcc | ||
|
||
|
Oops, something went wrong.