Cuda_nvcc_flags

broken image



> CMake Group-
>
> I'm trying to build a CUDA project with NVCC. The project uses 'separate
> compilation'. Unfortunately, 'separate compilation' breaks in a variety of
> ways when I try to use the version in FindCUDA.cmake. First, it doesn't
> include CUDA_NVCC_FLAGS in the -dlink phase so it immediately complains that
> the dlink flag can't be used without sm_20+. That has already been noted as
> a bug (http://public.kitware.com/Bug/view.php?id=14238) and there seems to
> be some discussion about it being inappropriate to default to some sm_
> version. Since multiple sm_ options can be listed but only one arch flag,
> it seems like this may need a more advanced way to be dealt with. Anyway,
> after modifying things to add a -arch=sm_20 to the command line, it works
> for a while but then cannot dlink one of my objects because of:
> 'nvlink error : Undefined reference to '_Z3minRK6float3S1_' in '(..some
> path...)_generated_(...some file...).cu.o'
>
> I can't find this problem because I don't really understand function name
> mangling, but it looks like it cannot link to a 'min' function probably.
> It's not one of the '__cudaRegisterLinkedBinary...' type issues though, and
> so I'm not clear why nvlink is trying to resolve all the symbols for an
> intermediate object anyway.
>
> As a workaround for all this, I tried adding '-dc' to the normal compiles
> and linking with nvcc instead of gcc so that nvcc can do device and host
> linking in one pass.
> (http://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/index.html#using-sepa
> rate-compilation-in-cuda ... 'nvcc '). This almost works except
> for a few link command line incompatibilities. First, nvcc doesn't know
> what to do with '-Wl,-rpath...'. It needs some '-Xlinker' in front of that
> to know where to send it. I can get around that by just turning off rpath
> with 'set(CMAKE_SKIP_RPATH TRUE)', but it's not a great solution. I also
> have to remove the '-rdynamic' flag by setting
> CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS to nothing ('). The last issue is that
> for some reason on some machines CMake tries to use full paths for shared
> libraries rather than -l & -L and nvcc chokes on the extension (static
> libraries with .a are fine). The error message is:
>
> Nvlink fatal : Unsupported file type '/usr/lib/openmpi/lib/libmpi_cxx.so'
>
> If I replace the '/usr/lib/openmpi/lib/libmpi_cxx.so' with
> '-L/usr/lib/openmpi/lib/ -lmpi_cxx', it works. When I look at the ldd
> output, it's even correctly still linking to the .so (rather than a static
> library). Interestingly enough, on a different machine with a similar setup
> the FindMPI module adds the '-L -l' options instead of the full path (mpich
> instead of openmpi though?). I found this page on the cmake wiki that
> suggests getting rid of '-L/-l' as an 'improvement':
> http://www.cmake.org/Wiki/CMake:Improving_Find*_Modules#Converting_-L.2F-l_f
> lags
>
> Is this currently an encouraged approach? Is there a way to control the
> behavior in cmake to force CMake to choose using '-L/-l' instead of full
> paths? I realize this could also be considered more of a bug with nvlink
> than with cmake, but I figured I could try to start here. It would be a
> simple enough regular expression to break the full path into the two pieces,
> but I'm pretty new to CMake and I'm not sure how this could be accomplished.
> If I could just get control of this behavior, I'd have something that would
> work for now until FindCUDA can get sorted out a little more with respect to
> all the CUDA 5+ changes and/or more tightly integrated into CMake like other
> compilers tend to be.
>
> Thanks for any help people can provide.
>
>
>
>
>
> Robert Martin, ERC Inc.
> EP Modeling and Simulation Group
> In-Space Propulsion Branch
> Air Force Research Laboratory
> 661-275-6659
>
>
> --
>
> Powered by www.kitware.com
>
> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
>
> Kitware offers various services to support the CMake community. For more information on each offering, please visit:
>
> CMake Support: http://cmake.org/cmake/help/support.html
> CMake Consulting: http://cmake.org/cmake/help/consulting.html
> CMake Training Courses: http://cmake.org/cmake/help/training.html
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake

Asked: 2015-03-27 14:08:42 -0500 Seen: 922 times Last updated: Mar 27 '15. CUDANVCCFLAGS is the old 'FindCUDA' variable. 点赞 采纳 已采纳 粉丝 回答 采纳.

If you have ever created or built a CUDA CMake project in the past, you have probably heard about the FindCUDA CMake module. Prior to CMake 3.8, it has been providing this module to support compiling CUDA code and linking with CUDA libraries. This approach is not perfect though. Unlike other libraries, CUDA provides not only some libraries but a compiler as well. To let CMake use nvcc to compile something, the FindCUDA module provides macros like cuda_add_executable (similar to add_executable). Essentially, it has to duplicate a lot of features already in CMake specifically for CUDA support. These all changed with CUDA becoming a language in CMake 3.8. In this blog post, I will talk about how to use CUDA in CMake 3.8+.

Enabling CUDA as a language

The first thing you have to do is to set CUDA as a language in your CMake project. This can be easily done with

Setting compiler flags

We can follow the same way we set compiler flags for C/C++ source.

Creating libraries and executables

The CUDA specific cuda_add_executable and cuda_add_library macros are no longer necessary. Simply use add_executable and add_library to build executables and libraries which contain CUDA code. CMake will use different compiler depending on the file extension and link everything properly in the end.

Enabling separable compilation

Example

Unlike with FindCUDA, we have to enable CUDA device code separable compilation on a per target basis now.

Since CMake 3.11, we can also directly set the CMAKE_CUDA_SEPARABLE_COMPILATION property which will internally be used to initialize the value of CUDA_SEPARABLE_COMPILATION on each target.

Cuda_nvcc_flags Example

Cuda_nvcc_flags example

Unlike with FindCUDA, we have to enable CUDA device code separable compilation on a per target basis now.

Since CMake 3.11, we can also directly set the CMAKE_CUDA_SEPARABLE_COMPILATION property which will internally be used to initialize the value of CUDA_SEPARABLE_COMPILATION on each target.

Cuda_nvcc_flags Example

Finding CUDA libraries

Append Cuda_nvcc_flags

Sometimes you may just want to link to certain CUDA libraries with pure C/C++ code. We could find those libraries relying on the new CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES. This variable contains the paths that nvcc implicitly uses to find libraries.

Conclusion

Cuda Nvcc Flags

With CMake 3.8, we have a new way to use CUDA in our CMake projects. It could be a bit difficult to get started because CUDA-related changes are not documented in a single place. The things I mentioned above are just what I have to change in my own CMake project to make CUDA work again. There are more things this release introduced that you may need. None the less, I hope you have a smoother transition from an old CMake version with my tips above.

References

Please enable JavaScript to view the comments powered by Disqus.comments powered by

Cuda_nvcc_flags Std=c++11

Disqus



broken image