我遵循了Tensorflow Add a new op tutorial,它说
TF_CFLAGS=( $(python -c 'import tensorflow as tf; print(" ".join(tf.sysconfig.get_compile_flags()))') )
TF_LFLAGS=( $(python -c 'import tensorflow as tf; print(" ".join(tf.sysconfig.get_link_flags()))') )
g++ -std=c++11 -shared zero_out.cc -o zero_out.so -fPIC ${TF_CFLAGS[@]} ${TF_LFLAGS[@]} -O2
但是,我遇到了错误:
tensorflow.python.framework.errors_impl.NotFoundError: ./encoding_gpu.so: undefined symbol: _Z29ScaledL2ForwardKernelLauncherPKfS0_S0_iiiPf
我认为它仅考虑CPU操作,并且我想知道如何使用.cu
文件构建GPU操作。
答案 0 :(得分:0)
Tensorflow实际上提供了编译GPU操作的说明,请在gpu support进行检查。
nvcc -std=c++11 -c -o cuda_op_kernel.cu.o cuda_op_kernel.cu.cc \
${TF_CFLAGS[@]} -D GOOGLE_CUDA=1 -x cu -Xcompiler -fPIC
g++ -std=c++11 -shared -o cuda_op_kernel.so cuda_op_kernel.cc \
cuda_op_kernel.cu.o ${TF_CFLAGS[@]} -fPIC -lcudart ${TF_LFLAGS[@]}