-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2315f17
commit 92ef4c0
Showing
1 changed file
with
20 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,34 @@ | ||
target_cpu=integrand.so | ||
cpu_src=integrand.cpp | ||
|
||
target_gpu=integrand.cu.o | ||
gpu_src=integrand.cu.cpp | ||
target_lib=integrand.so | ||
|
||
TF_CFLAGS=`python -c 'import tensorflow as tf; print(" ".join(tf.sysconfig.get_compile_flags()))' 2> /dev/null` | ||
TF_LFLAGS=`python -c 'import tensorflow as tf; print(" ".join(tf.sysconfig.get_link_flags()))' 2>/dev/null` | ||
|
||
CXX=g++ | ||
NCC=nvcc | ||
CXFLAGS=-std=c++11 -shared -fPIC -O2 | ||
KERNEL=-D KERNEL_CUDA=1 | ||
NCCFLAGS=-std=c++11 $(KERNEL) -x cu -Xcompiler -fPIC | ||
NLFLAGS=-L/opt/cuda/lib64 -lcudart | ||
KERNEL_DEF=-D KERNEL_CUDA=1 | ||
NCCFLAGS=-std=c++11 $(KERNEL_DEF) -x cu -Xcompiler -fPIC --disable-warnings | ||
|
||
.PHONY: run_cpu run_gpu clean | ||
# Check whether there's nvcc | ||
ifeq (,$(shell which nvcc 2>/dev/null)) | ||
else | ||
NCC:=nvcc | ||
NCCLIB:=$(subst bin/nvcc,lib64, $(shell which nvcc)) | ||
CXFLAGS+=$(KERNEL_DEF) -L$(NCCLIB) -lcudart | ||
kernel_comp=integrand.cu.o | ||
endif | ||
|
||
run_cpu: $(target_cpu) | ||
@python cuda_example.py | ||
.PHONY: run clean | ||
|
||
run_gpu: $(target_gpu) | ||
run: $(target_lib) | ||
@python cuda_example.py | ||
|
||
$(target_cpu): $(cpu_src) | ||
@echo "Compiling CPU kernel" | ||
@$(CXX) $(CXFLAGS) $< -o $@ -fPIC $(TF_CFLAGS) $(TF_LFLAGS) | ||
|
||
$(target_gpu): $(gpu_src) | ||
@echo "Compiling GPU kernel" | ||
%.cu.o: %.cu.cpp | ||
@echo "[$(NCC)] Integrating cuda kernel..." | ||
@$(NCC) $(NCCFLAGS) -c -o $@ $< $(TF_CFLAGS) | ||
@$(CXX) $(CXFLAGS) $(KERNEL) -o $(target_cpu) $(cpu_src) $(target_gpu) $(TF_CFLAGS) $(NLFLAGS) $(TF_LFLAGS) | ||
|
||
%.so: %.cpp $(kernel_comp) | ||
@echo "[$(CXX)] Integrating operator..." | ||
@$(CXX) $(CXFLAGS) $(KERNEL) -o $@ $^ $(TF_CFLAGS) $(TF_LFLAGS) | ||
|
||
clean: | ||
rm -f $(target_gpu) $(target_cpu) | ||
rm -f $(target_lib) $(kernel_comp) |