"src/targets/gpu/vscode:/vscode.git/clone" did not exist on "6a331a5b13488bee804bcc8a92203dd47e17f6f3"
Makefile 7.78 KB
Newer Older
liuzhe-lz's avatar
liuzhe-lz committed
1
2
3
# Setting variables

SHELL := /bin/bash
Zejun Lin's avatar
Zejun Lin committed
4
5
PIP_INSTALL := python3 -m pip install
PIP_UNINSTALL := python3 -m pip uninstall
liuzhe-lz's avatar
liuzhe-lz committed
6

7
8
9
10
11
12
## Colorful output
_INFO := $(shell echo -e '\e[1;36m')
_WARNING := $(shell echo -e '\e[1;33m')
_END := $(shell echo -e '\e[0m')


liuzhe-lz's avatar
liuzhe-lz committed
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
## Install directories
ifeq ($(shell id -u), 0)  # is root
    _ROOT := 1
    BIN_PATH ?= /usr/bin
    INSTALL_PREFIX ?= /usr/share
    EXAMPLES_PATH ?= $(INSTALL_PREFIX)/nni/examples
    BASH_COMP_SCRIPT ?= /usr/share/bash-completion/completions/nnictl
else  # is normal user
    BIN_PATH ?= ${HOME}/.local/bin
    INSTALL_PREFIX ?= ${HOME}/.local
    EXAMPLES_PATH ?= ${HOME}/nni/examples
    ifndef VIRTUAL_ENV
        PIP_MODE ?= --user
    endif
    BASH_COMP_SCRIPT ?= ${HOME}/.bash_completion.d/nnictl
28
endif
Deshui Yu's avatar
Deshui Yu committed
29

liuzhe-lz's avatar
liuzhe-lz committed
30
## Dependency information
Zejun Lin's avatar
Zejun Lin committed
31
32
33
NNI_NODE_VERSION ?= v10.12.0
NNI_NODE_TARBALL ?= node-$(NNI_NODE_VERSION)-linux-x64.tar.xz
NNI_NODE_PATH ?= $(INSTALL_PREFIX)/nni/node
liuzhe-lz's avatar
liuzhe-lz committed
34

Zejun Lin's avatar
Zejun Lin committed
35
36
37
NNI_YARN_VERSION ?= v1.10.1
NNI_YARN_TARBALL ?= yarn-$(NNI_YARN_VERSION).tar.gz
NNI_YARN_PATH ?= /tmp/nni-yarn
liuzhe-lz's avatar
liuzhe-lz committed
38
39
40

## Check if dependencies have been installed globally
ifeq (, $(shell command -v node 2>/dev/null))
41
    $(info $(_INFO) Node.js not found $(_END))
liuzhe-lz's avatar
liuzhe-lz committed
42
43
44
    _MISS_DEPS := 1  # node not found
else
    _VER := $(shell node --version)
Zejun Lin's avatar
Zejun Lin committed
45
    _NEWER := $(shell echo -e "$(NNI_NODE_VERSION)\n$(_VER)" | sort -Vr | head -n 1)
liuzhe-lz's avatar
liuzhe-lz committed
46
    ifneq ($(_VER), $(_NEWER))
47
        $(info $(_INFO) Node.js version not match $(_END))
liuzhe-lz's avatar
liuzhe-lz committed
48
49
50
51
        _MISS_DEPS := 1  # node outdated
    endif
endif
ifeq (, $(shell command -v yarnpkg 2>/dev/null))
52
    $(info $(_INFO) Yarn not found $(_END))
liuzhe-lz's avatar
liuzhe-lz committed
53
54
55
56
    _MISS_DEPS := 1  # yarn not found
endif

ifdef _MISS_DEPS
57
    $(info $(_INFO) Missing dependencies, use local toolchain $(_END))
Zejun Lin's avatar
Zejun Lin committed
58
59
    NNI_NODE := $(NNI_NODE_PATH)/bin/node
    NNI_YARN := PATH=$(NNI_NODE_PATH)/bin:$${PATH} $(NNI_YARN_PATH)/bin/yarn
liuzhe-lz's avatar
liuzhe-lz committed
60
else
61
    $(info $(_INFO) All dependencies found, use global toolchain $(_END))
Zejun Lin's avatar
Zejun Lin committed
62
63
    NNI_NODE := node
    NNI_YARN := yarnpkg
liuzhe-lz's avatar
liuzhe-lz committed
64
65
66
67
68
69
70
71
72
endif


# Setting variables end


# Main targets

.PHONY: build
Deshui Yu's avatar
Deshui Yu committed
73
build:
liuzhe-lz's avatar
liuzhe-lz committed
74
	#$(_INFO) Building NNI Manager $(_END)
Zejun Lin's avatar
Zejun Lin committed
75
	cd src/nni_manager && $(NNI_YARN) && $(NNI_YARN) build
Deshui Yu's avatar
Deshui Yu committed
76
	
goooxu's avatar
goooxu committed
77
	#$(_INFO) Building WebUI $(_END)
Zejun Lin's avatar
Zejun Lin committed
78
	cd src/webui && $(NNI_YARN) && $(NNI_YARN) build
Deshui Yu's avatar
Deshui Yu committed
79
	
liuzhe-lz's avatar
liuzhe-lz committed
80
	#$(_INFO) Building Python SDK $(_END)
Deshui Yu's avatar
Deshui Yu committed
81
82
	cd src/sdk/pynni && python3 setup.py build
	
liuzhe-lz's avatar
liuzhe-lz committed
83
	#$(_INFO) Building nnictl $(_END)
Deshui Yu's avatar
Deshui Yu committed
84
85
	cd tools && python3 setup.py build

liuzhe-lz's avatar
liuzhe-lz committed
86
87
88
89
90
91
92
# Standard installation target
# Must be invoked after building
.PHONY: install
install: install-python-modules
install: install-node-modules
install: install-scripts
install: install-examples
Deshui Yu's avatar
Deshui Yu committed
93
install:
liuzhe-lz's avatar
liuzhe-lz committed
94
	#$(_INFO) Complete! You may want to add $(BIN_PATH) to your PATH environment $(_END)
95

liuzhe-lz's avatar
liuzhe-lz committed
96
97
98
99
100

# Target for remote machine workers
# Only installs core SDK module
.PHONY: remote-machine-install
remote-machine-install:
101
	cd src/sdk/pynni && python3 setup.py install $(PIP_MODE)
liuzhe-lz's avatar
liuzhe-lz committed
102
103


liuzhe-lz's avatar
liuzhe-lz committed
104
# All-in-one target for non-expert users
liuzhe-lz's avatar
liuzhe-lz committed
105
106
107
108
109
# Installs NNI as well as its dependencies, and update bashrc to set PATH
.PHONY: easy-install
easy-install: check-perm
easy-install: install-dependencies
easy-install: build
liuzhe-lz's avatar
liuzhe-lz committed
110
easy-install: install
liuzhe-lz's avatar
liuzhe-lz committed
111
112
easy-install: update-bash-config

liuzhe-lz's avatar
liuzhe-lz committed
113
easy-install:
Zejun Lin's avatar
Zejun Lin committed
114
	#$(_INFO) Complete! $(_END)
liuzhe-lz's avatar
liuzhe-lz committed
115
116
117
118
119
120
121
122
123
124


# Target for setup.py
# Do not invoke this manually
.PHONY: pip-install
pip-install: install-dependencies
pip-install: build
pip-install: install-node-modules
pip-install: install-scripts
pip-install: install-examples
liuzhe-lz's avatar
liuzhe-lz committed
125
pip-install: update-bash-config
liuzhe-lz's avatar
liuzhe-lz committed
126
127
128
129
130
131
132
133
134
135
136
137
138
139


# Target for NNI developers
# Creates symlinks instead of copying files
.PHONY: dev-install
dev-install: check-dev-env
dev-install: install-dev-modules
dev-install: install-scripts
dev-install:
	#$(_INFO) Complete! You may want to add $(BIN_PATH) to your PATH environment $(_END)


.PHONY: uninstall
uninstall:
Zejun Lin's avatar
Zejun Lin committed
140
141
	-$(PIP_UNINSTALL) -y nni
	-$(PIP_UNINSTALL) -y nnictl
liuzhe-lz's avatar
liuzhe-lz committed
142
143
144
145
146
147
148
149
150
151
152
	-rm -rf $(INSTALL_PREFIX)/nni
	-rm -f $(BIN_PATH)/nnimanager
	-rm -f $(BIN_PATH)/nnictl
	-rm -f $(BASH_COMP_SCRIPT)
	-[ $(EXAMPLES_PATH) = ${PWD}/examples ] || rm -rf $(EXAMPLES_PATH)

# Main targets end


# Helper targets

Zejun Lin's avatar
Zejun Lin committed
153
$(NNI_NODE_TARBALL):
liuzhe-lz's avatar
liuzhe-lz committed
154
	#$(_INFO) Downloading Node.js $(_END)
Zejun Lin's avatar
Zejun Lin committed
155
	wget https://nodejs.org/dist/$(NNI_NODE_VERSION)/$(NNI_NODE_TARBALL)
liuzhe-lz's avatar
liuzhe-lz committed
156

Zejun Lin's avatar
Zejun Lin committed
157
$(NNI_YARN_TARBALL):
liuzhe-lz's avatar
liuzhe-lz committed
158
	#$(_INFO) Downloading Yarn $(_END)
Zejun Lin's avatar
Zejun Lin committed
159
	wget https://github.com/yarnpkg/yarn/releases/download/$(NNI_YARN_VERSION)/$(NNI_YARN_TARBALL)
liuzhe-lz's avatar
liuzhe-lz committed
160
161

.PHONY: intall-dependencies
Zejun Lin's avatar
Zejun Lin committed
162
install-dependencies: $(NNI_NODE_TARBALL) $(NNI_YARN_TARBALL)
liuzhe-lz's avatar
liuzhe-lz committed
163
	#$(_INFO) Cleaning $(_END)
Zejun Lin's avatar
Zejun Lin committed
164
165
166
167
	rm -rf $(NNI_NODE_PATH)
	rm -rf $(NNI_YARN_PATH)
	mkdir -p $(NNI_NODE_PATH)
	mkdir -p $(NNI_YARN_PATH)
Deshui Yu's avatar
Deshui Yu committed
168
	
liuzhe-lz's avatar
liuzhe-lz committed
169
	#$(_INFO) Extracting Node.js $(_END)
Zejun Lin's avatar
Zejun Lin committed
170
171
	tar -xf $(NNI_NODE_TARBALL)
	mv -fT node-$(NNI_NODE_VERSION)-linux-x64 $(NNI_NODE_PATH)
Deshui Yu's avatar
Deshui Yu committed
172
	
liuzhe-lz's avatar
liuzhe-lz committed
173
	#$(_INFO) Extracting Yarn $(_END)
Zejun Lin's avatar
Zejun Lin committed
174
175
	tar -xf $(NNI_YARN_TARBALL)
	mv -fT yarn-$(NNI_YARN_VERSION) $(NNI_YARN_PATH)
176

liuzhe-lz's avatar
liuzhe-lz committed
177
178
179
.PHONY: install-python-modules
install-python-modules:
	#$(_INFO) Installing Python SDK $(_END)
Zejun Lin's avatar
Zejun Lin committed
180
	cd src/sdk/pynni && $(PIP_INSTALL) $(PIP_MODE) .
181
	
liuzhe-lz's avatar
liuzhe-lz committed
182
	#$(_INFO) Installing nnictl $(_END)
Zejun Lin's avatar
Zejun Lin committed
183
	cd tools && $(PIP_INSTALL) $(PIP_MODE) .
184

liuzhe-lz's avatar
liuzhe-lz committed
185
186
.PHONY: install-node-modules
install-node-modules:
187
	mkdir -p $(INSTALL_PREFIX)/nni
Zejun Lin's avatar
Zejun Lin committed
188
	rm -rf src/nni_manager/dist/node_modules
QuanluZhang's avatar
QuanluZhang committed
189
	rm -rf $(INSTALL_PREFIX)/nni/nni_manager
190
	
liuzhe-lz's avatar
liuzhe-lz committed
191
	#$(_INFO) Installing NNI Manager $(_END)
Zejun Lin's avatar
Zejun Lin committed
192
193
	cp -rT src/nni_manager/dist $(INSTALL_PREFIX)/nni/nni_manager
	cp -rT src/nni_manager/node_modules $(INSTALL_PREFIX)/nni/nni_manager/node_modules
194
	
goooxu's avatar
goooxu committed
195
196
	#$(_INFO) Installing WebUI $(_END)
	cp -rT src/webui/build $(INSTALL_PREFIX)/nni/nni_manager/static
Deshui Yu's avatar
Deshui Yu committed
197
198


liuzhe-lz's avatar
liuzhe-lz committed
199
200
201
.PHONY: install-dev-modules
install-dev-modules:
	#$(_INFO) Installing Python SDK $(_END)
Zejun Lin's avatar
Zejun Lin committed
202
	cd src/sdk/pynni && $(PIP_INSTALL) $(PIP_MODE) -e .
203
	
liuzhe-lz's avatar
liuzhe-lz committed
204
	#$(_INFO) Installing nnictl $(_END)
Zejun Lin's avatar
Zejun Lin committed
205
	cd tools && $(PIP_INSTALL) $(PIP_MODE) -e .
206

liuzhe-lz's avatar
liuzhe-lz committed
207
	mkdir -p $(INSTALL_PREFIX)/nni
208
	
liuzhe-lz's avatar
liuzhe-lz committed
209
	#$(_INFO) Installing NNI Manager $(_END)
Zejun Lin's avatar
Zejun Lin committed
210
211
	ln -sf ${PWD}/src/nni_manager/dist $(INSTALL_PREFIX)/nni/nni_manager
	ln -sf ${PWD}/src/nni_manager/node_modules $(INSTALL_PREFIX)/nni/nni_manager/node_modules
Deshui Yu's avatar
Deshui Yu committed
212
	
goooxu's avatar
goooxu committed
213
214
	#$(_INFO) Installing WebUI $(_END)
	ln -sf ${PWD}/src/webui/build $(INSTALL_PREFIX)/nni/nni_manager/static
liuzhe-lz's avatar
liuzhe-lz committed
215
216
217
218
219


.PHONY: install-scripts
install-scripts:
	mkdir -p $(BIN_PATH)
220
221
	
	echo '#!/bin/sh' > $(BIN_PATH)/nnimanager
liuzhe-lz's avatar
liuzhe-lz committed
222
	echo 'cd $(INSTALL_PREFIX)/nni/nni_manager' >> $(BIN_PATH)/nnimanager
Zejun Lin's avatar
Zejun Lin committed
223
	echo '$(NNI_NODE) main.js $$@' >> $(BIN_PATH)/nnimanager
224
225
226
	chmod +x $(BIN_PATH)/nnimanager
	
	echo '#!/bin/sh' > $(BIN_PATH)/nnictl
liuzhe-lz's avatar
liuzhe-lz committed
227
228
	echo 'NNI_MANAGER=$(BIN_PATH)/nnimanager \' >> $(BIN_PATH)/nnictl
	echo 'python3 -m nnicmd.nnictl $$@' >> $(BIN_PATH)/nnictl
229
230
	chmod +x $(BIN_PATH)/nnictl
	
liuzhe-lz's avatar
liuzhe-lz committed
231
	install -Dm644 tools/bash-completion $(BASH_COMP_SCRIPT)
Deshui Yu's avatar
Deshui Yu committed
232
233


liuzhe-lz's avatar
liuzhe-lz committed
234
235
236
237
238
239
.PHONY: install-examples
install-examples:
	mkdir -p $(EXAMPLES_PATH)
	[ $(EXAMPLES_PATH) = ${PWD}/examples ] || cp -rT examples $(EXAMPLES_PATH)


liuzhe-lz's avatar
liuzhe-lz committed
240
241
242
243
244
.PHONY: update-bash-config
ifndef _ROOT
update-bash-config:
	#$(_INFO) Updating bash configurations $(_END)
    ifeq (, $(shell echo $$PATH | tr ':' '\n' | grep -x '$(BIN_PATH)'))  # $(BIN_PATH) not in PATH
liuzhe-lz's avatar
liuzhe-lz committed
245
246
	#$(_WARNING) NOTE: adding $(BIN_PATH) to PATH in bashrc $(_END)
	echo 'export PATH="$$PATH:$(BIN_PATH)"' >> ~/.bashrc
liuzhe-lz's avatar
liuzhe-lz committed
247
248
249
250
251
252
253
    endif
    ifeq (, $(shell (source ~/.bash_completion ; command -v _nnictl) 2>/dev/null))  # completion not installed
	#$(_WARNING) NOTE: adding $(BASH_COMP_SCRIPT) to ~/.bash_completion $(_END)
	echo '[[ -f $(BASH_COMP_SCRIPT) ]] && source $(BASH_COMP_SCRIPT)' >> ~/.bash_completion
    endif
else
update-bash-config: ;
liuzhe-lz's avatar
liuzhe-lz committed
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
endif


.PHONY: check-perm
ifdef _ROOT
check-perm:
	#$(_WARNING) Run easy-install as root is not optimal $(_END)
	#$(_WARNING) Suggest run as non-privileged user or manually install instead $(_END)
	#$(_WARNING) Continue easy-install as root? (y/N) $(_END)
	@read CONFIRM && [ "$$CONFIRM" = y ]
else
check-perm: ;
endif


.PHONY: check-dev-env
check-dev-env:
	#$(_INFO) Checking developing environment... $(_END)
ifdef _ROOT
	$(error You should not develop NNI as root)
endif
ifdef _MISS_DEPS
goooxu's avatar
goooxu committed
276
#	$(error Please install Node.js and Yarn to develop NNI)
liuzhe-lz's avatar
liuzhe-lz committed
277
278
279
280
endif
	#$(_INFO) Pass! $(_END)

# Helper targets end