UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
cuda_wrapper.cu File Reference
#include <stdio.h>
#include <stdlib.h>
#include "cuda_runtime.h"
#include "cuda_wrapper.h"
Include dependency graph for cuda_wrapper.cu:

Go to the source code of this file.

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)
 
static int map_cuda_error (cudaError_t cuda_error)
 
static enum cudaMemcpyKind map_cuda_memcpy_kind (int our_kind)
 
static const char * map_error_string (int error)
 

Typedef Documentation

◆ cuda_wrapper_stream_t

typedef void* cuda_wrapper_stream_t

Definition at line 51 of file cuda_wrapper.cu.

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:

◆ map_cuda_error()

static int map_cuda_error ( cudaError_t cuda_error)
inlinestatic

◆ map_cuda_memcpy_kind()

static enum cudaMemcpyKind map_cuda_memcpy_kind ( int our_kind)
inlinestatic

Definition at line 62 of file cuda_wrapper.cu.

62 {
63 struct kind_mapping {
64 enum cudaMemcpyKind kind;
65 int our_kind;
66 };
67 struct kind_mapping mapping[] = {
69 { cudaMemcpyDeviceToHost, CUDA_WRAPPER_MEMCPY_DEVICE_TO_HOST },
70 };
71
72 int i;
73 for (i = 0; i < sizeof(mapping)/sizeof(struct kind_mapping); ++i) {
74 if (our_kind == mapping[i].our_kind) {
75 return mapping[i].kind;
76 }
77 }
78
79 abort(); // should not reach here
80};
static const struct codec_param mapping[AC_COUNT]
Definition libavcodec.c:87
#define cudaMemcpyHostToDevice
#define CUDA_WRAPPER_MEMCPY_HOST_TO_DEVICE
#define CUDA_WRAPPER_MEMCPY_DEVICE_TO_HOST

References CUDA_WRAPPER_MEMCPY_DEVICE_TO_HOST, CUDA_WRAPPER_MEMCPY_HOST_TO_DEVICE, cudaMemcpyHostToDevice, and mapping.

Referenced by cuda_wrapper_memcpy().

◆ map_error_string()

static const char * map_error_string ( int error)
inlinestatic

Definition at line 57 of file cuda_wrapper.cu.

57 {
58
59 return cudaGetErrorString((cudaError_t) error);
60};
#define cudaError_t

References cudaError_t, and cudaGetErrorString.

Referenced by cuda_wrapper_get_error_string().