Skip to content

Commit d5af573

Browse files
committed
chapter 11 Makefile
1 parent 7d0d84d commit d5af573

File tree

3 files changed

+73
-2
lines changed

3 files changed

+73
-2
lines changed

chapter_10/ch10__spmv.cu

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,11 +227,11 @@ int main(){
227227
printf("Running on Device with 1024 threads per block...");
228228
ch10__spmv(Device, {.block_dim = {1024, 1, 1}, .kernel_version = CH10__SPMV_CSR});
229229

230-
printf("\n_____ spmv [ELL] _____\n\n");
230+
printf("\n_____ spmv [ELL] _____\n");
231231
printf("Running on Device with 1024 threads per block...");
232232
ch10__spmv(Device, {.block_dim = {1024, 1, 1}, .kernel_version = CH10__SPMV_ELL});
233233

234-
printf("\n_____ spmv_CPU [CSR] _____\n\n");
234+
printf("\n_____ spmv_CPU [CSR] _____\n");
235235
ch10__spmv(Host, {});
236236

237237
return 0;

chapter_11/Makefile

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

chapter_11/ch11__merge_sort.cu

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,3 +382,30 @@ void ch11__merge_sort(env_e env, kernel_config_t config){
382382

383383
return;
384384
}
385+
386+
int main(){
387+
printf("Chapter 11\n");
388+
printf("Array A length: %d\n", CH11__A_LENGTH);
389+
printf("Array B length: %d\n", CH11__B_LENGTH);
390+
391+
printf("\n_____ merge_sort _____\n\n");
392+
393+
printf("Running on Device with 256 threads per block...");
394+
ch11__merge_sort(Device, {.block_dim = {256, 1, 1}, .kernel_version = CH11__BASIC_MERGE_SORT});
395+
396+
printf("\n_____ merge_sort_tiled _____\n\n");
397+
398+
printf("Running on Device with 256 threads per block...");
399+
ch11__merge_sort(Device, {.block_dim = {256}, .kernel_version = CH11__TILED_MERGE_SORT});
400+
401+
printf("\n_____ merge_sort_circular_buffer _____\n\n");
402+
403+
printf("Running on Device with 256 threads per block...");
404+
ch11__merge_sort(Device, {.block_dim = {256, 1, 1}, .kernel_version = CH11__CIRCULAR_BUFFER_MERGE_SORT});
405+
406+
407+
printf("\n_____ merge_sort_CPU_____\n");
408+
ch11__merge_sort(Host, {});
409+
410+
return 0;
411+
}

0 commit comments

Comments
 (0)