Automake 和 CUDA,包括标志被忽略

huangapple go评论81阅读模式
英文:

Automake and CUDA, Include flags ignored

问题

以下是您要翻译的内容:

I am writing a simple automake example with CUDA but the implicit flags that should be added are ignored.

I have 2 files, main.cpp:

  1. #include <stdio.h>
  2. #include <cuda_runtime.h>
  3. int cuda_hello_launcher();
  4. int main() {
  5. cuda_hello_launcher();
  6. return 0;
  7. }

and aux.cu:

  1. #include <cuda_runtime.h>
  2. #include <stdio.h>
  3. __global__ void cuda_hello(){
  4. printf("Hello World from GPU!\n");
  5. }
  6. void cuda_hello_launcher(){
  7. cuda_hello<<<1,1>>>();
  8. cudaDeviceSynchronize();
  9. }

These two files are inside the src directory.
I also have a Makefile.am in the src directory:

  1. bin_PROGRAMS = cuda_automake_example
  2. cuda_automake_example_SOURCES = main.cu aux.cpp
  3. cuda_automake_example_LDFLAGS = $(CUDA_LIBS)
  4. cuda_automake_example_LDADD = $(cuda_automake_example_LDFLAGS)
  5. cuda_automake_example_CXXFLAGS = $(CUDA_INCLUDE_FLAGS) $(CUDA_LIBS)
  6. $(info $(cuda_automake_example_CXXFLAGS))
  7. $(info $(CUDA_INCLUDE_FLAGS))
  8. .cu.o:
  9. $(NVCC) -c -o $@ $<

And in the root directory (src directory is root/src):
I have configure.ac:

  1. AC_INIT([cuda_automake], [1.0], [])
  2. AM_INIT_AUTOMAKE([foreign])
  3. AC_PROG_CXX
  4. AC_CONFIG_HEADERS([src/config.h])
  5. AC_CONFIG_FILES([
  6. Makefile
  7. src/Makefile
  8. ])
  9. AC_LANG_DEFINE([CUDA], [cuda], [CUDA], [CUDACXX],
  10. [])
  11. AC_ARG_WITH([cuda],
  12. [AS_HELP_STRING([--with-cuda=PATH], [specify CUDA installation path])],
  13. [with_cuda="$withval"],
  14. [with_cuda=""])
  15. if test -n "$with_cuda"
  16. then
  17. if test "$with_cuda" = yes
  18. then
  19. AC_MSG_ERROR([With-cuda argument requires the path to CUDA, --with-cuda=<CUDA_PATH>])
  20. fi
  21. if test -z "$with_cuda"
  22. then
  23. AC_MSG_ERROR([If you are building with CUDA GPU support, please input the CUDA path with --with-cuda=<CUDA_PATH>])
  24. fi
  25. # Extract the path from the "--with-cuda" argument
  26. cuda_path=$(echo "$with_cuda" | sed 's/--with-cuda=//')
  27. # Check if the path is valid
  28. if test ! -d "$cuda_path"; then
  29. AC_MSG_ERROR([The input for cuda-path=$cuda_path is not a valid directory])
  30. fi
  31. CUDA_INCLUDE_FLAGS="-I$with_cuda/include"
  32. CUDA_LIBS="-L$with_cuda/lib64 -L$with_cuda/lib -lcudart"
  33. NVCC="$with_cuda/bin/nvcc"
  34. CUDA_PATH="$with_cuda"
  35. else
  36. AC_MSG_ERROR([B: $with_cuda])
  37. fi
  38. AC_SUBST(CUDA_INCLUDE_FLAGS)
  39. AC_SUBST(CUDA_LIBS)
  40. AC_SUBST(NVCC)
  41. AC_SUBST(CUDA_PATH)
  42. AC_OUTPUT

and a Makefile.am:

  1. SUBDIRS = src
  2. ACLOCAL_AMFLAGS = -I m4

When I call:

  1. automake && autoconf && ./configure --with-cuda=/opt/nvidia/hpc_sdk/Linux_x86_64/23.3/cuda && VERBOSE=1 make

I get the following error:

  1. Making all in src
  2. make[1]: Entering directory '/home/primrose/Work/aux/cuda_automake/src'
  3. -I/opt/nvidia/hpc_sdk/Linux_x86_64/23.3/cuda/include -L/opt/nvidia/hpc_sdk/Linux_x86_64/23.3/cuda/lib64 -L/opt/nvidia/hpc_sdk/Linux_x86_64/23.3/cuda/lib -lcudart
  4. -I/opt/nvidia/hpc_sdk/Linux_x86_64/23.3/cuda/include
  5. make all-am
  6. make[2]: Entering directory '/home/primrose/Work/aux/cuda_automake/src'
  7. -I/opt/nvidia/hpc_sdk/Linux_x86_64/23.3/cuda/include -L/opt/nvidia/hpc_sdk/Linux_x86_64/23.3/cuda/lib64 -L/opt/nvidia/hpc_sdk/Linux_x86_64/23.3/cuda/lib -lcudart
  8. -I/opt/nvidia/hpc_sdk/Linux_x86_64/23.3/cuda/include
  9. g++ -DHAVE_CONFIG_H -I. -g -O2 -MT main.o -MD -MP -MF .deps/main.Tpo -c -o main.o main.cpp
  10. main.cpp:2:10: fatal error: cuda_runtime.h: No such file or directory
  11. 2 | #include <cuda_runtime.h>
  12. | ^~~~~~~~~~~~~~~~
  13. compilation terminated.
  14. make[2]: *** [Makefile:380: main.o] Error 1
  15. make[2]: Leaving directory '/home/primrose/Work/aux/cuda_automake/src'
  16. make[1]: *** [Makefile:270: all] Error 2
  17. make[1]: Leaving directory '/home/primrose/Work/aux/cuda_automake/src'
  18. make: *** [Makefile:337: all-recursive] Error 1

I would expect the target_CXXFLAGS of the target I am building also to include the include directory containing cuda_runtime.h as well as attached to the build command (the folder has cuda_runtime.h btw that is not a problem, I checked it with ls), but apparently it is not the case, why would it be so?

英文:

I am writing a simple automake example with CUDA but the implicit flags that should be added are ignored.

I have 2 files, main.cpp:

  1. #include <stdio.h>
  2. #include <cuda_runtime.h>
  3. int cuda_hello_launcher();
  4. int main() {
  5. cuda_hello_launcher();
  6. return 0;
  7. }

and aux.cu:

  1. #include <cuda_runtime.h>
  2. #include <stdio.h>
  3. __global__ void cuda_hello(){
  4. printf("Hello World from GPU!\n");
  5. }
  6. void cuda_hello_launcher(){
  7. cuda_hello<<<1,1>>>();
  8. cudaDeviceSynchronize();
  9. }

These two files are inside the src directory.
I also have a Makefile.am in the src directory:

  1. bin_PROGRAMS = cuda_automake_example
  2. cuda_automake_example_SOURCES = main.cu aux.cpp
  3. cuda_automake_example_LDFLAGS = $(CUDA_LIBS)
  4. cuda_automake_example_LDADD = $(cuda_automake_example_LDFLAGS)
  5. cuda_automake_example_CXXFLAGS = $(CUDA_INCLUDE_FLAGS) $(CUDA_LIBS)
  6. $(info $(cuda_automake_example_CXXFLAGS))
  7. $(info $(CUDA_INCLUDE_FLAGS))
  8. .cu.o:
  9. $(NVCC) -c -o $@ $<

And in the root directory (src directory is root/src):
I have configure.ac:

  1. AC_INIT([cuda_automake], [1.0], [])
  2. AM_INIT_AUTOMAKE([foreign])
  3. AC_PROG_CXX
  4. AC_CONFIG_HEADERS([src/config.h])
  5. AC_CONFIG_FILES([
  6. Makefile
  7. src/Makefile
  8. ])
  9. AC_LANG_DEFINE([CUDA], [cuda], [CUDA], [CUDACXX],
  10. [])
  11. AC_ARG_WITH([cuda],
  12. [AS_HELP_STRING([--with-cuda=PATH], [specify CUDA installation path])],
  13. [with_cuda="$withval"],
  14. [with_cuda=""])
  15. if test -n "$with_cuda"
  16. then
  17. if test "$with_cuda" = yes
  18. then
  19. AC_MSG_ERROR([With-cuda argument requires the path to CUDA, --with-cuda=<CUDA_PATH>])
  20. fi
  21. if test -z "$with_cuda"
  22. then
  23. AC_MSG_ERROR([If you are building with CUDA GPU support, please input the CUDA path with --with-cuda=<CUDA_PATH>])
  24. fi
  25. # Extract the path from the "--with-cuda" argument
  26. cuda_path=$(echo "$with_cuda" | sed 's/--with-cuda=//')
  27. # Check if the path is valid
  28. if test ! -d "$cuda_path"; then
  29. AC_MSG_ERROR([The input for cuda-path=$cuda_path is not a valid directory])
  30. fi
  31. CUDA_INCLUDE_FLAGS="-I$with_cuda/include"
  32. CUDA_LIBS="-L$with_cuda/lib64 -L$with_cuda/lib -lcudart"
  33. NVCC="$with_cuda/bin/nvcc"
  34. CUDA_PATH="$with_cuda"
  35. else
  36. AC_MSG_ERROR([B: $with_cuda])
  37. fi
  38. AC_SUBST(CUDA_INCLUDE_FLAGS)
  39. AC_SUBST(CUDA_LIBS)
  40. AC_SUBST(NVCC)
  41. AC_SUBST(CUDA_PATH)
  42. AC_OUTPUT

and a Makefile.am:

  1. SUBDIRS = src
  2. ACLOCAL_AMFLAGS = -I m4

When I call:

  1. automake && autoconf && ./configure --with-cuda=/opt/nvidia/hpc_sdk/Linux_x86_64/23.3/cuda && VERBOSE=1 make

I get the following error:

  1. Making all in src
  2. make[1]: Entering directory '/home/primrose/Work/aux/cuda_automake/src'
  3. -I/opt/nvidia/hpc_sdk/Linux_x86_64/23.3/cuda/include -L/opt/nvidia/hpc_sdk/Linux_x86_64/23.3/cuda/lib64 -L/opt/nvidia/hpc_sdk/Linux_x86_64/23.3/cuda/lib -lcudart
  4. -I/opt/nvidia/hpc_sdk/Linux_x86_64/23.3/cuda/include
  5. make all-am
  6. make[2]: Entering directory '/home/primrose/Work/aux/cuda_automake/src'
  7. -I/opt/nvidia/hpc_sdk/Linux_x86_64/23.3/cuda/include -L/opt/nvidia/hpc_sdk/Linux_x86_64/23.3/cuda/lib64 -L/opt/nvidia/hpc_sdk/Linux_x86_64/23.3/cuda/lib -lcudart
  8. -I/opt/nvidia/hpc_sdk/Linux_x86_64/23.3/cuda/include
  9. g++ -DHAVE_CONFIG_H -I. -g -O2 -MT main.o -MD -MP -MF .deps/main.Tpo -c -o main.o main.cpp
  10. main.cpp:2:10: fatal error: cuda_runtime.h: No such file or directory
  11. 2 | #include <cuda_runtime.h>
  12. | ^~~~~~~~~~~~~~~~
  13. compilation terminated.
  14. make[2]: *** [Makefile:380: main.o] Error 1
  15. make[2]: Leaving directory '/home/primrose/Work/aux/cuda_automake/src'
  16. make[1]: *** [Makefile:270: all] Error 2
  17. make[1]: Leaving directory '/home/primrose/Work/aux/cuda_automake/src'
  18. make: *** [Makefile:337: all-recursive] Error 1

I would expect the target_CXXFLAGS of the target I am building also to include the include directory containing cuda_runtime.h as well as attached to the build command (the folder has cuda_runtime.h btw that is not a problem, I checked it with ls), but apparently it is not the case, why would it be so?

答案1

得分: 1

<target_name>_CPPFLAGS<target_name>_CXXFLAGS 会自动添加为目标的 C++ 标志。

当然,确保文件的扩展名正确,或者手动定义它们为 C++ 扩展名。

英文:

<target_name>_CPPFLAGS and <target_name>_CXXFLAGS are automatically added as C++ flags to the target.

Of course, make sure you have the correct filename extensions for the files or manually define the extensions as C++ extensions.

huangapple
  • 本文由 发表于 2023年7月3日 03:07:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/76600415.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定