fml  0.1-0
Fused Matrix Library
gpuprims.hh
1 // This file is part of fml which is released under the Boost Software
2 // License, Version 1.0. See accompanying file LICENSE or copy at
3 // https://www.boost.org/LICENSE_1_0.txt
4 
5 #ifndef FML_GPU_ARCH_CUDA_GPUPRIMS_H
6 #define FML_GPU_ARCH_CUDA_GPUPRIMS_H
7 #pragma once
8 
9 
10 #include <cublas.h>
11 #include <cusolverDn.h>
12 
13 
14 namespace fml
15 {
16  namespace gpuprims
17  {
18  // device management
19  inline cudaError_t get_device_count(int *ngpus)
20  {
21  return cudaGetDeviceCount(ngpus);
22  }
23 
24  inline cudaError_t gpu_set_device(int device)
25  {
26  return cudaSetDevice(device);
27  }
28 
29  inline cudaError_t gpu_synch()
30  {
31  return cudaDeviceSynchronize();
32  }
33 
34  inline cudaError_t gpu_device_reset()
35  {
36  return cudaDeviceReset();
37  }
38 
39 
40 
41  // memory management
42  inline cudaError_t gpu_malloc(void **x, size_t size)
43  {
44  return cudaMalloc(x, size);
45  }
46 
47  inline cudaError_t gpu_memset(void *x, int value, size_t count)
48  {
49  return cudaMemset(x, value, count);
50  }
51 
52  inline cudaError_t gpu_free(void *x)
53  {
54  return cudaFree(x);
55  }
56 
57  inline cudaError_t gpu_memcpy(void *dst, const void *src, size_t count, cudaMemcpyKind kind)
58  {
59  return cudaMemcpy(dst, src, count, kind);
60  }
61 
62 
63 
64  // error handling
65  inline std::string gpu_error_string(cudaError_t code)
66  {
67  return cudaGetErrorString(code);
68  }
69 
70  inline cudaError_t gpu_last_error()
71  {
72  return cudaGetLastError();
73  }
74 
75 
76 
77  // cublas and cusolver
78  inline cublasStatus_t gpu_blas_init(cublasHandle_t *handle)
79  {
80  return cublasCreate(handle);
81  }
82 
83  inline cublasStatus_t gpu_blas_free(cublasHandle_t handle)
84  {
85  return cublasDestroy(handle);
86  }
87 
88  inline cusolverStatus_t gpu_lapack_init(cusolverDnHandle_t *handle)
89  {
90  return cusolverDnCreate(handle);
91  }
92 
93  inline cusolverStatus_t gpu_lapack_free(cusolverDnHandle_t handle)
94  {
95  return cusolverDnDestroy(handle);
96  }
97  }
98 }
99 
100 
101 #endif
fml
Core namespace.
Definition: dimops.hh:10
fml::get_device_count
int get_device_count()
Return number of GPU devices.
Definition: card.hh:19