24#include <cuda_runtime.h>
30#if defined(OMPI_MPI_H) || defined(_MPI_H)
31#error CU-file includes mpi.h! This should not happen!
51 cudaDeviceProp deviceProp;
52 CUDA_CHECK(cudaGetDeviceProperties(&deviceProp, dev))
62 char buffer[256] = {
'\0'};
63 std::strncpy(buffer, prop.name, 256);
65 std::strncpy(name, buffer, 256);
69 cudaDeviceProp deviceProp;
70 CUDA_CHECK(cudaGetDeviceProperties(&deviceProp, dev))
75 cudaDeviceProp deviceProp;
76 CUDA_CHECK(cudaGetDeviceProperties(&deviceProp, dev))
83 deviceProp.totalGlobalMem,
84 deviceProp.multiProcessorCount};
102 auto const deleter = [](
int *p) { cudaFree(
reinterpret_cast<void *
>(p)); };
105 CUDA_CHECK(cudaMalloc(
reinterpret_cast<void **
>(&ptr),
sizeof(
int)));
106 std::unique_ptr<int,
decltype(deleter)> d(ptr, deleter);
107 CUDA_CHECK(cudaMemcpy(d.get(), &h,
sizeof(
int), cudaMemcpyHostToDevice));
109 CUDA_CHECK(cudaMemcpy(&h, d.get(),
sizeof(
int), cudaMemcpyDeviceToHost));
120 if (incompatible or communication_failure) {
122 " is not capable of running ESPResSo.");
Wrapper for CUDA runtime exceptions.
cudaStream_t stream[1]
CUDA streams for parallel computing on CPU and GPU.
static const int computeCapabilityMinMajor
EspressoGpuDevice cuda_get_device_props(const int dev)
Get properties of a CUDA device.
void cuda_check_device()
Check that a device is available, that its compute capability is sufficient for ESPResSo,...
bool cuda_check_gpu_compute_capability(int dev)
Check that a given GPU has compute capability.
void cuda_get_gpu_name(int dev, char *const name)
Get the name of a CUDA device.
bool cuda_test_device_access()
Test if communication to the CUDA device works.
static const int computeCapabilityMinMinor
int cuda_get_device()
Get the current CUDA device.
static void cuda_copy_gpu_name(char *const name, cudaDeviceProp const &prop)
Safely copy the device name and pad the string with null characters.
void cuda_set_device(int dev)
Choose a device for future CUDA computations.
int cuda_get_n_gpus()
Get the number of CUDA devices.
void cuda_init()
Initializes the CUDA stream.
Struct to hold information relevant to ESPResSo about GPUs.
#define CUDA_CHECK(statement)
Convert CUDA error codes into runtime errors.