accelerInt  v0.1
gpu_memory.cu
Go to the documentation of this file.
1 
6 #include "gpu_memory.cuh"
7 
8 #ifdef GENERATE_DOCS
9 //put this in the van der Pol namespace for documentation
10 namespace van_der_pol_cu {
11 #endif
12 
16  //returns the total required size for the mechanism per thread
17  size_t mech_size = 0;
18  //state vector y
19  mech_size += NSP;
20  //dydt vector
21  mech_size += NSP;
22  //Jacobian
23  mech_size += NSP * NSP;
24  //and mu parameter
25  mech_size += 1;
26  return mech_size * sizeof(double);
27 }
31 {
32  // Allocate storage for the device struct
33  cudaErrorCheck( cudaMalloc(d_mem, sizeof(mechanism_memory)) );
34  //allocate the device arrays on the host pointer
35  cudaErrorCheck( cudaMalloc(&((*h_mem)->y), NSP * padded * sizeof(double)) );
36  cudaErrorCheck( cudaMalloc(&((*h_mem)->dy), NSP * padded * sizeof(double)) );
37  cudaErrorCheck( cudaMalloc(&((*h_mem)->var), 1 * padded * sizeof(double)) );
38  cudaErrorCheck( cudaMalloc(&((*h_mem)->jac), NSP * NSP * padded * sizeof(double)) );
39  // set non-initialized values to zero
40  cudaErrorCheck( cudaMemset((*h_mem)->dy, 0, NSP * padded * sizeof(double)) );
41  cudaErrorCheck( cudaMemset((*h_mem)->jac, 0, NSP * NSP * padded * sizeof(double)) );
42  // and copy to device pointer
43  cudaErrorCheck( cudaMemcpy(*d_mem, *h_mem, sizeof(mechanism_memory), cudaMemcpyHostToDevice) );
44 }
48 {
49  cudaErrorCheck(cudaFree((*h_mem)->y));
50  cudaErrorCheck(cudaFree((*h_mem)->dy));
51  cudaErrorCheck(cudaFree((*h_mem)->var));
52  cudaErrorCheck(cudaFree((*h_mem)->jac));
53  cudaErrorCheck(cudaFree(*d_mem));
54 }
55 
56 #ifdef GENERATE_DOCS
57 }
58 #endif
int padded
Padded # of ODEs to solve.
#define NSP
The IVP system size.
Definition: header.cuh:20
void initialize_gpu_memory(int padded, mechanism_memory **h_mem, mechanism_memory **d_mem)
Initializes the host and device mechanism_memory structs. This is required in order to enable passing...
Definition: gpu_memory.cu:30
void free_gpu_memory(mechanism_memory **h_mem, mechanism_memory **d_mem)
Frees the host and device mechanism_memory structs.
Definition: gpu_memory.cu:47
#define cudaErrorCheck(ans)
Definition: gpu_macros.cuh:26
This struct is used to store memory for the CUDA RHS and Jacobian evaluation. Along with the solver_m...
Definition: gpu_memory.cuh:25
Headers for GPU memory initialization.
size_t required_mechanism_size()
Calculates and returns the total memory size (in bytes) required by an individual thread for the mech...
Definition: gpu_memory.cu:15