Makefile 3.35 KB
Newer Older
1
2
3
4
5
6
# This Makefile compiles the HPVM-CAVA pilot project. 
# It builds HPVM-related dependencies, then the native camera pipeline ISP 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.

Akash Kothari's avatar
Akash Kothari committed
7
CONFIG_FILE := ../include/Makefile.config
8
9
10
11
12
13
14
15
16
17

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

# Compiler Flags

LFLAGS += -lm -lrt

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

# Build dirs
23
24
SRC_DIR = src/
CAM_PIPE_SRC_DIR = $(SRC_DIR)
Adel Ejjeh's avatar
Adel Ejjeh committed
25
BUILD_DIR = build/$(TARGET)
26
27
28
CURRENT_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))


29
INCLUDES += -I$(SRC_DIR) -I$(CAM_PIPE_SRC_DIR)
30
ifneq ($(CONFUSE_ROOT),)
31
32
  INCLUDES += -I$(CONFUSE_ROOT)/include
  LFLAGS += -L$(CONFUSE_ROOT)/lib
33
34
endif

Akash Kothari's avatar
Akash Kothari committed
35
EXE = cava-hpvm-$(TARGET)
36
37
38
39

LFLAGS += -pthread

## BEGIN HPVM MAKEFILE
Yifan Zhao's avatar
Yifan Zhao committed
40
LANGUAGE=hpvm
Yifan Zhao's avatar
Yifan Zhao committed
41
42
SRCDIR_OBJS=load_cam_model.ll cam_pipe_utility.ll utility.ll
OBJS_SRC=src/load_cam_model.c src/cam_pipe_utility.c src/utility.c
Yifan Zhao's avatar
Yifan Zhao committed
43
HPVM_OBJS=main.hpvm.ll
44
45
46
47
48
49
50
51
52
53
54
APP = $(EXE)
APP_CUDALDFLAGS=-lm -lstdc++
APP_CFLAGS= $(INCLUDES) -DDMA_MODE -DDMA_INTERFACE_V3
APP_CXXFLAGS=-ffast-math -O0 -I/opt/opencv/include
APP_LDFLAGS=$(LFLAGS)

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

Akash Kothari's avatar
Akash Kothari committed
55
HPVM_RT_PATH = $(LLVM_BUILD_DIR)/tools/hpvm/projects/hpvm-rt
56

Yifan Zhao's avatar
Yifan Zhao committed
57
HPVM_RT_LIB = $(HPVM_RT_PATH)/hpvm-rt.bc
58
59


Yifan Zhao's avatar
Yifan Zhao committed
60
TESTGEN_OPTFLAGS = -load LLVMGenHPVM.so -genhpvm -globaldce
61
62
63

ifeq ($(TARGET),seq)
  DEVICE = CPU_TARGET
64
65
  HPVM_OPTFLAGS = -load LLVMBuildDFG.so -load LLVMDFG2LLVM_CPU.so -load LLVMClearDFG.so -dfg2llvm-cpu -clearDFG
  HPVM_OPTFLAGS += -hpvm-timers-cpu
66
67
else
  DEVICE = GPU_TARGET
Yifan Zhao's avatar
Yifan Zhao committed
68
  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
69
  HPVM_OPTFLAGS += -hpvm-timers-cpu -hpvm-timers-ptx
70
endif
Yifan Zhao's avatar
Yifan Zhao committed
71
  TESTGEN_OPTFLAGS += -hpvm-timers-gen
72
73
74
75
76
77
78
79
80
81

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
82
TEST_OBJS = $(call INBUILDDIR,$(HPVM_OBJS))
83
84
KERNEL = $(TEST_OBJS).kernels.ll

85
ifeq ($(TARGET),gpu)
86
87
88
89
90
91
92
93
94
95
96
97
98
  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
Adel Ejjeh's avatar
Adel Ejjeh committed
99

100
101
default: $(FAILSAFE) $(BUILD_DIR) $(KERNEL_OCL) $(EXE)

Adel Ejjeh's avatar
Adel Ejjeh committed
102
103
104
105
106
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

107
$(KERNEL_OCL) : $(KERNEL)
108
	$(OCLBE) $< -o $@
109
110
111
112

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

Yifan Zhao's avatar
Yifan Zhao committed
113
$(HOST_LINKED) : $(HOST) $(OBJS) $(HPVM_RT_LIB)
114
115
	$(LLVM_LINK) $^ -S -o $@

Yifan Zhao's avatar
Yifan Zhao committed
116
117
$(HOST) $(KERNEL): $(BUILD_DIR)/$(HPVM_OBJS)
	$(OPT) $(HPVM_OPTFLAGS) -S $< -o $(HOST)
118
119
120
121
122
123
124
125
126
127

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

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

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

Yifan Zhao's avatar
Yifan Zhao committed
128
$(BUILD_DIR)/main.hpvm.ll : $(BUILD_DIR)/main.ll
129
	$(OPT) $(TESTGEN_OPTFLAGS) $< -S -o $@
130
131

## END HPVM MAKEFILE