Skip to content

Instantly share code, notes, and snippets.

@shyoshyo
Last active April 27, 2018 11:50
Show Gist options
  • Save shyoshyo/40c8ab56bbac2b20cba7a448cb7b2f25 to your computer and use it in GitHub Desktop.
Save shyoshyo/40c8ab56bbac2b20cba7a448cb7b2f25 to your computer and use it in GitHub Desktop.
CXX = /usr/bin/g++
NVCC = /usr/local/cuda-9.1/bin/nvcc
CUDA_LIB = /usr/local/cuda-9.1/lib64
CUDA_INC = /usr/local/cuda-9.1/include
CUDA_CFLAGS = -I $(CUDA_INC)
CUDA_LFLAGS = -lcudart -L $(CUDA_LIB)
TF_LIB = $(shell python -c 'import tensorflow as tf; print(tf.sysconfig.get_lib())')
TF_INC = $(shell python -c 'import tensorflow as tf; print(tf.sysconfig.get_include())')
TF_CFLAGS = $(shell python -c 'import tensorflow as tf; print(" ".join(tf.sysconfig.get_compile_flags()))')
TF_LFLAGS = $(shell python -c 'import tensorflow as tf; print(" ".join(tf.sysconfig.get_link_flags()))')
# for tf <= 1.4.0
# TF_CFLAGS = -I $(TF_INC) -I $(TF_INC)/external/nsync/public -L $(TF_LIB) -D_GLIBCXX_USE_CXX11_ABI=1
# TF_LFLAGS = -L $(TF_LIB) -ltensorflow_framework
all: tf_sampling_so.so
%.cu:
%.cu.o: %.cu
$(NVCC) -std=c++11 -c -o $@ $^ $(TF_CFLAGS) -D GOOGLE_CUDA=1 -x cu -Xcompiler -fPIC -O2 --expt-relaxed-constexpr
%_so.so: %.cpp %_g.cu.o
$(CXX) -std=c++11 -shared -o $@ $^ $(TF_CFLAGS) $(CUDA_CFLAGS) $(CUDA_LFLAGS) $(TF_LFLAGS) -fPIC -O2
clean:
rm -f *.so *.cu.o
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment