UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
cuda_wrapper.h File Reference

This file contais wrapper around CUDA functions. More...

#include <stddef.h>
Include dependency graph for cuda_wrapper.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define CUDA_WRAPPER_SUCCESS   0
 
#define CUDA_WRAPPER_MEMCPY_DEVICE_TO_HOST   1
 
#define CUDA_WRAPPER_MEMCPY_HOST_TO_DEVICE   0
 

Typedefs

typedef void * cuda_wrapper_stream_t
 

Functions

void cuda_wrapper_device_reset (void)
 
int cuda_wrapper_free (void *buffer)
 
int cuda_wrapper_free_host (void *buffer)
 
const char * cuda_wrapper_get_error_string (int error)
 
int cuda_wrapper_get_last_error (void)
 
int cuda_wrapper_host_alloc (void **pHost, size_t size, unsigned int flags)
 
const char * cuda_wrapper_last_error_string (void)
 
int cuda_wrapper_malloc (void **buffer, size_t data_len)
 
int cuda_wrapper_malloc_host (void **buffer, size_t data_len)
 
int cuda_wrapper_memcpy (void *dst, const void *src, size_t count, int kind)
 
void cuda_wrapper_print_devices_info (void)
 adapted from gpujpeg_print_devices_info()
 
int cuda_wrapper_set_device (int index)
 

Detailed Description

This file contais wrapper around CUDA functions.

Author
Martin Pulec pulec.nosp@m.@ces.nosp@m.net.c.nosp@m.z

This file is needed for Windows to wrap CUDA calls that need to be compiled with nvcc/MSVC and not gcc/clang as a glue with the rest of UltraGrid CUDA-related code (using cudaMemcpy etc., obviously not possible to compile kernels etc.)

Author
Martin Pulec pulec.nosp@m.@ces.nosp@m.net.c.nosp@m.z

Definition in file cuda_wrapper.h.

Macro Definition Documentation

◆ CUDA_WRAPPER_MEMCPY_DEVICE_TO_HOST

#define CUDA_WRAPPER_MEMCPY_DEVICE_TO_HOST   1

Definition at line 53 of file cuda_wrapper.h.

Referenced by map_cuda_memcpy_kind(), and worker_thread().

◆ CUDA_WRAPPER_MEMCPY_HOST_TO_DEVICE

#define CUDA_WRAPPER_MEMCPY_HOST_TO_DEVICE   0

Definition at line 52 of file cuda_wrapper.h.

Referenced by do_gpu_copy(), and map_cuda_memcpy_kind().

◆ CUDA_WRAPPER_SUCCESS

#define CUDA_WRAPPER_SUCCESS   0

Definition at line 48 of file cuda_wrapper.h.

Referenced by reconfigure_thread(), and worker_thread().

Typedef Documentation

◆ cuda_wrapper_stream_t

typedef void* cuda_wrapper_stream_t

Definition at line 56 of file cuda_wrapper.h.

Function Documentation

◆ cuda_wrapper_device_reset()

void cuda_wrapper_device_reset ( void )

Definition at line 168 of file cuda_wrapper.cu.

169{
170 // to allow "cuda-memcheck --leak-check full"
171 if (cudaDeviceReset() != cudaSuccess) {
172 fprintf(stderr, "cudaDeviceReset failed!\n");
173 }
174}
#define cudaSuccess

References cudaSuccess.

Referenced by common_cleanup().

◆ cuda_wrapper_free()

int cuda_wrapper_free ( void * buffer)

Definition at line 82 of file cuda_wrapper.cu.

83{
84 return map_cuda_error(cudaFree(buffer));
85}
#define cudaFree
static int map_cuda_error(cudaError_t cuda_error)

References cudaFree, and map_cuda_error().

Referenced by reconfigure_thread(), set_pool(), and worker_thread().

Here is the call graph for this function:

◆ cuda_wrapper_free_host()

int cuda_wrapper_free_host ( void * buffer)

Definition at line 87 of file cuda_wrapper.cu.

88{
89 return map_cuda_error(cudaFreeHost(buffer));
90}
#define cudaFreeHost

References cudaFreeHost, and map_cuda_error().

Referenced by set_pool().

Here is the call graph for this function:

◆ cuda_wrapper_get_error_string()

const char * cuda_wrapper_get_error_string ( int error)

Definition at line 125 of file cuda_wrapper.cu.

126{
127 return map_error_string(error);
128}
static const char * map_error_string(int error)

References map_error_string().

Here is the call graph for this function:

◆ cuda_wrapper_get_last_error()

int cuda_wrapper_get_last_error ( void )

Definition at line 120 of file cuda_wrapper.cu.

121{
123}
#define cudaGetLastError

References cudaGetLastError, and map_cuda_error().

Here is the call graph for this function:

◆ cuda_wrapper_host_alloc()

int cuda_wrapper_host_alloc ( void ** pHost,
size_t size,
unsigned int flags )

Definition at line 92 of file cuda_wrapper.cu.

93{
94 return map_cuda_error(cudaHostAlloc(pHost, size, flags));
95}
const char unsigned int flags
#define cudaHostAlloc

References cudaHostAlloc, flags, and map_cuda_error().

Here is the call graph for this function:

◆ cuda_wrapper_last_error_string()

const char * cuda_wrapper_last_error_string ( void )

Definition at line 115 of file cuda_wrapper.cu.

116{
118}
#define cudaGetErrorString

References cudaGetErrorString, and cudaGetLastError.

◆ cuda_wrapper_malloc()

int cuda_wrapper_malloc ( void ** buffer,
size_t data_len )

Definition at line 97 of file cuda_wrapper.cu.

98{
99 return map_cuda_error(cudaMalloc(buffer, data_len));
100}
#define cudaMalloc

References cudaMalloc, and map_cuda_error().

Referenced by set_pool().

Here is the call graph for this function:

◆ cuda_wrapper_malloc_host()

int cuda_wrapper_malloc_host ( void ** buffer,
size_t data_len )

Definition at line 102 of file cuda_wrapper.cu.

103{
104 return map_cuda_error(cudaMallocHost(buffer, data_len));
105}

References map_cuda_error().

Referenced by reconfigure_thread(), and set_pool().

Here is the call graph for this function:

◆ cuda_wrapper_memcpy()

int cuda_wrapper_memcpy ( void * dst,
const void * src,
size_t count,
int kind )

Definition at line 107 of file cuda_wrapper.cu.

109{
110 return map_cuda_error(
111 cudaMemcpy(dst, src, count,
112 map_cuda_memcpy_kind(kind)));
113}
#define cudaMemcpy
static enum cudaMemcpyKind map_cuda_memcpy_kind(int our_kind)
int count
Definition hd-rum.c:44

References count, cudaMemcpy, map_cuda_error(), and map_cuda_memcpy_kind().

Referenced by do_gpu_copy(), and worker_thread().

Here is the call graph for this function:

◆ cuda_wrapper_print_devices_info()

void cuda_wrapper_print_devices_info ( void )

adapted from gpujpeg_print_devices_info()

Definition at line 137 of file cuda_wrapper.cu.

138{
139 int device_count = 0;
140 if (cudaGetDeviceCount(&device_count) != cudaSuccess) {
141 fprintf(stderr, "Cannot get number of CUDA devices: %s\n", cudaGetErrorString(cudaGetLastError()));
142 return;
143 }
144 if (device_count == 0) {
145 fprintf(stderr, "There is no device supporting CUDA.\n");
146 } else {
147 printf("There %s %d devices supporting CUDA:\n", device_count == 1 ? "is" : "are", device_count);
148 }
149
150 for ( int device_id = 0; device_id < device_count; device_id++ ) {
151 struct cudaDeviceProp device_properties;
152 if (cudaGetDeviceProperties(&device_properties, device_id) != cudaSuccess) {
153 fprintf(stderr, "Cannot get number of CUDA device #%d properties: %s\n", device_id, cudaGetErrorString(cudaGetLastError()));
154 continue;
155 }
156
157 printf("\nDevice #%d: \"%s\"\n", device_id, device_properties.name);
158 printf(" Compute capability: %d.%d\n", device_properties.major, device_properties.minor);
159 printf(" Total amount of global memory: %zu kB\n", device_properties.totalGlobalMem / 1024);
160 printf(" Total amount of constant memory: %zu kB\n", device_properties.totalGlobalMem / 1024);
161 printf(" Total amount of shared memory per block: %zu kB\n", device_properties.sharedMemPerBlock / 1024);
162 printf(" Total number of registers available per block: %d\n", device_properties.regsPerBlock);
163 printf(" Multiprocessors: %d\n", device_properties.multiProcessorCount);
164 }
165}

References cudaGetErrorString, cudaGetLastError, and cudaSuccess.

Referenced by parse_cuda_device().

◆ cuda_wrapper_set_device()

int cuda_wrapper_set_device ( int index)

Definition at line 130 of file cuda_wrapper.cu.

131{
132 return map_cuda_error(
133 cudaSetDevice(index));
134}

References map_cuda_error().

Referenced by do_gpu_copy().

Here is the call graph for this function: