Cholla 3.0.1-dev
Cholla - Massively parallel hydro on GPUs
Loading...
Searching...
No Matches
global_cuda.h
1
5#ifndef GLOBAL_CUDA_H
6#define GLOBAL_CUDA_H
7
8#include <math.h>
9#include <stdio.h>
10#include <stdlib.h>
11
12#include "../global/global.h"
13#include "../utils/gpu.hpp"
14
15#define TPB 256 // threads per block
16// #define TPB 64
17
18extern bool memory_allocated; // Flag becomes true after allocating the memory
19 // on the first timestep
20
21// Arrays are global so that they can be allocated only once.
22// Not all arrays will be allocated for every integrator
23// GPU arrays
24// conserved variables
25extern Real *dev_conserved, *dev_conserved_half;
26// input states and associated interface fluxes (Q* and F* from Stone, 2008)
27// Note that for hydro the size of these arrays is n_fields*n_cells*sizeof(Real)
28// while for MHD it is (n_fields-1)*n_cells*sizeof(Real), i.e. they has one
29// fewer field than you would expect
30extern Real *Q_Lx, *Q_Rx, *Q_Ly, *Q_Ry, *Q_Lz, *Q_Rz, *F_x, *F_y, *F_z;
31// Constrained transport electric fields
32extern Real *ctElectricFields;
33
34// Arrays for potential in GPU: Will be set to NULL if not using GRAVITY
35extern Real *dev_grav_potential;
36extern Real *temp_potential;
37extern Real *buffer_potential;
38
41__device__ inline int sgn_CUDA(Real x)
42{
43 if (x < 0) {
44 return -1;
45 } else {
46 return 1;
47 }
48}
49
50// Define atomic_add if it's not supported
51#if !defined(__CUDA_ARCH__) || __CUDA_ARCH__ >= 600
52#else
53__device__ double atomicAdd(double *address, double val)
54{
55 unsigned long long int *address_as_ull = (unsigned long long int *)address;
56 unsigned long long int old = *address_as_ull, assumed;
57 do {
58 assumed = old;
59 old = atomicCAS(address_as_ull, assumed, __double_as_longlong(val + __longlong_as_double(assumed)));
60 } while (assumed != old);
61 return __longlong_as_double(old);
62}
63#endif
64
65// This helper function exists to make it easier to find printfs inside
66// kernels
67#define kernel_printf printf
68
69#endif // GLOBAL_CUDA_H