This repository has been archived by the owner on Nov 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathMakefile
183 lines (153 loc) · 5.5 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
NAME=graphpipe-tf
RUN_TYPE?=cpu
TF_DIR=/usr/local
SUDO=sudo
LIBTF_IMAGE=libtensorflow
GRAPHPIPE_TF_IMAGE=graphpipe-tf
DOCKER=docker
MODEL_URL?=https://objectstorage.us-phoenix-1.oraclecloud.com/n/bmcskeppareuser/b/c4/o/squeezenet.pb
ifeq ('$(USE_SUDO)', '0')
SUDO=
endif
ifeq ('$(RUN_TYPE)', 'gpu')
DOCKER=nvidia-docker
LD_STUBS=LD_LIBRARY_PATH=/usr/local/cuda/lib64/stubs/:$$LD_LIBRARY_PATH
endif
sha = $(shell git rev-parse --short HEAD | tr -d ' \n')
ifeq ($(VERSION),)
VERSION = $(shell git describe --tags --match 'v*.*.*' 2> /dev/null | tr -d 'v \n')
realv = $(shell echo $(VERSION) | cut -d- -f1)
ifneq ($(VERSION),$(realv))
commits = $(shell echo $(VERSION) | cut -d- -f2)
VERSION := $(realv).$(commits).$(sha)
endif
endif
dirty = $(shell git diff --shortstat 2> /dev/null | tail -n1 | tr -d ' \n')
ifneq ($(dirty),)
VERSION := $(VERSION).dev
endif
.PHONY: $(NAME)
in-docker:
docker inspect --type=image $(LIBTF_IMAGE):$(RUN_TYPE)-dev > /dev/null || make dev-container
docker run -it --rm \
-v $(PWD)/../../:/go/src/github.com/oracle/graphpipe-go \
-w /go/src/github.com/oracle/graphpipe-go/cmd/graphpipe-tf \
-e http_proxy=$(http_proxy) \
-e https_proxy=$(https_proxy) \
-e USE_SUDO=0 \
-e GOPATH=/go \
-e CHOWN=$$(id -u):$$(id -g) \
$(LIBTF_IMAGE):$(RUN_TYPE)-dev \
/usr/bin/make install-govendor deps $(RUN_TYPE) copy-files-$(RUN_TYPE) graphpipe-tf fix-perms
check-go-version:
$(eval min_version := go1.8)
$(eval lesser_version=$(shell echo "`go version | cut -d " " -f3` ${min_version}" | tr " " "\n" | sort -s -t- -k 2,2nr | sort -t. -s -k 1,1nr -k 2,2nr -k 3,3nr -k 4,4nr | tail -1))
@if [ "${min_version}" != "${lesser_version}" ]; then \
echo "minimum go version is ${min_version}. You have ${lesser_version}"; \
exit 1;\
fi
$(NAME): check-go-version
$(LD_STUBS) go build -ldflags '-X "main.ver=$(VERSION)" -X "main.sha=$(sha)"'
local: $(NAME)
cpu:
# pass
copy-files-cpu:
mkdir -p lib
cp /root/.cache/bazel/_bazel_root/*/external/mkl_linux/lib/* lib/
cp /usr/local/lib/libtensorflow* lib/
oraclelinux-cpu:
# pass
copy-files-oraclelinux-cpu:
mkdir -p lib
cp /root/.cache/bazel/_bazel_root/*/external/mkl_linux/lib/* lib/
cp /usr/local/lib/libtensorflow* lib/
gpu:
ln -s /usr/local/cuda/lib64/stubs/libcuda.so /usr/local/cuda/lib64/libcuda.so.1
copy-files-gpu:
mkdir -p lib
cp /root/.cache/bazel/_bazel_root/*/external/mkl_linux/lib/* lib/
cp /usr/local/lib/libtensorflow* lib/
devshell:
docker run -it --rm \
-v $(PWD)/../../:/go/src/github.com/oracle/graphpipe-go \
-w /go/src/github.com/oracle/graphpipe-go/cmd/graphpipe-tf \
-p 9000:9000 \
-e http_proxy=$(http_proxy) \
-e https_proxy=$(https_proxy) \
-e GOPATH=/go \
$(LIBTF_IMAGE):$(RUN_TYPE)-dev \
/bin/bash
dev-container:
docker build \
-f Dockerfile.$(RUN_TYPE)-dev \
-t $(LIBTF_IMAGE):$(RUN_TYPE)-dev \
--build-arg http_proxy=$(http_proxy) \
--build-arg https_proxy=$(https_proxy) \
.
devserver:
$(DOCKER) run -it --rm \
-v $(PWD)/../../:/go/src/github.com/oracle/graphpipe-go \
-w /go/src/github.com/oracle/graphpipe-go/cmd/graphpipe-tf \
-e http_proxy=$(http_proxy) \
-e https_proxy=$(https_proxy) \
-p 9000:9000 \
-e GOPATH=/go \
$(LIBTF_IMAGE):$(RUN_TYPE)-dev \
./graphpipe-tf --model=$(MODEL_URL) \
--listen=0.0.0.0:9000
runtime-container:
docker build \
-f Dockerfile.$(RUN_TYPE) \
-t $(GRAPHPIPE_TF_IMAGE):$(RUN_TYPE) \
--build-arg http_proxy=$(http_proxy) \
--build-arg https_proxy=$(https_proxy) \
.
runserver:
$(DOCKER) run -it --rm \
-e http_proxy=$(http_proxy) \
-e https_proxy=$(https_proxy) \
-p 9000:9000 \
$(GRAPHPIPE_TF_IMAGE):$(RUN_TYPE) \
--model=$(MODEL_URL) \
--listen=0.0.0.0:9000
install-govendor:
@if [ ! -e $(GOPATH)/bin/govendor ]; then \
go get -u github.com/kardianos/govendor; \
fi
govendor:
@if [ ! -e $(GOPATH)/bin/govendor ]; then \
echo "You need govendor: go get -u github.com/kardianos/govendor" && exit 1; \
fi
graphpipe-go-deps:
cd ../../ && make deps
go-deps: govendor
$(GOPATH)/bin/govendor sync -v
install-tensorflow:
@if [ ! -e /usr/local/include/tensorflow/c/c_api.h ]; then \
curl -L "https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-$(RUN_TYPE)-linux-x86_64-1.8.0.tar.gz" | \
$(SUDO) tar -C $(TF_DIR) -xz; \
fi
tensorflow:
@if [ ! -e /usr/local/include/tensorflow/c/c_api.h ]; then \
echo "You need tensorflow installed: https://www.tensorflow.org/install/install_go" && exit 1; \
fi
fix-perms:
@if [ -n "$${CHOWN}" ]; then \
chown -R $${CHOWN} lib vendor $(NAME) ../../vendor; \
fi
PROTOC=protoc
TF=$(GOPATH)/src/github.com/tensorflow/tensorflow
PROTOS = $(TF)/tensorflow/core/protobuf/config.proto \
$(TF)/tensorflow/core/protobuf/debug.proto \
$(TF)/tensorflow/core/protobuf/cluster.proto \
$(TF)/tensorflow/core/protobuf/rewriter_config.proto
protobuf:
go get github.com/gogo/protobuf/proto
go get github.com/gogo/protobuf/gogoproto
go get github.com/tensorflow/tensorflow/tensorflow/go
cd protoc-gen-gogotf && go install
PATH=$(GOPATH)/bin:$(PATH) $(PROTOC) -I$(TF)/ $(TF)/tensorflow/core/framework/*.proto --gogotf_out=internal/
PATH=$(GOPATH)/bin:$(PATH) $(PROTOC) -I$(TF)/ $(PROTOS) --gogotf_out=internal/
sed -i 's;github.com/tensorflow;github.com/oracle/graphpipe-go/cmd/graphpipe-tf/internal/github.com/tensorflow;g' internal/github.com/tensorflow/tensorflow/tensorflow/go/core/protobuf/*.pb.go
deps: graphpipe-go-deps go-deps
all: dev-container in-docker runtime-container