forked from jwetzl/MAPSuperresolution
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GPUHandles.h
51 lines (44 loc) · 1.59 KB
/
GPUHandles.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/**
* ___ _ _ ___ _ __ __ _ ___
* / __| | | | \ /_\ | \/ | /_\ | _ \
* | (__| |_| | |) / _ \ | |\/| |/ _ \| _/
* \___|\___/|___/_/_\_\_|_|__|_/_/_\_\_|_ ___
* / __| | | | _ \ __| _ \___| _ \ __/ __|
* \__ \ |_| | _/ _|| /___| / _|\__ \
* |___/\___/|_| |___|_|_\ |_|_\___|___/
* 2012
*
* by Jens Wetzl ([email protected])
* and Oliver Taubmann ([email protected])
*
* This work is licensed under a Creative Commons
* Attribution 3.0 Unported License. (CC-BY)
* http://creativecommons.org/licenses/by/3.0/
*
**/
#ifndef GPU_HANDLES_H
#define GPU_HANDLES_H
#include "cudalbfgs_error_checking.h"
// A small wrapper for cuBLAS and cuSPARSE states with
// automatic initialization and cleanup.
struct GPUHandles
{
cublasHandle_t cublasHandle;
cusparseHandle_t cusparseHandle;
cusparseMatDescr_t cusparseDescriptor;
GPUHandles()
{
CublasSafeCall ( cublasCreate (&cublasHandle) );
CusparseSafeCall( cusparseCreate (&cusparseHandle) );
CusparseSafeCall( cusparseCreateMatDescr(&cusparseDescriptor) );
CusparseSafeCall( cusparseSetMatType (cusparseDescriptor, CUSPARSE_MATRIX_TYPE_GENERAL) );
CusparseSafeCall( cusparseSetMatIndexBase(cusparseDescriptor, CUSPARSE_INDEX_BASE_ZERO) );
}
~GPUHandles()
{
CublasSafeCall ( cublasDestroy (cublasHandle) );
CusparseSafeCall( cusparseDestroy (cusparseHandle) );
CusparseSafeCall( cusparseDestroyMatDescr(cusparseDescriptor) );
}
};
#endif // GPU_HANDLES_H