Rewrite the force calculations to fix memory issues
This commit is contained in:
parent
2d948a7e76
commit
ac44ceaab1
4 changed files with 79 additions and 64 deletions
|
@ -5,13 +5,13 @@
|
|||
|
||||
// Include your header files
|
||||
#include "forces.cuh"
|
||||
#include "pair_potentials.cuh"
|
||||
#include "potentials/pair_potentials.cuh"
|
||||
#include "precision.hpp"
|
||||
|
||||
class CudaForceKernelTest : public ::testing::Test {
|
||||
protected:
|
||||
const int BLOCK_SIZE = 1;
|
||||
const int THREADS_PER_BLOCK = 4;
|
||||
const int GRID_SIZE = 1;
|
||||
const int BLOCK_SIZE = 4;
|
||||
|
||||
void SetUp() override {
|
||||
// Set up CUDA device
|
||||
|
@ -66,17 +66,9 @@ protected:
|
|||
real *d_energies = allocateAndCopyToGPU(energies);
|
||||
real *d_box_len = allocateAndCopyToGPU(box_dimensions);
|
||||
|
||||
// Allocate potential on the GPU
|
||||
LennardJones h_potential(1.0, 1.0, 3.0);
|
||||
LennardJones *d_potential;
|
||||
checkCudaError(cudaMalloc(&d_potential, sizeof(LennardJones)),
|
||||
"cudaMalloc potential");
|
||||
checkCudaError(cudaMemcpy(d_potential, &h_potential, sizeof(LennardJones),
|
||||
cudaMemcpyHostToDevice),
|
||||
"cudaMemcpy H2D potential");
|
||||
|
||||
CAC::calc_forces_and_energies<<<BLOCK_SIZE, THREADS_PER_BLOCK>>>(
|
||||
d_positions, d_forces, d_energies, n_particles, d_box_len, d_potential);
|
||||
std::vector<PairPotentials> potentials = {LennardJones(1.0, 1.0, 3.0)};
|
||||
CAC::launch_force_kernels(d_positions, d_forces, d_energies, n_particles,
|
||||
d_box_len, potentials, GRID_SIZE, BLOCK_SIZE);
|
||||
|
||||
checkCudaError(cudaGetLastError(), "kernel launch");
|
||||
checkCudaError(cudaDeviceSynchronize(), "kernel execution");
|
||||
|
@ -88,7 +80,6 @@ protected:
|
|||
|
||||
checkCudaError(cudaFree(d_positions), "cudaFree positions");
|
||||
checkCudaError(cudaFree(d_box_len), "cudaFree box_len");
|
||||
checkCudaError(cudaFree(d_potential), "cudaFree potential");
|
||||
|
||||
return {result_forces, result_energies};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue