Skip to content

Commit

Permalink
misc changes to compile without grav
Browse files Browse the repository at this point in the history
  • Loading branch information
mabruzzo committed Jul 26, 2024
1 parent 4e40aef commit 95dd375
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/grid/grid3D.h
Original file line number Diff line number Diff line change
Expand Up @@ -845,13 +845,13 @@ class Grid3D
void Advance_Particles_KDK_Step2_GPU();
void Set_Particles_Boundary_GPU(int dir, int side);
void Set_Particles_Density_Boundaries_Periodic_GPU(int direction, int side);
int Load_Particles_Density_Boundary_to_Buffer_GPU(int direction, int side, Real *buffer);
void Unload_Particles_Density_Boundary_From_Buffer_GPU(int direction, int side, Real *buffer);
#endif // PARTICLES_GPU
#ifdef GRAVITY_GPU
void Copy_Potential_From_GPU();
void Copy_Particles_Density_to_GPU();
void Copy_Particles_Density_GPU();
int Load_Particles_Density_Boundary_to_Buffer_GPU(int direction, int side, Real *buffer);
void Unload_Particles_Density_Boundary_From_Buffer_GPU(int direction, int side, Real *buffer);
#endif // GRAVITY_GPU
#endif // PARTICLES

Expand Down
6 changes: 4 additions & 2 deletions src/particles/density_CIC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void Grid3D::Copy_Particles_Density()
Copy_Particles_Density_to_GPU();
#endif
Copy_Particles_Density_GPU();
#else
#elif defined(GRAVITY)

#ifndef PARALLEL_OMP
Copy_Particles_Density_function(0, Grav.nz_local);
Expand All @@ -90,11 +90,12 @@ void Grid3D::Copy_Particles_Density()
}
#endif // PARALLEL_OMP

#endif // GRAVITY_GPU
#endif // GRAVITY_GPU and GRAVITY
}

void Grid3D::Copy_Particles_Density_function(int g_start, int g_end)
{
#ifdef GRAVITY
int nx_part, ny_part, nz_part, nGHST;
nGHST = Particles.G.n_ghost_particles_grid;
nx_part = Particles.G.nx_local + 2 * nGHST;
Expand All @@ -116,6 +117,7 @@ void Grid3D::Copy_Particles_Density_function(int g_start, int g_end)
}
}
}
#endif // GRAVITY
}

// Clear the density array: density=0
Expand Down
14 changes: 12 additions & 2 deletions src/particles/density_boundaries_gpu.cu
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#if defined(PARTICLES_GPU) && defined(GRAVITY_GPU)
#if defined(PARTICLES_GPU)

#include <iostream>

#include "../grid/grid3D.h"
#include "../io/io.h"
#include "../utils/error_handling.h"
#include "particles_3D.h"

__global__ void Set_Particles_Density_Boundaries_Periodic_kernel(int direction, int side, int n_i, int n_j, int nx,
Expand Down Expand Up @@ -68,6 +69,9 @@ __global__ void Set_Particles_Density_Boundaries_Periodic_kernel(int direction,

void Grid3D::Set_Particles_Density_Boundaries_Periodic_GPU(int direction, int side)
{
#ifndef GRAVITY_GPU
CHOLLA_ERROR("This function should not be invoked when compiled without GPU-Gravity");
#endif GRAVITY_GPU
int n_ghost, nx_g, ny_g, nz_g, size, ngrid, n_i, n_j;
n_ghost = Particles.G.n_ghost_particles_grid;
nx_g = Particles.G.nx_local + 2 * n_ghost;
Expand Down Expand Up @@ -148,6 +152,9 @@ __global__ void Load_Particles_Density_Boundary_to_Buffer_kernel(int direction,

int Grid3D::Load_Particles_Density_Boundary_to_Buffer_GPU(int direction, int side, Real *buffer)
{
#ifndef GRAVITY_GPU
CHOLLA_ERROR("This function should not be invoked when compiled without GPU-Gravity");
#endif GRAVITY_GPU
int n_ghost, nx_g, ny_g, nz_g, size_buffer, ngrid, n_i, n_j;
n_ghost = Particles.G.n_ghost_particles_grid;
nx_g = Particles.G.nx_local + 2 * n_ghost;
Expand Down Expand Up @@ -236,6 +243,9 @@ __global__ void Unload_Particles_Density_Boundary_to_Buffer_kernel(int direction

void Grid3D::Unload_Particles_Density_Boundary_From_Buffer_GPU(int direction, int side, Real *buffer)
{
#ifndef GRAVITY_GPU
CHOLLA_ERROR("This function should not be invoked when compiled without GPU-Gravity");
#endif GRAVITY_GPU
int n_ghost, nx_g, ny_g, nz_g, size_buffer, ngrid, n_i, n_j;
n_ghost = Particles.G.n_ghost_particles_grid;
nx_g = Particles.G.nx_local + 2 * n_ghost;
Expand Down Expand Up @@ -276,4 +286,4 @@ void Grid3D::Unload_Particles_Density_Boundary_From_Buffer_GPU(int direction, in

#endif // MPI_CHOLLA

#endif // PARTICLES_GPU & GRAVITY_GPU
#endif // PARTICLES_GPU
2 changes: 1 addition & 1 deletion src/particles/gravity_CIC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void Grid3D::Get_Gravity_Field_Particles()
#endif // PARALLEL_OMP
#endif // PARTICLES_CPU

#ifdef PARTICLES_GPU
#if defined(PARTICLES_GPU) && defined(GRAVITY_GPU)
Particles.Get_Gravity_Field_Particles_GPU(Grav.F.potential_h);
#endif
}
Expand Down
6 changes: 4 additions & 2 deletions src/particles/gravity_CIC_gpu.cu
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,10 @@ void Particles3D::Get_Gravity_Field_Particles_GPU_function(int nx_local, int ny_
Real *gravity_x_dev, Real *gravity_y_dev,
Real *gravity_z_dev)
{
#ifndef GRAVITY_GPU
#ifdef GRAVITY
#ifndef GRAVITY_GPU
Copy_Potential_To_GPU(potential_host, potential_dev, n_cells_potential);
#endif
#endif

int nx_g, ny_g, nz_g;
nx_g = nx_local + 2 * N_GHOST_POTENTIAL;
Expand All @@ -133,6 +134,7 @@ void Particles3D::Get_Gravity_Field_Particles_GPU_function(int nx_local, int ny_
gravity_y_dev, gravity_z_dev, nx_local, ny_local, nz_local, n_ghost_particles_grid,
N_GHOST_POTENTIAL, dx, dy, dz);
GPU_Error_Check();
#endif // GRAVITY
}

// Get CIC indexes from the particles positions
Expand Down
2 changes: 2 additions & 0 deletions src/particles/particles_3D.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include "../grid/spatial_domain_props.h"

#ifdef PARTICLES_GPU
#include "../utils/gpu.hpp" // cudaFree

#define TPB_PARTICLES 1024
// #define PRINT_GPU_MEMORY
#define PRINT_MAX_MEMORY_USAGE
Expand Down
2 changes: 2 additions & 0 deletions src/particles/particles_boundaries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,11 @@ void Grid3D::Unload_Particles_From_Buffers_BLOCK(int index, int *flags)
if (H.TRANSFER_HYDRO_BOUNDARIES) {
return;
}
#ifdef GRAVITY
if (Grav.TRANSFER_POTENTIAL_BOUNDARIES) {
return;
}
#endif

if (index == 0) {
Unload_Particles_from_Buffer_X0(flags);
Expand Down

0 comments on commit 95dd375

Please sign in to comment.