Makefile 3.13 KB
Newer Older
bjschre2's avatar
bjschre2 committed
1
# This Makefile compiles the HPVM-pipeline test.
2
3
4
5
6
# 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
20
21
ifeq ($(TARGET),)
    TARGET = gpu
endif

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

EXE = pipeline-$(TARGET)

29
INCLUDES += -I$(SRC_DIR)
30

31
## BEGIN HPVM MAKEFILE
Yifan Zhao's avatar
Yifan Zhao committed
32
SRCDIR_OBJS=
Yifan Zhao's avatar
Yifan Zhao committed
33
HPVM_OBJS=main.hpvm.ll
34
APP = $(EXE)
35
36
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
37
38
39
40
41
42
43
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)

Akash Kothari's avatar
Akash Kothari committed
44
HPVM_RT_PATH = $(LLVM_BUILD_DIR)/tools/hpvm/projects/hpvm-rt
Yifan Zhao's avatar
Yifan Zhao committed
45
HPVM_RT_LIB = $(HPVM_RT_PATH)/hpvm-rt.bc
46

Yifan Zhao's avatar
Yifan Zhao committed
47
TESTGEN_OPTFLAGS = -load LLVMGenHPVM.so -genhpvm -globaldce
48
49
50

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

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
69
TEST_OBJS = $(call INBUILDDIR,$(HPVM_OBJS))
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
KERNEL = $(TEST_OBJS).kernels.ll

ifeq ($(TARGET),seq)
else
  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
89
90
91
92
93
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

94
$(KERNEL_OCL) : $(KERNEL)
Yifan Zhao's avatar
Yifan Zhao committed
95
	$(OCLBE) $< -o $@
96
97
98
99

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

Yifan Zhao's avatar
Yifan Zhao committed
100
$(HOST_LINKED) : $(HOST) $(OBJS) $(HPVM_RT_LIB)
101
102
	$(LLVM_LINK) $^ -S -o $@

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

$(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
115
$(BUILD_DIR)/main.hpvm.ll : $(BUILD_DIR)/main.ll
Yifan Zhao's avatar
Yifan Zhao committed
116
	$(OPT) $(TESTGEN_OPTFLAGS) $< -S -o $@
117
118

## END HPVM MAKEFILE