-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbase_cuda.cpp
49 lines (44 loc) · 1.04 KB
/
base_cuda.cpp
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
#include "base_cuda.h"
// Includes CUDA
#include <cuda_runtime.h>
// Utilities and timing functions
#include <helper_functions.h> // includes cuda.h and cuda_runtime_api.h
// CUDA helper functions
#include <helper_cuda.h> // helper functions for CUDA error check
void copy2gpu(void * h_data, void * d_data, int data_size)
{
cudaError_t err;
err = cudaMemcpy(d_data, h_data, data_size, cudaMemcpyHostToDevice);
if(err!= cudaSuccess)
{
printf("copy mem to gpu err!\n");
DEVICE_RESET
exit(EXIT_FAILURE);
}
}
void gpu_malloc(void ** d_data, int data_size)
{
cudaError_t err;
err = cudaMalloc((void **) d_data, data_size);
if(err!= cudaSuccess)
{
printf("gpu malloc mem err!\n");
DEVICE_RESET
exit(EXIT_FAILURE);
}
}
void copy2host(void * h_data, void * d_data , int data_size)
{
cudaError_t err;
err = cudaMemcpy(h_data, d_data, data_size, cudaMemcpyDeviceToHost);
if(err!= cudaSuccess)
{
printf("gpu malloc mem err!\n");
DEVICE_RESET
exit(EXIT_FAILURE);
}
}
void gpu_free(void * d_data)
{
cudaFree(d_data);
}