Makefile 3.28 KB
Newer Older
1
2
3
4
5
6
# This Makefile compiles an HPVM project.
# It builds HPVM-related dependencies, then the user provided code.
#
# Paths to some dependencies (e.g., HPVM, LLVM) must exist in Makefile.config,
# which can be copied from Makefile.config.example for a start.

Adel Ejjeh's avatar
Adel Ejjeh committed
7
CONFIG_FILE := ../include/Makefile.config
8
9
10
11
12
13
14
15
16
17
18
19

ifeq ($(wildcard $(CONFIG_FILE)),)
    $(error $(CONFIG_FILE) not found. See $(CONFIG_FILE).example)
endif
include $(CONFIG_FILE)

# Replace this with the name of your program
EXE_NAME = "exe"

# Compiler Flags
LFLAGS += -lm -lrt

Adel Ejjeh's avatar
Adel Ejjeh committed
20
21
22
23
ifeq ($(TARGET),)
    TARGET = gpu
endif

24
25
26
27
28
29
30
31
# Build dirs
SRC_DIR = src/
BUILD_DIR = build/$(TARGET)
CURRENT_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))

EXE = $(EXE_NAME)-$(TARGET)

INCLUDES += -I$(SRC_DIR)
Yifan Zhao's avatar
Yifan Zhao committed
32
INCLUDES += -I$(LLVM_SRC_ROOT)/include -I../include -I$(HPVM_BUILD_DIR)/include
33
34
35
36

## BEGIN HPVM MAKEFILE
SRCDIR_OBJS= io.ll
OBJS_SRC=src/io.cc
Yifan Zhao's avatar
Yifan Zhao committed
37
HPVM_OBJS=main.hpvm.ll
38
39
40
41
42
43
44
45
46
47
APP = $(EXE)
APP_CFLAGS += $(INCLUDES) -ffast-math -O3 -fno-lax-vector-conversions -fno-vectorize -fno-slp-vectorize
APP_CXXFLAGS += $(INCLUDES) -ffast-math -O3 -fno-lax-vector-conversions -fno-vectorize -fno-slp-vectorize
APP_LDFLAGS=`pkg-config opencv --libs`

CFLAGS = $(APP_CFLAGS) $(PLATFORM_CFLAGS)
OBJS_CFLAGS = $(APP_CFLAGS) $(PLATFORM_CFLAGS)
CXXFLAGS = $(APP_CXXFLAGS) $(PLATFORM_CXXFLAGS)
LDFLAGS= $(APP_LDFLAGS) $(PLATFORM_LDFLAGS)

Adel Ejjeh's avatar
Adel Ejjeh committed
48
HPVM_RT_PATH = $(LLVM_BUILD_DIR)/../build/tools/hpvm/projects/hpvm-rt
Yifan Zhao's avatar
Yifan Zhao committed
49
HPVM_RT_LIB = $(HPVM_RT_PATH)/hpvm-rt.bc
50

Yifan Zhao's avatar
Yifan Zhao committed
51
TESTGEN_OPTFLAGS = -load LLVMGenHPVM.so -genhpvm -globaldce
52
53
54

ifeq ($(TARGET),seq)
  DEVICE = CPU_TARGET
55
56
  HPVM_OPTFLAGS = -load LLVMBuildDFG.so -load LLVMDFG2LLVM_CPU.so -load LLVMClearDFG.so -dfg2llvm-cpu -clearDFG
  HPVM_OPTFLAGS += -hpvm-timers-cpu
57
58
else
  DEVICE = GPU_TARGET
Yifan Zhao's avatar
Yifan Zhao committed
59
  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
60
  HPVM_OPTFLAGS += -hpvm-timers-cpu -hpvm-timers-ptx
61
endif
Yifan Zhao's avatar
Yifan Zhao committed
62
  TESTGEN_OPTFLAGS += -hpvm-timers-gen
63
64
65
66
67
68
69
70
71
72

CFLAGS += -DDEVICE=$(DEVICE)
CXXFLAGS += -DDEVICE=$(DEVICE)

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

.PRECIOUS: $(BUILD_DIR)/%.ll

OBJS = $(call INBUILDDIR,$(SRCDIR_OBJS))
Yifan Zhao's avatar
Yifan Zhao committed
73
TEST_OBJS = $(call INBUILDDIR,$(HPVM_OBJS))
74
75
KERNEL = $(TEST_OBJS).kernels.ll

Adel Ejjeh's avatar
Adel Ejjeh committed
76
ifeq ($(TARGET),gpu)
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
  KERNEL_OCL = $(TEST_OBJS).kernels.cl
endif

HOST_LINKED = $(BUILD_DIR)/$(APP).linked.ll
HOST = $(BUILD_DIR)/$(APP).host.ll

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

# Targets
default: $(FAILSAFE) $(BUILD_DIR) $(KERNEL_OCL) $(EXE)

Adel Ejjeh's avatar
Adel Ejjeh committed
92
93
94
95
96
clean :
	if [ -f $(EXE) ]; then rm $(EXE); fi
	if [ -f DataflowGraph.dot ]; then rm DataflowGraph.dot*; fi
	if [ -d $(BUILD_DIR) ]; then rm -rf $(BUILD_DIR); fi

97
$(KERNEL_OCL) : $(KERNEL)
Adel Ejjeh's avatar
Adel Ejjeh committed
98
	$(OCLBE) $< -o $@
99
100
101
102

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

Yifan Zhao's avatar
Yifan Zhao committed
103
$(HOST_LINKED) : $(HOST) $(OBJS) $(HPVM_RT_LIB)
104
105
	$(LLVM_LINK) $^ -S -o $@

Yifan Zhao's avatar
Yifan Zhao committed
106
107
$(HOST) $(KERNEL): $(BUILD_DIR)/$(HPVM_OBJS)
	$(OPT) $(HPVM_OPTFLAGS) -S $< -o $(HOST)
108
109
110
111
112
113
114
115
116
117

$(BUILD_DIR):
	mkdir -p $(BUILD_DIR)

$(BUILD_DIR)/%.ll : $(SRC_DIR)/%.cc
	$(CC) $(OBJS_CFLAGS) -emit-llvm -S -o $@ $<

$(BUILD_DIR)/main.ll : $(SRC_DIR)/main.cc
	$(CC) $(CXXFLAGS) -emit-llvm -S -o $@ $<

Yifan Zhao's avatar
Yifan Zhao committed
118
$(BUILD_DIR)/main.hpvm.ll : $(BUILD_DIR)/main.ll
Adel Ejjeh's avatar
Adel Ejjeh committed
119
	$(OPT) $(TESTGEN_OPTFLAGS) $< -S -o $@
120
121

## END HPVM MAKEFILE