-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
121 lines (98 loc) · 2.83 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
APP ?=vararg_gpu
OPT ?=-O3 -Xarch_device -fno-builtin -v
CC = clang
CXX = clang++
bin: bin/$(APP)
target: bin
STD = -std=c++2a
CFLAGS = -Wall -Iinclude -nogpuinc #-std=c++2a
comma:= ,
star:= *
ifdef GPUFUN
CFLAGS += -DGPUFUN=$(GPUFUN)
endif
ifdef CPUFUN
CFLAGS += -DCPUFUN="$(CPUFUN)"
endif
ifdef PREFIX
CFLAGS += -DPREFIX=$(PREFIX)
endif
ifndef ARGS
ARGS=float,float
endif
# Finding the number of arguments as the number of commas plus one. The first comma is to increment by one.
ifdef NARGS
CFLAGS += -DNARGS=$(NARGS)
else
CFLAGS += -DNARGS=$(shell echo ,$(ARGS) | tr -cd , | wc -c)
endif
# Defining argument types with and without pointers
ifdef ARGS
CFLAGS += -DARGS="$(subst $(star),,$(ARGS))"
CFLAGS += -DPTRARGS="$(ARGS)"
endif
ifdef RETTYPE
CFLAGS += -DRETTYPE="$(RETTYPE)"
endif
# If the return type is void, this case must be handled in a special way.
ifeq ($(RETTYPE),void)
CFLAGS += -DVOIDRETTYPE
endif
getarg = $(word $1,$(subst $(comma), ,$(ARGS)))
ifneq ($(findstring $(star),$(call getarg,1)),)
CFLAGS += -DARG1POINTER
endif
ifneq ($(findstring $(star),$(call getarg,2)),)
CFLAGS += -DARG2POINTER
endif
ifneq ($(findstring $(star),$(call getarg,3)),)
CFLAGS += -DARG3POINTER
endif
WRAPPERARGS=
WRAPPERNAMES=
getarg = $(word $1,$(subst $(comma), ,$(ARGS)))
ifneq ($(call getarg,1),)
WRAPPERARGS += $(call getarg,1) x
WRAPPERNAMES += x
endif
ifneq ($(call getarg,2),)
WRAPPERARGS += ,$(call getarg,2) y
WRAPPERNAMES += ,y
endif
ifneq ($(call getarg,3),)
WRAPPERARGS += ,$(call getarg,3) z
WRAPPERNAMES += ,z
endif
CFLAGS += -DWRAPPERARGS="$(WRAPPERARGS)" -DWRAPPERNAMES="$(WRAPPERNAMES)"
OMPTARGET?=amdgcn-amd-amdhsa
GPUARCH?=gfx906
CFLAGS += -fopenmp
CFLAGS += -fopenmp-targets=$(OMPTARGET) --offload-arch=$(GPUARCH)
CFLAGS += -fopenmp-offload-mandatory #--offload-device-only
LDFLAGS += -foffload-lto -L$(LLVMDIR)/install/lib -lomp
LDFLAGS += -L$(LLVMDIR)/install/lib -lomptarget
LDFLAGS += -L$(LLVMDIR)/install/lib -lomptarget.devicertl
LDFLAGS += -L$(LLVMDIR)/install/lib/x86_64-unknown-linux-gnu -lmgpu -lcgpu
LDFLAGS += -lm
#LDFLAGS += -Xlinker --verbose
# Compiling source to binary
bin/$(APP): src/$(APP).cpp
$(CXX) $(STD) $(OPT) $(CFLAGS) src/$(APP).cpp -o bin/$(APP) $(LDFLAGS)
.PHONY: clean ir temps
clean:
rm -rf bin/* ir/* *.core ast/* *.bc *.o *.s *.ii *.ll $(APP)*.out $(APP)*.img $(APP)*.i $(APP)*.s *.i *.img
ir:
$(CXX) $(STD) $(OPT) $(CFLAGS) -emit-llvm -S src/$(APP).cpp -o ir/$(APP).ll
temps: clean
rm -rf $(TMPOUT)
mkdir -p $(TMPOUT)
$(CC) $(OPT) $(CFLAGS) -save-temps src/$(APP).c -o $(APP).o $(LDFLAGS)
mv $(APP)*.o $(TMPOUT)
mv $(APP)*.bc $(TMPOUT)
#mv $(APP)*.ii $(TMPOUT)
mv $(APP)*.i $(TMPOUT)
mv $(APP)*.s $(TMPOUT)
mv $(APP)*.out $(TMPOUT)
mv $(APP)*.img $(TMPOUT)
llvm-dis $(TMPOUT)/*.bc
llvm-objdump -d $(TMPOUT)/$(APP).o.amdgcn-amd-amdhsa.$(GPUARCH).o > $(TMPOUT)/$(APP).o.amdgcn-amd-amdhsa.$(GPUARCH).o.objdump