#include #include "GPU_MagneticField.h" //------------------------------------ // MakeGPUResidentBfieldSectionList //------------------------------------ BfieldSectionList* MakeGPUResidentBfieldSectionList(BfieldSectionList *host_BfieldSectionList) { /// Allocate memory on the GPU to hold a BfieldSectionList /// structure and copy the host-resident one into it. The /// sections arrays should contain pointers to *host* resident /// structures. Each of those will be copied into gpu resident /// structures as the BfieldSectionList is made. // Copy host_BfieldSectionList to temporary structure so we can // replace the BfieldSection pointers with device resident ones BfieldSectionList tmp_BfieldSectionList; tmp_BfieldSectionList = *host_BfieldSectionList; // Allocate memory on device for BfieldSectionList int size = sizeof(BfieldSectionList); BfieldSectionList *device_BfieldSectionList; cudaMalloc(&device_BfieldSectionList, size); // Loop over Bx sections, copying them to GPU memory for(int i=0; isections_Bx[i]); } // Loop over Bz sections, copying them to GPU memory for(int i=0; isections_Bz[i]); } // Copy temporary BfieldSectionList into GPU memory cudaMemcpy(device_BfieldSectionList, &tmp_BfieldSectionList, size, cudaMemcpyHostToDevice); return device_BfieldSectionList; } //------------------------------------ // MakeGPUResidentBfieldSection //------------------------------------ BfieldSection* MakeGPUResidentBfieldSection(BfieldSection *host_BfieldSection) { /// Allocate memory on the GPU to hold a BfieldSection structure /// and copy the contents of the given host resident structure to /// it. Returns a pointer to the GPU resident copy. int size = sizeof(BfieldSection); BfieldSection *device_BfieldSection; cudaMalloc(&device_BfieldSection, size); cudaMemcpy(device_BfieldSection, host_BfieldSection, size, cudaMemcpyHostToDevice); return device_BfieldSection; } //------------------------------------ // BfieldSectionIsInRange //------------------------------------ __device__ int BfieldSectionIsInRange(BfieldSection *bfs, double z) { return z<=bfs->zmax && z>=bfs->zmin; }