Skip to content

Commit

Permalink
fix undefined symbol issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Zardinality committed Jul 31, 2017
1 parent cd3cdce commit f7945b2
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 64 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ scikit-image

cython

g++ 4.9
g++ 4.9(For gcc5 users, you should check make.sh and modify it as told.)

Cuda 8.0

Expand Down Expand Up @@ -153,4 +153,5 @@ After training, you could run scripts in `./experiments/eval`to evaluate on VOC2
1. cudaCheckError() failed : invalid device function.
Check ./lib/make.sh and change the -arch flag accordingly. (Credit to [here](https://github.com/smallcorgi/Faster-RCNN_TF/issues/19))


2. undefined symbol: _ZN10tensorflow8internal21CheckOpMessageBuilder9NewStringB5cxx11Ev
If you use gcc5 to build, modify `make.sh` to gcc5 version(simply adding a `-D_GLIBCXX_USE_CXX11_ABI=0` flag as pointed out in [this issue](https://github.com/tensorflow/tensorflow/issues/1569)).
104 changes: 52 additions & 52 deletions lib/deform_psroi_pooling_layer/deform_psroi_pooling_op_grad.py
Original file line number Diff line number Diff line change
@@ -1,59 +1,59 @@
from __future__ import absolute_import
import tensorflow as tf
from tensorflow.python.framework import ops
import deform_psroi_pooling_op
import pdb


# @tf.RegisterShape("DeformPSROIPool")
# def _deform_psroi_pool_shape(op):
# """Shape function for the DeformPSROIPool op.

# from __future__ import absolute_import
# import tensorflow as tf
# from tensorflow.python.framework import ops
# import deform_psroi_pooling_op
# import pdb


# # @tf.RegisterShape("DeformPSROIPool")
# # def _deform_psroi_pool_shape(op):
# # """Shape function for the DeformPSROIPool op.

# # """
# # dims_data = op.inputs[0].get_shape().as_list()
# # channels = dims_data[3]
# # dims_rois = op.inputs[1].get_shape().as_list()
# # num_rois = dims_rois[0]
# # output_dim = op.get_attr('output_dim')
# # group_size = op.get_attr('group_size')
# # pooled_height = group_size
# # pooled_width = group_size

# # output_shape = tf.TensorShape([num_rois, pooled_height, pooled_width, output_dim])
# # return [output_shape, output_shape]

# @ops.RegisterGradient("DeformPSROIPool")
# def _deform_psroi_pool_grad(op, grad, _):
# """The gradients for `Deform_PSROI_pool`.
# Args:
# op: The `roi_pool` `Operation` that we are differentiating, which we can use
# to find the inputs and outputs of the original op.
# grad: Gradient with respect to the output of the `roi_pool` op.
# Returns:
# Gradients with respect to the input of `zero_out`.
# """
# dims_data = op.inputs[0].get_shape().as_list()
# channels = dims_data[3]
# dims_rois = op.inputs[1].get_shape().as_list()
# num_rois = dims_rois[0]
# output_dim = op.get_attr('output_dim')
# group_size = op.get_attr('group_size')
# pooled_height = group_size
# pooled_width = group_size

# output_shape = tf.TensorShape([num_rois, pooled_height, pooled_width, output_dim])
# return [output_shape, output_shape]

@ops.RegisterGradient("DeformPSROIPool")
def _deform_psroi_pool_grad(op, grad, _):
"""The gradients for `Deform_PSROI_pool`.
Args:
op: The `roi_pool` `Operation` that we are differentiating, which we can use
to find the inputs and outputs of the original op.
grad: Gradient with respect to the output of the `roi_pool` op.
Returns:
Gradients with respect to the input of `zero_out`.
"""


data = op.inputs[0]
rois = op.inputs[1]
trans = op.inputs[2]
mapping_channel = op.outputs[1]
spatial_scale = op.get_attr('spatial_scale')
output_dim = op.get_attr('output_dim')
group_size = op.get_attr('group_size')
pooled_size = op.get_attr('pooled_size')
part_size = op.get_attr('part_size')
sample_per_part = op.get_attr('sample_per_part')
trans_std = op.get_attr('trans_std')
no_trans = op.get_attr('no_trans')
# data = op.inputs[0]
# rois = op.inputs[1]
# trans = op.inputs[2]
# mapping_channel = op.outputs[1]
# spatial_scale = op.get_attr('spatial_scale')
# output_dim = op.get_attr('output_dim')
# group_size = op.get_attr('group_size')
# pooled_size = op.get_attr('pooled_size')
# part_size = op.get_attr('part_size')
# sample_per_part = op.get_attr('sample_per_part')
# trans_std = op.get_attr('trans_std')
# no_trans = op.get_attr('no_trans')



# compute gradient
#data_grad = psroi_pooling_op.psroi_pool_grad(data, rois, argmax, grad, pooled_height, pooled_width, spatial_scale)
data_grad, trans_grad = deform_psroi_pooling_op.deform_psroi_pool_grad(data, rois, trans, mapping_channel, grad, spatial_scale,
output_dim, group_size, pooled_size, part_size, sample_per_part,
trans_std, no_trans)
# rois_grad = tf.zeros(rois.shape)
return [data_grad, None, trans_grad] # List of one Tensor, since we have one input
# # compute gradient
# #data_grad = psroi_pooling_op.psroi_pool_grad(data, rois, argmax, grad, pooled_height, pooled_width, spatial_scale)
# data_grad, trans_grad = deform_psroi_pooling_op.deform_psroi_pool_grad(data, rois, trans, mapping_channel, grad, spatial_scale,
# output_dim, group_size, pooled_size, part_size, sample_per_part,
# trans_std, no_trans)
# # rois_grad = tf.zeros(rois.shape)
# return [data_grad, None, trans_grad] # List of one Tensor, since we have one input

31 changes: 21 additions & 10 deletions lib/make.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ TF_INC=$(python -c 'import tensorflow as tf; print(tf.sysconfig.get_include())')
echo $TF_INC


# If coming across: cudaCheckError() failed : invalid device function. change -arch=sm_xx accordingly.

# Which CUDA capabilities do we want to pre-build for?
# https://developer.nvidia.com/cuda-gpus
Expand Down Expand Up @@ -31,12 +32,12 @@ nvcc -std=c++11 -c -o roi_pooling_op.cu.o roi_pooling_op_gpu.cu.cc \
-I $TF_INC -D GOOGLE_CUDA=1 -x cu -Xcompiler -fPIC -D GOOGLE_CUDA -arch=sm_37

## if you install tf using already-built binary, or gcc version 4.x, uncomment the two lines below
g++ -std=c++11 -shared -D_GLIBCXX_USE_CXX11_ABI=0 -o roi_pooling.so roi_pooling_op.cc \
g++ -std=c++11 -shared -o roi_pooling.so roi_pooling_op.cc \
roi_pooling_op.cu.o -I $TF_INC -fPIC -D GOOGLE_CUDA -lcudart -L $CUDA_HOME/lib64

# for gcc5-built tf
# g++ -std=c++11 -shared -D_GLIBCXX_USE_CXX11_ABI=1 -o roi_pooling.so roi_pooling_op.cc \
# roi_pooling_op.cu.o -I $TF_INC -fPIC -D GOOGLE_CUDA -lcudart -L $CUDA_HOME/lib64
# g++ -std=c++11 -shared -o roi_pooling.so roi_pooling_op.cc \
# roi_pooling_op.cu.o -I $TF_INC -fPIC -D GOOGLE_CUDA -lcudart -L $CUDA_HOME/lib64 -D_GLIBCXX_USE_CXX11_ABI=0
cd ..


Expand All @@ -45,28 +46,38 @@ cd psroi_pooling_layer
nvcc -std=c++11 -c -o psroi_pooling_op.cu.o psroi_pooling_op_gpu.cu.cc \
-I $TF_INC -D GOOGLE_CUDA=1 -x cu -Xcompiler -fPIC -D GOOGLE_CUDA -arch=sm_37

g++ -std=c++11 -shared -o psroi_pooling.so psroi_pooling_op.cc \
psroi_pooling_op.cu.o -I $TF_INC -fPIC -D GOOGLE_CUDA -lcudart -L $CUDA_HOME/lib64

## if you install tf using already-built binary, or gcc version 4.x, uncomment the two lines below
#g++ -std=c++11 -shared -D_GLIBCXX_USE_CXX11_ABI=0 -o psroi_pooling.so psroi_pooling_op.cc \
# psroi_pooling_op.cu.o -I $TF_INC -fPIC -D GOOGLE_CUDA -lcudart -L $CUDA_HOME/lib64
g++ -std=c++11 -shared -o psroi_pooling.so psroi_pooling_op.cc \
psroi_pooling_op.cu.o -I $TF_INC -fPIC -D GOOGLE_CUDA -lcudart -L $CUDA_HOME/lib64
# for gcc5-built tf
# g++ -std=c++11 -shared -o psroi_pooling.so psroi_pooling_op.cc \
# psroi_pooling_op.cu.o -I $TF_INC -fPIC -D GOOGLE_CUDA -lcudart -L $CUDA_HOME/lib64 -D_GLIBCXX_USE_CXX11_ABI=0

cd ..

cd deform_psroi_pooling_layer
nvcc -std=c++11 -c -o deform_psroi_pooling_op.cu.o deform_psroi_pooling_op_gpu.cu.cc \
-I $TF_INC -D GOOGLE_CUDA=1 -x cu -Xcompiler -fPIC -D GOOGLE_CUDA -arch=sm_37

g++ -std=c++11 -shared -o deform_psroi_pooling.so deform_psroi_pooling_op.cc deform_psroi_pooling_op.cu.o -I \
## if you install tf using already-built binary, or gcc version 4.x, uncomment the three lines below
g++ -std=c++11 -shared -o deform_psroi_pooling.so deform_psroi_pooling_op.cc deform_psroi_pooling_op.cu.o -I \
$TF_INC -fPIC -lcudart -L $CUDA_HOME/lib64 -D GOOGLE_CUDA=1 -Wfatal-errors -I \
$CUDA_HOME/include -D_GLIBCXX_USE_CXX11_ABI=0
$CUDA_HOME/include
# for gcc5-built tf
# g++ -std=c++11 -shared -o deform_psroi_pooling.so deform_psroi_pooling_op.cc deform_psroi_pooling_op.cu.o \
# -I $TF_INC -fPIC -D GOOGLE_CUDA -lcudart -L $CUDA_HOME/lib64 -D_GLIBCXX_USE_CXX11_ABI=0
cd ..

cd deform_conv_layer
nvcc -std=c++11 -c -o deform_conv.cu.o deform_conv.cu.cc -I $TF_INC -D\
GOOGLE_CUDA=1 -x cu -Xcompiler -fPIC -L /usr/local/cuda-8.0/lib64/ --expt-relaxed-constexpr -arch=sm_37
## if you install tf using already-built binary, or gcc version 4.x, uncomment the three lines below
g++ -std=c++11 -shared -o deform_conv.so deform_conv.cc deform_conv.cu.o -I\
$TF_INC -fPIC -lcudart -L $CUDA_HOME/lib64 -D GOOGLE_CUDA=1 -Wfatal-errors -I\
$CUDA_HOME/include -D_GLIBCXX_USE_CXX11_ABI=0
$CUDA_HOME/include
# for gcc5-built tf
# g++ -std=c++11 -shared -o deform_conv.so deform_conv.cc deform_conv.cu.o \
# -I $TF_INC -fPIC -D GOOGLE_CUDA -lcudart -L $CUDA_HOME/lib64 -D_GLIBCXX_USE_CXX11_ABI=0

cd ..

0 comments on commit f7945b2

Please sign in to comment.