0

I'm trying to compile custom ops for Tensorflow, the shell script and implementation comes from a Git repository. I'm running it in a docker container. I get strange errors, e.g. for option -02, it returns "argument to ‘-O’ should be a non-negative integer, ‘g’, ‘s’ or ‘fast’". So I think, the script may be read in faulty? How can I overcome this problem?

This is the .sh file:

#/bin/bash

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()))')
CUDA_ROOT=/usr/local/cuda-10.1

g++ -std=c++11 -shared ./interpolation/tf_interpolate.cpp -o ./interpolation/tf_interpolate_so.so  -I $CUDA_ROOT/include -lcudart -L $CUDA_ROOT/lib64/ -fPIC ${TF_CFLAGS} ${TF_LFLAGS} -O2

$CUDA_ROOT/bin/nvcc ./grouping/tf_grouping_g.cu -o ./grouping/tf_grouping_g.cu.o -c -O2 -DGOOGLE_CUDA=1 -x cu -Xcompiler -fPIC
g++ -std=c++11 -shared ./grouping/tf_grouping.cpp ./grouping/tf_grouping_g.cu.o -o ./grouping/tf_grouping_so.so -I $CUDA_ROOT/include -L $CUDA_ROOT/lib64/ -fPIC ${TF_CFLAGS} ${TF_LFLAGS} -O2

$CUDA_ROOT/bin/nvcc ./sampling/tf_sampling_g.cu -o ./sampling/tf_sampling_g.cu.o -c -O2 -DGOOGLE_CUDA=1 -x cu -Xcompiler -fPIC
g++ -std=c++11 -shared ./sampling/tf_sampling.cpp ./sampling/tf_sampling_g.cu.o -o ./sampling/tf_sampling_so.so -I $CUDA_ROOT/include -L $CUDA_ROOT/lib64/ -fPIC ${TF_CFLAGS} ${TF_LFLAGS} -O2

And here the terminal output:

root@11840eb27d51:/radarseg/radarseg/model/tf_ops# bash compile_ops.sh
compile_ops.sh: line 2: $'\r': command not found
compile_ops.sh: line 6: $'\r': command not found
cc1plus: error: argument to ‘-O’ should be a non-negative integer, ‘g’, ‘s’ or ‘fast’
compile_ops.sh: line 8: $'\r': command not found
/bin/nvcc: No such file or directoryuda-10.1
cc1plus: error: argument to ‘-O’ should be a non-negative integer, ‘g’, ‘s’ or ‘fast’
compile_ops.sh: line 11: $'\r': command not found
/bin/nvcc: No such file or directorycuda-10.1
cc1plus: error: argument to ‘-O’ should be a non-negative integer, ‘g’, ‘s’ or ‘fast’
talonmies
  • 70,661
  • 34
  • 192
  • 269
  • 1
    At first sight, it's because you wrote your shell script with a platform using [CR](https://en.wikipedia.org/wiki/Carriage_return)+[LF](https://en.wikipedia.org/wiki/Newline) characters for newlines (e.g. if you're on windows). Basically, it fails because bash believes you run the command `g++ … "-O2$'\r'"`. To avoid this, you should try to convert your file by using [dos2unix](https://linux.die.net/man/1/dos2unix) or a similar tool. – ErikMD Dec 04 '21 at 14:16
  • So I won't post an answer because your question definitely looks like a duplicate of existing questions. – ErikMD Dec 04 '21 at 14:17
  • Thanks @talonmies for finding a good duplicate. Just FTR, another one: https://stackoverflow.com/questions/16491959/why-would-a-bash-script-produce-the-error-command-not-founde/ – ErikMD Dec 04 '21 at 14:20
  • And no, g++ isn’t emitting errors here, bash is – talonmies Dec 04 '21 at 14:43

0 Answers0