Skip to content

Commit c05efbe

Browse files
howard0supiiswrong
authored andcommitted
Improve build system to avoid calling pkg-config many times (apache#4111)
* Improve build system to avoid calling pkg-config many times * support specify cuda arch
1 parent bab6d61 commit c05efbe

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

Makefile

+7-7
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ endif
4747

4848
# setup opencv
4949
ifeq ($(USE_OPENCV), 1)
50-
CFLAGS += -DMXNET_USE_OPENCV=1 `pkg-config --cflags opencv`
51-
LDFLAGS += `pkg-config --libs opencv`
50+
CFLAGS += -DMXNET_USE_OPENCV=1 $(shell pkg-config --cflags opencv)
51+
LDFLAGS += $(shell pkg-config --libs opencv)
5252
BIN += bin/im2rec
5353
else
5454
CFLAGS+= -DMXNET_USE_OPENCV=0
@@ -183,15 +183,15 @@ build/src/%.o: src/%.cc
183183

184184
build/src/%_gpu.o: src/%.cu
185185
@mkdir -p $(@D)
186-
$(NVCC) $(NVCCFLAGS) -Xcompiler "$(CFLAGS)" -M -MT build/src/$*_gpu.o $< >build/src/$*_gpu.d
187-
$(NVCC) -c -o $@ $(NVCCFLAGS) -Xcompiler "$(CFLAGS)" $<
186+
$(NVCC) $(NVCCFLAGS) $(CUDA_ARCH) -Xcompiler "$(CFLAGS)" -M -MT build/src/$*_gpu.o $< >build/src/$*_gpu.d
187+
$(NVCC) -c -o $@ $(NVCCFLAGS) $(CUDA_ARCH) -Xcompiler "$(CFLAGS)" $<
188188

189189
# A nvcc bug cause it to generate "generic/xxx.h" dependencies from torch headers.
190190
# Use CXX to generate dependency instead.
191191
build/plugin/%_gpu.o: plugin/%.cu
192192
@mkdir -p $(@D)
193193
$(CXX) -std=c++11 $(CFLAGS) -MM -MT build/plugin/$*_gpu.o $< >build/plugin/$*_gpu.d
194-
$(NVCC) -c -o $@ $(NVCCFLAGS) -Xcompiler "$(CFLAGS)" $<
194+
$(NVCC) -c -o $@ $(NVCCFLAGS) $(CUDA_ARCH) -Xcompiler "$(CFLAGS)" $<
195195

196196
build/plugin/%.o: plugin/%.cc
197197
@mkdir -p $(@D)
@@ -200,8 +200,8 @@ build/plugin/%.o: plugin/%.cc
200200

201201
%_gpu.o: %.cu
202202
@mkdir -p $(@D)
203-
$(NVCC) $(NVCCFLAGS) -Xcompiler "$(CFLAGS) -Isrc/operator" -M -MT $*_gpu.o $< >$*_gpu.d
204-
$(NVCC) -c -o $@ $(NVCCFLAGS) -Xcompiler "$(CFLAGS) -Isrc/operator" $<
203+
$(NVCC) $(NVCCFLAGS) $(CUDA_ARCH) -Xcompiler "$(CFLAGS) -Isrc/operator" -M -MT $*_gpu.o $< >$*_gpu.d
204+
$(NVCC) -c -o $@ $(NVCCFLAGS) $(CUDA_ARCH) -Xcompiler "$(CFLAGS) -Isrc/operator" $<
205205

206206
%.o: %.cc
207207
@mkdir -p $(@D)

make/config.mk

+7
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ USE_CUDA_PATH = NONE
4848
# whether use CuDNN R3 library
4949
USE_CUDNN = 0
5050

51+
# CUDA architecture setting: going with all of them.
52+
# For CUDA < 6.0, comment the *_50 lines for compatibility.
53+
CUDA_ARCH := -gencode arch=compute_30,code=sm_30 \
54+
-gencode arch=compute_35,code=sm_35 \
55+
-gencode arch=compute_50,code=sm_50 \
56+
-gencode arch=compute_50,code=compute_50
57+
5158
# whether use cuda runtime compiling for writing kernels in native language (i.e. Python)
5259
USE_NVRTC = 0
5360

make/osx.mk

+7
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ USE_CUDA = 0
4545
# USE_CUDA_PATH = /usr/local/cuda
4646
USE_CUDA_PATH = NONE
4747

48+
# CUDA architecture setting: going with all of them.
49+
# For CUDA < 6.0, comment the *_50 lines for compatibility.
50+
CUDA_ARCH := -gencode arch=compute_30,code=sm_30 \
51+
-gencode arch=compute_35,code=sm_35 \
52+
-gencode arch=compute_50,code=sm_50 \
53+
-gencode arch=compute_50,code=compute_50
54+
4855
# whether use CUDNN R3 library
4956
USE_CUDNN = 0
5057

0 commit comments

Comments
 (0)