accelerInt  v0.1
radau2a_init.cu
Go to the documentation of this file.
1 
10  #include "solver_init.cuh"
11 
12 #ifdef GENERATE_DOCS
13 namespace radau2acu {
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 = "radau2a-int-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  //regular jacobian factorization
43  num_bytes += NSP * NSP * sizeof(double);
44  //complex jacobian factorization
45  num_bytes += NSP * NSP * sizeof(cuDoubleComplex);
46  //an error scale array
47  num_bytes += NSP * sizeof(double);
48  //two pivot index arrays
49  num_bytes += 2 * NSP * sizeof(int);
50  //6 RHS and interpolant arrays
51  num_bytes += 6 * NSP * sizeof(double);
52  //continuation array of size 3 * NSP
53  num_bytes += 3 * NSP * sizeof(double);
54  //y0
55  num_bytes += NSP * sizeof(double);
56  //3 work arrays
57  num_bytes += 3 * NSP * sizeof(double);
58  //1 complex work array
59  num_bytes += NSP * sizeof(double);
60  //result flag
61  num_bytes += 1 * sizeof(int);
62 
63  return num_bytes;
64  }
65 
71 void createAndZero(void** ptr, size_t size)
72 {
73  cudaErrorCheck(cudaMalloc(ptr, size));
74  cudaErrorCheck(cudaMemset(*ptr, 0, size));
75 }
76 
83 void initialize_solver(const int padded, solver_memory** h_mem, solver_memory** d_mem) {
84  // Allocate storage for the device struct
85  cudaErrorCheck( cudaMalloc(d_mem, sizeof(solver_memory)) );
86  //allocate the device arrays on the host pointer
87  createAndZero((void**)&((*h_mem)->E1), NSP * NSP * padded * sizeof(double));
88  createAndZero((void**)&((*h_mem)->E2), NSP * NSP * padded * sizeof(cuDoubleComplex));
89  createAndZero((void**)&((*h_mem)->scale), NSP * padded * sizeof(cuDoubleComplex));
90  createAndZero((void**)&((*h_mem)->ipiv1), NSP * padded * sizeof(int));
91  createAndZero((void**)&((*h_mem)->ipiv2), NSP * padded * sizeof(int));
92  createAndZero((void**)&((*h_mem)->Z1), NSP * padded * sizeof(double));
93  createAndZero((void**)&((*h_mem)->Z2), NSP * padded * sizeof(double));
94  createAndZero((void**)&((*h_mem)->Z3), NSP * padded * sizeof(double));
95  createAndZero((void**)&((*h_mem)->DZ1), NSP * padded * sizeof(double));
96  createAndZero((void**)&((*h_mem)->DZ2), NSP * padded * sizeof(double));
97  createAndZero((void**)&((*h_mem)->DZ3), NSP * padded * sizeof(double));
98  createAndZero((void**)&((*h_mem)->CONT), 3 * NSP * padded * sizeof(double));
99  createAndZero((void**)&((*h_mem)->y0), NSP * padded * sizeof(double));
100  createAndZero((void**)&((*h_mem)->work1), NSP * padded * sizeof(double));
101  createAndZero((void**)&((*h_mem)->work2), NSP * padded * sizeof(double));
102  createAndZero((void**)&((*h_mem)->work3), NSP * padded * sizeof(double));
103  createAndZero((void**)&((*h_mem)->work4), NSP * padded * sizeof(cuDoubleComplex));
104  createAndZero((void**)&((*h_mem)->result), padded * sizeof(int));
105 
106  //copy host struct to device
107  cudaErrorCheck( cudaMemcpy(*d_mem, *h_mem, sizeof(solver_memory), cudaMemcpyHostToDevice) );
108 }
109 
116  void cleanup_solver(solver_memory** h_mem, solver_memory** d_mem) {
117  cudaErrorCheck(cudaFree((*h_mem)->E1));
118  cudaErrorCheck(cudaFree((*h_mem)->E2));
119  cudaErrorCheck(cudaFree((*h_mem)->scale));
120  cudaErrorCheck(cudaFree((*h_mem)->ipiv1));
121  cudaErrorCheck(cudaFree((*h_mem)->ipiv2));
122  cudaErrorCheck(cudaFree((*h_mem)->Z1));
123  cudaErrorCheck(cudaFree((*h_mem)->Z2));
124  cudaErrorCheck(cudaFree((*h_mem)->Z3));
125  cudaErrorCheck(cudaFree((*h_mem)->DZ1));
126  cudaErrorCheck(cudaFree((*h_mem)->DZ2));
127  cudaErrorCheck(cudaFree((*h_mem)->DZ3));
128  cudaErrorCheck(cudaFree((*h_mem)->CONT));
129  cudaErrorCheck(cudaFree((*h_mem)->y0));
130  cudaErrorCheck(cudaFree((*h_mem)->work1));
131  cudaErrorCheck(cudaFree((*h_mem)->work2));
132  cudaErrorCheck(cudaFree((*h_mem)->work3));
133  cudaErrorCheck(cudaFree((*h_mem)->work4));
134  cudaErrorCheck(cudaFree((*h_mem)->result));
135  cudaErrorCheck(cudaFree(*d_mem));
136 }
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