| 1 |
# example here is inspired by Nvidia's blog post: |
| 2 |
# https://developer.nvidia.com/blog/separate-compilation-linking-cuda-device-code/ |
| 3 |
# code: |
| 4 |
# https://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/index.html#examples |
| 5 |
|
| 6 |
project('device linking', ['cpp'], version : '1.0.0') |
| 7 |
|
| 8 |
# test that optional initialization of cuda works to disable thin archives |
| 9 |
add_languages('cuda') |
| 10 |
|
| 11 |
nvcc = meson.get_compiler('cuda') |
| 12 |
cuda = import('unstable-cuda') |
| 13 |
|
| 14 |
arch_flags = cuda.nvcc_arch_flags(nvcc.version(), 'Common') |
| 15 |
|
| 16 |
message('NVCC version: ' + nvcc.version()) |
| 17 |
message('NVCC flags: ' + ' '.join(arch_flags)) |
| 18 |
|
| 19 |
# test device linking with -dc (which is equivalent to `--relocatable-device-code true`) |
| 20 |
lib = static_library('devicefuncs', ['b.cu'], cuda_args : ['-dc'] + arch_flags) |
| 21 |
exe = executable('app', 'main.cu', cuda_args : ['-dc'] + arch_flags, link_with : lib, link_args : arch_flags) |
| 22 |
|
| 23 |
# if we don't have a CUDA-capable GPU available, avoid creating the test |
| 24 |
if run_command('__nvcc_device_query', check : false).returncode() == 0 |
| 25 |
test('cudatest', exe) |
| 26 |
endif |