kaldi-asr / kaldi

kaldi-asr/kaldi is the official location of the Kaldi project.
http://kaldi-asr.org
Other
14.18k stars 5.32k forks source link

Identifier "FLT_MAX" is undefined #4914

Closed danijel3 closed 4 months ago

danijel3 commented 4 months ago

Not sure if something hasn't changed recently, but seems something isn't letting cudadecoder compile properly:

/usr/local/cuda/bin/nvcc -c cuda-decoder-kernels.cu -o cuda-decoder-kernels.o -I/usr/local/cuda/include -I/opt/kaldi/tools/cub-1.8.0 -I.. -isystem /opt/kaldi/tools/openfst-1.7.2/include --compiler-options -fPIC --machine 64 -DHAVE_CUDA -ccbin c++ -DKALDI_DOUBLEPRECISION=0 -std=c++14 -DCUDA_API_PER_THREAD_DEFAULT_STREAM -lineinfo --verbose -Wno-deprecated-gpu-targets -gencode arch=compute_50,code=sm_50 -gencode arch=compute_52,code=sm_52 -gencode arch=compute_60,code=sm_60 -gencode arch=compute_61,code=sm_61 -gencode arch=compute_70,code=sm_70 -gencode arch=compute_75,code=sm_75 -gencode arch=compute_80,code=sm_80 -gencode arch=compute_86,code=sm_86 -gencode arch=compute_90,code=sm_90 -I../ -I/opt/kaldi/tools/openfst-1.7.2/include
#$ _NVVM_BRANCH_=nvvm
#$ _SPACE_=
#$ _CUDART_=cudart
#$ _HERE_=/usr/local/cuda/bin
#$ _THERE_=/usr/local/cuda/bin
#$ _TARGET_SIZE_=
#$ _TARGET_DIR_=
#$ _TARGET_DIR_=targets/x86_64-linux
#$ TOP=/usr/local/cuda/bin/..
#$ CICC_PATH=/usr/local/cuda/bin/../nvvm/bin
#$ CICC_NEXT_PATH=/usr/local/cuda/bin/../nvvm-next/bin
#$ NVVMIR_LIBRARY_DIR=/usr/local/cuda/bin/../nvvm/libdevice
#$ LD_LIBRARY_PATH=/usr/local/cuda/bin/../lib:
#$ PATH=/usr/local/cuda/bin/../nvvm/bin:/usr/local/cuda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
#$ INCLUDES="-I/usr/local/cuda/bin/../targets/x86_64-linux/include"
#$ LIBRARIES=  "-L/usr/local/cuda/bin/../targets/x86_64-linux/lib/stubs" "-L/usr/local/cuda/bin/../targets/x86_64-linux/lib"
#$ CUDAFE_FLAGS=
#$ PTXAS_FLAGS=
#$ c++ -std=c++14 -D__CUDA_ARCH_LIST__=500,520,600,610,700,750,800,860,900 -D__NV_LEGACY_LAUNCH -E -x c++ -D__CUDACC__ -D__NVCC__  -fPIC -I"/usr/local/cuda/include" -I"/opt/kaldi/tools/cub-1.8.0" -I".." -I"../" -I"/opt/kaldi/tools/openfst-1.7.2/include" "-I/usr/local/cuda/bin/../targets/x86_64-linux/include"   -isystem "/opt/kaldi/tools/openfst-1.7.2/include"  -D "HAVE_CUDA" -D "KALDI_DOUBLEPRECISION=0" -D "CUDA_API_PER_THREAD_DEFAULT_STREAM" -D__CUDACC_VER_MAJOR__=12 -D__CUDACC_VER_MINOR__=5 -D__CUDACC_VER_BUILD__=40 -D__CUDA_API_VER_MAJOR__=12 -D__CUDA_API_VER_MINOR__=5 -D__NVCC_DIAG_PRAGMA_SUPPORT__=1 -include "cuda_runtime.h" -m64 "cuda-decoder-kernels.cu" -o "/tmp/tmpxft_00006ccd_00000000-5_cuda-decoder-kernels.cpp4.ii"
#$ cudafe++ --c++14 --gnu_version=110400 --display_error_number --orig_src_file_name "cuda-decoder-kernels.cu" --orig_src_path_name "/opt/kaldi/src/cudadecoder/cuda-decoder-kernels.cu" --allow_managed  --m64 --parse_templates --gen_c_file_name "/tmp/tmpxft_00006ccd_00000000-6_cuda-decoder-kernels.compute_90.cudafe1.cpp" --stub_file_name "tmpxft_00006ccd_00000000-6_cuda-decoder-kernels.compute_90.cudafe1.stub.c" --gen_module_id_file --module_id_file_name "/tmp/tmpxft_00006ccd_00000000-4_cuda-decoder-kernels.module_id" "/tmp/tmpxft_00006ccd_00000000-5_cuda-decoder-kernels.cpp4.ii"
cuda-decoder-kernels.cu(539): error: identifier "FLT_MAX" is undefined
      CostType total_cost = FLT_MAX;

My version of NVCC:

$ /usr/local/cuda/bin/nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2024 NVIDIA Corporation
Built on Wed_Apr_17_19:19:55_PDT_2024
Cuda compilation tools, release 12.5, V12.5.40
Build cuda_12.5.r12.5/compiler.34177558_0

And g++: g++ (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0

danijel3 commented 4 months ago

My quick and dirty solution was to temporarily add:

const float FLT_MAX=3.402823466e+38F;

at the start of cudadecoder/cuda-decoder-kernels.cu, but it would nice to know what caused it. Is this something only on my Ubuntu machine or are there others facing the same problem?

jtrmal commented 4 months ago

inluding might solve it another way -- not sure what has changed, maybe you have a new release of cuda when they changed strategy of includes? y.

On Thu, May 23, 2024 at 1:57 PM Danijel Koržinek @.***> wrote:

My quick and dirty solution was to temporarily add:

const float FLT_MAX=3.402823466e+38F;

at the start of cudadecoder/cuda-decoder-kernels.cu, but it would nice to know what caused it. Is this something only on my Ubuntu machine or are there others facing the same problem?

— Reply to this email directly, view it on GitHub https://github.com/kaldi-asr/kaldi/issues/4914#issuecomment-2126927252, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACUKYX7ZEWMBT6H4BRSUNBLZDXKRVAVCNFSM6AAAAABIFO7M2CVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMRWHEZDOMRVGI . You are receiving this because you are subscribed to this thread.Message ID: @.***>

danpovey commented 4 months ago

Yeah we probably committed the sin of relying on things that are indirectly included. @danijel3 is there any chance you could commit a fix? It looks like we are supposed to

include

... I think your approach would cause a syntax error if float.h were included, as it's done via a define statement.

danijel3 commented 4 months ago

limits.h unfortunately doesn't help and float.h is already included, but doesn't work for some reason. I'll keep digging at it. It may be an installation issue or something, but I can at least figure it out in case it happens to someone else...

danpovey commented 4 months ago

It would be fine to just replace FLT_MAX in the code with that constant, and put // FLT_MAX as a comment.

danijel3 commented 4 months ago

I confirmed the issue using a blank Ubuntu Docker image. From what I can see, it is related only to CUDA SDK (so the cu files) and not the standard C++ libs. The install uses the latest (as of now) version of the SDK from the NVidia repo on the Ubuntu 22.04:

deb [signed-by=/usr/share/keyrings/cuda-archive-keyring.gpg] https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/ /

The PR above is harmless and hopefully sufficient. I've checked and it does resolve the issue.