Commit Graph

53 Commits

Author SHA1 Message Date
Robert Maynard
0d0145138f CUDA: Add abstraction for cuda runtime selection
Fixes #17559
Replace our hard-coded default of cudart=static with a first-class abstraction to select the runtime library from an enumeration of logical names.
2020-01-27 16:02:26 -05:00
Robert Maynard
568298a336 CUDA: MSVC + NVCC support --compiler-options compiler flag
Fixes #20164
2020-01-02 14:35:24 -05:00
Robert Maynard
d484a3c4d8 FindCUDAToolkit: correct searches for Toolkit components 2019-12-16 14:35:03 -05:00
Robert Maynard
e2a5d8374f FindCUDAToolkit: Improve usage, library set, and tests
Refined the initial design of FindCUDAToolkit and improve it
by adding more library support, more toolkit information and
tests.
2019-12-16 11:15:12 -05:00
Robert Maynard
2467a2b318 CUDA: Add cuda meta-features (e.g. `cuda_std_11`) support 2019-12-10 17:56:48 -05:00
Kitware Robot
ed98209ddc Revise include order using clang-format-6.0
Run the `clang-format.bash` script to update our C and C++ code to a new
include order `.clang-format`.  Use `clang-format` version 6.0.
2019-10-01 12:26:36 -04:00
Robert Maynard
2d7bb13da7 CUDA: static lib device linking computes required static libs
Previously the CMake didn't compute the required set of libraries
needed to properly device link a static library when
CUDA_RESOLVE_DEVICE_SYMBOLS was enabled.
2019-09-05 10:51:02 -04:00
Robert Maynard
8f1d22c2d9 CUDA: Support CMAKE_CUDA_RESOLVE_DEVICE_SYMBOLS global variable 2019-08-06 09:55:40 -04:00
Robert Maynard
b53766b205 CUDA: Support compiler id and version generator expressions
Introduce the CUDA_COMPILER_ID and CUDA_COMPILER_VERSION generator
expressions.
2019-03-11 12:33:43 -04:00
Robert Maynard
850ef90a66 CUDA: Honor CUDA_RESOLVE_DEVICE_SYMBOLS for more target types
`CUDA_RESOLVE_DEVICE_SYMBOLS` can be used with shared, module, and
executable target types.  This relaxation is to allow for better
interoperability with linkers that automatically do CUDA device symbol
resolution and have no way to disable it.
2019-02-05 11:09:48 -05:00
Robert Maynard
2cc050b53b CUDA: Add test for device linking when host linking uses threads
Convert the `CudaOnly.LinkSystemDeviceLibraries` test to a new
`Cuda.ProperDeviceLibraries` test.  The former covered only the
`cublas_device` library which is removed by CUDA 10.  Extend the new
test to also cover various cases of using threads.

Issue: #18008
2018-10-24 10:15:48 -04:00
Brad King
fb378fc4d7 Tests: Fix Cuda test project names
Make them match what `ADD_TEST_MACRO` gives to ctest as the
project name to build so that the `.sln` file will be found.
2018-10-10 13:29:47 -04:00
Brad King
36f49faa3c Merge topic 'cuda-no-cublas_device'
122c79748c CUDA: Avoid using deprecated cublas_device to identify device lib dirs

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !2296
2018-08-24 13:35:01 -04:00
Robert Maynard
122c79748c CUDA: Avoid using deprecated cublas_device to identify device lib dirs
Use `curand_static` to identify directories containing device libraries
because `cublas_device` is deprecated and will be removed in the future.

Issue: #18290
2018-08-23 14:43:31 -04:00
Robert Maynard
fd0523a215 CUDA: Properly de-duplicate libs when doing device linking
The nvcc device linker is designed so that each static library
with device symbols only needs to be listed once as it doesn't
care about link order. If you provide the same static library
multiple times it will error out. To make sure this occurs
we find the unique set of link items.
2018-07-17 10:42:57 -04:00
Robert Maynard
b07c71831c CUDA: Add a test to verify device linking can handle circular deps 2018-07-17 10:04:39 -04:00
Kitware Robot
d7204e649e Revise C++ coding style using clang-format-6.0
Run the `clang-format.bash` script to update all our C and C++ code to a
new style defined by `.clang-format`.  Use `clang-format` version 6.0.

* If you reached this commit for a line in `git blame`, re-run the blame
  operation starting at the parent of this commit to see older history
  for the content.

* See the parent commit for instructions to rebase a change across this
  style transition commit.
2018-06-01 09:53:42 -04:00
Brad King
134e795fa9 VS: Add workaround for CUDA compiler PDB location
The CUDA Toolkit Visual Studio Integration does not honor the
`ClCompile.ProgramDataBaseFileName` field when telling `nvcc` how to
invoke `cl`.  Work around this problem by passing `-Xcompiler=-Fd...`
ourselves through `AdditionalOptions`.

Fixes: #17647
2018-04-13 12:56:36 -04:00
Robert Maynard
41eab150a8 CUDA: Pass more link libraries to device linking
Previously we dropped non-target items from the device link line because
nvcc rejects paths to shared library files, and only with target items
do we know the kind of library.  However, this also prevents projects
from linking to system-provided libraries like `cublas_device` that
contain device code.

Fix this by passing more link items to device linking.  Items that are
not file paths, such as `-lfoo`, can simply be passed unconditionally.
Items that are targets known to be shared libraries can still be
skipped.  Items that are paths to library files can be passed directly
if they end in `.a`.  Otherwise, pass them using `-Xnvlink` to bypass
nvcc's front-end.  The nvlink tool knows to ignore shared library files.

Issue: #16317
2018-03-28 09:38:43 -04:00
Brad King
8285aa9e4e Tests: Add missing error check in CudaOnly.GPUDebugFlag
If `cudaMallocManaged` fails then later use of `has_debug` is not valid.
2018-02-01 09:07:50 -05:00
Brad King
bffdc2e2e1 Merge topic 'msvc_cuda_8_explicitly_specify_cuda_language'
46abfedb CUDA: MSVC will now state files are cuda files when needed

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !1658
2018-01-18 09:41:01 -05:00
Brad King
b4dfe1d816 Merge topic 'extend-compile-language-genex'
506fda1c Genex: Enable COMPILE_LANGUAGE for INCLUDE_DIRECTORIES with VS and Xcode
c2f79c98 Genex: Enable COMPILE_LANGUAGE for COMPILE_DEFINITIONS with VS and Xcode
0795d25b cmVisualStudio10TargetGenerator: Factor out include dir computation
1ab4d186 cmLocalVisualStudio7Generator: Clarify variable name of compiled language
07e1a743 cmLocalVisualStudio7Generator: Clarify condition for target that compiles

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !1657
2018-01-16 09:33:23 -05:00
Robert Maynard
46abfedb83 CUDA: MSVC will now state files are cuda files when needed
The MSVC CUDA build customizations before CUDA 9 would not explicitly
add the -x cu option when building. This caused .cpp and .c files
invoked with CudaCompile to be compiled as host code and not
cuda. Now when we detect CUDA < 9 we will explicitly add this
option to correct this bug.
2018-01-12 15:17:03 -05:00
Brad King
506fda1cf0 Genex: Enable COMPILE_LANGUAGE for INCLUDE_DIRECTORIES with VS and Xcode
The set of compile flags used for a target's C and C++ sources is based
on the linker language.  By default this is always the C++ flags if any
C++ sources appear in the target, and otherwise the C flags.  Therefore
we can define the `COMPILE_LANGUAGE` generator expression in
`INCLUDE_DIRECTORIES` to match the selected language.

This is not exactly the same as for other generators, but is the best VS
and Xcode can do.  It is also sufficient for many use cases since the
set of include directories for C and C++ is frequently similar but may
be distinct from those for other languages like CUDA.

Fixes: #17435
2018-01-12 14:27:37 -05:00
Brad King
c2f79c9867 Genex: Enable COMPILE_LANGUAGE for COMPILE_DEFINITIONS with VS and Xcode
The set of compile flags used for a target's C and C++ sources is based
on the linker language.  By default this is always the C++ flags if any
C++ sources appear in the target, and otherwise the C flags.  Therefore
we can define the `COMPILE_LANGUAGE` generator expression in
`COMPILE_DEFINITIONS` to match the selected language.

This is not exactly the same as for other generators, but is the best VS
and Xcode can do.  It is also sufficient for many use cases since the
set of definitions for C and C++ is frequently similar but may be
distinct from those for other languages like CUDA.

Issue: #17435
2018-01-12 14:27:37 -05:00
Brad King
46ad721597 Merge topic 'cuda_allow_G_to_device_debugging_on_msvc'
dcc606ad CUDA: Allow -G to control device debuging on MSVC.

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !1619
2018-01-12 09:51:42 -05:00
Robert Maynard
dcc606ad47 CUDA: Allow -G to control device debuging on MSVC.
Fixes #17551
2018-01-11 13:33:00 -05:00
Robert Maynard
a91fde135d CUDA: gencode signature that list multiple code types now supported.
Fixes #17263
2018-01-10 10:45:57 -05:00
Robert Maynard
8164298935 Cuda: ResolveDeviceSymbols now properly execute everywhere.
The previous version had two bugs that caused the JIT runtime errors.

1. It was building the executable without separable compilation enabled

2. All kernel launches will fail if any kernel is missing a symbol, that
   is why the call to file2_launch_kernel had to be removed
2017-12-13 17:34:48 -05:00
Brad King
1882ba2e05 Merge topic 'extend-compile-language-genex'
2ae880fa Genex: Enable COMPILE_LANGUAGE for COMPILE_OPTIONS with Visual Studio
2b7d59f3 Genex: Enable COMPILE_LANGUAGE for file(GENERATE) with Visual Studio
0f6f7c8a Genex: Fix COMPILE_LANGUAGE messages to allow file(GENERATE) with Xcode
c5a82d0f Tests: Decouple COMPILE_LANGUAGE in file(GENERATE) from COMPILE_OPTIONS
25773650 Tests: Remove unnecessary result files from RunCMake.File_Generate

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: Jason Juang <jasjuang@gmail.com>
Merge-request: !1511
2017-11-27 09:00:44 -05:00
Brad King
2ae880fa8f Genex: Enable COMPILE_LANGUAGE for COMPILE_OPTIONS with Visual Studio
Since commit v3.9.0-rc4~3^2~1 (VS: Fix target_compile_options for CUDA,
2017-06-21), the evaluation of `COMPILE_LANGUAGE` receives the proper
language.  The set of compile flags used for a target's C and C++
sources is based on the linker language.  By default this is always the
C++ flags if any C++ sources appear in the target, and otherwise the C
flags.  Therefore we can define the `COMPILE_LANGUAGE` generator
expression in `COMPILE_OPTIONS` to match the selected language.

This is not exactly the same as for other generators, but is the best VS
can do.  It is also sufficient for many use cases since the set of
allowed flags for C and C++ is almost the same in Visual Studio.
Furthermore, since the VS generator moves many of the flags to
declarative `.vcxproj` elements, it will automatically avoid passing
C++ flags for C sources.

Issue: #17435
2017-11-20 13:51:25 -05:00
Brad King
00e13993fd CUDA: Add CMAKE_CUDA_SEPARABLE_COMPILATION variable
Use its value to initialize the `CUDA_SEPARABLE_COMPILATION` target
property when targets are created.

Fixes: #17478
2017-11-17 09:51:39 -05:00
Brad King
aa640cc20f Tests: Fix CudaOnly.WithDefs test on CUDA 9
CUDA 9 dropped support for `compute_20`, so use a different alternative.
2017-09-29 09:55:11 -04:00
Daniel Pfeifer
2b4c32c95f clang-format: format all code as Cpp11 2017-08-30 11:07:05 -04:00
Brad King
dc11a20d7b Merge topic 'vs-cuda-fix-flags'
bbc1f364 VS: Fix support for nvcc flags not in our flag table

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !1007
2017-06-27 09:18:34 -04:00
Brad King
bbc1f3642c VS: Fix support for nvcc flags not in our flag table
The change in commit v3.9.0-rc4~3^2 (VS: Improve workaround for CUDA
-Xcompiler placement bug, 2017-06-21) accidentally appended to the
`AdditionalOptions` as if it were a `;`-separated list, but it is
actually a command-line string.  Append with a space instead.

While at it, fix the same problem for the `AdditionalOptions` added to
`CudaLink` by commit v3.9.0-rc3~1^2 (CUDA: When linking device code
suppress CUDA 8.0+ deprecation warnings, 2017-06-09).

Fixes: #17008
2017-06-27 09:08:50 -04:00
Brad King
396b618c52 Merge topic 'vs-cuda-fix-flags'
3b754215 VS: Improve workaround for CUDA -Xcompiler placement bug
f2059585 VS: Fix target_compile_options for CUDA

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !996
2017-06-22 10:04:37 -04:00
Brad King
3b75421515 VS: Improve workaround for CUDA -Xcompiler placement bug
In commit v3.9.0-rc1~431^2~6 (VS: Place CUDA host compiler options in
proper project file fields, 2017-03-07) we worked around a bug in the
CUDA VS integration by dropping `AdditionalCompilerOptions`.  However,
this silently drops `-Xcompiler=` options given by the user that don't
map to one of CudaCompile's dedicated settings.  Improve the workaround
to instead put the remaining `AdditionalCompilerOptions` into the
`AdditionalOptions` field behind `-Xcompiler=` ourselves.
2017-06-21 14:24:11 -04:00
Brad King
f2059585e6 VS: Fix target_compile_options for CUDA
Fix the VS generator to honor `COMPILE_OPTIONS` for CUDA.  The exclusion
added by commit v3.9.0-rc1~431^2~7 (VS: Do not pass CUDA compile options
to C compiler, 2017-03-07) was correct but we need additional logic to
pass the CUDA compile options to the CUDA compiler.  Also we should
still pass the CXX or C options to MSVC (ClCompile) when those languages
are enabled even if the link language is CUDA.
2017-06-21 14:23:46 -04:00
Brad King
fff782f6a6 Tests: Simplify CUDA rpath on macOS
Use the `BUILD_RPATH` property and reference the CMake-computed location
of the runtime libraries.
2017-06-21 10:41:49 -04:00
Robert Maynard
493671a521 CUDA: Static libraries can now explicitly resolve device symbols
If a static library has the property CUDA_RESOLVE_DEVICE_SYMBOLS enabled
it will now perform the device link step. The normal behavior is
to delay calling device link until the static library is consumed by
a shared library or an executable.
2017-04-26 16:18:25 -04:00
Robert Maynard
a36fb229ba CUDA: Visual Studio now properly delays device linking 2017-04-26 11:41:22 -04:00
Robert Maynard
23691d789e CUDA: Allow sources to be compiled to .ptx files
When the target property `CUDA_PTX_COMPILATION` is enabled CUDA OBJECT
libraries will generate ptx files instead of object files.
2017-04-20 13:25:38 -04:00
Brad King
65481a60a0 CUDA: Work around VS limitation in CudaOnly.WithDefs test
CUDA 8.0 MSBuild rules do not pass `-x cu` to nvcc and so cannot support
a custom file extension.  Fix our test for this to use a `.cu` extension
instead.
2017-03-10 10:19:58 -05:00
Brad King
613b3e49a0 CUDA: Fix spelling of CudaOnly.SeparateCompilation test targets 2017-03-07 13:26:01 -05:00
Brad King
d7c80f6036 CUDA: Fix test cases to not override CUDA flags
Append to `CMAKE_CUDA_FLAGS` instead of overwriting it.
2017-02-15 11:12:09 -05:00
Brad King
c4a6135039 Tests: Run clang-format on CUDA code 2017-02-14 10:20:50 -05:00
Brad King
592e3d2f96 clang-format.bash: Format CUDA source files too
Add `.clang-format` configuration files for Cuda test directories that
use `Standard: Cpp11`.  Otherwise clang-format splits the triple angle
brackets used for CUDA kernels.
2017-02-14 10:20:23 -05:00
Robert Maynard
44f3acb202 CUDA: Detect the toolkit include directories
The `nvcc -v` output provides what include directories need to be added
to use the CUDA toolkit from other languages ( C/C++ ).
2017-02-10 16:08:06 -05:00
Brad King
f9a810f7b3 CUDA: Enable CudaOnly.SeparateCompilation test runtime calls
Uncomment the calls in `main.cpp` (and fix the signatures).
2017-01-12 10:39:04 -05:00