GHOST  1.1.2
General, Hybrid, and Optimized Sparse Toolkit
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
cu_util.h
Go to the documentation of this file.
1 
7 #ifndef GHOST_CU_UTIL_H
8 #define GHOST_CU_UTIL_H
9 
10 #include "config.h"
11 #include "types.h"
12 #include "error.h"
13 #ifdef GHOST_HAVE_CUDA
14 #include <cublas_v2.h>
15 #include <curand.h>
16 #include <cusparse_v2.h>
17 #endif
18 
19 #ifdef GHOST_HAVE_CUDA
20 typedef cublasHandle_t ghost_cublas_handle_t;
21 typedef cusparseHandle_t ghost_cusparse_handle_t;
22 typedef struct cudaDeviceProp ghost_cu_deviceprop;
23 typedef curandGenerator_t ghost_cu_rand_generator;
24 #else
27 typedef int ghost_cu_deviceprop;
29 #endif
30 
34 typedef struct {
42  int *ndevice;
46  char **names;
48 
49 #ifdef __cplusplus
50 extern "C" {
51 #endif
52 
60 ghost_error ghost_cu_init(int dev);
69 ghost_error ghost_cu_malloc_managed(void **mem, size_t bytesize);
78 ghost_error ghost_cu_malloc(void **mem, size_t bytesize);
87 ghost_error ghost_cu_malloc_mapped(void **mem, const size_t size);
96 ghost_error ghost_cu_malloc_pinned(void **mem, const size_t size);
106 ghost_error ghost_cu_download(void *hostmem, void *devmem, size_t bytesize);
120 ghost_error ghost_cu_download2d(void *dest, size_t dpitch, const void *src, size_t spitch, size_t width, size_t height);
130 ghost_error ghost_cu_upload(void *devmem, void *hostmem, size_t bytesize);
144 ghost_error ghost_cu_upload2d(void *dest, size_t dpitch, const void *src, size_t spitch, size_t width, size_t height);
154 ghost_error ghost_cu_memcpy(void *dest, void *src, size_t bytesize);
168 ghost_error ghost_cu_memcpy2d(void *dest, size_t dpitch, const void *src, size_t spitch, size_t width, size_t height);
178 ghost_error ghost_cu_memset(void *s, int c, size_t n);
186 ghost_error ghost_cu_free(void *mem);
209 ghost_error ghost_cu_ndevice(int *devcount);
217 ghost_error ghost_cu_version(int *ver);
233 ghost_error ghost_cu_device(int *device);
258 
261 ghost_error ghost_cu_memtranspose(int torows, int tocols, void *to, int ldto, const void *from, int ldfrom, ghost_datatype dt);
262 
263 ghost_error ghost_cu_reduce(void *out, void *data, ghost_datatype dt, ghost_lidx n);
264 ghost_error ghost_cu_reduce_multiple(void *out, void *data, ghost_datatype dt, ghost_lidx n, ghost_lidx ncols);
265 
266 #ifdef __cplusplus
267 }
268 #endif
269 
270 #endif
char ** names
The names of each distince device type.
Definition: cu_util.h:46
int ghost_cu_deviceprop
Definition: cu_util.h:27
ghost_error ghost_cu_reduce(void *out, void *data, ghost_datatype dt, ghost_lidx n)
Header file for type definitions.
ghost_error ghost_cu_cublas_handle(ghost_cublas_handle_t *handle)
Get the cuBLAS handle.
Definition: cu_util.c:452
ghost_error ghost_cu_malloc_mapped(void **mem, const size_t size)
Allocate mapped host memory.
Definition: cu_util.c:397
ghost_error ghost_cu_finalize()
Definition: cu_util.c:548
ghost_error ghost_cu_memcpy(void *dest, void *src, size_t bytesize)
Memcpy GPU memory.
Definition: cu_util.c:108
Information about avaiable GPUs.
Definition: cu_util.h:34
ghost_error ghost_cu_ndevice(int *devcount)
Get the number of available GPUs.
Definition: cu_util.c:264
ghost_error ghost_cu_upload(void *devmem, void *hostmem, size_t bytesize)
Upload memory from the the host to the GPU.
Definition: cu_util.c:160
ghost_error ghost_cu_deviceprop_get(ghost_cu_deviceprop *prop)
Get the CUDA device properties.
Definition: cu_util.c:517
int * ndevice
The number of GPUs of each distinct device type.
Definition: cu_util.h:42
ghost_error ghost_cu_init(int dev)
Initalize CUDA on a given device.
Definition: cu_util.c:33
ghost_error ghost_cu_memset(void *s, int c, size_t n)
Memset GPU memory.
Definition: cu_util.c:145
int32_t ghost_lidx
Definition: types.h:503
ghost_error ghost_cu_device(int *device)
Get the active GPU.
Definition: cu_util.c:435
ghost_error ghost_cu_memtranspose(int torows, int tocols, void *to, int ldto, const void *from, int ldfrom, ghost_datatype dt)
Definition: cu_util.c:566
ghost_error ghost_cu_malloc(void **mem, size_t bytesize)
Allocate CUDA device memory.
Definition: cu_util.c:88
ghost_error ghost_cu_gpu_info_create(ghost_gpu_info **gpu_info)
Get information about available GPUs.
Definition: cu_util.c:280
Types, functions and macros for error handling.
ghost_error
Error return type.
Definition: error.h:23
ghost_error ghost_cu_memcpy2d(void *dest, size_t dpitch, const void *src, size_t spitch, size_t width, size_t height)
Memcpy strided GPU memory. Copy height rows of width bytes each.
Definition: cu_util.c:126
int ghost_cu_rand_generator
Definition: cu_util.h:28
ghost_error ghost_cu_rand_generator_get(ghost_cu_rand_generator *gen)
Definition: cu_util.c:530
ghost_error ghost_cu_free(void *mem)
Free GPU memory.
Definition: cu_util.c:232
ghost_error ghost_cu_download2d(void *dest, size_t dpitch, const void *src, size_t spitch, size_t width, size_t height)
Download strided memory from a GPU to the host. Copy height rows of width bytes each.
Definition: cu_util.c:196
ghost_error ghost_cu_barrier()
Wait for any outstanding CUDA kernel.
Definition: cu_util.c:246
ghost_datatype
Available primitive data types.
Definition: types.h:248
ghost_error ghost_cu_cusparse_handle(ghost_cusparse_handle_t *handle)
Get the CuSparse handle.
Definition: cu_util.c:469
ghost_error ghost_cu_download(void *hostmem, void *devmem, size_t bytesize)
Download memory from a GPU to the host.
Definition: cu_util.c:215
int ghost_cublas_handle_t
Definition: cu_util.h:25
ghost_error ghost_cu_reduce_multiple(void *out, void *data, ghost_datatype dt, ghost_lidx n, ghost_lidx ncols)
ghost_error ghost_cu_version(int *ver)
Get the CUDA version.
Definition: cu_util.c:486
ghost_error ghost_cu_malloc_managed(void **mem, size_t bytesize)
Allocate managed CUDA device memory.
Definition: cu_util.c:68
ghost_error ghost_cu_upload2d(void *dest, size_t dpitch, const void *src, size_t spitch, size_t width, size_t height)
Upload strided memory from the host to the GPU. Copy height rows of width bytes each.
Definition: cu_util.c:177
int ghost_cusparse_handle_t
Definition: cu_util.h:26
ghost_error ghost_cu_malloc_pinned(void **mem, const size_t size)
Allocate pinned host memory.
Definition: cu_util.c:416
int ndistinctdevice
The number of distinct CUDA device types.
Definition: cu_util.h:38
ghost_error ghost_cu_free_host(void *mem)
Free host memory which has been allocated with ghost_cu_malloc_pinned() or ghost_cu_malloc_mapped().
Definition: cu_util.c:505