accelerInt  v0.1
rkc_init.cu
Go to the documentation of this file.
1 
10  #include "solver_init.cuh"
11 
12 #ifdef GENERATE_DOCS
13 namespace rkc_cu {
14 #endif
15 
16  void init_solver_log() {
17 
18  }
19 
20  void solver_log() {
21 
22  }
23 
28  const char* solver_name() {
29  const char* name = "rkc-gpu";
30  return name;
31  }
32 
39  size_t required_solver_size() {
40  //return the size (in bytes), needed per cuda thread
41  size_t num_bytes = 0;
42  // state vector
43  num_bytes += NSP * sizeof(double);
44  // derivatives
45  num_bytes += NSP * sizeof(double);
46  // work array with 4 extra spots
47  num_bytes += (4 + NSP) * sizeof(double);
48  // four regular work arrays of size NSP
49  num_bytes += 4 * NSP * sizeof(double);
50  // result array
51  num_bytes += 1 * sizeof(int);
52 
53  return num_bytes;
54  }
55 
61 void createAndZero(void** ptr, size_t size)
62 {
63  cudaErrorCheck(cudaMalloc(ptr, size));
64  cudaErrorCheck(cudaMemset(*ptr, 0, size));
65 }
66 
73 void initialize_solver(const int padded, solver_memory** h_mem, solver_memory** d_mem) {
74  // Allocate storage for the device struct
75  cudaErrorCheck( cudaMalloc(d_mem, sizeof(solver_memory)) );
76  //allocate the device arrays on the host pointer
77  createAndZero((void**)&((*h_mem)->y_n), NSP * padded * sizeof(double));
78  createAndZero((void**)&((*h_mem)->F_n), NSP * padded * sizeof(double));
79  createAndZero((void**)&((*h_mem)->work), (NSP + 4) * padded * sizeof(double));
80  createAndZero((void**)&((*h_mem)->temp_arr), NSP * padded * sizeof(double));
81  createAndZero((void**)&((*h_mem)->temp_arr2), NSP * padded * sizeof(double));
82  createAndZero((void**)&((*h_mem)->y_jm1), NSP * padded * sizeof(double));
83  createAndZero((void**)&((*h_mem)->y_jm2), NSP * padded * sizeof(double));
84  createAndZero((void**)&((*h_mem)->result), padded * sizeof(int));
85 
86  //copy host struct to device
87  cudaErrorCheck( cudaMemcpy(*d_mem, *h_mem, sizeof(solver_memory), cudaMemcpyHostToDevice) );
88 }
89 
96  void cleanup_solver(solver_memory** h_mem, solver_memory** d_mem) {
97  cudaErrorCheck(cudaFree((*h_mem)->y_n));
98  cudaErrorCheck(cudaFree((*h_mem)->F_n));
99  cudaErrorCheck(cudaFree((*h_mem)->work));
100  cudaErrorCheck(cudaFree((*h_mem)->temp_arr));
101  cudaErrorCheck(cudaFree((*h_mem)->temp_arr2));
102  cudaErrorCheck(cudaFree((*h_mem)->y_jm1));
103  cudaErrorCheck(cudaFree((*h_mem)->y_jm2));
104  cudaErrorCheck(cudaFree((*h_mem)->result));
105  cudaErrorCheck(cudaFree(*d_mem));
106 }
Definition: rkc.cu:5
int padded
Padded # of ODEs to solve.
void solver_log()
Definition: cvodes_init.c:192
#define NSP
The IVP system size.
Definition: header.cuh:20
Header definitions for solver initialization routins.
const char * solver_name()
Returns a descriptive solver name.
Definition: cvodes_init.c:181
void createAndZero(void **ptr, size_t size)
Convienvience method to Cuda Malloc and memset a pointer to zero.
Definition: exp4_init.cu:25
void initialize_solver(int num_threads)
Initializes the solver.
Definition: cvodes_init.c:49
size_t required_solver_size()
Returns the total size (in bytes) required for memory storage for a single GPU thread Used in calcula...
Definition: exp4_init.cu:167
void cleanup_solver(int num_threads)
Cleans up the created solvers.
Definition: cvodes_init.c:165
#define cudaErrorCheck(ans)
Definition: gpu_macros.cuh:26
void init_solver_log()
Definition: cvodes_init.c:190