hpvm.mk 5.01 KB
Newer Older
1
2
3
4
# (c) 2007 The Board of Trustees of the University of Illinois.

# Default language wide options
LANG_CFLAGS=-I$(PARBOIL_ROOT)/common/include
5
LANG_CXXFLAGS=$(LANG_CFLAGS)  
6
LANG_LDFLAGS=-lOpenCL -L$(OPENCL_LIB_PATH) -lrt -L$(CUDA_LIB_PATH) -lcudart
7
8
9
10
11

CFLAGS=$(LANG_CFLAGS) $(PLATFORM_CFLAGS) $(APP_CFLAGS)
CXXFLAGS=$(LANG_CXXFLAGS) $(PLATFORM_CXXFLAGS) $(APP_CXXFLAGS)
LDFLAGS=$(LANG_LDFLAGS) $(PLATFORM_LDFLAGS) $(APP_LDFLAGS)

Yifan Zhao's avatar
Yifan Zhao committed
12
# HPVM
Akash Kothari's avatar
Akash Kothari committed
13
HPVM_RT_PATH = $(LLVM_BUILD_DIR)/tools/hpvm/projects/hpvm-rt
14

Yifan Zhao's avatar
Yifan Zhao committed
15
HPVM_RT_LIB = $(HPVM_RT_PATH)/hpvm-rt.bc
16

Yifan Zhao's avatar
Yifan Zhao committed
17
TESTGEN_OPTFLAGS = -load LLVMGenHPVM.so -genhpvm -globaldce
18
KERNEL_GEN_FLAGS = -O3 -target nvptx64-nvidia-nvcl
19

Akash Kothari's avatar
Akash Kothari committed
20
ifeq ($(TARGET),seq)
21
  DEVICE = CPU_TARGET
22
  HPVM_OPTFLAGS = -load LLVMBuildDFG.so -load LLVMDFG2LLVM_CPU.so -load LLVMClearDFG.so -dfg2llvm-cpu -clearDFG
23
else
24
  DEVICE = GPU_TARGET
Yifan Zhao's avatar
Yifan Zhao committed
25
  HPVM_OPTFLAGS = -load LLVMBuildDFG.so -load LLVMLocalMem.so -load LLVMDFG2LLVM_OpenCL.so -load LLVMDFG2LLVM_CPU.so -load LLVMClearDFG.so -localmem -dfg2llvm-nvptx -dfg2llvm-cpu -clearDFG
26
27
endif

28
29
30
CFLAGS += -DDEVICE=$(DEVICE)
CXXFLAGS += -DDEVICE=$(DEVICE)

31
32
HOST_LINKFLAGS =

33
34
ifeq ($(TIMER),cpu)
  HPVM_OPTFLAGS += -hpvm-timers-cpu
35
else ifeq ($(TIMER),gen)
Yifan Zhao's avatar
Yifan Zhao committed
36
  TESTGEN_OPTFLAGS += -hpvm-timers-gen
37
38
else ifeq ($(TIMER),no)
else
Akash Kothari's avatar
Akash Kothari committed
39
  ifeq ($(TARGET),seq)
40
    HPVM_OPTFLAGS += -hpvm-timers-cpu
41
  else
42
    HPVM_OPTFLAGS += -hpvm-timers-cpu -hpvm-timers-ptx
43
  endif
Yifan Zhao's avatar
Yifan Zhao committed
44
  TESTGEN_OPTFLAGS += -hpvm-timers-gen
45
endif
46

47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# Rules common to all makefiles

########################################
# Functions
########################################

# Add BUILDDIR as a prefix to each element of $1
INBUILDDIR=$(addprefix $(BUILDDIR)/,$(1))

# Add SRCDIR as a prefix to each element of $1
INSRCDIR=$(addprefix $(SRCDIR)/,$(1))

########################################
# Environment variable check
########################################

63
64
OPENCV_LIB_PATH=${OpenCV_DIR}/lib

65
66
67
68
69
70
71
72
73
74
75
76
# The second-last directory in the $(BUILDDIR) path
# must have the name "build".  This reduces the risk of terrible
# accidents if paths are not set up correctly.
ifeq ("$(notdir $(BUILDDIR))", "")
$(error $$BUILDDIR is not set correctly)
endif

ifneq ("$(notdir $(patsubst %/,%,$(dir $(BUILDDIR))))", "build")
$(error $$BUILDDIR is not set correctly)
endif

.PHONY: run
Prakalp Srivastava's avatar
Prakalp Srivastava committed
77
.PRECIOUS: $(BUILDDIR)/%.ll
78
79
80
81
82
83
84
85
86
87
88
89

ifeq ($(OPENCL_PATH),)
FAILSAFE=no_opencl
else 
FAILSAFE=
endif

########################################
# Derived variables
########################################

OBJS = $(call INBUILDDIR,$(SRCDIR_OBJS))
Yifan Zhao's avatar
Yifan Zhao committed
90
TEST_OBJS = $(call INBUILDDIR,$(HPVM_OBJS))
91
PARBOIL_OBJS = $(call INBUILDDIR,parboil.ll)
92
KERNEL = $(TEST_OBJS).kernels.ll
Akash Kothari's avatar
Akash Kothari committed
93
ifeq ($(TARGET),seq)
94
else
95
  KERNEL_OCL = $(TEST_OBJS).kernels.cl
96
endif
97
98
HOST_LINKED = $(BUILDDIR)/$(APP).linked.ll
HOST = $(BUILDDIR)/$(APP).host.ll
99

100
101
102
103
104
105
106
107
ifeq ($(DEBUGGER),)
DEBUGGER=gdb
endif

########################################
# Rules
########################################

108
default: $(FAILSAFE) $(BUILDDIR) $(KERNEL_OCL) $(SPIR_ASSEMBLY) $(BIN)
109
#default: $(FAILSAFE) $(BUILDDIR) $(BIN)
110
111

run : $(RUNDIR)
112
113
	echo "Resolving CUDA library..."
	$(shell echo $(RUNTIME_ENV)) LD_LIBRARY_PATH=$(CUDA_LIB_PATH) ldd ./$(BIN) | grep cuda
114
115
	#echo "Resolving OpenCV library..."
	#$(shell echo $(RUNTIME_ENV)) LD_LIBRARY_PATH=$(OPENCV_LIB_PATH) ldd ./$(BIN) | grep opencv
116
	$(shell echo $(RUNTIME_ENV)) LD_LIBRARY_PATH=$(OPENCL_LIB_PATH):$(OPENCV_LIB_PATH):$(CUDA_LIB_PATH) ./$(BIN) $(ARGS)
117
	$(TOOL) $(OUTPUT) $(REF_OUTPUT)
118
119
120
121
122
123
124

debug:
	@echo "Resolving OpenCL library..."
	@$(shell echo $(RUNTIME_ENV)) LD_LIBRARY_PATH=$(OPENCL_LIB_PATH) ldd $(BIN) | grep OpenCL
	@$(shell echo $(RUNTIME_ENV)) LD_LIBRARY_PATH=$(OPENCL_LIB_PATH) $(DEBUGGER) --args $(BIN) $(ARGS)

clean :
125
	rm -rf $(BUILDDIR)/*
Adel Ejjeh's avatar
Adel Ejjeh committed
126
127
	if [ -f $(BIN) ]; then rm $(BIN); fi
	if [ -f DataflowGraph.dot ]; then rm DataflowGraph.dot*; fi
128
	if [ -d $(BUILDDIR) ]; then rm -rf $(BUILDDIR); fi
129
	if [ -d $(RUNDIR) ]; then rm -rf $(RUNDIR); fi
130

Akash Kothari's avatar
Akash Kothari committed
131
$(KERNEL_OCL) : $(KERNEL)
132
	$(OCLBE) $< -o $@
133
134
135
136

$(BIN) : $(HOST_LINKED)
	$(CXX) -O3 $(LDFLAGS) $< -o $@

Yifan Zhao's avatar
Yifan Zhao committed
137
$(HOST_LINKED) : $(HOST) $(OBJS) $(BUILDDIR)/parboil.ll $(HPVM_RT_LIB)
138
139
	$(LLVM_LINK) $^ -S -o $@

Yifan Zhao's avatar
Yifan Zhao committed
140
141
$(HOST) $(KERNEL): $(BUILDDIR)/$(HPVM_OBJS)
	$(OPT) $(HPVM_OPTFLAGS) -S $< -o $(HOST)
142
143
144
145
146
147
148
149
150
151

$(RUNDIR) :
	mkdir -p $(RUNDIR)

$(BUILDDIR) :
	mkdir -p $(BUILDDIR)

$(BUILDDIR)/%.ll: $(SRCDIR)/%.c
	$(CC) $(CFLAGS) -S -emit-llvm $< -o $@

152
153
154
$(BUILDDIR)/%.ll : $(SRCDIR)/%.cc
	$(CXX) $(CXXFLAGS) -S -emit-llvm $< -o $@

155
156
157
$(BUILDDIR)/%.ll : $(SRCDIR)/%.cpp
	$(CXX) $(CXXFLAGS) -S -emit-llvm $< -o $@

Yifan Zhao's avatar
Yifan Zhao committed
158
$(BUILDDIR)/%.hpvm.ll: $(BUILDDIR)/%.ll
159
	$(OPT) $(TESTGEN_OPTFLAGS) $< -S -o $@
160
161
162
163
164
165
166
167
168
169
170
171
172

$(BUILDDIR)/%.o : $(SRCDIR)/%.c
	$(CC) $(CFLAGS) -c $< -o $@

$(BUILDDIR)/parboil.ll : $(PARBOIL_ROOT)/common/src/parboil.c
	$(CC) $(CFLAGS) -S -emit-llvm $< -o $@

$(BUILDDIR)/%.o : $(SRCDIR)/%.cc
	$(CXX) $(CXXFLAGS) -c $< -o $@

$(BUILDDIR)/%.o : $(SRCDIR)/%.cpp
	$(CXX) $(CXXFLAGS) -c $< -o $@

173
174
175
$(BUILDDIR)/%.o : $(SRCDIR)/%.cpp
	$(CXX) $(CXXFLAGS) -c $< -o $@

176
177
178
179
180
no_opencl:
	@echo "OPENCL_PATH is not set. Open $(PARBOIL_ROOT)/common/Makefile.conf to set default value."
	@echo "You may use $(PLATFORM_MK) if you want a platform specific configurations."
	@exit 1