diff options
author | Angelos Mouzakitis <a.mouzakitis@virtualopensystems.com> | 2023-10-10 14:33:42 +0000 |
---|---|---|
committer | Angelos Mouzakitis <a.mouzakitis@virtualopensystems.com> | 2023-10-10 14:33:42 +0000 |
commit | af1a266670d040d2f4083ff309d732d648afba2a (patch) | |
tree | 2fc46203448ddcc6f81546d379abfaeb323575e9 /meson/test cases/cuda | |
parent | e02cda008591317b1625707ff8e115a4841aa889 (diff) |
Change-Id: Iaf8d18082d3991dec7c0ebbea540f092188eb4ec
Diffstat (limited to 'meson/test cases/cuda')
54 files changed, 915 insertions, 0 deletions
diff --git a/meson/test cases/cuda/1 simple/meson.build b/meson/test cases/cuda/1 simple/meson.build new file mode 100644 index 000000000..19af734af --- /dev/null +++ b/meson/test cases/cuda/1 simple/meson.build @@ -0,0 +1,5 @@ +project('simple', 'cuda', version : '1.0.0') + +exe = executable('prog', 'prog.cu') +test('cudatest', exe) + diff --git a/meson/test cases/cuda/1 simple/prog.cu b/meson/test cases/cuda/1 simple/prog.cu new file mode 100644 index 000000000..b893bd331 --- /dev/null +++ b/meson/test cases/cuda/1 simple/prog.cu @@ -0,0 +1,30 @@ +#include <iostream> + +int main(void) { + int cuda_devices = 0; + std::cout << "CUDA version: " << CUDART_VERSION << "\n"; + cudaGetDeviceCount(&cuda_devices); + if(cuda_devices == 0) { + std::cout << "No Cuda hardware found. Exiting.\n"; + return 0; + } + std::cout << "This computer has " << cuda_devices << " Cuda device(s).\n"; + cudaDeviceProp props; + cudaGetDeviceProperties(&props, 0); + std::cout << "Properties of device 0.\n\n"; + + std::cout << " Name: " << props.name << "\n"; + std::cout << " Global memory: " << props.totalGlobalMem << "\n"; + std::cout << " Shared memory: " << props.sharedMemPerBlock << "\n"; + std::cout << " Constant memory: " << props.totalConstMem << "\n"; + std::cout << " Block registers: " << props.regsPerBlock << "\n"; + + std::cout << " Warp size: " << props.warpSize << "\n"; + std::cout << " Threads per block: " << props.maxThreadsPerBlock << "\n"; + std::cout << " Max block dimensions: [ " << props.maxThreadsDim[0] << ", " << props.maxThreadsDim[1] << ", " << props.maxThreadsDim[2] << " ]" << "\n"; + std::cout << " Max grid dimensions: [ " << props.maxGridSize[0] << ", " << props.maxGridSize[1] << ", " << props.maxGridSize[2] << " ]" << "\n"; + std::cout << "\n"; + + return 0; +} + diff --git a/meson/test cases/cuda/10 cuda dependency/c/meson.build b/meson/test cases/cuda/10 cuda dependency/c/meson.build new file mode 100644 index 000000000..921bc43a0 --- /dev/null +++ b/meson/test cases/cuda/10 cuda dependency/c/meson.build @@ -0,0 +1,2 @@ +exe = executable('prog', 'prog.c', dependencies: dependency('cuda')) +test('cudatest', exe) diff --git a/meson/test cases/cuda/10 cuda dependency/c/prog.c b/meson/test cases/cuda/10 cuda dependency/c/prog.c new file mode 100644 index 000000000..ed9333efb --- /dev/null +++ b/meson/test cases/cuda/10 cuda dependency/c/prog.c @@ -0,0 +1,19 @@ +#include <cuda_runtime.h> +#include <stdio.h> + +int cuda_devices(void) { + int result = 0; + cudaGetDeviceCount(&result); + return result; +} + +int main(void) { + int n = cuda_devices(); + if (n == 0) { + printf("No CUDA hardware found. Exiting.\n"); + return 0; + } + + printf("Found %i CUDA devices.\n", n); + return 0; +} diff --git a/meson/test cases/cuda/10 cuda dependency/cpp/meson.build b/meson/test cases/cuda/10 cuda dependency/cpp/meson.build new file mode 100644 index 000000000..a661b8875 --- /dev/null +++ b/meson/test cases/cuda/10 cuda dependency/cpp/meson.build @@ -0,0 +1,2 @@ +exe = executable('prog', 'prog.cc', dependencies: dependency('cuda')) +test('cudatest', exe) diff --git a/meson/test cases/cuda/10 cuda dependency/cpp/prog.cc b/meson/test cases/cuda/10 cuda dependency/cpp/prog.cc new file mode 100644 index 000000000..4832afa81 --- /dev/null +++ b/meson/test cases/cuda/10 cuda dependency/cpp/prog.cc @@ -0,0 +1,19 @@ +#include <cuda_runtime.h> +#include <iostream> + +int cuda_devices(void) { + int result = 0; + cudaGetDeviceCount(&result); + return result; +} + +int main(void) { + int n = cuda_devices(); + if (n == 0) { + std::cout << "No CUDA hardware found. Exiting.\n"; + return 0; + } + + std::cout << "Found " << n << " CUDA devices.\n"; + return 0; +} diff --git a/meson/test cases/cuda/10 cuda dependency/meson.build b/meson/test cases/cuda/10 cuda dependency/meson.build new file mode 100644 index 000000000..3e602b668 --- /dev/null +++ b/meson/test cases/cuda/10 cuda dependency/meson.build @@ -0,0 +1,6 @@ +project('cuda dependency', 'c', 'cpp') + +subdir('c') +subdir('cpp') +subdir('modules') +subdir('version_reqs') diff --git a/meson/test cases/cuda/10 cuda dependency/modules/meson.build b/meson/test cases/cuda/10 cuda dependency/modules/meson.build new file mode 100644 index 000000000..0da43f29d --- /dev/null +++ b/meson/test cases/cuda/10 cuda dependency/modules/meson.build @@ -0,0 +1,2 @@ +exe = executable('prog', 'prog.cc', dependencies: dependency('cuda', modules: ['cublas'])) +test('cudatest', exe) diff --git a/meson/test cases/cuda/10 cuda dependency/modules/prog.cc b/meson/test cases/cuda/10 cuda dependency/modules/prog.cc new file mode 100644 index 000000000..b4af4d41f --- /dev/null +++ b/meson/test cases/cuda/10 cuda dependency/modules/prog.cc @@ -0,0 +1,33 @@ +#include <cuda_runtime.h> +#include <cublas_v2.h> +#include <iostream> + +int cuda_devices(void) { + int result = 0; + cudaGetDeviceCount(&result); + return result; +} + +int main(void) { + int n = cuda_devices(); + if (n == 0) { + std::cout << "No CUDA hardware found. Exiting.\n"; + return 0; + } + + std::cout << "Found " << n << " CUDA devices.\n"; + + cublasHandle_t handle; + if (cublasCreate(&handle) != CUBLAS_STATUS_SUCCESS) { + std::cout << "cuBLAS initialization failed. Exiting.\n"; + return -1; + } + + std::cout << "Initialized cuBLAS\n"; + if (cublasDestroy(handle) != CUBLAS_STATUS_SUCCESS) { + std::cout << "cuBLAS de-initialization failed. Exiting.\n"; + return -1; + } + + return 0; +} diff --git a/meson/test cases/cuda/10 cuda dependency/version_reqs/meson.build b/meson/test cases/cuda/10 cuda dependency/version_reqs/meson.build new file mode 100644 index 000000000..45b5daa1c --- /dev/null +++ b/meson/test cases/cuda/10 cuda dependency/version_reqs/meson.build @@ -0,0 +1,2 @@ +exe = executable('prog', 'prog.cc', dependencies: dependency('cuda', version: ['>=8.5', '<10'], required: false, disabler: true)) +test('cudatest', exe) diff --git a/meson/test cases/cuda/10 cuda dependency/version_reqs/prog.cc b/meson/test cases/cuda/10 cuda dependency/version_reqs/prog.cc new file mode 100644 index 000000000..56688303f --- /dev/null +++ b/meson/test cases/cuda/10 cuda dependency/version_reqs/prog.cc @@ -0,0 +1,28 @@ +#include <cuda_runtime.h> +#include <iostream> + +int cuda_devices(void) { + int result = 0; + cudaGetDeviceCount(&result); + return result; +} + +int main(void) { + std::cout << "Compiled against CUDA version: " << CUDART_VERSION << "\n"; + int runtime_version = 0; + cudaError_t r = cudaRuntimeGetVersion(&runtime_version); + if (r != cudaSuccess) { + std::cout << "Couldn't obtain CUDA runtime version (error " << r << "). Exiting.\n"; + return -1; + } + std::cout << "CUDA runtime version: " << runtime_version << "\n"; + + int n = cuda_devices(); + if (n == 0) { + std::cout << "No CUDA hardware found. Exiting.\n"; + return 0; + } + + std::cout << "Found " << n << " CUDA devices.\n"; + return 0; +} diff --git a/meson/test cases/cuda/11 cuda dependency (nvcc)/meson.build b/meson/test cases/cuda/11 cuda dependency (nvcc)/meson.build new file mode 100644 index 000000000..67b6568c5 --- /dev/null +++ b/meson/test cases/cuda/11 cuda dependency (nvcc)/meson.build @@ -0,0 +1,4 @@ +project('cuda dependency', 'cuda') + +subdir('modules') +subdir('version_reqs') diff --git a/meson/test cases/cuda/11 cuda dependency (nvcc)/modules/meson.build b/meson/test cases/cuda/11 cuda dependency (nvcc)/modules/meson.build new file mode 100644 index 000000000..c0fed8349 --- /dev/null +++ b/meson/test cases/cuda/11 cuda dependency (nvcc)/modules/meson.build @@ -0,0 +1,2 @@ +exe = executable('prog', 'prog.cu', dependencies: dependency('cuda', modules: ['cublas'])) +test('cudatest', exe) diff --git a/meson/test cases/cuda/11 cuda dependency (nvcc)/modules/prog.cu b/meson/test cases/cuda/11 cuda dependency (nvcc)/modules/prog.cu new file mode 100644 index 000000000..b4af4d41f --- /dev/null +++ b/meson/test cases/cuda/11 cuda dependency (nvcc)/modules/prog.cu @@ -0,0 +1,33 @@ +#include <cuda_runtime.h> +#include <cublas_v2.h> +#include <iostream> + +int cuda_devices(void) { + int result = 0; + cudaGetDeviceCount(&result); + return result; +} + +int main(void) { + int n = cuda_devices(); + if (n == 0) { + std::cout << "No CUDA hardware found. Exiting.\n"; + return 0; + } + + std::cout << "Found " << n << " CUDA devices.\n"; + + cublasHandle_t handle; + if (cublasCreate(&handle) != CUBLAS_STATUS_SUCCESS) { + std::cout << "cuBLAS initialization failed. Exiting.\n"; + return -1; + } + + std::cout << "Initialized cuBLAS\n"; + if (cublasDestroy(handle) != CUBLAS_STATUS_SUCCESS) { + std::cout << "cuBLAS de-initialization failed. Exiting.\n"; + return -1; + } + + return 0; +} diff --git a/meson/test cases/cuda/11 cuda dependency (nvcc)/version_reqs/meson.build b/meson/test cases/cuda/11 cuda dependency (nvcc)/version_reqs/meson.build new file mode 100644 index 000000000..6644c9e2b --- /dev/null +++ b/meson/test cases/cuda/11 cuda dependency (nvcc)/version_reqs/meson.build @@ -0,0 +1,2 @@ +exe = executable('prog', 'prog.cu', dependencies: dependency('cuda', version: ['>=10.1'], required: false, disabler: true)) +test('cudatest', exe) diff --git a/meson/test cases/cuda/11 cuda dependency (nvcc)/version_reqs/prog.cu b/meson/test cases/cuda/11 cuda dependency (nvcc)/version_reqs/prog.cu new file mode 100644 index 000000000..bc90081e5 --- /dev/null +++ b/meson/test cases/cuda/11 cuda dependency (nvcc)/version_reqs/prog.cu @@ -0,0 +1,29 @@ +#include <cuda_runtime.h> +#include <iostream> + +int cuda_devices(void) { + int result = 0; + cudaGetDeviceCount(&result); + return result; +} + +int main(void) { + std::cout << "Compiled against CUDA version: " << CUDART_VERSION << "\n"; + + int runtime_version = 0; + switch (cudaError_t r = cudaRuntimeGetVersion(&runtime_version)) { + case cudaSuccess: + std::cout << "CUDA runtime version: " << runtime_version << "\n"; + break; + case cudaErrorNoDevice: + std::cout << "No CUDA hardware found. Exiting.\n"; + return 0; + default: + std::cout << "Couldn't obtain CUDA runtime version (error " << r << "). Exiting.\n"; + return -1; + } + + int n = cuda_devices(); + std::cout << "Found " << n << " CUDA devices.\n"; + return 0; +} diff --git a/meson/test cases/cuda/12 cuda dependency (mixed)/kernel.cu b/meson/test cases/cuda/12 cuda dependency (mixed)/kernel.cu new file mode 100644 index 000000000..7daaa6839 --- /dev/null +++ b/meson/test cases/cuda/12 cuda dependency (mixed)/kernel.cu @@ -0,0 +1,8 @@ +#include <cuda_runtime.h> + +__global__ void kernel (void){ +} + +void do_cuda_stuff(void) { + kernel<<<1,1>>>(); +} diff --git a/meson/test cases/cuda/12 cuda dependency (mixed)/meson.build b/meson/test cases/cuda/12 cuda dependency (mixed)/meson.build new file mode 100644 index 000000000..5df4f846e --- /dev/null +++ b/meson/test cases/cuda/12 cuda dependency (mixed)/meson.build @@ -0,0 +1,4 @@ +project('cuda dependency', 'cpp', 'cuda') + +exe = executable('prog', 'prog.cpp', 'kernel.cu', dependencies: dependency('cuda', modules: ['cublas'])) +test('cudatest', exe) diff --git a/meson/test cases/cuda/12 cuda dependency (mixed)/prog.cpp b/meson/test cases/cuda/12 cuda dependency (mixed)/prog.cpp new file mode 100644 index 000000000..50bb156ad --- /dev/null +++ b/meson/test cases/cuda/12 cuda dependency (mixed)/prog.cpp @@ -0,0 +1,37 @@ +#include <cuda_runtime.h> +#include <cublas_v2.h> +#include <iostream> + +void do_cuda_stuff(void); + +int cuda_devices(void) { + int result = 0; + cudaGetDeviceCount(&result); + return result; +} + +int main(void) { + int n = cuda_devices(); + if (n == 0) { + std::cout << "No CUDA hardware found. Exiting.\n"; + return 0; + } + + std::cout << "Found " << n << " CUDA devices.\n"; + + do_cuda_stuff(); + + cublasHandle_t handle; + if (cublasCreate(&handle) != CUBLAS_STATUS_SUCCESS) { + std::cout << "cuBLAS initialization failed. Exiting.\n"; + return -1; + } + + std::cout << "Initialized cuBLAS\n"; + if (cublasDestroy(handle) != CUBLAS_STATUS_SUCCESS) { + std::cout << "cuBLAS de-initialization failed. Exiting.\n"; + return -1; + } + + return 0; +} diff --git a/meson/test cases/cuda/13 cuda compiler setting/meson.build b/meson/test cases/cuda/13 cuda compiler setting/meson.build new file mode 100644 index 000000000..19af734af --- /dev/null +++ b/meson/test cases/cuda/13 cuda compiler setting/meson.build @@ -0,0 +1,5 @@ +project('simple', 'cuda', version : '1.0.0') + +exe = executable('prog', 'prog.cu') +test('cudatest', exe) + diff --git a/meson/test cases/cuda/13 cuda compiler setting/nativefile.ini b/meson/test cases/cuda/13 cuda compiler setting/nativefile.ini new file mode 100644 index 000000000..ffaad65fd --- /dev/null +++ b/meson/test cases/cuda/13 cuda compiler setting/nativefile.ini @@ -0,0 +1,5 @@ +[binaries] + +cuda = 'nvcc' + + diff --git a/meson/test cases/cuda/13 cuda compiler setting/prog.cu b/meson/test cases/cuda/13 cuda compiler setting/prog.cu new file mode 100644 index 000000000..b893bd331 --- /dev/null +++ b/meson/test cases/cuda/13 cuda compiler setting/prog.cu @@ -0,0 +1,30 @@ +#include <iostream> + +int main(void) { + int cuda_devices = 0; + std::cout << "CUDA version: " << CUDART_VERSION << "\n"; + cudaGetDeviceCount(&cuda_devices); + if(cuda_devices == 0) { + std::cout << "No Cuda hardware found. Exiting.\n"; + return 0; + } + std::cout << "This computer has " << cuda_devices << " Cuda device(s).\n"; + cudaDeviceProp props; + cudaGetDeviceProperties(&props, 0); + std::cout << "Properties of device 0.\n\n"; + + std::cout << " Name: " << props.name << "\n"; + std::cout << " Global memory: " << props.totalGlobalMem << "\n"; + std::cout << " Shared memory: " << props.sharedMemPerBlock << "\n"; + std::cout << " Constant memory: " << props.totalConstMem << "\n"; + std::cout << " Block registers: " << props.regsPerBlock << "\n"; + + std::cout << " Warp size: " << props.warpSize << "\n"; + std::cout << " Threads per block: " << props.maxThreadsPerBlock << "\n"; + std::cout << " Max block dimensions: [ " << props.maxThreadsDim[0] << ", " << props.maxThreadsDim[1] << ", " << props.maxThreadsDim[2] << " ]" << "\n"; + std::cout << " Max grid dimensions: [ " << props.maxGridSize[0] << ", " << props.maxGridSize[1] << ", " << props.maxGridSize[2] << " ]" << "\n"; + std::cout << "\n"; + + return 0; +} + diff --git a/meson/test cases/cuda/14 cuda has header symbol/meson.build b/meson/test cases/cuda/14 cuda has header symbol/meson.build new file mode 100644 index 000000000..b29c52e58 --- /dev/null +++ b/meson/test cases/cuda/14 cuda has header symbol/meson.build @@ -0,0 +1,27 @@ +project('cuda has header symbol', 'cuda') + +cuda = meson.get_compiler('cuda') + +# C checks +assert (cuda.has_header_symbol('stdio.h', 'int'), 'base types should always be available') +assert (cuda.has_header_symbol('stdio.h', 'printf'), 'printf function not found') +assert (cuda.has_header_symbol('stdio.h', 'FILE'), 'FILE structure not found') +assert (cuda.has_header_symbol('limits.h', 'INT_MAX'), 'INT_MAX define not found') +assert (not cuda.has_header_symbol('limits.h', 'guint64'), 'guint64 is not defined in limits.h') +assert (not cuda.has_header_symbol('stdlib.h', 'FILE'), 'FILE structure is defined in stdio.h, not stdlib.h') +assert (not cuda.has_header_symbol('stdlol.h', 'printf'), 'stdlol.h shouldn\'t exist') +assert (not cuda.has_header_symbol('stdlol.h', 'int'), 'shouldn\'t be able to find "int" with invalid header') + +# C++ checks +assert (cuda.has_header_symbol('iostream', 'std::iostream'), 'iostream not found in iostream.h') +assert (cuda.has_header_symbol('vector', 'std::vector'), 'vector not found in vector.h') +assert (not cuda.has_header_symbol('limits.h', 'std::iostream'), 'iostream should not be defined in limits.h') + +# CUDA checks +assert (cuda.has_header_symbol('cuda.h', 'CUDA_VERSION'), 'CUDA_VERSION not found in cuda.h') +assert (not cuda.has_header_symbol('cuda.h', 'cublasSaxpy'), 'cublasSaxpy is defined in cublas.h, not cuda.h') +if cuda.version().version_compare('>=4.0') + assert (cuda.has_header_symbol('thrust/device_vector.h', 'thrust::device_vector'), 'thrust::device_vector not found') + assert (not cuda.has_header_symbol('thrust/fill.h', 'thrust::sort'), 'thrust::sort should not be defined in thrust/fill.h') +endif + diff --git a/meson/test cases/cuda/15 sanitizer/meson.build b/meson/test cases/cuda/15 sanitizer/meson.build new file mode 100644 index 000000000..367a4e2f8 --- /dev/null +++ b/meson/test cases/cuda/15 sanitizer/meson.build @@ -0,0 +1,4 @@ +project('simple', 'cuda', version : '1.0.0', + default_options: ['b_sanitize=address,undefined']) + +libtests = shared_library('tests', 'prog.cu') diff --git a/meson/test cases/cuda/15 sanitizer/prog.cu b/meson/test cases/cuda/15 sanitizer/prog.cu new file mode 100644 index 000000000..340b07aea --- /dev/null +++ b/meson/test cases/cuda/15 sanitizer/prog.cu @@ -0,0 +1,30 @@ +#include <iostream> + +int run_tests(void) { + int cuda_devices = 0; + std::cout << "CUDA version: " << CUDART_VERSION << "\n"; + cudaGetDeviceCount(&cuda_devices); + if(cuda_devices == 0) { + std::cout << "No Cuda hardware found. Exiting.\n"; + return 0; + } + std::cout << "This computer has " << cuda_devices << " Cuda device(s).\n"; + cudaDeviceProp props; + cudaGetDeviceProperties(&props, 0); + std::cout << "Properties of device 0.\n\n"; + + std::cout << " Name: " << props.name << "\n"; + std::cout << " Global memory: " << props.totalGlobalMem << "\n"; + std::cout << " Shared memory: " << props.sharedMemPerBlock << "\n"; + std::cout << " Constant memory: " << props.totalConstMem << "\n"; + std::cout << " Block registers: " << props.regsPerBlock << "\n"; + + std::cout << " Warp size: " << props.warpSize << "\n"; + std::cout << " Threads per block: " << props.maxThreadsPerBlock << "\n"; + std::cout << " Max block dimensions: [ " << props.maxThreadsDim[0] << ", " << props.maxThreadsDim[1] << ", " << props.maxThreadsDim[2] << " ]" << "\n"; + std::cout << " Max grid dimensions: [ " << props.maxGridSize[0] << ", " << props.maxGridSize[1] << ", " << props.maxGridSize[2] << " ]" << "\n"; + std::cout << "\n"; + + return 0; +} + diff --git a/meson/test cases/cuda/16 multistd/main.cu b/meson/test cases/cuda/16 multistd/main.cu new file mode 100644 index 000000000..a2ffba489 --- /dev/null +++ b/meson/test cases/cuda/16 multistd/main.cu @@ -0,0 +1,20 @@ +#include <cuda_runtime.h> +#include <iostream> + +auto cuda_devices(void) { + int result = 0; + cudaGetDeviceCount(&result); + return result; +} + + +int main(void) { + int n = cuda_devices(); + if (n == 0) { + std::cout << "No Cuda hardware found. Exiting.\n"; + return 0; + } + + std::cout << "Found " << n << "Cuda devices.\n"; + return 0; +} diff --git a/meson/test cases/cuda/16 multistd/meson.build b/meson/test cases/cuda/16 multistd/meson.build new file mode 100644 index 000000000..4769a87dd --- /dev/null +++ b/meson/test cases/cuda/16 multistd/meson.build @@ -0,0 +1,4 @@ +project('C++-CUDA multi-std', 'cpp', 'cuda', version : '1.0.0', default_options : ['cpp_std=c++17', 'cuda_std=c++14']) + +exe = executable('prog', 'main.cu') +test('cudatest', exe) diff --git a/meson/test cases/cuda/2 split/lib.cu b/meson/test cases/cuda/2 split/lib.cu new file mode 100644 index 000000000..850d7ddfb --- /dev/null +++ b/meson/test cases/cuda/2 split/lib.cu @@ -0,0 +1,13 @@ +#include <stdio.h> +#include <iostream> + +__global__ void kernel (void){ +} + +int do_cuda_stuff(void) { + kernel<<<1,1>>>(); + + printf("Hello, World!\n"); + return 0; +} + diff --git a/meson/test cases/cuda/2 split/main.cpp b/meson/test cases/cuda/2 split/main.cpp new file mode 100644 index 000000000..ce79003e5 --- /dev/null +++ b/meson/test cases/cuda/2 split/main.cpp @@ -0,0 +1,7 @@ +#include<iostream> + +int do_cuda_stuff(void); + +int main(void) { + return do_cuda_stuff(); +} diff --git a/meson/test cases/cuda/2 split/meson.build b/meson/test cases/cuda/2 split/meson.build new file mode 100644 index 000000000..51bf6ce23 --- /dev/null +++ b/meson/test cases/cuda/2 split/meson.build @@ -0,0 +1,7 @@ +project('simple', 'cuda', 'cpp') + +exe = executable('prog', 'main.cpp', 'lib.cu') +test('cudatest', exe) + +subdir('static') + diff --git a/meson/test cases/cuda/2 split/static/lib.cu b/meson/test cases/cuda/2 split/static/lib.cu new file mode 100644 index 000000000..c0471d048 --- /dev/null +++ b/meson/test cases/cuda/2 split/static/lib.cu @@ -0,0 +1,13 @@ +#include <stdio.h> +#include <iostream> + +__global__ void kernel (void){ +} + +int do_cuda_stuff() { + kernel<<<1,1>>>(); + + printf("Hello, World!\n"); + return 0; +} + diff --git a/meson/test cases/cuda/2 split/static/libsta.cu b/meson/test cases/cuda/2 split/static/libsta.cu new file mode 100644 index 000000000..c0471d048 --- /dev/null +++ b/meson/test cases/cuda/2 split/static/libsta.cu @@ -0,0 +1,13 @@ +#include <stdio.h> +#include <iostream> + +__global__ void kernel (void){ +} + +int do_cuda_stuff() { + kernel<<<1,1>>>(); + + printf("Hello, World!\n"); + return 0; +} + diff --git a/meson/test cases/cuda/2 split/static/main_static.cpp b/meson/test cases/cuda/2 split/static/main_static.cpp new file mode 100644 index 000000000..ce79003e5 --- /dev/null +++ b/meson/test cases/cuda/2 split/static/main_static.cpp @@ -0,0 +1,7 @@ +#include<iostream> + +int do_cuda_stuff(void); + +int main(void) { + return do_cuda_stuff(); +} diff --git a/meson/test cases/cuda/2 split/static/meson.build b/meson/test cases/cuda/2 split/static/meson.build new file mode 100644 index 000000000..9078198d5 --- /dev/null +++ b/meson/test cases/cuda/2 split/static/meson.build @@ -0,0 +1,4 @@ +l = static_library('clib', 'lib.cu') +exe = executable('staexe', 'main_static.cpp', + link_with : l) +test('static Cuda test', exe) diff --git a/meson/test cases/cuda/3 cudamodule/meson.build b/meson/test cases/cuda/3 cudamodule/meson.build new file mode 100644 index 000000000..fd5e83fea --- /dev/null +++ b/meson/test cases/cuda/3 cudamodule/meson.build @@ -0,0 +1,70 @@ +project('cudamodule', 'cuda', version : '1.0.0') + +nvcc = meson.get_compiler('cuda') +cuda = import('unstable-cuda') + +arch_flags = cuda.nvcc_arch_flags(nvcc.version(), 'Auto', detected: ['6.0']) +arch_readable = cuda.nvcc_arch_readable(nvcc.version(), 'Auto', detected: ['6.0']) +driver_version = cuda.min_driver_version(nvcc.version()) + +message('NVCC version: ' + nvcc.version()) +message('NVCC flags: ' + ' '.join(arch_flags)) +message('NVCC readable: ' + ' '.join(arch_readable)) +message('Driver version: >=' + driver_version) + +exe = executable('prog', 'prog.cu', cuda_args: arch_flags) +test('cudatest', exe) + + +# +# Assert Series +# + +# Sanity test. +assert(' '.join(cuda.nvcc_arch_flags('11.1', '8.6')) == + '-gencode arch=compute_86,code=sm_86') + +# CUDA Toolkit too old, flag filtered out. +assert(' '.join(cuda.nvcc_arch_flags('11.0', '8.6')) == + '') + +# Named architectures. +assert(' '.join(cuda.nvcc_arch_flags('11.0', 'Ampere')) == + '-gencode arch=compute_80,code=sm_80') + +# Splitting & deduplication. +assert(' '.join(cuda.nvcc_arch_flags('11.0', 'Ampere;8.0,8.0')) == + '-gencode arch=compute_80,code=sm_80') + +# Same, but list supplied as list. +assert(' '.join(cuda.nvcc_arch_flags('11.0', ['Ampere', '8.0', '8.0'])) == + '-gencode arch=compute_80,code=sm_80') + +# Same, but mode set to Auto with detected set to a string with a variety of separators. +assert(' '.join(cuda.nvcc_arch_flags('11.0', 'Auto', detected: 'Ampere;8.0,8.0')) == + '-gencode arch=compute_80,code=sm_80') + +# Same, but detected set to a list. +assert(' '.join(cuda.nvcc_arch_flags('11.0', 'Auto', detected: ['Ampere', '8.0', '8.0'])) == + '-gencode arch=compute_80,code=sm_80') + +# Ask for 8.6 binary with 8.0-level PTX. +assert(' '.join(cuda.nvcc_arch_flags('11.1', '8.6(8.0)')) == + '-gencode arch=compute_80,code=sm_86') + +# Same, but keep the 8.0 PTX. +assert(' '.join(cuda.nvcc_arch_flags('11.1', '8.6(8.0)+PTX')) == + '-gencode arch=compute_80,code=sm_86 -gencode arch=compute_80,code=compute_80') + +# Detected Ampere RTX 3090 on CUDA 10.2, saturate to 7.5+PTX +assert(' '.join(cuda.nvcc_arch_flags('10.2', 'Auto', detected: ['8.0'])) == + '-gencode arch=compute_75,code=sm_75 -gencode arch=compute_75,code=compute_75') + +# Failed to auto-detect with CUDA 10.2, default to common GPUs (3.0;3.5;5.0;5.2;6.0;6.1;7.0;7.5+PTX) +assert(' '.join(cuda.nvcc_arch_flags('10.2', 'Auto', detected: [])) == + '-gencode arch=compute_30,code=sm_30 -gencode arch=compute_35,code=sm_35 '+ + '-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_75,code=compute_75') + diff --git a/meson/test cases/cuda/3 cudamodule/prog.cu b/meson/test cases/cuda/3 cudamodule/prog.cu new file mode 100644 index 000000000..b893bd331 --- /dev/null +++ b/meson/test cases/cuda/3 cudamodule/prog.cu @@ -0,0 +1,30 @@ +#include <iostream> + +int main(void) { + int cuda_devices = 0; + std::cout << "CUDA version: " << CUDART_VERSION << "\n"; + cudaGetDeviceCount(&cuda_devices); + if(cuda_devices == 0) { + std::cout << "No Cuda hardware found. Exiting.\n"; + return 0; + } + std::cout << "This computer has " << cuda_devices << " Cuda device(s).\n"; + cudaDeviceProp props; + cudaGetDeviceProperties(&props, 0); + std::cout << "Properties of device 0.\n\n"; + + std::cout << " Name: " << props.name << "\n"; + std::cout << " Global memory: " << props.totalGlobalMem << "\n"; + std::cout << " Shared memory: " << props.sharedMemPerBlock << "\n"; + std::cout << " Constant memory: " << props.totalConstMem << "\n"; + std::cout << " Block registers: " << props.regsPerBlock << "\n"; + + std::cout << " Warp size: " << props.warpSize << "\n"; + std::cout << " Threads per block: " << props.maxThreadsPerBlock << "\n"; + std::cout << " Max block dimensions: [ " << props.maxThreadsDim[0] << ", " << props.maxThreadsDim[1] << ", " << props.maxThreadsDim[2] << " ]" << "\n"; + std::cout << " Max grid dimensions: [ " << props.maxGridSize[0] << ", " << props.maxGridSize[1] << ", " << props.maxGridSize[2] << " ]" << "\n"; + std::cout << "\n"; + + return 0; +} + diff --git a/meson/test cases/cuda/4 shared/main.cu b/meson/test cases/cuda/4 shared/main.cu new file mode 100644 index 000000000..12359140e --- /dev/null +++ b/meson/test cases/cuda/4 shared/main.cu @@ -0,0 +1,20 @@ +#include <stdio.h> +#include <cuda_runtime.h> +#include "shared/kernels.h" + + +int main(void) { + int cuda_devices = 0; + cudaGetDeviceCount(&cuda_devices); + if(cuda_devices == 0) { + printf("No Cuda hardware found. Exiting.\n"); + return 0; + } + + if(run_tests() != 0){ + printf("CUDA tests failed! Exiting.\n"); + return 0; + } + + return 0; +} diff --git a/meson/test cases/cuda/4 shared/meson.build b/meson/test cases/cuda/4 shared/meson.build new file mode 100644 index 000000000..532aaebfb --- /dev/null +++ b/meson/test cases/cuda/4 shared/meson.build @@ -0,0 +1,6 @@ +project('simple', 'cuda', version : '1.0.0') + +subdir('shared') + +exe = executable('prog', 'main.cu', dependencies: libkernels) +test('cudatest', exe) diff --git a/meson/test cases/cuda/4 shared/shared/kernels.cu b/meson/test cases/cuda/4 shared/shared/kernels.cu new file mode 100644 index 000000000..41a95536f --- /dev/null +++ b/meson/test cases/cuda/4 shared/shared/kernels.cu @@ -0,0 +1,14 @@ +#include <stdio.h> +#include <cuda_runtime.h> +#include "kernels.h" + + +TAG_HIDDEN __global__ void kernel (void){ +} + +TAG_PUBLIC int run_tests(void) { + kernel<<<1,1>>>(); + + return (int)cudaDeviceSynchronize(); +} + diff --git a/meson/test cases/cuda/4 shared/shared/kernels.h b/meson/test cases/cuda/4 shared/shared/kernels.h new file mode 100644 index 000000000..dbcb99d10 --- /dev/null +++ b/meson/test cases/cuda/4 shared/shared/kernels.h @@ -0,0 +1,86 @@ +/* Include Guard */ +#ifndef SHARED_KERNELS_H +#define SHARED_KERNELS_H + +/** + * Includes + */ + +#include <cuda_runtime.h> + + +/** + * Defines + */ + +/** + * When building a library, it is a good idea to expose as few as possible + * internal symbols (functions, objects, data structures). Not only does it + * prevent users from relying on private portions of the library that are + * subject to change without any notice, but it can have performance + * advantages: + * + * - It can make shared libraries link faster at dynamic-load time. + * - It can make internal function calls faster by bypassing the PLT. + * + * Thus, the compilation should by default hide all symbols, while the API + * headers will explicitly mark public the few symbols the users are permitted + * to use with a PUBLIC tag. We also define a HIDDEN tag, since it may be + * required to explicitly tag certain C++ types as visible in order for + * exceptions to function correctly. + * + * Additional complexity comes from non-POSIX-compliant systems, which + * artificially impose a requirement on knowing whether we are building or + * using a DLL. + * + * The above commentary and below code is inspired from + * 'https://gcc.gnu.org/wiki/Visibility' + */ + +#if defined(_WIN32) || defined(__CYGWIN__) +# define TAG_ATTRIBUTE_EXPORT __declspec(dllexport) +# define TAG_ATTRIBUTE_IMPORT __declspec(dllimport) +# define TAG_ATTRIBUTE_HIDDEN +#elif __GNUC__ >= 4 +# define TAG_ATTRIBUTE_EXPORT __attribute__((visibility("default"))) +# define TAG_ATTRIBUTE_IMPORT __attribute__((visibility("default"))) +# define TAG_ATTRIBUTE_HIDDEN __attribute__((visibility("hidden"))) +#else +# define TAG_ATTRIBUTE_EXPORT +# define TAG_ATTRIBUTE_IMPORT +# define TAG_ATTRIBUTE_HIDDEN +#endif + +#if TAG_IS_SHARED +# if TAG_IS_BUILDING +# define TAG_PUBLIC TAG_ATTRIBUTE_EXPORT +# else +# define TAG_PUBLIC TAG_ATTRIBUTE_IMPORT +# endif +# define TAG_HIDDEN TAG_ATTRIBUTE_HIDDEN +#else +# define TAG_PUBLIC +# define TAG_HIDDEN +#endif +#define TAG_STATIC static + + + + +/* Extern "C" Guard */ +#ifdef __cplusplus +extern "C" { +#endif + + + +/* Function Prototypes */ +TAG_PUBLIC int run_tests(void); + + + +/* End Extern "C" and Include Guard */ +#ifdef __cplusplus +} +#endif +#endif diff --git a/meson/test cases/cuda/4 shared/shared/meson.build b/meson/test cases/cuda/4 shared/shared/meson.build new file mode 100644 index 000000000..59879166b --- /dev/null +++ b/meson/test cases/cuda/4 shared/shared/meson.build @@ -0,0 +1,5 @@ +libkernels = shared_library('kernels', 'kernels.cu', + cuda_args: ['-DTAG_IS_SHARED=1', '-DTAG_IS_BUILDING=1'], + gnu_symbol_visibility: 'hidden') +libkernels = declare_dependency(compile_args: ['-DTAG_IS_SHARED=1'], + link_with: libkernels) diff --git a/meson/test cases/cuda/5 threads/main.cu b/meson/test cases/cuda/5 threads/main.cu new file mode 100644 index 000000000..12359140e --- /dev/null +++ b/meson/test cases/cuda/5 threads/main.cu @@ -0,0 +1,20 @@ +#include <stdio.h> +#include <cuda_runtime.h> +#include "shared/kernels.h" + + +int main(void) { + int cuda_devices = 0; + cudaGetDeviceCount(&cuda_devices); + if(cuda_devices == 0) { + printf("No Cuda hardware found. Exiting.\n"); + return 0; + } + + if(run_tests() != 0){ + printf("CUDA tests failed! Exiting.\n"); + return 0; + } + + return 0; +} diff --git a/meson/test cases/cuda/5 threads/meson.build b/meson/test cases/cuda/5 threads/meson.build new file mode 100644 index 000000000..2a804a34f --- /dev/null +++ b/meson/test cases/cuda/5 threads/meson.build @@ -0,0 +1,7 @@ +project('simple', 'cuda', version : '1.0.0') + +subdir('shared') + +thread_dep = dependency('threads') +exe = executable('prog', 'main.cu', dependencies: [libkernels, thread_dep]) +test('cudatest', exe) diff --git a/meson/test cases/cuda/5 threads/shared/kernels.cu b/meson/test cases/cuda/5 threads/shared/kernels.cu new file mode 100644 index 000000000..41a95536f --- /dev/null +++ b/meson/test cases/cuda/5 threads/shared/kernels.cu @@ -0,0 +1,14 @@ +#include <stdio.h> +#include <cuda_runtime.h> +#include "kernels.h" + + +TAG_HIDDEN __global__ void kernel (void){ +} + +TAG_PUBLIC int run_tests(void) { + kernel<<<1,1>>>(); + + return (int)cudaDeviceSynchronize(); +} + diff --git a/meson/test cases/cuda/5 threads/shared/kernels.h b/meson/test cases/cuda/5 threads/shared/kernels.h new file mode 100644 index 000000000..dbcb99d10 --- /dev/null +++ b/meson/test cases/cuda/5 threads/shared/kernels.h @@ -0,0 +1,86 @@ +/* Include Guard */ +#ifndef SHARED_KERNELS_H +#define SHARED_KERNELS_H + +/** + * Includes + */ + +#include <cuda_runtime.h> + + +/** + * Defines + */ + +/** + * When building a library, it is a good idea to expose as few as possible + * internal symbols (functions, objects, data structures). Not only does it + * prevent users from relying on private portions of the library that are + * subject to change without any notice, but it can have performance + * advantages: + * + * - It can make shared libraries link faster at dynamic-load time. + * - It can make internal function calls faster by bypassing the PLT. + * + * Thus, the compilation should by default hide all symbols, while the API + * headers will explicitly mark public the few symbols the users are permitted + * to use with a PUBLIC tag. We also define a HIDDEN tag, since it may be + * required to explicitly tag certain C++ types as visible in order for + * exceptions to function correctly. + * + * Additional complexity comes from non-POSIX-compliant systems, which + * artificially impose a requirement on knowing whether we are building or + * using a DLL. + * + * The above commentary and below code is inspired from + * 'https://gcc.gnu.org/wiki/Visibility' + */ + +#if defined(_WIN32) || defined(__CYGWIN__) +# define TAG_ATTRIBUTE_EXPORT __declspec(dllexport) +# define TAG_ATTRIBUTE_IMPORT __declspec(dllimport) +# define TAG_ATTRIBUTE_HIDDEN +#elif __GNUC__ >= 4 +# define TAG_ATTRIBUTE_EXPORT __attribute__((visibility("default"))) +# define TAG_ATTRIBUTE_IMPORT __attribute__((visibility("default"))) +# define TAG_ATTRIBUTE_HIDDEN __attribute__((visibility("hidden"))) +#else +# define TAG_ATTRIBUTE_EXPORT +# define TAG_ATTRIBUTE_IMPORT +# define TAG_ATTRIBUTE_HIDDEN +#endif + +#if TAG_IS_SHARED +# if TAG_IS_BUILDING +# define TAG_PUBLIC TAG_ATTRIBUTE_EXPORT +# else +# define TAG_PUBLIC TAG_ATTRIBUTE_IMPORT +# endif +# define TAG_HIDDEN TAG_ATTRIBUTE_HIDDEN +#else +# define TAG_PUBLIC +# define TAG_HIDDEN +#endif +#define TAG_STATIC static + + + + +/* Extern "C" Guard */ +#ifdef __cplusplus +extern "C" { +#endif + + + +/* Function Prototypes */ +TAG_PUBLIC int run_tests(void); + + + +/* End Extern "C" and Include Guard */ +#ifdef __cplusplus +} +#endif +#endif diff --git a/meson/test cases/cuda/5 threads/shared/meson.build b/meson/test cases/cuda/5 threads/shared/meson.build new file mode 100644 index 000000000..59879166b --- /dev/null +++ b/meson/test cases/cuda/5 threads/shared/meson.build @@ -0,0 +1,5 @@ +libkernels = shared_library('kernels', 'kernels.cu', + cuda_args: ['-DTAG_IS_SHARED=1', '-DTAG_IS_BUILDING=1'], + gnu_symbol_visibility: 'hidden') +libkernels = declare_dependency(compile_args: ['-DTAG_IS_SHARED=1'], + link_with: libkernels) diff --git a/meson/test cases/cuda/6 std/main.cu b/meson/test cases/cuda/6 std/main.cu new file mode 100644 index 000000000..a2ffba489 --- /dev/null +++ b/meson/test cases/cuda/6 std/main.cu @@ -0,0 +1,20 @@ +#include <cuda_runtime.h> +#include <iostream> + +auto cuda_devices(void) { + int result = 0; + cudaGetDeviceCount(&result); + return result; +} + + +int main(void) { + int n = cuda_devices(); + if (n == 0) { + std::cout << "No Cuda hardware found. Exiting.\n"; + return 0; + } + + std::cout << "Found " << n << "Cuda devices.\n"; + return 0; +} diff --git a/meson/test cases/cuda/6 std/meson.build b/meson/test cases/cuda/6 std/meson.build new file mode 100644 index 000000000..69a6868ca --- /dev/null +++ b/meson/test cases/cuda/6 std/meson.build @@ -0,0 +1,4 @@ +project('C++ std', 'cuda', version : '1.0.0', default_options : ['cuda_std=c++14']) + +exe = executable('prog', 'main.cu') +test('cudatest', exe) diff --git a/meson/test cases/cuda/7 static vs runtime/main.cu b/meson/test cases/cuda/7 static vs runtime/main.cu new file mode 100644 index 000000000..bd1dbc4a0 --- /dev/null +++ b/meson/test cases/cuda/7 static vs runtime/main.cu @@ -0,0 +1,20 @@ +#include <cuda_runtime.h> +#include <iostream> + +int cuda_devices(void) { + int result = 0; + cudaGetDeviceCount(&result); + return result; +} + + +int main(void) { + int n = cuda_devices(); + if (n == 0) { + std::cout << "No Cuda hardware found. Exiting.\n"; + return 0; + } + + std::cout << "Found " << n << "Cuda devices.\n"; + return 0; +} diff --git a/meson/test cases/cuda/7 static vs runtime/meson.build b/meson/test cases/cuda/7 static vs runtime/meson.build new file mode 100644 index 000000000..ab133044d --- /dev/null +++ b/meson/test cases/cuda/7 static vs runtime/meson.build @@ -0,0 +1,4 @@ +project('static msvc runtime', 'cuda', version : '1.0.0', default_options : ['b_vscrt=mtd']) + +exe = executable('prog', 'main.cu') +test('cudatest', exe) diff --git a/meson/test cases/cuda/8 release/main.cu b/meson/test cases/cuda/8 release/main.cu new file mode 100644 index 000000000..bd1dbc4a0 --- /dev/null +++ b/meson/test cases/cuda/8 release/main.cu @@ -0,0 +1,20 @@ +#include <cuda_runtime.h> +#include <iostream> + +int cuda_devices(void) { + int result = 0; + cudaGetDeviceCount(&result); + return result; +} + + +int main(void) { + int n = cuda_devices(); + if (n == 0) { + std::cout << "No Cuda hardware found. Exiting.\n"; + return 0; + } + + std::cout << "Found " << n << "Cuda devices.\n"; + return 0; +} diff --git a/meson/test cases/cuda/8 release/meson.build b/meson/test cases/cuda/8 release/meson.build new file mode 100644 index 000000000..bdb311d96 --- /dev/null +++ b/meson/test cases/cuda/8 release/meson.build @@ -0,0 +1,4 @@ +project('release', 'cuda', version : '1.0.0', default_options : ['buildtype=release']) + +exe = executable('prog', 'main.cu') +test('cudatest', exe) diff --git a/meson/test cases/cuda/9 optimize for space/main.cu b/meson/test cases/cuda/9 optimize for space/main.cu new file mode 100644 index 000000000..bd1dbc4a0 --- /dev/null +++ b/meson/test cases/cuda/9 optimize for space/main.cu @@ -0,0 +1,20 @@ +#include <cuda_runtime.h> +#include <iostream> + +int cuda_devices(void) { + int result = 0; + cudaGetDeviceCount(&result); + return result; +} + + +int main(void) { + int n = cuda_devices(); + if (n == 0) { + std::cout << "No Cuda hardware found. Exiting.\n"; + return 0; + } + + std::cout << "Found " << n << "Cuda devices.\n"; + return 0; +} diff --git a/meson/test cases/cuda/9 optimize for space/meson.build b/meson/test cases/cuda/9 optimize for space/meson.build new file mode 100644 index 000000000..cd6ac055d --- /dev/null +++ b/meson/test cases/cuda/9 optimize for space/meson.build @@ -0,0 +1,4 @@ +project('optimize for space', 'cuda', version : '1.0.0', default_options : ['optimization=s']) + +exe = executable('prog', 'main.cu') +test('cudatest', exe) |