Skip to content
Snippets Groups Projects
Commit ed161431 authored by Markus Holzer's avatar Markus Holzer
Browse files

changed normlizaton factor in CUDA codegen

parent 1b472a22
Branches
Tags
No related merge requests found
......@@ -78,7 +78,7 @@ void testJacobi2D()
// Create blocks
shared_ptr< StructuredBlockForest > blocks = blockforest::createUniformBlockGrid (
uint_t(1) , uint_t(1), uint_t(1), // number of blocks in x,y,z direction
xSize, ySize, uint_t(1), // how many cells per block (x,y,z)
xSize, ySize, uint_t(1), // how many cells per block (x,y,z)
real_t(1), // dx: length of one cell in physical coordinates
false, // one block per process - "false" means all blocks to one process
true, true, true ); // no periodicity
......@@ -87,7 +87,8 @@ void testJacobi2D()
BlockDataID cpuFieldID = blocks->addStructuredBlockData<ScalarField>( &createField, "CPU Field" );
BlockDataID gpuField = cuda::addGPUFieldToStorage<ScalarField>( blocks, cpuFieldID, "GPU Field Src" );
// Initialize a quarter of the field with ones, the rest remains 0
// Jacobi averages the domain -> every cell should be at 0.25 at sufficiently many timesteps
for(auto blockIt = blocks->begin(); blockIt != blocks->end(); ++blockIt)
{
auto f = blockIt->getData<ScalarField>( cpuFieldID );
......@@ -96,8 +97,6 @@ void testJacobi2D()
f->get( x, y, 0 ) = 1.0;
}
typedef blockforest::communication::UniformBufferedScheme<stencil::D2Q9> CommScheme;
typedef cuda::communication::GPUPackInfo<GPUField> Packing;
......@@ -110,7 +109,7 @@ void testJacobi2D()
// Registering the sweep
timeloop.add() << BeforeFunction( commScheme, "Communication" )
<< Sweep( pystencils::CudaJacobiKernel2D(gpuField, 1.0), "Jacobi Kernel" );
<< Sweep( pystencils::CudaJacobiKernel2D(gpuField, 2.0), "Jacobi Kernel" );
cuda::fieldCpy<GPUField, ScalarField>( blocks, gpuField, cpuFieldID );
......@@ -141,7 +140,8 @@ void testJacobi3D()
BlockDataID cpuFieldID = blocks->addStructuredBlockData<ScalarField>( &createField, "CPU Field" );
BlockDataID gpuField = cuda::addGPUFieldToStorage<ScalarField>( blocks, cpuFieldID, "GPU Field Src" );
// Initialize a quarter of the field with ones, the rest remains 0
// Jacobi averages the domain -> every cell should be at 0.25 at sufficiently many timesteps
for(auto blockIt = blocks->begin(); blockIt != blocks->end(); ++blockIt)
{
auto f = blockIt->getData<ScalarField>( cpuFieldID );
......@@ -151,8 +151,6 @@ void testJacobi3D()
f->get( x, y, z ) = 1.0;
}
typedef blockforest::communication::UniformBufferedScheme<stencil::D3Q7> CommScheme;
typedef cuda::communication::GPUPackInfo<GPUField> Packing;
......
......@@ -7,11 +7,11 @@ with CodeGeneration() as ctx:
h = sp.symbols("h")
# ----- Jacobi 2D - created by specifying weights in nested list --------------------------
src, dst = ps.fields("src, src_tmp: [2D]")
stencil = [[0, 1, 0],
[1, 0, 1],
[0, 1, 0]]
assignments = ps.assignment_from_stencil(stencil, src, dst, normalization_factor=0.25 * h**2)
src, dst = ps.fields("src, src_tmp: [2D]", layout='fzyx')
stencil = [[0, 4, 0],
[4, 0, 4],
[0, 4, 0]]
assignments = ps.assignment_from_stencil(stencil, src, dst, normalization_factor=1 / (4 * h ** 2))
generate_sweep(ctx, 'CudaJacobiKernel2D', assignments, field_swaps=[(src, dst)], target="gpu")
# ----- Jacobi 3D - created by using kernel_decorator with assignments in '@=' format -----
......
......@@ -21,6 +21,6 @@ with CodeGeneration() as ctx:
def kernel_func():
dst[0, 0, 0] @= (src[1, 0, 0] + src[-1, 0, 0] +
src[0, 1, 0] + src[0, -1, 0] +
src[0, 0, 1] + src[0, 0, -1]) / (h ** 2 * 6)
src[0, 0, 1] + src[0, 0, -1]) / (6 * h ** 2)
generate_sweep(ctx, 'JacobiKernel3D', kernel_func, field_swaps=[(src, dst)])
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment