Skip to content

Commit 7d0d84d

Browse files
committed
chapter 10 Makefile
1 parent 5d08d6f commit 7d0d84d

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

chapter_10/Makefile

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
CC = nvcc
2+
OBJDIR = ./obj
3+
4+
DEPSNAMES = \
5+
nvixnu__array_utils \
6+
nvixnu__populate_arrays_utils \
7+
nvixnu__error_utils
8+
9+
CFLAGS = -g -G --compiler-options -Wall -lm
10+
11+
INCLUDES = $(patsubst %,-I ../../%, $(DEPSNAMES))
12+
13+
# List with all .cu files inside $(REPOSDIR)/<repoName>
14+
CUFILES = $(foreach dep,$(DEPSNAMES), $(wildcard ../../$(dep)/*.cu))
15+
16+
# List with all .o paths
17+
OBJS = $(patsubst %.cu,%.o,$(CUFILES))
18+
19+
# Compiled objects path
20+
COMPILEDOBJS := $(patsubst %,$(OBJDIR)/%,$(notdir $(OBJS)))
21+
22+
# Creates the obj dir, compiles each dependency and then the main app
23+
all: objdir $(OBJS)
24+
nvcc ch10__spmv.cu -o spmv.out $(COMPILEDOBJS) $(CFLAGS) $(INCLUDES)
25+
26+
# Creates the ./obj dir
27+
objdir:
28+
mkdir -p $(OBJDIR)
29+
30+
# Compile a dependency
31+
%.o: %.cu
32+
nvcc -c $< -o $(OBJDIR)/$(notdir $@) $(CFLAGS)
33+
34+
# Run the executable
35+
run:
36+
./main
37+
38+
# Remove the generated artifacts
39+
clean:
40+
rm -Rf $(OBJDIR)/*.o
41+
rm -Rf spmv.out
42+
43+
.PHONY: all clean app run objdir

chapter_10/ch10__spmv.cu

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,3 +215,24 @@ void ch10__spmv(env_e env, kernel_config_t config){
215215

216216
return;
217217
}
218+
219+
int main(){
220+
printf("Chapter 10\n");
221+
printf("Matrix dimensions: %dx%d\n", CH10__INPUT_ROWS, CH10__INPUT_COLS);
222+
printf("Matrix nonzeros: %d\n", CH10__INPUT_NON_ZERO_LENGTH);
223+
printf("Matrix largest nz row width: %d\n", CH10__INPUT_LARGEST_NONZERO_ROW_WIDTH);
224+
225+
printf("\n_____ spmv [CSR] _____\n\n");
226+
227+
printf("Running on Device with 1024 threads per block...");
228+
ch10__spmv(Device, {.block_dim = {1024, 1, 1}, .kernel_version = CH10__SPMV_CSR});
229+
230+
printf("\n_____ spmv [ELL] _____\n\n");
231+
printf("Running on Device with 1024 threads per block...");
232+
ch10__spmv(Device, {.block_dim = {1024, 1, 1}, .kernel_version = CH10__SPMV_ELL});
233+
234+
printf("\n_____ spmv_CPU [CSR] _____\n\n");
235+
ch10__spmv(Host, {});
236+
237+
return 0;
238+
}

0 commit comments

Comments
 (0)